You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ev...@apache.org on 2007/05/18 17:22:15 UTC

svn commit: r539498 - in /maven/release/trunk/maven-release-manager/src: main/java/org/apache/maven/shared/release/phase/ test/java/org/apache/maven/shared/release/phase/ test/resources/projects/rewrite-for-development/basic-pom-ejb-client-dep/

Author: evenisse
Date: Fri May 18 08:22:14 2007
New Revision: 539498

URL: http://svn.apache.org/viewvc?view=rev&rev=539498
Log:
[MRELEASE-178] Set correctly the version of dependent dependencies like ejb-client

Added:
    maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-development/basic-pom-ejb-client-dep/
    maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-development/basic-pom-ejb-client-dep/expected-pom.xml   (with props)
    maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-development/basic-pom-ejb-client-dep/pom.xml   (with props)
Modified:
    maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java
    maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhaseTest.java

Modified: maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java
URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java?view=diff&rev=539498&r1=539497&r2=539498
==============================================================================
--- maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java (original)
+++ maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java Fri May 18 08:22:14 2007
@@ -63,6 +63,7 @@
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.Writer;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -334,13 +335,22 @@
     {
         if ( dependencies != null )
         {
+            List dependenciesAlreadyChanged = new ArrayList();
             for ( Iterator i = dependencies.iterator(); i.hasNext(); )
             {
                 Dependency dep = (Dependency) i.next();
+                String depId = ArtifactUtils.versionlessKey( dep.getGroupId(), dep.getArtifactId() );
+                if ( !dependenciesAlreadyChanged.contains( depId ) )
+                {
+                    //This check is required because updateDomVersion update all dependencies with the current groupId/artifactId
+                    //(standard dependencies and sub-dependencies like ejb-client) so we don't need to re-update them
+
+                    dependenciesAlreadyChanged.add( depId );
 
-                updateDomVersion( dep.getGroupId(), dep.getArtifactId(), mappedVersions, resolvedSnapshotDependencies,
-                                  dep.getVersion(), originalVersions, "dependencies", "dependency", dependencyRoot,
-                                  projectId, properties, result, releaseDescriptor );
+                    updateDomVersion( dep.getGroupId(), dep.getArtifactId(), mappedVersions,
+                                      resolvedSnapshotDependencies, dep.getVersion(), originalVersions, "dependencies",
+                                      "dependency", dependencyRoot, projectId, properties, result, releaseDescriptor );
+                }
             }
         }
     }
@@ -411,8 +421,8 @@
         }
     }
 
-    private Element getDependency( String groupId, String artifactId, String groupTagName, String tagName,
-                                   Element dependencyRoot )
+    private List getDependencies( String groupId, String artifactId, String groupTagName, String tagName,
+                                  Element dependencyRoot )
         throws JDOMException
     {
         XPath xpath;
@@ -428,20 +438,20 @@
                 "' and artifactId='" + artifactId + "']" );
         }
 
-        Element elem = (Element) xpath.selectSingleNode( dependencyRoot );
+        List dependencies = xpath.selectNodes( dependencyRoot );
 
         //MRELEASE-147
-        if ( elem == null && groupId.indexOf( "${" ) == -1 )
+        if ( ( dependencies == null || dependencies.isEmpty() ) && groupId.indexOf( "${" ) == -1 )
         {
-            elem = getDependency( "${project.groupId}", artifactId, groupTagName, tagName, dependencyRoot );
+            dependencies = getDependencies( "${project.groupId}", artifactId, groupTagName, tagName, dependencyRoot );
 
-            if ( elem == null )
+            if ( dependencies == null || dependencies.isEmpty() )
             {
-                elem = getDependency( "${pom.groupId}", artifactId, groupTagName, tagName, dependencyRoot );
+                dependencies = getDependencies( "${pom.groupId}", artifactId, groupTagName, tagName, dependencyRoot );
             }
         }
 
-        return elem;
+        return dependencies;
     }
 
     private void updateDomVersion( String groupId, String artifactId, Map mappedVersions,
@@ -461,121 +471,128 @@
             originalVersion = getOriginalResolvedSnapshotVersion( key, resolvedSnapshotDepedencies );
         }
 
-        Element dependency;
         try
         {
-            dependency = getDependency( groupId, artifactId, groupTagName, tagName, dependencyRoot );
-        }
-        catch ( JDOMException e )
-        {
-            throw new ReleaseExecutionException( "Unable to locate " + tagName + " to process in document", e );
-        }
-
-        String dependencyVersion = "";
-        Element versionElement = null;
-
-        if ( dependency != null )
-        {
-            versionElement = dependency.getChild( "version", dependencyRoot.getNamespace() );
-            if ( versionElement != null )
-            {
-                dependencyVersion = versionElement.getTextTrim();
-            }
-        }
+            List dependencies = getDependencies( groupId, artifactId, groupTagName, tagName, dependencyRoot );
 
