elharo commented on code in PR #218:
URL:
https://github.com/apache/maven-dependency-plugin/pull/218#discussion_r1331499957
##########
src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java:
##########
@@ -266,7 +267,30 @@ public abstract class AbstractAnalyzeMojo
// defaultValue value on @Parameter - not work with Maven 3.2.5
// When is set defaultValue always win, and there is no possibility to
override by plugin configuration.
@Parameter
- private List<String> ignoredPackagings = Arrays.asList( "pom", "ear" );
+ private final List<String> ignoredPackagings = Arrays.asList( "pom", "ear"
);
+
+
+ /**
+ * List of dependencies to be included. The result of this list is then
applied to the ignore parameters.
+ *
+ * The filter syntax is:
+ *
+ * <pre>
+ * [groupId]:[artifactId]:[type]:[version]
+ * </pre>
+ *
+ * where each pattern segment is optional and supports full and partial
<code>*</code> wildcards. An empty pattern
+ * segment is treated as an implicit wildcard. *
+ * <p>
+ * For example, <code>org.apache.*</code> will match all artifacts whose
group id starts with
+ * <code>org.apache.</code>, and <code>:maven-dependency-plugin</code>
will result in the analysis being applied
Review Comment:
This is confusing. Try using an example of an unrelated library instead like
JodaTime.
##########
src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java:
##########
@@ -621,7 +695,15 @@ private void writeScriptableOutput( Set<Artifact>
artifacts )
}
}
- private List<Artifact> filterDependencies( Set<Artifact> artifacts,
String[] excludes )
+
+ /**
+ * Filter for artifacts that don't match the <code>exclude</code> criteria.
+ *
+ * @param artifacts filtered by elements that don't match the
<code>excludes</code> argument
Review Comment:
exclude or excludes? You have both.
##########
src/it/projects/analyze-include-dependency/pom.xml:
##########
@@ -0,0 +1,81 @@
+<?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:analyze with includeDependencies
+ </description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
Review Comment:
why so old?
##########
src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java:
##########
@@ -438,6 +478,40 @@ private boolean checkDependencies()
warning = true;
}
+ // log dependencies that weren't included
+ if ( verbose && !notIncludedUsedDeclared.isEmpty() )
Review Comment:
why are these logged? I thought the point of this PR was to avoid reporting
on these.
##########
src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java:
##########
@@ -638,4 +720,35 @@ private List<Artifact> filterDependencies( Set<Artifact>
artifacts, String[] exc
return result;
}
+
+
+ /**
+ * Filter for artifacts that match the <code>include</code> criteria.
+ * No filtering is applied if the criteria is empty.
+ *
+ * @param artifacts filtered for elements that do match the criteria
+ * @param includes the filter to be applied
+ * @return the list of artifacts that didn't match the criteria
+ */
+ private List<Artifact> filterDependencies( Set<Artifact> artifacts,
String[] includes )
+ {
+ List<Artifact> result = new ArrayList<>();
+
+ if ( includes.length > 0 )
+ {
+ ArtifactFilter filter = new StrictPatternIncludesArtifactFilter(
Arrays.asList( includes ) );
+
+ for ( Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); )
+ {
+ Artifact artifact = it.next();
+ if ( !filter.include( artifact ) )
+ {
+ it.remove();
Review Comment:
why the remove call? Doesn't seem needed.
##########
src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java:
##########
@@ -266,7 +267,30 @@ public abstract class AbstractAnalyzeMojo
// defaultValue value on @Parameter - not work with Maven 3.2.5
// When is set defaultValue always win, and there is no possibility to
override by plugin configuration.
@Parameter
- private List<String> ignoredPackagings = Arrays.asList( "pom", "ear" );
+ private final List<String> ignoredPackagings = Arrays.asList( "pom", "ear"
);
+
+
+ /**
+ * List of dependencies to be included. The result of this list is then
applied to the ignore parameters.
Review Comment:
This isn't clear that everything is included by default when this isn't set.
##########
src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java:
##########
@@ -638,4 +720,35 @@ private List<Artifact> filterDependencies( Set<Artifact>
artifacts, String[] exc
return result;
}
+
+
+ /**
+ * Filter for artifacts that match the <code>include</code> criteria.
+ * No filtering is applied if the criteria is empty.
+ *
+ * @param artifacts filtered for elements that do match the criteria
+ * @param includes the filter to be applied
+ * @return the list of artifacts that didn't match the criteria
+ */
+ private List<Artifact> filterDependencies( Set<Artifact> artifacts,
String[] includes )
+ {
+ List<Artifact> result = new ArrayList<>();
+
+ if ( includes.length > 0 )
Review Comment:
!isEmpty()
##########
src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java:
##########
@@ -266,7 +267,30 @@ public abstract class AbstractAnalyzeMojo
// defaultValue value on @Parameter - not work with Maven 3.2.5
// When is set defaultValue always win, and there is no possibility to
override by plugin configuration.
@Parameter
- private List<String> ignoredPackagings = Arrays.asList( "pom", "ear" );
+ private final List<String> ignoredPackagings = Arrays.asList( "pom", "ear"
);
+
+
+ /**
+ * List of dependencies to be included. The result of this list is then
applied to the ignore parameters.
+ *
+ * The filter syntax is:
+ *
+ * <pre>
+ * [groupId]:[artifactId]:[type]:[version]
+ * </pre>
+ *
+ * where each pattern segment is optional and supports full and partial
<code>*</code> wildcards. An empty pattern
+ * segment is treated as an implicit wildcard. *
+ * <p>
+ * For example, <code>org.apache.*</code> will match all artifacts whose
group id starts with
Review Comment:
will match --> matches (tech writing lives in the eternal present)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]