maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r564299 - in /maven/components/trunk/maven-project/src/main/java/org/apache/maven/project: DefaultMavenProjectBuilder.java build/model/DefaultModelLineageBuilder.java
Date Thu, 09 Aug 2007 17:45:39 GMT
Author: jdcasey
Date: Thu Aug  9 10:45:37 2007
New Revision: 564299

URL: http://svn.apache.org/viewvc?view=rev&rev=564299
Log:
Fixing a problem where parent POMs that are not found during model-lineage discovery were
not previously stubbed out, and caused the build to fail where it didn't in 2.0.7

Modified:
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?view=diff&rev=564299&r1=564298&r2=564299
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
(original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
Thu Aug  9 10:45:37 2007
@@ -156,7 +156,7 @@
     private ModelInheritanceAssembler modelInheritanceAssembler;
 
     private ModelValidator validator;
-    
+
     // TODO: make it a component
     private MavenXpp3Reader modelReader;
 
@@ -167,9 +167,9 @@
     private ModelInterpolator modelInterpolator;
 
     private ModelLineageBuilder modelLineageBuilder;
-    
+
     private ProfileAdvisor profileAdvisor;
-    
+
     private BuildContextManager buildContextManager;
 
     private MavenTools mavenTools;
@@ -178,7 +178,7 @@
     // I am making this available for use with a new method that takes a
     // a monitor wagon monitor as a parameter so that tools can use the
     // methods here and receive callbacks. MNG-1015
-    //     
+    //
     //    Probably no longer relevant with wagonManager/wagonManager change - joakime
     // ----------------------------------------------------------------------
 
@@ -223,8 +223,8 @@
         throws ProjectBuildingException
     {
         ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager
);
-        
-        MavenProject project = (MavenProject) projectBuildCache.getCachedProject( artifact
);
+
+        MavenProject project = projectBuildCache.getCachedProject( artifact );
 
         if ( project != null )
         {
@@ -252,8 +252,8 @@
         ProfileManager profileManager = new DefaultProfileManager( container );
         return buildStandaloneSuperProject( localRepository, profileManager );
     }
-    
-    public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository,
ProfileManager profileManager ) 
+
+    public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository,
ProfileManager profileManager )
         throws ProjectBuildingException
     {
         Model superModel = getSuperModel();
@@ -265,27 +265,27 @@
         superModel.setVersion( STANDALONE_SUPERPOM_VERSION );
 
         MavenProject project = new MavenProject( superModel );
-        
+
         ProjectBuildContext projectContext = ProjectBuildContext.getProjectBuildContext(
buildContextManager, true );
-        
+
         projectContext.setCurrentProject( project );
         projectContext.store( buildContextManager );
-        
+
         String projectId = safeVersionlessKey( STANDALONE_SUPERPOM_GROUPID, STANDALONE_SUPERPOM_ARTIFACTID
);
-        
+
         project.setManagedVersionMap(createManagedVersionMap(projectId, superModel.getDependencyManagement(),
null));
 
         List activeProfiles = profileAdvisor.applyActivatedProfiles( superModel, null, profileManager.getExplicitlyActivatedIds(),
profileManager.getExplicitlyDeactivatedIds() );
         List activeExternalProfiles = profileAdvisor.applyActivatedExternalProfiles( superModel,
null, profileManager );
-        
+
         LinkedHashSet profiles = new LinkedHashSet();
-        
-        if ( activeProfiles != null && !activeProfiles.isEmpty() )
+
+        if ( ( activeProfiles != null ) && !activeProfiles.isEmpty() )
         {
             profiles.addAll( activeProfiles );
         }
-        
-        if ( activeExternalProfiles != null && !activeExternalProfiles.isEmpty()
)
+
+        if ( ( activeExternalProfiles != null ) && !activeExternalProfiles.isEmpty()
)
         {
             profiles.addAll( activeExternalProfiles );
         }
@@ -408,7 +408,7 @@
     {
         Map map = null;
         List deps;
-        if ( dependencyManagement != null && (deps = dependencyManagement.getDependencies())
!= null && deps.size() > 0)
+        if ( ( dependencyManagement != null ) && ( (deps = dependencyManagement.getDependencies())
!= null ) && ( deps.size() > 0 ))
         {
             map = new ManagedVersionMap( map );
 
@@ -436,7 +436,7 @@
                     // If the dependencyManagement section listed exclusions,
                     // add them to the managed artifacts here so that transitive
                     // dependencies will be excluded if necessary.
-                    if ( null != d.getExclusions() && !d.getExclusions().isEmpty()
)
+                    if ( ( null != d.getExclusions() ) && !d.getExclusions().isEmpty()
)
                     {
                         List exclusions = new ArrayList();
                         Iterator exclItr = d.getExclusions().iterator();
@@ -479,7 +479,7 @@
         {
             container.addContextValue("SystemProperties", System.getProperties());
         }
-        
+
         Model model = readModel( "unknown", projectDescriptor, STRICT_MODEL_PARSING );
 
         MavenProject project = buildInternal( projectDescriptor.getAbsolutePath(),
@@ -492,7 +492,7 @@
 
         if ( checkDistributionManagementStatus )
         {
-            if ( project.getDistributionManagement() != null && project.getDistributionManagement().getStatus()
!= null )
+            if ( ( project.getDistributionManagement() != null ) && ( project.getDistributionManagement().getStatus()
!= null ) )
             {
                 String projectId = safeVersionlessKey( project.getGroupId(), project.getArtifactId()
);
 
@@ -593,7 +593,7 @@
         throws ArtifactNotFoundException
     {
         // TODO: configurable actions dependant on status
-        if ( !projectArtifact.isSnapshot() && status.compareTo( ArtifactStatus.DEPLOYED
) < 0 )
+        if ( !projectArtifact.isSnapshot() && ( status.compareTo( ArtifactStatus.DEPLOYED
) < 0 ) )
         {
             // use default policy (enabled, daily update, warn on bad checksum)
             ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy();
@@ -674,12 +674,12 @@
         Model superModel = getSuperModel();
 
         MavenProject superProject = new MavenProject( superModel );
-        
+
         String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId()
);
 
         List explicitlyActive;
         List explicitlyInactive;
-        
+
         if ( externalProfileManager != null )
         {
             // used to trigger the caching of SystemProperties in the container context...
@@ -691,7 +691,7 @@
             {
                 throw new ProjectBuildingException( projectId, "Failed to activate external
profiles.", e );
             }
-            
+
             explicitlyActive = externalProfileManager.getExplicitlyActivatedIds();
             explicitlyInactive = externalProfileManager.getExplicitlyDeactivatedIds();
         }
@@ -700,7 +700,7 @@
             explicitlyActive = Collections.EMPTY_LIST;
             explicitlyInactive = Collections.EMPTY_LIST;
         }
-        
+
         superProject.setActiveProfiles( profileAdvisor.applyActivatedProfiles( superModel,
null, explicitlyActive, explicitlyInactive ) );
 
         //noinspection CollectionDeclaredAsConcreteClass
@@ -710,7 +710,7 @@
                                                                                       parentSearchRepositories,
                                                                                       projectDir,
explicitlyActive,
                                                                                       explicitlyInactive
);
-        
+
         Model originalModel = ModelUtils.cloneModel( model );
 
         MavenProject project = null;
@@ -754,8 +754,12 @@
                 getLogger().debug( "Cannot determine whether " + currentProject.getId() +
" is a module of " + previousProject.getId() + ". Reason: " + e.getMessage(), e );
             }
 
+            getLogger().debug( "[buildInternal] Assembling model-inheritance: child=" + current.getId()
+ ", parent=" + previous.getId() );
+
             modelInheritanceAssembler.assembleModelInheritance( current, previous, pathAdjustment
);
 
+            getLogger().debug( "[buildInternal] Assembled model-inheritance for child=" +
current.getId() );
+
             previous = current;
             previousProject = currentProject;
         }
@@ -810,13 +814,13 @@
             // Only track the file of a POM in the source tree
             project.setFile( projectDescriptor );
         }
-        
+
         MavenProject rawParent = project.getParent();
-        
+
         if ( rawParent != null )
         {
-            MavenProject processedParent = (MavenProject) projectBuildCache.getCachedProject(
rawParent );
-            
+            MavenProject processedParent = projectBuildCache.getCachedProject( rawParent
);
+
             // yeah, this null check might be a bit paranoid, but better safe than sorry...
             if ( processedParent != null )
             {
@@ -829,10 +833,10 @@
 
         return project;
     }
-    
+
     /*
      * Order is:
-     * 
+     *
      * 1. model profile repositories
      * 2. model repositories
      * 3. superModel profile repositories
@@ -844,16 +848,16 @@
         throws ProjectBuildingException
     {
         LinkedHashSet collected = new LinkedHashSet();
-        
+
         collectInitialRepositoriesFromModel( collected, model, projectDir, explicitlyActive,
explicitlyInactive );
 
         collectInitialRepositoriesFromModel( collected, superModel, projectDir, explicitlyActive,
explicitlyInactive );
 
-        if ( parentSearchRepositories != null && !parentSearchRepositories.isEmpty()
)
+        if ( ( parentSearchRepositories != null ) && !parentSearchRepositories.isEmpty()
)
         {
             collected.addAll( parentSearchRepositories );
         }
-        
+
         return collected;
     }
 
@@ -865,13 +869,13 @@
                                                                                         
 explicitlyActive,
                                                                                         
 explicitlyInactive );
 
-        if ( reposFromProfiles != null && !reposFromProfiles.isEmpty() )
+        if ( ( reposFromProfiles != null ) && !reposFromProfiles.isEmpty() )
         {
             collected.addAll( reposFromProfiles );
         }
 
         List modelRepos = model.getRepositories();
-        if ( modelRepos != null && !modelRepos.isEmpty() )
+        if ( ( modelRepos != null ) && !modelRepos.isEmpty() )
         {
             try
             {
@@ -967,7 +971,7 @@
         MavenProject parentProject = project.getParent();
 
         Model originalModel = project.getOriginalModel();
-        
+
         Artifact parentArtifact = project.getParentArtifact();
 
         // We will return a different project object using the new model (hence the need
to return a project, not just modify the parameter)
@@ -1049,17 +1053,17 @@
     {
         ModelLineage modelLineage = new DefaultModelLineage();
         modelLineage.setOrigin( model, new File( projectDir, "pom.xml" ), new ArrayList(
aggregatedRemoteWagonRepositories ) );
-        
+
         modelLineageBuilder.resumeBuildingModelLineage( modelLineage, localRepository, externalProfileManager
);
-        
+
         ProjectBuildContext projectContext = ProjectBuildContext.getProjectBuildContext(
buildContextManager, true );
-        
+
         projectContext.setModelLineage( modelLineage );
         projectContext.store( buildContextManager );
-        
+
         List explicitlyActive;
         List explicitlyInactive;
-        
+
         if ( externalProfileManager != null )
         {
             explicitlyActive = externalProfileManager.getExplicitlyActivatedIds();
@@ -1070,50 +1074,53 @@
             explicitlyActive = Collections.EMPTY_LIST;
             explicitlyInactive = Collections.EMPTY_LIST;
         }
-        
+
         MavenProject lastProject = null;
         for ( ModelLineageIterator it = modelLineage.lineageIterator(); it.hasNext(); )
         {
             Model currentModel = (Model) it.next();
+
+            getLogger().debug( "[assembleLineage] Assembling MavenProject instance for: "
+ currentModel.getId() );
+
             File currentPom = it.getPOMFile();
-            
+
             MavenProject project = new MavenProject( currentModel );
             project.setFile( currentPom );
-            
+
             projectContext.setCurrentProject( project );
             projectContext.store( buildContextManager );
 
             project.setActiveProfiles( profileAdvisor.applyActivatedProfiles( currentModel,
projectDir, explicitlyActive,
                                                                               explicitlyInactive
) );
-            
+
             if ( lastProject != null )
             {
                 lastProject.setParent( project );
-                
+
                 lastProject.setParentArtifact( artifactFactory.createParentArtifact( project.getGroupId(),
project
                     .getArtifactId(), project.getVersion() ) );
             }
-            
+
             lineage.addFirst( project );
-            
+
             lastProject = project;
         }
 
         MavenProject result = (MavenProject) lineage.getLast();
-        
+
         if ( externalProfileManager != null )
         {
             LinkedHashSet active = new LinkedHashSet();
-            
+
             List existingActiveProfiles = result.getActiveProfiles();
-            if ( existingActiveProfiles != null && !existingActiveProfiles.isEmpty()
)
+            if ( ( existingActiveProfiles != null ) && !existingActiveProfiles.isEmpty()
)
             {
                 active.addAll( existingActiveProfiles );
             }
-            
+
             profileAdvisor.applyActivatedExternalProfiles( result.getModel(), projectDir,
externalProfileManager );
         }
-        
+
         return result;
     }
 
@@ -1343,6 +1350,6 @@
     public void contextualize( Context context )
         throws ContextException
     {
-        this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
     }
 }

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java?view=diff&rev=564299&r1=564298&r2=564299
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java
(original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java
Thu Aug  9 10:45:37 2007
@@ -67,7 +67,7 @@
     private MavenTools mavenTools;
 
     private ProfileAdvisor profileAdvisor;
-    
+
     private BuildContextManager buildContextManager;
 
     private Logger logger;
@@ -78,7 +78,7 @@
 
     public DefaultModelLineageBuilder( ArtifactResolver resolver, ArtifactFactory artifactFactory,
BuildContextManager buildContextManager )
     {
-        this.artifactResolver = resolver;
+        artifactResolver = resolver;
         this.artifactFactory = artifactFactory;
         this.buildContextManager = buildContextManager;
     }
@@ -91,30 +91,28 @@
         throws ProjectBuildingException
     {
         ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager
);
-        
+
         ModelLineage lineage = new DefaultModelLineage();
 
-        File pomFile = pom;
         List currentRemoteRepositories = remoteRepositories == null ? new ArrayList()
                                                                    : new ArrayList( remoteRepositories
);
 
-        while ( pomFile != null )
-        {
-            Model model = readModel( pomFile, projectBuildCache );
+        ModelAndFile current = new ModelAndFile( readModel( pom, projectBuildCache ), pom
);
 
+        while ( current != null )
+        {
             if ( lineage.size() == 0 )
             {
-                lineage.setOrigin( model, pomFile, currentRemoteRepositories );
+                lineage.setOrigin( current.model, current.file, currentRemoteRepositories
);
             }
             else
             {
-                lineage.addParent( model, pomFile, currentRemoteRepositories );
+                lineage.addParent( current.model, current.file, currentRemoteRepositories
);
             }
 
-            currentRemoteRepositories = updateRepositorySet( model, currentRemoteRepositories,
pomFile, profileManager );
+            currentRemoteRepositories = updateRepositorySet( current.model, currentRemoteRepositories,
current.file, profileManager );
 
-            pomFile = resolveParentPom( model, currentRemoteRepositories, localRepository,
pomFile,
-                                        projectBuildCache );
+            current = resolveParentPom( current, currentRemoteRepositories, localRepository,
projectBuildCache );
         }
 
         return lineage;
@@ -125,8 +123,7 @@
         throws ProjectBuildingException
     {
         ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager
);
-        
-        File pomFile = lineage.getDeepestFile();
+
         List currentRemoteRepositories = lineage.getDeepestArtifactRepositoryList();
 
         if ( currentRemoteRepositories == null )
@@ -134,28 +131,25 @@
             currentRemoteRepositories = new ArrayList();
         }
 
-        Model model = lineage.getDeepestModel();
+        ModelAndFile current = new ModelAndFile( lineage.getDeepestModel(), lineage.getDeepestFile()
);
 
         // use the above information to re-bootstrap the resolution chain...
-        pomFile = resolveParentPom( model, currentRemoteRepositories, localRepository, pomFile,
projectBuildCache );
+        current = resolveParentPom( current, currentRemoteRepositories, localRepository,
projectBuildCache );
 
-        while ( pomFile != null )
+        while ( current != null )
         {
-            model = readModel( pomFile, projectBuildCache );
-
             if ( lineage.size() == 0 )
             {
-                lineage.setOrigin( model, pomFile, currentRemoteRepositories );
+                lineage.setOrigin( current.model, current.file, currentRemoteRepositories
);
             }
             else
             {
-                lineage.addParent( model, pomFile, currentRemoteRepositories );
+                lineage.addParent( current.model, current.file, currentRemoteRepositories
);
             }
 
-            currentRemoteRepositories = updateRepositorySet( model, currentRemoteRepositories,
pomFile, profileManager );
+            currentRemoteRepositories = updateRepositorySet( current.model, currentRemoteRepositories,
current.file, profileManager );
 
-            pomFile = resolveParentPom( model, currentRemoteRepositories, localRepository,
pomFile,
-                                        projectBuildCache );
+            current = resolveParentPom( current, currentRemoteRepositories, localRepository,
projectBuildCache );
         }
     }
 
@@ -170,7 +164,7 @@
     }
 
     /**
-     * Read the Model instance from the given POM file, and cache it in the given Map before

+     * Read the Model instance from the given POM file, and cache it in the given Map before
      * returning it.
      */
     private Model readModel( File pomFile, ProjectBuildCache projectBuildCache )
@@ -193,7 +187,7 @@
             pomFile = new File( pom, "pom.xml" );
 //            getLogger().debug( "readModel(..): POM: " + pom + " is a directory. Trying:
" + pomFile + " instead." );
         }
-        
+
         Model model;
         FileReader reader = null;
 
@@ -225,10 +219,10 @@
     }
 
     /**
-     * Update the remote repository set used to resolve parent POMs, by adding those declared
in 
+     * Update the remote repository set used to resolve parent POMs, by adding those declared
in
      * the given model to the HEAD of a new list, then appending the old remote repositories
list.
      * The specified pomFile is used for error reporting.
-     * @param profileManager 
+     * @param profileManager
      */
     private List updateRepositorySet( Model model, List oldArtifactRepositories, File pomFile,
                                       ProfileManager externalProfileManager )
@@ -236,7 +230,9 @@
     {
         List repositories = model.getRepositories();
 
-        loadActiveProfileRepositories( repositories, model, externalProfileManager, pomFile.getParentFile()
);
+        File projectDir = pomFile == null ? null : pomFile.getParentFile();
+
+        loadActiveProfileRepositories( repositories, model, externalProfileManager, projectDir
);
 
         Set artifactRepositories = null;
 
@@ -293,36 +289,57 @@
     /**
      * Pull the parent specification out of the given model, construct an Artifact instance,
and
      * resolve that artifact...then, return the resolved POM file for the parent.
-     * @param projectBuildCache 
+     * @param projectBuildCache
      */
-    private File resolveParentPom( Model model, List remoteRepositories, ArtifactRepository
localRepository,
-                                   File modelPomFile, ProjectBuildCache projectBuildCache
)
+    private ModelAndFile resolveParentPom( ModelAndFile child, List remoteRepositories, ArtifactRepository
localRepository,
+                                   ProjectBuildCache projectBuildCache )
         throws ProjectBuildingException
     {
+        Model model = child.model;
+        File modelPomFile = child.file;
+
         Parent modelParent = model.getParent();
 
-        File pomFile = null;
+        ModelAndFile result = null;
 
         if ( modelParent != null )
         {
             validateParentDeclaration( modelParent, model );
 
 //            getLogger().debug( "Looking for cached parent POM under: " + cacheKey );
-            
-            pomFile = (File) projectBuildCache.getCachedModelFile( modelParent );
 
-            if ( pomFile == null )
+            File parentPomFile = projectBuildCache.getCachedModelFile( modelParent );
+
+            if ( parentPomFile == null )
+            {
+                parentPomFile = resolveParentWithRelativePath( modelParent, modelPomFile
);
+            }
+
+            if ( parentPomFile == null )
             {
-                pomFile = resolveParentWithRelativePath( modelParent, modelPomFile );
+                parentPomFile = resolveParentFromRepositories( modelParent, localRepository,
remoteRepositories, modelPomFile );
             }
 
-            if ( pomFile == null )
+            Model parent;
+            if ( parentPomFile == null )
             {
-                pomFile = resolveParentFromRepositories( modelParent, localRepository, remoteRepositories,
modelPomFile );
+                getLogger().warn( "Cannot find parent POM: " + modelParent.getId() + " for
child: " + model.getId() + ". Using stub model instead." );
+
+                parent = new Model();
+
+                parent.setGroupId( modelParent.getGroupId() );
+                parent.setArtifactId( modelParent.getArtifactId() );
+                parent.setVersion( modelParent.getVersion() );
             }
+            else
+            {
+                parent = readModel( parentPomFile );
+            }
+
+            result = new ModelAndFile( parent, parentPomFile );
         }
 
-        return pomFile;
+        return result;
     }
 
     private void validateParentDeclaration( Parent modelParent, Model model )
@@ -404,9 +421,9 @@
         {
             Model parentModel = readModel( parentPomFile );
 
-            boolean groupsMatch = parentModel.getGroupId() == null
+            boolean groupsMatch = ( parentModel.getGroupId() == null )
                 || parentModel.getGroupId().equals( modelParent.getGroupId() );
-            boolean versionsMatch = parentModel.getVersion() == null
+            boolean versionsMatch = ( parentModel.getVersion() == null )
                 || parentModel.getVersion().equals( modelParent.getVersion() );
 
             if ( groupsMatch && versionsMatch && parentModel.getArtifactId().equals(
modelParent.getArtifactId() ) )
@@ -431,6 +448,18 @@
     public void enableLogging( Logger logger )
     {
         this.logger = logger;
+    }
+
+    private static final class ModelAndFile
+    {
+        private final Model model;
+        private final File file;
+
+        ModelAndFile( Model model, File file )
+        {
+            this.model = model;
+            this.file = file;
+        }
     }
 
 }



Mime
View raw message