michal 2004/05/17 14:11:34
Modified: maven-project/src/main/java/org/apache/maven/artifact/collector
DefaultArtifactCollector.java
ArtifactCollector.java
ArtifactCollectionResult.java
maven-project/src/main/java/org/apache/maven/project
DefaultMavenProjectBuilder.java MavenProject.java
maven-project/src/main/resources/META-INF/plexus
components.xml
maven-project/src/test/resources/local-repo/maven-test/poms
maven-test-b-1.0.pom maven-test-c-1.0.pom
maven-test-d-1.2.pom
maven-project/src/main/java/org/apache/maven/artifact/satisfier
ArtifactSatisfier.java
maven-project/src/main/java/org/apache/maven/artifact/resolver
DefaultArtifactResolver.java
maven-project/src/main/java/org/apache/maven/artifact
AbstractMavenArtifact.java
maven-project/src/test/java/org/apache/maven/artifact/collector
DefaultArtifactCollectorTest.java
Added: maven-project/src/main/java/org/apache/maven/artifact/collector
ArtifactCollectionResultEntry.java
Log:
New version of ArtifactCollector
Revision Changes Path
1.4 +43 -132
maven-components/maven-project/src/main/java/org/apache/maven/artifact/collector/DefaultArtifactCollector.java
Index: DefaultArtifactCollector.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-project/src/main/java/org/apache/maven/artifact/collector/DefaultArtifactCollector.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultArtifactCollector.java 10 May 2004 19:06:30 -0000 1.3
+++ DefaultArtifactCollector.java 17 May 2004 21:11:33 -0000 1.4
@@ -1,25 +1,23 @@
package org.apache.maven.artifact.collector;
-import java.util.ArrayList;
+import java.io.File;
import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
import org.apache.maven.artifact.MavenArtifact;
-import org.apache.maven.artifact.collector.ArtifactCollectionResult;
-import org.apache.maven.artifact.collector.ArtifactCollector;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Michal Maczka</a>
* @version $Id$
*/
-public class DefaultArtifactCollector implements ArtifactCollector
+public class DefaultArtifactCollector extends AbstractLogEnabled implements
ArtifactCollector
{
/**
@@ -28,161 +26,74 @@
private ArtifactResolver artifactResolver;
/**
- *
- * @requirement
- */
- private MavenProjectBuilder projectBuilder;
-
- /**
* @see
org.apache.maven.artifact.collector.ArtifactCollector#getArtifacts(org.apache.maven.project.MavenProject)
*/
- public ArtifactCollectionResult getArtifacts( MavenProject project )
- throws Exception
+ public ArtifactCollectionResult collect( MavenProject project,
MavenProjectBuilder projectBuilder ) throws Exception
{
ArtifactCollectionResult retValue = new ArtifactCollectionResult();
- resolveDependencies( project, retValue );
+ for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); )
+ {
+ MavenArtifact artifact = ( MavenArtifact ) i.next();
- return retValue;
+ Dependency dependency = artifact.getDependency();
- }
+ String id = dependency.getId();
- void resolveDependencies( MavenProject project,
- ArtifactCollectionResult result ) throws Exception
- {
+ retValue.addArtifact( artifact, project );
- // I want to use BSF not DFS
- //so the artifact of top level project are always processed in first place
-
-
- // linked list - we will have a lot add/remove operation
- List queue = new LinkedList();
+ MavenProject referencedProject = getProject( dependency, project,
projectBuilder );
- queue.add( project );
-
- while ( !queue.isEmpty() )
- {
-
- MavenProject currentProject = ( MavenProject ) queue.remove( 0 );
-
-
- for ( Iterator i = currentProject.getArtifacts().iterator();
i.hasNext(); )
+ if ( referencedProject != null )
{
- MavenArtifact newArtifact = ( MavenArtifact ) i.next();
+ retValue.merge( referencedProject );
+ }
- String id = newArtifact.getDependency().getId();
-
-
+ else
+ {
+ getLogger().debug( "POM for " + dependency.getId() + ":" +
dependency.getVersion() + " not found" );
- if ( result.getArtifacts().containsKey( id ) )
- {
- MavenArtifact knownArtifact = ( MavenArtifact ) result
- .getArtifacts().get( id );
-
- String newVersion = newArtifact.getDependency()
- .getVersion();
-
- String knownVersion = knownArtifact.getDependency()
- .getVersion();
-
- if ( newVersion.equals( knownVersion ) )
- {
- continue;
- }
- else
- {
- // WE HAVE A VERSION CONFLICT!!
-
- // will check if this artifact is in the top level project
- // if it is - version at the top level project wins
- //if ( project.getDependency( key ) != null )
- //{
- // continue;
- //}
-
- List list;
-
- if ( result.getConflicts().containsKey( id ) )
- {
- list = ( List ) result.getConflicts().get( id );
- }
- else
- {
- list = new ArrayList();
-
- list.add( knownArtifact );
-
- result.getConflicts().put( id, list );
- }
-
-
- list.add( newArtifact );
- }
- }
- else
- {
- //It's the first time we have encountered this artifact
-
- // Add the dependency itself
- result.getArtifacts().put( id, newArtifact );
-
- MavenProject childProject = getProject(
newArtifact.getDependency(),
- currentProject );
-
-
- if ( childProject == null )
- {
- // the pom for this artifact is not present in local
repository.
- // we will note this fact
- result.getArtifactsWithoutPoms().put( id, newArtifact );
-
- continue;
- }
- else
- {
- //@hack for testing I need to propagate the location of
mavenRepoLocal
- //this shows that some settings should be detached from
project.
-
- childProject.setLocalRepository(
currentProject.getLocalRepository() );
-
- }
-
- // the pom for given dependency exisit we will enqueue it
- queue.add( childProject );
-
- }
-
+ retValue.addArtifactWithoutPom( artifact.getDependency().getId() );
}
+
}
+ project.setArtifactCollectionResult( retValue );
+
+ return retValue;
+
}
/**
* @param pomArtifact
* @return
*/
- private MavenProject getProject( Dependency dependency, MavenProject project )
+ private MavenProject getProject( Dependency dependency,
+ MavenProject project, MavenProjectBuilder projectBuilder )
throws Exception
{
-
+
MavenProject retValue = null;
-
+
MavenArtifact pomArtifact = artifactResolver.getPomArtifact( dependency,
project );
-
+
if ( pomArtifact != null )
{
- try
- {
- retValue = projectBuilder.build( pomArtifact.getFile( ) );
- }
- catch ( ProjectBuildingException e )
- {
- throw new Exception( "POM for dependency: " + dependency
- + " exists in local repository but cannot be parsed", e );
- }
+ try
+ {
+
+ File f = pomArtifact.getFile();
+
+ retValue = projectBuilder.build( f );
+ }
+ catch ( ProjectBuildingException e )
+ {
+ throw new Exception( "POM for dependency: " + dependency.getId()
+ + " exists in local repository but cannot be parsed", e );
+ }
}
-
+
return retValue;
}
1.3 +3 -2
maven-components/maven-project/src/main/java/org/apache/maven/artifact/collector/ArtifactCollector.java
Index: ArtifactCollector.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-project/src/main/java/org/apache/maven/artifact/collector/ArtifactCollector.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ArtifactCollector.java 8 May 2004 12:19:23 -0000 1.2
+++ ArtifactCollector.java 17 May 2004 21:11:33 -0000 1.3
@@ -2,6 +2,7 @@
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
@@ -12,6 +13,6 @@
{
String ROLE = ArtifactCollector.class.getName();
- ArtifactCollectionResult getArtifacts( MavenProject project )
+ ArtifactCollectionResult collect( MavenProject project, MavenProjectBuilder
projectBuilder )
throws Exception;
}
1.4 +134 -17
maven-components/maven-project/src/main/java/org/apache/maven/artifact/collector/ArtifactCollectionResult.java
Index: ArtifactCollectionResult.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-project/src/main/java/org/apache/maven/artifact/collector/ArtifactCollectionResult.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ArtifactCollectionResult.java 8 May 2004 12:37:23 -0000 1.3
+++ ArtifactCollectionResult.java 17 May 2004 21:11:33 -0000 1.4
@@ -1,7 +1,13 @@
package org.apache.maven.artifact.collector;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
+import java.util.Set;
+
+import org.apache.maven.artifact.MavenArtifact;
+import org.apache.maven.project.MavenProject;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
@@ -9,41 +15,152 @@
*/
public class ArtifactCollectionResult
{
- /** Map<String,MavenArtifact> */
- private Map artifacts;
+ //We will keep artifacts in two data structures:
+
+ /** Set<MavenArtifact> */
+ private Set artifacts;
+
+ /** Set<String> */
+ private Set artifactsWithoutPoms;
-
/**
- * Map<String, List<MavenArtifact>>
+ * Map<String,ArtifactCollectionResultEntry>
*
*/
- private Map conflicts;
+ private Map entries;
- /** Map<String,MavenArtifact> */
- private Map artifactsWithoutPoms;
+ private boolean conflict;
-
public ArtifactCollectionResult()
{
- artifacts = new HashMap();
+ artifacts = new HashSet();
- conflicts = new HashMap();
+ artifactsWithoutPoms = new HashSet();
+
+ entries = new HashMap();
+
+
- artifactsWithoutPoms = new HashMap();
}
- public Map getArtifacts()
+ public Set getArtifacts()
{
return artifacts;
}
- public Map getConflicts()
+ public Map getEntries()
{
- return conflicts;
+ return entries;
}
- public Map getArtifactsWithoutPoms()
+ public void addArtifact( MavenArtifact artifact, MavenProject project )
+ {
+
+ String id = artifact.getDependency().getId();
+
+ ArtifactCollectionResultEntry entry;
+
+ if ( entries.containsKey( id ) )
+ {
+ entry = ( ArtifactCollectionResultEntry ) entries.get( id );
+
+ entry.add( artifact, project );
+
+ }
+
+ else
+ {
+ artifacts.add( artifact );
+
+ entry = new ArtifactCollectionResultEntry( artifact, project );
+
+ entries.put( id , entry );
+ }
+
+ conflict = conflict && entry.isConflict();
+
+ }
+
+ public void addArtifactWithoutPom( String id )
+ {
+ artifactsWithoutPoms.add( id );
+ }
+
+ public Set getArtifactsWithoutPoms()
{
return artifactsWithoutPoms;
}
-}
+
+ public boolean isConflict()
+ {
+ return conflict;
+ }
+
+ /**
+ * @todo this is still not opimal but I prefer simpler code at the moment
+ */
+ public void merge( MavenProject project )
+ {
+ ArtifactCollectionResult other = project.getArtifactCollectionResult();
+
+ Set artifactSet = other.getArtifacts();
+
+ for ( Iterator iter = artifactSet.iterator(); iter.hasNext(); )
+ {
+ MavenArtifact artifact = ( MavenArtifact ) iter.next();
+
+
+ String id = artifact.getDependency().getId();
+
+ addArtifact( artifact, project );
+
+ ArtifactCollectionResultEntry entry = ( ArtifactCollectionResultEntry )
entries.get( id );
+
+ ArtifactCollectionResultEntry otherEntry = (
ArtifactCollectionResultEntry ) other.entries.get( id );
+
+ entry.merge( otherEntry );
+
+
+
+ }
+
+ artifactsWithoutPoms.addAll( other.getArtifactsWithoutPoms() );
+
+ }
+
+ public boolean hasArtifact( String id )
+ {
+ boolean retValue = false;
+
+ for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
+ {
+ MavenArtifact artifact = ( MavenArtifact ) iter.next();
+
+ if ( id.equals( artifact.getDependency().getId() ) )
+ {
+ retValue = true;
+
+ break;
+ }
+
+ }
+
+ return retValue;
+ }
+
+ public boolean hasArtifactWithoutPom( String id )
+ {
+ boolean retValue = artifactsWithoutPoms.contains( id );
+
+ return retValue;
+ }
+
+ public ArtifactCollectionResultEntry getEntry( String id )
+ {
+ ArtifactCollectionResultEntry retValue = ( ArtifactCollectionResultEntry )
entries.get( id );
+
+ return retValue;
+
+ }
+
+}
\ No newline at end of file
1.1
maven-components/maven-project/src/main/java/org/apache/maven/artifact/collector/ArtifactCollectionResultEntry.java
Index: ArtifactCollectionResultEntry.java
===================================================================
package org.apache.maven.artifact.collector;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.maven.artifact.MavenArtifact;
import org.apache.maven.project.MavenProject;
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Michal Maczka</a>
* @version $Id: ArtifactCollectionResultEntry.java,v 1.1 2004/05/17 21:11:33 michal
Exp $
*/
public class ArtifactCollectionResultEntry
{
private String id;
private Set versions = new HashSet();
private Set projects = new HashSet();
private Map projectVersionMap = new HashMap();
public boolean isConflict()
{
boolean retValue = versions.size() > 1;
return retValue;
}
public ArtifactCollectionResultEntry( MavenArtifact artifact, MavenProject
project )
{
this.id = artifact.getDependency().getId();
add( artifact, project );
}
public void add( MavenArtifact artifact, MavenProject project )
{
String version = artifact.getDependency().getVersion();
versions.add( version );
projects.add( project.getId() );
projectVersionMap.put( project.getId(), version );
}
public String getId()
{
return id;
}
public Set getProjects()
{
return projects;
}
public Map getProjectVersionMap()
{
return projectVersionMap;
}
public Set getVersions()
{
return versions;
}
/**
* @param otherEntry
*/
public void merge( ArtifactCollectionResultEntry other )
{
versions.addAll( other.versions );
projects.addAll( other.projects );
projectVersionMap.putAll( other.projectVersionMap );
}
}
1.13 +2 -0
maven-components/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
Index: DefaultMavenProjectBuilder.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- DefaultMavenProjectBuilder.java 8 May 2004 12:19:22 -0000 1.12
+++ DefaultMavenProjectBuilder.java 17 May 2004 21:11:34 -0000 1.13
@@ -105,6 +105,8 @@
setupMavenFinalName( project );
+ artifactCollector.collect( project, this );
+
project.initialize();
return project;
1.8 +25 -1
maven-components/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
Index: MavenProject.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-project/src/main/java/org/apache/maven/project/MavenProject.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- MavenProject.java 13 May 2004 19:25:59 -0000 1.7
+++ MavenProject.java 17 May 2004 21:11:34 -0000 1.8
@@ -17,6 +17,7 @@
*/
import org.apache.maven.artifact.MavenArtifact;
+import org.apache.maven.artifact.collector.ArtifactCollectionResult;
import org.apache.maven.model.Build;
import org.apache.maven.model.Contributor;
import org.apache.maven.model.Dependency;
@@ -84,6 +85,11 @@
/**List of remote repositories which are visible for this project */
private List repositories = new ArrayList();
+
+ /**
+ * @todo find shorter name for this
+ **/
+ private ArtifactCollectionResult artifactCollectionResult;
// ----------------------------------------------------------------------
// Accessors
@@ -917,6 +923,24 @@
addRepository( repository );
+ }
+
+ /**
+ * @return
+ */
+ public ArtifactCollectionResult getArtifactCollectionResult()
+ {
+
+ return artifactCollectionResult;
+ }
+
+ /**
+ * @return
+ */
+ public void setArtifactCollectionResult( ArtifactCollectionResult
artifactCollectionResult )
+ {
+
+ this.artifactCollectionResult = artifactCollectionResult ;
}
}
1.12 +3 -8
maven-components/maven-project/src/main/resources/META-INF/plexus/components.xml
Index: components.xml
===================================================================
RCS file:
/home/cvs/maven-components/maven-project/src/main/resources/META-INF/plexus/components.xml,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- components.xml 16 May 2004 15:58:10 -0000 1.11
+++ components.xml 17 May 2004 21:11:34 -0000 1.12
@@ -7,12 +7,10 @@
<requirement>
<role>org.apache.maven.project.ModelInheritanceAssembler</role>
</requirement>
-
- <!-- This introduces circ. dep. builder ==> collector ==> builder
+
<requirement>
<role>org.apache.maven.artifact.collector.ArtifactCollector</role>
- </requirement>
- -->
+ </requirement>
<requirement>
<role>org.apache.maven.artifact.factory.MavenArtifactFactory</role>
</requirement>
@@ -31,10 +29,7 @@
<requirements>
<requirement>
<role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
- </requirement>
- <requirement>
- <role>org.apache.maven.project.MavenProjectBuilder</role>
- </requirement>
+ </requirement>
</requirements>
</component>
<component>
1.2 +4 -0
maven-components/maven-project/src/test/resources/local-repo/maven-test/poms/maven-test-b-1.0.pom
Index: maven-test-b-1.0.pom
===================================================================
RCS file:
/home/cvs/maven-components/maven-project/src/test/resources/local-repo/maven-test/poms/maven-test-b-1.0.pom,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- maven-test-b-1.0.pom 10 May 2004 19:06:30 -0000 1.1
+++ maven-test-b-1.0.pom 17 May 2004 21:11:34 -0000 1.2
@@ -2,16 +2,20 @@
<groupId>maven-test</groupId>
<artifactId>maven-test-b</artifactId>
<version>1.0</version>
+
<dependencies>
+
<dependency>
<groupId>maven-test</groupId>
<artifactId>maven-test-c</artifactId>
<version>1.0</version>
</dependency>
+
<dependency>
<groupId>maven-test</groupId>
<artifactId>maven-test-d</artifactId>
<version>1.1</version>
</dependency>
+
</dependencies>
</project>
1.2 +2 -0
maven-components/maven-project/src/test/resources/local-repo/maven-test/poms/maven-test-c-1.0.pom
Index: maven-test-c-1.0.pom
===================================================================
RCS file:
/home/cvs/maven-components/maven-project/src/test/resources/local-repo/maven-test/poms/maven-test-c-1.0.pom,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- maven-test-c-1.0.pom 10 May 2004 19:06:30 -0000 1.1
+++ maven-test-c-1.0.pom 17 May 2004 21:11:34 -0000 1.2
@@ -2,6 +2,8 @@
<groupId>maven-test</groupId>
<artifactId>maven-test-c</artifactId>
<version>1.0</version>
+
+
<dependencies>
<dependency>
<groupId>maven-test</groupId>
1.2 +1 -1
maven-components/maven-project/src/test/resources/local-repo/maven-test/poms/maven-test-d-1.2.pom
Index: maven-test-d-1.2.pom
===================================================================
RCS file:
/home/cvs/maven-components/maven-project/src/test/resources/local-repo/maven-test/poms/maven-test-d-1.2.pom,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- maven-test-d-1.2.pom 10 May 2004 19:06:30 -0000 1.1
+++ maven-test-d-1.2.pom 17 May 2004 21:11:34 -0000 1.2
@@ -1,5 +1,5 @@
<project>
<groupId>maven-test</groupId>
- <artifactId>maven-test-d/artifactId>
+ <artifactId>maven-test-d</artifactId>
<version>1.1</version>
</project>
1.2 +3 -1
maven-components/maven-project/src/main/java/org/apache/maven/artifact/satisfier/ArtifactSatisfier.java
Index: ArtifactSatisfier.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-project/src/main/java/org/apache/maven/artifact/satisfier/ArtifactSatisfier.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ArtifactSatisfier.java 5 Apr 2004 17:23:56 -0000 1.1
+++ ArtifactSatisfier.java 17 May 2004 21:11:34 -0000 1.2
@@ -27,6 +27,8 @@
*/
public interface ArtifactSatisfier
{
+
+
static String ROLE = ArtifactSatisfier.class.getName();
public void verifyDependencies( MavenProject project )
1.6 +1 -3
maven-components/maven-project/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
Index: DefaultArtifactResolver.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-project/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultArtifactResolver.java 16 May 2004 15:58:10 -0000 1.5
+++ DefaultArtifactResolver.java 17 May 2004 21:11:34 -0000 1.6
@@ -36,8 +36,6 @@
{
MavenArtifact retValue = artifactFactory.createArtifact( dependency,
project.getLocalRepository() );
- System.out.println( "Checking: " + retValue.getPath() );
-
if ( retValue.isSnapshot() )
{
1.7 +14 -0
maven-components/maven-project/src/main/java/org/apache/maven/artifact/AbstractMavenArtifact.java
Index: AbstractMavenArtifact.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-project/src/main/java/org/apache/maven/artifact/AbstractMavenArtifact.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractMavenArtifact.java 10 May 2004 19:26:22 -0000 1.6
+++ AbstractMavenArtifact.java 17 May 2004 21:11:34 -0000 1.7
@@ -169,4 +169,18 @@
}
+
+ public boolean equals( Object obj )
+ {
+
+ MavenArtifact other = ( MavenArtifact ) obj;
+
+ Dependency otherDependency = other.getDependency();
+
+ //if paths are the same artifats are the same
+ boolean retValue = getPath().equals( other.getPath() );
+
+ return retValue;
+
+ }
}
1.3 +25 -23
maven-components/maven-project/src/test/java/org/apache/maven/artifact/collector/DefaultArtifactCollectorTest.java
Index: DefaultArtifactCollectorTest.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-project/src/test/java/org/apache/maven/artifact/collector/DefaultArtifactCollectorTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultArtifactCollectorTest.java 10 May 2004 19:06:30 -0000 1.2
+++ DefaultArtifactCollectorTest.java 17 May 2004 21:11:34 -0000 1.3
@@ -17,12 +17,11 @@
*/
import java.io.File;
-import java.util.List;
-import java.util.Map;
+import java.util.Set;
-import org.apache.maven.artifact.MavenArtifact;
import org.apache.maven.project.AbstractProjectTestCase;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
/**
*
@@ -50,8 +49,12 @@
artifactCollector = ( ArtifactCollector ) lookup( ArtifactCollector.ROLE );
+ projectBuilder = ( MavenProjectBuilder ) lookup( MavenProjectBuilder.ROLE );
+
assertNotNull( "Test artifactCollector can't be null!", artifactCollector );
+ System.setProperty( "maven.repo.local", getLocalRepository() );
+
System.out.println( "local repo:" + getLocalRepository() );
}
@@ -73,13 +76,11 @@
project.setLocalRepository( getLocalRepository() );
- ArtifactCollectionResult result = artifactCollector.getArtifacts(
project );
-
- Map artifacts = result.getArtifacts();
+ ArtifactCollectionResult result = artifactCollector.collect( project,
projectBuilder );
+
+ Set artifacts = result.getArtifacts();
- Map conflicts = result.getConflicts();
-
- Map artifactsWithoutPoms = result.getArtifactsWithoutPoms();
+ Set artifactsWithoutPoms = result.getArtifactsWithoutPoms();
// [d 1.1]
// |
@@ -87,32 +88,33 @@
// | |
// |---------------------- > [z] (no pom)
- assertTrue( artifacts.containsKey( "maven-test:maven-test-b" ) );
+ assertEquals( 4, artifacts.size() );
- assertTrue( artifacts.containsKey( "maven-test:maven-test-c" ) );
+ assertTrue( result.hasArtifact( "maven-test:maven-test-b" ) );
- assertTrue( artifacts.containsKey( "maven-test:maven-test-d" ) );
+ assertTrue( result.hasArtifact( "maven-test:maven-test-c" ) );
- assertTrue( artifacts.containsKey( "maven-test:maven-test-z" ) );
+ assertTrue( result.hasArtifact( "maven-test:maven-test-d" ) );
- assertTrue( artifactsWithoutPoms.containsKey(
"maven-test:maven-test-z" ) );
+ assertTrue( result.hasArtifact( "maven-test:maven-test-z" ) );
+ //assertTrue( result.isConflict() );
+
+ //assertEquals( 1, conflicts.size() );
- assertEquals( 1, conflicts.size() );
+ ArtifactCollectionResultEntry entryD = result.getEntry(
"maven-test:maven-test-d" );
- assertTrue( conflicts.containsKey( "maven-test:maven-test-d" ) );
+ assertNotNull( entryD );
- List conflictsForD = ( List ) conflicts.get( "maven-test:maven-test-d"
);
+ assertEquals( 2, entryD.getVersions().size() );
- assertEquals( 2,conflictsForD.size() );
+ assertTrue( entryD.isConflict() );
- MavenArtifact d_1_1 = ( MavenArtifact ) conflictsForD.get( 0 );
+ assertTrue( entryD.getVersions().contains( "1.2" ) );
- MavenArtifact d_1_2 = ( MavenArtifact ) conflictsForD.get( 1 );
+ assertTrue( entryD.getVersions().contains( "1.1" ) );
- assertEquals( "1.1", d_1_1.getDependency().getVersion() );
- assertEquals( "1.2", d_1_2.getDependency().getVersion() );
}
catch ( Exception e )
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]