Browse Source

Avoid line.separator

master
Gintas Grigelionis 7 years ago
parent
commit
845c2c5b39
22 changed files with 58 additions and 109 deletions
  1. +2
    -1
      src/main/org/apache/tools/ant/DefaultLogger.java
  2. +1
    -1
      src/main/org/apache/tools/ant/Main.java
  3. +2
    -4
      src/main/org/apache/tools/ant/ProjectHelper.java
  4. +3
    -7
      src/main/org/apache/tools/ant/TaskConfigurationChecker.java
  5. +1
    -7
      src/main/org/apache/tools/ant/filters/util/JavaClassHelper.java
  6. +8
    -16
      src/main/org/apache/tools/ant/taskdefs/AntStructure.java
  7. +7
    -7
      src/main/org/apache/tools/ant/taskdefs/Copy.java
  8. +1
    -4
      src/main/org/apache/tools/ant/taskdefs/Jar.java
  9. +1
    -0
      src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
  10. +4
    -4
      src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java
  11. +1
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/NetRexxC.java
  12. +4
    -7
      src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/DefaultJspCompilerAdapter.java
  13. +4
    -7
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  14. +5
    -9
      src/main/org/apache/tools/ant/taskdefs/optional/junit/SummaryJUnitResultFormatter.java
  15. +0
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/AbstractJUnitResultFormatter.java
  16. +1
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyPlainResultFormatter.java
  17. +5
    -13
      src/main/org/apache/tools/ant/types/Commandline.java
  18. +3
    -5
      src/main/org/apache/tools/ant/util/DOMElementWriter.java
  19. +2
    -7
      src/main/org/apache/tools/ant/util/LineOrientedOutputStreamRedirector.java
  20. +1
    -1
      src/main/org/apache/tools/ant/util/StringUtils.java
  21. +1
    -1
      src/tests/junit/org/apache/tools/ant/taskdefs/CVSPassTest.java
  22. +1
    -1
      src/tests/junit/org/apache/tools/ant/taskdefs/ConcatTest.java

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

