This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch MDEP-752 in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
commit 5092530624e497baeba11ff4423473fd79fd5333 Author: Slawomir Jaranowski <[email protected]> AuthorDate: Sun Sep 12 17:09:17 2021 +0200 [MDEP-752] Add ignoredPackagings options for analyze By default pom and ear packaging are ignored from analyzing. --- .../ear/pom.xml | 42 +++++++++++++++ .../ejb/pom.xml | 35 ++++++++++++ .../ejb/src/main/java/Main.java | 23 ++++++++ .../invoker.properties | 18 +++++++ .../pom.xml | 62 ++++++++++++++++++++++ .../verify.groovy | 30 +++++++++++ .../ear/pom.xml | 42 +++++++++++++++ .../ejb/pom.xml | 35 ++++++++++++ .../ejb/src/main/java/Main.java | 23 ++++++++ .../invoker.properties | 18 +++++++ .../pom.xml | 44 +++++++++++++++ .../verify.groovy | 27 ++++++++++ .../dependency/analyze/AbstractAnalyzeMojo.java | 17 ++++-- 13 files changed, 413 insertions(+), 3 deletions(-) diff --git a/src/it/projects/mdep-752-analyze-ignored-packaging-custom/ear/pom.xml b/src/it/projects/mdep-752-analyze-ignored-packaging-custom/ear/pom.xml new file mode 100644 index 0000000..62aa704 --- /dev/null +++ b/src/it/projects/mdep-752-analyze-ignored-packaging-custom/ear/pom.xml @@ -0,0 +1,42 @@ +<?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> + + <parent> + <groupId>org.apache.maven.its.dependency</groupId> + <artifactId>mdep-752-analyze-ignored-packaging-custom</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <artifactId>mdep-752-ear</artifactId> + <packaging>ear</packaging> + + <dependencies> + <dependency> + <groupId>org.apache.maven.its.dependency</groupId> + <artifactId>mdep-752-ejb</artifactId> + <version>1.0-SNAPSHOT</version> + </dependency> + </dependencies> +</project> diff --git a/src/it/projects/mdep-752-analyze-ignored-packaging-custom/ejb/pom.xml b/src/it/projects/mdep-752-analyze-ignored-packaging-custom/ejb/pom.xml new file mode 100644 index 0000000..d4527d8 --- /dev/null +++ b/src/it/projects/mdep-752-analyze-ignored-packaging-custom/ejb/pom.xml @@ -0,0 +1,35 @@ +<?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> + + <parent> + <groupId>org.apache.maven.its.dependency</groupId> + <artifactId>mdep-752-analyze-ignored-packaging-custom</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <artifactId>mdep-752-ejb</artifactId> + <packaging>ejb</packaging> + +</project> diff --git a/src/it/projects/mdep-752-analyze-ignored-packaging-custom/ejb/src/main/java/Main.java b/src/it/projects/mdep-752-analyze-ignored-packaging-custom/ejb/src/main/java/Main.java new file mode 100644 index 0000000..5e405ff --- /dev/null +++ b/src/it/projects/mdep-752-analyze-ignored-packaging-custom/ejb/src/main/java/Main.java @@ -0,0 +1,23 @@ +/* + * 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/it/projects/mdep-752-analyze-ignored-packaging-custom/invoker.properties b/src/it/projects/mdep-752-analyze-ignored-packaging-custom/invoker.properties new file mode 100644 index 0000000..0eca1be --- /dev/null +++ b/src/it/projects/mdep-752-analyze-ignored-packaging-custom/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 = ${project.groupId}:${project.artifactId}:${project.version}:analyze diff --git a/src/it/projects/mdep-752-analyze-ignored-packaging-custom/pom.xml b/src/it/projects/mdep-752-analyze-ignored-packaging-custom/pom.xml new file mode 100644 index 0000000..8fa4df1 --- /dev/null +++ b/src/it/projects/mdep-752-analyze-ignored-packaging-custom/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>mdep-752-analyze-ignored-packaging-custom</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>pom</packaging> + + <description> + Test dependency:analyze with custom ignored packaging + </description> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <modules> + <module>ear</module> + <module>ejb</module> + </modules> + + <build> + <pluginManagement> + <plugins> + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + <configuration> + <failOnWarning>true</failOnWarning> + <ignoredPackagings> + <ignoredPackaging>pom</ignoredPackaging> + <ignoredPackaging>ear</ignoredPackaging> + <ignoredPackaging>ejb</ignoredPackaging> + </ignoredPackagings> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> + +</project> diff --git a/src/it/projects/mdep-752-analyze-ignored-packaging-custom/verify.groovy b/src/it/projects/mdep-752-analyze-ignored-packaging-custom/verify.groovy new file mode 100644 index 0000000..392d161 --- /dev/null +++ b/src/it/projects/mdep-752-analyze-ignored-packaging-custom/verify.groovy @@ -0,0 +1,30 @@ +/* + * 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. + */ + +File file = new File( basedir, "build.log" ); +assert file.exists(); + +String buildLog = file.getText( "UTF-8" ); +// custom configuration for ignoredPackagings should be applied to Mojo +assert buildLog.contains( 'ignoredPackagings = [pom, ear, ejb]' ); +assert buildLog.contains( '[INFO] Skipping pom project' ); +assert buildLog.contains( '[INFO] Skipping ear project' ); +assert buildLog.contains( '[INFO] Skipping ejb project' ); + +return true; diff --git a/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/ear/pom.xml b/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/ear/pom.xml new file mode 100644 index 0000000..ea80642 --- /dev/null +++ b/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/ear/pom.xml @@ -0,0 +1,42 @@ +<?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> + + <parent> + <groupId>org.apache.maven.its.dependency</groupId> + <artifactId>mdep-752-analyze-ignored-packaging-defaults</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <artifactId>mdep-752-ear</artifactId> + <packaging>ear</packaging> + + <dependencies> + <dependency> + <groupId>org.apache.maven.its.dependency</groupId> + <artifactId>mdep-752-ejb</artifactId> + <version>1.0-SNAPSHOT</version> + </dependency> + </dependencies> +</project> diff --git a/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/ejb/pom.xml b/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/ejb/pom.xml new file mode 100644 index 0000000..546cbba --- /dev/null +++ b/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/ejb/pom.xml @@ -0,0 +1,35 @@ +<?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> + + <parent> + <groupId>org.apache.maven.its.dependency</groupId> + <artifactId>mdep-752-analyze-ignored-packaging-defaults</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <artifactId>mdep-752-ejb</artifactId> + <packaging>ejb</packaging> + +</project> diff --git a/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/ejb/src/main/java/Main.java b/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/ejb/src/main/java/Main.java new file mode 100644 index 0000000..5e405ff --- /dev/null +++ b/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/ejb/src/main/java/Main.java @@ -0,0 +1,23 @@ +/* + * 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/it/projects/mdep-752-analyze-ignored-packaging-defaults/invoker.properties b/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/invoker.properties new file mode 100644 index 0000000..0eca1be --- /dev/null +++ b/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/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 = ${project.groupId}:${project.artifactId}:${project.version}:analyze diff --git a/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/pom.xml b/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/pom.xml new file mode 100644 index 0000000..c11b388 --- /dev/null +++ b/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/pom.xml @@ -0,0 +1,44 @@ +<?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>mdep-752-analyze-ignored-packaging-defaults</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>pom</packaging> + + <description> + Test dependency:analyze with default ignored packaging + </description> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <modules> + <module>ear</module> + <module>ejb</module> + </modules> + +</project> diff --git a/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/verify.groovy b/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/verify.groovy new file mode 100644 index 0000000..2de46b2 --- /dev/null +++ b/src/it/projects/mdep-752-analyze-ignored-packaging-defaults/verify.groovy @@ -0,0 +1,27 @@ +/* + * 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. + */ + +File file = new File( basedir, "build.log" ); +assert file.exists(); + +String buildLog = file.getText( "UTF-8" ); +assert buildLog.contains( '[INFO] Skipping pom project' ); +assert buildLog.contains( '[INFO] Skipping ear project' ); + +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 d2bb601..98c9a69 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 @@ -222,6 +222,18 @@ public abstract class AbstractAnalyzeMojo @Parameter private String[] ignoredUnusedDeclaredDependencies = new String[0]; + /** + * List of project packaging that will be ignored. + * <br/> + * <b>Default value is<b>: <code>pom, ear</code> + * + * @since 3.2.1 + */ + // 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" ); + // Mojo methods ----------------------------------------------------------- /* @@ -237,9 +249,9 @@ public abstract class AbstractAnalyzeMojo return; } - if ( "pom".equals( project.getPackaging() ) ) + if ( ignoredPackagings.contains( project.getPackaging() ) ) { - getLog().info( "Skipping pom project" ); + getLog().info( "Skipping " + project.getPackaging() + " project" ); return; } @@ -521,7 +533,6 @@ public abstract class AbstractAnalyzeMojo } private List<Artifact> filterDependencies( Set<Artifact> artifacts, String[] excludes ) - throws MojoExecutionException { ArtifactFilter filter = new StrictPatternExcludesArtifactFilter( Arrays.asList( excludes ) ); List<Artifact> result = new ArrayList<>();
