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