You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by br...@apache.org on 2005/06/21 18:12:46 UTC
svn commit: r191675 - in /maven/components/trunk/maven-artifact: ./
src/main/java/org/apache/maven/artifact/factory/
src/main/java/org/apache/maven/artifact/resolver/
src/test/java/org/apache/maven/artifact/resolver/
Author: brett
Date: Tue Jun 21 09:12:44 2005
New Revision: 191675
URL: http://svn.apache.org/viewcvs?rev=191675&view=rev
Log:
add failing test for MNG-63
Added:
maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/CyclicDependencyException.java
Modified:
maven/components/trunk/maven-artifact/pom.xml
maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java
maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
Modified: maven/components/trunk/maven-artifact/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/pom.xml?rev=191675&r1=191674&r2=191675&view=diff
==============================================================================
--- maven/components/trunk/maven-artifact/pom.xml (original)
+++ maven/components/trunk/maven-artifact/pom.xml Tue Jun 21 09:12:44 2005
@@ -10,6 +10,12 @@
<dependencies>
<dependency>
<groupId>plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ <version>1.0-alpha-3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>1.0-alpha-3</version>
</dependency>
Modified: maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java?rev=191675&r1=191674&r2=191675&view=diff
==============================================================================
--- maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java (original)
+++ maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java Tue Jun 21 09:12:44 2005
@@ -27,6 +27,15 @@
// TODO: remove, it doesn't know the ones from the plugins
private ArtifactHandlerManager artifactHandlerManager;
+ public DefaultArtifactFactory()
+ {
+ }
+
+ public DefaultArtifactFactory( ArtifactHandlerManager artifactHandlerManager )
+ {
+ this.artifactHandlerManager = artifactHandlerManager;
+ }
+
public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type )
{
return createArtifact( groupId, artifactId, version, scope, type, null, null );
Added: maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/CyclicDependencyException.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/CyclicDependencyException.java?rev=191675&view=auto
==============================================================================
--- maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/CyclicDependencyException.java (added)
+++ maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/CyclicDependencyException.java Tue Jun 21 09:12:44 2005
@@ -0,0 +1,47 @@
+package org.apache.maven.artifact.resolver;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+import java.util.List;
+
+/**
+ * Indiciates a cycle in the dependency graph.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @version $Id$
+ */
+ public class CyclicDependencyException
+ extends ArtifactResolutionException
+{
+ public CyclicDependencyException( String message, String groupId, String artifactId, String version, String type,
+ List remoteRepositories, String downloadUrl, Throwable t )
+ {
+ super( message, groupId, artifactId, version, type, remoteRepositories, downloadUrl, t );
+ }
+
+ public CyclicDependencyException( String message, Artifact artifact, List remoteRepositories, Throwable t )
+ {
+ super( message, artifact, remoteRepositories, t );
+ }
+
+ public CyclicDependencyException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+}
Modified: maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java?rev=191675&r1=191674&r2=191675&view=diff
==============================================================================
--- maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java (original)
+++ maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java Tue Jun 21 09:12:44 2005
@@ -16,7 +16,19 @@
* limitations under the License.
*/
-import junit.framework.TestCase;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* Test the default artifact collector.
@@ -25,24 +37,101 @@
* @version $Id$
*/
public class DefaultArtifactCollectorTest
- extends TestCase
+ extends PlexusTestCase
{
private ArtifactCollector artifactCollector;
+ private ArtifactFactory artifactFactory;
+
+ private ArtifactSpec projectArtifact;
+
+ private Source source;
+
protected void setUp()
throws Exception
{
super.setUp();
+
+ this.source = new Source();
+ this.artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
this.artifactCollector = new DefaultArtifactCollector();
+
+ this.projectArtifact = createArtifact( "project", "1.0" );
}
public void testCircularDependencyNotIncludingCurrentProject()
+ throws ArtifactResolutionException
{
-
+ ArtifactSpec a = createArtifact( "a", "1.0" );
+ ArtifactSpec b = a.addDependency( "b", "1.0" );
+ b.addDependency( "a", "1.0" );
+ try
+ {
+ collect( a );
+// fail( "Should have failed on cyclic dependency not involving project" );
+ }
+ catch ( CyclicDependencyException expected )
+ {
+ assertTrue( true );
+ }
}
public void testCircularDependencyIncludingCurrentProject()
+ throws ArtifactResolutionException
+ {
+ ArtifactSpec a = createArtifact( "a", "1.0" );
+ ArtifactSpec b = a.addDependency( "b", "1.0" );
+ b.addDependency( "project", "1.0" );
+ try
+ {
+ collect( a );
+// fail( "Should have failed on cyclic dependency involving project" );
+ }
+ catch ( CyclicDependencyException expected )
+ {
+ assertTrue( true );
+ }
+ }
+
+ private void collect( ArtifactSpec a )
+ throws ArtifactResolutionException
+ {
+ artifactCollector.collect( Collections.singleton( a.artifact ), projectArtifact.artifact, null, null, source,
+ null, artifactFactory );
+ }
+
+ private ArtifactSpec createArtifact( String id, String version )
+ {
+ ArtifactSpec spec = new ArtifactSpec();
+ spec.artifact = artifactFactory.createArtifact( "test", id, version, null, "jar" );
+ source.artifacts.put( spec.artifact.getId(), spec );
+ return spec;
+ }
+
+ private class ArtifactSpec
+ {
+ Artifact artifact;
+
+ Set dependencies = new HashSet();
+
+ public ArtifactSpec addDependency( String id, String version )
+ {
+ ArtifactSpec dep = createArtifact( id, version );
+ dependencies.add( dep.artifact );
+ return dep;
+ }
+ }
+
+ private static class Source
+ implements ArtifactMetadataSource
{
+ Map artifacts = new HashMap();
+ public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
+ throws ArtifactMetadataRetrievalException, ArtifactResolutionException
+ {
+ ArtifactSpec a = (ArtifactSpec) artifacts.get( artifact.getId() );
+ return a.dependencies;
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org