diff --git a/src/it/projects/mdep-779-analyze-only-verbose-shows-class-names/invoker.properties b/src/it/projects/mdep-779-analyze-only-verbose-shows-class-names/invoker.properties
new file mode 100644
index 000000000..342590243
--- /dev/null
+++ b/src/it/projects/mdep-779-analyze-only-verbose-shows-class-names/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 = clean package ${project.groupId}:${project.artifactId}:${project.version}:analyze-only -Dverbose
diff --git a/src/it/projects/mdep-779-analyze-only-verbose-shows-class-names/pom.xml b/src/it/projects/mdep-779-analyze-only-verbose-shows-class-names/pom.xml
new file mode 100644
index 000000000..2a8e65209
--- /dev/null
+++ b/src/it/projects/mdep-779-analyze-only-verbose-shows-class-names/pom.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.shared.dependency-analyzer.tests
+ usedUndeclaredReference
+ 1.0
+ jar
+
+
+
+ dom4j
+ dom4j
+ 1.6.1
+
+
+
diff --git a/src/it/projects/mdep-779-analyze-only-verbose-shows-class-names/src/main/java/usedUndeclaredReference/Project.java b/src/it/projects/mdep-779-analyze-only-verbose-shows-class-names/src/main/java/usedUndeclaredReference/Project.java
new file mode 100644
index 000000000..5432b4056
--- /dev/null
+++ b/src/it/projects/mdep-779-analyze-only-verbose-shows-class-names/src/main/java/usedUndeclaredReference/Project.java
@@ -0,0 +1,25 @@
+package usedUndeclaredReference;
+
+/*
+ * 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.
+ */
+
+public class Project
+{
+ public static final Class CLASS_REF = org.apache.xmlcommons.Version.class;
+}
diff --git a/src/it/projects/mdep-779-analyze-only-verbose-shows-class-names/verify.bsh b/src/it/projects/mdep-779-analyze-only-verbose-shows-class-names/verify.bsh
new file mode 100644
index 000000000..35957daaf
--- /dev/null
+++ b/src/it/projects/mdep-779-analyze-only-verbose-shows-class-names/verify.bsh
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+import org.codehaus.plexus.util.*;
+
+String log = FileUtils.fileRead( new File( basedir, "build.log" ) );
+
+log = StringUtils.unifyLineSeparators(log, "\n");
+
+String expected = "[WARNING] Used undeclared dependencies found:\n"
+ + "[WARNING] xml-apis:xml-apis:jar:1.0.b2:compile\n"
+ + "[WARNING] class org.apache.xmlcommons.Version\n";
+
+if ( !log.contains(expected) )
+{
+ throw new Exception( "Expected warning missing" );
+}
+
+return true;
diff --git a/src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java b/src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java
index e3634a0d1..860135565 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java
@@ -24,8 +24,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
@@ -327,7 +329,8 @@ private boolean checkDependencies()
}
Set usedDeclared = new LinkedHashSet<>( analysis.getUsedDeclaredArtifacts() );
- Set usedUndeclared = new LinkedHashSet<>( analysis.getUsedUndeclaredArtifacts() );
+ Map> usedUndeclaredWithClasses =
+ new LinkedHashMap<>( analysis.getUsedUndeclaredArtifactsWithClasses() );
Set unusedDeclared = new LinkedHashSet<>( analysis.getUnusedDeclaredArtifacts() );
Set testArtifactsWithNonTestScope = new LinkedHashSet<>(
analysis.getTestArtifactsWithNonTestScope() );
@@ -340,8 +343,9 @@ private boolean checkDependencies()
filterArtifactsByScope( unusedDeclared, Artifact.SCOPE_RUNTIME );
}
- ignoredUsedUndeclared.addAll( filterDependencies( usedUndeclared, ignoredDependencies ) );
- ignoredUsedUndeclared.addAll( filterDependencies( usedUndeclared, ignoredUsedUndeclaredDependencies ) );
+ ignoredUsedUndeclared.addAll( filterDependencies( usedUndeclaredWithClasses.keySet(), ignoredDependencies ) );
+ ignoredUsedUndeclared.addAll( filterDependencies( usedUndeclaredWithClasses.keySet(),
+ ignoredUsedUndeclaredDependencies ) );
ignoredUnusedDeclared.addAll( filterDependencies( unusedDeclared, ignoredDependencies ) );
ignoredUnusedDeclared.addAll( filterDependencies( unusedDeclared, ignoredUnusedDeclaredDependencies ) );
@@ -357,11 +361,18 @@ private boolean checkDependencies()
reported = true;
}
- if ( !usedUndeclared.isEmpty() )
+ if ( !usedUndeclaredWithClasses.isEmpty() )
{
getLog().warn( "Used undeclared dependencies found:" );
- logArtifacts( usedUndeclared, true );
+ if ( verbose )
+ {
+ logArtifacts( usedUndeclaredWithClasses, true );
+ }
+ else
+ {
+ logArtifacts( usedUndeclaredWithClasses.keySet(), true );
+ }
reported = true;
warning = true;
}
@@ -402,12 +413,12 @@ private boolean checkDependencies()
if ( outputXML )
{
- writeDependencyXML( usedUndeclared );
+ writeDependencyXML( usedUndeclaredWithClasses.keySet() );
}
if ( scriptableOutput )
{
- writeScriptableOutput( usedUndeclared );
+ writeScriptableOutput( usedUndeclaredWithClasses.keySet() );
}
if ( !reported )
@@ -449,6 +460,40 @@ private void logArtifacts( Set artifacts, boolean warn )
}
}
+ private void logArtifacts( Map> artifacts, boolean warn )
+ {
+ if ( artifacts.isEmpty() )
+ {
+ getLog().info( " None" );
+ }
+ else
+ {
+ for ( Map.Entry> entry : artifacts.entrySet() )
+ {
+ // called because artifact will set the version to -SNAPSHOT only if I do this. MNG-2961
+ entry.getKey().isSnapshot();
+
+ if ( warn )
+ {
+ getLog().warn( " " + entry.getKey() );
+ for ( String clazz : entry.getValue() )
+ {
+ getLog().warn( " class " + clazz );
+ }
+ }
+ else
+ {
+ getLog().info( " " + entry.getKey() );
+ for ( String clazz : entry.getValue() )
+ {
+ getLog().info( " class " + clazz );
+ }
+ }
+
+ }
+ }
+ }
+
private void writeDependencyXML( Set artifacts )
{
if ( !artifacts.isEmpty() )