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/20 02:55:06 UTC

svn commit: r557829 - in /maven/plugins/branches/maven-dependency-plugin-MDEP-47/src: main/java/org/apache/maven/plugin/dependency/ main/java/org/apache/maven/plugin/dependency/fromConfiguration/ site/apt/ site/apt/examples/ test/java/org/apache/maven/...

Author: brianf
Date: Thu Jul 19 17:55:05 2007
New Revision: 557829

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

Modified:
    maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/UnpackDependenciesMojo.java
    maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java
    maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java
    maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/site/apt/examples/unpacking-artifacts.apt
    maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/site/apt/examples/unpacking-project-dependencies.apt
    maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/site/apt/usage.apt
    maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackMojo.java
    maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestUnpackMarkerFileHandler.java

Modified: maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/UnpackDependenciesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/UnpackDependenciesMojo.java?view=diff&rev=557829&r1=557828&r2=557829
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/UnpackDependenciesMojo.java (original)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/UnpackDependenciesMojo.java Thu Jul 19 17:55:05 2007
@@ -47,7 +47,7 @@
 {
 	/**
      * A comma separated list of file patterns to include when unpacking the
-     * artifact.
+     * artifact.  i.e.  **\/*.xml,**\/*.properties
      * 
      * @parameter expression="${mdep.unpack.includes}"
      */
@@ -55,7 +55,7 @@
 
     /**
      * A comma separated list of file patterns to exclude when unpacking the
-     * artifact.
+     * artifact.  i.e.  **\/*.xml,**\/*.properties
      * 
      * @parameter expression="${mdep.unpack.excludes}"
      */

Modified: maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java?view=diff&rev=557829&r1=557828&r2=557829
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java (original)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java Thu Jul 19 17:55:05 2007
@@ -104,16 +104,12 @@
     /**
      * A comma separated list of file patterns to include when unpacking the
      * artifact.
-     * 
-     * @parameter expression="${mdep.artifact.item.unpack.includes}"
      */
     private String includes;
 
     /**
      * A comma separated list of file patterns to exclude when unpacking the
      * artifact.
-     * 
-     * @parameter expression="${mdep.artifact.item.unpack.excludes}"
      */
     private String excludes;
 

Modified: maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java?view=diff&rev=557829&r1=557828&r2=557829
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java (original)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java Thu Jul 19 17:55:05 2007
@@ -57,15 +57,15 @@
     
     /**
      * A comma separated list of file patterns to include when unpacking the
-     * artifact.
-     * 
+     * artifact.  i.e.  **\/*.xml,**\/*.properties
+     *  
      * @parameter expression="${mdep.unpack.includes}"
      */
     private String includes;
 
     /**
      * A comma separated list of file patterns to exclude when unpacking the
-     * artifact.
+     * artifact.  i.e.  **\/*.xml,**\/*.properties
      * 
      * @parameter expression="${mdep.unpack.excludes}"
      */
@@ -118,22 +118,8 @@
         throws MojoExecutionException
     {
         MarkerHandler handler = new UnpackFileMarkerHandler( artifactItem, this.markersDirectory );
-
-        //Allow the artifactItem includes/excludes to override the global includes/excludes
-        String includes = getIncludes();
-        String excludes = getExcludes();
-        
-        if ( StringUtils.isNotEmpty(artifactItem.getIncludes()) )
-        {
-        	includes = artifactItem.getIncludes();
-        }
         
-        if ( StringUtils.isNotEmpty(artifactItem.getExcludes()) )
-        {
-        	excludes = artifactItem.getExcludes();
-        }
-        
-        unpack( artifactItem.getArtifact().getFile(), artifactItem.getOutputDirectory(), includes, excludes );
+        unpack( artifactItem.getArtifact().getFile(), artifactItem.getOutputDirectory(), artifactItem.getIncludes(), artifactItem.getExcludes() );
         handler.setMarker();
 
     }
@@ -145,6 +131,26 @@
         return new MarkerFileFilter( this.isOverWriteReleases(), this.isOverWriteSnapshots(),
                                      this.isOverWriteIfNewer(), handler );
     }
