You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2007/02/20 20:22:06 UTC

svn commit: r509715 - in /maven/components/trunk/maven-core/src/main/java/org/apache/maven: DefaultMaven.java extension/BuildExtensionScanner.java extension/DefaultBuildExtensionScanner.java

Author: jdcasey
Date: Tue Feb 20 11:22:05 2007
New Revision: 509715

URL: http://svn.apache.org/viewvc?view=rev&rev=509715
Log:
Prevent scanning of modules that are not in the current reactor, and simplify the API usage for scanning in a reactor scenario.

Modified:
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/extension/BuildExtensionScanner.java
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java?view=diff&rev=509715&r1=509714&r2=509715
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java Tue Feb 20 11:22:05 2007
@@ -343,18 +343,13 @@
         
         // TODO: We should probably do this discovery just-in-time, if we can move to building project
         // instances just-in-time.
-        for ( Iterator it = files.iterator(); it.hasNext(); )
+        try
         {
-            File pom = (File) it.next();
-
-            try
-            {
-                buildExtensionScanner.scanForBuildExtensions( pom, request.getLocalRepository(), globalProfileManager );
-            }
-            catch ( ExtensionScanningException e )
-            {
-                throw new MavenExecutionException( "Error scanning: " + pom + " for extensions: " + e.getMessage(), e );
-            }
+            buildExtensionScanner.scanForBuildExtensions( files, request.getLocalRepository(), globalProfileManager );
+        }
+        catch ( ExtensionScanningException e )
+        {
+            throw new MavenExecutionException( "Error scanning for extensions: " + e.getMessage(), e );
         }
         
         try

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/extension/BuildExtensionScanner.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/extension/BuildExtensionScanner.java?view=diff&rev=509715&r1=509714&r2=509715
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/extension/BuildExtensionScanner.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/extension/BuildExtensionScanner.java Tue Feb 20 11:22:05 2007
@@ -4,12 +4,16 @@
 import org.apache.maven.profiles.ProfileManager;
 
 import java.io.File;
+import java.util.List;
 
 public interface BuildExtensionScanner
 {
     
     String ROLE = BuildExtensionScanner.class.getName();
     
+    void scanForBuildExtensions( List files, ArtifactRepository localRepository, ProfileManager globalProfileManager )
+        throws ExtensionScanningException;
+
     void scanForBuildExtensions( File pom, ArtifactRepository localRepository, ProfileManager globalProfileManager )
         throws ExtensionScanningException;
 

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java?view=diff&rev=509715&r1=509714&r2=509715
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java Tue Feb 20 11:22:05 2007
@@ -27,6 +27,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -46,21 +47,37 @@
     private MavenProjectBuilder projectBuilder;
 
     private ModelLineageBuilder modelLineageBuilder;
-    
+
     private ModelInterpolator modelInterpolator;
 
+    public void scanForBuildExtensions( List files, ArtifactRepository localRepository,
+                                        ProfileManager globalProfileManager )
+        throws ExtensionScanningException
+    {
+        List visited = new ArrayList();
+
+        for ( Iterator it = files.iterator(); it.hasNext(); )
+        {
+            File pom = (File) it.next();
+
+            scanInternal( pom, localRepository, globalProfileManager, visited, files );
+        }
+    }
+
     public void scanForBuildExtensions( File pom, ArtifactRepository localRepository,
                                         ProfileManager globalProfileManager )
         throws ExtensionScanningException
     {
-        scanInternal( pom, localRepository, globalProfileManager, new ArrayList() );
+        scanInternal( pom, localRepository, globalProfileManager, new ArrayList(), Collections.singletonList( pom ) );
     }
-    
+
+    // TODO: Use a build-context cache object for visitedModelIdx and reactorFiles, 
+    //       once we move to just-in-time project scanning.
     private void scanInternal( File pom, ArtifactRepository localRepository, ProfileManager globalProfileManager,
-                               List visitedModelIds )
+                               List visitedModelIds, List reactorFiles )
         throws ExtensionScanningException
     {
-        
+
         // setup the CustomActivatorAdvice to fail quietly while we discover extensions...then, we'll
         // reset it.
         CustomActivatorAdvice activatorAdvice = CustomActivatorAdvice.getCustomActivatorAdvice( buildContextManager );
@@ -77,35 +94,47 @@
                                                       globalProfileManager );
 
             Map inheritedInterpolationValues = new HashMap();
