Skip to content

Commit 809af92

Browse files
committed
Use System.lineSeparator()
System.getProperty("line.separator") involves SecurityManager checks (depending on JVM used), key validity check and Properties retrieval while lineSeparator() returns the value used to populate the properties with directly.
1 parent 0dfe86c commit 809af92

File tree

22 files changed

+89
-90
lines changed

22 files changed

+89
-90
lines changed

ant/org.eclipse.ant.launching/loggers/org/eclipse/ant/internal/launching/runtime/logger/AntProcessBuildLogger.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2013 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -63,7 +63,7 @@ protected void logMessage(String message, BuildEvent event, int overridePriority
6363

6464
StringBuffer fullMessage = new StringBuffer();
6565
if (!loggingToLogFile()) {
66-
fullMessage.append(System.getProperty("line.separator")); //$NON-NLS-1$
66+
fullMessage.append(System.lineSeparator());
6767
}
6868
if (event.getException() == null && event.getTask() != null && !fEmacsMode) {
6969
adornMessage(event, fullMessage);
@@ -117,7 +117,7 @@ private void adornMessage(BuildEvent event, StringBuffer fullMessage) {
117117
appendAndLink(fullMessage, location, label, offset, line);
118118
line = r.readLine();
119119
while (line != null) {
120-
fullMessage.append(System.getProperty("line.separator")); //$NON-NLS-1$
120+
fullMessage.append(System.lineSeparator());
121121
fullMessage.append(column);
122122
appendAndLink(fullMessage, location, label, offset, line);
123123
line = r.readLine();
@@ -262,7 +262,7 @@ private String getTimeString(long milliseconds) {
262262
result.append(RuntimeMessages.AntProcessBuildLogger__milliseconds_6);
263263
}
264264

265-
result.append(System.getProperty("line.separator")); //$NON-NLS-1$
265+
result.append(System.lineSeparator());
266266
return result.toString();
267267
}
268268

@@ -282,7 +282,7 @@ public void targetStarted(BuildEvent event) {
282282
return;
283283
}
284284
Target target = event.getTarget();
285-
StringBuilder msg = new StringBuilder(System.getProperty("line.separator")); //$NON-NLS-1$
285+
StringBuilder msg = new StringBuilder(System.lineSeparator());
286286
String targetName = target.getName();
287287
msg.append(targetName);
288288
msg.append(':');

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2023 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
* Portions Copyright 2000-2005 The Apache Software Foundation
44
*
55
* This program and the accompanying materials are made
@@ -328,7 +328,7 @@ private void printTargets(Project project) {
328328
*/
329329
private void printTargets(Project project, List<String> names, List<String> descriptions, String heading, int maxlen) {
330330
// now, start printing the targets and their descriptions
331-
String lSep = System.getProperty("line.separator"); //$NON-NLS-1$
331+
String lSep = System.lineSeparator();
332332

333333
String spaces = " "; //$NON-NLS-1$
334334
while (spaces.length() < maxlen) {
@@ -1164,7 +1164,7 @@ private void printVersion() {
11641164
* Logs a message with the client outlining the usage of <b>Ant</b>.
11651165
*/
11661166
private void printUsage() {
1167-
String lSep = System.getProperty("line.separator"); //$NON-NLS-1$
1167+
String lSep = System.lineSeparator();
11681168
StringBuilder msg = new StringBuilder();
11691169
msg.append("ant ["); //$NON-NLS-1$
11701170
msg.append(RemoteAntMessages.getString("InternalAntRunner.options_13")); //$NON-NLS-1$

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2003, 2016 IBM Corporation and others.
2+
* Copyright (c) 2003, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -192,7 +192,7 @@ protected void receiveMessage(String message) {
192192
if (index > 0) {
193193
int priority = Integer.parseInt(message.substring(0, index));
194194
String msg = message.substring(index + 1);
195-
writeMessage(msg + System.getProperty("line.separator"), priority); //$NON-NLS-1$
195+
writeMessage(msg + System.lineSeparator(), priority);
196196
if (msg.startsWith("BUILD FAILED")) { //$NON-NLS-1$
197197
fBuildFailed = true;
198198
} else if (fBuildFailed) {
@@ -222,7 +222,7 @@ private void receiveTargetMessage(String message) {
222222
int lineNumber = Integer.parseInt(tokenizer.nextToken());
223223
generateLink(msg, location, lineNumber, 0, msg.length() - 1);
224224
}
225-
writeMessage(msg + System.getProperty("line.separator"), Project.MSG_INFO); //$NON-NLS-1$
225+
writeMessage(msg + System.lineSeparator(), Project.MSG_INFO);
226226
}
227227

228228
private void receiveTaskMessage(String message) {
@@ -269,7 +269,7 @@ private void receiveTaskMessage(String message) {
269269

270270
StringBuffer fullMessage = new StringBuffer();
271271
adornMessage(taskName, line, fullMessage);
272-
writeMessage(fullMessage.append(System.getProperty("line.separator")).toString(), priority); //$NON-NLS-1$
272+
writeMessage(fullMessage.append(System.lineSeparator()).toString(), priority);
273273
}
274274

275275
private void generateLink(String line, String fileName, int lineNumber, int offset, int length) {

ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/XmlDocumentFormatterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2004, 2005 John-Mason P. Shackelford and others.
2+
* Copyright (c) 2004, 2025 John-Mason P. Shackelford and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -93,7 +93,7 @@ public boolean useSpacesInsteadOfTabs() {
9393
private void simpleTest(String sourceFileName, String targetFileName, FormattingPreferences prefs) throws Exception {
9494

9595
XmlDocumentFormatter xmlFormatter = new XmlDocumentFormatter();
96-
xmlFormatter.setDefaultLineDelimiter(System.getProperty("line.separator")); //$NON-NLS-1$
96+
xmlFormatter.setDefaultLineDelimiter(System.lineSeparator());
9797
String result = xmlFormatter.format(Files.readString(getBuildFile(sourceFileName).toPath()), prefs);
9898
String expectedResult = Files.readString(getBuildFile(targetFileName).toPath());
9999

ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/XmlFormatterTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*******************************************************************************
2-
* Copyright (c) 2004, 2013 John-Mason P. Shackelford and others.
2+
* Copyright (c) 2004, 2025 John-Mason P. Shackelford and others.
33
*
4-
* This program and the accompanying materials
4+
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
66
* which accompanies this distribution, and is available at
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10-
*
10+
*
1111
* Contributors:
1212
* John-Mason P. Shackelford - initial API and implementation
1313
* IBM Corporation - bug 84342
@@ -37,7 +37,7 @@ public final void testFormatUsingPreferenceStore() throws Exception {
3737
node.putInt(AntEditorPreferenceConstants.FORMATTER_TAB_SIZE, 4);
3838
node.flush();
3939
}
40-
String lineSep = System.getProperty("line.separator"); //$NON-NLS-1$
40+
String lineSep = System.lineSeparator();
4141
String xmlDoc = "<project default=\"go\"><target name=\"go\" description=\"Demonstrate the wrapping of long tags.\"><echo>hi</echo></target></project>"; //$NON-NLS-1$
4242
String formattedDoc = XmlFormatter.format(xmlDoc);
4343
String expected = "<project default=\"go\">" + lineSep + "\t<target name=\"go\"" + lineSep //$NON-NLS-1$ //$NON-NLS-2$
@@ -74,7 +74,7 @@ public int getTabWidth() {
7474
return 6;
7575
}
7676
};
77-
String lineSep = System.getProperty("line.separator"); //$NON-NLS-1$
77+
String lineSep = System.lineSeparator();
7878
String xmlDoc = "<project default=\"go\"><target name=\"go\" description=\"Demonstrate the wrapping of long tags.\"><echo>hi</echo></target></project>"; //$NON-NLS-1$
7979
String formattedDoc = XmlFormatter.format(xmlDoc, prefs);
8080
String expected = "<project default=\"go\">" + lineSep + " <target name=\"go\"" + lineSep //$NON-NLS-1$ //$NON-NLS-2$
@@ -114,7 +114,7 @@ public int getTabWidth() {
114114
return 6;
115115
}
116116
};
117-
String lineSep = System.getProperty("line.separator"); //$NON-NLS-1$
117+
String lineSep = System.lineSeparator();
118118
String xmlDoc = "<project default=\"go\"><target name=\"go\" description=\"Demonstrate the wrapping of long tags.\"><echo>hi</echo></target>" //$NON-NLS-1$
119119
+ lineSep + lineSep + "</project>"; //$NON-NLS-1$
120120
String formattedDoc = XmlFormatter.format(xmlDoc, prefs);

ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/XmlTagFormatterTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*******************************************************************************
2-
* Copyright (c) 2004, 2013 John-Mason P. Shackelford and others.
2+
* Copyright (c) 2004, 2025 John-Mason P. Shackelford and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
66
* which accompanies this distribution, and is available at
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10-
*
10+
*
1111
* Contributors:
1212
* John-Mason P. Shackelford - initial API and implementation
1313
* IBM Corporation - Bug 84342
@@ -192,7 +192,7 @@ public void testParserGetAttributes() throws Exception {
192192

193193
@Test
194194
public void testFormat01() throws Exception {
195-
String lineSep = System.getProperty("line.separator"); //$NON-NLS-1$
195+
String lineSep = System.lineSeparator();
196196
String indent = "\t"; //$NON-NLS-1$
197197
String source = "<target name=\"myTargetName\" depends=\"a,b,c,d,e,f,g\" description=\"This is a very long element which ought to be wrapped.\">"; //$NON-NLS-1$
198198
String target = "<target name=\"myTargetName\"" + lineSep //$NON-NLS-1$
@@ -204,7 +204,7 @@ public void testFormat01() throws Exception {
204204

205205
@Test
206206
public void testFormat02() throws Exception {
207-
String lineSep = System.getProperty("line.separator"); //$NON-NLS-1$
207+
String lineSep = System.lineSeparator();
208208
String indent = "\t"; //$NON-NLS-1$
209209
String source = "<target name=\"myTargetName\" depends=\"a,b,c,d,e,f,g\" description=\"This is a very long element which ought to be wrapped.\">"; //$NON-NLS-1$
210210
String target = "<target name=\"myTargetName\"" + lineSep //$NON-NLS-1$
@@ -217,7 +217,7 @@ public void testFormat02() throws Exception {
217217

218218
@Test
219219
public void testBug73411() throws Exception {
220-
String lineSep = System.getProperty("line.separator"); //$NON-NLS-1$
220+
String lineSep = System.lineSeparator();
221221
String indent = "\t"; //$NON-NLS-1$
222222
String source = "<target name='myTargetName' depends=\"a,b,c,d,e,f,g\" description=\'This is a very long element which ought to be \"wrapped\".'>"; //$NON-NLS-1$
223223
String target = "<target name='myTargetName'" + lineSep //$NON-NLS-1$
@@ -307,7 +307,7 @@ public boolean alignElementCloseChar() {
307307

308308
tag.setClosed(true);
309309

310-
String lineSep = System.getProperty("line.separator"); //$NON-NLS-1$
310+
String lineSep = System.lineSeparator();
311311
assertEquals("<myElement attribute1=\"value1\"" + lineSep //$NON-NLS-1$
312312
+ "\t\t attribute2=\"value2\" />", //$NON-NLS-1$
313313
tagFormatter.wrapTag(tag, dontAlignCloseChar, "\t\t ", lineSep)); //$NON-NLS-1$
@@ -334,7 +334,7 @@ public void testBug63558() throws Exception {
334334
// Ordinarily the double space after the element name would be repaired
335335
// but if the formatter is working correctly these examples will be
336336
// considered malformed and will be passed through untouched.
337-
String lineSep = System.getProperty("line.separator"); //$NON-NLS-1$
337+
String lineSep = System.lineSeparator();
338338
String source1 = "<echo file=\"foo\">" + lineSep + "&lt;html>&lt;body>&lt;pre>" //$NON-NLS-1$ //$NON-NLS-2$
339339
+ "${compilelog}&lt;/pre>&lt;/body>&lt;/html>"; //$NON-NLS-1$
340340
FormattingPreferences prefs = getPreferences(true, false, 60);

ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AbstractAntUITest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2003, 2021 IBM Corporation and others.
2+
* Copyright (c) 2003, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -285,7 +285,7 @@ protected String getReaderContentAsString(BufferedReader bufferedReader) {
285285

286286
while (line != null) {
287287
if (result.length() != 0) {
288-
result.append(System.getProperty("line.separator")); //$NON-NLS-1$
288+
result.append(System.lineSeparator());
289289
}
290290
result.append(line);
291291
line = bufferedReader.readLine();

ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/ExportUtil.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*******************************************************************************
2-
* Copyright (c) 2004, 2017 Richard Hoefter and others.
2+
* Copyright (c) 2004, 2025 Richard Hoefter and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
66
* which accompanies this distribution, and is available at
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10-
*
10+
*
1111
* Contributors:
12-
* Richard Hoefter ([email protected]) - initial API and implementation, bug 95300, bug 95297, bug 128104, bug 201180, bug 288830
13-
* IBM Corporation - NLS'ing and incorporating into Eclipse.
14-
* - Bug 177833 Class created from combination of all utility classes of contribution
12+
* Richard Hoefter ([email protected]) - initial API and implementation, bug 95300, bug 95297, bug 128104, bug 201180, bug 288830
13+
* IBM Corporation - NLS'ing and incorporating into Eclipse.
14+
* - Bug 177833 Class created from combination of all utility classes of contribution
1515
* - Bug 267459 Java project with an external jar file from C:\ on the build path throws a NPE during the Ant Buildfile generation.
1616
* - bug fixing
1717
*******************************************************************************/
@@ -134,7 +134,7 @@ public static String getProjectRoot(IJavaProject project) {
134134

135135
/**
136136
* Convert Eclipse path to absolute filename.
137-
*
137+
*
138138
* @param file
139139
* Project root optionally followed by resource name. An absolute path is simply converted to a string.
140140
* @return full qualified path
@@ -192,7 +192,7 @@ public static String removeProjectRoot(String file, IProject project) {
192192

193193
/**
194194
* Remove project root from given project file.
195-
*
195+
*
196196
* @param newProjectRoot
197197
* replace project root, e.g. with a variable ${project.location}
198198
*/
@@ -213,7 +213,7 @@ public static String replaceProjectRoot(String file, IProject project, String ne
213213

214214
/**
215215
* Get for given project all directly dependent projects.
216-
*
216+
*
217217
* @return set of IJavaProject objects
218218
*/
219219
public static List<IJavaProject> getClasspathProjects(IJavaProject project) throws JavaModelException {
@@ -239,7 +239,7 @@ private static void addClasspathProjects(List<IJavaProject> projects, IClasspath
239239

240240
/**
241241
* Get for given project all directly and indirectly dependent projects.
242-
*
242+
*
243243
* @return set of IJavaProject objects
244244
*/
245245
public static List<IJavaProject> getClasspathProjectsRecursive(IJavaProject project) throws JavaModelException {
@@ -259,7 +259,7 @@ private static void getClasspathProjectsRecursive(IJavaProject project, LinkedLi
259259

260260
/**
261261
* Sort projects according to General -&gt; Workspace -&gt; Build Order.
262-
*
262+
*
263263
* @param javaProjects
264264
* list of IJavaProject objects
265265
* @return list of IJavaProject objects with new order
@@ -303,10 +303,10 @@ private static List<IJavaProject> sortProjectsUsingBuildOrder(List<IJavaProject>
303303

304304
/**
305305
* Returns cyclic dependency marker for a given project.
306-
*
306+
*
307307
* <p>
308308
* See org.eclipse.jdt.core.tests.model.ClasspathTests.numberOfCycleMarkers.
309-
*
309+
*
310310
* @param javaProject
311311
* project for which cyclic dependency marker should be found
312312
* @return cyclic dependency marker for a given project or <code>null</code> if there is no such marker
@@ -324,7 +324,7 @@ public static IMarker getCyclicDependencyMarker(IJavaProject javaProject) throws
324324

325325
/**
326326
* Find JUnit tests. Same tests are also returned by Eclipse run configuration wizard.
327-
*
327+
*
328328
* @param containerHandle
329329
* project, package or source folder
330330
*/
@@ -411,7 +411,7 @@ public int compare(IType o1, IType o2) {
411411
/**
412412
* Platform specific newline character(s).
413413
*/
414-
public static final String NEWLINE = System.getProperty("line.separator"); //$NON-NLS-1$
414+
public static final String NEWLINE = System.lineSeparator();
415415

416416
public static String removePrefix(String s, String prefix) {
417417
if (s == null) {
@@ -483,7 +483,7 @@ public static String toString(Document doc) throws TransformerConfigurationExcep
483483

484484
/**
485485
* Converts collection to a separated string.
486-
*
486+
*
487487
* @param c
488488
* collection
489489
* @param separator
@@ -504,7 +504,7 @@ public static String toString(Collection<String> c, String separator) {
504504

505505
/**
506506
* Remove duplicates preserving original order.
507-
*
507+
*
508508
* @param l
509509
* list to remove duplicates from
510510
* @return new list without duplicates
@@ -548,7 +548,7 @@ public static boolean existsUserFile(String filename) {
548548

549549
/**
550550
* Request write access to given file. Depending on the version control plug-in opens a confirm checkout dialog.
551-
*
551+
*
552552
* @param shell
553553
* parent instance for dialogs
554554
* @param file
@@ -561,7 +561,7 @@ public static boolean validateEdit(Shell shell, IFile file) {
561561

562562
/**
563563
* Request write access to given files. Depending on the version control plug-in opens a confirm checkout dialog.
564-
*
564+
*
565565
* @param shell
566566
* parent instance for dialogs
567567
* @return <code>IFile</code> objects for which user confirmed checkout
@@ -633,7 +633,7 @@ public static boolean isDefaultClasspath(IJavaProject project, EclipseClasspath
633633

634634
/**
635635
* Add variable/value for Eclipse variable. If given string is no variable, nothing is added.
636-
*
636+
*
637637
* @param variable2valueMap
638638
* property map to add variable/value
639639
* @param s

0 commit comments

Comments
 (0)