Browse Source

Deprecate StringUtils.LINE_SEP

master
Gintas Grigelionis 7 years ago
parent
commit
03bb68d6ba
43 changed files with 215 additions and 396 deletions
  1. +4
    -4
      src/main/org/apache/tools/ant/Main.java
  2. +1
    -3
      src/main/org/apache/tools/ant/NoBannerLogger.java
  3. +2
    -3
      src/main/org/apache/tools/ant/Project.java
  4. +7
    -20
      src/main/org/apache/tools/ant/listener/BigProjectLogger.java
  5. +1
    -2
      src/main/org/apache/tools/ant/listener/MailLogger.java
  6. +4
    -6
      src/main/org/apache/tools/ant/listener/ProfileLogger.java
  7. +7
    -18
      src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java
  8. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/AntStructure.java
  9. +1
    -2
      src/main/org/apache/tools/ant/taskdefs/CVSPass.java
  10. +2
    -4
      src/main/org/apache/tools/ant/taskdefs/Checksum.java
  11. +1
    -2
      src/main/org/apache/tools/ant/taskdefs/Concat.java
  12. +2
    -5
      src/main/org/apache/tools/ant/taskdefs/Copy.java
  13. +7
    -10
      src/main/org/apache/tools/ant/taskdefs/DefaultExcludes.java
  14. +1
    -2
      src/main/org/apache/tools/ant/taskdefs/Echo.java
  15. +2
    -3
      src/main/org/apache/tools/ant/taskdefs/Execute.java
  16. +1
    -2
      src/main/org/apache/tools/ant/taskdefs/Javadoc.java
  17. +1
    -2
      src/main/org/apache/tools/ant/taskdefs/Parallel.java
  18. +3
    -6
      src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java
  19. +5
    -17
      src/main/org/apache/tools/ant/taskdefs/Redirector.java
  20. +2
    -3
      src/main/org/apache/tools/ant/taskdefs/Replace.java
  21. +1
    -2
      src/main/org/apache/tools/ant/taskdefs/Retry.java
  22. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
  23. +3
    -6
      src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java
  24. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/Javah.java
  25. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/NetRexxC.java
  26. +1
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/SchemaValidate.java
  27. +9
    -30
      src/main/org/apache/tools/ant/taskdefs/optional/extension/Extension.java
  28. +19
    -48
      src/main/org/apache/tools/ant/taskdefs/optional/extension/Specification.java
  29. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/DefaultJspCompilerAdapter.java
  30. +8
    -15
      src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java
  31. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  32. +6
    -13
      src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java
  33. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/ssh/Directory.java
  34. +5
    -5
      src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java
  35. +3
    -5
      src/main/org/apache/tools/ant/util/DOMElementWriter.java
  36. +11
    -11
      src/main/org/apache/tools/ant/util/DeweyDecimal.java
  37. +10
    -10
      src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java
  38. +1
    -0
      src/main/org/apache/tools/ant/util/StringUtils.java
  39. +5
    -5
      src/main/org/apache/tools/zip/ZipEntry.java
  40. +14
    -25
      src/tests/junit/org/apache/tools/ant/DefaultLoggerTest.java
  41. +22
    -28
      src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java
  42. +1
    -2
      src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
  43. +31
    -65
      src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java

+ 4
- 4
src/main/org/apache/tools/ant/Main.java View File

@@ -1269,14 +1269,14 @@ public class Main implements AntMain {
final String heading, final String heading,
final int maxlen) { final int maxlen) {
// now, start printing the targets and their descriptions // now, start printing the targets and their descriptions
final String lSep = System.lineSeparator();
final String eol = System.lineSeparator();
// got a bit annoyed that I couldn't find a pad function // got a bit annoyed that I couldn't find a pad function
StringBuilder spaces = new StringBuilder(" "); StringBuilder spaces = new StringBuilder(" ");
while (spaces.length() <= maxlen) { while (spaces.length() <= maxlen) {
spaces.append(spaces); spaces.append(spaces);
} }
final StringBuilder msg = new StringBuilder(); final StringBuilder msg = new StringBuilder();
msg.append(heading).append(lSep).append(lSep);
msg.append(heading).append(eol).append(eol);
final int size = names.size(); final int size = names.size();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
msg.append(" "); msg.append(" ");
@@ -1286,7 +1286,7 @@ public class Main implements AntMain {
spaces.substring(0, maxlen - names.elementAt(i).length() + 2)); spaces.substring(0, maxlen - names.elementAt(i).length() + 2));
msg.append(descriptions.elementAt(i)); msg.append(descriptions.elementAt(i));
} }
msg.append(lSep);
msg.append(eol);
if (!dependencies.isEmpty()) { if (!dependencies.isEmpty()) {
final Enumeration<String> deps = dependencies.elementAt(i); final Enumeration<String> deps = dependencies.elementAt(i);
if (deps.hasMoreElements()) { if (deps.hasMoreElements()) {
@@ -1297,7 +1297,7 @@ public class Main implements AntMain {
msg.append(", "); msg.append(", ");
} }
} }
msg.append(lSep);
msg.append(eol);
} }
} }
} }


+ 1
- 3
src/main/org/apache/tools/ant/NoBannerLogger.java View File

@@ -18,8 +18,6 @@


package org.apache.tools.ant; package org.apache.tools.ant;


import org.apache.tools.ant.util.StringUtils;

/** /**
* Extends DefaultLogger to strip out empty targets. * Extends DefaultLogger to strip out empty targets.
* *
@@ -90,7 +88,7 @@ public class NoBannerLogger extends DefaultLogger {


synchronized (this) { synchronized (this) {
if (null != targetName) { if (null != targetName) {
out.println(StringUtils.LINE_SEP + targetName + ":");
out.println(String.format("%n%s:", targetName));
targetName = null; targetName = null;
} }
} }


+ 2
- 3
src/main/org/apache/tools/ant/Project.java View File

@@ -51,7 +51,6 @@ import org.apache.tools.ant.types.resources.FileResource;
import org.apache.tools.ant.util.CollectionUtils; import org.apache.tools.ant.util.CollectionUtils;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.JavaEnvUtils; import org.apache.tools.ant.util.JavaEnvUtils;
import org.apache.tools.ant.util.StringUtils;
import org.apache.tools.ant.util.VectorSet; import org.apache.tools.ant.util.VectorSet;


/** /**
@@ -2222,8 +2221,8 @@ public class Project implements ResourceFactory {
if (message == null) { if (message == null) {
message = String.valueOf(message); message = String.valueOf(message);
} }
if (message.endsWith(StringUtils.LINE_SEP)) {
final int endIndex = message.length() - StringUtils.LINE_SEP.length();
if (message.endsWith(System.lineSeparator())) {
final int endIndex = message.length() - System.lineSeparator().length();
event.setMessage(message.substring(0, endIndex), priority); event.setMessage(message.substring(0, endIndex), priority);
} else { } else {
event.setMessage(message, priority); event.setMessage(message, priority);


+ 7
- 20
src/main/org/apache/tools/ant/listener/BigProjectLogger.java View File

@@ -17,12 +17,9 @@
*/ */
package org.apache.tools.ant.listener; package org.apache.tools.ant.listener;


import java.io.File;

import org.apache.tools.ant.BuildEvent; import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.SubBuildListener; import org.apache.tools.ant.SubBuildListener;
import org.apache.tools.ant.util.StringUtils;


/** /**
* This is a special logger that is designed to make it easier to work * This is a special logger that is designed to make it easier to work
@@ -120,18 +117,11 @@ public class BigProjectLogger extends SimpleBigProjectLogger
* @param event An event with any relevant extra information. Must not be <code>null</code>. * @param event An event with any relevant extra information. Must not be <code>null</code>.
*/ */
public void subBuildStarted(BuildEvent event) { public void subBuildStarted(BuildEvent event) {
String name = extractNameOrDefault(event);
Project project = event.getProject(); Project project = event.getProject();

File base = project == null ? null : project.getBaseDir();
String path =
(base == null)
? "With no base directory"
: "In " + base.getAbsolutePath();
printMessage(StringUtils.LINE_SEP + getHeader()
+ StringUtils.LINE_SEP + "Entering project " + name
+ StringUtils.LINE_SEP + path
+ StringUtils.LINE_SEP + getFooter(),
String path = (project == null) ? "With no base directory"
: "In " + project.getBaseDir().getAbsolutePath();
printMessage(String.format("%n%s%nEntering project %s%n%s%n%s", getHeader(),
extractNameOrDefault(event), path, getFooter()),
out, out,
event.getPriority()); event.getPriority());
} }
@@ -154,12 +144,9 @@ public class BigProjectLogger extends SimpleBigProjectLogger


/** {@inheritDoc} */ /** {@inheritDoc} */
public void subBuildFinished(BuildEvent event) { public void subBuildFinished(BuildEvent event) {
String name = extractNameOrDefault(event);
String failed = event.getException() != null ? "failing " : "";
printMessage(StringUtils.LINE_SEP + getHeader()
+ StringUtils.LINE_SEP + "Exiting " + failed + "project "
+ name
+ StringUtils.LINE_SEP + getFooter(),
printMessage(String.format("%n%s%nExiting %sproject %s%n%s",
getHeader(), event.getException() != null ? "failing " : "",
extractNameOrDefault(event), getFooter()),
out, out,
event.getPriority()); event.getPriority());
} }


+ 1
- 2
src/main/org/apache/tools/ant/listener/MailLogger.java View File

