Author: bentmann
Date: Fri May  8 17:00:45 2009
New Revision: 773047

URL: http://svn.apache.org/viewvc?rev=773047&view=rev
Log:
o Decoupled calculation of child path adjustment from filesystem which would 
make the effective model depend on the user's environment and breaks with our 
goal of reproducible builds

Modified:
    
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/ProcessorContext.java
    
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java
    
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/InheritanceAssembler.java
    
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java

Modified: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/ProcessorContext.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/ProcessorContext.java?rev=773047&r1=773046&r2=773047&view=diff
==============================================================================
--- 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/ProcessorContext.java
 (original)
+++ 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/ProcessorContext.java
 Fri May  8 17:00:45 2009
@@ -242,7 +242,7 @@
         Model previousModel = null;
         for ( Model currentModel : models )
         {
-            inheritanceAssembler.assembleModelInheritance( currentModel, 
previousModel, "" );
+            inheritanceAssembler.assembleModelInheritance( currentModel, 
previousModel );
             previousModel = currentModel;
         }
         if ( true )

Modified: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java?rev=773047&r1=773046&r2=773047&view=diff
==============================================================================
--- 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java
 (original)
+++ 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java
 Fri May  8 17:00:45 2009
@@ -38,11 +38,62 @@
 
     private MavenModelMerger merger = new MavenModelMerger();
 
-    public void assembleModelInheritance( Model child, Model parent, String 
childPathAdjustment )
+    public void assembleModelInheritance( Model child, Model parent )
     {
         Map<Object, Object> hints = new HashMap<Object, Object>();
-        hints.put( MavenModelMerger.CHILD_PATH_ADJUSTMENT, childPathAdjustment 
);
+        hints.put( MavenModelMerger.CHILD_PATH_ADJUSTMENT, 
getChildPathAdjustment( child, parent ) );
         merger.merge( child, parent, false, hints );
     }
 
+    /**
+     * Calculates the relative path from the base directory of the parent to 
the parent directory of the base directory
+     * of the child. The general idea is to adjust inherited URLs to match the 
project layout (in SCM). This calculation
+     * is only a heuristic based on our conventions. In detail, the algo 
relies on the following assumptions. The parent
+     * uses aggregation and refers to the child via the modules section. The 
module path to the child is considered to
+     * point at the POM rather than its base directory if the path ends with 
".xml" (ignoring case). The name of the
+     * child's base directory matches the artifact id of the child. Note that 
for the sake of independence from the user
+     * environment, the filesystem is intentionally not used for the 
calculation.
+     * 
+     * @param child The child model, must not be <code>null</code>.
+     * @param parent The parent model, may be <code>null</code>.
+     * @return The path adjustment, can be empty but never <code>null</code>.
+     */
+    private String getChildPathAdjustment( Model child, Model parent )
+    {
+        String adjustment = "";
+
+        if ( parent != null )
+        {
+            String childArtifactId = child.getArtifactId();
+
+            for ( String module : parent.getModules() )
+            {
+                module = module.replace( '\\', '/' );
+
+                if ( module.regionMatches( true, module.length() - 4, ".xml", 
0, 4 ) )
+                {
+                    module = module.substring( 0, module.lastIndexOf( '/' ) + 
1 );
+                }
+
+                String moduleName = module;
+                if ( moduleName.endsWith( "/" ) )
+                {
+                    moduleName = moduleName.substring( 0, moduleName.length() 
- 1 );
+                }
+
+                int lastSlash = moduleName.lastIndexOf( '/' );
+
+                moduleName = moduleName.substring( lastSlash + 1 );
+
+                if ( moduleName.equals( childArtifactId ) && lastSlash >= 0 )
+                {
+                    adjustment = module.substring( 0, lastSlash );
+                    break;
+                }
+            }
+        }
+
+        return adjustment;
+    }
+
 }

Modified: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/InheritanceAssembler.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/InheritanceAssembler.java?rev=773047&r1=773046&r2=773047&view=diff
==============================================================================
--- 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/InheritanceAssembler.java
 (original)
+++ 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/InheritanceAssembler.java
 Fri May  8 17:00:45 2009
@@ -35,9 +35,7 @@
      * @param child The child model into which to merge the values inherited 
from the parent, must not be
      *            <code>null</code>.
      * @param parent The (read-only) parent model from which to inherit the 
values, may be <code>null</code>.
-     * @param childPathAdjustment The relative path adjustment required to 
navigate from the parent's base directory to
-     *            the parent directory of the child's base directory, must not 
be <code>null</code>.
      */
-    void assembleModelInheritance( Model child, Model parent, String 
childPathAdjustment );
+    void assembleModelInheritance( Model child, Model parent );
 
 }

Modified: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java?rev=773047&r1=773046&r2=773047&view=diff
==============================================================================
--- 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java
 (original)
+++ 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java
 Fri May  8 17:00:45 2009
@@ -568,7 +568,7 @@
     {
         String uncleanPath = parentPath;
 
-        if ( pathAdjustment != null )
+        if ( pathAdjustment != null && pathAdjustment.length() > 0 )
         {
             uncleanPath += "/" + pathAdjustment;
         }


Reply via email to