Skip to content

Commit bc1893f

Browse files
Use Resolver API in resolve-plugin
- change parent class to fewer details - use parameter where is needed - retrieve list of plugins from project reposting / build section
1 parent 9377649 commit bc1893f

File tree

5 files changed

+384
-101
lines changed

5 files changed

+384
-101
lines changed

src/it/projects/resolve-plugins/pom.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,55 @@
3636
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3737
</properties>
3838

39+
<build>
40+
<pluginManagement>
41+
<plugins>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-assembly-plugin</artifactId>
45+
<version>3.7.1</version>
46+
</plugin>
47+
<plugin>
48+
<groupId>org.apache.maven.plugins</groupId>
49+
<artifactId>maven-surefire-plugin</artifactId>
50+
<version>3.5.4</version>
51+
</plugin>
52+
<plugin>
53+
<groupId>org.apache.maven.plugins</groupId>
54+
<artifactId>maven-project-info-reports-plugin</artifactId>
55+
<dependencies>
56+
<dependency>
57+
<groupId>org.apache.commons</groupId>
58+
<artifactId>commons-lang3</artifactId>
59+
<version>3.18.0</version>
60+
</dependency>
61+
</dependencies>
62+
</plugin>
63+
</plugins>
64+
</pluginManagement>
65+
<plugins>
66+
<plugin>
67+
<groupId>org.apache.maven.plugins</groupId>
68+
<artifactId>maven-failsafe-plugin</artifactId>
69+
<version>3.5.4</version>
70+
</plugin>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-assembly-plugin</artifactId>
74+
</plugin>
75+
</plugins>
76+
</build>
77+
<reporting>
78+
<plugins>
79+
<plugin>
80+
<groupId>org.apache.maven.plugins</groupId>
81+
<artifactId>maven-project-info-reports-plugin</artifactId>
82+
</plugin>
83+
<plugin>
84+
<groupId>org.apache.maven.plugins</groupId>
85+
<artifactId>maven-surefire-report-plugin</artifactId>
86+
</plugin>
87+
</plugins>
88+
</reporting>
89+
3990
</project>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
package org.apache.maven.plugins.dependency.resolvers;
20+
21+
import java.util.List;
22+
import java.util.function.Predicate;
23+
24+
import org.apache.maven.model.Plugin;
25+
26+
/**
27+
* A filter to include or exclude plugins.
28+
*/
29+
class PluginsIncludeExcludeFilter implements Predicate<Plugin> {
30+
private final List<String> includesGroupId;
31+
32+
private final List<String> excludesGroupId;
33+
34+
private final List<String> includesArtifactId;
35+
36+
private final List<String> excludesArtifactId;
37+
38+
PluginsIncludeExcludeFilter(
39+
List<String> includeGroupIds,
40+
List<String> excludeGroupIds,
41+
List<String> includeArtifactIds,
42+
List<String> excludeArtifactIds) {
43+
this.includesGroupId = includeGroupIds;
44+
this.excludesGroupId = excludeGroupIds;
45+
this.includesArtifactId = includeArtifactIds;
46+
this.excludesArtifactId = excludeArtifactIds;
47+
}
48+
49+
@Override
50+
public boolean test(Plugin plugin) {
51+
if (!includesGroupId.isEmpty() && !includesGroupId.contains(plugin.getGroupId())) {
52+
return false;
53+
}
54+
55+
if (excludesGroupId.contains(plugin.getGroupId())) {
56+
return false;
57+
}
58+
59+
if (!includesArtifactId.isEmpty() && !includesArtifactId.contains(plugin.getArtifactId())) {
60+
return false;
61+
}
62+
63+
return !excludesArtifactId.contains(plugin.getArtifactId());
64+
}
65+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
package org.apache.maven.plugins.dependency.resolvers;
20+
21+
import java.util.LinkedHashSet;
22+
import java.util.List;
23+
import java.util.Set;
24+
import java.util.function.Predicate;
25+
26+
import org.apache.maven.artifact.ArtifactUtils;
27+
import org.apache.maven.model.Plugin;
28+
import org.apache.maven.project.MavenProject;
29+
30+
/**
31+
* A filter to exclude plugins that are part of the current reactor build.
32+
*/
33+
class PluginsReactorExcludeFilter implements Predicate<Plugin> {
34+
35+
private final Set<String> reactorArtifactKeys;
36+
37+
PluginsReactorExcludeFilter(List<MavenProject> reactorProjects) {
38+
this.reactorArtifactKeys = new LinkedHashSet<>(reactorProjects.size());
39+
for (final MavenProject project : reactorProjects) {
40+
this.reactorArtifactKeys.add(ArtifactUtils.key(project.getArtifact()));
41+
}
42+
}
43+
44+
@Override
45+
public boolean test(Plugin plugin) {
46+
String pluginKey = ArtifactUtils.key(plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion());
47+
return !reactorArtifactKeys.contains(pluginKey);
48+
}
49+
}

0 commit comments

Comments
 (0)