Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use linefeed directly to avoid platform dependent code #454

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public boolean visitLeave(DependencyNode node) {
}));

if (repositories.isEmpty()) {
getLog().info("No remote repository is used by this build." + System.lineSeparator());
getLog().info("No remote repository is used by this build.\n");
return;
}

Expand Down Expand Up @@ -132,16 +132,16 @@ private void prepareRemoteMirrorRepositoriesList(
.append(repo)
.append(" mirrored by ")
.append(mirror)
.append(System.lineSeparator()));
.append("\n"));
}

private void prepareRemoteRepositoriesList(
StringBuilder message, Collection<RemoteRepository> remoteProjectRepositories) {

message.append("Project remote repositories used by this build:").append(System.lineSeparator());
message.append("Project remote repositories used by this build:\n");

remoteProjectRepositories.forEach(
repo -> message.append(" * ").append(repo).append(System.lineSeparator()));
repo -> message.append(" * ").append(repo).append("\n"));
}

private Map<RemoteRepository, RemoteRepository> getMirroredRepo(Set<RemoteRepository> repositories) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,13 +623,11 @@ private void reResolveArtifacts(MavenProject theProject, Set<Artifact> artifacts
}

if (!missingArtifacts.isEmpty()) {
StringBuilder message = new StringBuilder("required artifacts missing:");
message.append(System.lineSeparator());
StringBuilder message = new StringBuilder("required artifacts missing:\n");
for (Artifact missingArtifact : missingArtifacts) {
message.append(" ").append(missingArtifact.getId()).append(System.lineSeparator());
message.append(" ").append(missingArtifact.getId()).append("\n");
}
message.append(System.lineSeparator());
message.append("for the artifact:");
message.append("\nfor the artifact:");

throw new ArtifactResolutionException(
message.toString(), theProject.getArtifact(), theProject.getRemoteArtifactRepositories());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ private void writeDependencyXML(Set<Artifact> artifacts) {
writer.endElement();
}

getLog().info(System.lineSeparator() + out.getBuffer());
getLog().info("\n" + out.getBuffer());
}
}

Expand All @@ -552,9 +552,9 @@ private void writeScriptableOutput(Set<Artifact> artifacts) {
.append(artifact.getBaseVersion())
.append(":")
.append(artifact.getScope())
.append(System.lineSeparator());
.append("\n");
}
getLog().info(System.lineSeparator() + buf);
getLog().info("\n" + buf);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ protected void doExecute() throws MojoExecutionException {
}

