1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 16:55:38 +02:00

autotools: Cosmetics

Try-with-resources for ErrorParserManager.

Change-Id: I5c36d3d68545cb50fcd416caefdc878212b57a88
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
This commit is contained in:
Alexander Kurtakov 2015-12-18 13:21:25 +02:00
parent e11035409f
commit 4f9dbedc0a

View file

@ -872,7 +872,6 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
"MakeGenerator.make.message", msgs)); //$NON-NLS-1$ "MakeGenerator.make.message", msgs)); //$NON-NLS-1$
ErrorParserManager epm = null;
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
// Launch command - main invocation // Launch command - main invocation
@ -911,7 +910,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
// Hook up an error parser manager // Hook up an error parser manager
URI uri = URIUtil.toURI(runPath); URI uri = URIUtil.toURI(runPath);
epm = new ErrorParserManager(project, uri, this); try (ErrorParserManager epm = new ErrorParserManager(project, uri, this)) {
epm.setOutputStream(consoleOutStream); epm.setOutputStream(consoleOutStream);
epm.addErrorParser(ErrorParser.ID, new ErrorParser(getSourcePath(), getBuildPath())); epm.addErrorParser(ErrorParser.ID, new ErrorParser(getSourcePath(), getBuildPath()));
@ -923,7 +922,8 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
int exitValue = 0; int exitValue = 0;
if (proc != null) { if (proc != null) {
try { try {
// Close the input of the process since we will never write to // Close the input of the process since we will never
// write to
// it // it
proc.getOutputStream().close(); proc.getOutputStream().close();
} catch (IOException e) { } catch (IOException e) {
@ -948,9 +948,11 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
} }
} }
// Force a resync of the projects without allowing the user to // Force a resync of the projects without allowing the user
// to
// cancel. // cancel.
// This is probably unkind, but short of this there is no way to // This is probably unkind, but short of this there is no
// way to
// ensure // ensure
// the UI is up-to-date with the build results // the UI is up-to-date with the build results
// monitor.subTask(ManagedMakeMessages // monitor.subTask(ManagedMakeMessages
@ -959,8 +961,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
try { try {
project.refreshLocal(IResource.DEPTH_INFINITE, null); project.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) { } catch (CoreException e) {
monitor.subTask(AutotoolsPlugin monitor.subTask(AutotoolsPlugin.getResourceString("MakeGenerator.refresh.error")); //$NON-NLS-1$
.getResourceString("MakeGenerator.refresh.error")); //$NON-NLS-1$
} }
} else { } else {
errMsg = launcher.getErrorMessage(); errMsg = launcher.getErrorMessage();
@ -969,8 +970,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
// Report either the success or failure of our mission // Report either the success or failure of our mission
buf = new StringBuffer(); buf = new StringBuffer();
if (errMsg != null && errMsg.length() > 0) { if (errMsg != null && errMsg.length() > 0) {
String errorDesc = AutotoolsPlugin String errorDesc = AutotoolsPlugin.getResourceString("MakeGenerator.generation.error"); //$NON-NLS-1$
.getResourceString("MakeGenerator.generation.error"); //$NON-NLS-1$
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
buf.append(errorDesc); buf.append(errorDesc);
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
@ -981,8 +981,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
String[] errArg = new String[2]; String[] errArg = new String[2];
errArg[0] = Integer.toString(proc.exitValue()); errArg[0] = Integer.toString(proc.exitValue());
errArg[1] = commandPath.toString(); errArg[1] = commandPath.toString();
errMsg = AutotoolsPlugin.getFormattedString( errMsg = AutotoolsPlugin.getFormattedString("MakeGenerator.config.error", errArg); //$NON-NLS-1$
"MakeGenerator.config.error", errArg); //$NON-NLS-1$
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$ 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(AutotoolsPlugin.getResourceString("MakeGenerator.generation.error")); //$NON-NLS-1$
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
@ -992,12 +991,12 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
rc = IStatus.ERROR; rc = IStatus.ERROR;
} else { } else {
// Report a successful build // Report a successful build
String successMsg = String successMsg = AutotoolsPlugin.getResourceString("MakeGenerator.success"); //$NON-NLS-1$
AutotoolsPlugin.getResourceString("MakeGenerator.success"); //$NON-NLS-1$
buf.append(successMsg); buf.append(successMsg);
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
rc = IStatus.OK; rc = IStatus.OK;
} }
}
// Write message on the console // Write message on the console
consoleOutStream.write(buf.toString().getBytes()); consoleOutStream.write(buf.toString().getBytes());
@ -1008,9 +1007,6 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
// .getResourceString(MARKERS)); // .getResourceString(MARKERS));
// epm.reportProblems(); // epm.reportProblems();
} finally {
if (epm != null)
epm.close();
} }
// If we have an error and no specific error markers, use the default error marker. // 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$ "MakeGenerator.make.message", msgs)); //$NON-NLS-1$
ErrorParserManager epm = null;
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
// Launch command - main invocation // Launch command - main invocation
@ -1246,7 +1241,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
// Hook up an error parser manager // Hook up an error parser manager
URI uri = URIUtil.toURI(runPath); URI uri = URIUtil.toURI(runPath);
epm = new ErrorParserManager(project, uri, this); try (ErrorParserManager epm = new ErrorParserManager(project, uri, this)) {
epm.setOutputStream(consoleOutStream); epm.setOutputStream(consoleOutStream);
epm.addErrorParser(ErrorParser.ID, new ErrorParser(getSourcePath(), getBuildPath())); epm.addErrorParser(ErrorParser.ID, new ErrorParser(getSourcePath(), getBuildPath()));
@ -1261,7 +1256,8 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
int exitValue = 0; int exitValue = 0;
if (proc != null) { if (proc != null) {
try { try {
// Close the input of the process since we will never write to // Close the input of the process since we will never
// write to
// it // it
proc.getOutputStream().close(); proc.getOutputStream().close();
} catch (IOException e) { } catch (IOException e) {
@ -1286,9 +1282,11 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
} }
} }
// Force a resync of the projects without allowing the user to // Force a resync of the projects without allowing the user
// to
// cancel. // cancel.
// This is probably unkind, but short of this there is no way to // This is probably unkind, but short of this there is no
// way to
// ensure // ensure
// the UI is up-to-date with the build results // the UI is up-to-date with the build results
// monitor.subTask(ManagedMakeMessages // monitor.subTask(ManagedMakeMessages
@ -1297,8 +1295,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
try { try {
project.refreshLocal(IResource.DEPTH_INFINITE, null); project.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) { } catch (CoreException e) {
monitor.subTask(AutotoolsPlugin monitor.subTask(AutotoolsPlugin.getResourceString("MakeGenerator.refresh.error")); //$NON-NLS-1$
.getResourceString("MakeGenerator.refresh.error")); //$NON-NLS-1$
} }
} else { } else {
errMsg = launcher.getErrorMessage(); errMsg = launcher.getErrorMessage();
@ -1307,8 +1304,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
// Report either the success or failure of our mission // Report either the success or failure of our mission
buf = new StringBuffer(); buf = new StringBuffer();
if (errMsg != null && errMsg.length() > 0) { if (errMsg != null && errMsg.length() > 0) {
String errorDesc = AutotoolsPlugin String errorDesc = AutotoolsPlugin.getResourceString("MakeGenerator.generation.error"); //$NON-NLS-1$
.getResourceString("MakeGenerator.generation.error"); //$NON-NLS-1$
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
buf.append(errorDesc); buf.append(errorDesc);
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
@ -1319,8 +1315,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
String[] errArg = new String[2]; String[] errArg = new String[2];
errArg[0] = Integer.toString(proc.exitValue()); errArg[0] = Integer.toString(proc.exitValue());
errArg[1] = commandPath.toString(); errArg[1] = commandPath.toString();
errMsg = AutotoolsPlugin.getFormattedString( errMsg = AutotoolsPlugin.getFormattedString("MakeGenerator.config.error", errArg); //$NON-NLS-1$
"MakeGenerator.config.error", errArg); //$NON-NLS-1$
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$ 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(AutotoolsPlugin.getResourceString("MakeGenerator.generation.error")); //$NON-NLS-1$
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
@ -1330,12 +1325,12 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
rc = IStatus.ERROR; rc = IStatus.ERROR;
} else { } else {
// Report a successful build // Report a successful build
String successMsg = String successMsg = AutotoolsPlugin.getResourceString("MakeGenerator.success"); //$NON-NLS-1$
AutotoolsPlugin.getResourceString("MakeGenerator.success"); //$NON-NLS-1$
buf.append(successMsg); buf.append(successMsg);
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
rc = IStatus.OK; rc = IStatus.OK;
} }
}
// Write message on the console // Write message on the console
consoleOutStream.write(buf.toString().getBytes()); consoleOutStream.write(buf.toString().getBytes());
@ -1345,9 +1340,6 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
// monitor.subTask(ManagedMakeMessages // monitor.subTask(ManagedMakeMessages
// .getResourceString(MARKERS)); // .getResourceString(MARKERS));
// epm.reportProblems(); // epm.reportProblems();
} finally {
if (epm != null)
epm.close();
} }
// If we have an error and no specific error markers, use the default error marker. // If we have an error and no specific error markers, use the default error marker.