From 444aa1d2ecb31c00d1ec28ebe8fb0e5a12322d6a Mon Sep 17 00:00:00 2001 From: kohsuke Date: Tue, 7 Apr 2009 16:01:36 +0000 Subject: [PATCH] improved AbortException so that it can record the error message. Necessary for plugins like nunit and cppunit as discussed in HUDSON-3427. This should be in 1.298. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@16904 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/AbortException.java | 13 ++++++- .../hudson/tasks/junit/AbortException.java | 35 ------------------- .../tasks/junit/JUnitResultArchiver.java | 9 ++--- .../hudson/maven/MavenModuleSetBuild.java | 18 +++++----- .../hudson/maven/MavenProcessFactory.java | 6 ++-- .../src/main/java/hudson/maven/MavenUtil.java | 12 +++---- 6 files changed, 31 insertions(+), 62 deletions(-) delete mode 100644 core/src/main/java/hudson/tasks/junit/AbortException.java diff --git a/core/src/main/java/hudson/AbortException.java b/core/src/main/java/hudson/AbortException.java index 7d492c94a9..3a1e50cd38 100644 --- a/core/src/main/java/hudson/AbortException.java +++ b/core/src/main/java/hudson/AbortException.java @@ -26,12 +26,23 @@ package hudson; import java.io.IOException; /** - * Signals a failure where the error message was reported. + * Signals a failure where the error was anticipated and diagnosed. * When this exception is caughted, * the stack trace will not be printed, and the build will be marked as a failure. * * @author Kohsuke Kawaguchi */ public final class AbortException extends IOException { + public AbortException() { + } + + /** + * When this exception is caught, the specified message will be reported. + * @since 1.298 + */ + public AbortException(String message) { + super(message); + } + private static final long serialVersionUID = 1L; } diff --git a/core/src/main/java/hudson/tasks/junit/AbortException.java b/core/src/main/java/hudson/tasks/junit/AbortException.java deleted file mode 100644 index 4e05e5e9a0..0000000000 --- a/core/src/main/java/hudson/tasks/junit/AbortException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package hudson.tasks.junit; - -/** - * Used to signal an orderly abort of the processing. - */ -class AbortException extends RuntimeException { - public AbortException(String msg) { - super(msg); - } - - private static final long serialVersionUID = 1L; -} diff --git a/core/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java b/core/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java index 355f52e817..ca3e16cacc 100644 --- a/core/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java +++ b/core/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java @@ -28,6 +28,7 @@ import hudson.FilePath; import hudson.FilePath.FileCallable; import hudson.Launcher; import hudson.Util; +import hudson.AbortException; import hudson.matrix.MatrixAggregatable; import hudson.matrix.MatrixAggregator; import hudson.matrix.MatrixBuild; @@ -98,10 +99,6 @@ public class JUnitResultArchiver extends Recorder implements Serializable, Matri action = new TestResultAction(build, result, listener); if(result.getPassCount()==0 && result.getFailCount()==0) throw new AbortException(Messages.JUnitResultArchiver_ResultIsEmpty()); - } catch (IOException e) { - e.printStackTrace(listener.error("Failed to archive JUnit reports")); - build.setResult(Result.FAILURE); - return true; } catch (AbortException e) { if(build.getResult()==Result.FAILURE) // most likely a build failed before it gets to the test phase. @@ -111,6 +108,10 @@ public class JUnitResultArchiver extends Recorder implements Serializable, Matri listener.getLogger().println(e.getMessage()); build.setResult(Result.FAILURE); return true; + } catch (IOException e) { + e.printStackTrace(listener.error("Failed to archive JUnit reports")); + build.setResult(Result.FAILURE); + return true; } diff --git a/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java b/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java index 29261b1952..4074646d90 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java @@ -387,7 +387,8 @@ public final class MavenModuleSetBuild extends AbstractBuild poms; @@ -717,10 +717,8 @@ public final class MavenModuleSetBuild extends AbstractBuild) project.getModules()) { File moduleFile = new File(new File(basedir, modulePath),"pom.xml"); - if(!moduleFile.exists()) { - listener.getLogger().println(moduleFile+" is referenced from "+project.getFile()+" but it doesn't exist"); - throw new AbortException(); - } + if(!moduleFile.exists()) + throw new AbortException(moduleFile+" is referenced from "+project.getFile()+" but it doesn't exist"); String relativePath = rel; if(relativePath.length()>0) relativePath+='/';