mirror of https://github.com/apache/maven.git
add failing test for MNG-63
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191675 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e90ba206d3
commit
ea5bbda3e0
|
@ -8,6 +8,12 @@
|
|||
<artifactId>maven-artifact</artifactId>
|
||||
<name>Maven Artifact</name>
|
||||
<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>
|
||||
|
|
|
@ -27,6 +27,15 @@ public class DefaultArtifactFactory
|
|||
// 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 );
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
|
@ -16,7 +16,19 @@ package org.apache.maven.artifact.resolver;
|
|||
* 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 @@ import junit.framework.TestCase;
|
|||
* @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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue