You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2022/06/24 08:03:33 UTC

[sling-maven-enforcer-rules] branch master updated: SLING-11410 add location details

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

kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-maven-enforcer-rules.git


The following commit(s) were added to refs/heads/master by this push:
     new 7ac084e  SLING-11410 add location details
7ac084e is described below

commit 7ac084ea22350069bec964c68f4050db7cf70eb1
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Fri Jun 24 10:03:28 2022 +0200

    SLING-11410 add location details
---
 src/it/require-dependency-scope/verify.groovy      |  2 +-
 .../enforcer/RequireExplicitDependencyScope.java   | 27 +++++++++++++++++++++-
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/it/require-dependency-scope/verify.groovy b/src/it/require-dependency-scope/verify.groovy
index 6140965..dbcbdb3 100644
--- a/src/it/require-dependency-scope/verify.groovy
+++ b/src/it/require-dependency-scope/verify.groovy
@@ -18,5 +18,5 @@
  */
 File buildLog = new File(basedir, 'build.log')
 assert buildLog.text.contains('Found 1 missing dependency scope. Look at the warnings emitted above for the details.')
-assert buildLog.text.contains('[WARNING] Dependency org.apache.jackrabbit.vault:vault-cli:jar does not have an explicit scope defined!')
+assert buildLog.text.contains('[WARNING] Dependency org.apache.jackrabbit.vault:vault-cli:jar @ line 73, column 21 does not have an explicit scope defined!')
 assert true
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/maven/enforcer/RequireExplicitDependencyScope.java b/src/main/java/org/apache/sling/maven/enforcer/RequireExplicitDependencyScope.java
index 7188924..58db245 100644
--- a/src/main/java/org/apache/sling/maven/enforcer/RequireExplicitDependencyScope.java
+++ b/src/main/java/org/apache/sling/maven/enforcer/RequireExplicitDependencyScope.java
@@ -29,6 +29,7 @@ import org.apache.maven.enforcer.rule.api.EnforcerRule2;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
 import org.apache.maven.model.Dependency;
+import org.apache.maven.model.InputLocation;
 import org.apache.maven.plugins.enforcer.AbstractNonCacheableEnforcerRule;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.shared.utils.logging.MessageBuilder;
@@ -54,7 +55,7 @@ public class RequireExplicitDependencyScope extends AbstractNonCacheableEnforcer
                 helper.getLog().debug("Found dependency " + dependency);
                 if (dependency.getScope() == null) {
                     MessageBuilder msgBuilder = MessageUtils.buffer();
-                    helper.getLog().warn(msgBuilder.a("Dependency ").strong(dependency.getManagementKey()).a(" does not have an explicit scope defined!").toString());
+                    helper.getLog().warn(msgBuilder.a("Dependency ").strong(dependency.getManagementKey()).a(" @ ").strong(formatLocation(dependency.getLocation(""))).a(" does not have an explicit scope defined!").toString());
                     numMissingDependencyScopes++;
                 }
             }
@@ -67,4 +68,28 @@ public class RequireExplicitDependencyScope extends AbstractNonCacheableEnforcer
         }
     }
 
+    /**
+     * Creates a string with line/column information for problems originating directly from this POM.
+     * Inspired by <a href="https://github.com/apache/maven/blob/d82ab09ae106131609efb8b98b67dae17b0780d0/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblemUtils.java#L136-L173">ModelProblemUtils.formatLocation(...)</a>
+     *
+     * @param location The location which should be formatted, must not be {@code null}.
+     * @return The formatted problem location or an empty string if unknown, never {@code null}.
+     */
+    protected static String formatLocation(InputLocation location) {
+        StringBuilder buffer = new StringBuilder();
+        if (location.getLineNumber() > 0) {
+            if (buffer.length() > 0) {
+                buffer.append( ", " );
+            }
+            buffer.append("line ").append(location.getLineNumber());
+        }
+        if (location.getColumnNumber() > 0) {
+            if (buffer.length() > 0) {
+                buffer.append( ", " );
+            }
+            buffer.append("column ").append(location.getColumnNumber());
+        }
+        return buffer.toString();
+    }
+
 }