View Javadoc

1   package org.apache.maven.plugins.scm.release;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  import org.dom4j.Node;
22  
23  /**
24   *
25   *
26   * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
27   *
28   * @version $Id: SnapshotVersionTransformer.java 521198 2007-03-22 10:39:43Z ltheussl $
29   */
30  public class SnapshotVersionTransformer
31      extends AbstractPomTransformer
32  {
33      // -------------------------------------------------------------------------
34      // Accessors
35      // -------------------------------------------------------------------------
36  
37      public String selectNodesXPathExpression()
38      {
39          return "/project";
40      }
41  
42      public String selectNodeXPath()
43      {
44          return "currentVersion";
45      }
46  
47      public String getNodeContent( Node node )
48          throws Exception
49      {
50          String currentVersion = node.selectSingleNode( selectNodeXPath() ).getText();
51  
52          int i = currentVersion.indexOf( "-SNAPSHOT" );
53          if ( i > 0 )
54          {
55              currentVersion = currentVersion.substring( 0, i );
56          }
57  
58          return currentVersion;
59      }
60  
61      public void transformNode( Node node )
62          throws Exception
63      {
64          Node currentVersion = node.selectSingleNode( selectNodeXPath() );
65          currentVersion.setText( getNodeContent( node ) );
66      }
67  
68      public Node getTransformedNode( Node node )
69          throws Exception
70      {
71          Node transformedNode = (Node) node.clone();
72          Node currentVersion = transformedNode.selectSingleNode( selectNodeXPath() );
73          currentVersion.setText( getNodeContent( transformedNode ) );
74  
75          return transformedNode;
76      }
77  }