+    
+    protected ArrayList getProcessedArtifactItems(boolean removeVersion)
+    	throws MojoExecutionException 
+    {
+    	ArrayList items = super.getProcessedArtifactItems( removeVersion );
+    	Iterator iter = items.iterator();
+        while ( iter.hasNext() )
+        {
+            ArtifactItem artifactItem = (ArtifactItem) iter.next();
+            if ( StringUtils.isEmpty(artifactItem.getIncludes()) )
+            {
+                artifactItem.setIncludes( getIncludes() );
+            }
+            if ( StringUtils.isEmpty(artifactItem.getExcludes()) )
+            {
+                artifactItem.setExcludes( getExcludes() );
+            }
+        }
+    	return items;
+    }
 
     /**
      * @return Returns the markersDirectory.
@@ -174,7 +180,7 @@
     
     /**
      * @param excludes 
-     * 			A comma seperated list of items to exclude 
+     * 			A comma separated list of items to exclude 
      * 			i.e.  **\/*.xml, **\/*.properties
      */
     public void setExcludes ( String excludes )
@@ -183,7 +189,7 @@
     }
     
     /**
-     * @return Returns a comma seperated list of included items
+     * @return Returns a comma separated list of included items
      */
     public String getIncludes()
     {
@@ -192,7 +198,7 @@
 
     /**
      * @param includes
-     * 			A comma seperated list of items to inmclude 
+     * 			A comma separated list of items to include 
      * 			i.e.  **\/*.xml, **\/*.properties
      */
     public void setIncludes ( String includes )

Modified: maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/site/apt/examples/unpacking-artifacts.apt
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/site/apt/examples/unpacking-artifacts.apt?view=diff&rev=557829&r1=557828&r2=557829
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/site/apt/examples/unpacking-artifacts.apt (original)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/site/apt/examples/unpacking-artifacts.apt Thu Jul 19 17:55:05 2007
@@ -56,15 +56,13 @@
                    <overWrite>false</overWrite>
                    <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
                    <destFileName>optional-new-name.jar</destFileName>
+                   <includes>**/*.class,**/*.xml</includes>
+                   <excludes>**/*test.class</excludes>
                  </artifactItem>
                </artifactItems>
-               <includes>
-	             <include>**/*.class</include>
-	           </includes>
-	           <excludes>
-	             <exclude>**/*.properties</exclude>
-	           </excludes>
-               <outputDirectory>${project.build.directory}/wars</outputDirectory>
+               <includes>**/*.java</includes>
+               <excludes>**/*.properties</excludes>
+	           <outputDirectory>${project.build.directory}/wars</outputDirectory>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>true</overWriteSnapshots>
              </configuration>
@@ -109,6 +107,8 @@
               <overWrite>[ true or false ]</overWrite>
               <outputDirectory>[ output directory ]</outputDirectory>
               <destFileName>[ filename ]</destFileName>
+              <includes>[ comma seperated list of file filters ]</includes>
+              <excludes>[ comma seperated list of file filters ]</excludes>
             </artifactItem>
           </artifactItems>
           <!-- other configurations here -->
@@ -119,6 +119,7 @@
   [...]
 </project>
 +---+	
+
 
 
 

Modified: maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/site/apt/examples/unpacking-project-dependencies.apt
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/site/apt/examples/unpacking-project-dependencies.apt?view=diff&rev=557829&r1=557828&r2=557829
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/site/apt/examples/unpacking-project-dependencies.apt (original)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/site/apt/examples/unpacking-project-dependencies.apt Thu Jul 19 17:55:05 2007
@@ -48,12 +48,8 @@
               <goal>unpack-dependencies</goal>
             </goals>
             <configuration>
-              <includes>
-                <include>**/*.class</include>
-              </includes>
-              <excludes>
-                <exclude>**/*.properties</exclude>
-              </excludes>
+              <includes>**/*.class</includes>
+              <excludes>**/*.properties</excludes>
               <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
               <overWriteReleases>false</overWriteReleases>
               <overWriteSnapshots>true</overWriteSnapshots>
@@ -66,6 +62,7 @@
   [...]
 </project>
 +---+
+
 
 
 

Modified: maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/site/apt/usage.apt
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/site/apt/usage.apt?view=diff&rev=557829&r1=557828&r2=557829
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/site/apt/usage.apt (original)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/site/apt/usage.apt Thu Jul 19 17:55:05 2007
@@ -204,6 +204,9 @@
    specified location. Multiple artifacts can be defined in a single execution.
    A default outputDirectory is specified but can be overriden for each
    ArtifactItem by setting the optional outputDirectory field. 
+   
+   A single artifact can be unpacked multiple times if different include/exclude parameters
+   are defined for each artifactItem
 
    See the {{#Overwrite Rules}} section for rules about how overwriting is handled.
 
@@ -266,6 +269,8 @@
               <overWrite>[ true or false ]</overWrite>
               <outputDirectory>[ output directory ]</outputDirectory>
               <destFileName>[ filename ]</destFileName>
+              <includes>[ comma seperated list of file filters ]</includes>
+              <excludes>[ comma seperated list of file filters ]</excludes>
             </artifactItem>
           </artifactItems>
           <!-- other configurations here -->
@@ -309,6 +314,8 @@
    resolve artifacts with the classifer and type. For example:
    <<<mvn dependency:unpack-dependencies -Dclassifer=sources>>> will try to find
    the sources for all dependencies and unpack them.
+   
+   Filters can be applied to include or exclude certain file or filesets as necessary
    
       	Also included is the ability to include or exclude by type (war, jar etc), scope (runtime, test, etc), classifier (jdk14, sources, etc), groupId, artifactId, or a combination of them. 
       	

Modified: maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackMojo.java?view=diff&rev=557829&r1=557828&r2=557829
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackMojo.java (original)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackMojo.java Thu Jul 19 17:55:05 2007
@@ -234,9 +234,11 @@
     	ArrayList list = new ArrayList();
     	Artifact artifact = stubFactory.createArtifact( "test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null );
         ArtifactItem item = stubFactory.getArtifactItem( artifact );
+        item.setOverWrite("false");
         item.setIncludes("**/test2" + UNPACKED_FILE_SUFFIX);        
         list.add( item );
         item = stubFactory.getArtifactItem( artifact );
+        item.setOverWrite("false");
         item.setIncludes("**/test3" + UNPACKED_FILE_SUFFIX);        
         list.add( item );
         mojo.setArtifactItems( list ); 
@@ -246,5 +248,41 @@
     	assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX );
     	assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX );
     	assertMarkerFiles( mojo.getArtifactItems(), true );
