From 26fbd73d13d3cda384ed8e34d90bb0eaff217847 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Wed, 4 Dec 2024 06:55:44 -0500 Subject: [PATCH 1/7] Avoid control characters in file --- .../projects/mdep-839-list/invoker.properties | 18 +++++++ src/it/projects/mdep-839-list/pom.xml | 54 +++++++++++++++++++ src/it/projects/mdep-839-list/verify.groovy | 25 +++++++++ .../resolvers/ResolveDependenciesMojo.java | 8 ++- 4 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 src/it/projects/mdep-839-list/invoker.properties create mode 100644 src/it/projects/mdep-839-list/pom.xml create mode 100644 src/it/projects/mdep-839-list/verify.groovy diff --git a/src/it/projects/mdep-839-list/invoker.properties b/src/it/projects/mdep-839-list/invoker.properties new file mode 100644 index 000000000..5bc8fd465 --- /dev/null +++ b/src/it/projects/mdep-839-list/invoker.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:list --Doutput-file="temp.txt" diff --git a/src/it/projects/mdep-839-list/pom.xml b/src/it/projects/mdep-839-list/pom.xml new file mode 100644 index 000000000..d74bc248d --- /dev/null +++ b/src/it/projects/mdep-839-list/pom.xml @@ -0,0 +1,54 @@ + + + + + 4.0.0 + + org.apache.maven.its.dependency + test + 1.0-SNAPSHOT + + Test + + Test dependency:list-repositories + + + + UTF-8 + + + + + fake-remote-repository + http://localhost:2345 + + + + + + org.apache.maven + maven-core + 3.2.5 + + + + \ No newline at end of file diff --git a/src/it/projects/mdep-839-list/verify.groovy b/src/it/projects/mdep-839-list/verify.groovy new file mode 100644 index 000000000..5aec7828a --- /dev/null +++ b/src/it/projects/mdep-839-list/verify.groovy @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +File file = new File( basedir, "temp.txt" ) +assert file.exists() + +String output = file.getText( "UTF-8" ) +assert output.contains( 'The following files have been resolved:') + diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java index 6f49a4767..23532ca1f 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java @@ -142,7 +142,9 @@ protected ArtifactsFilter getMarkedArtifactFilter() { */ public String getOutput(boolean outputAbsoluteArtifactFilename, boolean theOutputScope, boolean theSort) { StringBuilder sb = new StringBuilder(); - sb.append(System.lineSeparator()); + if (outputFile == null) { + sb.append(System.lineSeparator()); + } sb.append("The following files have been resolved:"); sb.append(System.lineSeparator()); if (results.getResolvedDependencies() == null @@ -182,9 +184,11 @@ private StringBuilder buildArtifactListOutput( Set artifacts, boolean outputAbsoluteArtifactFilename, boolean theOutputScope, boolean theSort) { StringBuilder sb = new StringBuilder(); List artifactStringList = new ArrayList<>(); + if (outputFile != null) { + MessageUtils.setColorEnabled(false); + } for (Artifact artifact : artifacts) { MessageBuilder messageBuilder = MessageUtils.buffer(); - messageBuilder.a(" "); if (theOutputScope) { From 9ce326ebcc616af653592e645f71aae7d52770c1 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Wed, 4 Dec 2024 07:17:09 -0500 Subject: [PATCH 2/7] tmp --- src/it/projects/mdep-839-list/invoker.properties | 2 +- src/it/projects/mdep-839-list/verify.groovy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/it/projects/mdep-839-list/invoker.properties b/src/it/projects/mdep-839-list/invoker.properties index 5bc8fd465..3e781b202 100644 --- a/src/it/projects/mdep-839-list/invoker.properties +++ b/src/it/projects/mdep-839-list/invoker.properties @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:list --Doutput-file="temp.txt" +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:list --Doutput-file="/tmp/temp.txt" diff --git a/src/it/projects/mdep-839-list/verify.groovy b/src/it/projects/mdep-839-list/verify.groovy index 5aec7828a..fe45f1b01 100644 --- a/src/it/projects/mdep-839-list/verify.groovy +++ b/src/it/projects/mdep-839-list/verify.groovy @@ -17,7 +17,7 @@ * under the License. */ -File file = new File( basedir, "temp.txt" ) +File file = new File( basedir, "/tmp/temp.txt" ) assert file.exists() String output = file.getText( "UTF-8" ) From 54c12682954e95bbe9a496efe11fd7fa0e311051 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Wed, 4 Dec 2024 07:51:13 -0500 Subject: [PATCH 3/7] outputFile --- .../projects/mdep-839-list/invoker.properties | 2 +- src/it/projects/mdep-839-list/test.properties | 19 +++++++++++++++++++ src/it/projects/mdep-839-list/verify.groovy | 4 ++-- .../dependency/utils/DependencyUtil.java | 4 +++- 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/it/projects/mdep-839-list/test.properties diff --git a/src/it/projects/mdep-839-list/invoker.properties b/src/it/projects/mdep-839-list/invoker.properties index 3e781b202..55afe77c1 100644 --- a/src/it/projects/mdep-839-list/invoker.properties +++ b/src/it/projects/mdep-839-list/invoker.properties @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:list --Doutput-file="/tmp/temp.txt" +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:list diff --git a/src/it/projects/mdep-839-list/test.properties b/src/it/projects/mdep-839-list/test.properties new file mode 100644 index 000000000..406dd9aba --- /dev/null +++ b/src/it/projects/mdep-839-list/test.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +outputFile = classpath.txt + diff --git a/src/it/projects/mdep-839-list/verify.groovy b/src/it/projects/mdep-839-list/verify.groovy index fe45f1b01..f20821cec 100644 --- a/src/it/projects/mdep-839-list/verify.groovy +++ b/src/it/projects/mdep-839-list/verify.groovy @@ -17,8 +17,8 @@ * under the License. */ -File file = new File( basedir, "/tmp/temp.txt" ) -assert file.exists() +File file = new File( basedir, "classpath.txt" ) +assert file.exists() : "output file $file does not exist" String output = file.getText( "UTF-8" ) assert output.contains( 'The following files have been resolved:') diff --git a/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java b/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java index 5ec05ccd6..bca7279de 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java +++ b/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java @@ -26,6 +26,7 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.OpenOption; +import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.Objects; @@ -229,7 +230,8 @@ public static synchronized void write(String string, File file, boolean append, */ public static synchronized void write(String string, File file, boolean append, String encoding) throws IOException { - Files.createDirectories(file.getParentFile().toPath()); + Path parent = Files.createDirectories(file.getParentFile().toPath()); + System.err.println(parent.toAbsolutePath()); OpenOption appendOption = append ? StandardOpenOption.APPEND : StandardOpenOption.TRUNCATE_EXISTING; From 3c8d42464edcf817bb9d39b893774fe40f498f69 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Wed, 4 Dec 2024 08:02:25 -0500 Subject: [PATCH 4/7] test --- src/it/projects/mdep-839-list/verify.groovy | 3 +++ .../apache/maven/plugins/dependency/utils/DependencyUtil.java | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/it/projects/mdep-839-list/verify.groovy b/src/it/projects/mdep-839-list/verify.groovy index f20821cec..5f77922d3 100644 --- a/src/it/projects/mdep-839-list/verify.groovy +++ b/src/it/projects/mdep-839-list/verify.groovy @@ -22,4 +22,7 @@ assert file.exists() : "output file $file does not exist" String output = file.getText( "UTF-8" ) assert output.contains( 'The following files have been resolved:') +for (char c : output) { // no color codes + assert c >= 32 || c == '\n' || c == '\r' || c == '\t'; +} diff --git a/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java b/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java index bca7279de..5ec05ccd6 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java +++ b/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java @@ -26,7 +26,6 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.OpenOption; -import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.Objects; @@ -230,8 +229,7 @@ public static synchronized void write(String string, File file, boolean append, */ public static synchronized void write(String string, File file, boolean append, String encoding) throws IOException { - Path parent = Files.createDirectories(file.getParentFile().toPath()); - System.err.println(parent.toAbsolutePath()); + Files.createDirectories(file.getParentFile().toPath()); OpenOption appendOption = append ? StandardOpenOption.APPEND : StandardOpenOption.TRUNCATE_EXISTING; From 1c753e4f888bbe241d6afb6e9e6177773b744819 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Wed, 4 Dec 2024 08:28:55 -0500 Subject: [PATCH 5/7] escape --- src/it/projects/mdep-839-list/pom.xml | 2 +- src/it/projects/mdep-839-list/verify.groovy | 4 ++-- .../plugins/dependency/resolvers/ResolveDependenciesMojo.java | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/it/projects/mdep-839-list/pom.xml b/src/it/projects/mdep-839-list/pom.xml index d74bc248d..f6cd86069 100644 --- a/src/it/projects/mdep-839-list/pom.xml +++ b/src/it/projects/mdep-839-list/pom.xml @@ -47,7 +47,7 @@ org.apache.maven maven-core - 3.2.5 + 3.9.9 diff --git a/src/it/projects/mdep-839-list/verify.groovy b/src/it/projects/mdep-839-list/verify.groovy index 5f77922d3..d526ceeac 100644 --- a/src/it/projects/mdep-839-list/verify.groovy +++ b/src/it/projects/mdep-839-list/verify.groovy @@ -22,7 +22,7 @@ assert file.exists() : "output file $file does not exist" String output = file.getText( "UTF-8" ) assert output.contains( 'The following files have been resolved:') -for (char c : output) { // no color codes - assert c >= 32 || c == '\n' || c == '\r' || c == '\t'; +for (char c : output) { // no escape codes + assert c != 27; } diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java index 23532ca1f..0a7811509 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java @@ -185,7 +185,9 @@ private StringBuilder buildArtifactListOutput( StringBuilder sb = new StringBuilder(); List artifactStringList = new ArrayList<>(); if (outputFile != null) { - MessageUtils.setColorEnabled(false); + // MessageUtils.setColorEnabled(false); + } else { + MessageUtils.setColorEnabled(true); } for (Artifact artifact : artifacts) { MessageBuilder messageBuilder = MessageUtils.buffer(); From dcb91836aff63550313d3cd498a68c2e9e9d4e89 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Wed, 4 Dec 2024 08:52:04 -0500 Subject: [PATCH 6/7] wip --- src/it/projects/mdep-839-list/verify.groovy | 6 +++--- .../dependency/resolvers/ResolveDependenciesMojo.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/it/projects/mdep-839-list/verify.groovy b/src/it/projects/mdep-839-list/verify.groovy index d526ceeac..11e5f395e 100644 --- a/src/it/projects/mdep-839-list/verify.groovy +++ b/src/it/projects/mdep-839-list/verify.groovy @@ -22,7 +22,7 @@ assert file.exists() : "output file $file does not exist" String output = file.getText( "UTF-8" ) assert output.contains( 'The following files have been resolved:') -for (char c : output) { // no escape codes - assert c != 27; -} +// no escape codes +assert !output.contains( '\u001B' ) + diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java index 0a7811509..c939ec4d8 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java @@ -184,11 +184,11 @@ private StringBuilder buildArtifactListOutput( Set artifacts, boolean outputAbsoluteArtifactFilename, boolean theOutputScope, boolean theSort) { StringBuilder sb = new StringBuilder(); List artifactStringList = new ArrayList<>(); - if (outputFile != null) { - // MessageUtils.setColorEnabled(false); + /* if (outputFile != null) { + MessageUtils.setColorEnabled(false); } else { MessageUtils.setColorEnabled(true); - } + } */ for (Artifact artifact : artifacts) { MessageBuilder messageBuilder = MessageUtils.buffer(); messageBuilder.a(" "); @@ -230,7 +230,7 @@ private StringBuilder buildArtifactListOutput( } } } - artifactStringList.add(messageBuilder + System.lineSeparator()); + artifactStringList.add(messageBuilder.build() + System.lineSeparator()); } if (theSort) { Collections.sort(artifactStringList); From 98ac1115612fc2e589393264036b1d0ede6f4676 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sun, 26 Jan 2025 21:05:49 -0600 Subject: [PATCH 7/7] startsWith --- src/it/projects/mdep-839-list/verify.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/it/projects/mdep-839-list/verify.groovy b/src/it/projects/mdep-839-list/verify.groovy index 11e5f395e..50cd4ea0f 100644 --- a/src/it/projects/mdep-839-list/verify.groovy +++ b/src/it/projects/mdep-839-list/verify.groovy @@ -21,7 +21,7 @@ File file = new File( basedir, "classpath.txt" ) assert file.exists() : "output file $file does not exist" String output = file.getText( "UTF-8" ) -assert output.contains( 'The following files have been resolved:') +assert output.startsWith( 'The following files have been resolved:') // no escape codes assert !output.contains( '\u001B' )