From a330f613b0b75a47e868c0b171f022ca57e654fc Mon Sep 17 00:00:00 2001 From: ltheussl Date: Thu, 2 Feb 2006 00:34:18 +0000 Subject: [PATCH] PR: MPSCM-76 Make scm plugin independent of release plugin. Imported all classes and the release:transform tag (now: scm:transform). git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@374214 13f79535-47bb-0310-9956-ffa450edef68 --- scm/plugin.jelly | 28 +- scm/project.xml | 49 +++ .../scm/release/AbstractPomTransformer.java | 353 ++++++++++++++++++ .../plugins/scm/release/PomNodeSelector.java | 121 ++++++ .../plugins/scm/release/PomTransformer.java | 36 ++ .../plugins/scm/release/SnapshotResolver.java | 142 +++++++ .../release/SnapshotVersionTransformer.java | 76 ++++ .../plugins/scm/release/Transformation.java | 95 +++++ .../scm/release/VersionTransformer.java | 129 +++++++ .../release/jelly/AbstractTransformerTag.java | 53 +++ .../scm/release/jelly/ReleaseTagLibrary.java | 41 ++ .../release/jelly/ResolveSnapshotsTag.java | 44 +++ .../jelly/SnapshotVersionTransformerTag.java | 44 +++ .../release/jelly/VersionTransformerTag.java | 68 ++++ .../plugins/scm/release/jelly/package.html | 10 + .../maven/plugins/scm/release/package.html | 9 + 16 files changed, 1295 insertions(+), 3 deletions(-) create mode 100644 scm/src/main/org/apache/maven/plugins/scm/release/AbstractPomTransformer.java create mode 100644 scm/src/main/org/apache/maven/plugins/scm/release/PomNodeSelector.java create mode 100644 scm/src/main/org/apache/maven/plugins/scm/release/PomTransformer.java create mode 100644 scm/src/main/org/apache/maven/plugins/scm/release/SnapshotResolver.java create mode 100644 scm/src/main/org/apache/maven/plugins/scm/release/SnapshotVersionTransformer.java create mode 100644 scm/src/main/org/apache/maven/plugins/scm/release/Transformation.java create mode 100644 scm/src/main/org/apache/maven/plugins/scm/release/VersionTransformer.java create mode 100644 scm/src/main/org/apache/maven/plugins/scm/release/jelly/AbstractTransformerTag.java create mode 100644 scm/src/main/org/apache/maven/plugins/scm/release/jelly/ReleaseTagLibrary.java create mode 100644 scm/src/main/org/apache/maven/plugins/scm/release/jelly/ResolveSnapshotsTag.java create mode 100644 scm/src/main/org/apache/maven/plugins/scm/release/jelly/SnapshotVersionTransformerTag.java create mode 100644 scm/src/main/org/apache/maven/plugins/scm/release/jelly/VersionTransformerTag.java create mode 100644 scm/src/main/org/apache/maven/plugins/scm/release/jelly/package.html create mode 100644 scm/src/main/org/apache/maven/plugins/scm/release/package.html diff --git a/scm/plugin.jelly b/scm/plugin.jelly index 53007e02..9f26327f 100644 --- a/scm/plugin.jelly +++ b/scm/plugin.jelly @@ -21,13 +21,14 @@ + xmlns:maven="jelly:maven" + xmlns:r="jelly:org.apache.maven.plugins.scm.release.jelly.ReleaseTagLibrary"> + + + + + + Updating POM with version ${version}; tag ${tag} + + + + + ${transformer.transformNodes()} + ${transformer.write(encoding)} + + + + + @@ -298,7 +320,7 @@ - + diff --git a/scm/project.xml b/scm/project.xml index 2c75c250..3b50e353 100644 --- a/scm/project.xml +++ b/scm/project.xml @@ -99,13 +99,62 @@ Java Developer + + Lukas Theussl + ltheussl + ltheussl@apache.org + + Developer + + + + maven + maven + 1.0.2 + commons-jelly commons-jelly-tags-interaction 1.0 + + commons-io + commons-io + 1.0 + + + This library is already loaded by maven's core. Be careful to use the same version number as in the core. + + + + + commons-jelly + commons-jelly + 1.0 + + + This library is already loaded by maven's core. Be careful to use the same version number as in the core. + + + + + dom4j + dom4j + 1.4 + http://www.dom4j.org/ + + + This library is already loaded by maven's core. Be careful to use the same version number as in the core. + + + + + jaxen + jaxen + 1.0-FCS-full + plexus plexus-container-default diff --git a/scm/src/main/org/apache/maven/plugins/scm/release/AbstractPomTransformer.java b/scm/src/main/org/apache/maven/plugins/scm/release/AbstractPomTransformer.java new file mode 100644 index 00000000..16da00d5 --- /dev/null +++ b/scm/src/main/org/apache/maven/plugins/scm/release/AbstractPomTransformer.java @@ -0,0 +1,353 @@ +package org.apache.maven.plugins.scm.release; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.commons.io.FileUtils; +import org.dom4j.Document; +import org.dom4j.Namespace; +import org.dom4j.Node; +import org.dom4j.io.OutputFormat; +import org.dom4j.io.SAXReader; +import org.dom4j.io.XMLWriter; +import org.jaxen.XPath; +import org.jaxen.dom4j.Dom4jXPath; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.XMLFilterImpl; + +/** + * 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 Jason van Zyl + * + * @version $Id$ + */ +public abstract class AbstractPomTransformer + implements PomTransformer +{ + /** POM document */ + private File project; + + /** Dom4j document. */ + private Document document; + + /** Output file. */ + private File outputFile; + + /** Properties used in transformNode */ + private Map variables; + + /** Nodes selected for transformation using xpath. */ + private List selectedNodes; + + private List transformations; + + // ------------------------------------------------------------------------- + // Accessors + // ------------------------------------------------------------------------- + + /** + * + * @return + */ + public Map getVariables() + { + return variables; + } + + /** + * + * @param variables + */ + public void setVariables( Map variables ) + { + this.variables = variables; + } + + /** + * + * @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; + } + + /** + * + * @return + */ + public List getSelectedNodes() + { + if ( selectedNodes == null ) + { + try + { + selectNodes(); + } + catch ( Exception e ) + { + // do nothing. + } + } + return selectedNodes; + } + + /** + * + * @param selectedNodes + */ + public void setSelectedNodes( List selectedNodes ) + { + this.selectedNodes = selectedNodes; + } + + /** + * + * @return + */ + public int getSelectedNodeCount() + { + return getSelectedNodes().size(); + } + + /** + * + * @return + */ + public List getTransformations() + { + if ( transformations == null ) + { + createTransformations(); + } + + return transformations; + } + + /** + * + */ + public void createTransformations() + { + transformations = new ArrayList(); + + 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 ); + } + } + } + + /** + * This is the automated way of transforming the nodes if there is + * no user interaction involved. + * + * @throws Exception If an error occurs while transforming the nodes. + */ + public void transformNodes() + throws Exception + { + for ( Iterator i = getSelectedNodes().iterator(); i.hasNext(); ) + { + Object o = i.next(); + + if ( o instanceof Node ) + { + transformNode( (Node) o ); + } + } + } + + // ---------------------------------------------------------------------- + // Implementation + // ---------------------------------------------------------------------- + + /** + * + * @return + */ + public abstract String selectNodesXPathExpression(); + + /** + * + * @param node + * @throws Exception + */ + public abstract void transformNode( Node node ) + throws Exception; + + /** + * Update the snapshot version identifiers with actual timestamp versions + * and write out the POM in its updated form. + * + * @throws Exception + */ + public void selectNodes() + throws Exception + { + SAXReader reader = new SAXReader(); + + // make xpath expressions worh with poms with or without namespace + reader.setXMLFilter( new XMLFilterImpl() + { + + public void endElement( String uri, String localName, String qName ) + throws SAXException + { + super.endElement( "", localName, "" ); + } + + public void startElement( String uri, String localName, String qName, Attributes atts ) + throws SAXException + { + super.startElement( "", localName, "", atts ); + } + + } ); + 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( selectNodesXPathExpression() ); + setSelectedNodes( xpath.selectNodes( getDocument() ) ); + } + + /** + * + * @throws Exception + */ + public void write() + throws Exception + { + write( null ); + } + + /** + * + * @throws Exception + */ + public void write( String encoding ) + throws Exception + { + OutputStream os = null; + + if ( getOutputFile() != null ) + { + // Backup the original first. + FileUtils.copyFile( getOutputFile(), new File( getOutputFile() + ".backup" ) ); + + // Now hand of the os. + os = new FileOutputStream( getOutputFile() ); + } + else + { + os = new PrintStream( System.out ); + } + + OutputFormat format = new OutputFormat(); + format.setIndentSize( 2 ); + format.setNewlines( true ); + format.setTrimText( true ); + if ( encoding != null ) + { + format.setEncoding( encoding ); + } + + XMLWriter writer = new XMLWriter( format ) + { + protected boolean isNamespaceDeclaration( Namespace ns ) + { + // this will filter out empty namespaces, only the correct POM ns is allowed + return "http://maven.apache.org/POM/3.0.0".equals( ns.getURI() ); + } + }; + + writer.setOutputStream( os ); + writer.write( getDocument() ); + writer.flush(); + writer.close(); + } +} diff --git a/scm/src/main/org/apache/maven/plugins/scm/release/PomNodeSelector.java b/scm/src/main/org/apache/maven/plugins/scm/release/PomNodeSelector.java new file mode 100644 index 00000000..3d736eac --- /dev/null +++ b/scm/src/main/org/apache/maven/plugins/scm/release/PomNodeSelector.java @@ -0,0 +1,121 @@ +package org.apache.maven.plugins.scm.release; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +import org.dom4j.Document; +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 PomNodeSelector +{ + /** + * POM document + */ + private File pom; + + /** + * Xpath expression. + */ + private String xpathExpression; + + /** + * Snapshot dependencies found. + */ + private List nodes; + + /** + * Constructor. + */ + public PomNodeSelector() + { + nodes = new ArrayList(); + } + + // ------------------------------------------------------------------------- + // Accessors + // ------------------------------------------------------------------------- + + public void setXpathExpression( String xpathExpression ) + { + this.xpathExpression = xpathExpression; + } + + public String getXpathExpression() + { + return xpathExpression; + } + + /** + * Sets the nodes attribute of the PomManipulator object + */ + public void setNodes( List nodes ) + { + this.nodes = nodes; + } + + /** + * Gets the nodes attribute of the PomManipulator object + */ + public List getNodes() + { + return nodes; + } + + public void setPom( File pom ) + { + this.pom = pom; + } + + public File getPom() + { + return pom; + } + + /** + * Update the snapshot version identifiers with actual timestamp versions + * and write out the POM in its updated form. + * + * @throws Exception + */ + public void execute() + throws Exception + { + SAXReader reader = new SAXReader(); + Document doc = reader.read( getPom() ); + + // 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( getXpathExpression() ); + setNodes( xpath.selectNodes( doc ) ); + } +} diff --git a/scm/src/main/org/apache/maven/plugins/scm/release/PomTransformer.java b/scm/src/main/org/apache/maven/plugins/scm/release/PomTransformer.java new file mode 100644 index 00000000..26411526 --- /dev/null +++ b/scm/src/main/org/apache/maven/plugins/scm/release/PomTransformer.java @@ -0,0 +1,36 @@ +package org.apache.maven.plugins.scm.release; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +import org.dom4j.Node; + +/** + * + * + * @author Jason van Zyl + * + * @version $Id$ + */ +public interface PomTransformer +{ + public void transformNode( Node node ) + throws Exception; + + public Node getTransformedNode( Node node ) + throws Exception; +} diff --git a/scm/src/main/org/apache/maven/plugins/scm/release/SnapshotResolver.java b/scm/src/main/org/apache/maven/plugins/scm/release/SnapshotResolver.java new file mode 100644 index 00000000..8a46da34 --- /dev/null +++ b/scm/src/main/org/apache/maven/plugins/scm/release/SnapshotResolver.java @@ -0,0 +1,142 @@ +package org.apache.maven.plugins.scm.release; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +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.Node; + +import java.io.File; +import java.util.Iterator; + +/** + * + * + * @author Jason van Zyl + * + * @version $Id$ + */ +public class SnapshotResolver + extends AbstractPomTransformer +{ + // ------------------------------------------------------------------------- + // Accessors + // ------------------------------------------------------------------------- + + public String selectNodesXPathExpression() + { + return "/project/dependencies/dependency[version='SNAPSHOT']"; + } + + public String selectNodeXPath() + { + return "version"; + } + + public String getNodeContent( Node node ) + throws Exception + { + String timestampVersion = "SNAPSHOT"; + + Node idNode = node.selectSingleNode( "id" ); + + String groupId; + String artifactId; + String artifactType = "jar"; + + if ( idNode != null ) + { + groupId = idNode.getText(); + artifactId = groupId; + } + else + { + Node artifactIdNode = node.selectSingleNode( "artifactId" ); + Node groupIdNode = node.selectSingleNode( "groupId" ); + + groupId = groupIdNode.getText(); + artifactId = artifactIdNode.getText(); + } + + Node typeIdNode = node.selectSingleNode( "type" ); + + if ( typeIdNode != null ) + { + artifactType = typeIdNode.getText(); + } + + // Now we need to attempt to find the the actual timestamp + // version for this dependency. + + // Variables are being stored as ConstantExpressions ... + + Project project = (Project) getVariables().get( MavenConstants.MAVEN_POM ); + File snapshotVersionFile = new File( getProject().getParentFile(), artifactId + "-snapshot-version" ); + + for ( Iterator i = project.getContext().getMavenRepoRemote().iterator(); i.hasNext(); ) + { + String remoteRepo = (String) i.next(); + String url = remoteRepo + "/" + groupId + "/" + artifactType + "s/" + artifactId + "-snapshot-version"; + + try + { + HttpUtils.getFile( url, + snapshotVersionFile, + true, // ignore errors + false, // use timestamps + (String) getVariables().get( MavenConstants.PROXY_HOST ), // proxy host + (String) getVariables().get( MavenConstants.PROXY_PORT ), // proxy port + (String) getVariables().get( MavenConstants.PROXY_USERNAME ), // proxy user name + (String) getVariables().get( MavenConstants.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. + System.out.println( "Can't retrieve snapshot version file: " + e.getLocalizedMessage() ); + } + + if ( snapshotVersionFile.exists() ) + { + timestampVersion = FileUtils.readFileToString( snapshotVersionFile, null ); + } + } + + 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 transformedNode = (Node) node.clone(); + Node version = transformedNode.selectSingleNode( selectNodeXPath() ); + version.setText( getNodeContent( transformedNode ) ); + + return transformedNode; + } +} diff --git a/scm/src/main/org/apache/maven/plugins/scm/release/SnapshotVersionTransformer.java b/scm/src/main/org/apache/maven/plugins/scm/release/SnapshotVersionTransformer.java new file mode 100644 index 00000000..b624c27e --- /dev/null +++ b/scm/src/main/org/apache/maven/plugins/scm/release/SnapshotVersionTransformer.java @@ -0,0 +1,76 @@ +package org.apache.maven.plugins.scm.release; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +import org.dom4j.Node; + +/** + * + * + * @author Jason van Zyl + * + * @version $Id$ + */ +public class SnapshotVersionTransformer + extends AbstractPomTransformer +{ + // ------------------------------------------------------------------------- + // Accessors + // ------------------------------------------------------------------------- + + public String selectNodesXPathExpression() + { + return "/project"; + } + + public String selectNodeXPath() + { + return "currentVersion"; + } + + public String getNodeContent( Node node ) + throws Exception + { + String currentVersion = node.selectSingleNode( selectNodeXPath() ).getText(); + + int i = currentVersion.indexOf( "-SNAPSHOT" ); + if ( i > 0 ) + { + currentVersion = currentVersion.substring( 0, i ); + } + + return currentVersion; + } + + public void transformNode( Node node ) + throws Exception + { + Node currentVersion = node.selectSingleNode( selectNodeXPath() ); + currentVersion.setText( getNodeContent( node ) ); + } + + public Node getTransformedNode( Node node ) + throws Exception + { + Node transformedNode = (Node) node.clone(); + Node currentVersion = transformedNode.selectSingleNode( selectNodeXPath() ); + currentVersion.setText( getNodeContent( transformedNode ) ); + + return transformedNode; + } +} diff --git a/scm/src/main/org/apache/maven/plugins/scm/release/Transformation.java b/scm/src/main/org/apache/maven/plugins/scm/release/Transformation.java new file mode 100644 index 00000000..40740c88 --- /dev/null +++ b/scm/src/main/org/apache/maven/plugins/scm/release/Transformation.java @@ -0,0 +1,95 @@ +package org.apache.maven.plugins.scm.release; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +import org.dom4j.Node; + +/** + * + * + * @author Jason van Zyl + * + * @version $Id$ + */ +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(); + } +} diff --git a/scm/src/main/org/apache/maven/plugins/scm/release/VersionTransformer.java b/scm/src/main/org/apache/maven/plugins/scm/release/VersionTransformer.java new file mode 100644 index 00000000..723723df --- /dev/null +++ b/scm/src/main/org/apache/maven/plugins/scm/release/VersionTransformer.java @@ -0,0 +1,129 @@ +package org.apache.maven.plugins.scm.release; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +import org.dom4j.Element; +import org.dom4j.Node; + +/** + * + * + * @author Brett Porter + * + * @version $Id$ + */ +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 + { + Element project = ( Element ) node; + + Node currentVersion = node.selectSingleNode( "currentVersion" ); + if ( currentVersion != null ) + { + currentVersion.setText( version ); + } + else + { + project.addElement( "currentVersion" ).addText( version ); + } + + Element version = ( Element ) node.selectSingleNode( "versions/version[tag='" + tag + "']" ); + if ( version != null ) + { + // tag exists - overwrite + Node id = version.selectSingleNode( "id" ); + if ( id != null ) + { + id.setText( this.version ); + } + else + { + version.addElement( "id" ).addText( this.version ); + } + Node name = version.selectSingleNode( "name" ); + if ( name != null ) + { + name.setText( this.version ); + } + else + { + version.addElement( "name" ).addText( this.version ); + } + } + else + { + // tag doesn't exist - add + 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 ); + if ( node == null ) + { + return true; + } + + Node currentVersion = node.selectSingleNode( "currentVersion" ); + if ( currentVersion == null || !currentVersion.getText().equals( version )) + { + return true; + } + + + Node v = node.selectSingleNode( "versions/version[tag='" + tag + "' and id='" + version + "' and name='" + version + "']" ); + return ( v == null ); + } +} + diff --git a/scm/src/main/org/apache/maven/plugins/scm/release/jelly/AbstractTransformerTag.java b/scm/src/main/org/apache/maven/plugins/scm/release/jelly/AbstractTransformerTag.java new file mode 100644 index 00000000..88da2bce --- /dev/null +++ b/scm/src/main/org/apache/maven/plugins/scm/release/jelly/AbstractTransformerTag.java @@ -0,0 +1,53 @@ +package org.apache.maven.plugins.scm.release.jelly; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +import org.apache.commons.jelly.JellyTagException; +import org.apache.commons.jelly.TagSupport; +import org.apache.commons.jelly.XMLOutput; + +public abstract class AbstractTransformerTag + extends TagSupport +{ + private String transformer; + + private String transformations; + + public void setTransformations( String transformations ) + { + this.transformations = transformations; + } + + public String getTransformations() + { + return transformations; + } + + public void setTransformer( String transformer ) + { + this.transformer = transformer; + } + + public String getTransformer() + { + return transformer; + } + + public abstract void doTag( XMLOutput output ) + throws JellyTagException; +} diff --git a/scm/src/main/org/apache/maven/plugins/scm/release/jelly/ReleaseTagLibrary.java b/scm/src/main/org/apache/maven/plugins/scm/release/jelly/ReleaseTagLibrary.java new file mode 100644 index 00000000..60763492 --- /dev/null +++ b/scm/src/main/org/apache/maven/plugins/scm/release/jelly/ReleaseTagLibrary.java @@ -0,0 +1,41 @@ +package org.apache.maven.plugins.scm.release.jelly; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +import org.apache.commons.jelly.tags.core.CoreTagLibrary; + +/** + * Release tag library. + * + * @author Jason van Zyl + * @version $Id$ + */ +public class ReleaseTagLibrary + extends CoreTagLibrary +{ + /** + * Create an instance of the {@link ReleaseTagLibrary}, registering related + * tag libraries + */ + public ReleaseTagLibrary() + { + registerTag( "resolve-snapshots", ResolveSnapshotsTag.class ); + registerTag( "increment-snapshot-version", SnapshotVersionTransformerTag.class ); + registerTag( "release-version", VersionTransformerTag.class ); + } +} diff --git a/scm/src/main/org/apache/maven/plugins/scm/release/jelly/ResolveSnapshotsTag.java b/scm/src/main/org/apache/maven/plugins/scm/release/jelly/ResolveSnapshotsTag.java new file mode 100644 index 00000000..63be0b8f --- /dev/null +++ b/scm/src/main/org/apache/maven/plugins/scm/release/jelly/ResolveSnapshotsTag.java @@ -0,0 +1,44 @@ +package org.apache.maven.plugins.scm.release.jelly; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +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.plugins.scm.release.SnapshotResolver; + +public class ResolveSnapshotsTag + extends AbstractTransformerTag +{ + private SnapshotResolver snapshotResolver; + + public void doTag( XMLOutput output ) + throws JellyTagException + { + Project project = (Project) context.getVariable( MavenConstants.MAVEN_POM ); + + snapshotResolver = new SnapshotResolver(); + snapshotResolver.setProject( project.getFile() ); + snapshotResolver.setVariables( project.getContext().getVariables() ); + snapshotResolver.setOutputFile( project.getFile() ); + + context.setVariable( getTransformer(), snapshotResolver ); + context.setVariable( getTransformations(), snapshotResolver.getTransformations() ); + } +} diff --git a/scm/src/main/org/apache/maven/plugins/scm/release/jelly/SnapshotVersionTransformerTag.java b/scm/src/main/org/apache/maven/plugins/scm/release/jelly/SnapshotVersionTransformerTag.java new file mode 100644 index 00000000..97443a35 --- /dev/null +++ b/scm/src/main/org/apache/maven/plugins/scm/release/jelly/SnapshotVersionTransformerTag.java @@ -0,0 +1,44 @@ +package org.apache.maven.plugins.scm.release.jelly; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +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.plugins.scm.release.SnapshotVersionTransformer; + +public class SnapshotVersionTransformerTag + extends AbstractTransformerTag +{ + private SnapshotVersionTransformer transformer; + + public void doTag( XMLOutput output ) + throws JellyTagException + { + Project project = (Project) context.getVariable( MavenConstants.MAVEN_POM ); + + transformer = new SnapshotVersionTransformer(); + transformer.setProject( project.getFile() ); + transformer.setVariables( project.getContext().getVariables() ); + transformer.setOutputFile( project.getFile() ); + + context.setVariable( getTransformer(), transformer ); + context.setVariable( getTransformations(), transformer.getTransformations() ); + } +} diff --git a/scm/src/main/org/apache/maven/plugins/scm/release/jelly/VersionTransformerTag.java b/scm/src/main/org/apache/maven/plugins/scm/release/jelly/VersionTransformerTag.java new file mode 100644 index 00000000..99310064 --- /dev/null +++ b/scm/src/main/org/apache/maven/plugins/scm/release/jelly/VersionTransformerTag.java @@ -0,0 +1,68 @@ +package org.apache.maven.plugins.scm.release.jelly; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +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.plugins.scm.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() ); + } +} diff --git a/scm/src/main/org/apache/maven/plugins/scm/release/jelly/package.html b/scm/src/main/org/apache/maven/plugins/scm/release/jelly/package.html new file mode 100644 index 00000000..03093798 --- /dev/null +++ b/scm/src/main/org/apache/maven/plugins/scm/release/jelly/package.html @@ -0,0 +1,10 @@ + + + +

+ Jelly tags used by org.apache.maven.plugins.scm.release. + These classes have originally been imported from the deprecated + Maven Release Plugin. +

+ + \ No newline at end of file diff --git a/scm/src/main/org/apache/maven/plugins/scm/release/package.html b/scm/src/main/org/apache/maven/plugins/scm/release/package.html new file mode 100644 index 00000000..fee96ee8 --- /dev/null +++ b/scm/src/main/org/apache/maven/plugins/scm/release/package.html @@ -0,0 +1,9 @@ + + + +

+ Utility classes for preparing a release. These classes have originally + been imported from the deprecated Maven Release Plugin. +

+ + \ No newline at end of file