1   package org.apache.maven.release;
2   
3   /* ====================================================================
4    *   Copyright 2001-2004 The Apache Software Foundation.
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing, software
13   *   distributed under the License is distributed on an "AS IS" BASIS,
14   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *   See the License for the specific language governing permissions and
16   *   limitations under the License.
17   * ====================================================================
18   */
19  
20  import org.dom4j.Node;
21  
22  /**
23   * This is a simple POM manipulator that doesn't take into account any sort of
24   * POM inheritance. When the interpolation and inheritance is cleaned up in the
25   * Maven we will be able to serialize a POM directly with greater ease. But we
26   * may stick with this Jaxen solution anyway because it's so easy. Just turn the
27   * POM in memory into a Dom4j document and perform the same operation as we are
28   * here.
29   */
30  public class DummySnapshotResolver
31      extends AbstractPomTransformer
32  {
33      // -------------------------------------------------------------------------
34      // Accessors
35      // -------------------------------------------------------------------------
36  
37      public String selectNodesXPathExpression()
38      {
39          return "/project/dependencies/dependency[version='SNAPSHOT']";
40      }
41  
42      public String selectNodeXPath()
43      {
44          return "version";
45      }
46  
47      public String getNodeContent( Node node )
48          throws Exception
49      {
50          return "NON-SNAPSHOT";
51      }
52  
53      public void transformNode( Node node )
54          throws Exception
55      {
56          // Now with our xpath expression we have the whole <dependency/>
57          // element and we want to alter the <version/> element.
58          Node version = node.selectSingleNode( selectNodeXPath() );
59          version.setText( getNodeContent( node ) );
60      }
61  
62      public Node getTransformedNode( Node node )
63          throws Exception
64      {
65          // Now with our xpath expression we have the whole <dependency/>
66          // element and we want to alter the <version/> element.
67          Node version = node.selectSingleNode( selectNodeXPath() );
68          Node transformedNode = (Node) version.clone();
69          transformedNode.setText( getNodeContent( node ) );
70  
71          return transformedNode;
72      }
73  
74  }