You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2007/07/17 04:07:38 UTC

svn commit: r556791 - in /maven/plugins/branches/maven-dependency-plugin-MDEP-47: ./ src/main/java/org/apache/maven/plugin/dependency/ src/test/java/org/apache/maven/plugin/dependency/ src/test/resources/unit/unpack-dependencies-test/

Author: brianf
Date: Mon Jul 16 19:07:37 2007
New Revision: 556791

URL: http://svn.apache.org/viewvc?view=rev&rev=556791
Log:
applied patch from Damian Bradicich for MDEP-47

Added:
    maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackDependenciesMojo.java
    maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/resources/unit/unpack-dependencies-test/test.zip   (with props)
Modified:
    maven/plugins/branches/maven-dependency-plugin-MDEP-47/pom.xml
    maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java

Modified: maven/plugins/branches/maven-dependency-plugin-MDEP-47/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-47/pom.xml?view=diff&rev=556791&r1=556790&r2=556791
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-47/pom.xml (original)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-47/pom.xml Mon Jul 16 19:07:37 2007
@@ -77,6 +77,29 @@
 	<build>
 		<plugins>
 			<plugin>
+				<artifactId>maven-enforcer-plugin</artifactId>
+				<version>1.0-alpha-3</version>
+				<executions>
+					<execution>
+						<goals>
+							<goal>enforce</goal>
+						</goals>
+						<id>ensure-no-container-api</id>
+						<configuration>
+							<rules>
+								<bannedDependencies>
+									<excludes>
+										<exclude>org.codehaus.plexus:plexus-component-api</exclude>
+									</excludes>
+									<message>The new containers are not supported. You probably added a dependency that is missing the exclusions.</message>
+								</bannedDependencies>
+							</rules>  
+							<fail>true</fail>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
 				<groupId>org.codehaus.mojo</groupId>
 				<artifactId>cobertura-maven-plugin</artifactId>
 				<version>2.0</version>
@@ -145,17 +168,17 @@
 			<artifactId>plexus-archiver</artifactId>
 			<version>1.0-alpha-9-SNAPSHOT</version>
 			<exclusions>
-              <exclusion>
-                 <groupId>org.codehaus.plexus</groupId>
-                 <artifactId>plexus-container-default</artifactId>
-              </exclusion>
-              <exclusion>
-                 <groupId>org.codehaus.plexus</groupId>
-                 <artifactId>plexus-component-api</artifactId>
-              </exclusion>			  
-            </exclusions>
+				<exclusion>
+					<groupId>org.codehaus.plexus</groupId>
+					<artifactId>plexus-container-default</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>org.codehaus.plexus</groupId>
+					<artifactId>plexus-component-api</artifactId>
+				</exclusion>			  
+			</exclusions>
 		</dependency>
-<!--		<dependency>
+		<!--		<dependency>
 			<groupId>org.codehaus.plexus</groupId>
 			<artifactId>plexus-component-api</artifactId>
 			<version>1.0-alpha-9</version>
@@ -182,25 +205,40 @@
 			<version>1.0-alpha-9-stable-1</version>
 		</dependency>
 		<dependency>
-		    <groupId>org.apache.maven.shared</groupId>
-		    <artifactId>maven-dependency-analyzer</artifactId>
-		    <version>1.0-alpha-3-SNAPSHOT</version>
+			<groupId>org.apache.maven.shared</groupId>
+			<artifactId>maven-dependency-analyzer</artifactId>
+			<version>1.0-alpha-3-SNAPSHOT</version>
 		</dependency>
 		<dependency>
 			<groupId>org.apache.maven.shared</groupId>
 			<artifactId>maven-dependency-tree</artifactId>
 			<version>1.0</version>
 		</dependency>
+		<dependency>
+			<groupId>org.codehaus.plexus</groupId>
+			<artifactId>plexus-io</artifactId>
+			<version>1.0-alpha-1</version>
+			<exclusions>
+				<exclusion>
+					<groupId>org.codehaus.plexus</groupId>
+					<artifactId>plexus-container-default</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>org.codehaus.plexus</groupId>
+					<artifactId>plexus-component-api</artifactId>
+				</exclusion>			  
+			</exclusions>
+		</dependency>
 	</dependencies>
 
-  <!-- TODO: remove when plexus-archiver is released -->
-  <repositories>
-    <repository>
-      <id>codehaus.snapshots</id>
-      <url>http://snapshots.repository.codehaus.org/</url>
-      <releases>
-        <enabled>false</enabled>
-      </releases>
-    </repository>
-  </repositories>
+	<!-- TODO: remove when plexus-archiver is released -->
+	<repositories>
+		<repository>
+			<id>codehaus.snapshots</id>
+			<url>http://snapshots.repository.codehaus.org/</url>
+			<releases>
+				<enabled>false</enabled>
+			</releases>
+		</repository>
+	</repositories>
 </project>

