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 int maxlen) {
// 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
StringBuilder spaces = new StringBuilder(" ");
while (spaces.length() <= maxlen) {
spaces.append(spaces);
}
final StringBuilder msg = new StringBuilder();
msg.append(heading).append(lSep).append(lSep);
msg.append(heading).append(eol).append(eol);
final int size = names.size();
for (int i = 0; i < size; i++) {
msg.append(" ");
@@ -1286,7 +1286,7 @@ public class Main implements AntMain {
spaces.substring(0, maxlen - names.elementAt(i).length() + 2));
msg.append(descriptions.elementAt(i));
}
msg.append(lSep);
msg.append(eol);
if (!dependencies.isEmpty()) {
final Enumeration<String> deps = dependencies.elementAt(i);
if (deps.hasMoreElements()) {
@@ -1297,7 +1297,7 @@ public class Main implements AntMain {
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;

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

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

synchronized (this) {
if (null != targetName) {
out.println(StringUtils.LINE_SEP + targetName + ":");
out.println(String.format("%n%s:", targetName));
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.FileUtils;
import org.apache.tools.ant.util.JavaEnvUtils;
import org.apache.tools.ant.util.StringUtils;
import org.apache.tools.ant.util.VectorSet;

/**
@@ -2222,8 +2221,8 @@ public class Project implements ResourceFactory {
if (message == null) {
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);
} else {
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;

import java.io.File;

import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.Project;
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
@@ -120,18 +117,11 @@ public class BigProjectLogger extends SimpleBigProjectLogger
* @param event An event with any relevant extra information. Must not be <code>null</code>.
*/
public void subBuildStarted(BuildEvent event) {
String name = extractNameOrDefault(event);
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,
event.getPriority());
}
@@ -154,12 +144,9 @@ public class BigProjectLogger extends SimpleBigProjectLogger

/** {@inheritDoc} */
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,
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.DateUtils;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;
import org.apache.tools.mail.MailMessage;

/**
@@ -313,7 +312,7 @@ public class MailLogger extends DefaultLogger {
*/
@Override
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.DefaultLogger;
import org.apache.tools.ant.util.StringUtils;

/**
* This is a special logger that is designed to profile builds.
@@ -97,18 +96,17 @@ public class ProfileLogger extends DefaultLogger {
String msg;
if (start != null) {
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 {
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());
log(msg);
}

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());
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.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Vector;
import java.util.stream.Collectors;

import org.apache.tools.ant.BuildException;
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.Environment;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;

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

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) {
if (failOnError) {
@@ -422,19 +420,10 @@ public abstract class AbstractCvsTask extends Task {
.getCommandline());
StringBuilder buf = removeCvsPassword(cmdLine);

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

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();


+ 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(">").append(System.lineSeparator());
sb.append(String.format(">%n"));
out.println(sb);

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.Task;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;

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

while ((line = reader.readLine()) != null) {
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.selectors.Type;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;

/**
* Used to create or verify file checksums.
@@ -392,8 +391,7 @@ public class Checksum extends MatchingTask implements Condition {
try {
if (resources != null) {
for (Resource r : resources) {
File src = r.as(FileProvider.class)
.getFile();
File src = r.as(FileProvider.class).getFile();
if (totalproperty != null || todir != null) {
// Use '/' to calculate digest based on file name.
// This is required in order to get the same result
@@ -537,7 +535,7 @@ public class Checksum extends MatchingTask implements Condition {
src),
src.getAbsolutePath()
}).getBytes());
fos.write(StringUtils.LINE_SEP.getBytes());
fos.write(System.lineSeparator().getBytes());
fos.close();
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.ReaderInputStream;
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
@@ -525,7 +524,7 @@ public class Concat extends Task implements ResourceCollection {
binary = false;
outputWriter = null;
textBuffer = null;
eolString = StringUtils.LINE_SEP;
eolString = System.lineSeparator();
rc = null;
ignoreEmpty = true;
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")) {
message.append(String.format(
"%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();
}


+ 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.Project;
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..
@@ -61,15 +63,10 @@ public class DefaultExcludes extends Task {
DirectoryScanner.removeDefaultExclude(remove);
}
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.StringResource;
import org.apache.tools.ant.util.ResourceUtils;
import org.apache.tools.ant.util.StringUtils;

/**
* Writes a message to the Ant logging facilities.
@@ -63,7 +62,7 @@ public class Echo extends Task {
public void execute() throws BuildException {
try {
ResourceUtils.copyResource(
new StringResource(message.isEmpty() ? StringUtils.LINE_SEP : message),
new StringResource(message.isEmpty() ? System.lineSeparator() : message),
output == null ? new LogOutputResource(this, logLevel) : output,
null, null, false, false, append, null,
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.types.Commandline;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;

/**
* Runs an external program.
@@ -150,9 +149,9 @@ public class Execute {
// Chunk part of previous env var (UNIX env vars can
// contain embedded new lines).
if (var == null) {
var = new StringBuilder(StringUtils.LINE_SEP + line);
var = new StringBuilder(System.lineSeparator() + line);
} 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.util.FileUtils;
import org.apache.tools.ant.util.JavaEnvUtils;
import org.apache.tools.ant.util.StringUtils;

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

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

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.TaskContainer;
import org.apache.tools.ant.property.LocalProperties;
import org.apache.tools.ant.util.StringUtils;

/**
* Executes the contained tasks in separate threads, continuing
@@ -243,7 +242,7 @@ public class Parallel extends Task
// location should match the exit status
firstLocation = ex.getLocation();
}
exceptionMessage.append(StringUtils.LINE_SEP);
exceptionMessage.append(System.lineSeparator());
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.SubBuildListener;
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
@@ -108,10 +107,9 @@ public class RecorderEntry implements BuildLogger, SubBuildListener {
Throwable error = event.getException();

if (error == null) {
out.println(StringUtils.LINE_SEP + "BUILD SUCCESSFUL");
out.println(String.format("%nBUILD SUCCESSFUL"));
} else {
out.println(StringUtils.LINE_SEP + "BUILD FAILED"
+ StringUtils.LINE_SEP);
out.println(String.format("%nBUILD FAILED%n"));
error.printStackTrace(out); //NOSONAR
}
}
@@ -149,8 +147,7 @@ public class RecorderEntry implements BuildLogger, SubBuildListener {
*/
public void targetStarted(BuildEvent event) {
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();
}



+ 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.util.Arrays;
import java.util.Vector;
import java.util.stream.Collectors;

import org.apache.tools.ant.BuildException;
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.OutputStreamFunneler;
import org.apache.tools.ant.util.ReaderInputStream;
import org.apache.tools.ant.util.StringUtils;
import org.apache.tools.ant.util.TeeOutputStream;

/**
@@ -549,24 +549,12 @@ public class Redirector {
* contains the property value.
* @param propertyName
* the property name.
*
* @exception IOException
* if the value cannot be read form the stream.
*/
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.Union;
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
@@ -501,10 +500,10 @@ public class Replace extends MatchingTask {
// as needed
StringBuilder val = new StringBuilder(value.getText());
stringReplace(val, "\r\n", "\n");
stringReplace(val, "\n", StringUtils.LINE_SEP);
stringReplace(val, "\n", System.lineSeparator());
StringBuilder tok = new StringBuilder(token.getText());
stringReplace(tok, "\r\n", "\n");
stringReplace(tok, "\n", StringUtils.LINE_SEP);
stringReplace(tok, "\n", System.lineSeparator());
Replacefilter firstFilter = createPrimaryfilter();
firstFilter.setToken(tok.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.Task;
import org.apache.tools.ant.TaskContainer;
import org.apache.tools.ant.util.StringUtils;

/**
* 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...";
}
log(msg, e, Project.MSG_INFO);
errorMessages.append(StringUtils.LINE_SEP);
errorMessages.append(System.lineSeparator());
if (retryDelay > 0) {
try {
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)
.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.Module;
import org.apache.tools.ant.util.StringUtils;

/**
* A class used to parse the output of the CVS log command.
@@ -151,18 +150,16 @@ class ChangeLogParser {
.equals(line)) {
//We have ended changelog for that particular file
//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);
saveEntry();
status = GET_FILE;
} 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);
status = GET_PREVIOUS_REV;
} 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);
}
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) {


+ 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(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
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()) {
String joinedValue = schemaLocations.values().stream()
.map(SchemaLocation::getURIandLocation)
.peek(
tuple -> log("Adding schema " + tuple, Project.MSG_VERBOSE))
.peek(tuple -> log("Adding schema " + tuple, Project.MSG_VERBOSE))
.collect(Collectors.joining(" "));

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 org.apache.tools.ant.util.DeweyDecimal;
import org.apache.tools.ant.util.StringUtils;

/**
* <p>Utility class that represents either an available "Optional Package"
@@ -478,53 +477,33 @@ public final class Extension {
*/
@Override
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) {
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) {
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) {
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) {
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) {
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) {
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();


+ 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 org.apache.tools.ant.util.DeweyDecimal;
import org.apache.tools.ant.util.StringUtils;

/**
* <p>Utility class that represents either an available "Optional Package"
@@ -174,8 +173,7 @@ public final class Specification {
}
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()))
.ifPresent(results::add);
}
@@ -373,48 +371,31 @@ public final class Specification {
*/
@Override
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) {
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) {
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) {
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) {
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) {
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();
}

@@ -455,7 +436,7 @@ public final class Specification {
}
}
results.add(mergeInSections(specification, sections));
//Reset list of sections
// Reset list of sections
sections.clear();
}
return results;
@@ -493,12 +474,8 @@ public final class Specification {
if (sectionsToAdd.isEmpty()) {
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(),
specification.getSpecificationVersion().toString(),
@@ -530,38 +507,32 @@ public final class Specification {
//WARNING: We trim the values of all the attributes because
//Some extension declarations are badly defined (ie have spaces
//after version or vendor)
final String name
= getTrimmedString(attributes.getValue(SPECIFICATION_TITLE));
final String name = getTrimmedString(attributes.getValue(SPECIFICATION_TITLE));
if (null == name) {
return null;
}

final String specVendor
= getTrimmedString(attributes.getValue(SPECIFICATION_VENDOR));
final String specVendor = getTrimmedString(attributes.getValue(SPECIFICATION_VENDOR));
if (null == specVendor) {
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) {
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) {
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) {
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) {
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()
.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",
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.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;

/**
* 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.
}
try {
output.write("Testsuite: " + suite.getName() + StringUtils.LINE_SEP);
output.write(String.format("Testsuite: %s%n", suite.getName()));
output.flush();
} catch (IOException ex) {
throw new BuildException(ex);
@@ -147,25 +146,19 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter, IgnoredT
sb.append(suite.skipCount());
sb.append(", Time elapsed: ");
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
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()) {
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) {


+ 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 {
for (i = 0; i < numThreads; i++) {
threads[i].join();
threads[i].join();
}
} catch (final InterruptedException e) {
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.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;


/**
* 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.
}
try {
out.write(("Testsuite: " + suite.getName() +
StringUtils.LINE_SEP).getBytes());
out.write(String.format("Testsuite: %s%n",suite.getName()).getBytes());
out.flush();
} catch (IOException 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
if (systemOutput != null && !systemOutput.isEmpty()) {
write("------------- Standard Output ---------------");
write(StringUtils.LINE_SEP);
write(String.format("------------- Standard Output ---------------%n"));
write(systemOutput);
write("------------- ---------------- ---------------");
write(StringUtils.LINE_SEP);
write(String.format("------------- ---------------- ---------------%n"));
}

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

write(StringUtils.LINE_SEP);
write(System.lineSeparator());
if (out != null) {
try {
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) {
StringTokenizer tokenizer = new StringTokenizer(thePath,
File.separator);
String[] path = new String[ tokenizer.countTokens() ];
String[] path = new String[tokenizer.countTokens()];

int i = 0;
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<>();
for (Resource r : rc) {
if (!r.isExists()) {
if (!r.isExists()) {
throw new BuildException("Could not find resource %s to scp.",
r.toLongString());
r.toLongString());
}

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

FileResource fr = ResourceUtils.asFileResource(fp);
File baseDir = fr.getBaseDir();
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


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

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

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

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

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

//Strip '.' token
if (tokenizer.hasMoreTokens()) {
@@ -94,7 +94,7 @@ public class DeweyDecimal implements Comparable<DeweyDecimal> {
* @return the value of component at 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);

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) {
return false;
@@ -152,8 +152,8 @@ public class DeweyDecimal implements Comparable<DeweyDecimal> {
final int max = Math.max(other.components.length, components.length);

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) {
return false;
@@ -177,8 +177,8 @@ public class DeweyDecimal implements Comparable<DeweyDecimal> {
final int max = Math.max(other.components.length, components.length);

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) {
return false;
@@ -212,8 +212,8 @@ public class DeweyDecimal implements Comparable<DeweyDecimal> {
public int compareTo(DeweyDecimal other) {
final int max = Math.max(other.components.length, components.length);
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) {
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 {
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
@@ -266,7 +266,7 @@ public class LayoutPreservingProperties extends Properties {
final int totalLines = logicalLines.size();

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

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

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

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

if (ch == '\r') {
LS = "\r";
eol = "\r";
hasCR = true;
} else if (ch == '\n') {
LS = hasCR ? "\r\n" : "\n";
eol = hasCR ? "\r\n" : "\n";
break;
} else {
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 */
@Deprecated
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.Date;
import java.util.List;
import java.util.NoSuchElementException;
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) {
if (extraFields == null) {
throw new java.util.NoSuchElementException();
throw new NoSuchElementException();
}
List<ZipExtraField> newResult = new ArrayList<>();
for (ZipExtraField extraField : extraFields) {
@@ -464,7 +465,7 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable {
}
}
if (extraFields.length == newResult.size()) {
throw new java.util.NoSuchElementException();
throw new NoSuchElementException();
}
extraFields = newResult.toArray(new ZipExtraField[newResult.size()]);
setExtra();
@@ -475,7 +476,7 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable {
*/
public void removeUnparseableExtraFieldData() {
if (unparseableExtra == null) {
throw new java.util.NoSuchElementException();
throw new NoSuchElementException();
}
unparseableExtra = null;
setExtra();
@@ -744,8 +745,7 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable {
addExtraField(element);
} else {
if (local
|| !(existing
instanceof CentralDirectoryParsingZipExtraField)) {
|| !(existing instanceof CentralDirectoryParsingZipExtraField)) {
final byte[] b = element.getLocalFileDataData();
existing.parseFromLocalFileData(b, 0, b.length);
} else {


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

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

package org.apache.tools.ant;

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

import java.io.PrintWriter;
@@ -38,19 +37,16 @@ public class DefaultLoggerTest {
@Test
public void testThrowableMessage() { // #43398
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));
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));
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));
Exception x = new Exception("problem") {
public void printStackTrace(PrintWriter w) {
@@ -58,21 +54,14 @@ public class DefaultLoggerTest {
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));
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));
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.FileUtilities;
import org.apache.tools.ant.util.StringUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -38,35 +37,30 @@ import static org.junit.Assert.assertThat;
*/
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 =
"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
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.PropertiesfileCache;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
@@ -879,7 +878,7 @@ public class ModifiedSelectorTest {
try {
FileWriter out = new FileWriter(file.getAbsolutePath(), true);
out.write(line);
out.write(StringUtils.LINE_SEP);
out.write(System.lineSeparator());
out.flush();
out.close();
} 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();
DOMElementWriter w = new DOMElementWriter();
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
@@ -147,11 +146,8 @@ public class DOMElementWriterTest {
StringWriter sw = new StringWriter();
DOMElementWriter w = new DOMElementWriter();
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
@@ -163,11 +159,8 @@ public class DOMElementWriterTest {
StringWriter sw = new StringWriter();
DOMElementWriter w = new DOMElementWriter();
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
@@ -179,12 +172,7 @@ public class DOMElementWriterTest {
StringWriter sw = new StringWriter();
DOMElementWriter w = new DOMElementWriter();
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
@@ -196,8 +184,7 @@ public class DOMElementWriterTest {
StringWriter sw = new StringWriter();
DOMElementWriter w = new DOMElementWriter();
w.write(root, sw, 0, " ");
assertEquals("<root bar=\"baz\" />"
+ StringUtils.LINE_SEP, sw.toString());
assertEquals(String.format("<root bar=\"baz\" />%n"), sw.toString());
}

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

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, " ");
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
@@ -223,14 +207,11 @@ public class DOMElementWriterTest {
root.setAttributeNS("urn:foo2", "bar", "baz");

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, " ");
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
@@ -240,11 +221,11 @@ public class DOMElementWriterTest {
root.setAttributeNS("urn:foo2", "bar", "baz");

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, " ");
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
@@ -254,17 +235,11 @@ public class DOMElementWriterTest {
Element child = d.createElementNS("urn:foo", "child");
root.appendChild(child);
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, " ");
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
@@ -280,24 +255,15 @@ public class DOMElementWriterTest {
Element child3 = d.createElementNS("urn:foo2", "child");
root.appendChild(child3);
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, " ");
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