You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2020/12/30 00:51:09 UTC

[maven-enforcer] 01/03: [MENFORCER-313] - Added [] to the conflicting artifacts in the

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

slachiewicz pushed a commit to branch MENFORCER-313
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git

commit bd993c2e3a6f9063e5a0b4f99497f08e58864f56
Author: Gabriel Belingueres <be...@gmail.com>
AuthorDate: Fri Aug 10 18:18:52 2018 -0300

    [MENFORCER-313] - Added [<scope>] to the conflicting artifacts in the
    
    output. Highlight those with compile scope.
    
    Closes #38
---
 .../plugins/enforcer/RequireUpperBoundDeps.java    | 14 ++++-
 .../invoker.properties                             | 18 ++++++
 .../pom.xml                                        | 64 ++++++++++++++++++++++
 .../verify.groovy                                  | 31 +++++++++++
 4 files changed, 126 insertions(+), 1 deletion(-)

diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireUpperBoundDeps.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireUpperBoundDeps.java
index 0a4ba38..7eee9ae 100644
--- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireUpperBoundDeps.java
+++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireUpperBoundDeps.java
@@ -42,6 +42,7 @@ import org.apache.maven.shared.dependency.tree.DependencyNode;
 import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
 import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
 import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor;
+import org.apache.maven.shared.utils.logging.MessageUtils;
 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 
@@ -253,7 +254,18 @@ public class RequireUpperBoundDeps
         {
             version = uniqueVersions ? artifact.getVersion() : artifact.getBaseVersion();
         }
-        return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + version;
+        String result = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + version;
+
+        if ( "compile".equals( artifact.getScope() ) )
+        {
+            return MessageUtils.buffer().strong( result ).toString();
+        }
+        if ( artifact.getScope() != null )
+        {
+            return result + " [" + artifact.getScope() + ']';
+        }
+
+        return result;
     }
 
     private static class RequireUpperBoundDepsVisitor
diff --git a/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure_show_scopes/invoker.properties b/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure_show_scopes/invoker.properties
new file mode 100644
index 0000000..c98ac4c
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure_show_scopes/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.buildResult=failure
\ No newline at end of file
diff --git a/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure_show_scopes/pom.xml b/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure_show_scopes/pom.xml
new file mode 100644
index 0000000..ef8eddc
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure_show_scopes/pom.xml
@@ -0,0 +1,64 @@
+<?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.plugins.enforcer.its</groupId>
+  <artifactId>menforcer313</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+      <artifactId>menforcer128_api</artifactId>
+      <version>1.4.0</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+      <artifactId>menforcer128_classic</artifactId>
+      <version>0.9.9</version>
+      <scope>provided</scope>
+      <!-- Depends on org.apache.maven.plugins.enforcer.its:menforcer128_api:1.5.0 -->
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-enforcer-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>enforce</id>
+            <configuration>
+              <rules>
+                <RequireUpperBoundDeps/>
+              </rules>
+            </configuration>
+            <goals>
+              <goal>enforce</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure_show_scopes/verify.groovy b/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure_show_scopes/verify.groovy
new file mode 100644
index 0000000..f916d09
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure_show_scopes/verify.groovy
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+def LS = System.getProperty( "line.separator" )
+File buildLog = new File( basedir, 'build.log' )
+
+assert buildLog.text.contains( 'Rule 0: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:' )
+def message = 
+'Require upper bound dependencies error for org.apache.maven.plugins.enforcer.its:menforcer128_api:1.4.0 [runtime] paths to dependency are:'+LS+
+'+-org.apache.maven.plugins.enforcer.its:menforcer313:1.0-SNAPSHOT'+LS+
+'  +-org.apache.maven.plugins.enforcer.its:menforcer128_api:1.4.0 [runtime]'+LS+
+'and'+LS+
+'+-org.apache.maven.plugins.enforcer.its:menforcer313:1.0-SNAPSHOT'+LS+
+'  +-org.apache.maven.plugins.enforcer.its:menforcer128_classic:0.9.9 [provided]'+LS+
+'    +-org.apache.maven.plugins.enforcer.its:menforcer128_api:1.5.0 [provided]'+LS
+assert buildLog.text.contains( message )