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 11e5d71  tweak exception handling
11e5d71 is described below

commit 11e5d71d265fdc857375780dc1b8ff87030fd5ec
Author: Konrad Windszus <k...@apache.org>
AuthorDate: Fri Jun 24 09:23:51 2022 +0200

    tweak exception handling
    
    improve error message
---
 .../maven/enforcer/RequireExplicitDependencyScope.java   |  2 +-
 .../RequireProvidedDependenciesInRuntimeClasspath.java   | 16 ++++++++++++----
 2 files changed, 13 insertions(+), 5 deletions(-)

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 09e46c9..89e280a 100644
--- 
a/src/main/java/org/apache/sling/maven/enforcer/RequireExplicitDependencyScope.java
+++ 
b/src/main/java/org/apache/sling/maven/enforcer/RequireExplicitDependencyScope.java
@@ -62,7 +62,7 @@ public class RequireExplicitDependencyScope extends 
AbstractNonCacheableEnforcer
                 throw new EnforcerRuleException("Found " + 
numMissingDependencyScopes + " missing dependency " + 
scopesFormat.format(numMissingDependencyScopes) + ". Look at the warnings 
emitted above for the details.");
             }
         } catch (ExpressionEvaluationException eee) {
-            throw new EnforcerRuleException("Cannot resolve expression: " + 
eee.getCause(),  eee);
+            throw new EnforcerRuleException("Cannot resolve expression: " + 
eee.getCause(), eee);
         }
     }
 
diff --git 
a/src/main/java/org/apache/sling/maven/enforcer/RequireProvidedDependenciesInRuntimeClasspath.java
 
b/src/main/java/org/apache/sling/maven/enforcer/RequireProvidedDependenciesInRuntimeClasspath.java
index aa6ee5e..34d5a9c 100644
--- 
a/src/main/java/org/apache/sling/maven/enforcer/RequireProvidedDependenciesInRuntimeClasspath.java
+++ 
b/src/main/java/org/apache/sling/maven/enforcer/RequireProvidedDependenciesInRuntimeClasspath.java
@@ -21,6 +21,7 @@ package org.apache.sling.maven.enforcer;
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.text.ChoiceFormat;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -109,13 +110,19 @@ public class RequireProvidedDependenciesInRuntimeClasspath
         List<RemoteRepository> remoteRepositories;
         try {
             project = (MavenProject) helper.evaluate("${project}");
+            if (project == null) {
+                throw new ExpressionEvaluationException("${project} is null");
+            }
+            RepositorySystemSession repoSession = (RepositorySystemSession) 
helper.evaluate("${repositorySystemSession}");
+            if (repoSession == null) {
+                throw new 
ExpressionEvaluationException("${repositorySystemSession} is null");
+            }
             // get a new session to be able to tweak the dependency selector
-            newRepoSession = new DefaultRepositorySystemSession(
-                    (RepositorySystemSession) 
helper.evaluate("${repositorySystemSession}"));
+            newRepoSession = new DefaultRepositorySystemSession(repoSession);
             remoteRepositories = (List<RemoteRepository>) 
helper.evaluate("${project.remoteProjectRepositories}");
             repoSystem = helper.getComponent(RepositorySystem.class);
         } catch (ExpressionEvaluationException eee) {
-            throw new EnforcerRuleException("Unable to retrieve Maven project 
or repository system sesssion", eee);
+            throw new EnforcerRuleException("Cannot resolve expression: " + 
eee.getCause(), eee);
         } catch (ComponentLookupException cle) {
             throw new EnforcerRuleException("Unable to retrieve component 
RepositorySystem", cle);
         }
@@ -153,7 +160,8 @@ public class RequireProvidedDependenciesInRuntimeClasspath
                     rootDependency, repoSystem, newRepoSession, 
remoteRepositories, log);
             int numViolations = checkForMissingArtifacts(rootDependencyNode, 
runtimeArtifacts, log);
             if (numViolations > 0) {
-                throw new EnforcerRuleException("Found " + numViolations + " 
missing runtime dependencies. Look at the warnings emitted above for the 
details.");
+                ChoiceFormat dependenciesFormat = new 
ChoiceFormat("1#dependency|1<dependencies");
+                throw new EnforcerRuleException("Found " + numViolations + " 
missing runtime " + dependenciesFormat.format(numViolations) + ". Look at the 
warnings emitted above for the details.");
             }
         } catch (DependencyCollectionException e) {
             // draw graph

Reply via email to