This is an automated email from the ASF dual-hosted git repository. michaelo pushed a commit to branch MDEP-714 in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
commit 9aa0fc026dccb64d4dc5529583ed9e936e37c394 Author: Lars Knickrehm <[email protected]> AuthorDate: Sat Jan 2 15:38:16 2021 +0100 [MDEP-714] Add analyze parameter "ignoreUnusedRuntime" This closes #123 --- .../invoker.properties | 18 +++++++ .../mdep-714-analyze-ignore-unused-runtime/pom.xml | 62 ++++++++++++++++++++++ .../src/main/java/Main.java | 22 ++++++++ .../dependency/analyze/AbstractAnalyzeMojo.java | 23 ++++++++ 4 files changed, 125 insertions(+) diff --git a/src/it/projects/mdep-714-analyze-ignore-unused-runtime/invoker.properties b/src/it/projects/mdep-714-analyze-ignore-unused-runtime/invoker.properties new file mode 100644 index 0000000..e602830 --- /dev/null +++ b/src/it/projects/mdep-714-analyze-ignore-unused-runtime/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 ${project.groupId}:${project.artifactId}:${project.version}:analyze diff --git a/src/it/projects/mdep-714-analyze-ignore-unused-runtime/pom.xml b/src/it/projects/mdep-714-analyze-ignore-unused-runtime/pom.xml new file mode 100644 index 0000000..15afd8d --- /dev/null +++ b/src/it/projects/mdep-714-analyze-ignore-unused-runtime/pom.xml @@ -0,0 +1,62 @@ +<?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 ignoreUnusedRuntime + </description> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>2.0.6</version> + <scope>runtime</scope> + </dependency> + </dependencies> + + <build> + <pluginManagement> + <plugins> + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + <configuration> + <verbose>true</verbose> + <failOnWarning>true</failOnWarning> + <ignoreUnusedRuntime>true</ignoreUnusedRuntime> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> +</project> diff --git a/src/it/projects/mdep-714-analyze-ignore-unused-runtime/src/main/java/Main.java b/src/it/projects/mdep-714-analyze-ignore-unused-runtime/src/main/java/Main.java new file mode 100644 index 0000000..293e02c --- /dev/null +++ b/src/it/projects/mdep-714-analyze-ignore-unused-runtime/src/main/java/Main.java @@ -0,0 +1,22 @@ +/* + * 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 Main +{ +} 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 d32420c..0f735ae 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 @@ -102,6 +102,12 @@ public abstract class AbstractAnalyzeMojo private boolean ignoreNonCompile; /** + * Ignore Runtime scope for unused dependency analysis. + */ + @Parameter( property = "ignoreUnusedRuntime", defaultValue = "false" ) + private boolean ignoreUnusedRuntime; + + /** * Output the xml for the missing dependencies (used but not declared). * * @since 2.0-alpha-5 @@ -324,6 +330,11 @@ public abstract class AbstractAnalyzeMojo Set<Artifact> ignoredUsedUndeclared = new LinkedHashSet<>(); Set<Artifact> ignoredUnusedDeclared = new LinkedHashSet<>(); + if ( ignoreUnusedRuntime ) + { + filterArtifactsByScope( unusedDeclared, Artifact.SCOPE_RUNTIME ); + } + ignoredUsedUndeclared.addAll( filterDependencies( usedUndeclared, ignoredDependencies ) ); ignoredUsedUndeclared.addAll( filterDependencies( usedUndeclared, ignoredUsedUndeclaredDependencies ) ); @@ -402,6 +413,18 @@ public abstract class AbstractAnalyzeMojo return warning; } + private void filterArtifactsByScope( Set<Artifact> artifacts, String scope ) + { + for ( Iterator<Artifact> iterator = artifacts.iterator(); iterator.hasNext(); ) + { + Artifact artifact = iterator.next(); + if ( artifact.getScope().equals( scope ) ) + { + iterator.remove(); + } + } + } + private void logArtifacts( Set<Artifact> artifacts, boolean warn ) { if ( artifacts.isEmpty() )
