Skip to content

Commit 0db1acc

Browse files
Use Resolver API in go-offline for dependencies resolving (#1533)
* Use Resolver API in go-offline for dependencies resolving - add assertions in IT test - filters should be rewritten to Resolver API * invoker 3.9.1
1 parent e50031a commit 0db1acc

File tree

8 files changed

+149
-214
lines changed

8 files changed

+149
-214
lines changed

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ under the License.
9999
<plexus-archiver.version>4.10.1</plexus-archiver.version>
100100
<pluginTestingVersion>3.3.0</pluginTestingVersion>
101101

102+
<!-- TODO remove with next parent -->
103+
<version.maven-invoker-plugin>3.9.1</version.maven-invoker-plugin>
104+
102105
<!-- strict check by dependency:analyze-only -->
103106
<enforce.dependency.declarations>true</enforce.dependency.declarations>
104107
<project.build.outputTimestamp>2024-10-18T18:16:14Z</project.build.outputTimestamp>

src/it/projects/go-offline/pom.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,24 @@
3636
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3737
</properties>
3838

39+
3940
<dependencies>
4041
<dependency>
4142
<groupId>org.apache.maven</groupId>
42-
<artifactId>maven-project</artifactId>
43-
<version>2.0.6</version>
43+
<artifactId>maven-core</artifactId>
44+
<version>3.9.11</version>
4445
</dependency>
4546
</dependencies>
4647

48+
<build>
49+
<pluginManagement>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.apache.maven.plugins</groupId>
53+
<artifactId>maven-clean-plugin</artifactId>
54+
<version>3.5.0</version>
55+
</plugin>
56+
</plugins>
57+
</pluginManagement>
58+
</build>
4759
</project>

src/it/projects/go-offline/test.properties

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
File file = new File(basedir, 'build.log')
21+
assert file.exists()
22+
23+
String buildLog = file.getText("UTF-8")
24+
25+
assert buildLog.contains('[INFO] Resolved plugin: maven-clean-plugin-3.5.0.jar')
26+
assert buildLog.contains('[INFO] Resolved plugin dependency:')
27+
assert buildLog.contains('[INFO] maven-clean-plugin-3.5.0.jar')
28+
assert buildLog.contains('[INFO] plexus-utils-4.0.2.jar')
29+
30+
assert buildLog.contains('[INFO] Resolved dependency: maven-core-3.9.11.jar')
31+
assert buildLog.contains('[INFO] Resolved dependency: maven-model-3.9.11.jar')
32+
assert buildLog.contains('[INFO] Resolved dependency: maven-settings-3.9.11.jar')
33+
34+

src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsDependencyFilter.java

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,57 +20,39 @@
2020

2121
import java.util.List;
2222
import java.util.Set;
23+
import java.util.function.Predicate;
2324
import java.util.stream.Collectors;
2425

2526
import org.apache.maven.artifact.ArtifactUtils;
2627
import org.apache.maven.model.Dependency;
27-
import org.apache.maven.plugin.logging.Log;
2828
import org.apache.maven.project.MavenProject;
29-
import org.apache.maven.shared.artifact.filter.resolve.AbstractFilter;
30-
import org.apache.maven.shared.artifact.filter.resolve.Node;
31-
import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
3231

3332
/**
34-
* {@link TransformableFilter} implementation that excludes artifacts found in the Reactor.
33+
* Filter implementation that excludes artifacts found in the Reactor.
3534
*
3635
* @author Maarten Mulders
3736
*/
38-
public class ExcludeReactorProjectsDependencyFilter extends AbstractFilter {
39-
private final Log log;
37+
public class ExcludeReactorProjectsDependencyFilter implements Predicate<Dependency> {
38+
private final Logger log = LoggerFactory.getLogger(ExcludeReactorProjectsDependencyFilter.class);
4039
private final Set<String> reactorArtifactKeys;
4140

42-
public ExcludeReactorProjectsDependencyFilter(final List<MavenProject> reactorProjects, final Log log) {
43-
this.log = log;
41+
public ExcludeReactorProjectsDependencyFilter(final List<MavenProject> reactorProjects) {
4442
this.reactorArtifactKeys = reactorProjects.stream()
4543
.map(project -> ArtifactUtils.key(project.getArtifact()))
4644
.collect(Collectors.toSet());
4745
}
4846

4947
@Override
50-
public boolean accept(final Node node, final List<Node> parents) {
51-
final Dependency dependency = node.getDependency();
52-
if (dependency != null) {
53-
final String dependencyArtifactKey =
54-
ArtifactUtils.key(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
55-
56-
final boolean result = isDependencyArtifactInReactor(dependencyArtifactKey);
57-
58-
if (log.isDebugEnabled() && result) {
59-
log.debug("Skipped dependency " + dependencyArtifactKey + " because it is present in the reactor");
48+
public boolean test(Dependency dependency) {
49+
String key = ArtifactUtils.key(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
50+
if (reactorArtifactKeys.contains(key)) {
51+
if (log.isDebugEnabled()) {
52+
log.debug("Skipped dependency {} because it is present in the reactor", key);
6053
}
61-
62-
return !result;
54+
return false;
6355
}
6456
return true;
6557
}
66-
67-
private boolean isDependencyArtifactInReactor(final String dependencyArtifactKey) {
68-
for (final String reactorArtifactKey : this.reactorArtifactKeys) {
69-
// This check only includes GAV. Should we take a look at the types, too?
70-
if (reactorArtifactKey.equals(dependencyArtifactKey)) {
71-
return true;
72-
}
73-
}
74-
return false;
75-
}
7658
}

0 commit comments

Comments
 (0)