1 package org.apache.maven.plugin.war.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.Properties;
25
26 import org.apache.maven.artifact.Artifact;
27 import org.codehaus.plexus.interpolation.InterpolationException;
28 import org.codehaus.plexus.interpolation.ObjectBasedValueSource;
29 import org.codehaus.plexus.interpolation.PropertiesBasedValueSource;
30 import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
31 import org.codehaus.plexus.interpolation.ValueSource;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public class MappingUtils
50 {
51
52
53
54
55
56
57
58
59 public static String evaluateFileNameMapping( String expression, Artifact artifact )
60 throws InterpolationException
61 {
62 String value = expression;
63
64
65 artifact.isSnapshot();
66
67 RegexBasedInterpolator interpolator = new RegexBasedInterpolator( "\\@\\{(", ")?([^}]+)\\}@" );
68 interpolator.addValueSource( new ObjectBasedValueSource( artifact ) );
69 interpolator.addValueSource( new ObjectBasedValueSource( artifact.getArtifactHandler() ) );
70
71 Properties classifierMask = new Properties();
72 classifierMask.setProperty( "classifier", "" );
73
74
75 String classifier = artifact.getClassifier();
76 if ( classifier != null )
77 {
78 classifierMask.setProperty( "dashClassifier?", "-" + classifier );
79 classifierMask.setProperty( "dashClassifier", "-" + classifier );
80 }
81 else
82 {
83 classifierMask.setProperty( "dashClassifier?", "" );
84 classifierMask.setProperty( "dashClassifier", "" );
85 }
86
87 interpolator.addValueSource( new PropertiesBasedValueSource ( classifierMask ) );
88
89 value = interpolator.interpolate( value, "__artifact" );
90
91 return value;
92 }
93
94
95
96
97
98 static class PropertiesInterpolationValueSource
99 implements ValueSource
100 {
101
102 private final Properties properties;
103
104 public PropertiesInterpolationValueSource( Properties properties )
105 {
106 this.properties = properties;
107 }
108
109 public Object getValue( String key )
110 {
111 return properties.getProperty( key );
112 }
113
114 public void clearFeedback()
115 {
116
117
118 }
119
120 public List getFeedback()
121 {
122
123 return Collections.EMPTY_LIST;
124 }
125
126 }
127
128 }