This is an automated email from the ASF dual-hosted git repository. sjaranowski pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git
The following commit(s) were added to refs/heads/master by this push: new 1bd7bb2 [MINVOKER-368] Filter artifacts by scope before resolving in install 1bd7bb2 is described below commit 1bd7bb2d009b40d747fad3808458d984c4abde21 Author: Slawomir Jaranowski <s.jaranow...@gmail.com> AuthorDate: Sat Jul 6 09:11:50 2024 +0200 [MINVOKER-368] Filter artifacts by scope before resolving in install --- src/it/MINVOKER-368-install-filter-scope/pom.xml | 76 ++++++++++++++++++++++ .../verify.groovy | 32 +++++++++ .../apache/maven/plugins/invoker/InstallMojo.java | 13 ++-- 3 files changed, 112 insertions(+), 9 deletions(-) diff --git a/src/it/MINVOKER-368-install-filter-scope/pom.xml b/src/it/MINVOKER-368-install-filter-scope/pom.xml new file mode 100644 index 0000000..ed5374e --- /dev/null +++ b/src/it/MINVOKER-368-install-filter-scope/pom.xml @@ -0,0 +1,76 @@ +<?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/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.plugins.invoker</groupId> + <artifactId>MINVOKER-368</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>pom</packaging> + + <description> + Test to check for scope filtering during installation. + </description> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <!-- shared-utils has dependencies to commons-io:2.11.0 --> + <!-- in runtime this version will be used --> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-shared-utils</artifactId> + <version>3.4.2</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.16.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-invoker-plugin</artifactId> + <version>@project.version@</version> + <configuration> + <localRepositoryPath>${project.build.directory}/it-repo</localRepositoryPath> + </configuration> + <executions> + <execution> + <id>integration-test</id> + <phase>initialize</phase> + <goals> + <goal>install</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> diff --git a/src/it/MINVOKER-368-install-filter-scope/verify.groovy b/src/it/MINVOKER-368-install-filter-scope/verify.groovy new file mode 100644 index 0000000..1a8e1c2 --- /dev/null +++ b/src/it/MINVOKER-368-install-filter-scope/verify.groovy @@ -0,0 +1,32 @@ +/* + * 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. + */ + + +def expected = [ + 'org/apache/maven/shared/maven-shared-utils/3.4.2/maven-shared-utils-3.4.2.pom', + 'org/apache/maven/shared/maven-shared-utils/3.4.2/maven-shared-utils-3.4.2.jar', + 'commons-io/commons-io/2.11.0/commons-io-2.11.0.pom', + 'commons-io/commons-io/2.11.0/commons-io-2.11.0.jar' +] + +def localRepo = new File(basedir, 'target/it-repo') + +def missingFiles = expected.findAll { !new File(localRepo, it).isFile() } + +assert missingFiles == [] diff --git a/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java b/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java index 0a7ec02..8894ef9 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java +++ b/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java @@ -52,6 +52,7 @@ import org.eclipse.aether.artifact.ArtifactType; import org.eclipse.aether.artifact.ArtifactTypeRegistry; import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.collection.CollectRequest; +import org.eclipse.aether.graph.DefaultDependencyNode; import org.eclipse.aether.graph.Dependency; import org.eclipse.aether.graph.DependencyFilter; import org.eclipse.aether.installation.InstallRequest; @@ -59,7 +60,6 @@ import org.eclipse.aether.installation.InstallationException; import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.LocalRepositoryManager; import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.resolution.ArtifactDescriptorException; import org.eclipse.aether.resolution.ArtifactRequest; import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.resolution.ArtifactResult; @@ -172,10 +172,7 @@ public class InstallMojo extends AbstractMojo { resolveExtraArtifacts(resolvedArtifacts); installArtifacts(resolvedArtifacts); - } catch (DependencyResolutionException - | InstallationException - | ArtifactDescriptorException - | ArtifactResolutionException e) { + } catch (DependencyResolutionException | InstallationException | ArtifactResolutionException e) { throw new MojoExecutionException(e.getMessage(), e); } } @@ -227,6 +224,7 @@ public class InstallMojo extends AbstractMojo { List<Dependency> dependencies = project.getDependencies().stream() .map(d -> RepositoryUtils.toDependency(d, artifactTypeRegistry)) + .filter(d -> classpathFilter.accept(new DefaultDependencyNode(d), null)) .collect(Collectors.toList()); CollectRequest collectRequest = new CollectRequest(); @@ -251,12 +249,9 @@ public class InstallMojo extends AbstractMojo { /** * Resolve extra artifacts. - * - * @return */ private void resolveExtraArtifacts(Map<String, Artifact> resolvedArtifacts) - throws MojoExecutionException, DependencyResolutionException, ArtifactDescriptorException, - ArtifactResolutionException { + throws MojoExecutionException, DependencyResolutionException, ArtifactResolutionException { if (extraArtifacts == null) { return;