-        //MRELEASE-220
-        if ( mappedVersion != null && mappedVersion.endsWith( "SNAPSHOT" ) &&
-            !dependencyVersion.endsWith( "SNAPSHOT" ) && !releaseDescriptor.isUpdateDependencies() )
-        {
-            return;
-        }
-
-        if ( version.equals( originalVersion ) || dependencyVersion.equals( originalVersion ) )
-        {
-            if ( ( mappedVersion != null ) || ( resolvedSnapshotVersion != null ) )
+            for ( Iterator i = dependencies.iterator(); i.hasNext(); )
             {
-                logInfo( result, "Updating " + artifactId + " to " +
-                    ( ( mappedVersion != null ) ? mappedVersion : resolvedSnapshotVersion ) );
+                Element dependency = (Element) i.next();
+                String dependencyVersion = "";
+                Element versionElement = null;
 
-                // If it was inherited, nothing to do
                 if ( dependency != null )
                 {
-                    // avoid if in management
+                    versionElement = dependency.getChild( "version", dependencyRoot.getNamespace() );
                     if ( versionElement != null )
                     {
-                        if ( mappedVersion == null )
-                        {
-                            versionElement.setText( resolvedSnapshotVersion );
-                            return;
-                        }
+                        dependencyVersion = versionElement.getTextTrim();
+                    }
+                }
 
-                        String versionText = versionElement.getTextTrim();
+                //MRELEASE-220
+                if ( mappedVersion != null && mappedVersion.endsWith( "SNAPSHOT" ) &&
+                    !dependencyVersion.endsWith( "SNAPSHOT" ) && !releaseDescriptor.isUpdateDependencies() )
+                {
+                    return;
+                }
 
-                        // avoid if it was not originally set to the original value (it may be an expression), unless mapped version differs
-                        if ( originalVersion.equals( versionText ) ||
-                            !mappedVersion.equals( mappedVersions.get( projectId ) ) )
-                        {
-                            versionElement.setText( mappedVersion );
-                        }
-                        else if ( versionText.matches( "\\$\\{project.+\\}" ) ||
-                            versionText.matches( "\\$\\{pom.+\\}" ) || "${version}".equals( versionText ) )
-                        {
-                            logInfo( result, "Ignoring artifact version update for expression: " + versionText );
-                            //ignore... we cannot update this expression
-                        }
-                        else if ( versionText.matches( "\\$\\{.+\\}" ) && properties != null )
+                if ( version.equals( originalVersion ) || dependencyVersion.equals( originalVersion ) )
+                {
+                    if ( ( mappedVersion != null ) || ( resolvedSnapshotVersion != null ) )
+                    {
+                        logInfo( result, "Updating " + artifactId + " to " +
+                            ( ( mappedVersion != null ) ? mappedVersion : resolvedSnapshotVersion ) );
+
+                        // If it was inherited, nothing to do
+                        if ( dependency != null )
                         {
-                            //version is an expression, check for properties to update instead
-                            String expression = versionText.substring( 2, versionText.length() - 1 );
-                            Element property = properties.getChild( expression, properties.getNamespace() );
-                            if ( property != null )
+                            // avoid if in management
+                            if ( versionElement != null )
                             {
-                                String propertyValue = property.getTextTrim();
+                                if ( mappedVersion == null )
+                                {
+                                    versionElement.setText( resolvedSnapshotVersion );
+                                    return;
+                                }
 
-                                if ( originalVersion.equals( propertyValue ) )
+                                String versionText = versionElement.getTextTrim();
+
+                                // avoid if it was not originally set to the original value (it may be an expression), unless mapped version differs
+                                if ( originalVersion.equals( versionText ) ||
+                                    !mappedVersion.equals( mappedVersions.get( projectId ) ) )
+                                {
+                                    versionElement.setText( mappedVersion );
+                                }
+                                else if ( versionText.matches( "\\$\\{project.+\\}" ) ||
+                                    versionText.matches( "\\$\\{pom.+\\}" ) || "${version}".equals( versionText ) )
                                 {
-                                    // change the property only if the property is the same as what's in the reactor
-                                    property.setText( mappedVersion );
+                                    logInfo( result,
+                                             "Ignoring artifact version update for expression: " + versionText );
+                                    //ignore... we cannot update this expression
                                 }
-                                else if ( !mappedVersion.equals( versionText ) )
+                                else if ( versionText.matches( "\\$\\{.+\\}" ) && properties != null )
                                 {
-                                    if ( mappedVersion.matches( "\\$\\{project.+\\}" ) ||
-                                        mappedVersion.matches( "\\$\\{pom.+\\}" ) ||
-                                        "${version}".equals( mappedVersion ) )
+                                    //version is an expression, check for properties to update instead
+                                    String expression = versionText.substring( 2, versionText.length() - 1 );
+                                    Element property = properties.getChild( expression, properties.getNamespace() );
+                                    if ( property != null )
                                     {
-                                        logInfo( result,
-                                                 "Ignoring artifact version update for expression: " + mappedVersion );
-                                        //ignore... we cannot update this expression
+                                        String propertyValue = property.getTextTrim();
+
+                                        if ( originalVersion.equals( propertyValue ) )
+                                        {
+                                            // change the property only if the property is the same as what's in the reactor
+                                            property.setText( mappedVersion );
+                                        }
+                                        else if ( !mappedVersion.equals( versionText ) )
+                                        {
+                                            if ( mappedVersion.matches( "\\$\\{project.+\\}" ) ||
+                                                mappedVersion.matches( "\\$\\{pom.+\\}" ) ||
+                                                "${version}".equals( mappedVersion ) )
+                                            {
+                                                logInfo( result, "Ignoring artifact version update for expression: " +
+                                                    mappedVersion );
+                                                //ignore... we cannot update this expression
+                                            }
+                                            else
+                                            {
+                                                // the value of the expression conflicts with what the user wanted to release
+                                                throw new ReleaseFailureException( "The artifact (" + key +
+                                                    ") requires a " + "different version (" + mappedVersion +
+                                                    ") than what is found (" + propertyValue +
+                                                    ") for the expression (" + expression + ") in the " + "project (" +
+                                                    projectId + ")." );
+                                            }
+                                        }
                                     }
                                     else
                                     {
-                                        // the value of the expression conflicts with what the user wanted to release
-                                        throw new ReleaseFailureException( "The artifact (" + key + ") requires a " +
-                                            "different version (" + mappedVersion + ") than what is found (" +
-                                            propertyValue + ") for the expression (" + expression + ") in the " +
-                                            "project (" + projectId + ")." );
+                                        // the expression used to define the version of this artifact may be inherited
+                                        throw new ReleaseFailureException(
+                                            "The version could not be updated: " + versionText );
                                     }
                                 }
+                                else
+                                {
+                                    // the version for this artifact could not be updated.
+                                    throw new ReleaseFailureException(
+                                        "The version could not be updated: " + versionText );
+                                }
                             }
-                            else
-                            {
-                                // the expression used to define the version of this artifact may be inherited
-                                throw new ReleaseFailureException( "The version could not be updated: " + versionText );
-                            }
-                        }
-                        else
-                        {
-                            // the version for this artifact could not be updated.
-                            throw new ReleaseFailureException( "The version could not be updated: " + versionText );
                         }
                     }
+                    else
+                    {
+                        throw new ReleaseFailureException(
+                            "Version '" + version + "' for " + tagName + " '" + key + "' was not mapped" );
+                    }
                 }
             }
-            else
-            {
-                throw new ReleaseFailureException(
-                    "Version '" + version + "' for " + tagName + " '" + key + "' was not mapped" );
-            }
+        }
+        catch ( JDOMException e )
+        {
+            throw new ReleaseExecutionException( "Unable to locate " + tagName + " to process in document", e );
         }
     }
 

