Author: brianf Date: Wed Jul 18 19:35:53 2007 New Revision: 557464 URL: http://svn.apache.org/viewvc?view=rev&rev=557464 Log: applied patch from Damian Bradicich for MDEP-47
Added: maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/utils/markers/UnpackFileMarkerHandler.java 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/testUtils/stubs/StubUnpackFileMarkerHandler.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/AbstractDependencyMojo.java 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/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java 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=557464&r1=557463&r2=557464 ============================================================================== --- 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 Wed Jul 18 19:35:53 2007 @@ -147,22 +147,6 @@ */ 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; /** @@ -216,6 +200,12 @@ throw new MojoExecutionException( "Error copying artifact from " + artifact + " to " + destFile, e ); } } + + protected void unpack ( File file, File location ) + throws MojoExecutionException + { + unpack( file, location, null, null); + } /** * Unpacks the archive file. @@ -223,8 +213,12 @@ * @param file File to be unpacked. * @param location Location where to put the unpacked * files. + * @param includes Comma separated list of file patterns to include + * i.e. **\/*.xml, **\/*.properties + * @param excludes Comma separated list of file patterns to exclude + * i.e. **\/*.xml, **\/*.properties */ - protected void unpack ( File file, File location ) + protected void unpack ( File file, File location, String includes, String excludes ) throws MojoExecutionException { @@ -254,7 +248,7 @@ if ( StringUtils.isNotEmpty( includes ) ) { - selectors[0].setIncludes( this.includes.split( "," ) ); + selectors[0].setIncludes( includes.split( "," ) ); } unArchiver.setFileSelectors( selectors ); @@ -410,21 +404,5 @@ 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; } } 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=557464&r1=557463&r2=557464 ============================================================================== --- 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 Wed Jul 18 19:35:53 2007 @@ -45,8 +45,23 @@ public class UnpackDependenciesMojo extends AbstractFromDependenciesMojo { + /** + * A comma separated list of file patterns to include when unpacking the + * artifact. + * + * @parameter expression="${mdep.unpack.includes}" + */ + private String includes; /** + * A comma separated list of file patterns to exclude when unpacking the + * artifact. + * + * @parameter expression="${mdep.unpack.excludes}" + */ + private String excludes; + + /** * Main entry into mojo. This method gets the dependencies and iterates * through each one passing it to DependencyUtil.unpackFile(). * @@ -70,7 +85,7 @@ destDir = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerType, useSubDirectoryPerArtifact, useRepositoryLayout, stripVersion, outputDirectory, artifact ); - unpack( artifact.getFile(), destDir ); + unpack( artifact.getFile(), destDir, getIncludes(), getExcludes() ); DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler( artifact, this.markersDirectory ); handler.setMarker(); } @@ -87,5 +102,41 @@ { return new MarkerFileFilter( this.overWriteReleases, this.overWriteSnapshots, this.overWriteIfNewer, new DefaultFileMarkerHandler( this.markersDirectory ) ); + } + + /** + * @return Returns a comma separated list of excluded items + */ + public String getExcludes () + { + return this.excludes; + } + + /** + * @param excludes + * A comma separated list of items to exclude + * i.e. **\/*.xml, **\/*.properties + */ + public void setExcludes ( String excludes ) + { + this.excludes = excludes; + } + + /** + * @return Returns a comma seperated list of included items + */ + public String getIncludes() + { + return this.includes; + } + + /** + * @param includes + * A comma seperated list of items to inmclude + * i.e. **\/*.xml, **\/*.properties + */ + public void setIncludes ( String includes ) + { + this.includes = includes; } } 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=557464&r1=557463&r2=557464 ============================================================================== --- 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 Wed Jul 18 19:35:53 2007 @@ -100,6 +100,22 @@ * Artifact Item */ private Artifact artifact; + + /** + * 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; public ArtifactItem() { @@ -309,5 +325,41 @@ public void setArtifact( Artifact artifact ) { this.artifact = artifact; + } + + /** + * @return Returns a comma separated list of excluded items + */ + public String getExcludes () + { + return this.excludes; + } + + /** + * @param excludes + * A comma seperated list of items to exclude + * i.e. **\/*.xml, **\/*.properties + */ + public void setExcludes ( String excludes ) + { + this.excludes = excludes; + } + + /** + * @return Returns a comma seperated list of included items + */ + public String getIncludes() + { + return this.includes; + } + + /** + * @param includes + * A comma seperated list of items to inmclude + * i.e. **\/*.xml, **\/*.properties + */ + public void setIncludes ( String includes ) + { + this.includes = includes; } } 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=557464&r1=557463&r2=557464 ============================================================================== --- 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 Wed Jul 18 19:35:53 2007 @@ -28,10 +28,11 @@ import org.apache.maven.plugin.dependency.utils.DependencyUtil; import org.apache.maven.plugin.dependency.utils.filters.ArtifactItemFilter; import org.apache.maven.plugin.dependency.utils.filters.MarkerFileFilter; -import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler; import org.apache.maven.plugin.dependency.utils.markers.MarkerHandler; +import org.apache.maven.plugin.dependency.utils.markers.UnpackFileMarkerHandler; import org.apache.maven.plugin.logging.Log; import org.codehaus.plexus.archiver.manager.ArchiverManager; +import org.codehaus.plexus.util.StringUtils; /** * Goal that retrieves a list of artifacts from the repository and unpacks them @@ -53,6 +54,22 @@ * @parameter expression="${project.build.directory}/dependency-maven-plugin-markers" */ private File markersDirectory; + + /** + * A comma separated list of file patterns to include when unpacking the + * artifact. + * + * @parameter expression="${mdep.unpack.includes}" + */ + private String includes; + + /** + * A comma separated list of file patterns to exclude when unpacking the + * artifact. + * + * @parameter expression="${mdep.unpack.excludes}" + */ + private String excludes; /** * Main entry into mojo. This method gets the ArtifactItems and iterates @@ -100,18 +117,30 @@ private void unpackArtifact( ArtifactItem artifactItem ) throws MojoExecutionException { - Artifact artifact = artifactItem.getArtifact(); - - MarkerHandler handler = new DefaultFileMarkerHandler( artifact, this.markersDirectory ); + MarkerHandler handler = new UnpackFileMarkerHandler( artifactItem, this.markersDirectory ); - unpack( artifact.getFile(), artifactItem.getOutputDirectory() ); + //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 ); handler.setMarker(); } ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item ) { - MarkerHandler handler = new DefaultFileMarkerHandler( item.getArtifact(), this.markersDirectory ); + MarkerHandler handler = new UnpackFileMarkerHandler( item, this.markersDirectory ); return new MarkerFileFilter( this.isOverWriteReleases(), this.isOverWriteSnapshots(), this.isOverWriteIfNewer(), handler ); @@ -132,5 +161,42 @@ public void setMarkersDirectory( File theMarkersDirectory ) { this.markersDirectory = theMarkersDirectory; + } + + + /** + * @return Returns a comma separated list of excluded items + */ + public String getExcludes () + { + return this.excludes; + } + + /** + * @param excludes + * A comma seperated list of items to exclude + * i.e. **\/*.xml, **\/*.properties + */ + public void setExcludes ( String excludes ) + { + this.excludes = excludes; + } + + /** + * @return Returns a comma seperated list of included items + */ + public String getIncludes() + { + return this.includes; + } + + /** + * @param includes + * A comma seperated list of items to inmclude + * i.e. **\/*.xml, **\/*.properties + */ + public void setIncludes ( String includes ) + { + this.includes = includes; } } Added: maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/utils/markers/UnpackFileMarkerHandler.java URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/utils/markers/UnpackFileMarkerHandler.java?view=auto&rev=557464 ============================================================================== --- maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/utils/markers/UnpackFileMarkerHandler.java (added) +++ maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/main/java/org/apache/maven/plugin/dependency/utils/markers/UnpackFileMarkerHandler.java Wed Jul 18 19:35:53 2007 @@ -0,0 +1,95 @@ +package org.apache.maven.plugin.dependency.utils.markers; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; + +import org.apache.maven.plugin.dependency.fromConfiguration.ArtifactItem; +import org.codehaus.plexus.util.StringUtils; + +/** + * @author <a href="mailto:[EMAIL PROTECTED]">Damian Bradicich</a> + * @version $Id: UnpackFileMarkerHandler.java 552528 2007-07-02 16:12:47 +0000 (Mon, 02 Jul 2007) markh $ + */ +public class UnpackFileMarkerHandler extends DefaultFileMarkerHandler +{ + protected ArtifactItem artifactItem; + + public UnpackFileMarkerHandler( File markerFilesDirectory ) + { + super( markerFilesDirectory ); + } + + public UnpackFileMarkerHandler( ArtifactItem artifactItem, File markerFilesDirectory ) + { + this( markerFilesDirectory ); + setArtifactItem( artifactItem ); + } + + protected File getMarkerFile() + { + /** + * Build a hash of all include/exclude strings, to determine + * if an artifactItem has been unpacked using the include/exclude + * parameters, this will allow an artifact to be included multiple + * times with different include/exclude parameters + */ + File markerFile = null; + if ( this.artifactItem == null + || ( StringUtils.isEmpty( this.artifactItem.getIncludes() ) + && StringUtils.isEmpty( this.artifactItem.getExcludes() ) ) ) + { + markerFile = super.getMarkerFile(); + } + else + { + int includeExcludeHash = 0; + + if ( StringUtils.isNotEmpty( this.artifactItem.getIncludes() ) ) + { + includeExcludeHash += this.artifactItem.getIncludes().hashCode(); + } + + if ( StringUtils.isNotEmpty( this.artifactItem.getExcludes() ) ) + { + includeExcludeHash += this.artifactItem.getExcludes().hashCode(); + } + + markerFile = new File( this.markerFilesDirectory, this.artifact.getId().replace( ':', '-' ) + includeExcludeHash ); + } + + return markerFile; + } + + public void setArtifactItem( ArtifactItem artifactItem ) + { + this.artifactItem = artifactItem; + + if (this.artifactItem != null) + { + setArtifact( this.artifactItem.getArtifact() ); + } + } + + public ArtifactItem getArtifactItem( ) + { + return this.artifactItem; + } +} 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=557464&r1=557463&r2=557464 ============================================================================== --- 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 Wed Jul 18 19:35:53 2007 @@ -58,6 +58,12 @@ <destFileName>optional-new-name.jar</destFileName> </artifactItem> </artifactItems> + <includes> + <include>**/*.class</include> + </includes> + <excludes> + <exclude>**/*.properties</exclude> + </excludes> <outputDirectory>${project.build.directory}/wars</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>true</overWriteSnapshots> @@ -113,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=557464&r1=557463&r2=557464 ============================================================================== --- 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 Wed Jul 18 19:35:53 2007 @@ -48,6 +48,12 @@ <goal>unpack-dependencies</goal> </goals> <configuration> + <includes> + <include>**/*.class</include> + </includes> + <excludes> + <exclude>**/*.properties</exclude> + </excludes> <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>true</overWriteSnapshots> @@ -60,5 +66,6 @@ [...] </project> +---+ + Added: 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=auto&rev=557464 ============================================================================== --- maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackMojo.java (added) +++ maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackMojo.java Wed Jul 18 19:35:53 2007 @@ -0,0 +1,250 @@ +package org.apache.maven.plugin.dependency; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.dependency.fromConfiguration.ArtifactItem; +import org.apache.maven.plugin.dependency.fromConfiguration.UnpackMojo; +import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils; +import org.apache.maven.plugin.dependency.utils.markers.UnpackFileMarkerHandler; +import org.apache.maven.plugin.testing.stubs.StubArtifactCollector; +import org.apache.maven.plugin.testing.stubs.StubArtifactResolver; +import org.apache.maven.project.MavenProject; + +public class TestIncludeExcludeUnpackMojo + 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; + + UnpackMojo mojo; + + protected void setUp() + throws Exception + { + // required for mojo lookups to work + super.setUp( "unpack", true ); + + File testPom = new File( getBasedir(), "target/test-classes/unit/unpack-test/plugin-config.xml" ); + mojo = (UnpackMojo) lookupMojo( "unpack", testPom ); + mojo.setOutputDirectory( 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 ) ); + Artifact artifact = stubFactory.createArtifact( "test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null ); + ArtifactItem item = stubFactory.getArtifactItem( artifact ); + ArrayList list = new ArrayList( 1 ); + list.add( item ); + assertNotNull( mojo ); + assertNotNull( mojo.getProject() ); + MavenProject project = mojo.getProject(); + + mojo.setFactory( DependencyTestUtils.getArtifactFactory() ); + mojo.setResolver( new StubArtifactResolver( stubFactory, false, false ) ); + mojo.setMarkersDirectory( new File( this.testDir, "markers" ) ); + mojo.setArtifactCollector( new StubArtifactCollector() ); + mojo.setArtifactItems( list ); + } + + protected void tearDown() + { + super.tearDown(); + + mojo = null; + System.gc(); + } + + public void assertMarkerFiles( Collection items, boolean exist ) + { + Iterator iter = items.iterator(); + while ( iter.hasNext() ) + { + assertMarkerFile( exist, (ArtifactItem) iter.next() ); + } + } + + public void assertMarkerFile( boolean val, ArtifactItem item ) + { + UnpackFileMarkerHandler handle = new UnpackFileMarkerHandler( item, mojo.getMarkersDirectory() ); + try + { + assertEquals( val, handle.isMarkerSet() ); + } + catch ( MojoExecutionException e ) + { + fail( e.getLongMessage() ); + } + } + + 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); + } + + public void testIncludeArtifactItemOverride() + throws Exception + { + Artifact artifact = stubFactory.createArtifact( "test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null ); + ArtifactItem item = stubFactory.getArtifactItem( artifact ); + item.setIncludes("**/*"); + ArrayList list = new ArrayList( 1 ); + list.add( item ); + mojo.setArtifactItems( list ); + mojo.setIncludes( "**/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( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + public void testExcludeArtifactItemOverride() + throws Exception + { + Artifact artifact = stubFactory.createArtifact( "test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null ); + ArtifactItem item = stubFactory.getArtifactItem( artifact ); + item.setExcludes("**/*"); + ArrayList list = new ArrayList( 1 ); + list.add( item ); + mojo.setArtifactItems( list ); + mojo.setExcludes( "**/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( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + public void testIncludeArtifactItemMultipleMarker() + 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.setIncludes("**/test2" + UNPACKED_FILE_SUFFIX); + list.add( item ); + item = stubFactory.getArtifactItem( artifact ); + 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 ); + } +} Modified: maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java?view=diff&rev=557464&r1=557463&r2=557464 ============================================================================== --- maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java (original) +++ maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java Wed Jul 18 19:35:53 2007 @@ -32,7 +32,7 @@ import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase; import org.apache.maven.plugin.dependency.testUtils.DependencyArtifactStubFactory; import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils; -import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler; +import org.apache.maven.plugin.dependency.utils.markers.UnpackFileMarkerHandler; import org.apache.maven.plugin.testing.stubs.StubArtifactCollector; import org.apache.maven.plugin.testing.stubs.StubArtifactRepository; import org.apache.maven.plugin.testing.stubs.StubArtifactResolver; @@ -119,7 +119,7 @@ public void assertMarkerFile( boolean val, ArtifactItem item ) { - DefaultFileMarkerHandler handle = new DefaultFileMarkerHandler( item.getArtifact(), mojo.getMarkersDirectory() ); + UnpackFileMarkerHandler handle = new UnpackFileMarkerHandler( item, mojo.getMarkersDirectory() ); try { assertEquals( val, handle.isMarkerSet() ); Added: maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubUnpackFileMarkerHandler.java URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubUnpackFileMarkerHandler.java?view=auto&rev=557464 ============================================================================== --- maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubUnpackFileMarkerHandler.java (added) +++ maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubUnpackFileMarkerHandler.java Wed Jul 18 19:35:53 2007 @@ -0,0 +1,45 @@ +package org.apache.maven.plugin.dependency.testUtils.stubs; + +import java.io.File; + +import org.apache.maven.plugin.dependency.fromConfiguration.ArtifactItem; +import org.apache.maven.plugin.dependency.utils.markers.UnpackFileMarkerHandler; +import org.codehaus.plexus.util.StringUtils; + +public class StubUnpackFileMarkerHandler + extends UnpackFileMarkerHandler +{ + public StubUnpackFileMarkerHandler( ArtifactItem artifactItem, File markerFilesDirectory ) + { + super( artifactItem, markerFilesDirectory ); + } + + protected File getMarkerFile() + { + File markerFile = null; + if ( this.artifactItem == null + || ( StringUtils.isEmpty( this.artifactItem.getIncludes() ) + && StringUtils.isEmpty( this.artifactItem.getExcludes() ) ) ) + { + markerFile = new StubMarkerFile( this.markerFilesDirectory, this.artifact.getId().replace( ':', '-' ) + ".marker" ); + } + else + { + int includeExcludeHash = 0; + + if ( StringUtils.isNotEmpty( this.artifactItem.getIncludes() ) ) + { + includeExcludeHash += this.artifactItem.getIncludes().hashCode(); + } + + if ( StringUtils.isNotEmpty( this.artifactItem.getExcludes() ) ) + { + includeExcludeHash += this.artifactItem.getExcludes().hashCode(); + } + + markerFile = new StubMarkerFile( this.markerFilesDirectory, this.artifact.getId().replace( ':', '-' ) + includeExcludeHash ); + } + + return markerFile; + } +} Added: 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=auto&rev=557464 ============================================================================== --- maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestUnpackMarkerFileHandler.java (added) +++ maven/plugins/branches/maven-dependency-plugin-MDEP-47/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestUnpackMarkerFileHandler.java Wed Jul 18 19:35:53 2007 @@ -0,0 +1,259 @@ +package org.apache.maven.plugin.dependency.utils.markers; + +import java.io.File; +import java.io.IOException; +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.DependencyTestUtils; +import org.apache.maven.plugin.dependency.testUtils.stubs.StubUnpackFileMarkerHandler; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugin.testing.SilentLog; + +public class TestUnpackMarkerFileHandler + extends TestCase +{ + List artifactItems = new ArrayList(); + + Log log = new SilentLog(); + + File outputFolder; + + 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 ); + artifactItem = new ArtifactItem( artifact ); + artifactItem.setIncludes( "**/*.xml" ); + artifactItems.add( artifactItem ); + artifact = new DefaultArtifact( "test", "3", vr, Artifact.SCOPE_TEST, "sources", "", ah, false ); + artifactItem = new ArtifactItem( artifact ); + artifactItem.setExcludes( "**/*.class" ); + artifactItems.add( artifactItem ); + artifact = new DefaultArtifact( "test", "4", vr, Artifact.SCOPE_RUNTIME, "zip", "", ah, false ); + artifactItem = new ArtifactItem( artifact ); + artifactItem.setIncludes( "**/*.xml" ); + artifactItem.setExcludes( "**/*.class" ); + artifactItems.add( artifactItem ); + + outputFolder = new File( "target/markers/" ); + DependencyTestUtils.removeDirectory( this.outputFolder ); + assertFalse( outputFolder.exists() ); + } + + protected void tearDown() + throws IOException + { + DependencyTestUtils.removeDirectory( this.outputFolder ); + } + + /** + * + * Assert that default functionallity still exists + * + */ + + public void testSetMarker() + throws MojoExecutionException + { + UnpackFileMarkerHandler handler = new UnpackFileMarkerHandler( (ArtifactItem) artifactItems.get( 0 ), + this.outputFolder ); + assertFalse( handler.isMarkerSet() ); + handler.setMarker(); + assertTrue( handler.isMarkerSet() ); + handler.clearMarker(); + assertFalse( handler.isMarkerSet() ); + + handler.setMarker(); + assertTrue( handler.isMarkerSet() ); + handler.setMarker(); + assertTrue( handler.isMarkerSet() ); + + handler.clearMarker(); + assertFalse( handler.isMarkerSet() ); + handler.clearMarker(); + assertFalse( handler.isMarkerSet() ); + } + + public void testMarkerFile() + throws MojoExecutionException, IOException + { + UnpackFileMarkerHandler handler = new UnpackFileMarkerHandler( (ArtifactItem) artifactItems.get( 0 ), + this.outputFolder ); + + File handle = handler.getMarkerFile(); + assertFalse( handle.exists() ); + assertFalse( handler.isMarkerSet() ); + + handler.setMarker(); + assertTrue( handler.isMarkerSet() ); + assertTrue( handle.exists() ); + + handle.delete(); + assertFalse( handler.isMarkerSet() ); + + handle.createNewFile(); + assertTrue( handler.isMarkerSet() ); + + handler.clearMarker(); + assertFalse( handle.exists() ); + } + + public void testMarkerTimeStamp() + throws MojoExecutionException, IOException, InterruptedException + { + File theFile = new File( outputFolder, "theFile.jar" ); + outputFolder.mkdirs(); + theFile.createNewFile(); + ArtifactItem theArtifactItem = (ArtifactItem) artifactItems.get( 0 ); + Artifact theArtifact = theArtifactItem.getArtifact(); + theArtifact.setFile( theFile ); + UnpackFileMarkerHandler handler = new UnpackFileMarkerHandler( theArtifactItem, this.outputFolder ); + assertFalse( handler.isMarkerSet() ); + // if the marker is not set, assume it is infinately older than the + // artifact. + assertTrue( handler.isMarkerOlder( theArtifact ) ); + handler.setMarker(); + assertFalse( handler.isMarkerOlder( theArtifact ) ); + + theFile.setLastModified( theFile.lastModified() + 60000 ); + assertTrue( handler.isMarkerOlder( theArtifact ) ); + + theFile.delete(); + handler.clearMarker(); + assertFalse( handler.isMarkerSet() ); + } + + public void testMarkerFileException() + { + // this stub wraps the file with an object to throw exceptions + StubUnpackFileMarkerHandler handler = new StubUnpackFileMarkerHandler( (ArtifactItem) artifactItems.get( 0 ), + this.outputFolder ); + try + { + handler.setMarker(); + fail( "Expected an Exception here" ); + } + catch ( MojoExecutionException e ) + { + + } + } + + public void testGetterSetter() + { + UnpackFileMarkerHandler handler = new UnpackFileMarkerHandler( null, null ); + assertTrue( handler.getArtifactItem() == null ); + assertTrue( handler.getArtifact() == null ); + handler.setArtifactItem( (ArtifactItem) artifactItems.get( 0 ) ); + assertSame( artifactItems.get( 0 ), handler.getArtifactItem() ); + assertSame( ((ArtifactItem) artifactItems.get( 0 )).getArtifact(), handler.getArtifact() ); + + assertTrue( handler.getMarkerFilesDirectory() == null ); + handler.setMarkerFilesDirectory( outputFolder ); + assertSame( outputFolder, handler.getMarkerFilesDirectory() ); + } + + public void testNullParent() + throws MojoExecutionException + { + // the parent isn't set so this will create the marker in the local + // folder. We must clear the + // marker to avoid leaving test droppings in root. + UnpackFileMarkerHandler handler = new UnpackFileMarkerHandler( null, null ); + handler.setArtifactItem( (ArtifactItem) artifactItems.get( 0 ) ); + handler.setMarker(); + assertTrue( handler.isMarkerSet() ); + handler.clearMarker(); + assertFalse( handler.isMarkerSet() ); + } + + public void testIncludesMarker() + throws MojoExecutionException, IOException + { + UnpackFileMarkerHandler handler = new UnpackFileMarkerHandler( (ArtifactItem) artifactItems.get( 1 ), outputFolder ); + File handle = handler.getMarkerFile(); + assertFalse( handle.exists() ); + assertFalse( handler.isMarkerSet() ); + + handler.setMarker(); + assertTrue( handler.isMarkerSet() ); + assertTrue( handle.exists() ); + String hashCode = "" + ( 0 + "**/*.xml".hashCode() ); + assertTrue( handle.getName().indexOf( hashCode ) > -1 ); + + handle.delete(); + assertFalse( handler.isMarkerSet() ); + + handle.createNewFile(); + assertTrue( handler.isMarkerSet() ); + + handler.clearMarker(); + assertFalse( handle.exists() ); + } + + public void testExcludesMarker() + throws MojoExecutionException, IOException + { + UnpackFileMarkerHandler handler = new UnpackFileMarkerHandler( (ArtifactItem) artifactItems.get( 2 ), outputFolder ); + File handle = handler.getMarkerFile(); + assertFalse( handle.exists() ); + assertFalse( handler.isMarkerSet() ); + + handler.setMarker(); + assertTrue( handler.isMarkerSet() ); + assertTrue( handle.exists() ); + String hashCode = "" + ( 0 + "**/*.class".hashCode() ); + assertTrue( handle.getName().indexOf( hashCode ) > -1 ); + + handle.delete(); + assertFalse( handler.isMarkerSet() ); + + handle.createNewFile(); + assertTrue( handler.isMarkerSet() ); + + handler.clearMarker(); + assertFalse( handle.exists() ); + } + + public void testIncludesExcludesMarker() + throws MojoExecutionException, IOException + { + UnpackFileMarkerHandler handler = new UnpackFileMarkerHandler( (ArtifactItem) artifactItems.get( 3 ), outputFolder ); + File handle = handler.getMarkerFile(); + assertFalse( handle.exists() ); + assertFalse( handler.isMarkerSet() ); + + handler.setMarker(); + assertTrue( handler.isMarkerSet() ); + assertTrue( handle.exists() ); + String hashCode = "" + ( 0 + "**/*.class".hashCode() + "**/*.xml".hashCode() ); + assertTrue( handle.getName().indexOf( hashCode ) > -1 ); + + handle.delete(); + assertFalse( handler.isMarkerSet() ); + + handle.createNewFile(); + assertTrue( handler.isMarkerSet() ); + + handler.clearMarker(); + assertFalse( handle.exists() ); + } +} +