Skip to content

Commit 16215b5

Browse files
eclipse-platform-botakurtakov
authored andcommitted
Perform clean code of ant/org.eclipse.ant.launching
1 parent 917ba29 commit 16215b5

File tree

8 files changed

+37
-54
lines changed

8 files changed

+37
-54
lines changed

ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/InputHandlerSetter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ protected void setInputHandler(Project project, String inputHandlerClassname) {
3535
handler = (InputHandler) (Class.forName(inputHandlerClassname).getConstructor().newInstance());
3636
}
3737
catch (ClassCastException e) {
38-
String msg = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.The_specified_input_handler_class_{0}_does_not_implement_the_org.apache.tools.ant.input.InputHandler_interface_5"), new Object[] { //$NON-NLS-1$
39-
inputHandlerClassname });
38+
String msg = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.The_specified_input_handler_class_{0}_does_not_implement_the_org.apache.tools.ant.input.InputHandler_interface_5"), inputHandlerClassname);
4039
throw new BuildException(msg, e);
4140
}
4241
catch (Exception e) {
43-
String msg = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Unable_to_instantiate_specified_input_handler_class_{0}___{1}_6"), new Object[] { //$NON-NLS-1$
44-
inputHandlerClassname, e.getClass().getName() });
42+
String msg = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Unable_to_instantiate_specified_input_handler_class_{0}___{1}_6"), inputHandlerClassname, e.getClass().getName());
4543
throw new BuildException(msg, e);
4644
}
4745
}

ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/InternalAntRunner.java

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ private void addBuildListeners(Project project) {
192192
}
193193
}
194194
catch (ClassCastException e) {
195-
String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.{0}_which_was_specified_to_be_a_build_listener_is_not_an_instance_of_org.apache.tools.ant.BuildListener._1"), new Object[] { //$NON-NLS-1$
196-
clazz });
195+
String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.{0}_which_was_specified_to_be_a_build_listener_is_not_an_instance_of_org.apache.tools.ant.BuildListener._1"), clazz);
197196
logMessage(null, message, Project.MSG_ERR);
198197
throw new BuildException(message, e);
199198
}
@@ -215,11 +214,11 @@ private void parseBuildFile(Project project) {
215214
File buildFile = new File(getBuildFileLocation());
216215
if (!buildFile.exists()) {
217216
throw new BuildException(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Buildfile__{0}_does_not_exist_!_1"), //$NON-NLS-1$
218-
new Object[] { buildFile.getAbsolutePath() }));
217+
buildFile.getAbsolutePath()));
219218
}
220219
if (!buildFile.isFile()) {
221220
throw new BuildException(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Buildfile__{0}_is_not_a_file_1"), //$NON-NLS-1$
222-
new Object[] { buildFile.getAbsolutePath() }));
221+
buildFile.getAbsolutePath()));
223222
}
224223

