maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r628876 - in /maven/plugins/trunk/maven-assembly-plugin/src: main/java/org/apache/maven/plugin/assembly/archive/task/ test/java/org/apache/maven/plugin/assembly/archive/task/ test/java/org/apache/maven/plugin/assembly/archive/task/testutils/
Date Mon, 18 Feb 2008 21:56:18 GMT
Author: jdcasey
Date: Mon Feb 18 13:56:15 2008
New Revision: 628876

URL: http://svn.apache.org/viewvc?rev=628876&view=rev
Log:
[MASSEMBLY-254] Add more protections against invalid POMs when working with DependencySets.

Modified:
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddDependencySetsTask.java
    maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/archive/task/AddDependencySetsTaskTest.java
    maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/archive/task/testutils/ArtifactMock.java
    maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/archive/task/testutils/MockAndControlForAddDependencySetsTask.java

Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddDependencySetsTask.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddDependencySetsTask.java?rev=628876&r1=628875&r2=628876&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddDependencySetsTask.java
(original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddDependencySetsTask.java
Mon Feb 18 13:56:15 2008
@@ -23,6 +23,7 @@
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.model.Model;
 import org.apache.maven.plugin.assembly.AssemblerConfigurationSource;
 import org.apache.maven.plugin.assembly.InvalidAssemblerConfigurationException;
 import org.apache.maven.plugin.assembly.archive.ArchiveCreationException;
@@ -140,12 +141,14 @@
             try
             {
                 depProject = projectBuilder.buildFromRepository( depArtifact, configSource.getRemoteRepositories(),
-                                                                 configSource.getLocalRepository(),
true );
+                                                                 configSource.getLocalRepository()
);
             }
             catch ( ProjectBuildingException e )
             {
-                throw new ArchiveCreationException( "Error retrieving POM of module-dependency:
" + depArtifact.getId()
-                    + "; Reason: " + e.getMessage(), e );
+                logger.debug( "Error retrieving POM of module-dependency: " + depArtifact.getId()
+                    + "; Reason: " + e.getMessage() + "\n\nBuilding stub project instance."
);
+
+                depProject = buildProjectStub( depArtifact );
             }
 
             if ( NON_ARCHIVE_DEPENDENCY_TYPES.contains( depArtifact.getType() ) )
@@ -174,6 +177,19 @@
                 task.execute( archiver, configSource );
             }
         }
+    }
+
+    private MavenProject buildProjectStub( Artifact depArtifact )
+    {
+        Model model = new Model();
+        model.setGroupId( depArtifact.getGroupId() );
+        model.setArtifactId( depArtifact.getArtifactId() );
+        model.setVersion( depArtifact.getBaseVersion() );
+        model.setPackaging( depArtifact.getType() );
+
+        model.setDescription( "Stub for " + depArtifact.getId() );
+
+        return new MavenProject( model );
     }
 
     protected Set resolveDependencyArtifacts( DependencySet dependencySet, AssemblerConfigurationSource
configSource )

