o Cleaning up the release plugin.

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@112879 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
jvanzyl
2003-02-10 14:06:06 +00:00
parent 4f845a3a6e
commit cf72243a66
7 changed files with 545 additions and 26 deletions

View File

@@ -3,6 +3,7 @@
<project
xmlns:j="jelly:core"
xmlns:i="jelly:interaction"
xmlns:u="jelly:util"
xmlns:r="jelly:org.apache.maven.release.jelly.ReleaseTagLibrary">
<!-- ================================================================== -->
@@ -43,19 +44,6 @@
-->
<goal name="convert-snapshots">
<r:snapshot-dependencies var="snapshots"/>
<j:if test="${size(snapshots) > 0}">
<j:forEach var="dependency" items="${snapshots}">
<get
dest="${maven.build.dir}/${dependency.artifactId}-snapshot-version"
usetimestamp="false"
ignoreerrors="true"
src="http://www.ibiblio.org/${dependency.groupId}/jars/${dependency.artifactId}-snapshot-version"
/>
</j:forEach>
</j:if>
</goal>
<!--

View File

@@ -32,6 +32,15 @@
</developers>
<dependencies>
<dependency>
<id>maven</id>
<version>1.0-beta-8</version>
<jar>maven.jar</jar>
</dependency>
<dependency>
<id>commons-io</id>
<version>SNAPSHOT</version>
</dependency>
<dependency>
<id>dom4j</id>
<version>1.4-dev-8</version>

View File

@@ -0,0 +1,256 @@
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 MavenSession" 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 MavenSession", 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.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.jaxen.XPath;
import org.jaxen.dom4j.Dom4jXPath;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.List;
import java.util.Iterator;
import java.util.Properties;
/**
* This is a simple POM manipulator that doesn't take into account any sort of
* POM inheritance. When the interpolation and inheritance is cleaned up in the
* Maven we will be able to serialize a POM directly with greater ease. But we
* may stick with this Jaxen solution anyway because it's so easy. Just turn the
* POM in memory into a Dom4j document and perform the same operation as we are
* here.
*/
public abstract class AbstractPomTransformer
{
/** POM document */
private File project;
/** Dom4j document. */
private Document document;
/** Output file. */
private File outputFile;
/** Properties used in transformNode */
private Properties properties;
// -------------------------------------------------------------------------
// Accessors
// -------------------------------------------------------------------------
/**
*
* @return
*/
public Properties getProperties()
{
return properties;
}
/**
*
* @param properties
*/
public void setProperties( Properties properties )
{
this.properties = properties;
}
/**
*
* @param project
*/
public void setProject( File project )
{
this.project = project;
}
/**
*
* @return
*/
public File getProject()
{
return project;
}
/**
*
* @return
*/
public Document getDocument()
{
return document;
}
/**
*
* @param document
*/
public void setDocument( Document document )
{
this.document = document;
}
/**
*
* @return
*/
public File getOutputFile()
{
return outputFile;
}
/**
*
* @param outputFile
*/
public void setOutputFile( File outputFile )
{
this.outputFile = outputFile;
}
// ----------------------------------------------------------------------
// Implementation
// ----------------------------------------------------------------------
/**
*
* @return
*/
public abstract String createXPathExpression();
/**
*
* @param node
* @throws Exception
*/
public abstract void transformNode( Node node )
throws Exception;
/**
*
* @throws Exception
*/
public void transformNodes()
throws Exception
{
for ( Iterator i = selectNodes().iterator(); i.hasNext(); )
{
Object o = i.next();
if ( o instanceof Node )
{
transformNode( (Node) o );
}
}
}
/**
* Update the snapshot version identifiers with actual timestamp versions
* and write out the POM in its updated form.
*
* @throws Exception
*/
public List selectNodes()
throws Exception
{
SAXReader reader = new SAXReader();
setDocument( reader.read( getProject() ) );
// The selecting nodes with the xpath expression will give us a list
// of dependencies elements where the version element is equal to 'SNAPSHOT'.
// So we can get any information we need, and alter anything we need to before writing
// the dom4j document back out.
XPath xpath = new Dom4jXPath( createXPathExpression() );
return xpath.selectNodes( getDocument() );
}
/**
*
* @throws Exception
*/
public void write()
throws Exception
{
OutputStream os = null;
if ( getOutputFile() != null )
{
os = new FileOutputStream( getOutputFile() );
}
else
{
os = new PrintStream( System.out );
}
OutputFormat format = new OutputFormat();
format.setIndentSize( 2 );
format.setNewlines( true );
format.setTrimText( true );
XMLWriter writer = new XMLWriter( format );
writer.setOutputStream( os );
writer.write( getDocument() );
}
}

View File