Modified: maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java?view=diff&rev=556791&r1=556790&r2=556791
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java (original)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java Mon Jul 16 19:07:37 2007
@@ -34,12 +34,15 @@
 import org.codehaus.plexus.archiver.UnArchiver;
 import org.codehaus.plexus.archiver.manager.ArchiverManager;
 import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
+import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.ReflectionUtils;
+import org.codehaus.plexus.util.StringUtils;
 
 /**
  * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
- * @version $Id$
+ * @version $Id: AbstractDependencyMojo.java 552528
+ *          2007-07-02 16:12:47Z markh $
  */
 public abstract class AbstractDependencyMojo
     extends AbstractMojo
@@ -129,7 +132,8 @@
      * 
      * @optional
      * @since 2.0
-     * @parameter expression="${silent}" default-value="false"
+     * @parameter expression="${silent}"
+     *            default-value="false"
      */
     public boolean silent;
 
@@ -143,12 +147,28 @@
      */
     protected boolean outputAbsoluteArtifactFilename;
 
+    /**
+     * A set of file patterns to include when unpacking the
+     * artifact.
+     * 
+     * @parameter expression="${mdep.unpack.includes}"
+     */
+    private String includes;
+
+    /**
+     * A set of file patterns to exclude when unpacking the
+     * artifact.
+     * 
+     * @parameter expression="${mdep.unpack.excludes}"
+     */
+    private String excludes;
+
     private Log log;
 
     /**
      * @return Returns the log.
      */
