maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r379290 - in /maven/components/branches/maven-2.0.x/maven-project/src: main/java/org/apache/maven/project/ main/java/org/apache/maven/project/inheritance/ test/java/org/apache/maven/project/inheritance/
Date Mon, 20 Feb 2006 23:49:33 GMT
Author: jdcasey
Date: Mon Feb 20 15:49:31 2006
New Revision: 379290

URL: http://svn.apache.org/viewcvs?rev=379290&view=rev
Log:
[MNG-2006] Merged from trunk. This will allow rewriting of child POM URLs when parent POM
is not directly above it in the directory structure.

Modified:
    maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
    maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
    maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java
    maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java
    maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java

Modified: maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?rev=379290&r1=379289&r2=379290&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
(original)
+++ maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
Mon Feb 20 15:49:31 2006
@@ -686,6 +686,8 @@
         project.setOriginalModel( originalModel );
 
         // we don't have to force the collision exception for superModel here, it's already
been done in getSuperModel()
+        MavenProject previousProject = superProject;
+        
         Model previous = superProject.getModel();
 
         for ( Iterator i = lineage.iterator(); i.hasNext(); )
@@ -693,10 +695,22 @@
             MavenProject currentProject = (MavenProject) i.next();
 
             Model current = currentProject.getModel();
+            
+            String pathAdjustment = null;
+            
+            try
+            {
+                pathAdjustment = previousProject.getModulePathAdjustment( currentProject
);
+            }
+            catch ( IOException e )
+            {
+                getLogger().debug( "Cannot determine whether " + currentProject.getId() +
" is a module of " + previousProject.getId() + ". Reason: " + e.getMessage(), e );
+            }
 
-            modelInheritanceAssembler.assembleModelInheritance( current, previous );
+            modelInheritanceAssembler.assembleModelInheritance( current, previous, pathAdjustment
);
 
             previous = current;
+            previousProject = currentProject;
         }
 
         // only add the super repository if it wasn't overridden by a profile or project

Modified: maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/MavenProject.java?rev=379290&r1=379289&r2=379290&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
(original)
+++ maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
Mon Feb 20 15:49:31 2006
@@ -135,6 +135,8 @@
     private Build buildOverlay;
 
     private boolean executionRoot;
+    
+    private Map moduleFiles;
 
     public MavenProject( Model model )
     {
@@ -187,6 +189,44 @@
         this.executionRoot = project.executionRoot;
 
         this.artifact = ArtifactUtils.copyArtifact( project.artifact );
+    }
+    
+    public String getModulePathAdjustment( MavenProject moduleProject ) throws IOException
+    {
+        File module = moduleProject.getFile();
+        
+        if ( module == null )
+        {
+            return null;
+        }
+        
+        module = module.getCanonicalFile();
+        
+        if ( moduleFiles == null )
+        {
+            moduleFiles = new HashMap();
+            
+            List modules = getModules();
+            File myFile = getFile();
+            
+            if ( myFile != null )
+            {
+                File myDir = myFile.getCanonicalFile().getParentFile();
+                if ( modules != null )
+                {
+                    for ( Iterator it = modules.iterator(); it.hasNext(); )
+                    {
+                        String modulePath = (String) it.next();
+
+                        File moduleFile = new File( myDir, modulePath ).getCanonicalFile();
+
+                        moduleFiles.put( moduleFile, modulePath );
+                    }
+                }
+            }            
+        }
+        
+        return (String) moduleFiles.get( module );
     }
 
     // ----------------------------------------------------------------------

Modified: maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java?rev=379290&r1=379289&r2=379290&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java
(original)
+++ maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java
Mon Feb 20 15:49:31 2006
@@ -16,6 +16,15 @@
  * limitations under the License.
  */
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.TreeMap;
+
 import org.apache.maven.model.Build;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.DependencyManagement;
@@ -29,14 +38,6 @@
 import org.apache.maven.project.ModelUtils;
 import org.codehaus.plexus.util.StringUtils;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.TreeMap;
