Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorAlexander Kurtakov2015-12-18 11:21:25 +0000
committerAlexander Kurtakov2015-12-18 11:21:25 +0000
commit4f9dbedc0adf2587a15a753f0fd17e2ce90852b3 (patch)
treeca19e7250b649d45df519b5b0a05f372b83ec47e /build
parente11035409fb1d4c581911a738570e994caabe14e (diff)
downloadorg.eclipse.cdt-4f9dbedc0adf2587a15a753f0fd17e2ce90852b3.tar.gz
org.eclipse.cdt-4f9dbedc0adf2587a15a753f0fd17e2ce90852b3.tar.xz
org.eclipse.cdt-4f9dbedc0adf2587a15a753f0fd17e2ce90852b3.zip
autotools: Cosmetics
Try-with-resources for ErrorParserManager. Change-Id: I5c36d3d68545cb50fcd416caefdc878212b57a88 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'build')
-rw-r--r--build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/AutotoolsNewMakeGenerator.java314
1 files changed, 153 insertions, 161 deletions
diff --git a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/AutotoolsNewMakeGenerator.java b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/AutotoolsNewMakeGenerator.java
index 45dcdd5ea52..4d54e921475 100644
--- a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/AutotoolsNewMakeGenerator.java
+++ b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/AutotoolsNewMakeGenerator.java
@@ -872,7 +872,6 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
"MakeGenerator.make.message", msgs)); //$NON-NLS-1$
- ErrorParserManager epm = null;
StringBuffer buf = new StringBuffer();
// Launch command - main invocation
@@ -911,92 +910,92 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
// Hook up an error parser manager
URI uri = URIUtil.toURI(runPath);
- epm = new ErrorParserManager(project, uri, this);
- epm.setOutputStream(consoleOutStream);
- epm.addErrorParser(ErrorParser.ID, new ErrorParser(getSourcePath(), getBuildPath()));
+ try (ErrorParserManager epm = new ErrorParserManager(project, uri, this)) {
+ epm.setOutputStream(consoleOutStream);
+ epm.addErrorParser(ErrorParser.ID, new ErrorParser(getSourcePath(), getBuildPath()));
- OutputStream stdout = epm.getOutputStream();
- OutputStream stderr = stdout;
+ OutputStream stdout = epm.getOutputStream();
+ OutputStream stderr = stdout;
- launcher.showCommand(true);
- Process proc = launcher.execute(commandPath, configTargets, env, runPath, SubMonitor.convert(monitor));
- int exitValue = 0;
- if (proc != null) {
- try {
- // Close the input of the process since we will never write to
- // it
- proc.getOutputStream().close();
- } catch (IOException e) {
- }
+ launcher.showCommand(true);
+ Process proc = launcher.execute(commandPath, configTargets, env, runPath, SubMonitor.convert(monitor));
+ int exitValue = 0;
+ if (proc != null) {
+ try {
+ // Close the input of the process since we will never
+ // write to
+ // it
+ proc.getOutputStream().close();
+ } catch (IOException e) {
+ }
- if (launcher.waitAndRead(stdout, stderr, SubMonitor.convert(monitor)) != ICommandLauncher.OK) {
- errMsg = launcher.getErrorMessage();
- }
+ if (launcher.waitAndRead(stdout, stderr, SubMonitor.convert(monitor)) != ICommandLauncher.OK) {
+ errMsg = launcher.getErrorMessage();
+ }
- // There can be a problem looking at the process exit value,
- // so prevent an exception from occurring.
- if (errMsg == null || errMsg.length() == 0) {
- try {
- exitValue = proc.exitValue();
- } catch (IllegalThreadStateException e) {
+ // There can be a problem looking at the process exit value,
+ // so prevent an exception from occurring.
+ if (errMsg == null || errMsg.length() == 0) {
try {
- proc.waitFor();
- } catch (InterruptedException e1) {
- e1.printStackTrace();
+ exitValue = proc.exitValue();
+ } catch (IllegalThreadStateException e) {
+ try {
+ proc.waitFor();
+ } catch (InterruptedException e1) {
+ e1.printStackTrace();
+ }
+ exitValue = proc.exitValue();
}
- exitValue = proc.exitValue();
}
- }
- // Force a resync of the projects without allowing the user to
- // cancel.
- // This is probably unkind, but short of this there is no way to
- // ensure
- // the UI is up-to-date with the build results
- // monitor.subTask(ManagedMakeMessages
- // .getResourceString(REFRESH));
- monitor.subTask(AutotoolsPlugin.getResourceString("MakeGenerator.refresh")); //$NON-NLS-1$
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE, null);
- } catch (CoreException e) {
- monitor.subTask(AutotoolsPlugin
- .getResourceString("MakeGenerator.refresh.error")); //$NON-NLS-1$
+ // Force a resync of the projects without allowing the user
+ // to
+ // cancel.
+ // This is probably unkind, but short of this there is no
+ // way to
+ // ensure
+ // the UI is up-to-date with the build results
+ // monitor.subTask(ManagedMakeMessages
+ // .getResourceString(REFRESH));
+ monitor.subTask(AutotoolsPlugin.getResourceString("MakeGenerator.refresh")); //$NON-NLS-1$
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ monitor.subTask(AutotoolsPlugin.getResourceString("MakeGenerator.refresh.error")); //$NON-NLS-1$
+ }
+ } else {
+ errMsg = launcher.getErrorMessage();
}
- } else {
- errMsg = launcher.getErrorMessage();
- }
- // Report either the success or failure of our mission
- buf = new StringBuffer();
- if (errMsg != null && errMsg.length() > 0) {
- String errorDesc = AutotoolsPlugin
- .getResourceString("MakeGenerator.generation.error"); //$NON-NLS-1$
- buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
- buf.append(errorDesc);
- buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
- buf.append("(").append(errMsg).append(")"); //$NON-NLS-1$ //$NON-NLS-2$
- rc = IStatus.ERROR;
- } else if (exitValue >= 1 || exitValue < 0) {
- // We have an invalid return code from configuration.
- String[] errArg = new String[2];
- errArg[0] = Integer.toString(proc.exitValue());
- errArg[1] = commandPath.toString();
- errMsg = AutotoolsPlugin.getFormattedString(
- "MakeGenerator.config.error", errArg); //$NON-NLS-1$
- buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
- buf.append(AutotoolsPlugin.getResourceString("MakeGenerator.generation.error")); //$NON-NLS-1$
- buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
- if (proc.exitValue() == 1)
- rc = IStatus.WARNING;
- else
+ // Report either the success or failure of our mission
+ buf = new StringBuffer();
+ if (errMsg != null && errMsg.length() > 0) {
+ String errorDesc = AutotoolsPlugin.getResourceString("MakeGenerator.generation.error"); //$NON-NLS-1$
+ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
+ buf.append(errorDesc);
+ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
+ buf.append("(").append(errMsg).append(")"); //$NON-NLS-1$ //$NON-NLS-2$
rc = IStatus.ERROR;
- } else {
- // Report a successful build
- String successMsg =
- AutotoolsPlugin.getResourceString("MakeGenerator.success"); //$NON-NLS-1$
- buf.append(successMsg);
- buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
- rc = IStatus.OK;
+ } else if (exitValue >= 1 || exitValue < 0) {
+ // We have an invalid return code from configuration.
+ String[] errArg = new String[2];
+ errArg[0] = Integer.toString(proc.exitValue());
+ errArg[1] = commandPath.toString();
+ errMsg = AutotoolsPlugin.getFormattedString("MakeGenerator.config.error", errArg); //$NON-NLS-1$
+ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
+ buf.append(AutotoolsPlugin.getResourceString("MakeGenerator.generation.error")); //$NON-NLS-1$
+ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
+ if (proc.exitValue() == 1)
+ rc = IStatus.WARNING;
+ else
+ rc = IStatus.ERROR;
+ } else {
+ // Report a successful build
+ String successMsg = AutotoolsPlugin.getResourceString("MakeGenerator.success"); //$NON-NLS-1$
+ buf.append(successMsg);
+ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
+ rc = IStatus.OK;
+ }
}
// Write message on the console
@@ -1008,9 +1007,6 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
// .getResourceString(MARKERS));
// epm.reportProblems();
- } finally {
- if (epm != null)
- epm.close();
}
// If we have an error and no specific error markers, use the default error marker.
@@ -1176,7 +1172,6 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
"MakeGenerator.make.message", msgs)); //$NON-NLS-1$
- ErrorParserManager epm = null;
StringBuffer buf = new StringBuffer();
// Launch command - main invocation
@@ -1246,95 +1241,95 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
// Hook up an error parser manager
URI uri = URIUtil.toURI(runPath);
- epm = new ErrorParserManager(project, uri, this);
- epm.setOutputStream(consoleOutStream);
- epm.addErrorParser(ErrorParser.ID, new ErrorParser(getSourcePath(), getBuildPath()));
+ try (ErrorParserManager epm = new ErrorParserManager(project, uri, this)) {
+ epm.setOutputStream(consoleOutStream);
+ epm.addErrorParser(ErrorParser.ID, new ErrorParser(getSourcePath(), getBuildPath()));
- OutputStream stdout = epm.getOutputStream();
- OutputStream stderr = stdout;
+ OutputStream stdout = epm.getOutputStream();
+ OutputStream stderr = stdout;
- launcher.showCommand(true);
- // Run the shell script via shell command.
- Process proc = launcher.execute(new Path(SHELL_COMMAND), configTargets, env, runPath,
- SubMonitor.convert(monitor));
-
- int exitValue = 0;
- if (proc != null) {
- try {
- // Close the input of the process since we will never write to
- // it
- proc.getOutputStream().close();
- } catch (IOException e) {
- }
+ launcher.showCommand(true);
+ // Run the shell script via shell command.
+ Process proc = launcher.execute(new Path(SHELL_COMMAND), configTargets, env, runPath,
+ SubMonitor.convert(monitor));
- if (launcher.waitAndRead(stdout, stderr, SubMonitor.convert(monitor)) != ICommandLauncher.OK) {
- errMsg = launcher.getErrorMessage();
- }
-
- // There can be a problem looking at the process exit value,
- // so prevent an exception from occurring.
- if (errMsg == null || errMsg.length() == 0) {
+ int exitValue = 0;
+ if (proc != null) {
try {
- exitValue = proc.exitValue();
- } catch (IllegalThreadStateException e) {
+ // Close the input of the process since we will never
+ // write to
+ // it
+ proc.getOutputStream().close();
+ } catch (IOException e) {
+ }
+
+ if (launcher.waitAndRead(stdout, stderr, SubMonitor.convert(monitor)) != ICommandLauncher.OK) {
+ errMsg = launcher.getErrorMessage();
+ }
+
+ // There can be a problem looking at the process exit value,
+ // so prevent an exception from occurring.
+ if (errMsg == null || errMsg.length() == 0) {
try {
- proc.waitFor();
- } catch (InterruptedException e1) {
- e1.printStackTrace();
+ exitValue = proc.exitValue();
+ } catch (IllegalThreadStateException e) {
+ try {
+ proc.waitFor();
+ } catch (InterruptedException e1) {
+ e1.printStackTrace();
+ }
+ exitValue = proc.exitValue();
}
- exitValue = proc.exitValue();
}
- }
- // Force a resync of the projects without allowing the user to
- // cancel.
- // This is probably unkind, but short of this there is no way to
- // ensure
- // the UI is up-to-date with the build results
- // monitor.subTask(ManagedMakeMessages
- // .getResourceString(REFRESH));
- monitor.subTask(AutotoolsPlugin.getResourceString("MakeGenerator.refresh")); //$NON-NLS-1$
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE, null);
- } catch (CoreException e) {
- monitor.subTask(AutotoolsPlugin
- .getResourceString("MakeGenerator.refresh.error")); //$NON-NLS-1$
+ // Force a resync of the projects without allowing the user
+ // to
+ // cancel.
+ // This is probably unkind, but short of this there is no
+ // way to
+ // ensure
+ // the UI is up-to-date with the build results
+ // monitor.subTask(ManagedMakeMessages
+ // .getResourceString(REFRESH));
+ monitor.subTask(AutotoolsPlugin.getResourceString("MakeGenerator.refresh")); //$NON-NLS-1$
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ monitor.subTask(AutotoolsPlugin.getResourceString("MakeGenerator.refresh.error")); //$NON-NLS-1$
+ }
+ } else {
+ errMsg = launcher.getErrorMessage();
}
- } else {
- errMsg = launcher.getErrorMessage();
- }
- // Report either the success or failure of our mission
- buf = new StringBuffer();
- if (errMsg != null && errMsg.length() > 0) {
- String errorDesc = AutotoolsPlugin
- .getResourceString("MakeGenerator.generation.error"); //$NON-NLS-1$
- buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
- buf.append(errorDesc);
- buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
- buf.append("(").append(errMsg).append(")"); //$NON-NLS-1$ //$NON-NLS-2$
- rc = IStatus.ERROR;
- } else if (exitValue >= 1 || exitValue < 0) {
- // We have an invalid return code from configuration.
- String[] errArg = new String[2];
- errArg[0] = Integer.toString(proc.exitValue());
- errArg[1] = commandPath.toString();
- errMsg = AutotoolsPlugin.getFormattedString(
- "MakeGenerator.config.error", errArg); //$NON-NLS-1$
- buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
- buf.append(AutotoolsPlugin.getResourceString("MakeGenerator.generation.error")); //$NON-NLS-1$
- buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
- if (proc.exitValue() == 1)
- rc = IStatus.WARNING;
- else
+ // Report either the success or failure of our mission
+ buf = new StringBuffer();
+ if (errMsg != null && errMsg.length() > 0) {
+ String errorDesc = AutotoolsPlugin.getResourceString("MakeGenerator.generation.error"); //$NON-NLS-1$
+ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
+ buf.append(errorDesc);
+ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
+ buf.append("(").append(errMsg).append(")"); //$NON-NLS-1$ //$NON-NLS-2$
rc = IStatus.ERROR;
- } else {
- // Report a successful build
- String successMsg =
- AutotoolsPlugin.getResourceString("MakeGenerator.success"); //$NON-NLS-1$
- buf.append(successMsg);
- buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
- rc = IStatus.OK;
+ } else if (exitValue >= 1 || exitValue < 0) {
+ // We have an invalid return code from configuration.
+ String[] errArg = new String[2];
+ errArg[0] = Integer.toString(proc.exitValue());
+ errArg[1] = commandPath.toString();
+ errMsg = AutotoolsPlugin.getFormattedString("MakeGenerator.config.error", errArg); //$NON-NLS-1$
+ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
+ buf.append(AutotoolsPlugin.getResourceString("MakeGenerator.generation.error")); //$NON-NLS-1$
+ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
+ if (proc.exitValue() == 1)
+ rc = IStatus.WARNING;
+ else
+ rc = IStatus.ERROR;
+ } else {
+ // Report a successful build
+ String successMsg = AutotoolsPlugin.getResourceString("MakeGenerator.success"); //$NON-NLS-1$
+ buf.append(successMsg);
+ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
+ rc = IStatus.OK;
+ }
}
// Write message on the console
@@ -1345,9 +1340,6 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
// monitor.subTask(ManagedMakeMessages
// .getResourceString(MARKERS));
// epm.reportProblems();
- } finally {
- if (epm != null)
- epm.close();
}
// If we have an error and no specific error markers, use the default error marker.

Back to the top