-    public Log getLog()
+    public Log getLog ()
     {
         if ( silent )
         {
@@ -165,7 +185,7 @@
     /**
      * @return Returns the archiverManager.
      */
-    public ArchiverManager getArchiverManager()
+    public ArchiverManager getArchiverManager ()
     {
         return this.archiverManager;
     }
@@ -173,15 +193,13 @@
     /**
      * Does the actual copy of the file and logging.
      * 
-     * @param artifact
-     *            represents the file to copy.
-     * @param destFile
-     *            file name of destination file.
+     * @param artifact represents the file to copy.
+     * @param destFile file name of destination file.
      * 
-     * @throws MojoExecutionException
-     *             with a message if an error occurs.
+     * @throws MojoExecutionException with a message if an
+     *             error occurs.
      */
-    protected void copyFile( File artifact, File destFile )
+    protected void copyFile ( File artifact, File destFile )
         throws MojoExecutionException
     {
         Log theLog = this.getLog();
@@ -202,12 +220,11 @@
     /**
      * Unpacks the archive file.
      * 
-     * @param file
-     *            File to be unpacked.
-     * @param location
-     *            Location where to put the unpacked files.
+     * @param file File to be unpacked.
+     * @param location Location where to put the unpacked
+     *            files.
      */
-    protected void unpack( File file, File location )
+    protected void unpack ( File file, File location )
         throws MojoExecutionException
     {
 
@@ -223,6 +240,25 @@
 
             unArchiver.setDestDirectory( location );
 
+            if ( StringUtils.isNotEmpty( excludes ) || StringUtils.isNotEmpty( includes ) )
+            {
+                // Create the selectors that will filter
+                // based on include/exclude parameters
+                // MDEP-47
+                IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() };
+
+                if ( StringUtils.isNotEmpty( excludes ) )
+                {
+                    selectors[0].setExcludes( excludes.split( "," ) );
+                }
+
+                if ( StringUtils.isNotEmpty( includes ) )
+                {
+                    selectors[0].setIncludes( this.includes.split( "," ) );
+                }
+
+                unArchiver.setFileSelectors( selectors );
+            }
             if ( this.silent )
             {
                 silenceUnarchiver( unArchiver );
@@ -242,9 +278,10 @@
         }
     }
 
-    private void silenceUnarchiver( UnArchiver unArchiver )
+    private void silenceUnarchiver ( UnArchiver unArchiver )
     {
-        // dangerous but handle any errors. It's the only way to silence the
+        // dangerous but handle any errors. It's the only
+        // way to silence the
         // unArchiver.
         try
         {
@@ -256,23 +293,23 @@
         }
         catch ( Exception e )
         {
-            // was a nice try. Don't bother logging because the log is silent.
+            // was a nice try. Don't bother logging because
+            // the log is silent.
         }
     }
 
     /**
      * @return Returns the factory.
      */
-    public org.apache.maven.artifact.factory.ArtifactFactory getFactory()
+    public org.apache.maven.artifact.factory.ArtifactFactory getFactory ()
     {
         return this.factory;
     }
 
     /**
-     * @param factory
-     *            The factory to set.
+     * @param factory The factory to set.
      */
-    public void setFactory( org.apache.maven.artifact.factory.ArtifactFactory factory )
+    public void setFactory ( org.apache.maven.artifact.factory.ArtifactFactory factory )
     {
         this.factory = factory;
     }
@@ -280,7 +317,7 @@
     /**
      * @return Returns the project.
      */
-    public MavenProject getProject()
+    public MavenProject getProject ()
     {
         return this.project;
     }
@@ -288,16 +325,15 @@
     /**
      * @return Returns the local.
      */
-    public org.apache.maven.artifact.repository.ArtifactRepository getLocal()
+    public org.apache.maven.artifact.repository.ArtifactRepository getLocal ()
     {
         return this.local;
     }
 
     /**
-     * @param local
-     *            The local to set.
+     * @param local The local to set.
      */
-    public void setLocal( org.apache.maven.artifact.repository.ArtifactRepository local )
+    public void setLocal ( org.apache.maven.artifact.repository.ArtifactRepository local )
     {
         this.local = local;
     }
@@ -305,16 +341,15 @@
     /**
      * @return Returns the remoteRepos.
      */
-    public java.util.List getRemoteRepos()
+    public java.util.List getRemoteRepos ()
     {
         return this.remoteRepos;
     }
 
     /**
-     * @param remoteRepos
-     *            The remoteRepos to set.
+     * @param remoteRepos The remoteRepos to set.
      */
-    public void setRemoteRepos( java.util.List remoteRepos )
+    public void setRemoteRepos ( java.util.List remoteRepos )
     {
         this.remoteRepos = remoteRepos;
     }
@@ -322,25 +357,23 @@
     /**
      * @return Returns the resolver.
      */
-    public org.apache.maven.artifact.resolver.ArtifactResolver getResolver()
+    public org.apache.maven.artifact.resolver.ArtifactResolver getResolver ()
     {
         return this.resolver;
     }
 
     /**
-     * @param resolver
-     *            The resolver to set.
+     * @param resolver The resolver to set.
      */
-    public void setResolver( org.apache.maven.artifact.resolver.ArtifactResolver resolver )
+    public void setResolver ( org.apache.maven.artifact.resolver.ArtifactResolver resolver )
     {
         this.resolver = resolver;
     }
 
     /**
-     * @param archiverManager
-     *            The archiverManager to set.
+     * @param archiverManager The archiverManager to set.
      */
-    public void setArchiverManager( ArchiverManager archiverManager )
+    public void setArchiverManager ( ArchiverManager archiverManager )
     {
         this.archiverManager = archiverManager;
     }
@@ -348,16 +381,16 @@
     /**
      * @return Returns the artifactCollector.
      */
-    public ArtifactCollector getArtifactCollector()
+    public ArtifactCollector getArtifactCollector ()
     {
         return this.artifactCollector;
     }
 
     /**
-     * @param theArtifactCollector
-     *            The artifactCollector to set.
+     * @param theArtifactCollector The artifactCollector to
+     *            set.
      */
-    public void setArtifactCollector( ArtifactCollector theArtifactCollector )
+    public void setArtifactCollector ( ArtifactCollector theArtifactCollector )
     {
         this.artifactCollector = theArtifactCollector;
     }
@@ -365,17 +398,33 @@
     /**
      * @return Returns the artifactMetadataSource.
      */
-    public ArtifactMetadataSource getArtifactMetadataSource()
+    public ArtifactMetadataSource getArtifactMetadataSource ()
     {
         return this.artifactMetadataSource;
     }
 
     /**
-     * @param theArtifactMetadataSource
-     *            The artifactMetadataSource to set.
+     * @param theArtifactMetadataSource The
+     *            artifactMetadataSource to set.
      */
-    public void setArtifactMetadataSource( ArtifactMetadataSource theArtifactMetadataSource )
+    public void setArtifactMetadataSource ( ArtifactMetadataSource theArtifactMetadataSource )
     {
         this.artifactMetadataSource = theArtifactMetadataSource;
+    }
+
+    /**
+     * @param excludes The items to exclude
+     */
+    public void setExcludes ( String excludes )
+    {
+        this.excludes = excludes;
+    }
+
+    /**
+     * @param includes The items to include
+     */
+    public void setIncludes ( String includes )
+    {
+        this.includes = includes;
     }
 }

Added: maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackDependenciesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackDependenciesMojo.java?view=auto&rev=556791
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackDependenciesMojo.java (added)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackDependenciesMojo.java Mon Jul 16 19:07:37 2007
@@ -0,0 +1,164 @@
+package org.apache.maven.plugin.dependency;
+
+import java.io.File;
+import java.util.Set;
+
+import org.apache.maven.project.MavenProject;
+
+public class TestIncludeExcludeUnpackDependenciesMojo 
+	extends AbstractDependencyMojoTestCase
+{
+	private final String PACKED_FILE = "test.zip";
+	
+	private final String UNPACKED_FILE_PREFIX = "test";
+	private final String UNPACKED_FILE_SUFFIX = ".txt";
+	
+	private final String PACKED_FILE_PATH = "target/test-classes/unit/unpack-dependencies-test/" + PACKED_FILE;
+	
+	UnpackDependenciesMojo mojo;
+
+    protected void setUp()
+        throws Exception
+    {
+    	// required for mojo lookups to work
+        super.setUp( "unpack-dependencies", true );
+
+        File testPom = new File( getBasedir(), "target/test-classes/unit/unpack-dependencies-test/plugin-config.xml" );
+        mojo = (UnpackDependenciesMojo) lookupMojo( "unpack-dependencies", testPom );
+        mojo.outputDirectory = new File( this.testDir, "outputDirectory" );
+        // mojo.silent = true;
+
+        // it needs to get the archivermanager
+        //stubFactory.setUnpackableFile( mojo.getArchiverManager() );
+        // i'm using one file repeatedly to archive so I can test the name
+        // programmatically.
+        stubFactory.setSrcFile( new File( getBasedir() + File.separatorChar + PACKED_FILE_PATH ) );
+
+        assertNotNull( mojo );
+        assertNotNull( mojo.getProject() );
+        MavenProject project = mojo.getProject();
+
+        Set artifacts = this.stubFactory.getScopedArtifacts();
+        Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
+        artifacts.addAll( directArtifacts );
+
+        project.setArtifacts( artifacts );
+        project.setDependencyArtifacts( directArtifacts );
+        mojo.markersDirectory = new File( this.testDir, "markers" );
+
+    }
+    
+    protected void tearDown()
+    {
+        super.tearDown();
+        
+        mojo = null;
+        System.gc();
+    }
+    
+    private void assertUnpacked(boolean unpacked, String fileName)
+    {
+    	File destFile = new File( mojo.getOutputDirectory().getAbsolutePath() , fileName );    	
+    	assertEquals(unpacked, destFile.exists());
+    }
+    
+    /**
+     * This test will validate that only the 1 and 11 files get unpacked
+     * @throws Exception
+     */
+    public void testUnpackIncludesManyFiles()
+		throws Exception
+	{
+    	mojo.setIncludes("**/*1" + UNPACKED_FILE_SUFFIX);
+    	mojo.execute();
+    	assertUnpacked(true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX);
+	}
+    
+    /**
+     * This test will verify only the 2 file gets unpacked
+     * @throws Exception
+     */
+    public void testUnpackIncludesSingleFile()
+    	throws Exception
+	{
+    	mojo.setIncludes("**/test2" + UNPACKED_FILE_SUFFIX);
+    	mojo.execute();
+    	assertUnpacked(false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX);
+	}
+    
+    /**
+     * This test will verify all files get unpacked
+     * @throws Exception
+     */
+    public void testUnpackIncludesAllFiles()
+    	throws Exception
+	{
+    	mojo.setIncludes("**/*");
+    	mojo.execute();
+    	assertUnpacked(true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX);
+	}
+    
+    /**
+     * This test will validate that only the 2 and 3 files get unpacked
+     * @throws Exception
+     */
+    public void testUnpackExcludesManyFiles()
+		throws Exception
+	{
+    	mojo.setExcludes("**/*1" + UNPACKED_FILE_SUFFIX);
+    	mojo.execute();
+    	assertUnpacked(false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX);
+	}
+    
+    /**
+     * This test will verify only the 1, 11 & 3 files get unpacked
+     * @throws Exception
+     */
+    public void testUnpackExcludesSingleFile()
+    	throws Exception
+	{
+    	mojo.setExcludes("**/test2" + UNPACKED_FILE_SUFFIX);
+    	mojo.execute();
+    	assertUnpacked(true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX);
+	}
+    
+    /**
+     * This test will verify no files get unpacked
+     * @throws Exception
+     */
+    public void testUnpackExcludesAllFiles()
+    	throws Exception
+	{
+    	mojo.setExcludes("**/*");
+    	mojo.execute();
+    	assertUnpacked(false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX);
+	}
+    
+    public void testNoIncludeExcludes()
+    	throws Exception
+	{
+    	mojo.execute();
+    	assertUnpacked(true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX);
+    	assertUnpacked(true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX);
+	}
+}

Added: maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/resources/unit/unpack-dependencies-test/test.zip
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/resources/unit/unpack-dependencies-test/test.zip?view=auto&rev=556791
==============================================================================
Binary file - no diff available.

Propchange: maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/resources/unit/unpack-dependencies-test/test.zip
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream