transformations for releasing projects that update versions

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@114745 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
brett 2004-02-25 22:34:46 +00:00
parent fad3b5e6c4
commit f7c6c104c4
14 changed files with 719 additions and 19 deletions

View File

@ -3,6 +3,7 @@
<project
xmlns:ant="jelly:ant"
xmlns:archive="release:archive"
xmlns:transform="release:transform"
xmlns:define="jelly:define"
xmlns:deploy="deploy"
xmlns:maven="jelly:maven"
@ -99,6 +100,28 @@
</define:tag>
</define:taglib>
<define:taglib uri="release:transform">
<define:tag name="release-version">
<r:release-version
version="${version}"
tag="${tag}"
transformer="transformer"
transformations="transformations"/>
<j:set var="required" value="${transformer.transformRequired()}" />
<j:if test="${required}">
<ant:echo>Updating POM with version ${version}; tag ${tag}</ant:echo>
${transformer.transformNodes()}
${transformer.write()}
</j:if>
</define:tag>
</define:taglib>
<goal name="release:update-pom">
<transform:release-version
version="${version}"
tag="${tag}" />
</goal>
<!--
|
| Convert SNAPSHOT version identifiers to real snapshot versions.

View File

@ -84,7 +84,7 @@ import java.util.Map;
*
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
*
* @version $Id: AbstractPomTransformer.java,v 1.8 2003/04/12 08:12:46 dion Exp $
* @version $Id: AbstractPomTransformer.java,v 1.9 2004/02/25 22:34:46 brett Exp $
*/
public abstract class AbstractPomTransformer
implements PomTransformer
@ -284,23 +284,6 @@ public abstract class AbstractPomTransformer
*/
public abstract String selectNodesXPathExpression();
/**
* The XPath expression returned will select the single node
* within the single node which needs to be transformed.
*
* @return
*/
public abstract String selectNodeXPath();
/**
*
* @param node
* @return
* @throws Exception
*/
public abstract String getNodeContent( Node node )
throws Exception;
/**
*
* @param node

View File

@ -0,0 +1,145 @@
package org.apache.maven.release;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
import org.apache.commons.io.FileUtils;
import org.apache.maven.MavenConstants;
import org.apache.maven.project.Project;
import org.apache.maven.util.HttpUtils;
import org.dom4j.Element;
import org.dom4j.Node;
import java.io.File;
import java.util.Iterator;
/**
*
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*
* @version $Id: VersionTransformer.java,v 1.1 2004/02/25 22:34:46 brett Exp $
*/
public class VersionTransformer
extends AbstractPomTransformer
{
private String version;
private String tag;
public VersionTransformer( String version, String tag )
{
this.version = version;
this.tag = tag;
}
// -------------------------------------------------------------------------
// Accessors
// -------------------------------------------------------------------------
public String selectNodesXPathExpression()
{
return "/project";
}
public void transformNode( Node node )
throws Exception
{
Node currentVersion = node.selectSingleNode( "currentVersion" );
currentVersion.setText( version );
Node version = node.selectSingleNode( "versions/version[tag='" + tag + "']" );
if ( version != null )
{
// tag exists - overwrite
version.selectSingleNode( "id" ).setText( this.version );
version.selectSingleNode( "name" ).setText( this.version );
}
else
{
// tag doesn't exist - add
Element project = ( Element ) node;
Element versions = ( Element ) project.selectSingleNode( "versions" );
if ( versions == null )
{
versions = project.addElement( "versions" );
}
Element v = versions.addElement( "version" );
v.addElement( "id" ).addText( this.version );
v.addElement( "name" ).addText( this.version );
v.addElement( "tag" ).addText( tag );
}
}
public Node getTransformedNode( Node node )
throws Exception
{
throw new UnsupportedOperationException( "getTransformedNode not implemented" );
}
public boolean transformRequired()
{
Node node = ( Node ) getSelectedNodes().get( 0 );
Node currentVersion = node.selectSingleNode( "currentVersion" );
if ( !currentVersion.getText().equals( version ))
{
return true;
}
Node v = node.selectSingleNode( "versions/version[tag='" + tag + "' and id='" + version + "' and name='" + version + "']" );
return ( v == null );
}
}

