Author: dantran Date: Tue Dec 29 23:33:02 2009 New Revision: 894515 URL: http://svn.apache.org/viewvc?rev=894515&view=rev Log: MDEP-179:Add ability to use an alternate repository at copy and unpack mojo's execution time
Added: maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/ maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/invoker.properties (with props) maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/pom.xml (with props) maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/validate.bsh (with props) Modified: maven/plugins/trunk/maven-dependency-plugin/src/it/copy/pom.xml maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractResolveMojo.java maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/BuildClasspathMojo.java maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolvePluginsMojo.java maven/plugins/trunk/maven-dependency-plugin/src/site/apt/examples/copying-artifacts.apt.vm maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java Added: maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/invoker.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/invoker.properties?rev=894515&view=auto ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/invoker.properties (added) +++ maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/invoker.properties Tue Dec 29 23:33:02 2009 @@ -0,0 +1 @@ +invoker.goals = clean package Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/invoker.properties ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/pom.xml?rev=894515&view=auto ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/pom.xml (added) +++ maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/pom.xml Tue Dec 29 23:33:02 2009 @@ -0,0 +1,81 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + ~ 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. + --> + +<project> + + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.its.dependency</groupId> + <artifactId>test</artifactId> + <version>1.0-SNAPSHOT</version> + + <name>Test</name> + <description> + Test dependency:copy and dependency:unpack with alternate local repository + </description> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <build> + <plugins> + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + <version>@project.version@</version> + <executions> + <execution> + <id>copy</id> + <goals> + <goal>copy</goal> + </goals> + <configuration> + <alternateLocalRepository>${project.build.directory}/repo</alternateLocalRepository> + <artifactItems> + <artifactItem> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + </artifactItem> + </artifactItems> + </configuration> + </execution> + <execution> + <id>unpack</id> + <goals> + <goal>unpack</goal> + </goals> + <configuration> + <alternateLocalRepository>${project.build.directory}/repo</alternateLocalRepository> + <artifactItems> + <artifactItem> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + </artifactItem> + </artifactItems> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/validate.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/validate.bsh?rev=894515&view=auto ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/validate.bsh (added) +++ maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/validate.bsh Tue Dec 29 23:33:02 2009 @@ -0,0 +1,26 @@ +import java.io.*; + + +File file = new File( basedir, "target/dependency/junit-3.8.1.jar" ); + +System.out.println( "Checking for existence of " + file ); +if ( !file.isFile() ) +{ + throw new Exception( "Missing " + file ); +} + +file = new File( basedir, "target/dependency/junit" ); +System.out.println( "Checking for existence of " + file ); +if ( !file.isDirectory() ) +{ + throw new Exception( "Missing " + file ); +} + +file = new File( basedir, "target/repo/junit/junit/3.8.1/junit-3.8.1.jar" ); +System.out.println( "Checking for existence of " + file ); +if ( !file.isFile() ) +{ + throw new Exception( "Missing " + file ); +} + +return true; Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/copy-and-unpack-with-alternate-local-repo/validate.bsh ------------------------------------------------------------------------------ svn:eol-style = native Modified: maven/plugins/trunk/maven-dependency-plugin/src/it/copy/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/copy/pom.xml?rev=894515&r1=894514&r2=894515&view=diff ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/it/copy/pom.xml (original) +++ maven/plugins/trunk/maven-dependency-plugin/src/it/copy/pom.xml Tue Dec 29 23:33:02 2009 @@ -29,7 +29,7 @@ <name>Test</name> <description> - Test dependency:copy-dependencies + Test dependency:copy </description> <properties> Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java?rev=894515&r1=894514&r2=894515&view=diff ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java (original) +++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java Tue Dec 29 23:33:02 2009 @@ -308,7 +308,7 @@ artifacts = status.getResolvedDependencies(); // resolve the rest of the artifacts - ArtifactsResolver artifactsResolver = new DefaultArtifactsResolver( this.resolver, this.local, + ArtifactsResolver artifactsResolver = new DefaultArtifactsResolver( this.resolver, this.getLocal(), this.remoteRepos, stopOnFailure ); resolvedArtifacts = artifactsResolver.resolve( artifacts, getLog() ); Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java?rev=894515&r1=894514&r2=894515&view=diff ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java (original) +++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java Tue Dec 29 23:33:02 2009 @@ -85,7 +85,7 @@ * @readonly * @required */ - protected org.apache.maven.artifact.repository.ArtifactRepository local; + private org.apache.maven.artifact.repository.ArtifactRepository local; /** * List of Remote Repositories used by the resolver @@ -318,7 +318,7 @@ /** * @return Returns the local. */ - public org.apache.maven.artifact.repository.ArtifactRepository getLocal () + protected org.apache.maven.artifact.repository.ArtifactRepository getLocal () { return this.local; } Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractResolveMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractResolveMojo.java?rev=894515&r1=894514&r2=894515&view=diff ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractResolveMojo.java (original) +++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractResolveMojo.java Tue Dec 29 23:33:02 2009 @@ -77,7 +77,7 @@ { Artifact artifact = (Artifact) i.next(); // resolve the new artifact - this.resolver.resolve( artifact, this.remoteRepos, this.local ); + this.resolver.resolve( artifact, this.remoteRepos, this.getLocal() ); } return artifacts; } @@ -102,7 +102,7 @@ Artifact pomArtifact = this.factory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact .getVersion(), "", "pom" ); - MavenProject pomProject = mavenProjectBuilder.buildFromRepository( pomArtifact, this.remoteRepos, this.local ); + MavenProject pomProject = mavenProjectBuilder.buildFromRepository( pomArtifact, this.remoteRepos, this.getLocal() ); return resolveDependencyArtifacts( pomProject ); } Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/BuildClasspathMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/BuildClasspathMojo.java?rev=894515&r1=894514&r2=894515&view=diff ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/BuildClasspathMojo.java (original) +++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/BuildClasspathMojo.java Tue Dec 29 23:33:02 2009 @@ -282,7 +282,7 @@ // substitute the property for the local repo path to make the classpath file portable. if ( StringUtils.isNotEmpty( localRepoProperty ) ) { - file = StringUtils.replace( file, local.getBasedir(), localRepoProperty ); + file = StringUtils.replace( file, getLocal().getBasedir(), localRepoProperty ); } sb.append( file ); } Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java?rev=894515&r1=894514&r2=894515&view=diff ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java (original) +++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java Tue Dec 29 23:33:02 2009 @@ -222,7 +222,7 @@ // Resolve the pom artifact using repos try { - this.resolver.resolve( pomArtifact, this.remoteRepos, this.local ); + this.resolver.resolve( pomArtifact, this.remoteRepos, this.getLocal() ); } catch ( Exception e ) { Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java?rev=894515&r1=894514&r2=894515&view=diff ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java (original) +++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java Tue Dec 29 23:33:02 2009 @@ -25,6 +25,9 @@ import java.util.List; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; @@ -97,6 +100,21 @@ * @since 1.0 */ private ArrayList artifactItems; + + /** + * Internal local repository + */ + private ArtifactRepository localRepository; + + /** + * Path to an alternate local repository during plugin's execution. + * Set this value to a location under your project's target directory so that + * downloaded artifacts are removed as part of the build. + * @parameter + * @since 2.2 + */ + private File alternateLocalRepository; + abstract ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item ); @@ -239,7 +257,7 @@ * iter.next(); artifact = node.getArtifact(); } */ - resolver.resolve( artifact, remoteRepos, local ); + resolver.resolve( artifact, remoteRepos, getLocal() ); } catch ( ArtifactResolutionException e ) { @@ -347,6 +365,32 @@ return map; }*/ + + /** + * @return Returns the local. + */ + protected ArtifactRepository getLocal () + { + if ( this.localRepository != null ) + { + return this.localRepository; + } + + if ( this.alternateLocalRepository != null ) + { + //create a temporary local repository with unique id + this.localRepository = new DefaultArtifactRepository( Long.toHexString( System.currentTimeMillis() ), "file://" + this.alternateLocalRepository.getAbsolutePath(), new DefaultRepositoryLayout() ); + + this.getLog().debug( "Execution local repository is at: " + this.localRepository.getBasedir() ); + + return this.localRepository; + } + + this.localRepository = super.getLocal(); + + return this.localRepository; + } + /** * @return Returns the artifactItems. */ @@ -431,4 +475,9 @@ { this.overWriteSnapshots = theOverWriteSnapshots; } + + public void setAlternateLocalRepository( File alternateLocalRepository ) + { + this.alternateLocalRepository = alternateLocalRepository; + } } Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolvePluginsMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolvePluginsMojo.java?rev=894515&r1=894514&r2=894515&view=diff ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolvePluginsMojo.java (original) +++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolvePluginsMojo.java Tue Dec 29 23:33:02 2009 @@ -152,7 +152,7 @@ { Artifact artifact = (Artifact) i.next(); // resolve the new artifact - this.resolver.resolve( artifact, this.remotePluginRepositories, this.local ); + this.resolver.resolve( artifact, this.remotePluginRepositories, this.getLocal() ); } return artifacts; } Modified: maven/plugins/trunk/maven-dependency-plugin/src/site/apt/examples/copying-artifacts.apt.vm URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/site/apt/examples/copying-artifacts.apt.vm?rev=894515&r1=894514&r2=894515&view=diff ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/site/apt/examples/copying-artifacts.apt.vm (original) +++ maven/plugins/trunk/maven-dependency-plugin/src/site/apt/examples/copying-artifacts.apt.vm Tue Dec 29 23:33:02 2009 @@ -115,6 +115,50 @@ </project> +---+ +{Using an alternate local repository}: + + <<dependency:copy>> always downloads artifacts to default local repository first, and then + copy the artifacts to the desired locations. For large size unique snapshot artifacts, the downloads can quickly + fill up default local repository, and therefore local disk, after many executions. + To clean up the downloaded artifacts as part the build, set <alternateLocalRepotority>'s value + to a location in your project's target directory. + + This use case also applies to <<dependency:unpack>> goal. + ++---+ +<project> + [...] + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <version>${project.version}</version> + <executions> + <execution> + <id>copy-with-alternalte-repo</id> + <phase>install</phase> + <goals> + <goal>copy</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + [...] + </artifactItem> + [...] + </artifactItems> + <alternateLocalRepository>\${project.build.directory}/localrepo</alternateLocalRepository> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + [...] +</project> ++---+ + {Copying from the command line}: If you intend to configure this mojo for execution on the command line using: Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java?rev=894515&r1=894514&r2=894515&view=diff ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java (original) +++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java Tue Dec 29 23:33:02 2009 @@ -479,7 +479,7 @@ // init classifier things mojo.factory = DependencyTestUtils.getArtifactFactory(); mojo.resolver = new StubArtifactResolver( null, are, anfe ); - mojo.local = new StubArtifactRepository( this.testDir.getAbsolutePath() ); + mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) ); try { Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java?rev=894515&r1=894514&r2=894515&view=diff ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java (original) +++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java Tue Dec 29 23:33:02 2009 @@ -568,7 +568,7 @@ mojo.type = testType; mojo.factory = DependencyTestUtils.getArtifactFactory(); mojo.resolver = new StubArtifactResolver( stubFactory, false, false ); - mojo.local = new StubArtifactRepository( this.testDir.getAbsolutePath() ); + mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) ); mojo.execute(); Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java?rev=894515&r1=894514&r2=894515&view=diff ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java (original) +++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java Tue Dec 29 23:33:02 2009 @@ -660,5 +660,25 @@ assertTrue( time < copiedFile.lastModified() ); } + + public void testCopyFileWithOverideLocalRepo() + throws IOException, MojoExecutionException + { + ArrayList list = stubFactory.getArtifactItems( stubFactory.getClassifiedArtifacts() ); + + mojo.setArtifactItems( list ); + mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) ); + + File execLocalRepo = new File( this.testDir.getAbsolutePath(), "executionLocalRepo" ); + assertFalse( execLocalRepo.exists() ); + + mojo.setAlternateLocalRepository( execLocalRepo ); + + assertEquals( execLocalRepo.getAbsolutePath(), mojo.getLocal().getBasedir() ); + mojo.execute(); + + assertFilesExist( list, true ); + + } }