@@ -0,0 +1,144 @@
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 MavenSession" 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 MavenSession", 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.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.jaxen.XPath;
import org.jaxen.dom4j.Dom4jXPath;
import org.apache.maven.util.HttpUtils;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* This is a simple POM manipulator that doesn't take into account any sort of
* POM inheritance. When the interpolation and inheritance is cleaned up in the
* Maven we will be able to serialize a POM directly with greater ease. But we
* may stick with this Jaxen solution anyway because it's so easy. Just turn the
* POM in memory into a Dom4j document and perform the same operation as we are
* here.
*/
public class SnapshotResolver
extends AbstractPomTransformer
{
// ----------------------------------------------------------------------
// Constants
// ----------------------------------------------------------------------
public static final String PROXY_HOST = "";
public static final String PROXY_PORT = "";
public static final String PROXY_USER_NAME = "";
public static final String PROXY_PASSWORD = "";
public static final String REPO_REMOTE = "";
// -------------------------------------------------------------------------
// Accessors
// -------------------------------------------------------------------------
public String createXPathExpression()
{
return "/project/dependencies/dependency[version='SNAPSHOT']";
}
public void transformNode( Node node )
throws Exception
{
Node idNode = node.selectSingleNode( "id" );
Node artifactIdNode = node.selectSingleNode( "artifactId" );
Node groupIdNode = node.selectSingleNode( "groupId" );
Node versionNode = node.selectSingleNode( "version" );
String groupId = null;
String artifactId = null;
// Now we need to attempt to find the the actual timestamp
// version for this dependency.
String url = getProperties().getProperty( REPO_REMOTE ) + "/" +
groupId + "/jars/" + artifactId + "-snapshot-version";
File snapshotVersionFile = new File( artifactId + "-snapshot-version" );
try
{
HttpUtils.getFile( url,
snapshotVersionFile,
true, // ignore errors
false, // use timestamps
getProperties().getProperty( PROXY_HOST ), // proxy host
getProperties().getProperty( PROXY_PORT ), // proxy port
getProperties().getProperty( PROXY_USER_NAME ), // proxy user name
getProperties().getProperty( PROXY_PASSWORD ) // proxy password
);
}
catch ( Exception e )
{
// Either doesn't exist, or we have a network problem. In
// either event we can't update the version field.
}
if ( snapshotVersionFile.exists() )
{
String timestampVersion = FileUtils.fileRead( snapshotVersionFile.getPath() );
versionNode.setText( timestampVersion );
}
}
}

View File

@@ -0,0 +1,21 @@
package org.apache.maven.release.jelly;
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.1 2003/02/10 14:06:03 jvanzyl Exp $
*/
public class ReleaseTagLibrary
extends CoreTagLibrary
{
/**
* Create an instance of the {@link ReleaseTagLibrary}, registering related
* tag libraries
*/
public ReleaseTagLibrary()
{
}
}

View File

@@ -0,0 +1,96 @@
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 MavenSession" 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 MavenSession", 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.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.jaxen.XPath;
import org.jaxen.dom4j.Dom4jXPath;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* This is a simple POM manipulator that doesn't take into account any sort of
* POM inheritance. When the interpolation and inheritance is cleaned up in the
* Maven we will be able to serialize a POM directly with greater ease. But we
* may stick with this Jaxen solution anyway because it's so easy. Just turn the
* POM in memory into a Dom4j document and perform the same operation as we are
* here.
*/
public class DummySnapshotResolver
extends AbstractPomTransformer
{
// -------------------------------------------------------------------------
// Accessors
// -------------------------------------------------------------------------
public String createXPathExpression()
{
return "/project/dependencies/dependency[version='SNAPSHOT']";
}
public void transformNode( Node node )
{
// Now with our xpath expression we have the whole <dependency/>
// element and we want to alter the <version/> element.
Node version = node.selectSingleNode( "version" );
version.setText( "NON-SNAPSHOT" );
}
}

View File

@@ -53,6 +53,7 @@ package org.apache.maven.release;
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import junit.framework.TestCase;
import java.io.File;
@@ -63,10 +64,10 @@ import org.dom4j.Node;
/**
*/
public class PomNodeSelectorTest
extends TestCase
public class SnapshotResolverTest
extends TestCase
{
private static String TEST_CONF = System.getProperty("basedir")
private static String TEST_CONF = System.getProperty( "basedir" )
+ "/src/test-data/test-pom.xml";
/**
@@ -74,21 +75,25 @@ public class PomNodeSelectorTest
*
* @param name Name of the test.
*/
public PomNodeSelectorTest(String name)
public SnapshotResolverTest( String name )
{
super(name);
super( name );
}
public void testBasic()
throws Exception
{
PomNodeSelector pns = new PomNodeSelector();
pns.setPom( new File( TEST_CONF ) );
pns.setXpathExpression( "/project/dependencies/dependency[version='SNAPSHOT']" );
pns.execute();
List list = pns.getNodes();
// Make sure we have three nodes.
assertEquals( 3, list.size() );
DummySnapshotResolver sr = new DummySnapshotResolver();
sr.setProject( new File( TEST_CONF ) );
sr.transformNodes();
sr.write();
List nodes = sr.getDocument().selectNodes( "/project/dependencies/dependency" );
assertEquals( 3, nodes.size() );
assertEquals( "NON-SNAPSHOT", ((Node)nodes.get(0)).selectSingleNode( "version" ).getText() );
assertEquals( "NON-SNAPSHOT", ((Node)nodes.get(1)).selectSingleNode( "version" ).getText() );
assertEquals( "NON-SNAPSHOT", ((Node)nodes.get(2)).selectSingleNode( "version" ).getText() );
}
}