KickJava   Java API By Example, From Geeks To Geeks.

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


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

23
24 public class FileProfileActivator
25     extends DetectedProfileActivator
26 {
27     protected boolean canDetectActivation( Profile profile )
28     {
29         return profile.getActivation() != null && profile.getActivation().getFile() != null;
30     }
31
32     public boolean isActive( Profile profile )
33     {
34         Activation activation = profile.getActivation();
35
36         ActivationFile actFile = activation.getFile();
37
38         if ( actFile != null )
39         {
40             // check if the file exists, if it does then the profile will be active
41
String JavaDoc fileString = actFile.getExists();
42
43             if ( fileString != null && !"".equals( fileString ) )
44             {
45                 return FileUtils.fileExists( fileString );
46             }
47
48             // check if the file is missing, if it is then the profile will be active
49
fileString = actFile.getMissing();
50
51             if ( fileString != null && !"".equals( fileString ) )
52             {
53                 return !FileUtils.fileExists( fileString );
54             }
55         }
56
57         return false;
58     }
59 }
60
Popular Tags