Modified: maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhaseTest.java
URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhaseTest.java?view=diff&rev=539498&r1=539497&r2=539498
==============================================================================
--- maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhaseTest.java (original)
+++ maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhaseTest.java Fri May 18 08:22:14 2007
@@ -22,6 +22,7 @@
 import org.apache.maven.model.Scm;
 import org.apache.maven.shared.release.ReleaseExecutionException;
 import org.apache.maven.shared.release.config.ReleaseDescriptor;
+import org.apache.maven.artifact.ArtifactUtils;
 import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
@@ -69,6 +70,28 @@
 
         expected = readTestProjectFile( "basic-pom/expected-pom.xml" );
         actual = readTestProjectFile( "basic-pom/pom.xml.next" );
+        assertEquals( "Check the transformed POM", expected, actual );
+    }
+
+    public void testSimulateRewriteEjbClientDeps()
+        throws Exception
+    {
+        List reactorProjects = createReactorProjects( "basic-pom-ejb-client-dep" );
+        ReleaseDescriptor config = createDescriptorFromBasicPom( reactorProjects );
+        config.mapReleaseVersion( "groupId:artifactId", RELEASE_VERSION );
+        config.mapDevelopmentVersion( "groupId:artifactId", NEXT_VERSION );
+        config.addDevelopmentVersion( ArtifactUtils.versionlessKey( "groupId", "artifactId1" ), NEXT_VERSION );
+        config.addReleaseVersion( ArtifactUtils.versionlessKey( "groupId", "artifactId1" ), RELEASE_VERSION );
+
+        String expected = readTestProjectFile( "basic-pom-ejb-client-dep/pom.xml" );
+
+        phase.simulate( config, null, reactorProjects );
+
+        String actual = readTestProjectFile( "basic-pom-ejb-client-dep/pom.xml" );
+        assertEquals( "Check the original POM untouched", expected, actual );
+
+        expected = readTestProjectFile( "basic-pom-ejb-client-dep/expected-pom.xml" );
+        actual = readTestProjectFile( "basic-pom-ejb-client-dep/pom.xml.next" );
         assertEquals( "Check the transformed POM", expected, actual );
     }
 