if (outputFile == null) {
getLog().info("Dependencies classpath:" + System.lineSeparator() + cpString);
getLog().info("Dependencies classpath:\n" + cpString);
} else {
if (regenerateFile || !isUpToDate(cpString)) {
storeClasspathFile(cpString, outputFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,38 +142,31 @@ protected ArtifactsFilter getMarkedArtifactFilter() {
*/
public String getOutput(boolean outputAbsoluteArtifactFilename, boolean theOutputScope, boolean theSort) {
StringBuilder sb = new StringBuilder();
sb.append(System.lineSeparator());
sb.append("The following files have been resolved:");
sb.append(System.lineSeparator());
sb.append("\nThe following files have been resolved:\n");
if (results.getResolvedDependencies() == null
|| results.getResolvedDependencies().isEmpty()) {
sb.append(" none");
sb.append(System.lineSeparator());
sb.append(" none\n");
} else {
sb.append(buildArtifactListOutput(
results.getResolvedDependencies(), outputAbsoluteArtifactFilename, theOutputScope, theSort));
}

if (results.getSkippedDependencies() != null
&& !results.getSkippedDependencies().isEmpty()) {
sb.append(System.lineSeparator());
sb.append("The following files were skipped:");
sb.append(System.lineSeparator());
sb.append("\nThe following files were skipped:\n");
Set<Artifact> skippedDependencies = new LinkedHashSet<>(results.getSkippedDependencies());
sb.append(buildArtifactListOutput(
skippedDependencies, outputAbsoluteArtifactFilename, theOutputScope, theSort));
}

if (results.getUnResolvedDependencies() != null
&& !results.getUnResolvedDependencies().isEmpty()) {
sb.append(System.lineSeparator());
sb.append("The following files have NOT been resolved:");
sb.append(System.lineSeparator());
sb.append("\nThe following files have NOT been resolved:\n");
Set<Artifact> unResolvedDependencies = new LinkedHashSet<>(results.getUnResolvedDependencies());
sb.append(buildArtifactListOutput(
unResolvedDependencies, outputAbsoluteArtifactFilename, theOutputScope, theSort));
}
sb.append(System.lineSeparator());
sb.append("\n");

return sb.toString();
}
Expand Down Expand Up @@ -224,7 +217,7 @@ private StringBuilder buildArtifactListOutput(
}
}
}
artifactStringList.add(messageBuilder + System.lineSeparator());
artifactStringList.add(messageBuilder + "\n");
}
if (theSort) {
Collections.sort(artifactStringList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,9 @@ protected void doExecute() throws MojoExecutionException {
final Set<Artifact> plugins = resolvePluginArtifacts();

StringBuilder sb = new StringBuilder();
sb.append(System.lineSeparator());
sb.append("The following plugins have been resolved:");
sb.append(System.lineSeparator());
sb.append("\nThe following plugins have been resolved:\n");
if (plugins == null || plugins.isEmpty()) {
sb.append(" none");
sb.append(System.lineSeparator());
sb.append(" none\n");
} else {
for (Artifact plugin : plugins) {
String artifactFilename = null;
Expand All @@ -103,7 +100,7 @@ protected void doExecute() throws MojoExecutionException {
sb.append(" ")
.append(id)
.append(outputAbsoluteArtifactFilename ? ":" + artifactFilename : "")
.append(System.lineSeparator());
.append("\n");

if (!excludeTransitive) {
DefaultDependableCoordinate pluginCoordinate = new DefaultDependableCoordinate();
Expand All @@ -128,11 +125,11 @@ protected void doExecute() throws MojoExecutionException {
sb.append(" ")
.append(id)
.append(outputAbsoluteArtifactFilename ? ":" + artifactFilename : "")
.append(System.lineSeparator());
.append("\n");
}
}
}
sb.append(System.lineSeparator());
sb.append("\n");

String output = sb.toString();
if (outputFile == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public DOTDependencyNodeVisitor(Writer writer) {
@Override
public boolean visit(DependencyNode node) {
if (node.getParent() == null || node.getParent() == node) {
writer.write("digraph \"" + node.toNodeString() + "\" { " + System.lineSeparator());
writer.write("digraph \"" + node.toNodeString() + "\" { \n");
}

// Generate "currentNode -> Child" lines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public class GraphmlDependencyNodeVisitor extends AbstractSerializingVisitor imp
+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ "xmlns:y=\"http://www.yworks.com/xml/graphml\" "
+ "xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns "
+ "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">" + System.lineSeparator()
+ " <key for=\"node\" id=\"d0\" yfiles.type=\"nodegraphics\"/> " + System.lineSeparator()
+ " <key for=\"edge\" id=\"d1\" yfiles.type=\"edgegraphics\"/> " + System.lineSeparator()
+ "<graph id=\"dependencies\" edgedefault=\"directed\">" + System.lineSeparator();
+ "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">\n"
+ " <key for=\"node\" id=\"d0\" yfiles.type=\"nodegraphics\"/> \n"
+ " <key for=\"edge\" id=\"d1\" yfiles.type=\"edgegraphics\"/> \n"
+ "<graph id=\"dependencies\" edgedefault=\"directed\">\n";

/**
* Graphml xml file footer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected void tearDown() {
FileUtils.deleteDirectory(testDir);
} catch (IOException e) {
e.printStackTrace();
fail("Trying to remove directory: " + testDir + System.lineSeparator() + e);
fail("Trying to remove directory: " + testDir + "\n" + e);
}
assertFalse(testDir.exists());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void warn(Throwable error) {

/** {@inheritDoc} */
public void error(CharSequence content) {
System.err.println("[error] " + content.toString());
System.err.println("[error] " + content);
}

/** {@inheritDoc} */
Expand All @@ -132,8 +132,7 @@ public void error(CharSequence content, Throwable error) {

error.printStackTrace(pWriter);

System.err.println(
"[error] " + content.toString() + System.lineSeparator() + System.lineSeparator() + sWriter);
System.err.println("[error] " + content + "\n\n" + sWriter);
}

/**
Expand Down Expand Up @@ -182,7 +181,7 @@ private void print(String prefix, CharSequence content) {
.append(prefix)
.append("] ")
.append(content.toString())
.append(System.lineSeparator());
.append("\n");
}

private void print(String prefix, Throwable error) {
Expand All @@ -191,7 +190,7 @@ private void print(String prefix, Throwable error) {

error.printStackTrace(pWriter);

sb.append("[").append(prefix).append("] ").append(sWriter).append(System.lineSeparator());
sb.append("[").append(prefix).append("] ").append(sWriter).append("\n");
}

private void print(String prefix, CharSequence content, Throwable error) {
Expand All @@ -204,9 +203,8 @@ private void print(String prefix, CharSequence content, Throwable error) {
.append(prefix)
.append("] ")
.append(content.toString())
.append(System.lineSeparator())
.append(System.lineSeparator());
sb.append(sWriter).append(System.lineSeparator());
.append("\n\n");
sb.append(sWriter).append("\n");
}

protected String getContent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,7 @@ public void error(CharSequence content, Throwable error) {

error.printStackTrace(pWriter);

System.err.println(
"[error] " + content.toString() + System.lineSeparator() + System.lineSeparator() + sWriter);
System.err.println("[error] " + content + "\n\n" + sWriter);
}

/**
Expand Down Expand Up @@ -356,7 +355,7 @@ private void print(String prefix, CharSequence content) {
.append(prefix)
.append("] ")
.append(content.toString())
.append(System.lineSeparator());
.append("\n");
}

private void print(String prefix, Throwable error) {
Expand All @@ -365,7 +364,7 @@ private void print(String prefix, Throwable error) {

error.printStackTrace(pWriter);

sb.append("[").append(prefix).append("] ").append(sWriter).append(System.lineSeparator());
sb.append("[").append(prefix).append("] ").append(sWriter).append("\n\n");
}

private void print(String prefix, CharSequence content, Throwable error) {
Expand All @@ -374,13 +373,8 @@ private void print(String prefix, CharSequence content, Throwable error) {

error.printStackTrace(pWriter);

sb.append("[")
.append(prefix)
.append("] ")
.append(content.toString())
.append(System.lineSeparator())
.append(System.lineSeparator());
sb.append(sWriter).append(System.lineSeparator());
sb.append("[").append(prefix).append("] ").append(content).append("\n\n");
sb.append(sWriter).append("\n");
}

protected String getContent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void testOptionalDependencyFormatting() throws IOException {
ResolveDependenciesMojo mojo = newMojo(new DependencyStatusSets());
mojo.results.setResolvedDependencies(set);
String output = mojo.getOutput(false, true, false);
assertTrue(output.contains("g:a:jar:1.0:test (optional)" + System.lineSeparator()));
assertTrue(output.contains("g:a:jar:1.0:test (optional)\n"));
}

public void doTestDependencyStatusLog(Set<Artifact> artifacts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
*/
class TestDependencyUtil {

private static final String TEST_CONTENT =
"Test line 1" + System.lineSeparator() + "Test line 2" + System.lineSeparator();
private static final String TEST_CONTENT = "Test line 1\n" + "Test line 2\n";

@TempDir
File temDir;
Expand Down