+	}
+    
+    public void testIncludeArtifactItemMultipleExecutions()
+    	throws Exception
+	{
+    	ArrayList list = new ArrayList();
+    	Artifact artifact = stubFactory.createArtifact( "test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null );
+        ArtifactItem item = stubFactory.getArtifactItem( artifact );
+        item.setOverWrite("false");
+        item.setIncludes("**/test2" + UNPACKED_FILE_SUFFIX);        
+        list.add( item );
+        item = stubFactory.getArtifactItem( artifact );
+        item.setOverWrite("false");
+        item.setIncludes("**/test3" + UNPACKED_FILE_SUFFIX);        
+        list.add( item );
+        mojo.setArtifactItems( list ); 
+    	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 );
+    	assertMarkerFiles( mojo.getArtifactItems(), true );
+    	    	
+    	//Now run again and make sure the extracted files haven't gotten overwritten
+    	File destFile2 = new File( mojo.getOutputDirectory().getAbsolutePath() , UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX );
+    	File destFile3 = new File( mojo.getOutputDirectory().getAbsolutePath() , UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX );
+    	long time = System.currentTimeMillis();
+        time = time - ( time % 1000 );
+        destFile2.setLastModified( time );
+        destFile3.setLastModified( time );
+        assertEquals( time, destFile2.lastModified() );
+        assertEquals( time, destFile3.lastModified() );
+        Thread.sleep( 100 );
+    	mojo.execute();
+    	assertEquals( time, destFile2.lastModified() );
+        assertEquals( time, destFile3.lastModified() );
 	}
 }

