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 java.io.IOException;
23
24 import org.apache.maven.model.Activation;
25 import org.apache.maven.model.ActivationFile;
26 import org.apache.maven.model.Profile;
27 import org.codehaus.plexus.interpolation.EnvarBasedValueSource;
28 import org.codehaus.plexus.interpolation.InterpolationException;
29 import org.codehaus.plexus.interpolation.MapBasedValueSource;
30 import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
31 import org.codehaus.plexus.logging.LogEnabled;
32 import org.codehaus.plexus.logging.Logger;
33 import org.codehaus.plexus.util.FileUtils;
34 import org.codehaus.plexus.util.StringUtils;
35
36 @Deprecated
37 public class FileProfileActivator
38 extends DetectedProfileActivator
39 implements LogEnabled
40 {
41 private Logger logger;
42
43 protected boolean canDetectActivation( Profile profile )
44 {
45 return profile.getActivation() != null && profile.getActivation().getFile() != null;
46 }
47
48 public boolean isActive( Profile profile )
49 {
50 Activation activation = profile.getActivation();
51
52 ActivationFile actFile = activation.getFile();
53
54 if ( actFile != null )
55 {
56
57 String fileString = actFile.getExists();
58
59 RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
60 try
61 {
62 interpolator.addValueSource( new EnvarBasedValueSource() );
63 }
64 catch ( IOException e )
65 {
66
67 }
68 interpolator.addValueSource( new MapBasedValueSource( System.getProperties() ) );
69
70 try
71 {
72 if ( StringUtils.isNotEmpty( fileString ) )
73 {
74 fileString = StringUtils.replace( interpolator.interpolate( fileString, "" ), "\\", "/" );
75 return FileUtils.fileExists( fileString );
76 }
77
78
79 fileString = actFile.getMissing();
80
81 if ( StringUtils.isNotEmpty( fileString ) )
82 {
83 fileString = StringUtils.replace( interpolator.interpolate( fileString, "" ), "\\", "/" );
84 return !FileUtils.fileExists( fileString );
85 }
86 }
87 catch ( InterpolationException e )
88 {
89 if ( logger.isDebugEnabled() )
90 {
91 logger.debug( "Failed to interpolate missing file location for profile activator: " + fileString,
92 e );
93 }
94 else
95 {
96 logger.warn( "Failed to interpolate missing file location for profile activator: " + fileString
97 + ". Run in debug mode (-X) for more information." );
98 }
99 }
100 }
101
102 return false;
103 }
104
105 public void enableLogging( Logger logger )
106 {
107 this.logger = logger;
108 }
109 }