@@ -40,7 +40,6 @@ import org.apache.tools.ant.taskdefs.email.Message;
import org.apache.tools.ant.util.ClasspathUtils; import org.apache.tools.ant.util.ClasspathUtils;
import org.apache.tools.ant.util.DateUtils; import org.apache.tools.ant.util.DateUtils;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;
import org.apache.tools.mail.MailMessage; import org.apache.tools.mail.MailMessage;


/** /**
@@ -313,7 +312,7 @@ public class MailLogger extends DefaultLogger {
*/ */
@Override @Override
protected void log(String message) { protected void log(String message) {
buffer.append(message).append(StringUtils.LINE_SEP);
buffer.append(message).append(System.lineSeparator());
} }






+ 4
- 6
src/main/org/apache/tools/ant/listener/ProfileLogger.java View File

@@ -23,7 +23,6 @@ import java.util.concurrent.ConcurrentHashMap;


import org.apache.tools.ant.BuildEvent; import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.DefaultLogger; import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.util.StringUtils;


/** /**
* This is a special logger that is designed to profile builds. * This is a special logger that is designed to profile builds.
@@ -97,18 +96,17 @@ public class ProfileLogger extends DefaultLogger {
String msg; String msg;
if (start != null) { if (start != null) {
long diff = now.getTime() - start.getTime(); long diff = now.getTime() - start.getTime();
msg = StringUtils.LINE_SEP + name + ": finished " + now + " ("
+ diff + "ms)";
msg = String.format("%n%s: finished %s (%d)", name, now, diff);
} else { } else {
msg = StringUtils.LINE_SEP + name + ": finished " + now
+ " (unknown duration, start not detected)";
msg = String.format("%n%s: finished %s (unknown duration, start not detected)",
name, now);
} }
printMessage(msg, out, event.getPriority()); printMessage(msg, out, event.getPriority());
log(msg); log(msg);
} }


private void logStart(BuildEvent event, Date start, String name) { private void logStart(BuildEvent event, Date start, String name) {
String msg = StringUtils.LINE_SEP + name + ": started " + start;
String msg = String.format("%n%s: started %s", name, start);
printMessage(msg, out, event.getPriority()); printMessage(msg, out, event.getPriority());
log(msg); log(msg);
} }


+ 7
- 18
src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java View File

@@ -25,8 +25,10 @@ import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Vector; import java.util.Vector;
import java.util.stream.Collectors;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
@@ -34,7 +36,6 @@ import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Environment; import org.apache.tools.ant.types.Environment;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;


/** /**
* original Cvs.java 1.20 * original Cvs.java 1.20
@@ -352,12 +353,9 @@ public abstract class AbstractCvsTask extends Task {
log("retCode=" + retCode, Project.MSG_DEBUG); log("retCode=" + retCode, Project.MSG_DEBUG);


if (failOnError && Execute.isFailure(retCode)) { if (failOnError && Execute.isFailure(retCode)) {
throw new BuildException("cvs exited with error code "
+ retCode
+ StringUtils.LINE_SEP
+ "Command line was ["
+ actualCommandLine + "]",
getLocation());
throw new BuildException(
String.format("cvs exited with error code %s%nCommand line was [%s]",
retCode, actualCommandLine), getLocation());
} }
} catch (IOException e) { } catch (IOException e) {
if (failOnError) { if (failOnError) {
@@ -422,19 +420,10 @@ public abstract class AbstractCvsTask extends Task {
.getCommandline()); .getCommandline());
StringBuilder buf = removeCvsPassword(cmdLine); StringBuilder buf = removeCvsPassword(cmdLine);


String newLine = StringUtils.LINE_SEP;
String[] variableArray = execute.getEnvironment(); String[] variableArray = execute.getEnvironment();

if (variableArray != null) { if (variableArray != null) {
buf.append(newLine);
buf.append(newLine);
buf.append("environment:");
buf.append(newLine);
for (String variable : variableArray) {
buf.append(newLine);
buf.append("\t");
buf.append(variable);
}
buf.append(Arrays.stream(variableArray).map(variable -> String.format("%n\t%s", variable))
.collect(Collectors.joining("", String.format("%n%nenvironment:%n"), "")));
} }


return buf.toString(); return buf.toString();


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/AntStructure.java View File

@@ -376,7 +376,7 @@ public class AntStructure extends Task {
} }
sb.append("#IMPLIED"); sb.append("#IMPLIED");
} }
sb.append(">").append(System.lineSeparator());
sb.append(String.format(">%n"));
out.println(sb); out.println(sb);


for (String nestedName : v) { for (String nestedName : v) {


+ 1
- 2
src/main/org/apache/tools/ant/taskdefs/CVSPass.java View File

@@ -29,7 +29,6 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;


/** /**
* Adds an new entry to a CVS password file. * Adds an new entry to a CVS password file.
@@ -107,7 +106,7 @@ public class CVSPass extends Task {


while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
if (!line.startsWith(cvsRoot)) { if (!line.startsWith(cvsRoot)) {
buf.append(line).append(StringUtils.LINE_SEP);
buf.append(line).append(System.lineSeparator());
} }
} }
} }


+ 2
- 4
src/main/org/apache/tools/ant/taskdefs/Checksum.java View File

@@ -48,7 +48,6 @@ import org.apache.tools.ant.types.resources.Restrict;
import org.apache.tools.ant.types.resources.Union; import org.apache.tools.ant.types.resources.Union;
import org.apache.tools.ant.types.resources.selectors.Type; import org.apache.tools.ant.types.resources.selectors.Type;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;


/** /**
* Used to create or verify file checksums. * Used to create or verify file checksums.
@@ -392,8 +391,7 @@ public class Checksum extends MatchingTask implements Condition {
try { try {
if (resources != null) { if (resources != null) {
for (Resource r : resources) { for (Resource r : resources) {
File src = r.as(FileProvider.class)
.getFile();
File src = r.as(FileProvider.class).getFile();
if (totalproperty != null || todir != null) { if (totalproperty != null || todir != null) {
// Use '/' to calculate digest based on file name. // Use '/' to calculate digest based on file name.
// This is required in order to get the same result // This is required in order to get the same result
@@ -537,7 +535,7 @@ public class Checksum extends MatchingTask implements Condition {
src), src),
src.getAbsolutePath() src.getAbsolutePath()
}).getBytes()); }).getBytes());
fos.write(StringUtils.LINE_SEP.getBytes());
fos.write(System.lineSeparator().getBytes());
fos.close(); fos.close();
fos = null; fos = null;
} }


+ 1
- 2
src/main/org/apache/tools/ant/taskdefs/Concat.java View File

@@ -57,7 +57,6 @@ import org.apache.tools.ant.util.ConcatResourceInputStream;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.ReaderInputStream; import org.apache.tools.ant.util.ReaderInputStream;
import org.apache.tools.ant.util.ResourceUtils; import org.apache.tools.ant.util.ResourceUtils;
import org.apache.tools.ant.util.StringUtils;


/** /**
* This class contains the 'concat' task, used to concatenate a series * This class contains the 'concat' task, used to concatenate a series
@@ -525,7 +524,7 @@ public class Concat extends Task implements ResourceCollection {
binary = false; binary = false;
outputWriter = null; outputWriter = null;
textBuffer = null; textBuffer = null;
eolString = StringUtils.LINE_SEP;
eolString = System.lineSeparator();
rc = null; rc = null;
ignoreEmpty = true; ignoreEmpty = true;
force = false; force = false;


+ 2
- 5
src/main/org/apache/tools/ant/taskdefs/Copy.java View File

@@ -1085,11 +1085,8 @@ public class Copy extends Task {
if (ex.getClass().getName().contains("MalformedInput")) { if (ex.getClass().getName().contains("MalformedInput")) {
message.append(String.format( message.append(String.format(
"%nThis is normally due to the input file containing invalid" "%nThis is normally due to the input file containing invalid"
+ "%nbytes for the character encoding used : "));
message.append(
(inputEncoding == null
? fileUtils.getDefaultEncoding() : inputEncoding));
message.append(System.lineSeparator());
+ "%nbytes for the character encoding used : %s%n",
inputEncoding == null ? fileUtils.getDefaultEncoding() : inputEncoding));
} }
return message.toString(); return message.toString();
} }


+ 7
- 10
src/main/org/apache/tools/ant/taskdefs/DefaultExcludes.java View File

@@ -22,7 +22,9 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.util.StringUtils;

import java.util.Arrays;
import java.util.stream.Collectors;


/** /**
* Alters the default excludes for the <strong>entire</strong> build.. * Alters the default excludes for the <strong>entire</strong> build..
@@ -61,15 +63,10 @@ public class DefaultExcludes extends Task {
DirectoryScanner.removeDefaultExclude(remove); DirectoryScanner.removeDefaultExclude(remove);
} }
if (echo) { if (echo) {
StringBuilder message
= new StringBuilder("Current Default Excludes:");
message.append(StringUtils.LINE_SEP);
for (String exclude : DirectoryScanner.getDefaultExcludes()) {
message.append(" ");
message.append(exclude);
message.append(StringUtils.LINE_SEP);
}
log(message.toString(), logLevel);
String message = Arrays.stream(DirectoryScanner.getDefaultExcludes())
.map(exclude -> String.format(" %s%n", exclude))
.collect(Collectors.joining("", "Current Default Excludes:%n", ""));
log(message, logLevel);
} }
} }




+ 1
- 2
src/main/org/apache/tools/ant/taskdefs/Echo.java View File

@@ -31,7 +31,6 @@ import org.apache.tools.ant.types.resources.FileResource;
import org.apache.tools.ant.types.resources.LogOutputResource; import org.apache.tools.ant.types.resources.LogOutputResource;
import org.apache.tools.ant.types.resources.StringResource; import org.apache.tools.ant.types.resources.StringResource;
import org.apache.tools.ant.util.ResourceUtils; import org.apache.tools.ant.util.ResourceUtils;
import org.apache.tools.ant.util.StringUtils;


/** /**
* Writes a message to the Ant logging facilities. * Writes a message to the Ant logging facilities.
@@ -63,7 +62,7 @@ public class Echo extends Task {
public void execute() throws BuildException { public void execute() throws BuildException {
try { try {
ResourceUtils.copyResource( ResourceUtils.copyResource(
new StringResource(message.isEmpty() ? StringUtils.LINE_SEP : message),
new StringResource(message.isEmpty() ? System.lineSeparator() : message),
output == null ? new LogOutputResource(this, logLevel) : output, output == null ? new LogOutputResource(this, logLevel) : output,
null, null, false, false, append, null, null, null, false, false, append, null,
encoding.isEmpty() ? null : encoding, getProject(), force); encoding.isEmpty() ? null : encoding, getProject(), force);


+ 2
- 3
src/main/org/apache/tools/ant/taskdefs/Execute.java View File

@@ -38,7 +38,6 @@ import org.apache.tools.ant.taskdefs.condition.Os;
import org.apache.tools.ant.taskdefs.launcher.CommandLauncher; import org.apache.tools.ant.taskdefs.launcher.CommandLauncher;
import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;


/** /**
* Runs an external program. * Runs an external program.
@@ -150,9 +149,9 @@ public class Execute {
// Chunk part of previous env var (UNIX env vars can // Chunk part of previous env var (UNIX env vars can
// contain embedded new lines). // contain embedded new lines).
if (var == null) { if (var == null) {
var = new StringBuilder(StringUtils.LINE_SEP + line);
var = new StringBuilder(System.lineSeparator() + line);
} else { } else {
var.append(StringUtils.LINE_SEP).append(line);
var.append(System.lineSeparator()).append(line);
} }
} }
} }


+ 1
- 2
src/main/org/apache/tools/ant/taskdefs/Javadoc.java View File

@@ -60,7 +60,6 @@ import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.resources.FileProvider; import org.apache.tools.ant.types.resources.FileProvider;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.JavaEnvUtils; import org.apache.tools.ant.util.JavaEnvUtils;
import org.apache.tools.ant.util.StringUtils;


/** /**
* Generates Javadoc documentation for a collection * Generates Javadoc documentation for a collection
@@ -2474,7 +2473,7 @@ public class Javadoc extends Task {


private String fixLineFeeds(final String orig) { private String fixLineFeeds(final String orig) {
return orig.replace("\r\n", "\n") return orig.replace("\r\n", "\n")
.replace("\n", StringUtils.LINE_SEP);
.replace("\n", System.lineSeparator());
} }


private String patchContent(final String fileContents, final String fixData) { private String patchContent(final String fileContents, final String fixData) {


+ 1
- 2
src/main/org/apache/tools/ant/taskdefs/Parallel.java View File

@@ -27,7 +27,6 @@ import org.apache.tools.ant.Location;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.TaskContainer; import org.apache.tools.ant.TaskContainer;
import org.apache.tools.ant.property.LocalProperties; import org.apache.tools.ant.property.LocalProperties;
import org.apache.tools.ant.util.StringUtils;


/** /**
* Executes the contained tasks in separate threads, continuing * Executes the contained tasks in separate threads, continuing
@@ -243,7 +242,7 @@ public class Parallel extends Task
// location should match the exit status // location should match the exit status
firstLocation = ex.getLocation(); firstLocation = ex.getLocation();
} }
exceptionMessage.append(StringUtils.LINE_SEP);
exceptionMessage.append(System.lineSeparator());
exceptionMessage.append(t.getMessage()); exceptionMessage.append(t.getMessage());
} }
} }


+ 3
- 6
src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java View File

@@ -28,7 +28,6 @@ import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.SubBuildListener; import org.apache.tools.ant.SubBuildListener;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;


/** /**
* This is a class that represents a recorder. This is the listener to the * This is a class that represents a recorder. This is the listener to the
@@ -108,10 +107,9 @@ public class RecorderEntry implements BuildLogger, SubBuildListener {
Throwable error = event.getException(); Throwable error = event.getException();


if (error == null) { if (error == null) {
out.println(StringUtils.LINE_SEP + "BUILD SUCCESSFUL");
out.println(String.format("%nBUILD SUCCESSFUL"));
} else { } else {
out.println(StringUtils.LINE_SEP + "BUILD FAILED"
+ StringUtils.LINE_SEP);
out.println(String.format("%nBUILD FAILED%n"));
error.printStackTrace(out); //NOSONAR error.printStackTrace(out); //NOSONAR
} }
} }
@@ -149,8 +147,7 @@ public class RecorderEntry implements BuildLogger, SubBuildListener {
*/ */
public void targetStarted(BuildEvent event) { public void targetStarted(BuildEvent event) {
log(">> TARGET STARTED -- " + event.getTarget(), Project.MSG_DEBUG); log(">> TARGET STARTED -- " + event.getTarget(), Project.MSG_DEBUG);
log(StringUtils.LINE_SEP + event.getTarget().getName() + ":",
Project.MSG_INFO);
log(String.format("%n%s:", event.getTarget().getName()), Project.MSG_INFO);
targetStartTime = System.currentTimeMillis(); targetStartTime = System.currentTimeMillis();
} }




