View Javadoc

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   *
24   *
25   * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
26   *
27   * @version $Id: SnapshotVersionTransformer.java 170200 2005-05-15 06:24:19Z brett $
28   */
29  public class SnapshotVersionTransformer
30      extends AbstractPomTransformer
31  {
32      // -------------------------------------------------------------------------
33      // Accessors
34      // -------------------------------------------------------------------------
35  
36      public String selectNodesXPathExpression()
37      {
38          return "/project";
39      }
40  
41      public String selectNodeXPath()
42      {
43          return "currentVersion";
44      }
45  
46      public String getNodeContent( Node node )
47          throws Exception
48      {
49          String currentVersion = node.selectSingleNode( selectNodeXPath() ).getText();
50  
51          int i = currentVersion.indexOf( "-SNAPSHOT" );
52          if ( i > 0 )
53          {
54              currentVersion = currentVersion.substring( 0, i );
55          }
56  
57          return currentVersion;
58      }
59  
60      public void transformNode( Node node )
61          throws Exception
62      {
63          Node currentVersion = node.selectSingleNode( selectNodeXPath() );
64          currentVersion.setText( getNodeContent( node ) );
65      }
66  
67      public Node getTransformedNode( Node node )
68          throws Exception
69      {
70          Node transformedNode = (Node) node.clone();
71          Node currentVersion = transformedNode.selectSingleNode( selectNodeXPath() );
72          currentVersion.setText( getNodeContent( transformedNode ) );
73  
74          return transformedNode;
75      }
76  }