Added: maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-development/basic-pom-ejb-client-dep/expected-pom.xml
URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-development/basic-pom-ejb-client-dep/expected-pom.xml?view=auto&rev=539498
==============================================================================
--- maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-development/basic-pom-ejb-client-dep/expected-pom.xml (added)
+++ maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-development/basic-pom-ejb-client-dep/expected-pom.xml Fri May 18 08:22:14 2007
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ Copyright 2005-2006 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.
+  -->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>groupId</groupId>
+  <artifactId>artifactId</artifactId>
+  <version>1.1-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <prerequisites>
+    <maven>2.0.4</maven>
+  </prerequisites>
+
+  <scm>
+    <connection>scm:svn:file://localhost/tmp/scm-repo/trunk</connection>
+    <developerConnection>scm:svn:file://localhost/tmp/scm-repo/trunk</developerConnection>
+    <url>file://localhost/tmp/scm-repo/trunk</url>
+  </scm>
+
+  <!--
+  a multi-line
+  comment
+  -->
+  <!--dependencyManagement-->
+    <dependencies>
+      <dependency>
+        <groupId>groupId</groupId>
+        <artifactId>artifactId1</artifactId>
+        <type>ejb</type>
+        <version>1.1-SNAPSHOT</version>      
+      </dependency>
+      <dependency>
+        <groupId>groupId</groupId>
+        <artifactId>artifactId1</artifactId>
+        <type>ejb-client</type>
+        <version>1.1-SNAPSHOT</version>
+      </dependency>    
+    </dependencies>
+  <!--/dependencyManagement-->
+</project>

Propchange: maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-development/basic-pom-ejb-client-dep/expected-pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-development/basic-pom-ejb-client-dep/expected-pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-development/basic-pom-ejb-client-dep/pom.xml
URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-development/basic-pom-ejb-client-dep/pom.xml?view=auto&rev=539498
==============================================================================
--- maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-development/basic-pom-ejb-client-dep/pom.xml (added)
+++ maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-development/basic-pom-ejb-client-dep/pom.xml Fri May 18 08:22:14 2007
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ Copyright 2005-2006 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.
+  -->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>groupId</groupId>
+  <artifactId>artifactId</artifactId>
+  <version>1.0</version>
+  <packaging>pom</packaging>
+
+  <prerequisites>
+    <maven>2.0.4</maven>
+  </prerequisites>
+
+  <scm>
+    <connection>scm:svn:file://localhost/tmp/scm-repo/trunk</connection>
+    <developerConnection>scm:svn:file://localhost/tmp/scm-repo/trunk</developerConnection>
+    <url>file://localhost/tmp/scm-repo/trunk</url>
+  </scm>
+
+  <!--
+  a multi-line
+  comment
+  -->
+  <!--dependencyManagement-->
+    <dependencies>
+      <dependency>
+        <groupId>groupId</groupId>
+        <artifactId>artifactId1</artifactId>
+        <type>ejb</type>
+        <version>1.0</version>      
+      </dependency>
+      <dependency>
+        <groupId>groupId</groupId>
+        <artifactId>artifactId1</artifactId>
+        <type>ejb-client</type>
+        <version>1.0</version>
+      </dependency>    
+    </dependencies>
+  <!--/dependencyManagement-->
+</project>

Propchange: maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-development/basic-pom-ejb-client-dep/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-development/basic-pom-ejb-client-dep/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"