-
 /**
  * @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
  * @version $Id: DefaultModelInheritanceAssembler.java,v 1.4 2004/08/23 20:24:54
@@ -48,15 +49,20 @@
 {
     public void copyModel( Model dest, Model source )
     {
-        assembleModelInheritance( dest, source, false );
+        assembleModelInheritance( dest, source, null, false );
+    }
+
+    public void assembleModelInheritance( Model child, Model parent, String childPathAdjustment
)
+    {
+        assembleModelInheritance( child, parent, childPathAdjustment, true );
     }
 
     public void assembleModelInheritance( Model child, Model parent )
     {
-        assembleModelInheritance( child, parent, true );
+        assembleModelInheritance( child, parent, null, true );
     }
 
-    private void assembleModelInheritance( Model child, Model parent, boolean appendPaths
)
+    private void assembleModelInheritance( Model child, Model parent, String childPathAdjustment,
boolean appendPaths )
     {
         // cannot inherit from null parent.
         if ( parent == null )
@@ -93,7 +99,7 @@
         {
             if ( parent.getUrl() != null )
             {
-                child.setUrl( appendPath( parent.getUrl(), child.getArtifactId(), appendPaths
) );
+                child.setUrl( appendPath( parent.getUrl(), child.getArtifactId(), childPathAdjustment,
appendPaths ) );
             }
             else
             {
@@ -105,7 +111,7 @@
         // Distribution
         // ----------------------------------------------------------------------
 
-        assembleDistributionInheritence( child, parent, appendPaths );
+        assembleDistributionInheritence( child, parent, childPathAdjustment, appendPaths
);
 
         // issueManagement
         if ( child.getIssueManagement() == null )
@@ -126,7 +132,7 @@
         }
 
         // Scm
-        assembleScmInheritance( child, parent, appendPaths );
+        assembleScmInheritance( child, parent, childPathAdjustment, appendPaths );
 
         // ciManagement
         if ( child.getCiManagement() == null )
@@ -399,7 +405,7 @@
         }
     }
 
-    private void assembleScmInheritance( Model child, Model parent, boolean appendPaths )
+    private void assembleScmInheritance( Model child, Model parent, String childPathAdjustment,
boolean appendPaths )
     {
         if ( parent.getScm() != null )
         {
@@ -416,7 +422,7 @@
 
             if ( StringUtils.isEmpty( childScm.getConnection() ) && !StringUtils.isEmpty(
parentScm.getConnection() ) )
             {
-                childScm.setConnection( appendPath( parentScm.getConnection(), child.getArtifactId(),
appendPaths ) );
+                childScm.setConnection( appendPath( parentScm.getConnection(), child.getArtifactId(),
childPathAdjustment, appendPaths ) );
             }
 
             if ( StringUtils.isEmpty( childScm.getDeveloperConnection() ) &&
@@ -424,17 +430,17 @@
             {
                 childScm
                     .setDeveloperConnection(
-                        appendPath( parentScm.getDeveloperConnection(), child.getArtifactId(),
appendPaths ) );
+                        appendPath( parentScm.getDeveloperConnection(), child.getArtifactId(),
childPathAdjustment, appendPaths ) );
             }
 
             if ( StringUtils.isEmpty( childScm.getUrl() ) && !StringUtils.isEmpty(
parentScm.getUrl() ) )
             {
-                childScm.setUrl( appendPath( parentScm.getUrl(), child.getArtifactId(), appendPaths
) );
+                childScm.setUrl( appendPath( parentScm.getUrl(), child.getArtifactId(), childPathAdjustment,
appendPaths ) );
             }
         }
     }
 
-    private void assembleDistributionInheritence( Model child, Model parent, boolean appendPaths
)
+    private void assembleDistributionInheritence( Model child, Model parent, String childPathAdjustment,
boolean appendPaths )
     {
         if ( parent.getDistributionManagement() != null )
         {
@@ -465,7 +471,7 @@
 
                     if ( site.getUrl() != null )
                     {
-                        site.setUrl( appendPath( site.getUrl(), child.getArtifactId(), appendPaths
) );
+                        site.setUrl( appendPath( site.getUrl(), child.getArtifactId(), childPathAdjustment,
appendPaths ) );
                     }
                 }
             }
@@ -508,23 +514,78 @@
         }
     }
 
-    private String appendPath( String url, String path, boolean appendPaths )
+    protected String appendPath( String parentPath, String childPath, String pathAdjustment,
boolean appendPaths )
     {
+        List pathFragments = new ArrayList();
+        
+        String rootPath = parentPath;
+
+        String protocol = null;
+        int protocolIdx = rootPath.indexOf( "://" );
+        
+        if ( protocolIdx > -1 )
+        {
+            protocol = rootPath.substring( 0, protocolIdx + 3 );
+            rootPath = rootPath.substring( protocolIdx + 3 );
+        }
+        
+        pathFragments.add( rootPath );
+        
         if ( appendPaths )
         {
-            if ( url.endsWith( "/" ) )
+            if ( pathAdjustment != null )
             {
-                return url + path;
+                pathFragments.add( pathAdjustment );
             }
-            else
+            
+            pathFragments.add( childPath );
+        }
+        
+        StringBuffer cleanedPath = new StringBuffer();
+        
+        if ( protocol != null )
+        {
+            cleanedPath.append( protocol );
+        }
+        
+        if ( rootPath.startsWith( "/" ) )
+        {
+            cleanedPath.append( '/' );
+        }
+        
+        String lastToken = null;
+        String currentToken = null;
+        
+        for ( Iterator it = pathFragments.iterator(); it.hasNext(); )
+        {
+            String pathFragment = (String) it.next();
+            
+            StringTokenizer tokens = new StringTokenizer( pathFragment, "/" );
+            
+            while( tokens.hasMoreTokens() )
             {
-                return url + "/" + path;
+                lastToken = currentToken;
+                currentToken = tokens.nextToken();
+                
+                if ( "..".equals( currentToken ) )
+                {
+                    // trim the previous path part off...
+                    cleanedPath.setLength( cleanedPath.length() - ( lastToken.length() +
1 ) );
+                }
+                else if ( !".".equals( currentToken ) )
+                {
+                    // don't worry about /./ self-references.
+                    cleanedPath.append( currentToken ).append( '/' );
+                }
             }
         }
-        else
+        
+        if ( !childPath.endsWith( "/" ) && appendPaths )
         {
-            return url;
+            cleanedPath.setLength( cleanedPath.length() - 1 );
         }
+        
+        return cleanedPath.toString();
     }
 
 }

Modified: maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java?rev=379290&r1=379289&r2=379290&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java
(original)
+++ maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java
Mon Feb 20 15:49:31 2006
@@ -26,6 +26,8 @@
 {
     String ROLE = ModelInheritanceAssembler.class.getName();
 
+    void assembleModelInheritance( Model child, Model parent, String childPathAdjustment
);
+
     void assembleModelInheritance( Model child, Model parent );
 
     void copyModel( Model dest, Model source );

Modified: maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java?rev=379290&r1=379289&r2=379290&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java
(original)
+++ maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java
Mon Feb 20 15:49:31 2006
@@ -43,6 +43,19 @@
     extends TestCase
 {
     private ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler();
+    
+    public void testShouldAppendPathWithChildPathAdjustment()
+    {
+        String parentPath = "http://maven.apache.org/shared/maven-shared-parent";
+        String childPath = "file-management";
+        String pathAdjustment = "..";
+        
+        String result = ((DefaultModelInheritanceAssembler) assembler).appendPath( parentPath,
childPath, pathAdjustment, true );
+        
+        System.out.println( "Resulting path is: \'" + result + "\'" );
+        
+        assertEquals( "Append with path adjustment failed.", "http://maven.apache.org/shared/file-management",
result );
+    }
 
     public void testShouldOverrideUnitTestExcludesOnly()
     {



Mime
View raw message