225224
if (!isVersionCompatible("1.5")) { //$NON-NLS-1$
@@ -248,7 +247,7 @@ private void printArguments(Project project) {
248247
sb.append(extraArgument);
249248
sb.append(' ');
250249
}
251-
project.log(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Arguments__{0}_2"), new Object[] { sb.toString().trim() })); //$NON-NLS-1$
250+
project.log(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Arguments__{0}_2"), sb.toString().trim())); //$NON-NLS-1$
252251
}
253252

254253
/**
@@ -433,8 +432,7 @@ private void run(List<String> argList) {
433432
}
434433
}
435434

436-
getCurrentProject().log(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Build_file__{0}_1"), new Object[] { //$NON-NLS-1$
437-
getBuildFileLocation() }));
435+
getCurrentProject().log(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Build_file__{0}_1"), getBuildFileLocation()));
438436

439437
setTasks();
440438
setTypes();
@@ -523,8 +521,8 @@ private void setTasks() {
523521
getCurrentProject().addTaskDefinition(taskName, taskClass);
524522
}
525523
catch (ClassNotFoundException e) {
526-
String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.161"), new Object[] { taskClassName, //$NON-NLS-1$
527-
taskName });
524+
String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.161"), taskClassName, //$NON-NLS-1$
525+
taskName);
528526
getCurrentProject().log(message, Project.MSG_WARN);
529527
}
530528
}
@@ -551,8 +549,8 @@ private void setTypes() {
551549
getCurrentProject().addDataTypeDefinition(typeName, typeClass);
552550
}
553551
catch (ClassNotFoundException e) {
554-
String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.162"), new Object[] { typeClassName, //$NON-NLS-1$
555-
typeName });
552+
String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.162"), typeClassName, //$NON-NLS-1$
553+
typeName);
556554
getCurrentProject().log(message, Project.MSG_WARN);
557555
}
558556
}
@@ -581,14 +579,12 @@ private BuildLogger createLogger() {
581579
buildLogger = (BuildLogger) (Class.forName(loggerClassname).getConstructor().newInstance());
582580
}
583581
catch (ClassCastException e) {
584-
String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.{0}_which_was_specified_to_perform_logging_is_not_an_instance_of_org.apache.tools.ant.BuildLogger._2"), new Object[] { //$NON-NLS-1$
585-
loggerClassname });
582+
String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.{0}_which_was_specified_to_perform_logging_is_not_an_instance_of_org.apache.tools.ant.BuildLogger._2"), loggerClassname);
586583
logMessage(null, message, Project.MSG_ERR);
587584
throw new BuildException(message, e);
588585
}
589586
catch (Exception e) {
590-
String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Unable_to_instantiate_logger__{0}_6"), new Object[] { //$NON-NLS-1$
591-
loggerClassname });
587+
String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Unable_to_instantiate_logger__{0}_6"), loggerClassname);
592588
logMessage(null, message, Project.MSG_ERR);
593589
throw new BuildException(message, e);
594590
}
@@ -688,8 +684,7 @@ private String getAntVersionNumber() throws BuildException {
688684
antVersionNumber = versionNumber;
689685
}
690686
catch (IOException ioe) {
691-
throw new BuildException(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Could_not_load_the_version_information._{0}_9"), new Object[] { //$NON-NLS-1$
692-
ioe.getMessage() }), ioe);
687+
throw new BuildException(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Could_not_load_the_version_information._{0}_9"), ioe.getMessage()), ioe);
693688
}
694689
catch (NullPointerException npe) {
695690
throw new BuildException(RemoteAntMessages.getString("InternalAntRunner.Could_not_load_the_version_information._10"), npe); //$NON-NLS-1$
@@ -900,8 +895,7 @@ private boolean processCommandLine(List<String> commands) {
900895
}
901896
catch (IOException e) {
902897
// just log message and ignore exception
903-
logMessage(getCurrentProject(), MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Could_not_write_to_the_specified_log_file__{0}._Make_sure_the_path_exists_and_you_have_write_permissions._2"), new Object[] { //$NON-NLS-1$
904-
arg }), Project.MSG_ERR);
898+
logMessage(getCurrentProject(), MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Could_not_write_to_the_specified_log_file__{0}._Make_sure_the_path_exists_and_you_have_write_permissions._2"), arg), Project.MSG_ERR);
905899
return false;
906900
}
907901

@@ -1017,8 +1011,7 @@ private void processUnrecognizedCommands(List<String> commands) {
10171011
}
10181012

10191013
// warn of ignored commands
1020-
String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Unknown_argument__{0}_2"), new Object[] { //$NON-NLS-1$
1021-
s.substring(1) });
1014+
String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Unknown_argument__{0}_2"), s.substring(1));
10221015
logMessage(currentProject, message, Project.MSG_WARN);
10231016
}
10241017

@@ -1044,8 +1037,7 @@ private void createLogFile(String fileName) throws FileNotFoundException, IOExce
10441037
// this stream is closed in the finally block of run(list)
10451038
out = new PrintStream(new FileOutputStream(logFile));
10461039
err = out;
1047-
logMessage(getCurrentProject(), MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Using_{0}_file_as_build_log._1"), new Object[] { //$NON-NLS-1$
1048-
logFile.getCanonicalPath() }), Project.MSG_INFO);
1040+
logMessage(getCurrentProject(), MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Using_{0}_file_as_build_log._1"), logFile.getCanonicalPath()), Project.MSG_INFO);
10491041
if (buildLogger != null) {
10501042
buildLogger.setErrorPrintStream(err);
10511043
buildLogger.setOutputPrintStream(out);
@@ -1132,8 +1124,9 @@ private void setProperties(Project project) {
11321124
setBuiltInProperties(project);
11331125
if (userProperties != null) {
11341126
for (Entry<String, String> entry : userProperties.entrySet()) {
1135-
if (entry.getValue() != null)
1127+
if (entry.getValue() != null) {
11361128
project.setUserProperty(entry.getKey(), entry.getValue());
1129+
}
11371130
}
11381131
}
11391132
}
@@ -1294,8 +1287,7 @@ private void loadPropertyFiles() {
12941287
props.load(fis);
12951288
}
12961289
catch (IOException e) {
1297-
fEarlyErrorMessage = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Could_not_load_property_file_{0}__{1}_4"), new Object[] { //$NON-NLS-1$
1298-
filename, e.getMessage() });
1290+
fEarlyErrorMessage = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Could_not_load_property_file_{0}__{1}_4"), filename, e.getMessage());
12991291
}
13001292
if (userProperties == null) {
13011293
userProperties = new HashMap<>();

ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/logger/RemoteAntBreakpoint.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ public String toMarshallString() {
4747

4848
@Override
4949
public boolean equals(Object obj) {
50-
if (!(obj instanceof RemoteAntBreakpoint)) {
50+
if (!(obj instanceof RemoteAntBreakpoint other)) {
5151
return false;
5252
}
53-
RemoteAntBreakpoint other = (RemoteAntBreakpoint) obj;
5453
return other.getLineNumber() == fLineNumber && other.getFile().equals(fFile);
5554
}
5655

ant/org.eclipse.ant.launching/src/org/eclipse/ant/internal/launching/AntLaunchingUtil.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ private AntLaunchingUtil() {
7373
* @return a single-string representation of the strings or <code>null</code> if the array is empty.
7474
*/
7575
public static String combineStrings(String[] strings) {
76-
if (strings.length == 0)
76+
if (strings.length == 0) {
7777
return null;
78+
}
7879

79-
if (strings.length == 1)
80+
if (strings.length == 1) {
8081
return strings[0];
82+
}
8183

8284
StringBuilder buf = new StringBuilder();
8385
for (int i = 0; i < strings.length - 1; i++) {
@@ -231,7 +233,7 @@ public static URL[] getCustomClasspath(ILaunchConfiguration config) throws CoreE
231233
private static String expandVariableString(String variableString, String invalidMessage) throws CoreException {
232234
String expandedString = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(variableString);
233235
if (expandedString == null || expandedString.length() == 0) {
234-
String msg = MessageFormat.format(invalidMessage, new Object[] { variableString });
236+
String msg = MessageFormat.format(invalidMessage, variableString);
235237
throw new CoreException(new Status(IStatus.ERROR, AntLaunching.PLUGIN_ID, 0, msg, null));
236238
}
237239
return expandedString;

ant/org.eclipse.ant.launching/src/org/eclipse/ant/internal/launching/debug/model/AntLineBreakpoint.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ public AntLineBreakpoint(final IResource resource, final int lineNumber, final M
7676
attributes.put(IBreakpoint.ENABLED, Boolean.TRUE);
7777
attributes.put(IMarker.LINE_NUMBER, Integer.valueOf(lineNumber));
7878
attributes.put(IBreakpoint.ID, IAntDebugConstants.ID_ANT_DEBUG_MODEL);
79-
attributes.put(IMarker.MESSAGE, MessageFormat.format(DebugModelMessages.AntLineBreakpoint_0, new Object[] {
80-
Integer.toString(lineNumber) }));
79+
attributes.put(IMarker.MESSAGE, MessageFormat.format(DebugModelMessages.AntLineBreakpoint_0, Integer.toString(lineNumber)));
8180
ensureMarker().setAttributes(attributes);
8281

8382
register(register);

ant/org.eclipse.ant.launching/src/org/eclipse/ant/internal/launching/debug/model/AntStackFrame.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ public String getSourceName() {
206206

207207
@Override
208208
public boolean equals(Object obj) {
209-
if (obj instanceof AntStackFrame) {
210-
AntStackFrame sf = (AntStackFrame) obj;
209+
if (obj instanceof AntStackFrame sf) {
211210
if (getSourceName() != null) {
212211
return getSourceName().equals(sf.getSourceName()) && sf.getLineNumber() == getLineNumber() && sf.fId == fId;
213212
}

ant/org.eclipse.ant.launching/src/org/eclipse/ant/internal/launching/launchConfigurations/AntHomeClasspathEntry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ public File resolveAntHome() throws CoreException {
119119
File lib = libDir.toFile();
120120
File parentDir = lib.getParentFile();
121121
if (parentDir == null || !parentDir.exists()) {
122-
abort(MessageFormat.format(AntLaunchConfigurationMessages.AntHomeClasspathEntry_10, new Object[] { antHomeLocation }), null);
122+
abort(MessageFormat.format(AntLaunchConfigurationMessages.AntHomeClasspathEntry_10, antHomeLocation), null);
123123
}
124124
if (!lib.exists() || !lib.isDirectory()) {
125-
abort(MessageFormat.format(AntLaunchConfigurationMessages.AntHomeClasspathEntry_11, new Object[] { antHomeLocation }), null);
125+
abort(MessageFormat.format(AntLaunchConfigurationMessages.AntHomeClasspathEntry_11, antHomeLocation), null);
126126
}
127127
return lib;
128128
}
@@ -138,7 +138,7 @@ public String getName() {
138138
if (antHomeLocation == null) {
139139
return AntLaunchConfigurationMessages.AntHomeClasspathEntry_8;
140140
}
141-
return MessageFormat.format(AntLaunchConfigurationMessages.AntHomeClasspathEntry_9, new Object[] { antHomeLocation });
141+
return MessageFormat.format(AntLaunchConfigurationMessages.AntHomeClasspathEntry_9, antHomeLocation);
142142
}
143143

144144
@Override

ant/org.eclipse.ant.launching/src/org/eclipse/ant/internal/launching/launchConfigurations/AntLaunchDelegate.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
124124
if (!path.isEmpty()) {
125125
IPath jrePath = IPath.fromPortableString(path);
126126
IVMInstall vm = JavaRuntime.getVMInstall(jrePath);
127-
if (vm instanceof AbstractVMInstall) {
128-
AbstractVMInstall install = (AbstractVMInstall) vm;
127+
if (vm instanceof AbstractVMInstall install) {
129128
vmver = install.getJavaVersion();
130129
// versionToJdkLevel only handles 3 char versions = 1.5, 1.6, 1.9, etc
131130
if (vmver.length() > 3) {
@@ -143,8 +142,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
143142
}
144143
if (vmver == null) {
145144
IVMInstall vm = JavaRuntime.getDefaultVMInstall();
146-
if (vm instanceof AbstractVMInstall) {
147-
AbstractVMInstall install = (AbstractVMInstall) vm;
145+
if (vm instanceof AbstractVMInstall install) {
148146
vmver = install.getJavaVersion();
149147
}
150148

@@ -162,11 +160,9 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
162160
boolean isSeparateJRE = AntLaunchingUtil.isSeparateJREAntBuild(configuration);
163161

164162
if (AntLaunchingUtil.isLaunchInBackground(configuration)) {
165-
monitor.beginTask(MessageFormat.format(AntLaunchConfigurationMessages.AntLaunchDelegate_Launching__0__1, new Object[] {
166-
configuration.getName() }), 10);
163+
monitor.beginTask(MessageFormat.format(AntLaunchConfigurationMessages.AntLaunchDelegate_Launching__0__1, configuration.getName()), 10);
167164
} else {
168-
monitor.beginTask(MessageFormat.format(AntLaunchConfigurationMessages.AntLaunchDelegate_Running__0__2, new Object[] {
169-
configuration.getName() }), 100);
165+
monitor.beginTask(MessageFormat.format(AntLaunchConfigurationMessages.AntLaunchDelegate_Running__0__2, configuration.getName()), 100);
170166
}
171167

172168
// resolve location
@@ -178,8 +174,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
178174
}
179175

180176
if (!isSeparateJRE && AntRunner.isBuildRunning()) {
181-
IStatus status = new Status(IStatus.ERROR, AntLaunching.PLUGIN_ID, 1, MessageFormat.format(AntLaunchConfigurationMessages.AntLaunchDelegate_Build_In_Progress, new Object[] {
182-
location.toOSString() }), null);
177+
IStatus status = new Status(IStatus.ERROR, AntLaunching.PLUGIN_ID, 1, MessageFormat.format(AntLaunchConfigurationMessages.AntLaunchDelegate_Build_In_Progress, location.toOSString()), null);
183178
throw new CoreException(status);
184179
}
185180

@@ -255,8 +250,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
255250
StringBuffer commandLine = generateCommandLine(location, arguments, userProperties, propertyFiles, targets, antHome, basedir, isSeparateJRE, captureOutput, setInputHandler, vmver);
256251

257252
if (isSeparateJRE) {
258-
monitor.beginTask(MessageFormat.format(AntLaunchConfigurationMessages.AntLaunchDelegate_Launching__0__1, new Object[] {
259-
configuration.getName() }), 10);
253+
monitor.beginTask(MessageFormat.format(AntLaunchConfigurationMessages.AntLaunchDelegate_Launching__0__1, configuration.getName()), 10);
260254
runInSeparateVM(configuration, launch, monitor, idStamp, antHome, port, requestPort, commandLine, captureOutput, setInputHandler);
261255
} else {
262256
runInSameVM(configuration, launch, monitor, location, idStamp, runner, commandLine);

0 commit comments

Comments
 (0)