+ 5
- 17
src/main/org/apache/tools/ant/taskdefs/Redirector.java View File

@@ -31,6 +31,7 @@ import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.util.Arrays; import java.util.Arrays;
import java.util.Vector; import java.util.Vector;
import java.util.stream.Collectors;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
@@ -46,7 +47,6 @@ import org.apache.tools.ant.util.LeadPipeInputStream;
import org.apache.tools.ant.util.LineOrientedOutputStreamRedirector; import org.apache.tools.ant.util.LineOrientedOutputStreamRedirector;
import org.apache.tools.ant.util.OutputStreamFunneler; import org.apache.tools.ant.util.OutputStreamFunneler;
import org.apache.tools.ant.util.ReaderInputStream; import org.apache.tools.ant.util.ReaderInputStream;
import org.apache.tools.ant.util.StringUtils;
import org.apache.tools.ant.util.TeeOutputStream; import org.apache.tools.ant.util.TeeOutputStream;


/** /**
@@ -549,24 +549,12 @@ public class Redirector {
* contains the property value. * contains the property value.
* @param propertyName * @param propertyName
* the property name. * the property name.
*
* @exception IOException
* if the value cannot be read form the stream.
*/ */
private void setPropertyFromBAOS(final ByteArrayOutputStream baos, private void setPropertyFromBAOS(final ByteArrayOutputStream baos,
final String propertyName) throws IOException {

final BufferedReader in = new BufferedReader(new StringReader(Execute
.toString(baos)));
String line = null;
final StringBuffer val = new StringBuffer();
while ((line = in.readLine()) != null) {
if (val.length() > 0) {
val.append(StringUtils.LINE_SEP);
}
val.append(line);
}
managingTask.getProject().setNewProperty(propertyName, val.toString());
final String propertyName) {
final BufferedReader in = new BufferedReader(new StringReader(Execute.toString(baos)));
managingTask.getProject().setNewProperty(propertyName,
in.lines().collect(Collectors.joining(System.lineSeparator())));
} }


