Author: brianf Date: Wed Jan 2 18:26:28 2008 New Revision: 608308 URL: http://svn.apache.org/viewvc?rev=608308&view=rev Log: MDEP-129: allow property substitution of the local repo paths.
Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/BuildClasspathMojo.java maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestBuildClasspathMojo.java maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/DependencyArtifactStubFactory.java 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=608308&r1=608307&r2=608308&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 Wed Jan 2 18:26:28 2008 @@ -108,6 +108,14 @@ * @parameter default-value="" expression="${mdep.pathSeparator}" */ private String pathSeparator; + + /** + * Replace the absolute path to the local repo with this property. This field is ignored + * it prefix is declared. + * @since 2.0-alpha-5 + * @parameter default-value="" expression="${mdep.localRepoProperty}" + */ + private String localRepoProperty; boolean isFileSepSet = true; @@ -212,14 +220,19 @@ { if ( prefix == null ) { - - sb.append( art.getFile() ); + String file = art.getFile().getPath(); + //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 ); + } + sb.append( file ); } else { // TODO: add param for prepending groupId and version. sb.append( prefix ); - sb.append( ( isFileSepSet ) ? this.fileSeparator : File.separator ); + sb.append( File.separator ); sb.append( DependencyUtil.getFormattedFileName( art, this.stripVersion ) ); } } @@ -475,5 +488,35 @@ public void setStripVersion( boolean theStripVersion ) { this.stripVersion = theStripVersion; + } + + public String getLocalRepoProperty() + { + return localRepoProperty; + } + + public void setLocalRepoProperty( String localRepoProperty ) + { + this.localRepoProperty = localRepoProperty; + } + + public boolean isFileSepSet() + { + return isFileSepSet; + } + + public void setFileSepSet( boolean isFileSepSet ) + { + this.isFileSepSet = isFileSepSet; + } + + public boolean isPathSepSet() + { + return isPathSepSet; + } + + public void setPathSepSet( boolean isPathSepSet ) + { + this.isPathSepSet = isPathSepSet; } } Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestBuildClasspathMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestBuildClasspathMojo.java?rev=608308&r1=608307&r2=608308&view=diff ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestBuildClasspathMojo.java (original) +++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestBuildClasspathMojo.java Wed Jan 2 18:26:28 2008 @@ -22,6 +22,10 @@ import java.io.File; import java.util.Set; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.plugin.dependency.utils.DependencyUtil; +import org.apache.maven.plugin.testing.stubs.StubArtifactRepository; import org.apache.maven.project.MavenProject; public class TestBuildClasspathMojo @@ -63,7 +67,7 @@ try { file = mojo.readClasspathFile(); - + fail( "Expected an illegal Argument Exception" ); } catch ( IllegalArgumentException e ) @@ -71,31 +75,73 @@ // expected to catch this. } - mojo.setCpFile( new File(testDir,"buildClasspath.txt") ); + mojo.setCpFile( new File( testDir, "buildClasspath.txt" ) ); mojo.execute(); - + file = mojo.readClasspathFile(); assertNotNull( file ); assertTrue( file.length() > 0 ); - assertTrue(file.indexOf( File.pathSeparator ) >= 0 ); - assertTrue(file.indexOf( File.separator ) >= 0 ); - + assertTrue( file.indexOf( File.pathSeparator ) >= 0 ); + assertTrue( file.indexOf( File.separator ) >= 0 ); + String fileSep = "#####"; String pathSep = "%%%%%"; - + mojo.setFileSeparator( fileSep ); mojo.setPathSeparator( pathSep ); mojo.execute(); - + file = mojo.readClasspathFile(); assertNotNull( file ); assertTrue( file.length() > 0 ); - assertFalse(file.indexOf( File.pathSeparator ) >= 0 ); - assertFalse(file.indexOf( File.separator ) >= 0 ); - assertTrue(file.indexOf( fileSep ) >= 0 ); - assertTrue(file.indexOf( pathSep ) >= 0 ); + assertFalse( file.indexOf( File.pathSeparator ) >= 0 ); + assertFalse( file.indexOf( File.separator ) >= 0 ); + assertTrue( file.indexOf( fileSep ) >= 0 ); + assertTrue( file.indexOf( pathSep ) >= 0 ); } + public void testPath() throws Exception + { + File testPom = new File( getBasedir(), "target/test-classes/unit/build-classpath-test/plugin-config.xml" ); + BuildClasspathMojo mojo = (BuildClasspathMojo) lookupMojo( "build-classpath", testPom ); + + assertNotNull( mojo ); + assertNotNull( mojo.getProject() ); + MavenProject project = mojo.getProject(); + ArtifactRepository local = new StubArtifactRepository(stubFactory.getWorkingDir().getPath()); + mojo.setLocal( local ); + + Artifact artifact = stubFactory.getReleaseArtifact(); + + + StringBuffer sb = new StringBuffer(); + mojo.setPrefix( null ); + mojo.setStripVersion( false ); + mojo.appendArtifactPath( artifact, sb ); + assertEquals(artifact.getFile().getPath(),sb.toString()); + + mojo.setLocalRepoProperty( "$M2_REPO" ); + sb.setLength( 0 ); + mojo.appendArtifactPath( artifact, sb ); + assertEquals("$M2_REPO"+File.separator+artifact.getFile().getName(),sb.toString()); + + mojo.setLocalRepoProperty( "%M2_REPO%" ); + sb.setLength( 0 ); + mojo.appendArtifactPath( artifact, sb ); + assertEquals("%M2_REPO%"+File.separator+artifact.getFile().getName(),sb.toString()); + + mojo.setLocalRepoProperty( "" ); + mojo.setPrefix( "prefix" ); + sb.setLength( 0 ); + mojo.appendArtifactPath( artifact, sb ); + assertEquals("prefix"+File.separator+artifact.getFile().getName(),sb.toString()); + + mojo.setPrefix( "prefix" ); + mojo.setStripVersion( true ); + sb.setLength( 0 ); + mojo.appendArtifactPath( artifact, sb ); + assertEquals("prefix"+File.separator+DependencyUtil.getFormattedFileName( artifact, true ),sb.toString()); + } } Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/DependencyArtifactStubFactory.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/DependencyArtifactStubFactory.java?rev=608308&r1=608307&r2=608308&view=diff ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/DependencyArtifactStubFactory.java (original) +++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/DependencyArtifactStubFactory.java Wed Jan 2 18:26:28 2008 @@ -57,5 +57,4 @@ } return list; } - }