@@ -58,6 +58,7 @@ public class DefaultLogger implements BuildLogger {

// CheckStyle:ConstantNameCheck OFF - bc
/** Line separator */
@Deprecated
protected static final String lSep = StringUtils.LINE_SEP;
// CheckStyle:ConstantNameCheck ON

@@ -149,7 +150,7 @@ public class DefaultLogger implements BuildLogger {
if (verbose || !(error instanceof BuildException)) {
m.append(StringUtils.getStackTrace(error));
} else {
m.append(error).append(lSep);
m.append(error).append(StringUtils.LINE_SEP);
}
}



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

@@ -1269,7 +1269,7 @@ public class Main implements AntMain {
final String heading,
final int maxlen) {
// now, start printing the targets and their descriptions
final String lSep = System.getProperty("line.separator");
final String lSep = System.lineSeparator();
// got a bit annoyed that I couldn't find a pad function
StringBuilder spaces = new StringBuilder(" ");
while (spaces.length() <= maxlen) {


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

@@ -556,10 +556,8 @@ public class ProjectHelper {
return ex;
}
String errorMessage
= "The following error occurred while executing this line:"
+ System.getProperty("line.separator")
+ ex.getLocation().toString()
+ ex.getMessage();
= String.format("The following error occurred while executing this line:%n%s%s",
ex.getLocation().toString(), ex.getMessage());
if (ex instanceof ExitStatusException) {
int exitStatus = ((ExitStatusException) ex).getStatus();
if (newLocation == null) {


+ 3
- 7
src/main/org/apache/tools/ant/TaskConfigurationChecker.java View File

@@ -94,14 +94,10 @@ public class TaskConfigurationChecker {
*/
public void checkErrors() throws BuildException {
if (!errors.isEmpty()) {
StringBuilder sb = new StringBuilder("Configuration error on <");
sb.append(task.getTaskName());
sb.append(">:");
sb.append(System.getProperty("line.separator"));
StringBuilder sb = new StringBuilder(String.format("Configuration error on <%s>:%n",
task.getTaskName()));
for (String msg : errors) {
sb.append("- ");
sb.append(msg);
sb.append(System.getProperty("line.separator"));
sb.append(String.format("- %s%n", msg));
}
throw new BuildException(sb.toString(), task.getLocation());
}


+ 1
- 7
src/main/org/apache/tools/ant/filters/util/JavaClassHelper.java View File

@@ -31,9 +31,6 @@ import org.apache.bcel.classfile.JavaClass;
*
*/
public final class JavaClassHelper {
/** System specific line separator. */
private static final String LS = System.getProperty("line.separator");

/**
* Get the constants declared in a file as name=value
*
@@ -55,10 +52,7 @@ public final class JavaClassHelper {
if (cvs.startsWith("\"") && cvs.endsWith("\"")) {
cvs = cvs.substring(1, cvs.length() - 1);
}
sb.append(field.getName());
sb.append('=');
sb.append(cvs);
sb.append(LS);
sb.append(String.format("%s=%s%n", field.getName(), cvs));
}
}
}


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

@@ -54,9 +54,6 @@ import org.apache.tools.ant.util.FileUtils;
*/
public class AntStructure extends Task {

private static final String LINE_SEP
= System.getProperty("line.separator");

private File output;
private StructurePrinter printer = new DTDPrinter();

@@ -293,15 +290,12 @@ public class AntStructure extends Task {
return;
}

StringBuilder sb =
new StringBuilder("<!ELEMENT ").append(name).append(" ");
StringBuilder sb = new StringBuilder("<!ELEMENT ").append(name).append(" ");

if (Reference.class.equals(element)) {
sb.append("EMPTY>").append(LINE_SEP);
sb.append("<!ATTLIST ").append(name);
sb.append(LINE_SEP).append(" id ID #IMPLIED");
sb.append(LINE_SEP).append(" refid IDREF #IMPLIED");
sb.append(">").append(LINE_SEP);
sb.append(String.format("EMPTY>%n<!ATTLIST %s%n"
+ " id ID #IMPLIED%n refid IDREF #IMPLIED>%n",
name));
out.println(sb);
return;
}
@@ -334,9 +328,8 @@ public class AntStructure extends Task {
sb.append(">");
out.println(sb);

sb = new StringBuilder("<!ATTLIST ");
sb.append(name);
sb.append(LINE_SEP).append(" id ID #IMPLIED");
sb = new StringBuilder();
sb.append(String.format("<!ATTLIST %s%n id ID #IMPLIED", name));

e = ih.getAttributes();
while (e.hasMoreElements()) {
@@ -345,8 +338,7 @@ public class AntStructure extends Task {
continue;
}

sb.append(LINE_SEP).append(" ")
.append(attrName).append(" ");
sb.append(String.format("%n %s ", attrName));
final Class<?> type = ih.getAttributeType(attrName);
if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
sb.append(BOOLEAN).append(" ");
@@ -384,7 +376,7 @@ public class AntStructure extends Task {
}
sb.append("#IMPLIED");
}
sb.append(">").append(LINE_SEP);
sb.append(">").append(System.lineSeparator());
out.println(sb);

for (String nestedName : v) {


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

@@ -50,6 +50,7 @@ import org.apache.tools.ant.util.IdentityMapper;
import org.apache.tools.ant.util.LinkedHashtable;
import org.apache.tools.ant.util.ResourceUtils;
import org.apache.tools.ant.util.SourceFileScanner;
import org.apache.tools.ant.util.StringUtils;

/**
* <p>Copies a file or directory to a new file
@@ -70,8 +71,9 @@ public class Copy extends Task {
private static final String MSG_WHEN_COPYING_EMPTY_RC_TO_FILE =
"Cannot perform operation from directory to file.";

@Deprecated
static final String LINE_SEPARATOR = StringUtils.LINE_SEP;
static final File NULL_FILE_PLACEHOLDER = new File("/NULL_FILE");
static final String LINE_SEPARATOR = System.getProperty("line.separator");
// CheckStyle:VisibilityModifier OFF - bc
protected File file = null; // the source file
protected File destFile = null; // the destination file
@@ -1083,15 +1085,13 @@ public class Copy extends Task {
message.append(ex.getMessage());
}
if (ex.getClass().getName().contains("MalformedInput")) {
message.append(LINE_SEPARATOR);
message.append(
"This is normally due to the input file containing invalid");
message.append(LINE_SEPARATOR);
message.append("bytes for the character encoding used : ");
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(LINE_SEPARATOR);
message.append(System.lineSeparator());
}
return message.toString();
}


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

@@ -906,7 +906,6 @@ public class Jar extends Zip {
*/
// CheckStyle:LineLength ON
private void checkJarSpec() {
String br = System.getProperty("line.separator");
StringBuilder message = new StringBuilder();
Section mainSection = (configuredManifest == null)
? null
@@ -929,9 +928,7 @@ public class Jar extends Zip {
}

if (message.length() > 0) {
message.append(br);
message.append("Location: ").append(getLocation());
message.append(br);
message.append(String.format("%nLocation: %s%n", getLocation()));
if ("fail".equalsIgnoreCase(strict.getValue())) {
throw new BuildException(message.toString(), getLocation());
}


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

@@ -63,6 +63,7 @@ public abstract class DefaultCompilerAdapter

//must keep for subclass BC, though unused:
// CheckStyle:ConstantNameCheck OFF - bc
@Deprecated
protected static final String lSep = StringUtils.LINE_SEP;
// CheckStyle:ConstantNameCheck ON



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

@@ -31,6 +31,7 @@ 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.
@@ -146,23 +147,22 @@ class ChangeLogParser {
* @param line the line
*/
private void processComment(final String line) {
final String lineSeparator = System.getProperty("line.separator");
if ("============================================================================="
.equals(line)) {
//We have ended changelog for that particular file
//so we can save it
final int end
= comment.length() - lineSeparator.length(); //was -1
= comment.length() - StringUtils.LINE_SEP.length(); //was -1
comment = comment.substring(0, end);
saveEntry();
status = GET_FILE;
} else if ("----------------------------".equals(line)) {
final int end
= comment.length() - lineSeparator.length(); //was -1
= comment.length() - StringUtils.LINE_SEP.length(); //was -1
comment = comment.substring(0, end);
status = GET_PREVIOUS_REV;
} else {
comment += line + lineSeparator;
comment += line + StringUtils.LINE_SEP;
}
}



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

@@ -777,9 +777,7 @@ public class NetRexxC extends MatchingTask {

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

final String eol = System.getProperty("line.separator");
log(
compileList.stream().map(s -> " " + s).collect(Collectors.joining(eol)),
log(compileList.stream().map(s -> " " + s).collect(Collectors.joining(System.lineSeparator())),
Project.MSG_VERBOSE);

// create a single array of arguments for the compiler


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

@@ -35,8 +35,6 @@ import org.apache.tools.ant.types.CommandlineJava;
public abstract class DefaultJspCompilerAdapter
implements JspCompilerAdapter {

private static String lSep = System.lineSeparator();

/**
* Logs the compilation parameters, adds the files to compile and logs the
* &quot;niceSourceList&quot;
@@ -50,13 +48,12 @@ public abstract class DefaultJspCompilerAdapter
jspc.log("Compilation " + cmd.describeJavaCommand(),
Project.MSG_VERBOSE);

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

// CheckStyle:VisibilityModifier OFF - bc


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

@@ -133,8 +133,6 @@ import org.apache.tools.ant.util.StringUtils;
*/
public class JUnitTask extends Task {

private static final String LINE_SEP
= System.getProperty("line.separator");
private static final String CLASSPATH = "CLASSPATH";

private static final int STRING_BUFFER_SIZE = 128;
@@ -1381,11 +1379,10 @@ public class JUnitTask extends Task {
e.hasMoreElements();) {
final URL current = e.nextElement();
if (previous != null && !urlEquals(current, previous)) {
log("WARNING: multiple versions of ant detected "
+ "in path for junit "
+ LINE_SEP + " " + previous
+ LINE_SEP + " and " + current,
Project.MSG_WARN);
log(String.format(
"WARNING: multiple versions of ant detected in path for junit%n"
+ " %s%n and %s", previous, current),
Project.MSG_WARN);
return;
}
previous = current;


+ 5
- 9
src/main/org/apache/tools/ant/taskdefs/optional/junit/SummaryJUnitResultFormatter.java View File

@@ -77,7 +77,6 @@ public class SummaryJUnitResultFormatter
*/
@Override
public void startTestSuite(JUnitTest suite) {
String newLine = System.getProperty("line.separator");
StringBuilder sb = new StringBuilder("Running ");
int antThreadID = suite.getThread();

@@ -87,7 +86,7 @@ public class SummaryJUnitResultFormatter
sb.append(" in thread ");
sb.append(antThreadID);
}
sb.append(newLine);
sb.append(System.lineSeparator());
writeOutputLine(sb.toString().getBytes());
}
/**
@@ -166,8 +165,7 @@ public class SummaryJUnitResultFormatter
*/
@Override
public void endTestSuite(JUnitTest suite) throws BuildException {
String newLine = System.getProperty("line.separator");
StringBuilder sb = new StringBuilder("Tests run: ");
StringBuilder sb = new StringBuilder("Tests run: ");
sb.append(suite.runCount());
sb.append(", Failures: ");
sb.append(suite.failureCount());
@@ -189,17 +187,15 @@ public class SummaryJUnitResultFormatter
sb.append(", Class: ");
sb.append(suite.getName());
}
sb.append(newLine);
sb.append(System.lineSeparator());

if (withOutAndErr) {
if (systemOutput != null && systemOutput.length() > 0) {
sb.append("Output:").append(newLine).append(systemOutput)
.append(newLine);
sb.append(String.format("Output:%n%s%n", systemOutput));
}

if (systemError != null && systemError.length() > 0) {
sb.append("Error: ").append(newLine).append(systemError)
.append(newLine);
sb.append(String.format("Output:%n%s%n", systemError));
}
}



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

@@ -28,8 +28,6 @@ import java.util.Optional;
*/
abstract class AbstractJUnitResultFormatter implements TestResultFormatter {


protected static String NEW_LINE = System.getProperty("line.separator");
protected TestExecutionContext context;

private SysOutErrContentStore sysOutStore;


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

@@ -258,8 +258,7 @@ class LegacyPlainResultFormatter extends AbstractJUnitResultFormatter implements
return;
}
final Throwable throwable = result.getThrowable().get();
sb.append(": ").append(throwable.getMessage());
sb.append(NEW_LINE);
sb.append(String.format(": %s%n", throwable.getMessage()));
final StringWriter stacktrace = new StringWriter();
throwable.printStackTrace(new PrintWriter(stacktrace));
sb.append(stacktrace.toString());


+ 5
- 13
src/main/org/apache/tools/ant/types/Commandline.java View File

@@ -66,12 +66,8 @@ public class Commandline implements Cloneable {
*/
private String executable = null;

protected static final String DISCLAIMER =
StringUtils.LINE_SEP
+ "The \' characters around the executable and arguments are"
+ StringUtils.LINE_SEP
+ "not part of the command."
+ StringUtils.LINE_SEP;
protected static final String DISCLAIMER = String.format(
"%nThe ' characters around the executable and arguments are%nnot part of the command.%n");

/**
* Create a command line from a string.
@@ -676,14 +672,10 @@ public class Commandline implements Cloneable {
if (args == null || args.length <= offset) {
return "";
}
StringBuilder buf = new StringBuilder("argument");
if (args.length > offset) {
buf.append("s");
}
buf.append(":").append(StringUtils.LINE_SEP);
StringBuilder buf = new StringBuilder();
buf.append(String.format("argument%s:%n", args.length > offset ? "s" : ""));
for (int i = offset; i < args.length; i++) {
buf.append("\'").append(args[i]).append("\'")
.append(StringUtils.LINE_SEP);
buf.append(String.format("\'%s\'%n", args[i]));
}
buf.append(DISCLAIMER);
return buf.toString();


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

@@ -151,8 +151,6 @@ public class DOMElementWriter {
this.namespacePolicy = namespacePolicy;
}

private static String lSep = System.getProperty("line.separator");

// CheckStyle:VisibilityModifier OFF - bc
/**
* Don't try to be too smart but at least recognize the predefined
@@ -219,7 +217,7 @@ public class DOMElementWriter {
case Node.ELEMENT_NODE:
hasChildElements = true;
if (i == 0) {
out.write(lSep);
out.write(StringUtils.LINE_SEP);
}
write((Element) child, out, indent + 1, indentWith);
break;
@@ -367,7 +365,7 @@ public class DOMElementWriter {
} else {
removeNSDefinitions(element);
out.write(" />");
out.write(lSep);
out.write(StringUtils.LINE_SEP);
out.flush();
}
}
@@ -408,7 +406,7 @@ public class DOMElementWriter {
}
out.write(element.getTagName());
out.write(">");
out.write(lSep);
out.write(StringUtils.LINE_SEP);
out.flush();
}



+ 2
- 7
src/main/org/apache/tools/ant/util/LineOrientedOutputStreamRedirector.java View File

@@ -34,11 +34,6 @@ public class LineOrientedOutputStreamRedirector

private OutputStream stream;

// these should be in the ASCII range and hopefully are single bytes
// (for LF and CR respectively) for any encoding thrown at this class
private static final byte[] EOL =
System.getProperty("line.separator").getBytes();

public LineOrientedOutputStreamRedirector(OutputStream stream) {
this.stream = stream;
}
@@ -46,12 +41,12 @@ public class LineOrientedOutputStreamRedirector
@Override
protected void processLine(byte[] b) throws IOException {
stream.write(b);
stream.write(EOL);
stream.write(System.lineSeparator().getBytes());
}

@Override
protected void processLine(String line) throws IOException {
stream.write((line + System.getProperty("line.separator")).getBytes());
stream.write(String.format("%s%n", line).getBytes());
}

@Override


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

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

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

/**
* Splits up a string into a list of lines. It is equivalent


+ 1
- 1
src/tests/junit/org/apache/tools/ant/taskdefs/CVSPassTest.java View File

@@ -37,7 +37,7 @@ import static org.junit.Assert.fail;
*
*/
public class CVSPassTest {
private final String EOL = System.getProperty("line.separator");
private final String EOL = System.lineSeparator();
private static final String JAKARTA_URL =
":pserver:anoncvs@jakarta.apache.org:/home/cvspublic Ay=0=h<Z";
private static final String XML_URL =


+ 1
- 1
src/tests/junit/org/apache/tools/ant/taskdefs/ConcatTest.java View File

@@ -270,7 +270,7 @@ public class ConcatTest {
@Test
public void testfixlastline() throws IOException {
buildRule.executeTarget("testfixlastline");
assertContains("end of line" + System.getProperty("line.separator") + "This has",
assertContains("end of line" + System.lineSeparator() + "This has",
FileUtilities.getFileContents(buildRule.getProject(), "concat.line4"));
}



Loading…
Cancel
Save