You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2007/03/25 05:52:30 UTC
svn commit: r522154 - in /maven/plugins/trunk/maven-dependency-plugin/src:
main/java/org/apache/maven/plugin/dependency/
test/java/org/apache/maven/plugin/dependency/
test/java/org/apache/maven/plugin/dependency/testUtils/stubs/
Author: brianf
Date: Sat Mar 24 20:52:25 2007
New Revision: 522154
URL: http://svn.apache.org/viewvc?view=rev&rev=522154
Log:
MDEP-76 more tests
Modified:
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDepMgt.java
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestAnalyzeDepMgt.java
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDepMgt.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDepMgt.java?view=diff&rev=522154&r1=522153&r2=522154
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDepMgt.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDepMgt.java Sat Mar 24 20:52:25 2007
@@ -32,6 +32,7 @@
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Exclusion;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -157,9 +158,9 @@
Iterator exclusionIter = exclusionErrors.iterator();
while ( exclusionIter.hasNext() )
{
- Artifact exclusion = (Artifact) iter.next();
+ Artifact exclusion = (Artifact) exclusionIter.next();
getLog().info(
- getArtifactManagementKey( exclusion ) + " was excluded in DepMgt, but version "
+ StringUtils.stripEnd( getArtifactManagementKey( exclusion ),":") + " was excluded in DepMgt, but version "
+ exclusion.getVersion() + " has been found in the dependency tree." );
foundError = true;
}
@@ -173,16 +174,17 @@
Dependency depMgtDependency = (Dependency) mismatch.get( resolvedArtifact );
logMismatch( resolvedArtifact, depMgtDependency );
}
+ if ( !foundError )
+ {
+ getLog().info( " None" );
+ }
}
else
{
getLog().info( " Nothing in DepMgt." );
}
- if ( !foundError )
- {
- getLog().info( " None" );
- }
+
return foundError;
}
@@ -204,8 +206,8 @@
Iterator exclusionIter = exclusionList.iterator();
while ( exclusionIter.hasNext() )
{
- Dependency exclusion = (Dependency) exclusionIter.next();
- exclusions.put( exclusion.getManagementKey(), exclusion );
+ Exclusion exclusion = (Exclusion) exclusionIter.next();
+ exclusions.put( getExclusionKey( exclusion ), exclusion );
}
}
return exclusions;
@@ -230,7 +232,7 @@
while ( iter.hasNext() )
{
Artifact artifact = (Artifact) iter.next();
- if ( exclusions.containsKey( getArtifactManagementKey( artifact ) ) )
+ if ( exclusions.containsKey( getExclusionKey( artifact ) ) )
{
list.add( artifact );
}
@@ -239,6 +241,16 @@
return list;
}
+ public String getExclusionKey(Artifact artifact)
+ {
+ return artifact.getGroupId()+":"+artifact.getArtifactId();
+ }
+
+ public String getExclusionKey(Exclusion ex)
+ {
+ return ex.getGroupId()+":"+ex.getArtifactId();
+ }
+
/**
* Calculate the mismatches between the DependencyManagement and resolved
* artifacts
@@ -293,7 +305,7 @@
+ dependencyFromDepMgt );
}
- getLog().info( "\tDependency: " + dependencyFromDepMgt.getManagementKey() );
+ getLog().info( "\tDependency: " + StringUtils.stripEnd(dependencyFromDepMgt.getManagementKey(),":") );
getLog().info( "\t\tDepMgt : " + dependencyFromDepMgt.getVersion() );
getLog().info( "\t\tResolved: " + dependencyArtifact.getVersion() );
}
Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestAnalyzeDepMgt.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestAnalyzeDepMgt.java?view=diff&rev=522154&r1=522153&r2=522154
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestAnalyzeDepMgt.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestAnalyzeDepMgt.java Sat Mar 24 20:52:25 2007
@@ -13,6 +13,8 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Dependency;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Exclusion;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.dependency.testUtils.ArtifactStubFactory;
@@ -38,26 +40,40 @@
* under the License.
*/
-
public class TestAnalyzeDepMgt
extends TestCase
{
AnalyzeDepMgt mojo;
+
ArtifactStubFactory stubFactory;
+
Dependency exclusion;
+
+ Exclusion ex;
+
Artifact exclusionArtifact;
+ DependencyManagement depMgt;
protected void setUp()
throws Exception
{
+
+ mojo = new AnalyzeDepMgt();
+ MavenProject project = new DependencyProjectStub();
- stubFactory = new ArtifactStubFactory( new File(""), false );
-
+ stubFactory = new ArtifactStubFactory( new File( "" ), false );
+
Set allArtifacts = stubFactory.getMixedArtifacts();
Set directArtifacts = stubFactory.getClassifiedArtifacts();
+
exclusionArtifact = stubFactory.getReleaseArtifact();
+ directArtifacts.add( exclusionArtifact );
+ ex = new Exclusion();
+ ex.setArtifactId( exclusionArtifact.getArtifactId() );
+ ex.setGroupId( exclusionArtifact.getGroupId() );
+
exclusion = new Dependency();
exclusion.setArtifactId( exclusionArtifact.getArtifactId() );
exclusion.setGroupId( exclusionArtifact.getGroupId() );
@@ -65,121 +81,170 @@
exclusion.setClassifier( "" );
exclusion.setVersion( "3.0" );
- mojo = new AnalyzeDepMgt();
- MavenProject project = new DependencyProjectStub();
+ exclusion.addExclusion( ex );
+ ArrayList list = new ArrayList();
+ list.add( exclusion );
+
+ depMgt = new DependencyManagement();
+ depMgt.setDependencies( list );
+
+
project.setArtifacts( allArtifacts );
project.setDependencyArtifacts( directArtifacts );
-
+
mojo.setProject( project );
-
+
}
- public void testGetManagementKey() throws IOException
+ public void testGetManagementKey()
+ throws IOException
{
Dependency dep = new Dependency();
dep.setArtifactId( "artifact" );
dep.setClassifier( "class" );
dep.setGroupId( "group" );
dep.setType( "type" );
-
- //version isn't used in the key, it can be different
+
+ // version isn't used in the key, it can be different
dep.setVersion( "1.1" );
-
- Artifact artifact = stubFactory.createArtifact( "group", "artifact", "1.0",Artifact.SCOPE_COMPILE,"type","class" );
- //basic case ok
+ Artifact artifact = stubFactory.createArtifact( "group", "artifact", "1.0", Artifact.SCOPE_COMPILE, "type",
+ "class" );
+
+ // basic case ok
assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) );
-
- //now change each one and make sure it fails, then set it back and make sure it's ok before
- //testing the next one
+
+ // now change each one and make sure it fails, then set it back and make
+ // sure it's ok before
+ // testing the next one
dep.setType( "t" );
- assertFalse ( dep.getManagementKey().equals(mojo.getArtifactManagementKey( artifact ) ));
-
+ assertFalse( dep.getManagementKey().equals( mojo.getArtifactManagementKey( artifact ) ) );
+
dep.setType( "type" );
assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) );
-
+
dep.setArtifactId( "a" );
- assertFalse ( dep.getManagementKey().equals(mojo.getArtifactManagementKey( artifact ) ));
-
+ assertFalse( dep.getManagementKey().equals( mojo.getArtifactManagementKey( artifact ) ) );
+
dep.setArtifactId( "artifact" );
assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) );
-
+
dep.setClassifier( "c" );
- assertFalse ( dep.getManagementKey().equals(mojo.getArtifactManagementKey( artifact ) ));
-
+ assertFalse( dep.getManagementKey().equals( mojo.getArtifactManagementKey( artifact ) ) );
+
dep.setClassifier( "class" );
assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) );
-
+
dep.setGroupId( "g" );
- assertFalse ( dep.getManagementKey().equals(mojo.getArtifactManagementKey( artifact ) ));
-
+ assertFalse( dep.getManagementKey().equals( mojo.getArtifactManagementKey( artifact ) ) );
+
dep.setGroupId( "group" );
dep.setClassifier( null );
- artifact = stubFactory.createArtifact( "group", "artifact", "1.0",Artifact.SCOPE_COMPILE,"type",null );
+ artifact = stubFactory.createArtifact( "group", "artifact", "1.0", Artifact.SCOPE_COMPILE, "type", null );
assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) );
-
+
dep.setClassifier( "" );
- artifact = stubFactory.createArtifact( "group", "artifact", "1.0",Artifact.SCOPE_COMPILE,"type","" );
+ artifact = stubFactory.createArtifact( "group", "artifact", "1.0", Artifact.SCOPE_COMPILE, "type", "" );
assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) );
}
-
+
public void testAddExclusions()
{
- Dependency dep = new Dependency();
- dep.setArtifactId( "artifact" );
- dep.setClassifier( "class" );
- dep.setGroupId( "group" );
- dep.setType( "type" );
assertEquals( 0, mojo.addExclusions( null ).size() );
-
+
ArrayList list = new ArrayList();
- assertEquals( 0, mojo.addExclusions( null ).size() );
-
- list.add( dep );
+ list.add( ex );
Map map = mojo.addExclusions( list );
-
- assertTrue(map.containsKey( dep.getManagementKey() ));
- assertSame( dep, map.get( dep.getManagementKey() ) );
+
+ assertEquals( 1,map.size() );
+ assertTrue( map.containsKey( mojo.getExclusionKey( ex ) ) );
+ assertSame( ex, map.get( mojo.getExclusionKey( ex ) ) );
}
-
+
public void testGetExclusionErrors()
{
ArrayList list = new ArrayList();
- list.add( exclusion );
-
- //already tested this method so I can trust it.
+ list.add( ex );
+
+ // already tested this method so I can trust it.
Map map = mojo.addExclusions( list );
-
+
List l = mojo.getExclusionErrors( map, mojo.getProject().getArtifacts() );
-
+
assertEquals( 1, l.size() );
-
- assertEquals( exclusion.getManagementKey(), mojo.getArtifactManagementKey( (Artifact) l.get( 0 ) ));
+
+ assertEquals( mojo.getExclusionKey( ex ), mojo.getExclusionKey(( Artifact) l.get( 0 ) ) );
}
- public void testGetMismatch() throws IOException
+ public void testGetMismatch()
+ throws IOException
{
Map depMgtMap = new HashMap();
depMgtMap.put( exclusion.getManagementKey(), exclusion );
-
+
Map results = mojo.getMismatch( depMgtMap, mojo.getProject().getArtifacts() );
-
+
assertEquals( 1, results.size() );
- //the release artifact is used to create the exclusion
- assertTrue( results.containsKey( stubFactory.getReleaseArtifact()));
- assertSame( exclusion,results.get( stubFactory.getReleaseArtifact()));
+ // the release artifact is used to create the exclusion
+ assertTrue( results.containsKey( stubFactory.getReleaseArtifact() ) );
+ assertSame( exclusion, results.get( stubFactory.getReleaseArtifact() ) );
}
-
- public void testMojo()
- {
+
+ public void testMojo() throws IOException
+ {
+ mojo.setIgnoreDirect( false );
+ try
+ {
+ // test with nothing in depMgt
+ mojo.execute();
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ fail("Caught Unexpected Exception:"+e.getLocalizedMessage());
+ }
+
+ try
+ {
+ DependencyProjectStub project = (DependencyProjectStub) mojo.getProject();
+ project.setDependencyManagement( depMgt );
+ // test with exclusion
+ mojo.execute();
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ fail("Caught Unexpected Exception:"+e.getLocalizedMessage());
+ }
+
+ try
+ {
+ DependencyProjectStub project = (DependencyProjectStub) mojo.getProject();
+ project.setDependencyManagement( depMgt );
+ // test with exclusion
+ mojo.setFailBuild( true );
+ mojo.execute();
+ fail("Expected exception to fail the build.");
+ }
+ catch ( Exception e )
+ {
+ System.out.println("Caught Expected Exception:"+e.getLocalizedMessage());
+ }
+
try
{
+ DependencyProjectStub project = (DependencyProjectStub) mojo.getProject();
+ project.setDependencyManagement( depMgt );
+ // test with exclusion
+ mojo.setFailBuild( true );
+ mojo.setIgnoreDirect( true );
mojo.execute();
}
catch ( Exception e )
{
+ e.printStackTrace();
fail("Caught Unexpected Exception:"+e.getLocalizedMessage());
}
}
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=522154&r1=522153&r2=522154
==============================================================================
--- 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 Sat Mar 24 20:52:25 2007
@@ -266,6 +266,10 @@
return dependencies;
}
+ public void setDependencyManagement(DependencyManagement depMgt)
+ {
+ this.dependencyManagement = depMgt;
+ }
public DependencyManagement getDependencyManagement()
{
if ( dependencyManagement == null )