Modified: maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestUnpackMarkerFileHandler.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestUnpackMarkerFileHandler.java?view=diff&rev=557829&r1=557828&r2=557829
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestUnpackMarkerFileHandler.java (original)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestUnpackMarkerFileHandler.java Thu Jul 19 17:55:05 2007
@@ -5,48 +5,52 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import junit.framework.TestCase;
-
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DefaultArtifact;
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
-import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.dependency.fromConfiguration.ArtifactItem;
+import org.apache.maven.plugin.dependency.testUtils.DependencyArtifactStubFactory;
 import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
 import org.apache.maven.plugin.dependency.testUtils.stubs.StubUnpackFileMarkerHandler;
 import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.apache.maven.plugin.testing.SilentLog;
 
 public class TestUnpackMarkerFileHandler
-	extends TestCase
+	extends AbstractMojoTestCase
 {
 	List artifactItems = new ArrayList();
 
     Log log = new SilentLog();
 
     File outputFolder;
+    
+    protected File testDir;
+    
+    protected DependencyArtifactStubFactory stubFactory;
 
     protected void setUp()
         throws Exception
     {
         super.setUp();
-
-        ArtifactHandler ah = new DefaultArtifactHandler();
-        VersionRange vr = VersionRange.createFromVersion( "1.1" );
-        Artifact artifact = new DefaultArtifact( "test", "1", vr, Artifact.SCOPE_COMPILE, "jar", "", ah, false );
-        ArtifactItem artifactItem = new ArtifactItem( artifact );
-        artifactItems.add( artifactItem );
-        artifact = new DefaultArtifact( "test", "2", vr, Artifact.SCOPE_PROVIDED, "war", "", ah, false );
+        
+        testDir = new File( getBasedir(), "target" + File.separatorChar + "unit-tests" + File.separatorChar
+                + "unpack-markers" + File.separatorChar );
+        DependencyTestUtils.removeDirectory( testDir );
+        assertFalse( testDir.exists() );
+
+        stubFactory = new DependencyArtifactStubFactory( this.testDir, false );
+        Artifact artifact = stubFactory.createArtifact( "test", "test", "1" );
+        ArtifactItem artifactItem = stubFactory.getArtifactItem( artifact );
+        artifactItems.add( stubFactory.getArtifactItem( stubFactory.createArtifact( "test", "test", "1" ) ) );
+        artifact = stubFactory.createArtifact("test2", "test2", "2");
         artifactItem = new ArtifactItem( artifact );
         artifactItem.setIncludes( "**/*.xml" );
         artifactItems.add( artifactItem );
-        artifact = new DefaultArtifact( "test", "3", vr, Artifact.SCOPE_TEST, "sources", "", ah, false );
+        artifact = stubFactory.createArtifact("test3", "test3", "3");
         artifactItem = new ArtifactItem( artifact );
         artifactItem.setExcludes( "**/*.class" );
         artifactItems.add( artifactItem );
-        artifact = new DefaultArtifact( "test", "4", vr, Artifact.SCOPE_RUNTIME, "zip", "", ah, false );
+        artifact = stubFactory.createArtifact("test4", "test4", "4");
         artifactItem = new ArtifactItem( artifact );
         artifactItem.setIncludes( "**/*.xml" );
         artifactItem.setExcludes( "**/*.class" );
@@ -256,4 +260,5 @@
 	    assertFalse( handle.exists() );
 	}
 }
+