/** /**


+ 2
- 3
src/main/org/apache/tools/ant/taskdefs/Replace.java View File

@@ -45,7 +45,6 @@ import org.apache.tools.ant.types.resources.FileProvider;
import org.apache.tools.ant.types.resources.FileResource; import org.apache.tools.ant.types.resources.FileResource;
import org.apache.tools.ant.types.resources.Union; import org.apache.tools.ant.types.resources.Union;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;


/** /**
* Replaces all occurrences of one or more string tokens with given * Replaces all occurrences of one or more string tokens with given
@@ -501,10 +500,10 @@ public class Replace extends MatchingTask {
// as needed // as needed
StringBuilder val = new StringBuilder(value.getText()); StringBuilder val = new StringBuilder(value.getText());
stringReplace(val, "\r\n", "\n"); stringReplace(val, "\r\n", "\n");
stringReplace(val, "\n", StringUtils.LINE_SEP);
stringReplace(val, "\n", System.lineSeparator());
StringBuilder tok = new StringBuilder(token.getText()); StringBuilder tok = new StringBuilder(token.getText());
stringReplace(tok, "\r\n", "\n"); stringReplace(tok, "\r\n", "\n");
stringReplace(tok, "\n", StringUtils.LINE_SEP);
stringReplace(tok, "\n", System.lineSeparator());
Replacefilter firstFilter = createPrimaryfilter(); Replacefilter firstFilter = createPrimaryfilter();
firstFilter.setToken(tok.toString()); firstFilter.setToken(tok.toString());
firstFilter.setValue(val.toString()); firstFilter.setValue(val.toString());


+ 1
- 2
src/main/org/apache/tools/ant/taskdefs/Retry.java View File

@@ -21,7 +21,6 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.TaskContainer; import org.apache.tools.ant.TaskContainer;
import org.apache.tools.ant.util.StringUtils;


/** /**
* Retries the nested task a set number of times * Retries the nested task a set number of times
@@ -102,7 +101,7 @@ public class Retry extends Task implements TaskContainer {
msg = "Attempt [" + i + "]: error occurred; retrying..."; msg = "Attempt [" + i + "]: error occurred; retrying...";
} }
log(msg, e, Project.MSG_INFO); log(msg, e, Project.MSG_INFO);
errorMessages.append(StringUtils.LINE_SEP);
errorMessages.append(System.lineSeparator());
if (retryDelay > 0) { if (retryDelay > 0) {
try { try {
Thread.sleep(retryDelay); Thread.sleep(retryDelay);


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java View File

@@ -492,8 +492,8 @@ public abstract class DefaultCompilerAdapter


attributes.log(Stream.of(compileList).map(File::getAbsolutePath) attributes.log(Stream.of(compileList).map(File::getAbsolutePath)
.peek(arg -> cmd.createArgument().setValue(arg)) .peek(arg -> cmd.createArgument().setValue(arg))
.map(arg -> " " + arg)
.collect(Collectors.joining(StringUtils.LINE_SEP)), Project.MSG_VERBOSE);
.map(arg -> String.format(" %s%n", arg))
.collect(Collectors.joining("")), Project.MSG_VERBOSE);
} }


/** /**


+ 3
- 6
src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java View File

@@ -31,7 +31,6 @@ import java.util.TimeZone;


import org.apache.tools.ant.taskdefs.AbstractCvsTask; import org.apache.tools.ant.taskdefs.AbstractCvsTask;
import org.apache.tools.ant.taskdefs.AbstractCvsTask.Module; import org.apache.tools.ant.taskdefs.AbstractCvsTask.Module;
import org.apache.tools.ant.util.StringUtils;


/** /**
* A class used to parse the output of the CVS log command. * A class used to parse the output of the CVS log command.
@@ -151,18 +150,16 @@ class ChangeLogParser {
.equals(line)) { .equals(line)) {
//We have ended changelog for that particular file //We have ended changelog for that particular file
//so we can save it //so we can save it
final int end
= comment.length() - StringUtils.LINE_SEP.length(); //was -1
final int end = comment.length() - System.lineSeparator().length(); //was -1
comment = comment.substring(0, end); comment = comment.substring(0, end);
saveEntry(); saveEntry();
status = GET_FILE; status = GET_FILE;
} else if ("----------------------------".equals(line)) { } else if ("----------------------------".equals(line)) {
final int end
= comment.length() - StringUtils.LINE_SEP.length(); //was -1
final int end = comment.length() - System.lineSeparator().length(); //was -1
comment = comment.substring(0, end); comment = comment.substring(0, end);
status = GET_PREVIOUS_REV; status = GET_PREVIOUS_REV;
} else { } else {
comment += line + StringUtils.LINE_SEP;
comment += line + System.lineSeparator();
} }
} }




+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/optional/Javah.java View File

@@ -432,7 +432,8 @@ public class Javah extends Task {
settings.add(Settings.files); settings.add(Settings.files);
} }
if (settings.size() > 1) { if (settings.size() > 1) {
throw new BuildException("Exactly one of " + Settings.values() + " attributes is required", getLocation());
throw new BuildException("Exactly one of " + Settings.values()
+ " attributes is required", getLocation());
} }


if (destDir != null) { if (destDir != null) {


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/optional/NetRexxC.java View File

@@ -775,8 +775,8 @@ public class NetRexxC extends MatchingTask {


log("Files to be compiled:", Project.MSG_VERBOSE); log("Files to be compiled:", Project.MSG_VERBOSE);


log(compileList.stream().map(s -> " " + s).collect(Collectors.joining(System.lineSeparator())),
Project.MSG_VERBOSE);
log(compileList.stream().map(s -> String.format(" %s%n", s))
.collect(Collectors.joining("")), Project.MSG_VERBOSE);


// create a single array of arguments for the compiler // create a single array of arguments for the compiler
String[] compileArgs = String[] compileArgs =


+ 1
- 2
src/main/org/apache/tools/ant/taskdefs/optional/SchemaValidate.java View File

@@ -268,8 +268,7 @@ public class SchemaValidate extends XMLValidateTask {
if (!schemaLocations.isEmpty()) { if (!schemaLocations.isEmpty()) {
String joinedValue = schemaLocations.values().stream() String joinedValue = schemaLocations.values().stream()
.map(SchemaLocation::getURIandLocation) .map(SchemaLocation::getURIandLocation)
.peek(
tuple -> log("Adding schema " + tuple, Project.MSG_VERBOSE))
.peek(tuple -> log("Adding schema " + tuple, Project.MSG_VERBOSE))
.collect(Collectors.joining(" ")); .collect(Collectors.joining(" "));


setProperty(XmlConstants.PROPERTY_SCHEMA_LOCATION, joinedValue); setProperty(XmlConstants.PROPERTY_SCHEMA_LOCATION, joinedValue);


+ 9
- 30
src/main/org/apache/tools/ant/taskdefs/optional/extension/Extension.java View File

@@ -27,7 +27,6 @@ import java.util.jar.Manifest;
import java.util.stream.Stream; import java.util.stream.Stream;


import org.apache.tools.ant.util.DeweyDecimal; import org.apache.tools.ant.util.DeweyDecimal;
import org.apache.tools.ant.util.StringUtils;


/** /**
* <p>Utility class that represents either an available "Optional Package" * <p>Utility class that represents either an available "Optional Package"
@@ -478,53 +477,33 @@ public final class Extension {
*/ */
@Override @Override
public String toString() { public String toString() {
final String brace = ": ";
final String format = "%s: %s%n";


final StringBuilder sb = new StringBuilder(EXTENSION_NAME.toString());
sb.append(brace);
sb.append(extensionName);
sb.append(StringUtils.LINE_SEP);
final StringBuilder sb = new StringBuilder(String.format(format,
EXTENSION_NAME, extensionName));


if (null != specificationVersion) { if (null != specificationVersion) {
sb.append(SPECIFICATION_VERSION);
sb.append(brace);
sb.append(specificationVersion);
sb.append(StringUtils.LINE_SEP);
sb.append(String.format(format, SPECIFICATION_VERSION, specificationVersion));
} }


if (null != specificationVendor) { if (null != specificationVendor) {
sb.append(SPECIFICATION_VENDOR);
sb.append(brace);
sb.append(specificationVendor);
sb.append(StringUtils.LINE_SEP);
sb.append(String.format(format, SPECIFICATION_VENDOR, specificationVendor));
} }


if (null != implementationVersion) { if (null != implementationVersion) {
sb.append(IMPLEMENTATION_VERSION);
sb.append(brace);
sb.append(implementationVersion);
sb.append(StringUtils.LINE_SEP);
sb.append(String.format(format, IMPLEMENTATION_VERSION, implementationVersion));
} }


if (null != implementationVendorID) { if (null != implementationVendorID) {
sb.append(IMPLEMENTATION_VENDOR_ID);
sb.append(brace);
sb.append(implementationVendorID);
sb.append(StringUtils.LINE_SEP);
sb.append(String.format(format, IMPLEMENTATION_VENDOR_ID, implementationVendorID));
} }


if (null != implementationVendor) { if (null != implementationVendor) {
sb.append(IMPLEMENTATION_VENDOR);
sb.append(brace);
sb.append(implementationVendor);
sb.append(StringUtils.LINE_SEP);
sb.append(String.format(format, IMPLEMENTATION_VENDOR, implementationVendor));
} }


if (null != implementationURL) { if (null != implementationURL) {
sb.append(IMPLEMENTATION_URL);
sb.append(brace);
sb.append(implementationURL);
sb.append(StringUtils.LINE_SEP);
sb.append(String.format(format, IMPLEMENTATION_URL, implementationURL));
} }


return sb.toString(); return sb.toString();


+ 19
- 48
src/main/org/apache/tools/ant/taskdefs/optional/extension/Specification.java View File

@@ -29,7 +29,6 @@ import java.util.jar.Manifest;
import java.util.stream.Stream; import java.util.stream.Stream;


import org.apache.tools.ant.util.DeweyDecimal; import org.apache.tools.ant.util.DeweyDecimal;
import org.apache.tools.ant.util.StringUtils;


/** /**
* <p>Utility class that represents either an available "Optional Package" * <p>Utility class that represents either an available "Optional Package"
@@ -174,8 +173,7 @@ public final class Specification {
} }
final List<Specification> results = new ArrayList<>(); final List<Specification> results = new ArrayList<>();


for (Map.Entry<String, Attributes> e : manifest.getEntries()
.entrySet()) {
for (Map.Entry<String, Attributes> e : manifest.getEntries().entrySet()) {
Optional.ofNullable(getSpecification(e.getKey(), e.getValue())) Optional.ofNullable(getSpecification(e.getKey(), e.getValue()))
.ifPresent(results::add); .ifPresent(results::add);
} }
@@ -373,48 +371,31 @@ public final class Specification {
*/ */
@Override @Override
public String toString() { public String toString() {
final String brace = ": ";
final String format = "%s: %s%n";


final StringBuilder sb
= new StringBuilder(SPECIFICATION_TITLE.toString());
sb.append(brace);
sb.append(specificationTitle);
sb.append(StringUtils.LINE_SEP);
final StringBuilder sb = new StringBuilder(String.format(format,
SPECIFICATION_TITLE, specificationTitle));


if (null != specificationVersion) { if (null != specificationVersion) {
sb.append(SPECIFICATION_VERSION);
sb.append(brace);
sb.append(specificationVersion);
sb.append(StringUtils.LINE_SEP);
sb.append(String.format(format, SPECIFICATION_VERSION, specificationVersion));
} }


if (null != specificationVendor) { if (null != specificationVendor) {
sb.append(SPECIFICATION_VENDOR);
sb.append(brace);
sb.append(specificationVendor);
sb.append(StringUtils.LINE_SEP);
sb.append(String.format(format, SPECIFICATION_VENDOR, specificationVendor));
} }


if (null != implementationTitle) { if (null != implementationTitle) {
sb.append(IMPLEMENTATION_TITLE);
sb.append(brace);
sb.append(implementationTitle);
sb.append(StringUtils.LINE_SEP);
sb.append(String.format(format, IMPLEMENTATION_TITLE, implementationTitle));
} }


if (null != implementationVersion) { if (null != implementationVersion) {
sb.append(IMPLEMENTATION_VERSION);
sb.append(brace);
sb.append(implementationVersion);
sb.append(StringUtils.LINE_SEP);
sb.append(String.format(format, IMPLEMENTATION_VERSION, implementationVersion));
} }


if (null != implementationVendor) { if (null != implementationVendor) {
sb.append(IMPLEMENTATION_VENDOR);
sb.append(brace);
sb.append(implementationVendor);
sb.append(StringUtils.LINE_SEP);
sb.append(String.format(format, IMPLEMENTATION_VENDOR, implementationVendor));
} }

return sb.toString(); return sb.toString();
} }


@@ -455,7 +436,7 @@ public final class Specification {
} }
} }
results.add(mergeInSections(specification, sections)); results.add(mergeInSections(specification, sections));
//Reset list of sections
// Reset list of sections
sections.clear(); sections.clear();
} }
return results; return results;
@@ -493,12 +474,8 @@ public final class Specification {
if (sectionsToAdd.isEmpty()) { if (sectionsToAdd.isEmpty()) {
return specification; return specification;
} }
Stream<String> sections =
Stream
.concat(
Optional.ofNullable(specification.getSections())
.map(Stream::of).orElse(Stream.empty()),
sectionsToAdd.stream());
Stream<String> sections = Stream.concat(Optional.ofNullable(specification.getSections())
.map(Stream::of).orElse(Stream.empty()), sectionsToAdd.stream());


return new Specification(specification.getSpecificationTitle(), return new Specification(specification.getSpecificationTitle(),
specification.getSpecificationVersion().toString(), specification.getSpecificationVersion().toString(),
@@ -530,38 +507,32 @@ public final class Specification {
//WARNING: We trim the values of all the attributes because //WARNING: We trim the values of all the attributes because
//Some extension declarations are badly defined (ie have spaces //Some extension declarations are badly defined (ie have spaces
//after version or vendor) //after version or vendor)
final String name
= getTrimmedString(attributes.getValue(SPECIFICATION_TITLE));
final String name = getTrimmedString(attributes.getValue(SPECIFICATION_TITLE));
if (null == name) { if (null == name) {
return null; return null;
} }


final String specVendor
= getTrimmedString(attributes.getValue(SPECIFICATION_VENDOR));
final String specVendor = getTrimmedString(attributes.getValue(SPECIFICATION_VENDOR));
if (null == specVendor) { if (null == specVendor) {
throw new ParseException(MISSING + SPECIFICATION_VENDOR, 0); throw new ParseException(MISSING + SPECIFICATION_VENDOR, 0);
} }


final String specVersion
= getTrimmedString(attributes.getValue(SPECIFICATION_VERSION));
final String specVersion = getTrimmedString(attributes.getValue(SPECIFICATION_VERSION));
if (null == specVersion) { if (null == specVersion) {
throw new ParseException(MISSING + SPECIFICATION_VERSION, 0); throw new ParseException(MISSING + SPECIFICATION_VERSION, 0);
} }


final String impTitle
= getTrimmedString(attributes.getValue(IMPLEMENTATION_TITLE));
final String impTitle = getTrimmedString(attributes.getValue(IMPLEMENTATION_TITLE));
if (null == impTitle) { if (null == impTitle) {
throw new ParseException(MISSING + IMPLEMENTATION_TITLE, 0); throw new ParseException(MISSING + IMPLEMENTATION_TITLE, 0);
} }


final String impVersion
= getTrimmedString(attributes.getValue(IMPLEMENTATION_VERSION));
final String impVersion = getTrimmedString(attributes.getValue(IMPLEMENTATION_VERSION));
if (null == impVersion) { if (null == impVersion) {
throw new ParseException(MISSING + IMPLEMENTATION_VERSION, 0); throw new ParseException(MISSING + IMPLEMENTATION_VERSION, 0);
} }


final String impVendor
= getTrimmedString(attributes.getValue(IMPLEMENTATION_VENDOR));
final String impVendor = getTrimmedString(attributes.getValue(IMPLEMENTATION_VENDOR));
if (null == impVendor) { if (null == impVendor) {
throw new ParseException(MISSING + IMPLEMENTATION_VENDOR, 0); throw new ParseException(MISSING + IMPLEMENTATION_VENDOR, 0);
} }


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/DefaultJspCompilerAdapter.java View File

@@ -50,8 +50,8 @@ public abstract class DefaultJspCompilerAdapter


String niceSourceList = compileList.stream() String niceSourceList = compileList.stream()
.peek(arg -> cmd.createArgument().setValue(arg)) .peek(arg -> cmd.createArgument().setValue(arg))
.map(arg -> " " + arg)
.collect(Collectors.joining(System.lineSeparator()));
.map(arg -> String.format(" %s%n", arg))
.collect(Collectors.joining(""));
jspc.log(String.format("File%s to be compiled:%n%s", jspc.log(String.format("File%s to be compiled:%n%s",
compileList.size() == 1 ? "" : "s", niceSourceList), Project.MSG_VERBOSE); compileList.size() == 1 ? "" : "s", niceSourceList), Project.MSG_VERBOSE);
} }


+ 8
- 15
src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java View File

@@ -29,7 +29,6 @@ import junit.framework.Test;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;


/** /**
* Prints plain text output of the test to a specified Writer. * Prints plain text output of the test to a specified Writer.
@@ -124,7 +123,7 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter, IgnoredT
return; // Quick return - no output do nothing. return; // Quick return - no output do nothing.
} }
try { try {
output.write("Testsuite: " + suite.getName() + StringUtils.LINE_SEP);
output.write(String.format("Testsuite: %s%n", suite.getName()));
output.flush(); output.flush();
} catch (IOException ex) { } catch (IOException ex) {
throw new BuildException(ex); throw new BuildException(ex);
@@ -147,25 +146,19 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter, IgnoredT
sb.append(suite.skipCount()); sb.append(suite.skipCount());
sb.append(", Time elapsed: "); sb.append(", Time elapsed: ");
sb.append(numberFormat.format(suite.getRunTime() / ONE_SECOND)); sb.append(numberFormat.format(suite.getRunTime() / ONE_SECOND));
sb.append(" sec");
sb.append(StringUtils.LINE_SEP);
sb.append(StringUtils.LINE_SEP);
sb.append(String.format(" sec%n%n"));


// append the err and output streams to the log // append the err and output streams to the log
if (systemOutput != null && !systemOutput.isEmpty()) { if (systemOutput != null && !systemOutput.isEmpty()) {
sb.append("------------- Standard Output ---------------")
.append(StringUtils.LINE_SEP)
.append(systemOutput)
.append("------------- ---------------- ---------------")
.append(StringUtils.LINE_SEP);
sb.append(String.format("------------- Standard Output ---------------%n"));
sb.append(systemOutput);
sb.append(String.format("------------- ---------------- ---------------%n"));
} }


if (systemError != null && !systemError.isEmpty()) { if (systemError != null && !systemError.isEmpty()) {
sb.append("------------- Standard Error -----------------")
.append(StringUtils.LINE_SEP)
.append(systemError)
.append("------------- ---------------- ---------------")
.append(StringUtils.LINE_SEP);
sb.append(String.format("------------- Standard Error -----------------%n"));
sb.append(systemError);
sb.append(String.format("------------- ---------------- ---------------%n"));
} }


if (output != null) { if (output != null) {


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -987,7 +987,7 @@ public class JUnitTask extends Task {


try { try {
for (i = 0; i < numThreads; i++) { for (i = 0; i < numThreads; i++) {
threads[i].join();
threads[i].join();
} }
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
exceptionOccurred = true; exceptionOccurred = true;


+ 6
- 13
src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java View File

@@ -31,8 +31,6 @@ import junit.framework.Test;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;



/** /**
* Prints plain text output of the test to a specified Writer. * Prints plain text output of the test to a specified Writer.
@@ -105,8 +103,7 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter, IgnoredT
return; // Quick return - no output do nothing. return; // Quick return - no output do nothing.
} }
try { try {
out.write(("Testsuite: " + suite.getName() +
StringUtils.LINE_SEP).getBytes());
out.write(String.format("Testsuite: %s%n",suite.getName()).getBytes());
out.flush(); out.flush();
} catch (IOException ex) { } catch (IOException ex) {
throw new BuildException("Unable to write output", ex); throw new BuildException("Unable to write output", ex);
@@ -128,22 +125,18 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter, IgnoredT


// write the err and output streams to the log // write the err and output streams to the log
if (systemOutput != null && !systemOutput.isEmpty()) { if (systemOutput != null && !systemOutput.isEmpty()) {
write("------------- Standard Output ---------------");
write(StringUtils.LINE_SEP);
write(String.format("------------- Standard Output ---------------%n"));
write(systemOutput); write(systemOutput);
write("------------- ---------------- ---------------");
write(StringUtils.LINE_SEP);
write(String.format("------------- ---------------- ---------------%n"));
} }


if (systemError != null && !systemError.isEmpty()) { if (systemError != null && !systemError.isEmpty()) {
write("------------- Standard Error -----------------");
write(StringUtils.LINE_SEP);
write(String.format("------------- Standard Error -----------------%n"));
write(systemError); write(systemError);
write("------------- ---------------- ---------------");
write(StringUtils.LINE_SEP);
write(String.format("------------- ---------------- ---------------%n"));
} }


write(StringUtils.LINE_SEP);
write(System.lineSeparator());
if (out != null) { if (out != null) {
try { try {
wri.flush(); wri.flush();


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/optional/ssh/Directory.java View File

@@ -172,7 +172,7 @@ public class Directory {
public static String[] getPath(String thePath) { public static String[] getPath(String thePath) {
StringTokenizer tokenizer = new StringTokenizer(thePath, StringTokenizer tokenizer = new StringTokenizer(thePath,
File.separator); File.separator);
String[] path = new String[ tokenizer.countTokens() ];
String[] path = new String[tokenizer.countTokens()];


int i = 0; int i = 0;
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) {


+ 5
- 5
src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java View File

@@ -493,22 +493,22 @@ public class Scp extends SSHBase {


List<Directory> ds = new ArrayList<>(); List<Directory> ds = new ArrayList<>();
for (Resource r : rc) { for (Resource r : rc) {
if (!r.isExists()) {
if (!r.isExists()) {
throw new BuildException("Could not find resource %s to scp.", throw new BuildException("Could not find resource %s to scp.",
r.toLongString());
r.toLongString());
} }


FileProvider fp = r.as(FileProvider.class); FileProvider fp = r.as(FileProvider.class);
if (fp == null) { if (fp == null) {
throw new BuildException("Resource %s is not a file.", throw new BuildException("Resource %s is not a file.",
r.toLongString());
r.toLongString());
} }


FileResource fr = ResourceUtils.asFileResource(fp); FileResource fr = ResourceUtils.asFileResource(fp);
File baseDir = fr.getBaseDir(); File baseDir = fr.getBaseDir();
if (baseDir == null) { if (baseDir == null) {
throw new BuildException(
"basedir for resource %s is undefined.", r.toLongString());
throw new BuildException("basedir for resource %s is undefined.",
r.toLongString());
} }


// if the basedir is set, the name will be relative to that // if the basedir is set, the name will be relative to that


+ 3
- 5
src/main/org/apache/tools/ant/util/DOMElementWriter.java View File

@@ -217,7 +217,7 @@ public class DOMElementWriter {
case Node.ELEMENT_NODE: case Node.ELEMENT_NODE:
hasChildElements = true; hasChildElements = true;
if (i == 0) { if (i == 0) {
out.write(StringUtils.LINE_SEP);
out.write(System.lineSeparator());
} }
write((Element) child, out, indent + 1, indentWith); write((Element) child, out, indent + 1, indentWith);
break; break;
@@ -364,8 +364,7 @@ public class DOMElementWriter {
out.write(">"); out.write(">");
} else { } else {
removeNSDefinitions(element); removeNSDefinitions(element);
out.write(" />");
out.write(StringUtils.LINE_SEP);
out.write(String.format(" />%n"));
out.flush(); out.flush();
} }
} }
@@ -405,8 +404,7 @@ public class DOMElementWriter {
removeNSDefinitions(element); removeNSDefinitions(element);
} }
out.write(element.getTagName()); out.write(element.getTagName());
out.write(">");
out.write(StringUtils.LINE_SEP);
out.write(String.format(">%n"));
out.flush(); out.flush();
} }




+ 11
- 11
src/main/org/apache/tools/ant/util/DeweyDecimal.java View File

@@ -56,7 +56,7 @@ public class DeweyDecimal implements Comparable<DeweyDecimal> {
final StringTokenizer tokenizer = new StringTokenizer(string, ".", true); final StringTokenizer tokenizer = new StringTokenizer(string, ".", true);
final int size = tokenizer.countTokens(); final int size = tokenizer.countTokens();


components = new int[ (size + 1) / 2 ];
components = new int[(size + 1) / 2];


for (int i = 0; i < components.length; i++) { for (int i = 0; i < components.length; i++) {
final String component = tokenizer.nextToken(); final String component = tokenizer.nextToken();
@@ -64,7 +64,7 @@ public class DeweyDecimal implements Comparable<DeweyDecimal> {
throw new NumberFormatException("Empty component in string"); throw new NumberFormatException("Empty component in string");
} }


components[ i ] = Integer.parseInt(component);
components[i] = Integer.parseInt(component);


//Strip '.' token //Strip '.' token
if (tokenizer.hasMoreTokens()) { if (tokenizer.hasMoreTokens()) {
@@ -94,7 +94,7 @@ public class DeweyDecimal implements Comparable<DeweyDecimal> {
* @return the value of component at index * @return the value of component at index
*/ */
public int get(final int index) { public int get(final int index) {
return components[ index ];
return components[index];
} }


/** /**
@@ -108,8 +108,8 @@ public class DeweyDecimal implements Comparable<DeweyDecimal> {
final int max = Math.max(other.components.length, components.length); final int max = Math.max(other.components.length, components.length);


for (int i = 0; i < max; i++) { for (int i = 0; i < max; i++) {
final int component1 = (i < components.length) ? components[ i ] : 0;
final int component2 = (i < other.components.length) ? other.components[ i ] : 0;
final int component1 = (i < components.length) ? components[i] : 0;
final int component2 = (i < other.components.length) ? other.components[i] : 0;


if (component2 != component1) { if (component2 != component1) {
return false; return false;
@@ -152,8 +152,8 @@ public class DeweyDecimal implements Comparable<DeweyDecimal> {
final int max = Math.max(other.components.length, components.length); final int max = Math.max(other.components.length, components.length);


for (int i = 0; i < max; i++) { for (int i = 0; i < max; i++) {
final int component1 = (i < components.length) ? components[ i ] : 0;
final int component2 = (i < other.components.length) ? other.components[ i ] : 0;
final int component1 = (i < components.length) ? components[i] : 0;
final int component2 = (i < other.components.length) ? other.components[i] : 0;


if (component2 > component1) { if (component2 > component1) {
return false; return false;
@@ -177,8 +177,8 @@ public class DeweyDecimal implements Comparable<DeweyDecimal> {
final int max = Math.max(other.components.length, components.length); final int max = Math.max(other.components.length, components.length);


for (int i = 0; i < max; i++) { for (int i = 0; i < max; i++) {
final int component1 = (i < components.length) ? components[ i ] : 0;
final int component2 = (i < other.components.length) ? other.components[ i ] : 0;
final int component1 = (i < components.length) ? components[i] : 0;
final int component2 = (i < other.components.length) ? other.components[i] : 0;


if (component2 > component1) { if (component2 > component1) {
return false; return false;
@@ -212,8 +212,8 @@ public class DeweyDecimal implements Comparable<DeweyDecimal> {
public int compareTo(DeweyDecimal other) { public int compareTo(DeweyDecimal other) {
final int max = Math.max(other.components.length, components.length); final int max = Math.max(other.components.length, components.length);
for (int i = 0; i < max; i++) { for (int i = 0; i < max; i++) {
final int component1 = (i < components.length) ? components[ i ] : 0;
final int component2 = (i < other.components.length) ? other.components[ i ] : 0;
final int component1 = (i < components.length) ? components[i] : 0;
final int component2 = (i < other.components.length) ? other.components[i] : 0;
if (component1 != component2) { if (component1 != component2) {
return component1 - component2; return component1 - component2;
} }


+ 10
- 10
src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java View File

@@ -82,7 +82,7 @@ import java.util.Properties;
public class LayoutPreservingProperties extends Properties { public class LayoutPreservingProperties extends Properties {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;


private String LS = StringUtils.LINE_SEP;
private String eol = System.lineSeparator();


/** /**
* Logical lines have escaping and line continuation taken care * Logical lines have escaping and line continuation taken care
@@ -266,7 +266,7 @@ public class LayoutPreservingProperties extends Properties {
final int totalLines = logicalLines.size(); final int totalLines = logicalLines.size();


if (header != null) { if (header != null) {
osw.write("#" + header + LS);
osw.write("#" + header + eol);
if (totalLines > 0 if (totalLines > 0
&& logicalLines.get(0) instanceof Comment && logicalLines.get(0) instanceof Comment
&& header.equals(logicalLines.get(0).toString().substring(1))) { && header.equals(logicalLines.get(0).toString().substring(1))) {
@@ -288,20 +288,20 @@ public class LayoutPreservingProperties extends Properties {
// not an existing date comment // not an existing date comment
} }
} }
osw.write("#" + DateUtils.getDateForHeader() + LS);
osw.write("#" + DateUtils.getDateForHeader() + eol);


boolean writtenSep = false; boolean writtenSep = false;
for (LogicalLine line : logicalLines.subList(skipLines, totalLines)) { for (LogicalLine line : logicalLines.subList(skipLines, totalLines)) {
if (line instanceof Pair) { if (line instanceof Pair) {
if (((Pair) line).isNew()) { if (((Pair) line).isNew()) {
if (!writtenSep) { if (!writtenSep) {
osw.write(LS);
osw.write(eol);
writtenSep = true; writtenSep = true;
} }
} }
osw.write(line.toString() + LS);
osw.write(line.toString() + eol);
} else if (line != null) { } else if (line != null) {
osw.write(line.toString() + LS);
osw.write(line.toString() + eol);
} }
} }
osw.close(); osw.close();
@@ -331,7 +331,7 @@ public class LayoutPreservingProperties extends Properties {
final StringBuilder fileBuffer = new StringBuilder(); final StringBuilder fileBuffer = new StringBuilder();
final StringBuilder logicalLineBuffer = new StringBuilder(); final StringBuilder logicalLineBuffer = new StringBuilder();
while (s != null) { while (s != null) {
fileBuffer.append(s).append(LS);
fileBuffer.append(s).append(eol);


if (continuation) { if (continuation) {
// put in the line feed that was removed // put in the line feed that was removed
@@ -390,7 +390,7 @@ public class LayoutPreservingProperties extends Properties {
boolean hasCR = false; boolean hasCR = false;
// when reaching EOF before the first EOL, assume native line // when reaching EOF before the first EOL, assume native line
// feeds // feeds
LS = StringUtils.LINE_SEP;
eol = System.lineSeparator();


while (ch >= 0) { while (ch >= 0) {
if (hasCR && ch != '\n') { if (hasCR && ch != '\n') {
@@ -400,10 +400,10 @@ public class LayoutPreservingProperties extends Properties {
} }


if (ch == '\r') { if (ch == '\r') {
LS = "\r";
eol = "\r";
hasCR = true; hasCR = true;
} else if (ch == '\n') { } else if (ch == '\n') {
LS = hasCR ? "\r\n" : "\n";
eol = hasCR ? "\r\n" : "\n";
break; break;
} else { } else {
sb.append((char) ch); sb.append((char) ch);


+ 1
- 0
src/main/org/apache/tools/ant/util/StringUtils.java View File

@@ -45,6 +45,7 @@ public final class StringUtils {
} }


/** the line separator for this OS */ /** the line separator for this OS */
@Deprecated
public static final String LINE_SEP = System.lineSeparator(); public static final String LINE_SEP = System.lineSeparator();


/** /**


+ 5
- 5
src/main/org/apache/tools/zip/ZipEntry.java View File

@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException;
import java.util.zip.ZipException; import java.util.zip.ZipException;


/** /**
@@ -455,7 +456,7 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable {
*/ */
public void removeExtraField(final ZipShort type) { public void removeExtraField(final ZipShort type) {
if (extraFields == null) { if (extraFields == null) {
throw new java.util.NoSuchElementException();
throw new NoSuchElementException();
} }
List<ZipExtraField> newResult = new ArrayList<>(); List<ZipExtraField> newResult = new ArrayList<>();
for (ZipExtraField extraField : extraFields) { for (ZipExtraField extraField : extraFields) {
@@ -464,7 +465,7 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable {
} }
} }
if (extraFields.length == newResult.size()) { if (extraFields.length == newResult.size()) {
throw new java.util.NoSuchElementException();
throw new NoSuchElementException();
} }
extraFields = newResult.toArray(new ZipExtraField[newResult.size()]); extraFields = newResult.toArray(new ZipExtraField[newResult.size()]);
setExtra(); setExtra();
@@ -475,7 +476,7 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable {
*/ */
public void removeUnparseableExtraFieldData() { public void removeUnparseableExtraFieldData() {
if (unparseableExtra == null) { if (unparseableExtra == null) {
throw new java.util.NoSuchElementException();
throw new NoSuchElementException();
} }
unparseableExtra = null; unparseableExtra = null;
setExtra(); setExtra();
@@ -744,8 +745,7 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable {
addExtraField(element); addExtraField(element);
} else { } else {
if (local if (local
|| !(existing
instanceof CentralDirectoryParsingZipExtraField)) {
|| !(existing instanceof CentralDirectoryParsingZipExtraField)) {
final byte[] b = element.getLocalFileDataData(); final byte[] b = element.getLocalFileDataData();
existing.parseFromLocalFileData(b, 0, b.length); existing.parseFromLocalFileData(b, 0, b.length);
} else { } else {


+ 14
- 25
src/tests/junit/org/apache/tools/ant/DefaultLoggerTest.java View File

@@ -18,7 +18,6 @@


package org.apache.tools.ant; package org.apache.tools.ant;


import org.apache.tools.ant.util.StringUtils;
import org.junit.Test; import org.junit.Test;


import java.io.PrintWriter; import java.io.PrintWriter;
@@ -38,19 +37,16 @@ public class DefaultLoggerTest {
@Test @Test
public void testThrowableMessage() { // #43398 public void testThrowableMessage() { // #43398
BuildException be = new BuildException("oops", new Location("build.xml", 1, 0)); BuildException be = new BuildException("oops", new Location("build.xml", 1, 0));
assertEquals(
"build.xml:1: oops" + StringUtils.LINE_SEP,
msg(be, false));
assertEquals(String.format("build.xml:1: oops%n"), msg(be, false));
be = ProjectHelper.addLocationToBuildException(be, new Location("build.xml", 2, 0)); be = ProjectHelper.addLocationToBuildException(be, new Location("build.xml", 2, 0));
assertEquals(
"build.xml:2: The following error occurred while executing this line:" + StringUtils.LINE_SEP +
"build.xml:1: oops" + StringUtils.LINE_SEP,
msg(be, false));
assertEquals(String.format(
"build.xml:2: The following error occurred while executing this line:%n"
+ "build.xml:1: oops%n"), msg(be, false));
be = ProjectHelper.addLocationToBuildException(be, new Location("build.xml", 3, 0)); be = ProjectHelper.addLocationToBuildException(be, new Location("build.xml", 3, 0));
assertEquals(
"build.xml:3: The following error occurred while executing this line:" + StringUtils.LINE_SEP +
"build.xml:2: The following error occurred while executing this line:" + StringUtils.LINE_SEP +
"build.xml:1: oops" + StringUtils.LINE_SEP,
assertEquals(String.format(
"build.xml:3: The following error occurred while executing this line:%n"
+ "build.xml:2: The following error occurred while executing this line:%n"
+ "build.xml:1: oops%n"),
msg(be, false)); msg(be, false));
Exception x = new Exception("problem") { Exception x = new Exception("problem") {
public void printStackTrace(PrintWriter w) { public void printStackTrace(PrintWriter w) {
@@ -58,21 +54,14 @@ public class DefaultLoggerTest {
w.println(" at p.C.m"); w.println(" at p.C.m");
} }
}; };
assertEquals(
"problem" + StringUtils.LINE_SEP +
" at p.C.m" + StringUtils.LINE_SEP,
msg(x, false));
assertEquals(String.format("problem%n at p.C.m%n"), msg(x, false));

be = new BuildException(x, new Location("build.xml", 1, 0)); be = new BuildException(x, new Location("build.xml", 1, 0));
assertEquals(
"build.xml:1: problem" + StringUtils.LINE_SEP +
" at p.C.m" + StringUtils.LINE_SEP,
msg(be, false));
assertEquals(String.format("build.xml:1: problem%n at p.C.m%n"), msg(be, false));

be = ProjectHelper.addLocationToBuildException(be, new Location("build.xml", 2, 0)); be = ProjectHelper.addLocationToBuildException(be, new Location("build.xml", 2, 0));
assertEquals(
"build.xml:2: The following error occurred while executing this line:" + StringUtils.LINE_SEP +
"build.xml:1: problem" + StringUtils.LINE_SEP +
" at p.C.m" + StringUtils.LINE_SEP,
msg(be, false));
assertEquals(String.format("build.xml:2: The following error occurred while executing this line:%n"
+ "build.xml:1: problem%n at p.C.m%n"), msg(be, false));
} }


} }

+ 22
- 28
src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java View File

@@ -23,7 +23,6 @@ import java.io.IOException;


import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.FileUtilities; import org.apache.tools.ant.FileUtilities;
import org.apache.tools.ant.util.StringUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@@ -38,35 +37,30 @@ import static org.junit.Assert.assertThat;
*/ */
public class ConcatFilterTest { public class ConcatFilterTest {


private static final String lSep = StringUtils.LINE_SEP;

private static final String FILE_PREPEND_WITH =
"this-should-be-the-first-line" + lSep
+ "Line 1" + lSep
+ "Line 2" + lSep
+ "Line 3" + lSep
+ "Line 4" + lSep;

private static final String FILE_PREPEND =
"Line 1" + lSep
+ "Line 2" + lSep
+ "Line 3" + lSep
+ "Line 4" + lSep
+ "Line 5" + lSep;

private static final String FILE_APPEND_WITH =
"Line 57" + lSep
+ "Line 58" + lSep
+ "Line 59" + lSep
+ "Line 60" + lSep
+ "this-should-be-the-last-line" + lSep;
private static final String FILE_PREPEND_WITH = String.format("this-should-be-the-first-line%n"
+ "Line 1%n"
+ "Line 2%n"
+ "Line 3%n"
+ "Line 4%n");

private static final String FILE_PREPEND = String.format("Line 1%n"
+ "Line 2%n"
+ "Line 3%n"
+ "Line 4%n"
+ "Line 5%n");

private static final String FILE_APPEND_WITH = String.format("Line 57%n"
+ "Line 58%n"
+ "Line 59%n"
+ "Line 60%n"
+ "this-should-be-the-last-line%n");


private static final String FILE_APPEND = private static final String FILE_APPEND =
"Line 56" + lSep
+ "Line 57" + lSep
+ "Line 58" + lSep
+ "Line 59" + lSep
+ "Line 60" + lSep;
String.format("Line 56%n"
+ "Line 57%n"
+ "Line 58%n"
+ "Line 59%n"
+ "Line 60%n");


@Rule @Rule
public BuildFileRule buildRule = new BuildFileRule(); public BuildFileRule buildRule = new BuildFileRule();


+ 1
- 2
src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java View File

@@ -41,7 +41,6 @@ import org.apache.tools.ant.types.selectors.modifiedselector.HashvalueAlgorithm;
import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector; import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector;
import org.apache.tools.ant.types.selectors.modifiedselector.PropertiesfileCache; import org.apache.tools.ant.types.selectors.modifiedselector.PropertiesfileCache;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Rule; import org.junit.Rule;
@@ -879,7 +878,7 @@ public class ModifiedSelectorTest {
try { try {
FileWriter out = new FileWriter(file.getAbsolutePath(), true); FileWriter out = new FileWriter(file.getAbsolutePath(), true);
out.write(line); out.write(line);
out.write(StringUtils.LINE_SEP);
out.write(System.lineSeparator());
out.flush(); out.flush();
out.close(); out.close();
} catch (Exception e) { } catch (Exception e) {


+ 31
- 65
src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java View File

@@ -100,8 +100,7 @@ public class DOMElementWriterTest {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
DOMElementWriter w = new DOMElementWriter(); DOMElementWriter w = new DOMElementWriter();
w.write(root, sw, 0, " "); w.write(root, sw, 0, " ");
assertEquals("<root foo=\"bar&#xa;baz\" />" + StringUtils.LINE_SEP,
sw.toString());
assertEquals(String.format("<root foo=\"bar&#xa;baz\" />%n"), sw.toString());
} }


@Test @Test
@@ -147,11 +146,8 @@ public class DOMElementWriterTest {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
DOMElementWriter w = new DOMElementWriter(); DOMElementWriter w = new DOMElementWriter();
w.write(root, sw, 0, " "); w.write(root, sw, 0, " ");
assertEquals("<root>" + StringUtils.LINE_SEP
+ " <textElement>content</textElement>"
+ StringUtils.LINE_SEP
+ "</root>" + StringUtils.LINE_SEP,
sw.toString());
assertEquals(String.format("<root>%n <textElement>content</textElement>%n</root>%n"),
sw.toString());
} }


@Test @Test
@@ -163,11 +159,8 @@ public class DOMElementWriterTest {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
DOMElementWriter w = new DOMElementWriter(); DOMElementWriter w = new DOMElementWriter();
w.write(root, sw, 0, " "); w.write(root, sw, 0, " ");
assertEquals("<root>" + StringUtils.LINE_SEP
+ " <cdataElement><![CDATA[content]]></cdataElement>"
+ StringUtils.LINE_SEP
+ "</root>" + StringUtils.LINE_SEP,
sw.toString());
assertEquals(String.format("<root>%n <cdataElement><![CDATA[content]]></cdataElement>%n"
+ "</root>%n"), sw.toString());
} }


@Test @Test
@@ -179,12 +172,7 @@ public class DOMElementWriterTest {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
DOMElementWriter w = new DOMElementWriter(); DOMElementWriter w = new DOMElementWriter();
w.write(root, sw, 0, " "); w.write(root, sw, 0, " ");
assertEquals("<root>" + StringUtils.LINE_SEP
// + " <emptyElement></emptyElement>"
+ " <emptyElement />"
+ StringUtils.LINE_SEP
+ "</root>" + StringUtils.LINE_SEP,
sw.toString());
assertEquals(String.format("<root>%n <emptyElement />%n</root>%n"), sw.toString());
} }


@Test @Test
@@ -196,8 +184,7 @@ public class DOMElementWriterTest {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
DOMElementWriter w = new DOMElementWriter(); DOMElementWriter w = new DOMElementWriter();
w.write(root, sw, 0, " "); w.write(root, sw, 0, " ");
assertEquals("<root bar=\"baz\" />"
+ StringUtils.LINE_SEP, sw.toString());
assertEquals(String.format("<root bar=\"baz\" />%n"), sw.toString());
} }


@Test @Test
@@ -207,13 +194,10 @@ public class DOMElementWriterTest {
root.setAttributeNS("urn:foo2", "bar", "baz"); root.setAttributeNS("urn:foo2", "bar", "baz");


StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
DOMElementWriter w =
new DOMElementWriter(false,
DOMElementWriter.XmlNamespacePolicy
.ONLY_QUALIFY_ELEMENTS);
DOMElementWriter w = new DOMElementWriter(false,
DOMElementWriter.XmlNamespacePolicy.ONLY_QUALIFY_ELEMENTS);
w.write(root, sw, 0, " "); w.write(root, sw, 0, " ");
assertEquals("<root bar=\"baz\" xmlns=\"urn:foo\" />"
+ StringUtils.LINE_SEP, sw.toString());
assertEquals(String.format("<root bar=\"baz\" xmlns=\"urn:foo\" />%n"), sw.toString());
} }


@Test @Test
@@ -223,14 +207,11 @@ public class DOMElementWriterTest {
root.setAttributeNS("urn:foo2", "bar", "baz"); root.setAttributeNS("urn:foo2", "bar", "baz");


StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
DOMElementWriter w =
new DOMElementWriter(false,
DOMElementWriter.XmlNamespacePolicy
.QUALIFY_ALL);
DOMElementWriter w = new DOMElementWriter(false,
DOMElementWriter.XmlNamespacePolicy.QUALIFY_ALL);
w.write(root, sw, 0, " "); w.write(root, sw, 0, " ");
assertEquals("<root ns0:bar=\"baz\" xmlns=\"urn:foo\""
+ " xmlns:ns0=\"urn:foo2\" />"
+ StringUtils.LINE_SEP, sw.toString());
assertEquals(String.format("<root ns0:bar=\"baz\" xmlns=\"urn:foo\""
+ " xmlns:ns0=\"urn:foo2\" />%n"), sw.toString());
} }


@Test @Test
@@ -240,11 +221,11 @@ public class DOMElementWriterTest {
root.setAttributeNS("urn:foo2", "bar", "baz"); root.setAttributeNS("urn:foo2", "bar", "baz");


StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
DOMElementWriter w =
new DOMElementWriter(false, new DOMElementWriter.XmlNamespacePolicy(false, true));
DOMElementWriter w = new DOMElementWriter(false,
new DOMElementWriter.XmlNamespacePolicy(false, true));
w.write(root, sw, 0, " "); w.write(root, sw, 0, " ");
assertEquals("<root ns0:bar=\"baz\" xmlns:ns0=\"urn:foo2\" />"
+ StringUtils.LINE_SEP, sw.toString());
assertEquals(String.format("<root ns0:bar=\"baz\" xmlns:ns0=\"urn:foo2\" />%n"),
sw.toString());
} }


@Test @Test
@@ -254,17 +235,11 @@ public class DOMElementWriterTest {
Element child = d.createElementNS("urn:foo", "child"); Element child = d.createElementNS("urn:foo", "child");
root.appendChild(child); root.appendChild(child);
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
DOMElementWriter w =
new DOMElementWriter(false,
DOMElementWriter.XmlNamespacePolicy
.ONLY_QUALIFY_ELEMENTS);
DOMElementWriter w = new DOMElementWriter(false,
DOMElementWriter.XmlNamespacePolicy.ONLY_QUALIFY_ELEMENTS);
w.write(root, sw, 0, " "); w.write(root, sw, 0, " ");
assertEquals("<root xmlns=\"urn:foo\">"
+ StringUtils.LINE_SEP
+ " <child />"
+ StringUtils.LINE_SEP
+ "</root>"
+ StringUtils.LINE_SEP, sw.toString());
assertEquals(String.format("<root xmlns=\"urn:foo\">%n <child />%n</root>%n"),
sw.toString());
} }


@Test @Test
@@ -280,24 +255,15 @@ public class DOMElementWriterTest {
Element child3 = d.createElementNS("urn:foo2", "child"); Element child3 = d.createElementNS("urn:foo2", "child");
root.appendChild(child3); root.appendChild(child3);
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
DOMElementWriter w =
new DOMElementWriter(false,
DOMElementWriter.XmlNamespacePolicy
.ONLY_QUALIFY_ELEMENTS);
DOMElementWriter w = new DOMElementWriter(false,
DOMElementWriter.XmlNamespacePolicy.ONLY_QUALIFY_ELEMENTS);
w.write(root, sw, 0, " "); w.write(root, sw, 0, " ");
assertEquals("<root xmlns=\"urn:foo\">"
+ StringUtils.LINE_SEP
+ " <ns0:child xmlns:ns0=\"urn:foo2\" />"
+ StringUtils.LINE_SEP
+ " <ns1:child xmlns:ns1=\"urn:foo2\">"
+ StringUtils.LINE_SEP
+ " <ns1:grandchild />"
+ StringUtils.LINE_SEP
+ " </ns1:child>"
+ StringUtils.LINE_SEP
+ " <ns2:child xmlns:ns2=\"urn:foo2\" />"
+ StringUtils.LINE_SEP
+ "</root>"
+ StringUtils.LINE_SEP, sw.toString());
assertEquals(String.format("<root xmlns=\"urn:foo\">%n"
+ " <ns0:child xmlns:ns0=\"urn:foo2\" />%n"
+ " <ns1:child xmlns:ns1=\"urn:foo2\">%n"
+ " <ns1:grandchild />%n"
+ " </ns1:child>%n"
+ " <ns2:child xmlns:ns2=\"urn:foo2\" />%n"
+ "</root>%n"), sw.toString());
} }
} }

Loading…
Cancel
Save