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.util.FileUtils; |
32 | |
import org.codehaus.plexus.util.StringUtils; |
33 | |
|
34 | 0 | public class FileProfileActivator |
35 | |
extends DetectedProfileActivator |
36 | |
{ |
37 | |
protected boolean canDetectActivation( Profile profile ) |
38 | |
{ |
39 | 0 | return profile.getActivation() != null && profile.getActivation().getFile() != null; |
40 | |
} |
41 | |
|
42 | |
public boolean isActive( Profile profile ) |
43 | |
{ |
44 | 0 | Activation activation = profile.getActivation(); |
45 | |
|
46 | 0 | ActivationFile actFile = activation.getFile(); |
47 | |
|
48 | 0 | if ( actFile != null ) |
49 | |
{ |
50 | |
|
51 | 0 | String fileString = actFile.getExists(); |
52 | |
|
53 | 0 | RegexBasedInterpolator interpolator = new RegexBasedInterpolator(); |
54 | |
try |
55 | |
{ |
56 | 0 | interpolator.addValueSource( new EnvarBasedValueSource() ); |
57 | |
} |
58 | 0 | catch ( IOException e ) |
59 | |
{ |
60 | |
|
61 | 0 | } |
62 | 0 | interpolator.addValueSource( new MapBasedValueSource( System.getProperties() ) ); |
63 | |
|
64 | 0 | if ( StringUtils.isNotEmpty( fileString ) ) |
65 | |
{ |
66 | |
try |
67 | |
{ |
68 | 0 | fileString = interpolator.interpolate( fileString, "" ); |
69 | |
} |
70 | 0 | catch ( InterpolationException e ) |
71 | |
{ |
72 | 0 | getLogger().debug( "Failed to interpolate path in file profile activator: " + fileString, e ); |
73 | 0 | } |
74 | |
|
75 | 0 | fileString = StringUtils.replace( fileString, "\\", "/" ); |
76 | 0 | return FileUtils.fileExists( fileString ); |
77 | |
} |
78 | |
|
79 | |
|
80 | 0 | fileString = actFile.getMissing(); |
81 | |
|
82 | 0 | if ( StringUtils.isNotEmpty( fileString ) ) |
83 | |
{ |
84 | |
try |
85 | |
{ |
86 | 0 | fileString = interpolator.interpolate( fileString, "" ); |
87 | |
} |
88 | 0 | catch ( InterpolationException e ) |
89 | |
{ |
90 | 0 | getLogger().debug( "Failed to interpolate path in file profile activator: " + fileString, e ); |
91 | 0 | } |
92 | |
|
93 | 0 | fileString = StringUtils.replace( fileString, "\\", "/" ); |
94 | 0 | return !FileUtils.fileExists( fileString ); |
95 | |
} |
96 | |
} |
97 | |
|
98 | 0 | return false; |
99 | |
} |
100 | |
} |