| @@ -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); | |||
| } | |||
| } | |||
| @@ -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) { | |||
| @@ -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) { | |||
| @@ -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()); | |||
| } | |||
| @@ -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)); | |||
| } | |||
| } | |||
| } | |||
| @@ -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) { | |||
| @@ -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(); | |||
| } | |||
| @@ -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()); | |||
| } | |||
| @@ -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 | |||
| @@ -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; | |||
| } | |||
| } | |||
| @@ -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 | |||
| @@ -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 | |||
| * "niceSourceList" | |||
| @@ -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 | |||
| @@ -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; | |||
| @@ -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)); | |||
| } | |||
| } | |||
| @@ -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; | |||
| @@ -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()); | |||
| @@ -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(); | |||
| @@ -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(); | |||
| } | |||
| @@ -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 | |||
| @@ -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 | |||
| @@ -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 = | |||
| @@ -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")); | |||
| } | |||