maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
Subject svn commit: r819596 - in /maven/maven-3/trunk/maven-core/src: main/java/org/apache/maven/project/ test/java/org/apache/maven/project/
Date Mon, 28 Sep 2009 15:43:14 GMT
Author: bentmann
Date: Mon Sep 28 15:43:14 2009
New Revision: 819596

URL: http://svn.apache.org/viewvc?rev=819596&view=rev
Log:
o Fixed tracking of extension realms in cache

Modified:
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingHelper.java
    maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyProjectBuildingHelper.java

Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java?rev=819596&r1=819595&r2=819596&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java
(original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java
Mon Sep 28 15:43:14 2009
@@ -25,12 +25,10 @@
 import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
 import org.apache.maven.artifact.repository.RepositoryRequest;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.building.AbstractModelBuildingListener;
 import org.apache.maven.model.building.ModelBuildingEvent;
 import org.apache.maven.plugin.version.PluginVersionResolutionException;
-import org.codehaus.plexus.classworlds.realm.ClassRealm;
 
 /**
  * Processes events from the model builder while building the effective model for a {@link
MavenProject} instance.
@@ -41,24 +39,28 @@
     extends AbstractModelBuildingListener
 {
 
+    private MavenProject project;
+
     private ProjectBuildingHelper projectBuildingHelper;
 
     private ProjectBuildingRequest projectBuildingRequest;
 
-    private ClassRealm projectRealm;
-
-    private ArtifactFilter extensionArtifactFilter;
-
     private List<ArtifactRepository> remoteRepositories;
 
     private List<ArtifactRepository> pluginRepositories;
 
-    public DefaultModelBuildingListener( ProjectBuildingHelper projectBuildingHelper,
+    public DefaultModelBuildingListener( MavenProject project, ProjectBuildingHelper projectBuildingHelper,
                                          ProjectBuildingRequest projectBuildingRequest )
     {
+        if ( project == null )
+        {
+            throw new IllegalArgumentException( "project missing" );
+        }
+        this.project = project;
+
         if ( projectBuildingHelper == null )
         {
-            throw new IllegalArgumentException( "project realm manager missing" );
+            throw new IllegalArgumentException( "project building helper missing" );
         }
         this.projectBuildingHelper = projectBuildingHelper;
 
@@ -72,51 +74,13 @@
     }
 
     /**
-     * Gets the project realm that hosts the build extensions.
-     * 
-     * @return The project realm or {@code null} if the project requires no extensions.
-     */
-    public ClassRealm getProjectRealm()
-    {
-        return projectRealm;
-    }
-
-    /**
-     * Gets the artifact filter to exclude extension artifacts from plugin realms.
-     * 
-     * @return The extension artifact filter or {@code null} if none.
-     */
-    public ArtifactFilter getExtentionArtifactFilter()
-    {
-        return extensionArtifactFilter;
-    }
-
-    /**
-     * Gets the effective remote artifact repositories for the project. The repository list
is created from the
-     * repositories given by {@link ProjectBuildingRequest#getRemoteRepositories()} and the
repositories given in the
-     * POM, i.e. {@link Model#getRepositories()}. The POM repositories themselves also contain
any repositories
-     * contributed by external profiles as specified in {@link ProjectBuildingRequest#getProfiles()}.
Furthermore, the
-     * repositories have already been mirrored.
-     * 
-     * @return The remote artifact repositories for the project.
-     */
-    public List<ArtifactRepository> getRemoteRepositories()
-    {
-        return remoteRepositories;
-    }
-
-    /**
-     * Gets the effective remote plugin repositories for the project. The repository list
is created from the
-     * repositories given by {@link ProjectBuildingRequest#getPluginArtifactRepositories()}
and the repositories given
-     * in the POM, i.e. {@link Model#getPluginRepositories()}. The POM repositories themselves
also contain any
-     * repositories contributed by external profiles as specified in {@link ProjectBuildingRequest#getProfiles()}.
-     * Furthermore, the repositories have already been mirrored.
+     * Gets the project whose model is being built.
      * 
-     * @return The remote plugin repositories for the project.
+     * @return The project, never {@code null}.
      */
-    public List<ArtifactRepository> getPluginRepositories()
+    public MavenProject getProject()
     {
-        return pluginRepositories;
+        return project;
     }
 
     @Override
@@ -134,6 +98,7 @@
         {
             event.getProblems().addError( "Invalid plugin repository: " + e.getMessage(),
e );
         }
+        project.setPluginArtifactRepositories( pluginRepositories );
 
         if ( event.getRequest().isProcessPlugins() )
         {
@@ -146,10 +111,10 @@
                 repositoryRequest.setOffline( projectBuildingRequest.isOffline() );
 
                 ProjectRealmCache.CacheRecord record =
-                    projectBuildingHelper.createProjectRealm( model, repositoryRequest );
+                    projectBuildingHelper.createProjectRealm( project, model, repositoryRequest
);
 
-                projectRealm = record.realm;
-                extensionArtifactFilter = record.extensionArtifactFilter;
+                project.setClassRealm( record.realm );
+                project.setExtensionArtifactFilter( record.extensionArtifactFilter );
             }
             catch ( ArtifactResolutionException e )
             {
@@ -160,14 +125,14 @@
                 event.getProblems().addError( "Unresolveable build extensions: " + e.getMessage(),
e );
             }
 
-            if ( projectRealm != null )
+            if ( project.getClassRealm() != null )
             {
                 /*
                  * Update the context class loader such that the container will search the
project realm when the model
                  * builder injects the lifecycle bindings from the packaging in the next
step. The context class loader
                  * will be reset by the project builder when the project is fully assembled.
                  */
-                Thread.currentThread().setContextClassLoader( projectRealm );
+                Thread.currentThread().setContextClassLoader( project.getClassRealm() );
             }
         }
 
@@ -182,6 +147,7 @@
         {
             event.getProblems().addError( "Invalid artifact repository: " + e.getMessage(),
e );
         }
+        project.setRemoteArtifactRepositories( remoteRepositories );
     }
 
 }

Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java?rev=819596&r1=819595&r2=819596&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
(original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
Mon Sep 28 15:43:14 2009
@@ -92,8 +92,11 @@
             if ( project == null )
             {
                 ModelBuildingRequest request = getModelBuildingRequest( configuration, null
);
-    
-                DefaultModelBuildingListener listener = new DefaultModelBuildingListener(
projectBuildingHelper, configuration );
+
+                project = new MavenProject( repositorySystem, this, configuration );
+
+                DefaultModelBuildingListener listener =
+                    new DefaultModelBuildingListener( project, projectBuildingHelper, configuration
);
                 request.setModelBuildingListener( listener );
     
                 if ( localProject )
@@ -117,7 +120,7 @@
 
                 modelProblems = result.getProblems();
 
-                project = toProject( result, configuration, listener );
+                initProject( project, result );
             }
 
             ArtifactResolutionResult artifactResult = null;
@@ -228,7 +231,10 @@
     {
         ModelBuildingRequest request = getModelBuildingRequest( config, null );
 
-        DefaultModelBuildingListener listener = new DefaultModelBuildingListener( projectBuildingHelper,
config );
+        MavenProject standaloneProject = new MavenProject( repositorySystem, this, config
);
+
+        DefaultModelBuildingListener listener =
+            new DefaultModelBuildingListener( standaloneProject, projectBuildingHelper, config
);
         request.setModelBuildingListener( listener );
 
         request.setModelSource( new UrlModelSource( getClass().getResource( "standalone.xml"
) ) );
@@ -243,12 +249,11 @@
             throw new ProjectBuildingException( "[standalone]", "Failed to build standalone
project", e );
         }
 
-        MavenProject standaloneProject = new MavenProject( result.getEffectiveModel(), repositorySystem,
this, config );
+        standaloneProject.setModel( result.getEffectiveModel() );
+        standaloneProject.setOriginalModel( result.getRawModel() );
 
         standaloneProject.setActiveProfiles( result.getActiveExternalProfiles() );
         standaloneProject.setInjectedProfileIds( "external", getProfileIds( result.getActiveExternalProfiles()
) );
-        standaloneProject.setRemoteArtifactRepositories( listener.getRemoteRepositories()
);
-        standaloneProject.setPluginArtifactRepositories( listener.getPluginRepositories()
);
 
         standaloneProject.setExecutionRoot( true );
 
@@ -300,11 +305,14 @@
         {
             ModelBuildingRequest request = getModelBuildingRequest( config, reactorModelPool
);
 
+            MavenProject project = new MavenProject( repositorySystem, this, config );
+
             request.setPomFile( pomFile );
             request.setTwoPhaseBuilding( true );
             request.setModelCache( modelCache );
 
-            DefaultModelBuildingListener listener = new DefaultModelBuildingListener( projectBuildingHelper,
config );
+            DefaultModelBuildingListener listener =
+                new DefaultModelBuildingListener( project, projectBuildingHelper, config
);
             request.setModelBuildingListener( listener );
 
             try
@@ -437,7 +445,8 @@
             {
                 ModelBuildingResult result = modelBuilder.build( interimResult.request, interimResult.result
);
 
-                MavenProject project = toProject( result, config, interimResult.listener
);
+                MavenProject project = interimResult.listener.getProject();
+                initProject( project, result );
 
                 projects.add( project );
 
@@ -463,12 +472,12 @@
         return noErrors;
     }
 
-    private MavenProject toProject( ModelBuildingResult result, ProjectBuildingRequest configuration,
-                                    DefaultModelBuildingListener listener )
+    private void initProject( MavenProject project, ModelBuildingResult result )
     {
         Model model = result.getEffectiveModel();
 
-        MavenProject project = new MavenProject( model, repositorySystem, this, configuration
);
+        project.setModel( model );
+        project.setOriginalModel( result.getRawModel() );
 
         project.setFile( model.getPomFile() );
 
@@ -480,14 +489,6 @@
                                              project.getPackaging() );
         project.setArtifact( projectArtifact );
 
-        project.setOriginalModel( result.getRawModel() );
-
-        project.setRemoteArtifactRepositories( listener.getRemoteRepositories() );
-        project.setPluginArtifactRepositories( listener.getPluginRepositories() );
-
-        project.setClassRealm( listener.getProjectRealm() );
-        project.setExtensionArtifactFilter( listener.getExtentionArtifactFilter() );
-
         Build build = project.getBuild();
         project.addScriptSourceRoot( build.getScriptSourceDirectory() );
         project.addCompileSourceRoot( build.getSourceDirectory() );
@@ -503,8 +504,6 @@
         {
             project.setInjectedProfileIds( modelId, getProfileIds( result.getActivePomProfiles(
modelId ) ) );
         }
-
-        return project;
     }
 
 }

Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java?rev=819596&r1=819595&r2=819596&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java
(original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java
Mon Sep 28 15:43:14 2009
@@ -129,7 +129,7 @@
         return artifactRepositories;
     }
 
-    public synchronized ProjectRealmCache.CacheRecord createProjectRealm( Model model,
+    public synchronized ProjectRealmCache.CacheRecord createProjectRealm( MavenProject project,
Model model,
                                                                           RepositoryRequest
repositoryRequest )
         throws ArtifactResolutionException, PluginVersionResolutionException
     {
@@ -261,6 +261,8 @@
                 extensionRealmCache.put( plugin, repositoryRequest, extensionRealm, artifacts,
extensionDescriptor );
             }
 
+            extensionRealmCache.register( project, extensionRealm );
+
             extensionRealms.add( extensionRealm );
             if ( extensionDescriptor != null )
             {

Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/MavenProject.java?rev=819596&r1=819595&r2=819596&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
(original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
Mon Sep 28 15:43:14 2009
@@ -216,30 +216,22 @@
     /**
      * Constructor
      * 
-     * @param model - may not be null
      * @param artifactFactory - may not be null
      * @param repositorySystem - may not be null
      * @param mavenProjectBuilder
      * @param projectBuilderConfiguration
      * @throws InvalidRepositoryException
      */
-    public MavenProject( Model model, RepositorySystem repositorySystem, ProjectBuilder mavenProjectBuilder,
ProjectBuildingRequest projectBuilderConfiguration )
+    MavenProject( RepositorySystem repositorySystem, ProjectBuilder mavenProjectBuilder,
ProjectBuildingRequest projectBuilderConfiguration )
     {
-        if ( model == null )
-        {
-            throw new IllegalArgumentException( "model: null" );
-        }
-
         if ( repositorySystem == null )
         {
             throw new IllegalArgumentException( "mavenTools: null" );
         }
 
-        setModel( model );
         this.mavenProjectBuilder = mavenProjectBuilder;
         this.projectBuilderConfiguration = projectBuilderConfiguration;
         this.repositorySystem = repositorySystem;
-        originalModel = model;
     }
 
     //TODO: need to integrate the effective scope and refactor it out of the MMS

Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingHelper.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingHelper.java?rev=819596&r1=819595&r2=819596&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingHelper.java
(original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingHelper.java
Mon Sep 28 15:43:14 2009
@@ -58,12 +58,14 @@
     /**
      * Creates the project realm that hosts the build extensions of the specified model.
      * 
+     * @param project The project to create the project realm for, must not be {@code null}
      * @param model The model to create the project realm for, must not be {@code null}
      * @param repositoryRequest The repository request to use for artifact resolution, must
not be {@code null}.
      * @return The record with the project realm and extension artifact filter, never {@code
null}.
      * @throws ArtifactResolutionException If any build extension could not be resolved.
      */
-    ProjectRealmCache.CacheRecord createProjectRealm( Model model, RepositoryRequest repositoryRequest
)
+    ProjectRealmCache.CacheRecord createProjectRealm( MavenProject project, Model model,
+                                                      RepositoryRequest repositoryRequest
)
         throws ArtifactResolutionException, PluginVersionResolutionException;
 
 }

Modified: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyProjectBuildingHelper.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyProjectBuildingHelper.java?rev=819596&r1=819595&r2=819596&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyProjectBuildingHelper.java
(original)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyProjectBuildingHelper.java
Mon Sep 28 15:43:14 2009
@@ -55,7 +55,8 @@
         }
     }
 
-    public ProjectRealmCache.CacheRecord createProjectRealm( Model model, RepositoryRequest
repositoryRequest )
+    public ProjectRealmCache.CacheRecord createProjectRealm( MavenProject proejct, Model
model,
+                                                             RepositoryRequest repositoryRequest
)
         throws ArtifactResolutionException
     {
         return new ProjectRealmCache.CacheRecord( null, null );



Mime
View raw message