Modified: maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/archive/task/AddDependencySetsTaskTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/archive/task/AddDependencySetsTaskTest.java?rev=628876&r1=628875&r2=628876&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/archive/task/AddDependencySetsTaskTest.java
(original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/archive/task/AddDependencySetsTaskTest.java
Mon Feb 18 13:56:15 2008
@@ -30,6 +30,7 @@
 import org.apache.maven.plugin.assembly.model.DependencySet;
 import org.apache.maven.plugin.assembly.testutils.MockManager;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingException;
 import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.logging.console.ConsoleLogger;
 
@@ -48,7 +49,8 @@
     private MockManager mockManager = new MockManager();
 
     public void testAddDependencySet_ShouldInterpolateDefaultOutputFileNameMapping()
-        throws AssemblyFormattingException, ArchiveCreationException, InvalidAssemblerConfigurationException,
IOException
+        throws AssemblyFormattingException, ArchiveCreationException,
+        InvalidAssemblerConfigurationException, IOException
     {
         String outDir = "tmp/";
         String mainAid = "main";
@@ -71,7 +73,8 @@
 
         MavenProject mainProject = new MavenProject( mainModel );
 
-        ArtifactMock mainArtifactMock = new ArtifactMock( mockManager, mainGid, mainAid,
mainVer, "jar", false );
+        ArtifactMock mainArtifactMock = new ArtifactMock( mockManager, mainGid, mainAid,
mainVer,
+                                                          "jar", false );
 
         mainProject.setArtifact( mainArtifactMock.getArtifact() );
 
@@ -83,13 +86,16 @@
 
         MavenProject depProject = new MavenProject( depModel );
 
-        ArtifactMock depArtifactMock = new ArtifactMock( mockManager, depGid, depAid, depVer,
depExt, false );
+        ArtifactMock depArtifactMock = new ArtifactMock( mockManager, depGid, depAid, depVer,
+                                                         depExt, false );
 
         File newFile = depArtifactMock.setNewFile();
 
         depProject.setArtifact( depArtifactMock.getArtifact() );
 
-        MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(
mockManager, mainProject );
+        MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(
+                                                                                        
            mockManager,
+                                                                                        
            mainProject );
 
         macTask.expectBuildFromRepository( depProject );
         macTask.expectCSGetFinalName( mainAid + "-" + mainVer );
@@ -104,7 +110,8 @@
 
         Logger logger = new ConsoleLogger( Logger.LEVEL_DEBUG, "test" );
 
-        AddDependencySetsTask task = new AddDependencySetsTask( Collections.singletonList(
ds ), depProject, macTask.projectBuilder,
+        AddDependencySetsTask task = new AddDependencySetsTask( Collections.singletonList(
ds ),
+                                                                depProject, macTask.projectBuilder,
                                                                 macTask.dependencyResolver,
logger );
 
         task.addDependencySet( ds, macTask.archiver, macTask.configSource );
@@ -113,11 +120,13 @@
     }
 
     public void testAddDependencySet_ShouldNotAddDependenciesWhenProjectHasNone()
-        throws AssemblyFormattingException, ArchiveCreationException, InvalidAssemblerConfigurationException
+        throws AssemblyFormattingException, ArchiveCreationException,
+        InvalidAssemblerConfigurationException
     {
         MavenProject project = new MavenProject( new Model() );
 
-        MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(
mockManager );
+        MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(
+                                                                                        
            mockManager );
 
         macTask.expectCSGetRepositories( null, null );
         macTask.expectResolveDependencies( Collections.EMPTY_SET );
@@ -129,7 +138,8 @@
 
         Logger logger = new ConsoleLogger( Logger.LEVEL_DEBUG, "test" );
 
-        AddDependencySetsTask task = new AddDependencySetsTask( Collections.singletonList(
ds ), project, macTask.projectBuilder,
+        AddDependencySetsTask task = new AddDependencySetsTask( Collections.singletonList(
ds ),
+                                                                project, macTask.projectBuilder,
                                                                 macTask.dependencyResolver,
logger );
 
         task.addDependencySet( ds, null, macTask.configSource );
@@ -137,20 +147,72 @@
         mockManager.verifyAll();
     }
 
+    // TODO: Find a better way of testing the project-stubbing behavior when a ProjectBuildingException
takes place.
+    public void testAddDependencySet_ShouldNotAddDependenciesWhenProjectIsStubbed()
+        throws AssemblyFormattingException, ArchiveCreationException,
+        InvalidAssemblerConfigurationException, IOException
+    {
+        MavenProject project = new MavenProject( new Model() );
+
+        ProjectBuildingException pbe = new ProjectBuildingException( "test", "Test error."
);
+
+        MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(
+                                                                                        
            mockManager );
+
+        String gid = "org.test";
+        String aid = "test-dep";
+        String version = "2.0-SNAPSHOT";
+        String type = "jar";
+
+        File file = new File( "dep-artifact.jar" );
+
+        ArtifactMock depMock = new ArtifactMock( mockManager, gid, aid, version, type, true
);
+        depMock.setBaseVersion( version );
+        depMock.setFile( file );
+
+        File destFile = new File( "assembly-dep-set.zip" );
+
+        macTask.expectGetDestFile( destFile );
+        macTask.expectBuildFromRepository( pbe );
+        macTask.expectCSGetRepositories( null, null );
+        macTask.expectCSGetFinalName( "final-name" );
+        macTask.expectResolveDependencies( Collections.singleton( depMock.getArtifact() )
);
+        macTask.expectAddFile( file, "out/" + aid + "-" + version + "." + type );
+
+        DependencySet ds = new DependencySet();
+        ds.setOutputDirectory( "/out" );
+
+        mockManager.replayAll();
+
+        Logger logger = new ConsoleLogger( Logger.LEVEL_DEBUG, "test" );
+
+        AddDependencySetsTask task = new AddDependencySetsTask( Collections.singletonList(
ds ),
+                                                                project, macTask.projectBuilder,
+                                                                macTask.dependencyResolver,
logger );
+
+        task.addDependencySet( ds, macTask.archiver, macTask.configSource );
+
+        mockManager.verifyAll();
+    }
+
     public void testAddDependencySet_ShouldAddOneDependencyFromProjectWithoutUnpacking()
-        throws AssemblyFormattingException, ArchiveCreationException, IOException, InvalidAssemblerConfigurationException
+        throws AssemblyFormattingException, ArchiveCreationException, IOException,
+        InvalidAssemblerConfigurationException
     {
         verifyOneDependencyAdded( "out", false );
     }
 
     public void testAddDependencySet_ShouldAddOneDependencyFromProjectUnpacked()
-        throws AssemblyFormattingException, ArchiveCreationException, IOException, InvalidAssemblerConfigurationException
+        throws AssemblyFormattingException, ArchiveCreationException, IOException,
+        InvalidAssemblerConfigurationException
     {
         verifyOneDependencyAdded( "out", true );
     }
 
-    private void verifyOneDependencyAdded( String outputLocation, boolean unpack )
-        throws AssemblyFormattingException, ArchiveCreationException, IOException, InvalidAssemblerConfigurationException
+    private void verifyOneDependencyAdded( String outputLocation,
+                                           boolean unpack )
+        throws AssemblyFormattingException, ArchiveCreationException, IOException,
+        InvalidAssemblerConfigurationException
     {
         MavenProject project = new MavenProject( new Model() );
 
@@ -163,9 +225,11 @@
         ds.setDirectoryMode( Integer.toString( 10, 8 ) );
         ds.setFileMode( Integer.toString( 10, 8 ) );
 
-        MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(
mockManager );
+        MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(
+                                                                                        
            mockManager );
 
-        ArtifactMock artifactMock = new ArtifactMock( mockManager, "group", "artifact", "version",
"jar", false );
+        ArtifactMock artifactMock = new ArtifactMock( mockManager, "group", "artifact", "version",
+                                                      "jar", false );
         File artifactFile = artifactMock.setNewFile();
 
         macTask.expectCSGetRepositories( null, null );
@@ -173,7 +237,10 @@
 
         if ( unpack )
         {
-            macTask.expectAddArchivedFileSet( artifactFile, outputLocation + "/", AddArtifactTask.DEFAULT_INCLUDES_ARRAY,
null );
+            macTask.expectAddArchivedFileSet( artifactFile,
+                                              outputLocation + "/",
+                                              AddArtifactTask.DEFAULT_INCLUDES_ARRAY,
+                                              null );
             macTask.expectModeChange( -1, -1, 10, 10, 2 );
         }
         else
@@ -190,7 +257,8 @@
 
         Logger logger = new ConsoleLogger( Logger.LEVEL_DEBUG, "test" );
 
-        AddDependencySetsTask task = new AddDependencySetsTask( Collections.singletonList(
ds ), project, macTask.projectBuilder,
+        AddDependencySetsTask task = new AddDependencySetsTask( Collections.singletonList(
ds ),
+                                                                project, macTask.projectBuilder,
                                                                 macTask.dependencyResolver,
logger );
 
         mockManager.replayAll();
@@ -205,9 +273,11 @@
     {
         MavenProject project = new MavenProject( new Model() );
 
-        MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(
mockManager );
+        MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(
+                                                                                        
            mockManager );
 
-        ArtifactMock artifactMock = new ArtifactMock( mockManager, "group", "artifact", "version",
"jar", false );
+        ArtifactMock artifactMock = new ArtifactMock( mockManager, "group", "artifact", "version",
+                                                      "jar", false );
 
         macTask.expectCSGetRepositories( null, null );
         macTask.expectResolveDependencies( Collections.singleton( artifactMock.getArtifact()
) );
@@ -220,8 +290,10 @@
 
         mockManager.replayAll();
 
-        AddDependencySetsTask task = new AddDependencySetsTask( Collections.singletonList(
dependencySet ), project,
-                                                                macTask.projectBuilder, macTask.dependencyResolver,
logger );
+        AddDependencySetsTask task = new AddDependencySetsTask(
+                                                                Collections.singletonList(
dependencySet ),
+                                                                project, macTask.projectBuilder,
+                                                                macTask.dependencyResolver,
logger );
 
         Set result = task.resolveDependencyArtifacts( dependencySet, macTask.configSource
);
 
@@ -237,7 +309,8 @@
     {
         MavenProject project = new MavenProject( new Model() );
 
-        MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(
mockManager );
+        MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(
+                                                                                        
            mockManager );
 
         Set artifacts = new HashSet();
 
@@ -272,7 +345,9 @@
 
         mockManager.replayAll();
 
-        AddDependencySetsTask task = new AddDependencySetsTask( Collections.singletonList(
dependencySet ), project, null,
+        AddDependencySetsTask task = new AddDependencySetsTask(
+                                                                Collections.singletonList(
dependencySet ),
+                                                                project, null,
                                                                 macTask.dependencyResolver,
logger );
 
         Set result = task.resolveDependencyArtifacts( dependencySet, macTask.configSource
);
@@ -289,7 +364,8 @@
     {
         MavenProject project = new MavenProject( new Model() );
 
-        MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(
mockManager );
+        MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(
+                                                                                        
            mockManager );
 
         Set artifacts = new HashSet();
 
@@ -323,7 +399,9 @@
 
         mockManager.replayAll();
 
-        AddDependencySetsTask task = new AddDependencySetsTask( Collections.singletonList(
dependencySet ), project, null,
+        AddDependencySetsTask task = new AddDependencySetsTask(
+                                                                Collections.singletonList(
dependencySet ),
+                                                                project, null,
                                                                 macTask.dependencyResolver,
logger );
 
         Set result = task.resolveDependencyArtifacts( dependencySet, macTask.configSource
);

Modified: maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/archive/task/testutils/ArtifactMock.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/archive/task/testutils/ArtifactMock.java?rev=628876&r1=628875&r2=628876&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/archive/task/testutils/ArtifactMock.java
(original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/archive/task/testutils/ArtifactMock.java
Mon Feb 18 13:56:15 2008
@@ -135,7 +135,7 @@
 
     public void setFile( File destination )
     {
-        if ( ( file != null ) && ( file == null ) )
+        if ( ( destination != null ) && ( file == null ) )
         {
             artifact.getFile();
             artifactCtl.setReturnValue( destination, MockControl.ZERO_OR_MORE );

Modified: maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/archive/task/testutils/MockAndControlForAddDependencySetsTask.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/archive/task/testutils/MockAndControlForAddDependencySetsTask.java?rev=628876&r1=628875&r2=628876&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/archive/task/testutils/MockAndControlForAddDependencySetsTask.java
(original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/archive/task/testutils/MockAndControlForAddDependencySetsTask.java
Mon Feb 18 13:56:15 2008
@@ -191,11 +191,25 @@
         configSourceCtl.setReturnValue( remoteRepos, MockControl.ONE_OR_MORE );
     }
 
+    public void expectBuildFromRepository( ProjectBuildingException error )
+    {
+        try
+        {
+            projectBuilder.buildFromRepository( null, null, null );
+            projectBuilderCtl.setMatcher( MockControl.ALWAYS_MATCHER );
+            projectBuilderCtl.setThrowable( error, MockControl.ONE_OR_MORE );
+        }
+        catch ( ProjectBuildingException e )
+        {
+            Assert.fail( "should never happen" );
+        }
+    }
+
     public void expectBuildFromRepository( MavenProject project )
     {
         try
         {
-            projectBuilder.buildFromRepository( null, null, null, true );
+            projectBuilder.buildFromRepository( null, null, null );
             projectBuilderCtl.setMatcher( MockControl.ALWAYS_MATCHER );
             projectBuilderCtl.setReturnValue( project, MockControl.ONE_OR_MORE );
         }



Mime
View raw message