maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject svn commit: r572366 - in /maven/components/trunk: maven-core/src/main/java/org/apache/maven/execution/ maven-embedder/ maven-embedder/src/main/java/org/apache/maven/embedder/ maven-embedder/src/test/java/org/apache/maven/cli/ maven-embedder/src/test/ja...
Date Mon, 03 Sep 2007 15:42:30 GMT
Author: jvanzyl
Date: Mon Sep  3 08:42:29 2007
New Revision: 572366

URL: http://svn.apache.org/viewvc?rev=572366&view=rev
Log:
o separating out the MavenEmbedderProjectWithExtensionReadingTest which shows that the artifacts
handlers must be loaded up-front
  in the readProjectWithDependencies method because it is not being done in the core unless
projects are executed. So Milos' assertion
  is correct. I'm now looking at a layered approach for project resolution and then execution
so that the readProjectWithDependencies
  (which is essential for IDE integration) will yield something that can be pushed into the
lifecycle executor. Right now there
  is much duplication which makes the IDE integration crappy.

  Another result of this is trying to create a simple IDE import model that gives back client
code the fully resolved, topo sorted
  set of projects which point to binary dependencies outside the reactor, and to source folders
inside the reactor. The result will
  be a useful model for all IDE integration, right now everyone is doing their own thing.
This model will need hooks for customization
  to take into account turning "workspace resolution" on/off and allow easy overriding of
this process.

o Fixed IT0035


Added:
    maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderProjectWithExtensionReadingTest.java
  (with props)
Modified:
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java
    maven/components/trunk/maven-embedder/pom.xml
    maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
    maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java
    maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
    maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
    maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java
    maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/project/MavenEmbedderProjectNotInRepositoryTest.java
    maven/components/trunk/maven-embedder/src/test/projects/no-artifact-in-repository-test/pom.xml

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java?rev=572366&r1=572365&r2=572366&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java
(original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java
Mon Sep  3 08:42:29 2007
@@ -78,7 +78,7 @@
         return exceptions;
     }
 
-    public void addException( Throwable t )
+    public MavenExecutionResult addException( Throwable t )
     {
         if ( exceptions == null )
         {
@@ -86,6 +86,8 @@
         }
 
         exceptions.add( t );
+
+        return this;
     }
 
     public boolean hasExceptions()

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java?rev=572366&r1=572365&r2=572366&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java
(original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java
Mon Sep  3 08:42:29 2007
@@ -48,7 +48,7 @@
     // - xmlpull parser exception
     List getExceptions();
 
-    void addException( Throwable t );
+    MavenExecutionResult addException( Throwable t );
 
     boolean hasExceptions();
 }

Modified: maven/components/trunk/maven-embedder/pom.xml
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/pom.xml?rev=572366&r1=572365&r2=572366&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/pom.xml (original)
+++ maven/components/trunk/maven-embedder/pom.xml Mon Sep  3 08:42:29 2007
@@ -228,5 +228,21 @@
         </plugins>
       </build>
     </profile>
+    <profile>
+      <!-- Single Test -->
+      <id>st</id>
+      <build>
+        <plugins>
+          <plugin>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <includes>
+                <include>**/MavenEmbedderTest.java</include>
+              </includes>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
   </profiles>
 </project>

Modified: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java?rev=572366&r1=572365&r2=572366&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
(original)
+++ maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
Mon Sep  3 08:42:29 2007
@@ -96,6 +96,7 @@
 import java.io.Reader;
 import java.io.Writer;
 import java.net.URL;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -422,32 +423,35 @@
     {
         MavenExecutionResult result = new DefaultMavenExecutionResult();
 
-        MavenProject project;
-
         try
         {
             request = populator.populateDefaults( request, this );
-            //mkleint: copied from DefaultLifecycleExecutor
 
-            project = readProject( new File( request.getPomFile() ) );
+            // This is necessary to make the MavenEmbedderProjectWithExtensionReadingTest
work which uses
+            // a custom type for a dependency like this:
+            //
+            // <dependency>
+            //   <groupId>junit</groupId>
+            //   <artifactId>junit</artifactId>
+            //   <version>3.8.1</version>
+            //   <scope>test</scope>
+            //   <type>mkleint</type>
+            // </dependency>
+            //
+            // If the artifact handlers are not loaded up-front then this dependency element
is not
+            // registered as an artifact and is not added to the classpath elements.
+
+            MavenProject project = readProject( new File( request.getPomFile() ) );
 
             Map handlers = findArtifactTypeHandlers( project );
 
-            //is this necessary in this context, I doubt it..mkleint
             artifactHandlerManager.addHandlers( handlers );
-
         }
         catch ( Exception e )
         {
-            // At this point real project building, and artifact resolution have not occured.
-
-            result.addException( e );
-
-            return result;
+            return result.addException( e );
         }
 
-        MavenProjectBuildingResult r = null;
-
         ReactorManager reactorManager = maven.createReactorManager( request, result );
 
         if ( result.hasExceptions() )
@@ -455,14 +459,11 @@
             return result;
         }
 
