o Adding functionality to see the before and after transformation so
the user can make an educated decision. git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@112885 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
1 parent
56e1e52bf0
commit
9506694e04
6 files changed
+219
-43
No files matched your search
@@ -59,6 +59,14 @@
|
||||
|
||||
<!-- Display transformation info. Needs to be consumable by a GUI. -->
|
||||
|
||||
<echo>
|
||||
${transformation.beforeTransformation}
|
||||
<echo>
|
||||
|
||||
<echo>
|
||||
${transformation.afterTransformation}
|
||||
<echo>
|
||||
|
||||
<i:ask
|
||||
question="Do you want to update this dependency?"
|
||||
answer="answer"
|
||||
|
||||
@@ -73,14 +73,19 @@ 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.
|
||||
* This is the base class for any tool that attempts to transform fields
|
||||
* in the POM. Currently we are using the XML form of the POM and using Jaxen
|
||||
* but eventually we will be able to perform the same transformations on
|
||||
* POM beans. Jaxen needs to be modified and some serious cleanup needs to
|
||||
* go on in Maven internally, but this will serve as a start. An attempt is
|
||||
* made to make this tool GUI friendly.
|
||||
*
|
||||
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
|
||||
*
|
||||
* @version $Id: AbstractPomTransformer.java,v 1.3 2003/02/11 00:56:36 jvanzyl Exp $
|
||||
*/
|
||||
public abstract class AbstractPomTransformer
|
||||
implements PomTransformer
|
||||
{
|
||||
/** POM document */
|
||||
private File project;
|
||||
@@ -94,8 +99,11 @@ public abstract class AbstractPomTransformer
|
||||
/** Properties used in transformNode */
|
||||
private Properties properties;
|
||||
|
||||
/** Nodes selected for transformation using xpath. */
|
||||
private List selectedNodes;
|
||||
|
||||
private List transformations;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Accessors
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -210,6 +218,38 @@ public abstract class AbstractPomTransformer
|
||||
return getSelectedNodes().size();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List getTransformations()
|
||||
{
|
||||
if ( transformations == null )
|
||||
{
|
||||
createTransformations();
|
||||
}
|
||||
|
||||
return transformations;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void createTransformations()
|
||||
{
|
||||
for ( Iterator i = getSelectedNodes().iterator(); i.hasNext(); )
|
||||
{
|
||||
Object o = i.next();
|
||||
|
||||
if ( o instanceof Node )
|
||||
{
|
||||
Transformation transformation = new Transformation( this );
|
||||
transformation.setNode( (Node) o );
|
||||
transformations.add( transformation );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
@@ -218,7 +258,24 @@ public abstract class AbstractPomTransformer
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String createXPathExpression();
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -228,24 +285,6 @@ public abstract class AbstractPomTransformer
|
||||
public abstract void transformNode( Node node )
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void transformNodes()
|
||||
throws Exception
|
||||
{
|
||||
for ( Iterator i = getSelectedNodes().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.
|
||||
@@ -262,7 +301,7 @@ public abstract class AbstractPomTransformer
|
||||
// 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() );
|
||||
XPath xpath = new Dom4jXPath( selectNodesXPathExpression() );
|
||||
setSelectedNodes( xpath.selectNodes( getDocument() ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.apache.maven.release;
|
||||
|
||||
import org.dom4j.Node;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
|
||||
*
|
||||
* @version $Id: PomTransformer.java,v 1.1 2003/02/11 00:56:36 jvanzyl Exp $
|
||||
*/
|
||||
public interface PomTransformer
|
||||
{
|
||||
public void transformNode( Node node )
|
||||
throws Exception;
|
||||
|
||||
public Node getTransformedNode( Node node )
|
||||
throws Exception;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ import java.io.File;
|
||||
*
|
||||
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
|
||||
*
|
||||
* @version $Id: SnapshotResolver.java,v 1.4 2003/02/10 16:43:41 jvanzyl Exp $
|
||||
* @version $Id: SnapshotResolver.java,v 1.5 2003/02/11 00:56:36 jvanzyl Exp $
|
||||
*/
|
||||
public class SnapshotResolver
|
||||
extends AbstractPomTransformer
|
||||
@@ -77,14 +77,21 @@ public class SnapshotResolver
|
||||
// Accessors
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public String createXPathExpression()
|
||||
public String selectNodesXPathExpression()
|
||||
{
|
||||
return "/project/dependencies/dependency[version='SNAPSHOT']";
|
||||
}
|
||||
|
||||
public void transformNode( Node node )
|
||||
public String selectNodeXPath()
|
||||
{
|
||||
return "version";
|
||||
}
|
||||
|
||||
public String getNodeContent( Node node )
|
||||
throws Exception
|
||||
{
|
||||
String timestampVersion = null;
|
||||
|
||||
Node idNode = node.selectSingleNode( "id" );
|
||||
|
||||
String groupId;
|
||||
@@ -132,9 +139,30 @@ public class SnapshotResolver
|
||||
|
||||
if ( snapshotVersionFile.exists() )
|
||||
{
|
||||
String timestampVersion = FileUtils.fileRead( snapshotVersionFile.getPath() );
|
||||
Node versionNode = node.selectSingleNode( "version" );
|
||||
versionNode.setText( timestampVersion );
|
||||
timestampVersion = FileUtils.fileRead( snapshotVersionFile.getPath() );
|
||||
}
|
||||
else
|
||||
{
|
||||
timestampVersion = "???";
|
||||
}
|
||||
|
||||
return timestampVersion;
|
||||
}
|
||||
|
||||
public void transformNode( Node node )
|
||||
throws Exception
|
||||
{
|
||||
Node version = node.selectSingleNode( selectNodeXPath() );
|
||||
version.setText( getNodeContent( node ) );
|
||||
}
|
||||
|
||||
public Node getTransformedNode( Node node )
|
||||
throws Exception
|
||||
{
|
||||
Node version = node.selectSingleNode( selectNodeXPath() );
|
||||
Node transformedNode = (Node) version.clone();
|
||||
transformedNode.setText( getNodeContent( node ) );
|
||||
|
||||
return transformedNode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
|
||||
*
|
||||
* @version $Id: Transformation.java,v 1.1 2003/02/11 00:56:36 jvanzyl Exp $
|
||||
*/
|
||||
package org.apache.maven.release;
|
||||
|
||||
import org.dom4j.Node;
|
||||
|
||||
public class Transformation
|
||||
{
|
||||
/** Pom Transformer associated with this transformation. */
|
||||
private PomTransformer pomTransformer;
|
||||
|
||||
/** Node to transform. */
|
||||
private Node node;
|
||||
|
||||
public Transformation( PomTransformer pomTransformer )
|
||||
{
|
||||
this.pomTransformer = pomTransformer;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Accessors
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Node getNode()
|
||||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param node
|
||||
*/
|
||||
public void setNode( Node node )
|
||||
{
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void transform()
|
||||
throws Exception
|
||||
{
|
||||
pomTransformer.transformNode( node );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public String getBeforeTransformation()
|
||||
throws Exception
|
||||
{
|
||||
return getNode().asXML();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public String getAfterTransformation()
|
||||
throws Exception
|
||||
{
|
||||
return pomTransformer.getTransformedNode( getNode() ).asXML();
|
||||
}
|
||||
}
|
||||
@@ -56,15 +56,7 @@ package org.apache.maven.release;
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
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
|
||||
@@ -81,16 +73,28 @@ public class DummySnapshotResolver
|
||||
// Accessors
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public String createXPathExpression()
|
||||
public String selectNodesXPathExpression()
|
||||
{
|
||||
return "/project/dependencies/dependency[version='SNAPSHOT']";
|
||||
}
|
||||
|
||||
public String selectNodeXPath()
|
||||
{
|
||||
return "version";
|
||||
}
|
||||
|
||||
public String getNodeContent( Node node )
|
||||
throws Exception
|
||||
{
|
||||
return "NON-SNAPSHOT";
|
||||
}
|
||||
|
||||
public void transformNode( Node node )
|
||||
throws Exception
|
||||
{
|
||||
// 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" );
|
||||
Node version = node.selectSingleNode( selectNodeXPath() );
|
||||
version.setText( getNodeContent( node ) );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user