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

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


The following commit(s) were added to refs/heads/master by this push:
     new cf997f70 [MDEP-839] Avoid extra blank lines in file (#495)
cf997f70 is described below

commit cf997f70c863fe741efd077ced8be3eedaef2535
Author: Elliotte Rusty Harold <elh...@users.noreply.github.com>
AuthorDate: Mon Feb 10 17:07:26 2025 +0000

    [MDEP-839] Avoid extra blank lines in file (#495)
    
    * 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/test.properties      | 19 ++++++++
 src/it/projects/mdep-839-list/verify.groovy        | 28 +++++++++++
 .../resolvers/ResolveDependenciesMojo.java         | 12 +++--
 5 files changed, 128 insertions(+), 3 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..55afe77c
--- /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
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..f6cd8606
--- /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.9.9</version>
+    </dependency>
+  </dependencies>
+
+</project>
\ No newline at end of file
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 00000000..406dd9ab
--- /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
new file mode 100644
index 00000000..50cd4ea0
--- /dev/null
+++ b/src/it/projects/mdep-839-list/verify.groovy
@@ -0,0 +1,28 @@
+/*
+ * 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, "classpath.txt" )
+assert file.exists() : "output file $file does not exist"
+
+String output = file.getText( "UTF-8" )
+assert output.startsWith( 'The following files have been resolved:')
+// 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 424d54bb..d326bda2 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
@@ -175,7 +175,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
@@ -215,9 +217,13 @@ 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);
+        } else {
+            MessageUtils.setColorEnabled(true);
+        } */
         for (Artifact artifact : artifacts) {
             MessageBuilder messageBuilder = MessageUtils.buffer();
-
             messageBuilder.a("   ");
 
             if (theOutputScope) {
@@ -257,7 +263,7 @@ public class ResolveDependenciesMojo extends 
AbstractResolveMojo {
                     }
                 }
             }
-            artifactStringList.add(messageBuilder + System.lineSeparator());
+            artifactStringList.add(messageBuilder.build() + 
System.lineSeparator());
         }
         if (theSort) {
             Collections.sort(artifactStringList);

Reply via email to