View File

@ -6,7 +6,7 @@ import org.apache.commons.jelly.tags.core.CoreTagLibrary;
* Release tag library.
*
* @author <a href="jason@zenplex.com">Jason van Zyl</a>
* @version $Id: ReleaseTagLibrary.java,v 1.3 2003/02/11 22:01:13 jvanzyl Exp $
* @version $Id: ReleaseTagLibrary.java,v 1.4 2004/02/25 22:34:46 brett Exp $
*/
public class ReleaseTagLibrary
extends CoreTagLibrary
@ -19,5 +19,6 @@ public class ReleaseTagLibrary
{
registerTag( "resolve-snapshots", ResolveSnapshotsTag.class );
registerTag( "increment-snapshot-version", SnapshotVersionTransformerTag.class );
registerTag( "release-version", VersionTransformerTag.class );
}
}

View File

@ -0,0 +1,107 @@
package org.apache.maven.release.jelly;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.XMLOutput;
import org.apache.maven.MavenConstants;
import org.apache.maven.project.Project;
import org.apache.maven.release.VersionTransformer;
public class VersionTransformerTag
extends AbstractTransformerTag
{
private VersionTransformer transformer;
private String version;
private String tag;
public String getVersion()
{
return this.version;
}
public void setVersion( String version )
{
this.version = version;
}
public String getTag()
{
return this.tag;
}
public void setTag( String tag )
{
this.tag = tag;
}
public void doTag( XMLOutput output )
throws JellyTagException
{
Project project = (Project) context.getVariable( MavenConstants.MAVEN_POM );
transformer = new VersionTransformer( version, tag );
transformer.setProject( project.getFile() );
transformer.setVariables( project.getContext().getVariables() );
transformer.setOutputFile( project.getFile() );
context.setVariable( getTransformer(), transformer );
context.setVariable( getTransformations(), transformer.getTransformations() );
}
}

View File

@ -0,0 +1,5 @@
<project>
<currentVersion>1.2-SNAPSHOT</currentVersion>
</project>

View File

@ -0,0 +1,18 @@
<project>
<currentVersion>1.2</currentVersion>
<versions>
<version>
<id>1.0</id>
<name>1.0</name>
<tag>TEST_1_0</tag>
</version>
<version>
<id>1.2</id>
<name>1.2</name>
<tag>TEST_1_2</tag>
</version>
</versions>
</project>

View File

@ -0,0 +1,18 @@
<project>
<currentVersion>1.2-SNAPSHOT</currentVersion>
<versions>
<version>
<id>1.0</id>
<name>1.0</name>
<tag>TEST_1_0</tag>
</version>
<version>
<id>1.1</id>
<name>1.1</name>
<tag>TEST_1_1</tag>
</version>
</versions>
</project>

View File

@ -0,0 +1,18 @@
<project>
<currentVersion>1.2-SNAPSHOT</currentVersion>
<versions>
<version>
<id>1.0</id>
<name>1.0</name>
<tag>TEST_1_0</tag>
</version>
<version>
<id>1.2</id>
<name>1.2</name>
<tag>TEST_1_2</tag>
</version>
</versions>
</project>

View File

@ -0,0 +1,13 @@
<project>
<currentVersion>1.2-SNAPSHOT</currentVersion>
<versions>
<version>
<id>1.2-SNAPSHOT</id>
<name>1.2-SNAPSHOT</name>
<tag>TEST_1_2</tag>
</version>
</versions>
</project>

View File

@ -0,0 +1,18 @@
<project>
<currentVersion>1.2-SNAPSHOT</currentVersion>
<versions>
<version>
<id>1.1</id>
<name>1.1</name>
<tag>TEST_1_1</tag>
</version>
<version>
<id>1.0</id>
<name>1.0</name>
<tag>TEST_1_0</tag>
</version>
</versions>
</project>

View File

