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