Author: brianf
Date: Thu Nov 23 13:18:08 2006
New Revision: 478674
URL: http://svn.apache.org/viewvc?view=rev&rev=478674
Log:
added more copymojo unit tests
Modified:
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/fromConfiguration/ArtifactItem.java
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyUtil.java
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyUtil.java
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?view=diff&rev=478674&r1=478673&r2=478674
==============================================================================
---
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
Thu Nov 23 13:18:08 2006
@@ -57,6 +57,7 @@
/**
* Overwrite release artifacts
+ *
* @optional
* @since 1.0
* @parameter expression="${overWriteReleases}" default-value="false"
@@ -65,14 +66,16 @@
/**
* Overwrite snapshot artifacts
+ *
* @optional
* @since 1.0
* @parameter expression="${overWriteSnapshots}" default-value="false"
*/
protected boolean overWriteSnapshots;
-
+
/**
* Overwrite if newer
+ *
* @optional
* @since 2.0
* @parameter expression="${overIfNewer}" default-value="true"
@@ -94,8 +97,9 @@
* Preprocesses the list of ArtifactItems. This method defaults the
* outputDirectory if not set and creates the output Directory if it
doesn't
* exist.
+ *
* @param removeVersion
- * remove the version from the filename.
+ * remove the version from the filename.
* @return An ArrayList of preprocessed ArtifactItems
*
* @throws MojoExecutionException
@@ -103,10 +107,14 @@
*
* @see ArtifactItem
*/
- protected ArrayList getArtifactItems(boolean removeVersion)
+ protected ArrayList getArtifactItems( boolean removeVersion )
throws MojoExecutionException
{
-
+ if (artifactItems == null || artifactItems.size() < 1)
+ {
+ throw new MojoExecutionException("There are no artifactItems
configured.");
+ }
+
Iterator iter = artifactItems.iterator();
while ( iter.hasNext() )
{
@@ -119,24 +127,31 @@
}
artifactItem.getOutputDirectory().mkdirs();
+ //make sure we have a version.
+ if ( StringUtils.isEmpty( artifactItem.getVersion() ) )
+ {
+ fillMissingArtifactVersion( artifactItem );
+ }
+
artifactItem.setArtifact( this.getArtifact( artifactItem ) );
- //TODO:refactor this
+ // TODO:refactor this
String overWrite = artifactItem.getOverWrite();
- if ( StringUtils.isEmpty(overWrite))
+ if ( StringUtils.isEmpty( overWrite ) )
{
- artifactItem.setDoOverWrite(false);
+ artifactItem.setDoOverWrite( false );
}
else
{
artifactItem.setDoOverWrite( overWrite.equalsIgnoreCase(
"true" ) );
}
-
+
if ( artifactItem.getDestFileName() == null )
{
-
artifactItem.setDestFileName(DependencyUtil.getFormattedFileName(
artifactItem.getArtifact(), removeVersion ));
+ artifactItem.setDestFileName(
DependencyUtil.getFormattedFileName( artifactItem.getArtifact(),
+
removeVersion ) );
}
-
+
}
return artifactItems;
}
@@ -160,23 +175,7 @@
{
Artifact artifact;
- if ( artifactItem.getVersion() == null )
- {
- fillMissingArtifactVersion( artifactItem );
-
- if ( artifactItem.getVersion() == null )
- {
- throw new MojoExecutionException( "Unable to find artifact
version of " + artifactItem.getGroupId()
- + ":" + artifactItem.getArtifactId()
- + " in either dependency list or in project's dependency
management." );
- }
-
- }
-
- // use classifer if set.
- String classifier = artifactItem.getClassifier();
-
- if ( classifier == null || classifier.equals( "" ) )
+ if ( StringUtils.isEmpty( artifactItem.getClassifier() ) )
{
artifact = factory.createArtifact( artifactItem.getGroupId(),
artifactItem.getArtifactId(), artifactItem
.getVersion(), Artifact.SCOPE_PROVIDED, artifactItem.getType()
);
@@ -210,47 +209,49 @@
*
* @param artifact
* representing configured file.
+ * @throws MojoExecutionException
*/
private void fillMissingArtifactVersion( ArtifactItem artifact )
+ throws MojoExecutionException
{
- // this.getLog().debug(
- // "Attempting to find missing version in " +
artifact.getGroupId() + ":"
- // + artifact.getArtifactId() );
-
- List list = this.project.getDependencies();
-
- for ( int i = 0; i < list.size(); ++i )
+ if ( !findDependencyVersion( artifact, project.getDependencies() ) )
{
- Dependency dependency = (Dependency) list.get( i );
-
- if ( dependency.getGroupId().equals( artifact.getGroupId() )
- && dependency.getArtifactId().equals( artifact.getArtifactId()
)
- && dependency.getType().equals( artifact.getType() ) )
+ if ( !findDependencyVersion( artifact,
project.getDependencyManagement().getDependencies() ) )
{
-// this.getLog().debug( "Found missing version: " +
dependency.getVersion() + " in dependency list." );
-
- artifact.setVersion( dependency.getVersion() );
-
- return;
+ throw new MojoExecutionException( "Unable to find artifact
version of " + artifact.getGroupId() + ":"
+ + artifact.getArtifactId() + " in either dependency list
or in project's dependency management." );
}
}
+ }
- list = this.project.getDependencyManagement().getDependencies();
-
- for ( int i = 0; i < list.size(); ++i )
+ /**
+ * Tries to find missing version from a list of dependencies. If found, the
+ * artifact is updated with the correct version.
+ *
+ * @param artifact
+ * representing configured file.
+ * @param list
+ * list of dependencies to search.
+ * @returns the found dependency
+ */
+ private boolean findDependencyVersion( ArtifactItem artifact, List list )
+ {
+ boolean result = false;
+ for ( int i = 0; i < list.size(); i++ )
{
Dependency dependency = (Dependency) list.get( i );
-
- if ( dependency.getGroupId().equals( artifact.getGroupId() )
- && dependency.getArtifactId().equals( artifact.getArtifactId()
)
- && dependency.getType().equals( artifact.getType() ) )
- {
- // this.getLog().debug(
- // "Found missing version: " +
dependency.getVersion()
- // + " in dependency management list"
);
+ if ( StringUtils.equals( dependency.getArtifactId(),
artifact.getArtifactId() )
+ && StringUtils.equals( dependency.getGroupId(),
artifact.getGroupId() )
+ && StringUtils.equals( dependency.getClassifier(),
artifact.getClassifier() )
+ && StringUtils.equals( dependency.getType(),
artifact.getType() ) )
+ {
artifact.setVersion( dependency.getVersion() );
+
+ result = true;
+ break;
}
}
+ return result;
}
}
Modified:
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java?view=diff&rev=478674&r1=478673&r2=478674
==============================================================================
---
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java
(original)
+++
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java
Thu Nov 23 13:18:08 2006
@@ -22,6 +22,8 @@
import java.io.File;
import org.apache.maven.artifact.Artifact;
+import org.codehaus.plexus.archiver.util.FilterSupport;
+import org.codehaus.plexus.util.StringUtils;
/**
* ArtifactItem represents information specified in the plugin configuration
@@ -114,6 +116,17 @@
this.setVersion(artifact.getVersion());
}
+ private final String filterEmptyString(String in)
+ {
+ if (in.equals(""))
+ {
+ return null;
+ }
+ else
+ {
+ return in;
+ }
+ }
/**
* @return Returns the artifactId.
*/
@@ -128,7 +141,7 @@
*/
public void setArtifactId( String artifact )
{
- this.artifactId = artifact;
+ this.artifactId = filterEmptyString(artifact);
}
/**
@@ -145,7 +158,7 @@
*/
public void setGroupId( String groupId )
{
- this.groupId = groupId;
+ this.groupId = filterEmptyString(groupId);
}
/**
@@ -162,7 +175,7 @@
*/
public void setType( String type )
{
- this.type = type;
+ this.type = filterEmptyString(type);
}
/**
@@ -179,7 +192,7 @@
*/
public void setVersion( String version )
{
- this.version = version;
+ this.version = filterEmptyString(version);
}
/**
@@ -196,19 +209,18 @@
*/
public void setClassifier( String classifier )
{
- this.classifier = classifier;
+ this.classifier = filterEmptyString(classifier);
}
public String toString()
{
- String ver = ( version == null ) ? "?" : version;
if ( this.classifier == null )
{
- return groupId + ":" + artifactId + ":" + ver + ":" + type;
+ return groupId + ":" + artifactId + ":" +
StringUtils.defaultString(version,"?") + ":" + type;
}
else
{
- return groupId + ":" + artifactId + ":" + classifier + ":" + ver +
":" + type;
+ return groupId + ":" + artifactId + ":" + classifier + ":" +
StringUtils.defaultString(version,"?") + ":" + type;
}
}
@@ -243,7 +255,7 @@
*/
public void setDestFileName( String destFileName )
{
- this.destFileName = destFileName;
+ this.destFileName = filterEmptyString(destFileName);
}
/**
Modified:
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyUtil.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyUtil.java?view=diff&rev=478674&r1=478673&r2=478674
==============================================================================
---
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyUtil.java
(original)
+++
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyUtil.java
Thu Nov 23 13:18:08 2006
@@ -47,39 +47,35 @@
public static String getFormattedFileName( Artifact artifact, boolean
removeVersion )
{
String destFileName = null;
+ String versionString = null;
if ( !removeVersion )
{
- File file = artifact.getFile();
- if ( file != null )
- {
- destFileName = file.getName();
- }
- // so it can be used offline
- else
- {
- if ( StringUtils.isNotEmpty( artifact.getClassifier() ) )
- {
- destFileName = artifact.getArtifactId() + "-" +
artifact.getClassifier() + "-"
- + artifact.getVersion() + "." + artifact.getType();
- }
- else
- {
- destFileName = artifact.getArtifactId() + "-" +
artifact.getVersion() + "." + artifact.getType();
- }
- }
+ versionString = "-" + artifact.getVersion();
+ }
+ else
+ {
+ versionString = "";
+ }
+ File file = artifact.getFile();
+ if ( file != null )
+ {
+ destFileName = file.getName();
}
+ // so it can be used offline
else
{
- if ( artifact.getClassifier() != null )
+ if ( StringUtils.isNotEmpty( artifact.getClassifier() ) )
{
- destFileName = artifact.getArtifactId() + "-" +
artifact.getClassifier() + "." + artifact.getType();
+ destFileName = artifact.getArtifactId() + "-" +
artifact.getClassifier() + versionString + "."
+ + artifact.getType();
}
else
{
- destFileName = artifact.getArtifactId() + "." +
artifact.getType();
+ destFileName = artifact.getArtifactId() + versionString + "."
+ artifact.getType();
}
}
+
return destFileName;
}
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?view=diff&rev=478674&r1=478673&r2=478674
==============================================================================
---
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
Thu Nov 23 13:18:08 2006
@@ -23,13 +23,17 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase;
import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
import
org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactRepository;
import org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactResolver;
-import org.apache.maven.plugin.dependency.utils.DependencyUtil;
+import org.apache.maven.project.MavenProject;
public class TestCopyMojo
extends AbstractDependencyMojoTestCase
@@ -50,7 +54,7 @@
File testPom = new File( getBasedir(),
"target/test-classes/unit/copy-test/plugin-config.xml" );
mojo = (CopyMojo) lookupMojo( "copy", testPom );
mojo.outputDirectory = new File( this.testDir, "outputDirectory" );
- mojo.silent = true;
+ // mojo.silent = true;
assertNotNull( mojo );
assertNotNull( mojo.getProject() );
@@ -89,7 +93,7 @@
item.setOverWrite( "true" );
result = getSingleArtifactItem( false );
assertTrue( result.isDoOverWrite() );
- assertEquals(mojo.outputDirectory,result.getOutputDirectory());
+ assertEquals( mojo.outputDirectory, result.getOutputDirectory() );
item.setOverWrite( "false" );
result = getSingleArtifactItem( false );
@@ -98,13 +102,13 @@
item.setOverWrite( "" );
result = getSingleArtifactItem( false );
assertFalse( result.isDoOverWrite() );
-
+
item.setOverWrite( "blah" );
- File output = new File(mojo.outputDirectory,"override");
- item.setOutputDirectory(output);
+ File output = new File( mojo.outputDirectory, "override" );
+ item.setOutputDirectory( output );
result = getSingleArtifactItem( false );
assertFalse( result.isDoOverWrite() );
- assertEquals(output,result.getOutputDirectory());
+ assertEquals( output, result.getOutputDirectory() );
}
public void assertFilesExist( Collection items, boolean exist )
@@ -170,9 +174,276 @@
assertFilesExist( list, true );
}
+ public void testNonClassifierStrip()
+ throws IOException, MojoExecutionException
+ {
+ ArrayList list = stubFactory.getArtifactItems(
stubFactory.getReleaseAndSnapshotArtifacts() );
+ mojo.setStripVersion( true );
+ mojo.artifactItems = list;
+
+ mojo.execute();
+
+ assertFilesExist( list, true );
+ }
+
+ public void testNonClassifierNoStrip()
+ throws IOException, MojoExecutionException
+ {
+ ArrayList list = stubFactory.getArtifactItems(
stubFactory.getReleaseAndSnapshotArtifacts() );
+
+ mojo.artifactItems = list;
+
+ mojo.execute();
+
+ assertFilesExist( list, true );
+ }
+
+ public void testMissingVersionNotFound()
+ throws MojoExecutionException
+ {
+ ArtifactItem item = new ArtifactItem();
+
+ item.setArtifactId( "artifactId" );
+ item.setClassifier( "" );
+ item.setGroupId( "groupId" );
+ item.setType( "type" );
+
+ ArrayList list = new ArrayList();
+ list.add( item );
+ mojo.artifactItems = list;
+
+ try
+ {
+ mojo.execute();
+ fail( "Expected Exception Here." );
+ }
+ catch ( MojoExecutionException e )
+ {
+ // caught the expected exception.
+ }
+ }
+
+ public List getDependencyList( ArtifactItem item )
+ {
+ Dependency dep = new Dependency();
+ dep.setArtifactId( item.getArtifactId() );
+ dep.setClassifier( item.getClassifier() );
+ dep.setGroupId( item.getGroupId() );
+ dep.setType( item.getType() );
+ dep.setVersion( "2.0-SNAPSHOT" );
+
+ Dependency dep2 = new Dependency();
+ dep2.setArtifactId( item.getArtifactId() );
+ dep2.setClassifier( "classifier" );
+ dep2.setGroupId( item.getGroupId() );
+ dep2.setType( item.getType() );
+ dep2.setVersion( "2.1" );
+
+ List list = new ArrayList( 2 );
+ list.add( dep2 );
+ list.add( dep );
+
+ return list;
+ }
+
+ public void testMissingVersionFromDependencies()
+ throws MojoExecutionException
+ {
+ ArtifactItem item = new ArtifactItem();
+
+ item.setArtifactId( "artifactId" );
+ item.setClassifier( "" );
+ item.setGroupId( "groupId" );
+ item.setType( "type" );
+
+ ArrayList list = new ArrayList();
+ list.add( item );
+ mojo.artifactItems = list;
+
+ MavenProject project = mojo.getProject();
+ project.setDependencies( getDependencyList( item ) );
+
+ mojo.execute();
+ this.assertFileExists( item, true );
+ assertEquals( "2.0-SNAPSHOT", item.getVersion() );
+ }
+
+ public void testMissingVersionFromDependenciesWithClassifier()
+ throws MojoExecutionException
+ {
+ ArtifactItem item = new ArtifactItem();
+
+ item.setArtifactId( "artifactId" );
+ item.setClassifier( "classifier" );
+ item.setGroupId( "groupId" );
+ item.setType( "type" );
+
+ ArrayList list = new ArrayList();
+ list.add( item );
+ mojo.artifactItems = list;
+
+ MavenProject project = mojo.getProject();
+ project.setDependencies( getDependencyList( item ) );
+
+ mojo.execute();
+ this.assertFileExists( item, true );
+ assertEquals( "2.1", item.getVersion() );
+ }
+
+ public List getDependencyMgtList(ArtifactItem item)
+ {
+ Dependency dep = new Dependency();
+ dep.setArtifactId(item.getArtifactId());
+ dep.setClassifier(item.getClassifier());
+ dep.setGroupId(item.getGroupId());
+ dep.setType(item.getType());
+ dep.setVersion("3.0-SNAPSHOT");
+
+ Dependency dep2 = new Dependency();
+ dep2.setArtifactId(item.getArtifactId());
+ dep2.setClassifier("classifier");
+ dep2.setGroupId(item.getGroupId());
+ dep2.setType(item.getType());
+ dep2.setVersion("3.1");
+
+ List list = new ArrayList(2);
+ list.add(dep2);
+ list.add(dep);
+
+ return list;
+ }
+ public void testMissingVersionFromDependencyMgt()
+ throws MojoExecutionException
+ {
+ ArtifactItem item = new ArtifactItem();
+
+ item.setArtifactId( "artifactId" );
+ item.setClassifier( "" );
+ item.setGroupId( "groupId" );
+ item.setType( "type" );
+
+
+ MavenProject project = mojo.getProject();
+ project.setDependencies( getDependencyList( item ) );
+
+ item = new ArtifactItem();
+
+ item.setArtifactId( "artifactId-2" );
+ item.setClassifier( "" );
+ item.setGroupId( "groupId" );
+ item.setType( "type" );
+
+ ArrayList list = new ArrayList();
+ list.add( item );
+
+ mojo.artifactItems = list;
+
+ project.getDependencyManagement().setDependencies(
getDependencyMgtList( item ) );
+
+ mojo.execute();
+ System.out.println("resolved:"+item.toString());
+ this.assertFileExists( item, true );
+ assertEquals( "3.0-SNAPSHOT", item.getVersion() );
+ }
+ public void testMissingVersionFromDependencyMgtWithClassifier()
+ throws MojoExecutionException
+{
+ ArtifactItem item = new ArtifactItem();
+
+ item.setArtifactId( "artifactId" );
+ item.setClassifier( "classifier" );
+ item.setGroupId( "groupId" );
+ item.setType( "type" );
+
+
+ MavenProject project = mojo.getProject();
+ project.setDependencies( getDependencyList( item ) );
+
+ item = new ArtifactItem();
+
+ item.setArtifactId( "artifactId-2" );
+ item.setClassifier( "classifier" );
+ item.setGroupId( "groupId" );
+ item.setType( "type" );
+
+ ArrayList list = new ArrayList();
+ list.add( item );
+
+ mojo.artifactItems = list;
+
+ project.getDependencyManagement().setDependencies( getDependencyMgtList(
item ) );
+
+ mojo.execute();
+ System.out.println("resolved:"+item.toString());
+ this.assertFileExists( item, true );
+ assertEquals( "3.1", item.getVersion() );
+}
+
+ public void testArtifactNotFound()
+ throws Exception
+{
+ dotestArtifactExceptions( false, true );
+}
+
+public void testArtifactResolutionException()
+ throws Exception
+{
+ dotestArtifactExceptions( true, false );
+}
+
+public void dotestArtifactExceptions( boolean are, boolean anfe )
+ throws Exception
+{
+ ArtifactItem item = new ArtifactItem();
+
+ item.setArtifactId( "artifactId" );
+ item.setClassifier( "" );
+ item.setGroupId( "groupId" );
+ item.setType( "type" );
+ item.setVersion("1.0");
+
+ ArrayList list = new ArrayList();
+ list.add( item );
+ mojo.artifactItems = list;
+
+ // init classifier things
+ mojo.setFactory(DependencyTestUtils.getArtifactFactory());
+ mojo.setResolver(new StubArtifactResolver( null, are, anfe ));
+ mojo.setLocal(new StubArtifactRepository( this.testDir.getAbsolutePath()
));
+
+ try
+ {
+ mojo.execute();
+ fail( "ExpectedException" );
+ }
+ catch ( MojoExecutionException e )
+ {
+ if (are)
+ {
+ assertEquals("Unable to resolve artifact.",e.getMessage());
+ }
+ else
+ {
+ assertEquals("Unable to find artifact.",e.getMessage());
+ }
+ }
+}
+
+public void testNoArtifactItems()
+{
+ try
+ {
+ mojo.getArtifactItems(false);
+ fail("Expected Exception");
+ }
+ catch ( MojoExecutionException e )
+ {
+ assertEquals("There are no artifactItems configured.",e.getMessage());
+ }
+
+}
+
// TODO: test overwrite / overwrite if newer / overwrite release /
overwrite
// snapshot
- // TODO: test non classifier
- // TODO: test missing version - from dependency and from dependency
- // management
+
}
Modified:
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java?view=diff&rev=478674&r1=478673&r2=478674
==============================================================================
---
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java
(original)
+++
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java
Thu Nov 23 13:18:08 2006
@@ -32,6 +32,7 @@
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.model.Dependency;
import org.apache.maven.plugin.dependency.fromConfiguration.ArtifactItem;
import org.apache.maven.plugin.dependency.utils.DependencyUtil;
import org.apache.maven.plugin.dependency.utils.SilentLog;
Modified:
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java?view=diff&rev=478674&r1=478673&r2=478674
==============================================================================
---
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
(original)
+++
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
Thu Nov 23 13:18:08 2006
@@ -86,6 +86,8 @@
private MavenProject parent;
+ private List dependencies;
+
private File file;
private List collectedProjects;
@@ -108,6 +110,8 @@
private Set dependencyArtifacts;
+ private DependencyManagement dependencyManagement;
+
private Artifact artifact;
private Map artifactMap;
@@ -253,17 +257,26 @@
public void setDependencies( List list )
{
-
+ dependencies = list;
}
public List getDependencies()
{
- return Collections.singletonList( "" );
+ if (dependencies == null)
+ {
+ dependencies = Collections.EMPTY_LIST;
+ }
+ return dependencies;
}
public DependencyManagement getDependencyManagement()
{
- return null;
+ if (dependencyManagement == null)
+ {
+ dependencyManagement = new DependencyManagement();
+ }
+
+ return dependencyManagement;
}
public void addCompileSourceRoot( String string )
Modified:
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyUtil.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyUtil.java?view=diff&rev=478674&r1=478673&r2=478674
==============================================================================
---
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyUtil.java
(original)
+++
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyUtil.java
Thu Nov 23 13:18:08 2006
@@ -60,7 +60,7 @@
ArtifactHandler ah = new DefaultArtifactHandler();
VersionRange vr = VersionRange.createFromVersion( "1.1" );
- this.release = new DefaultArtifact( "test", "1", vr,
Artifact.SCOPE_COMPILE, "jar", null, ah, false );
+ release = new DefaultArtifact( "test", "1", vr,
Artifact.SCOPE_COMPILE, "jar", null, ah, false );
artifacts.add( release );
vr = VersionRange.createFromVersion( "1.1-SNAPSHOT" );
@@ -79,8 +79,6 @@
}
-
-
public void testDirectoryName()
throws MojoExecutionException
{
@@ -127,7 +125,7 @@
public void testFileName()
throws MojoExecutionException
{
- DefaultArtifact artifact = (DefaultArtifact) artifacts.get( 0 );
+ Artifact artifact = (Artifact) artifacts.get( 0 );
String name = DependencyUtil.getFormattedFileName( artifact, false );
String expectedResult = "1-1.1.jar";
@@ -136,15 +134,27 @@
name = DependencyUtil.getFormattedFileName( artifact, true );
expectedResult = "1.jar";
assertTrue( expectedResult.equalsIgnoreCase( name ) );
+ }
- artifact = (DefaultArtifact) artifacts.get( 1 );
-
- name = DependencyUtil.getFormattedFileName( artifact, false );
- expectedResult = "2-sources-1.1-SNAPSHOT.war";
- assertTrue( expectedResult.equalsIgnoreCase( name ) );
+ public void testFileNameClassifier()
+ throws MojoExecutionException
+ {
+ ArtifactHandler ah = new DefaultArtifactHandler();
+ VersionRange vr = VersionRange.createFromVersion( "1.1-SNAPSHOT" );
+ Artifact artifact = new DefaultArtifact( "test", "2", vr,
Artifact.SCOPE_PROVIDED, "war", "sources", ah, false );
+
+ String name = DependencyUtil.getFormattedFileName( artifact, false );
+ String expectedResult = "2-sources-1.1-SNAPSHOT.war";
+ assertEquals(expectedResult,name );
name = DependencyUtil.getFormattedFileName( artifact, true );
expectedResult = "2-sources.war";
- assertTrue( expectedResult.equalsIgnoreCase( name ) );
+ assertEquals(expectedResult,name );
+
+ artifact = new DefaultArtifact( "test", "2", vr,
Artifact.SCOPE_PROVIDED, "war", "", ah, false );
+ name = DependencyUtil.getFormattedFileName( artifact, true );
+ expectedResult = "2.war";
+ assertEquals(expectedResult,name );
+
}
}