@ -0,0 +1,13 @@
<project>
<currentVersion>1.2-SNAPSHOT</currentVersion>
<versions>
<version>
<id>1.1</id>
<name>1.1</name>
<tag>TEST_1_1</tag>
</version>
</versions>
</project>

View File

@ -0,0 +1,332 @@
package org.apache.maven.release;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import junit.framework.TestCase;
import java.io.File;
import java.util.List;
import org.dom4j.Node;
/**
*/
public class VersionTransformerTest
extends TestCase
{
/**
* Constructor.
*
* @param name Name of the test.
*/
public VersionTransformerTest( String name )
{
super( name );
}
public void testNoVersions()
throws Exception
{
VersionTransformer vt = new VersionTransformer( "1.2", "TEST_1_2" );
vt.setProject( new File( System.getProperty( "basedir" ), "/src/test-data/test-pom-no-versions.xml" ) );
assertTrue( "check transform required", vt.transformRequired() );
vt.transformNodes();
vt.write();
List nodes = vt.getDocument().selectNodes( "/project" );
assertEquals( 1, nodes.size() );
Node project = ( Node ) nodes.get( 0 );
assertEquals( "Check currentVersion is 1.2", "1.2", project.selectSingleNode( "currentVersion" ).getText() );
List versionNodes = project.selectNodes( "versions/version" );
assertEquals( "Check # versions is 1", 1, versionNodes.size() );
Node version = ( Node ) versionNodes.get( 0 );
assertEquals( "Check version id is 1.2", "1.2", version.selectSingleNode( "id" ).getText() );
assertEquals( "Check version name is 1.2", "1.2", version.selectSingleNode( "name" ).getText() );
assertEquals( "Check version tag is TEST_1_2", "TEST_1_2", version.selectSingleNode( "tag" ).getText() );
}
public void testOneVersion()
throws Exception
{
VersionTransformer vt = new VersionTransformer( "1.2", "TEST_1_2" );
vt.setProject( new File( System.getProperty( "basedir" ), "/src/test-data/test-pom-versions.xml" ) );
assertTrue( "check transform required", vt.transformRequired() );
vt.transformNodes();
vt.write();
List nodes = vt.getDocument().selectNodes( "/project" );
assertEquals( 1, nodes.size() );
Node project = ( Node ) nodes.get( 0 );
assertEquals( "Check currentVersion is 1.2", "1.2", project.selectSingleNode( "currentVersion" ).getText() );
List versionNodes = project.selectNodes( "versions/version" );
assertEquals( "Check # versions is 2", 2, versionNodes.size() );
Node version = ( Node ) versionNodes.get( 0 );
assertEquals( "Check version id is 1.1", "1.1", version.selectSingleNode( "id" ).getText() );
assertEquals( "Check version name is 1.1", "1.1", version.selectSingleNode( "name" ).getText() );
assertEquals( "Check version tag is TEST_1_1", "TEST_1_1", version.selectSingleNode( "tag" ).getText() );
version = ( Node ) versionNodes.get( 1 );
assertEquals( "Check version id is 1.2", "1.2", version.selectSingleNode( "id" ).getText() );
assertEquals( "Check version name is 1.2", "1.2", version.selectSingleNode( "name" ).getText() );
assertEquals( "Check version tag is TEST_1_2", "TEST_1_2", version.selectSingleNode( "tag" ).getText() );
}
public void testMultipleVersions()
throws Exception
{
VersionTransformer vt = new VersionTransformer( "1.2", "TEST_1_2" );
vt.setProject( new File( System.getProperty( "basedir" ), "/src/test-data/test-pom-versions-multiple.xml" ) );
assertTrue( "check transform required", vt.transformRequired() );
vt.transformNodes();
vt.write();
List nodes = vt.getDocument().selectNodes( "/project" );
assertEquals( 1, nodes.size() );
Node project = ( Node ) nodes.get( 0 );
assertEquals( "Check currentVersion is 1.2", "1.2", project.selectSingleNode( "currentVersion" ).getText() );
List versionNodes = project.selectNodes( "versions/version" );
assertEquals( "Check # versions is 3", 3, versionNodes.size() );
Node version = ( Node ) versionNodes.get( 0 );
assertEquals( "Check version id is 1.0", "1.0", version.selectSingleNode( "id" ).getText() );
assertEquals( "Check version name is 1.0", "1.0", version.selectSingleNode( "name" ).getText() );
assertEquals( "Check version tag is TEST_1_0", "TEST_1_0", version.selectSingleNode( "tag" ).getText() );
version = ( Node ) versionNodes.get( 1 );
assertEquals( "Check version id is 1.1", "1.1", version.selectSingleNode( "id" ).getText() );
assertEquals( "Check version name is 1.1", "1.1", version.selectSingleNode( "name" ).getText() );
assertEquals( "Check version tag is TEST_1_1", "TEST_1_1", version.selectSingleNode( "tag" ).getText() );
version = ( Node ) versionNodes.get( 2 );
assertEquals( "Check version id is 1.2", "1.2", version.selectSingleNode( "id" ).getText() );
assertEquals( "Check version name is 1.2", "1.2", version.selectSingleNode( "name" ).getText() );
assertEquals( "Check version tag is TEST_1_2", "TEST_1_2", version.selectSingleNode( "tag" ).getText() );
}
public void testMultipleVersionsWrongOrder()
throws Exception
{
VersionTransformer vt = new VersionTransformer( "1.2", "TEST_1_2" );
vt.setProject( new File( System.getProperty( "basedir" ), "/src/test-data/test-pom-versions-wrong-order.xml" ) );
assertTrue( "check transform required", vt.transformRequired() );
vt.transformNodes();
vt.write();
List nodes = vt.getDocument().selectNodes( "/project" );
assertEquals( 1, nodes.size() );
Node project = ( Node ) nodes.get( 0 );
assertEquals( "Check currentVersion is 1.2", "1.2", project.selectSingleNode( "currentVersion" ).getText() );
List versionNodes = project.selectNodes( "versions/version" );
assertEquals( "Check # versions is 3", 3, versionNodes.size() );
Node version = ( Node ) versionNodes.get( 0 );
assertEquals( "Check version id is 1.1", "1.1", version.selectSingleNode( "id" ).getText() );
assertEquals( "Check version name is 1.1", "1.1", version.selectSingleNode( "name" ).getText() );
assertEquals( "Check version tag is TEST_1_1", "TEST_1_1", version.selectSingleNode( "tag" ).getText() );
version = ( Node ) versionNodes.get( 1 );
assertEquals( "Check version id is 1.0", "1.0", version.selectSingleNode( "id" ).getText() );
assertEquals( "Check version name is 1.0", "1.0", version.selectSingleNode( "name" ).getText() );
assertEquals( "Check version tag is TEST_1_0", "TEST_1_0", version.selectSingleNode( "tag" ).getText() );
version = ( Node ) versionNodes.get( 2 );
assertEquals( "Check version id is 1.2", "1.2", version.selectSingleNode( "id" ).getText() );
assertEquals( "Check version name is 1.2", "1.2", version.selectSingleNode( "name" ).getText() );
assertEquals( "Check version tag is TEST_1_2", "TEST_1_2", version.selectSingleNode( "tag" ).getText() );
}
public void testVersionsOverwrite()
throws Exception
{
VersionTransformer vt = new VersionTransformer( "1.2", "TEST_1_2" );
vt.setProject( new File( System.getProperty( "basedir" ), "/src/test-data/test-pom-versions-overwrite.xml" ) );
assertTrue( "check transform required", vt.transformRequired() );
vt.transformNodes();
vt.write();
List nodes = vt.getDocument().selectNodes( "/project" );
assertEquals( 1, nodes.size() );
Node project = ( Node ) nodes.get( 0 );
assertEquals( "Check currentVersion is 1.2", "1.2", project.selectSingleNode( "currentVersion" ).getText() );
List versionNodes = project.selectNodes( "versions/version" );
assertEquals( "Check # versions is 2", 2, versionNodes.size() );
Node version = ( Node ) versionNodes.get( 0 );
assertEquals( "Check version id is 1.0", "1.0", version.selectSingleNode( "id" ).getText() );
assertEquals( "Check version name is 1.0", "1.0", version.selectSingleNode( "name" ).getText() );
assertEquals( "Check version tag is TEST_1_0", "TEST_1_0", version.selectSingleNode( "tag" ).getText() );
version = ( Node ) versionNodes.get( 1 );
assertEquals( "Check version id is 1.2", "1.2", version.selectSingleNode( "id" ).getText() );
assertEquals( "Check version name is 1.2", "1.2", version.selectSingleNode( "name" ).getText() );
assertEquals( "Check version tag is TEST_1_2", "TEST_1_2", version.selectSingleNode( "tag" ).getText() );
}
public void testVersionsCorrect()
throws Exception
{
VersionTransformer vt = new VersionTransformer( "1.2", "TEST_1_2" );
vt.setProject( new File( System.getProperty( "basedir" ), "/src/test-data/test-pom-versions-correct.xml" ) );
assertFalse( "check transform not required", vt.transformRequired() );
vt.transformNodes();
vt.write();
List nodes = vt.getDocument().selectNodes( "/project" );
assertEquals( 1, nodes.size() );
Node project = ( Node ) nodes.get( 0 );
assertEquals( "Check currentVersion is 1.2", "1.2", project.selectSingleNode( "currentVersion" ).getText() );
List versionNodes = project.selectNodes( "versions/version" );
assertEquals( "Check # versions is 2", 2, versionNodes.size() );
Node version = ( Node ) versionNodes.get( 0 );
assertEquals( "Check version id is 1.0", "1.0", version.selectSingleNode( "id" ).getText() );
assertEquals( "Check version name is 1.0", "1.0", version.selectSingleNode( "name" ).getText() );
assertEquals( "Check version tag is TEST_1_0", "TEST_1_0", version.selectSingleNode( "tag" ).getText() );
version = ( Node ) versionNodes.get( 1 );
assertEquals( "Check version id is 1.2", "1.2", version.selectSingleNode( "id" ).getText() );
assertEquals( "Check version name is 1.2", "1.2", version.selectSingleNode( "name" ).getText() );
assertEquals( "Check version tag is TEST_1_2", "TEST_1_2", version.selectSingleNode( "tag" ).getText() );
}
public void testVersionsTagMatchOnly()
throws Exception
{
VersionTransformer vt = new VersionTransformer( "1.2", "TEST_1_2" );
vt.setProject( new File( System.getProperty( "basedir" ), "/src/test-data/test-pom-versions-tag-match-only.xml" ) );
assertTrue( "check transform required", vt.transformRequired() );
vt.transformNodes();
vt.write();
List nodes = vt.getDocument().selectNodes( "/project" );
assertEquals( 1, nodes.size() );
Node project = ( Node ) nodes.get( 0 );
assertEquals( "Check currentVersion is 1.2", "1.2", project.selectSingleNode( "currentVersion" ).getText() );
List versionNodes = project.selectNodes( "versions/version" );
assertEquals( "Check # versions is 1", 1, versionNodes.size() );
Node version = ( Node ) versionNodes.get( 0 );
assertEquals( "Check version id is 1.2", "1.2", version.selectSingleNode( "id" ).getText() );
assertEquals( "Check version name is 1.2", "1.2", version.selectSingleNode( "name" ).getText() );
assertEquals( "Check version tag is TEST_1_2", "TEST_1_2", version.selectSingleNode( "tag" ).getText() );
}
}

View File

@ -6,6 +6,12 @@
<author email="dion@apache.org">dIon Gillard</author>
</properties>
<body>
<release version="1.3-SNAPSHOT" date="in CVS">
<action dev="bporter" type="add">
Add POM transformer that updates currentVersion and the &lt;versions/&gt; element with a specified
version and tag.
</action>
</release>
<release version="1.2" date="2003-09-30">
<action dev="jvanzyl" type="fix">
Applied patch for <a href="http://jira.codehaus.org/secure/ViewIssue.jspa?id=11157">MAVEN-542</a>.