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