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
27
28
29
30 @Deprecated
31 public class JdkPrefixProfileActivator extends DetectedProfileActivator {
32 private static final String JDK_VERSION = System.getProperty("java.version");
33
34 public boolean isActive(Profile profile) throws ProfileActivationException {
35 Activation activation = profile.getActivation();
36
37 String jdk = activation.getJdk();
38
39
40 if (jdk.startsWith("[") || jdk.startsWith("(")) {
41 try {
42 return matchJdkVersionRange(jdk);
43 } catch (InvalidVersionSpecificationException e) {
44 throw new ProfileActivationException(
45 "Invalid JDK version in profile '" + profile.getId() + "': " + e.getMessage());
46 }
47 }
48
49 boolean reverse = false;
50
51 if (jdk.startsWith("!")) {
52 reverse = true;
53 jdk = jdk.substring(1);
54 }
55
56 if (getJdkVersion().startsWith(jdk)) {
57 return !reverse;
58 } else {
59 return reverse;
60 }
61 }
62
63 private boolean matchJdkVersionRange(String jdk) throws InvalidVersionSpecificationException {
64 VersionRange jdkVersionRange = VersionRange.createFromVersionSpec(convertJdkToMavenVersion(jdk));
65 DefaultArtifactVersion jdkVersion = new DefaultArtifactVersion(convertJdkToMavenVersion(getJdkVersion()));
66 return jdkVersionRange.containsVersion(jdkVersion);
67 }
68
69 private String convertJdkToMavenVersion(String jdk) {
70 return jdk.replace("_", "-");
71 }
72
73 protected String getJdkVersion() {
74 return JDK_VERSION;
75 }
76
77 protected boolean canDetectActivation(Profile profile) {
78 return profile.getActivation() != null
79 && profile.getActivation().getJdk() != null
80 && !profile.getActivation().getJdk().isEmpty();
81 }
82 }