1 package org.apache.maven.release;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import org.dom4j.Document;
21 import org.dom4j.io.SAXReader;
22 import org.jaxen.XPath;
23 import org.jaxen.dom4j.Dom4jXPath;
24
25 import java.io.File;
26 import java.util.ArrayList;
27 import java.util.List;
28
29 /**
30 * This is a simple POM manipulator that doesn't take into account any sort of
31 * POM inheritance. When the interpolation and inheritance is cleaned up in the
32 * Maven we will be able to serialize a POM directly with greater ease. But we
33 * may stick with this Jaxen solution anyway because it's so easy. Just turn the
34 * POM in memory into a Dom4j document and perform the same operation as we are
35 * here.
36 */
37 public class PomNodeSelector
38 {
39 /**
40 * POM document
41 */
42 private File pom;
43
44 /**
45 * Xpath expression.
46 */
47 private String xpathExpression;
48
49 /**
50 * Snapshot dependencies found.
51 */
52 private List nodes;
53
54 /**
55 * Constructor.
56 */
57 public PomNodeSelector()
58 {
59 nodes = new ArrayList();
60 }
61
62
63
64
65
66 public void setXpathExpression( String xpathExpression )
67 {
68 this.xpathExpression = xpathExpression;
69 }
70
71 public String getXpathExpression()
72 {
73 return xpathExpression;
74 }
75
76 /**
77 * Sets the nodes attribute of the PomManipulator object
78 */
79 public void setNodes( List nodes )
80 {
81 this.nodes = nodes;
82 }
83
84 /**
85 * Gets the nodes attribute of the PomManipulator object
86 */
87 public List getNodes()
88 {
89 return nodes;
90 }
91
92 public void setPom( File pom )
93 {
94 this.pom = pom;
95 }
96
97 public File getPom()
98 {
99 return pom;
100 }
101
102 /**
103 * Update the snapshot version identifiers with actual timestamp versions
104 * and write out the POM in its updated form.
105 *
106 * @throws Exception
107 */
108 public void execute()
109 throws Exception
110 {
111 SAXReader reader = new SAXReader();
112 Document doc = reader.read( getPom() );
113
114
115
116
117
118 XPath xpath = new Dom4jXPath( getXpathExpression() );
119 setNodes( xpath.selectNodes( doc ) );
120 }
121 }