maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r379331 - in /maven/components/branches/maven-2.0.x/maven-project/src: main/java/org/apache/maven/project/inheritance/ test/java/org/apache/maven/project/inheritance/
Date Tue, 21 Feb 2006 04:27:26 GMT
Author: brett
Date: Mon Feb 20 20:27:26 2006
New Revision: 379331

URL: http://svn.apache.org/viewcvs?rev=379331&view=rev
Log:
[MNG-1856] fix inheritance of the distribution management section and add tests (merged from
trunk r379324)

Modified:
    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/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/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=379331&r1=379330&r2=379331&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 20:27:26 2006
@@ -107,10 +107,6 @@
             }
         }
 
-        // ----------------------------------------------------------------------
-        // Distribution
-        // ----------------------------------------------------------------------
-
         assembleDistributionInheritence( child, parent, childPathAdjustment, appendPaths
);
 
         // issueManagement
@@ -177,8 +173,6 @@
 
         assembleDependencyManagementInheritance( child, parent );
 
-        assembleDistributionManagementInheritance( child, parent );
-
         Properties props = new Properties();
         props.putAll( parent.getProperties() );
         props.putAll( child.getProperties() );
@@ -186,46 +180,6 @@
         child.setProperties( props );
     }
 
-    private void assembleDistributionManagementInheritance( Model child, Model parent )
-    {
-        DistributionManagement cDistMgmt = child.getDistributionManagement();
-        DistributionManagement pDistMgmt = parent.getDistributionManagement();
-
-        if ( cDistMgmt == null )
-        {
-            child.setDistributionManagement( pDistMgmt );
-        }
-        else if ( pDistMgmt != null )
-        {
-            if ( cDistMgmt.getRepository() == null )
-            {
-                cDistMgmt.setRepository( pDistMgmt.getRepository() );
-            }
-
-            if ( cDistMgmt.getSnapshotRepository() == null )
-            {
-                cDistMgmt.setSnapshotRepository( pDistMgmt.getSnapshotRepository() );
-            }
-
-            if ( StringUtils.isEmpty( cDistMgmt.getDownloadUrl() ) )
-            {
-                cDistMgmt.setDownloadUrl( pDistMgmt.getDownloadUrl() );
-            }
-
-            if ( cDistMgmt.getRelocation() == null )
-            {
-                cDistMgmt.setRelocation( pDistMgmt.getRelocation() );
-            }
-
-            if ( cDistMgmt.getSite() == null )
-            {
-                cDistMgmt.setSite( pDistMgmt.getSite() );
-            }
-
-            // NOTE: We SHOULD NOT be inheriting status, since this is an assessment of the
POM quality.
-        }
-    }
-
     private void assembleDependencyManagementInheritance( Model child, Model parent )
     {
         DependencyManagement parentDepMgmt = parent.getDependencyManagement();
@@ -486,17 +440,8 @@
             {
                 if ( parentDistMgmt.getRepository() != null )
                 {
-                    DeploymentRepository repository = new DeploymentRepository();
-
+                    DeploymentRepository repository = copyDistributionRepository( parentDistMgmt.getRepository()
);
                     childDistMgmt.setRepository( repository );
-
-                    repository.setId( parentDistMgmt.getRepository().getId() );
-
-                    repository.setName( parentDistMgmt.getRepository().getName() );
-
-                    repository.setUrl( parentDistMgmt.getRepository().getUrl() );
-
-                    repository.setUniqueVersion( parentDistMgmt.getRepository().isUniqueVersion()
);
                 }
             }
 
@@ -504,20 +449,37 @@
             {
                 if ( parentDistMgmt.getSnapshotRepository() != null )
                 {
-                    DeploymentRepository repository = new DeploymentRepository();
-
+                    DeploymentRepository repository =
+                        copyDistributionRepository( parentDistMgmt.getSnapshotRepository()
);
                     childDistMgmt.setSnapshotRepository( repository );
+                }
+            }
+
+            if ( StringUtils.isEmpty( childDistMgmt.getDownloadUrl() ) )
+            {
+                childDistMgmt.setDownloadUrl( parentDistMgmt.getDownloadUrl() );
+            }
 
-                    repository.setId( parentDistMgmt.getSnapshotRepository().getId() );
+            // NOTE: We SHOULD NOT be inheriting status, since this is an assessment of the
POM quality.
+            // NOTE: We SHOULD NOT be inheriting relocation, since this relates to a single
POM
+        }
+    }
 
-                    repository.setName( parentDistMgmt.getSnapshotRepository().getName()
);
+    private static DeploymentRepository copyDistributionRepository( DeploymentRepository
parentRepository )
+    {
+        DeploymentRepository repository = new DeploymentRepository();
 
-                    repository.setUrl( parentDistMgmt.getSnapshotRepository().getUrl() );
+        repository.setId( parentRepository.getId() );
 
-                    repository.setUniqueVersion( parentDistMgmt.getSnapshotRepository().isUniqueVersion()
);
-                }
-            }
-        }
+        repository.setName( parentRepository.getName() );
+
+        repository.setUrl( parentRepository.getUrl() );
+
+        repository.setLayout( parentRepository.getLayout() );
+
+        repository.setUniqueVersion( parentRepository.isUniqueVersion() );
+
+        return repository;
     }
 
     protected String appendPath( String parentPath, String childPath, String pathAdjustment,
boolean appendPaths )

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=379331&r1=379330&r2=379331&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 20:27:26 2006
@@ -18,16 +18,21 @@
 
 import junit.framework.TestCase;
 import org.apache.maven.model.Build;
