| @@ -48,6 +48,7 @@ public class DefaultInputHandler implements InputHandler { | |||||
| public void handleInput(InputRequest request) throws BuildException { | public void handleInput(InputRequest request) throws BuildException { | ||||
| String prompt = getPrompt(request); | String prompt = getPrompt(request); | ||||
| BufferedReader r = null; | BufferedReader r = null; | ||||
| boolean success = false; | |||||
| try { | try { | ||||
| r = new BufferedReader(new InputStreamReader(getInputStream())); | r = new BufferedReader(new InputStreamReader(getInputStream())); | ||||
| do { | do { | ||||
| @@ -61,12 +62,15 @@ public class DefaultInputHandler implements InputHandler { | |||||
| + " Console.", e); | + " Console.", e); | ||||
| } | } | ||||
| } while (!request.isInputValid()); | } while (!request.isInputValid()); | ||||
| success = true; | |||||
| } finally { | } finally { | ||||
| if (r != null) { | if (r != null) { | ||||
| try { | try { | ||||
| r.close(); | r.close(); | ||||
| } catch (IOException e) { | } catch (IOException e) { | ||||
| throw new BuildException("Failed to close input.", e); | |||||
| if (success) { // don't hide inner exception | |||||
| throw new BuildException("Failed to close input.", e); //NOSONAR | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -117,4 +121,4 @@ public class DefaultInputHandler implements InputHandler { | |||||
| protected InputStream getInputStream() { | protected InputStream getInputStream() { | ||||
| return KeepAliveInputStream.wrapSystemIn(); | return KeepAliveInputStream.wrapSystemIn(); | ||||
| } | } | ||||
| } | |||||
| } | |||||
| @@ -1279,8 +1279,10 @@ public class JUnitTask extends Task { | |||||
| checkForkedPath(cmd); | checkForkedPath(cmd); | ||||
| final TestResultHolder result = new TestResultHolder(); | final TestResultHolder result = new TestResultHolder(); | ||||
| boolean success = false; | |||||
| try { | try { | ||||
| result.exitCode = execute.execute(); | result.exitCode = execute.execute(); | ||||
| success = true; | |||||
| } catch (final IOException e) { | } catch (final IOException e) { | ||||
| throw new BuildException("Process fork failed.", e, getLocation()); | throw new BuildException("Process fork failed.", e, getLocation()); | ||||
| } finally { | } finally { | ||||
| @@ -1322,9 +1324,13 @@ public class JUnitTask extends Task { | |||||
| } | } | ||||
| if (!FILE_UTILS.tryHardToDelete(propsFile)) { | if (!FILE_UTILS.tryHardToDelete(propsFile)) { | ||||
| throw new BuildException("Could not delete temporary " | |||||
| + "properties file '" | |||||
| + propsFile.getAbsolutePath() + "'."); | |||||
| String msg = "Could not delete temporary properties file '" | |||||
| + propsFile.getAbsolutePath() + "'."; | |||||
| if (success) { | |||||
| throw new BuildException(msg); //NOSONAR | |||||
| } else { // don't hide inner exception | |||||
| log(msg, Project.MSG_ERR); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -117,6 +117,7 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter, IgnoredT | |||||
| * @throws BuildException if unable to write the output | * @throws BuildException if unable to write the output | ||||
| */ | */ | ||||
| public void endTestSuite(JUnitTest suite) throws BuildException { | public void endTestSuite(JUnitTest suite) throws BuildException { | ||||
| boolean success = false; | |||||
| try { | try { | ||||
| StringBuffer sb = new StringBuffer("Tests run: "); | StringBuffer sb = new StringBuffer("Tests run: "); | ||||
| sb.append(suite.runCount()); | sb.append(suite.runCount()); | ||||
| @@ -158,12 +159,15 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter, IgnoredT | |||||
| throw new BuildException("Unable to write output", ioex); | throw new BuildException("Unable to write output", ioex); | ||||
| } | } | ||||
| } | } | ||||
| success = true; | |||||
| } finally { | } finally { | ||||
| if (out != null) { | if (out != null) { | ||||
| try { | try { | ||||
| wri.close(); | wri.close(); | ||||
| } catch (IOException ioex) { | } catch (IOException ioex) { | ||||
| throw new BuildException("Unable to flush output", ioex); | |||||
| if (success) { | |||||
| throw new BuildException("Unable to flush output", ioex); //NOSONAR | |||||
| } | |||||
| } finally { | } finally { | ||||
| if (out != System.out && out != System.err) { | if (out != System.out && out != System.err) { | ||||
| FileUtils.close(out); | FileUtils.close(out); | ||||
| @@ -354,6 +354,7 @@ public class RExecTask extends Task { | |||||
| /** Create the telnet client object */ | /** Create the telnet client object */ | ||||
| AntRExecClient rexec = null; | AntRExecClient rexec = null; | ||||
| boolean success = false; | |||||
| try { | try { | ||||
| rexec = new AntRExecClient(); | rexec = new AntRExecClient(); | ||||
| try { | try { | ||||
| @@ -372,6 +373,7 @@ public class RExecTask extends Task { | |||||
| /** Keep reading input stream until end of it or time-out */ | /** Keep reading input stream until end of it or time-out */ | ||||
| rexec.waitForEOF(defaultTimeout); | rexec.waitForEOF(defaultTimeout); | ||||
| success = true; | |||||
| } catch (IOException e) { | } catch (IOException e) { | ||||
| throw new BuildException("Error r-executing command", e); | throw new BuildException("Error r-executing command", e); | ||||
| } finally { | } finally { | ||||
| @@ -379,8 +381,12 @@ public class RExecTask extends Task { | |||||
| try { | try { | ||||
| rexec.disconnect(); | rexec.disconnect(); | ||||
| } catch (IOException e) { | } catch (IOException e) { | ||||
| throw new BuildException("Error disconnecting from " | |||||
| + server); | |||||
| String msg = "Error disconnecting from " + server; | |||||
| if (success) { | |||||
| throw new BuildException(msg); //NOSONAR | |||||
| } else { // don't hide inner exception | |||||
| log(msg, Project.MSG_ERR); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -98,6 +98,7 @@ public class TelnetTask extends Task { | |||||
| /** Create the telnet client object */ | /** Create the telnet client object */ | ||||
| AntTelnetClient telnet = null; | AntTelnetClient telnet = null; | ||||
| boolean success = false; | |||||
| try { | try { | ||||
| telnet = new AntTelnetClient(); | telnet = new AntTelnetClient(); | ||||
| try { | try { | ||||
| @@ -118,13 +119,18 @@ public class TelnetTask extends Task { | |||||
| } | } | ||||
| task.execute(telnet); | task.execute(telnet); | ||||
| } | } | ||||
| success = true; | |||||
| } finally { | } finally { | ||||
| if (telnet != null && telnet.isConnected()) { | if (telnet != null && telnet.isConnected()) { | ||||
| try { | try { | ||||
| telnet.disconnect(); | telnet.disconnect(); | ||||
| } catch (IOException e) { | } catch (IOException e) { | ||||
| throw new BuildException("Error disconnecting from " | |||||
| + server); | |||||
| String msg = "Error disconnecting from " + server; | |||||
| if (success) { | |||||
| throw new BuildException(msg); //NOSONAR | |||||
| } else { // don't hide inner exception | |||||
| log(msg, Project.MSG_ERR); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -75,6 +75,7 @@ public class SunRmic extends DefaultRmicAdapter { | |||||
| LogOutputStream logstr = new LogOutputStream(getRmic(), | LogOutputStream logstr = new LogOutputStream(getRmic(), | ||||
| Project.MSG_WARN); | Project.MSG_WARN); | ||||
| boolean success = false; | |||||
| try { | try { | ||||
| Class c = Class.forName(RMIC_CLASSNAME); | Class c = Class.forName(RMIC_CLASSNAME); | ||||
| Constructor cons | Constructor cons | ||||
| @@ -86,6 +87,7 @@ public class SunRmic extends DefaultRmicAdapter { | |||||
| Boolean ok = | Boolean ok = | ||||
| (Boolean) doRmic.invoke(rmic, | (Boolean) doRmic.invoke(rmic, | ||||
| (new Object[] {cmd.getArguments()})); | (new Object[] {cmd.getArguments()})); | ||||
| success = true; | |||||
| return ok.booleanValue(); | return ok.booleanValue(); | ||||
| } catch (ClassNotFoundException ex) { | } catch (ClassNotFoundException ex) { | ||||
| if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) { | if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) { | ||||
| @@ -105,7 +107,11 @@ public class SunRmic extends DefaultRmicAdapter { | |||||
| try { | try { | ||||
| logstr.close(); | logstr.close(); | ||||
| } catch (IOException e) { | } catch (IOException e) { | ||||
| throw new BuildException(e); | |||||
| // swallow if there was an error before so that | |||||
| // original error will be passed up | |||||
| if (success) { | |||||
| throw new BuildException(e); //NOSONAR | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -189,6 +189,7 @@ public class ContainsRegexpSelector extends BaseExtendSelector | |||||
| throw new BuildException("Could not get InputStream from " | throw new BuildException("Could not get InputStream from " | ||||
| + r.toLongString(), e); | + r.toLongString(), e); | ||||
| } | } | ||||
| boolean success = false; | |||||
| try { | try { | ||||
| teststr = in.readLine(); | teststr = in.readLine(); | ||||
| @@ -202,7 +203,7 @@ public class ContainsRegexpSelector extends BaseExtendSelector | |||||
| } | } | ||||
| teststr = in.readLine(); | teststr = in.readLine(); | ||||
| } | } | ||||
| success = true; | |||||
| return false; | return false; | ||||
| } catch (IOException ioe) { | } catch (IOException ioe) { | ||||
| throw new BuildException("Could not read " + r.toLongString()); | throw new BuildException("Could not read " + r.toLongString()); | ||||
| @@ -210,8 +211,10 @@ public class ContainsRegexpSelector extends BaseExtendSelector | |||||
| try { | try { | ||||
| in.close(); | in.close(); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| throw new BuildException("Could not close " | |||||
| + r.toLongString()); | |||||
| if (success) { | |||||
| throw new BuildException("Could not close " //NOSONAR | |||||
| + r.toLongString()); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -254,6 +254,7 @@ public class SymbolicLinkUtils { | |||||
| } | } | ||||
| boolean renamedTarget = false; | boolean renamedTarget = false; | ||||
| boolean success = false; | |||||
| try { | try { | ||||
| try { | try { | ||||
| FILE_UTILS.rename(target, temp); | FILE_UTILS.rename(target, temp); | ||||
| @@ -270,20 +271,26 @@ public class SymbolicLinkUtils { | |||||
| + " (was it a real file? is this " | + " (was it a real file? is this " | ||||
| + "not a UNIX system?)"); | + "not a UNIX system?)"); | ||||
| } | } | ||||
| success = true; | |||||
| } finally { | } finally { | ||||
| if (renamedTarget) { | if (renamedTarget) { | ||||
| // return the resource to its original name: | // return the resource to its original name: | ||||
| try { | try { | ||||
| FILE_UTILS.rename(temp, target); | FILE_UTILS.rename(temp, target); | ||||
| } catch (final IOException e) { | } catch (final IOException e) { | ||||
| throw new IOException("Couldn't return resource " | |||||
| + temp | |||||
| + " to its original name: " | |||||
| + target.getAbsolutePath() | |||||
| + ". Reason: " + e.getMessage() | |||||
| + "\n THE RESOURCE'S NAME ON DISK" | |||||
| + " HAS BEEN CHANGED BY THIS" | |||||
| + " ERROR!\n"); | |||||
| String msg = "Couldn't return resource " | |||||
| + temp | |||||
| + " to its original name: " | |||||
| + target.getAbsolutePath() | |||||
| + ". Reason: " + e.getMessage() | |||||
| + "\n THE RESOURCE'S NAME ON DISK" | |||||
| + " HAS BEEN CHANGED BY THIS" | |||||
| + " ERROR!\n"; | |||||
| if (success) { | |||||
| throw new IOException(msg); //NOSONAR | |||||
| } else { | |||||
| System.err.println(msg); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||