1 package org.apache.maven.artifact.ant;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.tools.ant.BuildException;
23 import org.apache.tools.ant.PropertyHelper;
24 import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
25
26
27
28
29 class POMPropertyHelper
30 extends PropertyHelper
31 {
32
33 protected final Pom pom;
34
35 POMPropertyHelper( Pom pom )
36 {
37 this.pom = pom;
38 }
39
40
41
42
43 public Object getPropertyHook( String ns, String name, boolean user )
44 {
45 String prefix = this.pom.antId + ".";
46
47 if ( !name.startsWith( prefix ) )
48 {
49
50 return super.getPropertyHook( ns, name, user );
51 }
52 try
53 {
54
55 String expression = name.substring( prefix.length() );
56 return getPOMValue( "project." + expression );
57 }
58 catch ( Exception ex )
59 {
60 ex.printStackTrace();
61 return null;
62 }
63 }
64
65 private static final String PROPERTIES_PREFIX = "project.properties.";
66
67 protected Object getPOMValue( String expression )
68 {
69 Object value = null;
70
71 try
72 {
73 if ( expression.startsWith( PROPERTIES_PREFIX ) )
74 {
75 expression = expression.substring( PROPERTIES_PREFIX.length() );
76 value = pom.getMavenProject().getProperties().get( expression );
77 }
78 else
79 {
80 value = ReflectionValueExtractor.evaluate( expression, pom.getMavenProject() );
81 }
82 }
83 catch ( Exception e )
84 {
85 throw new BuildException( "Error extracting expression from POM", e );
86 }
87
88 return value;
89 }
90
91 }