-            
+
             for ( ModelLineageIterator lineageIterator = lineage.reversedLineageIterator(); lineageIterator.hasNext(); )
             {
                 Model model = (Model) lineageIterator.next();
+                File modelPom = lineageIterator.getPOMFile();
+
                 String key = createKey( model );
-                
+
                 if ( visitedModelIds.contains( key ) )
                 {
                     getLogger().debug( "Already visited: " + key + "; continuing." );
                     continue;
                 }
-                
+
                 visitedModelIds.add( key );
-                
-                File modelPom = lineageIterator.getPOMFile();
 
-                getLogger().debug( "Checking: " + model.getId() + " for extensions. (It has " + model.getModules().size() + " modules.)" );
-                
+                getLogger().debug(
+                                   "Checking: " + model.getId() + " for extensions. (It has "
+                                       + model.getModules().size() + " modules.)" );
+
                 if ( inheritedInterpolationValues == null )
                 {
                     inheritedInterpolationValues = new HashMap();
                 }
-                
+
                 model = modelInterpolator.interpolate( model, inheritedInterpolationValues, false );
 
                 checkModelBuildForExtensions( model, localRepository, lineageIterator.getArtifactRepositories() );
 
-                checkModulesForExtensions( modelPom, model, localRepository, originalRemoteRepositories, globalProfileManager, visitedModelIds );
-                
+                if ( !reactorFiles.contains( modelPom ) )
+                {
+                    getLogger().debug(
+                                       "POM: " + modelPom
+                                           + " is not in the current reactor. Its modules will not be scanned." );
+                }
+                else
+                {
+                    checkModulesForExtensions( modelPom, model, localRepository, originalRemoteRepositories,
+                                               globalProfileManager, visitedModelIds, reactorFiles );
+                }
+
                 Properties modelProps = model.getProperties();
                 if ( modelProps != null )
                 {
@@ -114,12 +143,13 @@
             }
 
             getLogger().debug( "Finished pre-scanning: " + pom + " for build extensions." );
-            
+
             extensionManager.registerWagons();
         }
         catch ( ModelInterpolationException e )
         {
-            throw new ExtensionScanningException( "Failed to interpolate model from: " + pom + " prior to scanning for extensions.", e );
+            throw new ExtensionScanningException( "Failed to interpolate model from: " + pom
+                + " prior to scanning for extensions.", e );
         }
         finally
         {
@@ -131,21 +161,21 @@
     private String createKey( Model model )
     {
         Parent parent = model.getParent();
-        
+
         String groupId = model.getGroupId();
         if ( groupId == null )
         {
             groupId = parent.getGroupId();
         }
-        
+
         String artifactId = model.getArtifactId();
-        
+
         return groupId + ":" + artifactId;
     }
 
     private void checkModulesForExtensions( File containingPom, Model model, ArtifactRepository localRepository,
                                             List originalRemoteRepositories, ProfileManager globalProfileManager,
-                                            List visitedModelIds )
+                                            List visitedModelIds, List reactorFiles )
         throws ExtensionScanningException
     {
         // FIXME: This gets a little sticky, because modules can be added by profiles that require
@@ -161,7 +191,7 @@
             {
                 // TODO: change this if we ever find a way to replace module definitions with g:a:v
                 String moduleSubpath = (String) it.next();
-                
+
                 getLogger().debug( "Scanning module: " + moduleSubpath );
 
                 File modulePomDirectory;
@@ -191,7 +221,7 @@
                 }
                 catch ( IOException e )
                 {
-                    throw new ExtensionScanningException( "Error getting canonical path for modulePomDirectory.",  e );
+                    throw new ExtensionScanningException( "Error getting canonical path for modulePomDirectory.", e );
                 }
 
                 if ( modulePomDirectory.isDirectory() )
@@ -206,11 +236,12 @@
                 {
                     getLogger().debug(
                                        "Cannot find POM for module: " + moduleSubpath
-                                           + "; continuing scan with next module. (Full path was: " + modulePomDirectory + ")" );
+                                           + "; continuing scan with next module. (Full path was: "
+                                           + modulePomDirectory + ")" );
                     continue;
                 }
 
-                scanInternal( modulePomDirectory, localRepository, globalProfileManager, visitedModelIds );
+                scanInternal( modulePomDirectory, localRepository, globalProfileManager, visitedModelIds, reactorFiles );
             }
         }
     }