1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.profiles.activation;
20
21 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
22 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
23 import org.apache.maven.artifact.versioning.VersionRange;
24 import org.apache.maven.model.Activation;
25 import org.apache.maven.model.Profile;
26 import org.codehaus.plexus.util.StringUtils;
27
28
29
30
31 @Deprecated
32 public class JdkPrefixProfileActivator extends DetectedProfileActivator {
33 private static final String JDK_VERSION = System.getProperty("java.version");
34
35 public boolean isActive(Profile profile) throws ProfileActivationException {
36 Activation activation = profile.getActivation();
37
38 String jdk = activation.getJdk();
39
40
41 if (jdk.startsWith("[") || jdk.startsWith("(")) {
42 try {
43 return matchJdkVersionRange(jdk);
44 } catch (InvalidVersionSpecificationException e) {
45 throw new ProfileActivationException(
46 "Invalid JDK version in profile '" + profile.getId() + "': " + e.getMessage());
47 }
48 }
49
50 boolean reverse = false;
51
52 if (jdk.startsWith("!")) {
53 reverse = true;
54 jdk = jdk.substring(1);
55 }
56
57 if (getJdkVersion().startsWith(jdk)) {
58 return !reverse;
59 } else {
60 return reverse;
61 }
62 }
63
64 private boolean matchJdkVersionRange(String jdk) throws InvalidVersionSpecificationException {
65 VersionRange jdkVersionRange = VersionRange.createFromVersionSpec(convertJdkToMavenVersion(jdk));
66 DefaultArtifactVersion jdkVersion = new DefaultArtifactVersion(convertJdkToMavenVersion(getJdkVersion()));
67 return jdkVersionRange.containsVersion(jdkVersion);
68 }
69
70 private String convertJdkToMavenVersion(String jdk) {
71 return jdk.replaceAll("_", "-");
72 }
73
74 protected String getJdkVersion() {
75 return JDK_VERSION;
76 }
77
78 protected boolean canDetectActivation(Profile profile) {
79 return profile.getActivation() != null
80 && StringUtils.isNotEmpty(profile.getActivation().getJdk());
81 }
82 }