1 | |
package org.apache.maven.plugin.assembly.utils; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.codehaus.plexus.logging.Logger; |
23 | |
import org.codehaus.plexus.util.interpolation.ValueSource; |
24 | |
import org.codehaus.plexus.util.introspection.ReflectionValueExtractor; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class PrefixedObjectBasedValueSource |
30 | |
implements ValueSource |
31 | |
{ |
32 | |
|
33 | |
private String prefix; |
34 | |
private final Object root; |
35 | |
private final Logger logger; |
36 | |
|
37 | |
public PrefixedObjectBasedValueSource( String prefix, Object root ) |
38 | 337 | { |
39 | 337 | this.prefix = prefix; |
40 | 337 | this.root = root; |
41 | 337 | logger = null; |
42 | 337 | } |
43 | |
|
44 | |
public PrefixedObjectBasedValueSource( String prefix, Object root, Logger logger ) |
45 | 0 | { |
46 | 0 | this.prefix = prefix; |
47 | 0 | this.root = root; |
48 | 0 | this.logger = logger; |
49 | 0 | } |
50 | |
|
51 | |
public Object getValue( String expression ) |
52 | |
{ |
53 | 129 | if ( ( expression == null ) || !expression.startsWith( prefix ) ) |
54 | |
{ |
55 | 81 | return null; |
56 | |
} |
57 | |
|
58 | 48 | String realExpr = expression.substring( prefix.length() ); |
59 | 48 | if ( realExpr.startsWith( "." ) ) |
60 | |
{ |
61 | 0 | realExpr = realExpr.substring( 1 ); |
62 | |
} |
63 | |
|
64 | 48 | Object value = null; |
65 | |
try |
66 | |
{ |
67 | 48 | value = ReflectionValueExtractor.evaluate( realExpr, root, false ); |
68 | |
} |
69 | 0 | catch ( Exception e ) |
70 | |
{ |
71 | 0 | if ( ( logger != null ) && logger.isDebugEnabled() ) |
72 | |
{ |
73 | 0 | logger.debug( "Failed to extract \'" + realExpr + "\' from: " + root + " (full expression was: \'" + expression + "\').", e ); |
74 | |
} |
75 | 48 | } |
76 | |
|
77 | 48 | return value; |
78 | |
} |
79 | |
|
80 | |
} |