KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > profiles > activation > JdkPrefixProfileActivator


1 package org.apache.maven.profiles.activation;
2
3 import org.apache.maven.model.Activation;
4 import org.apache.maven.model.Profile;
5 import org.codehaus.plexus.util.StringUtils;
6
7 /*
8  * Copyright 2001-2005 The Apache Software Foundation.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */

22
23 public class JdkPrefixProfileActivator
24     extends DetectedProfileActivator
25 {
26     private static final String JavaDoc JDK_VERSION = System.getProperty( "java.version" );
27
28     public boolean isActive( Profile profile )
29     {
30         Activation activation = profile.getActivation();
31
32         String JavaDoc jdk = activation.getJdk();
33         
34         boolean reverse = false;
35         
36         if ( jdk.startsWith( "!" ) )
37         {
38             reverse = true;
39             jdk = jdk.substring( 1 );
40         }
41
42         // null case is covered by canDetermineActivation(), so we can do a straight startsWith() here.
43
boolean result = JDK_VERSION.startsWith( jdk );
44         
45         if ( reverse )
46         {
47             return !result;
48         }
49         else
50         {
51             return result;
52         }
53     }
54
55     protected boolean canDetectActivation( Profile profile )
56     {
57         return profile.getActivation() != null && StringUtils.isNotEmpty( profile.getActivation().getJdk() );
58     }
59
60 }
61
Popular Tags