+import org.apache.maven.model.DeploymentRepository;
+import org.apache.maven.model.DistributionManagement;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Parent;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.model.PluginExecution;
+import org.apache.maven.model.Relocation;
 import org.apache.maven.model.ReportPlugin;
 import org.apache.maven.model.ReportSet;
 import org.apache.maven.model.Reporting;
 import org.apache.maven.model.Repository;
+import org.apache.maven.model.RepositoryBase;
 import org.apache.maven.model.Resource;
 import org.apache.maven.model.Scm;
+import org.apache.maven.model.Site;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -57,6 +62,69 @@
         assertEquals( "Append with path adjustment failed.", "http://maven.apache.org/shared/file-management",
result );
     }
 
+    public void testDistributionManagementInheritance()
+    {
+        Model parent = makeBaseModel( "parent" );
+        Model child = makeBaseModel( "child" );
+
+        DistributionManagement distributionManagement = new DistributionManagement();
+        distributionManagement.setDownloadUrl( "downloadUrl" );
+        distributionManagement.setRelocation( new Relocation() );
+        distributionManagement.setStatus( "deployed" );
+
+        DeploymentRepository repository = new DeploymentRepository();
+        repository.setId( "apache.releases" );
+        repository.setUrl( "scp://minotaur.apache.org/www/www.apache.org/dist/java-repository"
);
+        repository.setName( "name" );
+        repository.setLayout( "legacy" );
+        distributionManagement.setRepository( repository );
+
+        DeploymentRepository snapshotRepository = new DeploymentRepository();
+        snapshotRepository.setId( "apache.snapshots" );
+        snapshotRepository.setUrl( "scp://minotaur.apache.org/www/cvs.apache.org/repository"
);
+        snapshotRepository.setName( "name" );
+        snapshotRepository.setLayout( "legacy" );
+        snapshotRepository.setUniqueVersion( false );
+        distributionManagement.setSnapshotRepository( snapshotRepository );
+
+        Site site = new Site();
+        site.setId( "apache.website" );
+        site.setUrl( "scp://minotaur.apache.org/www/maven.apache.org/" );
+        site.setName( "name3" );
+        distributionManagement.setSite( site );
+
+        parent.setDistributionManagement( distributionManagement );
+
+        assembler.assembleModelInheritance( child, parent );
+
+        DistributionManagement childDistMgmt = child.getDistributionManagement();
+        assertNotNull( "Check distMgmt inherited", childDistMgmt );
+        assertNull( "Check status NOT inherited", childDistMgmt.getStatus() );
+        assertNull( "Check relocation NOT inherited", childDistMgmt.getRelocation() );
+        assertEquals( "Check downloadUrl inherited", distributionManagement.getDownloadUrl(),
+                      childDistMgmt.getDownloadUrl() );
+
+        Site childSite = childDistMgmt.getSite();
+        assertNotNull( "Check site inherited", childSite );
+        assertEquals( "Check id matches", site.getId(), childSite.getId() );
+        assertEquals( "Check name matches", site.getName(), childSite.getName() );
+        assertEquals( "Check url matches with appended path", site.getUrl() + "child", childSite.getUrl()
);
+
+        assertRepositoryBase( childDistMgmt.getRepository(), repository );
+        assertRepositoryBase( childDistMgmt.getSnapshotRepository(), snapshotRepository );
+        assertEquals( "Check uniqueVersion is inherited", snapshotRepository.isUniqueVersion(),
+                      childDistMgmt.getSnapshotRepository().isUniqueVersion() );
+    }
+
+    private static void assertRepositoryBase( RepositoryBase childRepository, RepositoryBase
repository )
+    {
+        assertNotNull( "Check repository inherited", childRepository );
+        assertEquals( "Check id matches", repository.getId(), childRepository.getId() );
+        assertEquals( "Check name matches", repository.getName(), childRepository.getName()
);
+        assertEquals( "Check url matches", repository.getUrl(), childRepository.getUrl()
);
+        assertEquals( "Check layout matches", repository.getLayout(), childRepository.getLayout()
);
+    }
+
     public void testShouldOverrideUnitTestExcludesOnly()
     {
         Model parent = new Model();
@@ -659,13 +727,19 @@
     {
         Model model = makeBaseModel( artifactId );
 
-        Repository repository = new Repository();
-        repository.setId( id );
-        repository.setUrl( url );
+        Repository repository = makeRepository( id, url );
 
         model.setRepositories( new ArrayList( Collections.singletonList( repository ) ) );
 
         return model;
+    }
+
+    private static Repository makeRepository( String id, String url )
+    {
+        Repository repository = new Repository();
+        repository.setId( id );
+        repository.setUrl( url );
+        return repository;
     }
 
     private void assertRepositories( List expected, List actual )



Mime
View raw message