-        result.setTopologicallySortedProjects( reactorManager.getSortedProjects() );
-
-        // Now I should be able to pass this projects to the next request so that I don't
have to process
-        // any local projects again. And this logic is still too complicated.
+        MavenProjectBuildingResult projectBuildingResult = null;
 
         try
         {
-            r = mavenProjectBuilder.buildWithDependencies(
+            projectBuildingResult = mavenProjectBuilder.buildWithDependencies(
                 new File( request.getPomFile() ),
                 request.getLocalRepository(),
                 profileManager,
@@ -473,10 +474,28 @@
             result.addException( e );
         }
 
-        result.setProject( r.getProject() );
+        if ( reactorManager.hasMultipleProjects() )
+        {
+            result.setProject( projectBuildingResult.getProject() );
+
+            result.setTopologicallySortedProjects( reactorManager.getSortedProjects() );
+        }
+        else
+        {
+            result.setProject( projectBuildingResult.getProject() );
+
+            result.setTopologicallySortedProjects( Arrays.asList( new MavenProject[]{ projectBuildingResult.getProject()}
) );
+        }
 
-        result.setArtifactResolutionResult( r.getArtifactResolutionResult() );
+        result.setArtifactResolutionResult( projectBuildingResult.getArtifactResolutionResult()
);
 
+        // From this I could produce something that would help IDE integrators create importers:
+        // - topo sorted list of projects
+        // - binary dependencies
+        // - source dependencies (projects in the reactor)
+        //
+        // We could create a layer approach here. As to do anything you must resolve a projects
artifacts,
+        // and with that set you could then subsequently execute goals for each of those
project.
 
         return result;
     }

Modified: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java?rev=572366&r1=572365&r2=572366&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java
(original)
+++ maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java
Mon Sep  3 08:42:29 2007
@@ -37,18 +37,7 @@
 public abstract class AbstractConsoleDownloadMonitorTest
     extends TestCase
 {
-
-    private AbstractConsoleDownloadMonitor monitor;
-
-    public AbstractConsoleDownloadMonitorTest()
-    {
-        super();
-    }
-
-    public void setMonitor( AbstractConsoleDownloadMonitor monitor )
-    {
-        this.monitor = monitor;
-    }
+    protected AbstractConsoleDownloadMonitor monitor;
 
     public AbstractConsoleDownloadMonitor getMonitor()
     {

Modified: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java?rev=572366&r1=572365&r2=572366&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
(original)
+++ maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
Mon Sep  3 08:42:29 2007
@@ -31,8 +31,6 @@
     protected void setUp()
         throws Exception
     {
-        super.setMonitor( new BatchModeDownloadMonitor() );
-
-        super.setUp();
+        monitor = new BatchModeDownloadMonitor();
     }
 }

Modified: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java?rev=572366&r1=572365&r2=572366&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
(original)
+++ maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
Mon Sep  3 08:42:29 2007
@@ -21,19 +21,16 @@
 
 /**
  * Test for {@link ConsoleDownloadMonitor}
- * 
+ *
  * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
  * @version $Id$
  */
 public class ConsoleDownloadMonitorTest
     extends AbstractConsoleDownloadMonitorTest
 {
-
     protected void setUp()
         throws Exception
     {
-        super.setMonitor( new ConsoleDownloadMonitor() );
-
-        super.setUp();
+        monitor = new ConsoleDownloadMonitor();
     }
 }

Added: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderProjectWithExtensionReadingTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderProjectWithExtensionReadingTest.java?rev=572366&view=auto
==============================================================================
--- maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderProjectWithExtensionReadingTest.java
(added)
+++ maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderProjectWithExtensionReadingTest.java
Mon Sep  3 08:42:29 2007
@@ -0,0 +1,103 @@
+package org.apache.maven.embedder;
+
+import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.execution.DefaultMavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionResult;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.plugin.PluginManagerException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+
+import java.io.File;
+import java.util.Map;
+import java.util.HashMap;
+
+/** @author Jason van Zyl */
+public class MavenEmbedderProjectWithExtensionReadingTest
+    extends MavenEmbedderTest
+{
+    public void testProjectWithExtensionsReading()
+        throws Exception
+    {
+        MavenExecutionRequest request = new DefaultMavenExecutionRequest().setShowErrors(
true )
+            .setPomFile( new File( basedir, "src/test/resources/pom2.xml" ).getAbsolutePath()
);
+
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+
+        MavenExecutionResult result = new ExtendableMavenEmbedder( classLoader ).readProjectWithDependencies(
request );
+
+        assertNoExceptions( result );
+
+        // sources, test sources, and the junit jar..
+
+        assertEquals( 3, result.getProject().getTestClasspathElements().size() );
+    }
+
+    private class ExtendableMavenEmbedder
+        extends MavenEmbedder
+    {
+
+        public ExtendableMavenEmbedder( ClassLoader classLoader )
+            throws MavenEmbedderException
+        {
+            super( new DefaultConfiguration()
+                .setClassLoader( classLoader )
+                .setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() ) );
+        }
+
+        protected Map getPluginExtensionComponents( Plugin plugin )
+            throws PluginManagerException
+        {
+            Map toReturn = new HashMap();
+            MyArtifactHandler handler = new MyArtifactHandler();
+            toReturn.put( "mkleint", handler );
+            return toReturn;
+        }
+
+        protected void verifyPlugin( Plugin plugin,
+                                     MavenProject project )
+        {
+            //ignore don't want to actually verify in test
+        }
+    }
+
+    private class MyArtifactHandler
+        implements ArtifactHandler
+    {
+
+        public String getExtension()
+        {
+            return "jar";
+        }
+
+        public String getDirectory()
+        {
+            throw new UnsupportedOperationException( "Not supported yet." );
+        }
+
+        public String getClassifier()
+        {
+            return null;
+        }
+
+        public String getPackaging()
+        {
+            return "mkleint";
+        }
+
+        public boolean isIncludesDependencies()
+        {
+            return false;
+        }
+
+        public String getLanguage()
+        {
+            return "java";
+        }
+
+        public boolean isAddedToClasspath()
+        {
+            return true;
+        }
+    }    
+}

Propchange: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderProjectWithExtensionReadingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderProjectWithExtensionReadingTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java?rev=572366&r1=572365&r2=572366&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java
(original)
+++ maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java
Mon Sep  3 08:42:29 2007
@@ -29,7 +29,6 @@
 import org.apache.maven.model.Build;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Plugin;
-import org.apache.maven.plugin.PluginManagerException;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.settings.Profile;
 import org.apache.maven.settings.Repository;
@@ -46,18 +45,16 @@
 import java.io.IOException;
 import java.io.Writer;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 public class MavenEmbedderTest
     extends TestCase
 {
-    private String basedir;
+    protected String basedir;
 
-    private MavenEmbedder maven;
+    protected MavenEmbedder maven;
 
     protected void setUp()
         throws Exception
@@ -86,7 +83,7 @@
         maven.stop();
     }
 
-    private void assertNoExceptions( MavenExecutionResult result )
+    protected void assertNoExceptions( MavenExecutionResult result )
     {
         List exceptions = result.getExceptions();
         if ( ( exceptions == null ) || exceptions.isEmpty() )
@@ -330,22 +327,6 @@
         artifacts.iterator().next();
     }
 
-    public void testProjectWithExtensionsReading()
-        throws Exception
-    {
-        MavenExecutionRequest request = new DefaultMavenExecutionRequest().setShowErrors(
true )
-            .setPomFile( new File( basedir, "src/test/resources/pom2.xml" ).getAbsolutePath()
);
-
-        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-
-        MavenExecutionResult result = new ExtendableMavenEmbedder( classLoader ).readProjectWithDependencies(
request );
-
-        assertNoExceptions( result );
-
-        // sources, test sources, and the junit jar..
-        assertEquals( 3, result.getProject().getTestClasspathElements().size() );
-    }
-
     /*
     public void testProjectReadingWithDistributionStatus()
         throws Exception
@@ -532,73 +513,5 @@
     protected File getPomFile()
     {
         return new File( basedir, "src/test/resources/pom.xml" );
-    }
-
-    private class ExtendableMavenEmbedder
-        extends MavenEmbedder
-    {
-
-        public ExtendableMavenEmbedder( ClassLoader classLoader )
-            throws MavenEmbedderException
-        {
-            super( new DefaultConfiguration()
-                .setClassLoader( classLoader )
-                .setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() ) );
-        }
-
-        protected Map getPluginExtensionComponents( Plugin plugin )
-            throws PluginManagerException
-        {
-            Map toReturn = new HashMap();
-            MyArtifactHandler handler = new MyArtifactHandler();
-            toReturn.put( "mkleint", handler );
-            return toReturn;
-        }
-
-        protected void verifyPlugin( Plugin plugin,
-                                     MavenProject project )
-        {
-            //ignore don't want to actually verify in test
-        }
-    }
-
-    private class MyArtifactHandler
-        implements ArtifactHandler
-    {
-
-        public String getExtension()
-        {
-            return "jar";
-        }
-
-        public String getDirectory()
-        {
-            throw new UnsupportedOperationException( "Not supported yet." );
-        }
-
-        public String getClassifier()
-        {
-            return null;
-        }
-
-        public String getPackaging()
-        {
-            return "mkleint";
-        }
-
-        public boolean isIncludesDependencies()
-        {
-            return false;
-        }
-
-        public String getLanguage()
-        {
-            return "java";
-        }
-
-        public boolean isAddedToClasspath()
-        {
-            return true;
-        }
     }
 }

Modified: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/project/MavenEmbedderProjectNotInRepositoryTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/project/MavenEmbedderProjectNotInRepositoryTest.java?rev=572366&r1=572365&r2=572366&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/project/MavenEmbedderProjectNotInRepositoryTest.java
(original)
+++ maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/project/MavenEmbedderProjectNotInRepositoryTest.java
Mon Sep  3 08:42:29 2007
@@ -31,8 +31,8 @@
 import org.apache.maven.project.MavenProject;
 
 import java.io.File;
-import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 /**
  * We want to make sure when projects are newly created and have dependencies between them
that
@@ -60,22 +60,31 @@
 
         MavenEmbedder embedder = new MavenEmbedder( configuration );
 
-        File projectDirectory = new File( getBasedir(), "src/test/projects/no-artifact-in-repository-test"
);
+        File pom = new File( getBasedir(), "src/test/projects/no-artifact-in-repository-test"
);
 
         MavenExecutionRequest request = new DefaultMavenExecutionRequest()
-            .setBaseDirectory( projectDirectory );
+            .setBaseDirectory( pom );
 
         MavenExecutionResult result = embedder.readProjectWithDependencies( request );  
     
 
         List projects = result.getTopologicallySortedProjects();
 
-        /*
-        for ( Iterator i = projects.iterator(); i.hasNext(); )
-        {
-            MavenProject project = (MavenProject) i.next();
-
-            System.out.println( "project = " + project );
-        }
-        */
+        MavenProject project;
+
+        project = (MavenProject) projects.get( 0 );
+
+        assertEquals( "child-1", project.getArtifactId() );
+
+        project = (MavenProject) projects.get( 1 );
+
+        assertEquals( "child-2", project.getArtifactId() );
+
+        List deps = project.getDependencies();
+
+        assertEquals( 2, deps.size() );
+
+        project = (MavenProject) projects.get( 2 );
+
+        assertEquals( "parent", project.getArtifactId() );        
     }
 }

Modified: maven/components/trunk/maven-embedder/src/test/projects/no-artifact-in-repository-test/pom.xml
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/test/projects/no-artifact-in-repository-test/pom.xml?rev=572366&r1=572365&r2=572366&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/src/test/projects/no-artifact-in-repository-test/pom.xml
(original)
+++ maven/components/trunk/maven-embedder/src/test/projects/no-artifact-in-repository-test/pom.xml
Mon Sep  3 08:42:29 2007
@@ -2,7 +2,7 @@
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>test</groupId>
-  <artifactId>no-artifact-in-repository-test</artifactId>
+  <artifactId>parent</artifactId>
   <packaging>pom</packaging>
   <version>1.0-SNAPSHOT</version>
   <name>no-artifact-in-repository-test</name>



Mime
View raw message