1 package org.apache.maven.project.harness;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Iterator;
24
25 import org.apache.commons.jxpath.JXPathContext;
26 import org.apache.commons.jxpath.JXPathNotFoundException;
27 import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl;
28 import org.apache.maven.project.MavenProject;
29
30 public class PomTestWrapper
31 {
32
33 private File pomFile;
34
35 private JXPathContext context;
36
37 private MavenProject mavenProject;
38
39 static
40 {
41 JXPathContextReferenceImpl.addNodePointerFactory( new Xpp3DomPointerFactory() );
42 }
43
44 public PomTestWrapper( File pomFile, MavenProject mavenProject )
45 {
46 if ( mavenProject == null )
47 {
48 throw new IllegalArgumentException( "mavenProject: null" );
49 }
50 this.mavenProject = mavenProject;
51 this.pomFile = pomFile;
52 context = JXPathContext.newContext( mavenProject.getModel() );
53 }
54
55 public PomTestWrapper( MavenProject mavenProject )
56 {
57 if ( mavenProject == null )
58 {
59 throw new IllegalArgumentException( "mavenProject: null" );
60 }
61 this.mavenProject = mavenProject;
62 context = JXPathContext.newContext( mavenProject.getModel() );
63 }
64
65 public MavenProject getMavenProject()
66 {
67 return mavenProject;
68 }
69
70 public File getBasedir()
71 {
72 return ( pomFile != null ) ? pomFile.getParentFile() : null;
73 }
74
75 public void setValueOnModel( String expression, Object value )
76 {
77 context.setValue( expression, value );
78 }
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 public Iterator<?> getIteratorForXPathExpression( String expression )
95 {
96 return context.iterate( expression );
97 }
98
99 public boolean containsXPathExpression( String expression )
100 {
101 return context.getValue( expression ) != null;
102 }
103
104 public Object getValue( String expression )
105 {
106 try
107 {
108 return context.getValue( expression );
109 }
110 catch ( JXPathNotFoundException e )
111 {
112 return null;
113 }
114 }
115
116 public boolean xPathExpressionEqualsValue( String expression, String value )
117 {
118 return context.getValue( expression ) != null && context.getValue( expression ).equals( value );
119 }
120
121 }