1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.internal.impl.model.profile;
20
21 import org.apache.maven.api.di.Named;
22 import org.apache.maven.api.di.Singleton;
23 import org.apache.maven.api.model.Activation;
24 import org.apache.maven.api.model.ActivationProperty;
25 import org.apache.maven.api.model.Profile;
26 import org.apache.maven.api.services.BuilderProblem;
27 import org.apache.maven.api.services.ModelProblem;
28 import org.apache.maven.api.services.ModelProblemCollector;
29 import org.apache.maven.api.services.model.ProfileActivationContext;
30 import org.apache.maven.api.services.model.ProfileActivator;
31
32
33
34
35
36
37 @Named("property")
38 @Singleton
39 public class PropertyProfileActivator implements ProfileActivator {
40
41 @Override
42 public boolean isActive(Profile profile, ProfileActivationContext context, ModelProblemCollector problems) {
43 Activation activation = profile.getActivation();
44
45 if (activation == null) {
46 return false;
47 }
48
49 ActivationProperty property = activation.getProperty();
50
51 if (property == null) {
52 return false;
53 }
54
55 String name = property.getName();
56 boolean reverseName = false;
57
58 if (name != null && name.startsWith("!")) {
59 reverseName = true;
60 name = name.substring(1);
61 }
62
63 if (name == null || name.isEmpty()) {
64 problems.add(
65 BuilderProblem.Severity.ERROR,
66 ModelProblem.Version.BASE,
67 "The property name is required to activate the profile " + profile.getId(),
68 property.getLocation(""));
69 return false;
70 }
71
72 String sysValue = context.getUserProperties().get(name);
73 if (sysValue == null) {
74 sysValue = context.getSystemProperties().get(name);
75 }
76
77 String propValue = property.getValue();
78 if (propValue != null && !propValue.isEmpty()) {
79 boolean reverseValue = false;
80 if (propValue.startsWith("!")) {
81 reverseValue = true;
82 propValue = propValue.substring(1);
83 }
84
85
86 return reverseValue != propValue.equals(sysValue);
87 } else {
88 return reverseName != (sysValue != null && !sysValue.isEmpty());
89 }
90 }
91
92 @Override
93 public boolean presentInConfig(Profile profile, ProfileActivationContext context, ModelProblemCollector problems) {
94 Activation activation = profile.getActivation();
95
96 if (activation == null) {
97 return false;
98 }
99
100 ActivationProperty property = activation.getProperty();
101
102 return property != null;
103 }
104 }