-
-
Notifications
You must be signed in to change notification settings - Fork 303
/
PluginExecutions.java
62 lines (47 loc) · 1.65 KB
/
PluginExecutions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package aQute.bnd.maven.lib.executions;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import org.apache.maven.model.PluginExecution;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import aQute.bnd.unmodifiable.Sets;
public class PluginExecutions {
static final Set<String> PACKAGING_GOALS = Sets.of("jar", "test-jar", "war");
private PluginExecutions() {}
public static String defaultClassifier(PluginExecution pluginExecution) {
List<String> goals = pluginExecution.getGoals();
if (goals.contains("jar") || goals.contains("war")) {
return "";
}
if (goals.contains("test-jar")) {
return "tests";
}
return "";
}
public static String extractClassifier(PluginExecution pluginExecution) {
Xpp3Dom rootConfiguration = (Xpp3Dom) pluginExecution.getConfiguration();
if (rootConfiguration == null) {
return defaultClassifier(pluginExecution);
}
Xpp3Dom classifierConfiguration = rootConfiguration.getChild("classifier");
if (classifierConfiguration == null) {
return defaultClassifier(pluginExecution);
}
return Optional.ofNullable(classifierConfiguration.getValue())
.map(String::trim)
.filter(s -> !s.isEmpty())
.orElse("");
}
public static boolean isPackagingGoal(PluginExecution pluginExecution) {
return pluginExecution.getGoals()
.stream()
.anyMatch(PluginExecutions::isPackagingGoal);
}
public static boolean isPackagingGoal(String goal) {
return PACKAGING_GOALS.contains(goal);
}
public static boolean matchesClassifier(PluginExecution pluginExecution, String classifier) {
return Objects.equals(extractClassifier(pluginExecution), classifier);
}
}