This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch MDEP-839
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit 26fbd73d13d3cda384ed8e34d90bb0eaff217847
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Wed Dec 4 06:55:44 2024 -0500

    Avoid control characters in file
---
 src/it/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(-)

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 00000000..5bc8fd46
--- /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 00000000..d74bc248
--- /dev/null
+++ b/src/it/projects/mdep-839-list/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.dependency</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <name>Test</name>
+  <description>
+    Test dependency:list-repositories
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <repositories>
+    <repository>
+      <id>fake-remote-repository</id>
+      <url>http://localhost:2345</url>
+    </repository>
+  </repositories>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-core</artifactId>
+      <version>3.2.5</version>
+    </dependency>
+  </dependencies>
+
+</project>
\ 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 00000000..5aec7828
--- /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 6f49a476..23532ca1 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 @@ public class ResolveDependenciesMojo extends 
AbstractResolveMojo {
      */
     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 @@ public class ResolveDependenciesMojo extends 
AbstractResolveMojo {
             Set<Artifact> artifacts, boolean outputAbsoluteArtifactFilename, 
boolean theOutputScope, boolean theSort) {
         StringBuilder sb = new StringBuilder();
         List<String> artifactStringList = new ArrayList<>();
+        if (outputFile != null) {
+            MessageUtils.setColorEnabled(false);
+        }
         for (Artifact artifact : artifacts) {
             MessageBuilder messageBuilder = MessageUtils.buffer();
-
             messageBuilder.a("   ");
 
             if (theOutputScope) {

Reply via email to