Skip to content

Commit

Permalink
[MINVOKER-368] Filter artifacts by scope before resolving in install
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Jul 11, 2024
1 parent affa7be commit 1bd7bb2
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 9 deletions.
76 changes: 76 additions & 0 deletions src/it/MINVOKER-368-install-filter-scope/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
32 changes: 32 additions & 0 deletions src/it/MINVOKER-368-install-filter-scope/verify.groovy
Original file line number Diff line number Diff line change
@@ -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 == []
13 changes: 4 additions & 9 deletions src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@
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;
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;
Expand Down Expand Up @@ -172,10 +172,7 @@ public void execute() throws MojoExecutionException {
resolveExtraArtifacts(resolvedArtifacts);
installArtifacts(resolvedArtifacts);

} catch (DependencyResolutionException
| InstallationException
| ArtifactDescriptorException
| ArtifactResolutionException e) {
} catch (DependencyResolutionException | InstallationException | ArtifactResolutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
Expand Down Expand Up @@ -227,6 +224,7 @@ private void resolveProjectDependencies(Map<String, Artifact> resolvedArtifacts)

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();
Expand All @@ -251,12 +249,9 @@ private void resolveProjectDependencies(Map<String, Artifact> resolvedArtifacts)

/**
* Resolve extra artifacts.
*
* @return
*/
private void resolveExtraArtifacts(Map<String, Artifact> resolvedArtifacts)
throws MojoExecutionException, DependencyResolutionException, ArtifactDescriptorException,
ArtifactResolutionException {
throws MojoExecutionException, DependencyResolutionException, ArtifactResolutionException {

if (extraArtifacts == null) {
return;
Expand Down

0 comments on commit 1bd7bb2

Please sign in to comment.