diff options
author | Olivier Lamy <olamy@apache.org> | 2011-05-26 20:54:05 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2011-05-26 20:54:05 +0000 |
commit | 2816105cf3e3e4c1d6f43493b212008a9334f95f (patch) | |
tree | d38732282cdbf5bdde88d32c5a52694ea9f14879 /archiva-modules | |
parent | 22961f8dc45109662e5d10bb35df60ee79683eda (diff) | |
download | archiva-2816105cf3e3e4c1d6f43493b212008a9334f95f.tar.gz archiva-2816105cf3e3e4c1d6f43493b212008a9334f95f.zip |
[MRM-1473] remove plexus-spring
fix maven2-repository module
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1128079 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
12 files changed, 210 insertions, 98 deletions
diff --git a/archiva-modules/plugins/maven2-repository/pom.xml b/archiva-modules/plugins/maven2-repository/pom.xml index 07ced4f9e..e6b3f647d 100644 --- a/archiva-modules/plugins/maven2-repository/pom.xml +++ b/archiva-modules/plugins/maven2-repository/pom.xml @@ -41,12 +41,15 @@ <groupId>org.sonatype.sisu</groupId> <artifactId>sisu-inject-plexus</artifactId> </dependency> - <dependency> <groupId>org.sonatype.sisu</groupId> <artifactId>sisu-guice</artifactId> </dependency> <dependency> + <groupId>org.apache.archiva</groupId> + <artifactId>archiva-plexus-bridge</artifactId> + </dependency> + <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging-api</artifactId> <scope>test</scope> diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/DefaultDependencyTreeBuilder.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/DefaultDependencyTreeBuilder.java index bd53424c1..12db707ea 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/DefaultDependencyTreeBuilder.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/DefaultDependencyTreeBuilder.java @@ -19,6 +19,7 @@ package org.apache.archiva.dependency.tree.maven2; * under the License. */ +import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.metadata.repository.MetadataResolutionException; import org.apache.archiva.metadata.repository.MetadataResolver; import org.apache.archiva.metadata.repository.RepositorySession; @@ -26,6 +27,7 @@ import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; import org.apache.archiva.metadata.repository.storage.maven2.RepositoryModelResolver; import org.apache.commons.lang.StringUtils; +import org.apache.maven.archiva.common.utils.Slf4JPlexusLogger; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.artifact.Artifact; @@ -63,8 +65,14 @@ import org.apache.maven.shared.dependency.tree.traversal.BuildingDependencyNodeV import org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor; import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor; import org.apache.maven.shared.dependency.tree.traversal.FilteringDependencyNodeVisitor; -import org.codehaus.plexus.logging.AbstractLogEnabled; - +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.inject.Named; import java.io.File; import java.util.ArrayList; import java.util.Collection; @@ -79,50 +87,71 @@ import java.util.Set; * Default implementation of <code>DependencyTreeBuilder</code>. Customized wrapper for maven-dependency-tree to use * maven-model-builder instead of maven-project. Note that the role must differ to avoid conflicting with the * maven-shared implementation. - * - * @plexus.component role="org.apache.archiva.dependency.tree.maven2.DependencyTreeBuilder" role-hint="maven2" + * <p/> + * plexus.component role="org.apache.archiva.dependency.tree.maven2.DependencyTreeBuilder" role-hint="maven2" */ +@Service( "dependencyTreeBuilder#maven2" ) public class DefaultDependencyTreeBuilder - extends AbstractLogEnabled implements DependencyTreeBuilder { + + private Logger log = LoggerFactory.getLogger( getClass() ); + /** - * @plexus.requirement + * plexus.requirement */ private ArtifactFactory factory; /** - * @plexus.requirement + * plexus.requirement */ private ArtifactCollector collector; /** - * @plexus.requirement + * plexus.requirement */ private ModelBuilder builder; /** * TODO: can have other types, and this might eventually come through from the main request - * - * @plexus.requirement + * <p/> + * plexus.requirement */ + @Inject private RepositorySessionFactory repositorySessionFactory; /** - * @plexus.requirement role-hint="maven2" + * plexus.requirement role-hint="maven2" */ + @Inject + @Named( value = "repositoryPathTranslator#maven2" ) private RepositoryPathTranslator pathTranslator; /** - * @plexus.requirement + * plexus.requirement */ + @Inject + @Named( value = "archivaConfiguration#default" ) private ArchivaConfiguration archivaConfiguration; + @Inject + private PlexusSisuBridge plexusSisuBridge; + + @PostConstruct + public void initialize() + throws ComponentLookupException + { + factory = plexusSisuBridge.lookup( ArtifactFactory.class ); + collector = plexusSisuBridge.lookup( ArtifactCollector.class ); + builder = plexusSisuBridge.lookup( ModelBuilder.class ); + } + public void buildDependencyTree( List<String> repositoryIds, String groupId, String artifactId, String version, DependencyNodeVisitor nodeVisitor ) throws DependencyTreeBuilderException { - DependencyTreeResolutionListener listener = new DependencyTreeResolutionListener( getLogger() ); + DependencyTreeResolutionListener listener = + new DependencyTreeResolutionListener( new Slf4JPlexusLogger( getClass() ) ); Artifact projectArtifact = factory.createProjectArtifact( groupId, artifactId, version ); File basedir = findArtifactInRepositories( repositoryIds, projectArtifact ); @@ -135,8 +164,8 @@ public class DefaultDependencyTreeBuilder try { - Model model = buildProject( new RepositoryModelResolver( basedir, pathTranslator ), groupId, artifactId, - version ); + Model model = + buildProject( new RepositoryModelResolver( basedir, pathTranslator ), groupId, artifactId, version ); Map managedVersions = createManagedVersionMap( model ); @@ -145,8 +174,8 @@ public class DefaultDependencyTreeBuilder RepositorySession repositorySession = repositorySessionFactory.createSession(); try { - ArtifactMetadataSource metadataSource = new MetadataArtifactMetadataSource( repositoryIds, - repositorySession ); + ArtifactMetadataSource metadataSource = + new MetadataArtifactMetadataSource( repositoryIds, repositorySession ); // Note that we don't permit going to external repositories. We don't need to pass in a local and remote // since our metadata source has control over them @@ -164,12 +193,12 @@ public class DefaultDependencyTreeBuilder DependencyNodeVisitor visitor = new BuildingDependencyNodeVisitor( nodeVisitor ); CollectingDependencyNodeVisitor collectingVisitor = new CollectingDependencyNodeVisitor(); - DependencyNodeVisitor firstPassVisitor = new FilteringDependencyNodeVisitor( collectingVisitor, - StateDependencyNodeFilter.INCLUDED ); + DependencyNodeVisitor firstPassVisitor = + new FilteringDependencyNodeVisitor( collectingVisitor, StateDependencyNodeFilter.INCLUDED ); rootNode.accept( firstPassVisitor ); - DependencyNodeFilter secondPassFilter = new AncestorOrSelfDependencyNodeFilter( - collectingVisitor.getNodes() ); + DependencyNodeFilter secondPassFilter = + new AncestorOrSelfDependencyNodeFilter( collectingVisitor.getNodes() ); visitor = new FilteringDependencyNodeVisitor( visitor, secondPassFilter ); rootNode.accept( visitor ); @@ -202,8 +231,8 @@ public class DefaultDependencyTreeBuilder File repoDir = new File( repositoryConfiguration.getLocation() ); File file = pathTranslator.toFile( repoDir, projectArtifact.getGroupId(), projectArtifact.getArtifactId(), projectArtifact.getBaseVersion(), - projectArtifact.getArtifactId() + "-" + projectArtifact.getVersion() + - ".pom" ); + projectArtifact.getArtifactId() + "-" + projectArtifact.getVersion() + + ".pom" ); if ( file.exists() ) { @@ -245,10 +274,10 @@ public class DefaultDependencyTreeBuilder } VersionRange versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() ); - Artifact artifact = factory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(), - versionRange, dependency.getType(), - dependency.getClassifier(), scope, null, - dependency.isOptional() ); + Artifact artifact = + factory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(), versionRange, + dependency.getType(), dependency.getClassifier(), scope, null, + dependency.isOptional() ); if ( Artifact.SCOPE_SYSTEM.equals( scope ) ) { @@ -307,8 +336,8 @@ public class DefaultDependencyTreeBuilder Map<String, Artifact> map = null; List<Dependency> deps; - if ( ( dependencyManagement != null ) && ( ( deps = dependencyManagement.getDependencies() ) != null ) && - ( deps.size() > 0 ) ) + if ( ( dependencyManagement != null ) && ( ( deps = dependencyManagement.getDependencies() ) != null ) && ( + deps.size() > 0 ) ) { map = new ManagedVersionMap( map ); @@ -317,14 +346,12 @@ public class DefaultDependencyTreeBuilder VersionRange versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() ); - Artifact artifact = factory.createDependencyArtifact( dependency.getGroupId(), - dependency.getArtifactId(), versionRange, - dependency.getType(), dependency.getClassifier(), - dependency.getScope(), dependency.isOptional() ); - if ( getLogger().isDebugEnabled() ) - { - getLogger().debug( " " + artifact ); - } + Artifact artifact = + factory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(), versionRange, + dependency.getType(), dependency.getClassifier(), + dependency.getScope(), dependency.isOptional() ); + + log.debug( "artifact {}", artifact ); // If the dependencyManagement section listed exclusions, // add them to the managed artifacts here so that transitive @@ -379,8 +406,9 @@ public class DefaultDependencyTreeBuilder // TODO: we removed relocation support here. This is something that might need to be generically handled // throughout this module - Artifact pomArtifact = factory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), - artifact.getVersion(), artifact.getScope() ); + Artifact pomArtifact = + factory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), + artifact.getScope() ); File basedir = findArtifactInRepositories( repositoryIds, pomArtifact ); @@ -389,8 +417,9 @@ public class DefaultDependencyTreeBuilder { try { - project = buildProject( new RepositoryModelResolver( basedir, pathTranslator ), - artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ); + project = + buildProject( new RepositoryModelResolver( basedir, pathTranslator ), artifact.getGroupId(), + artifact.getArtifactId(), artifact.getVersion() ); } catch ( ModelBuildingException e ) { @@ -460,4 +489,9 @@ public class DefaultDependencyTreeBuilder return new ArrayList<ArtifactVersion>( versions ); } } + + public ArtifactFactory getFactory() + { + return factory; + } } diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java index 223db1ffb..e58ff70c3 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java @@ -21,6 +21,7 @@ package org.apache.archiva.metadata.repository.storage.maven2; import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.checksum.ChecksummedFile; +import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; @@ -41,13 +42,14 @@ import org.apache.maven.model.MailingList; import org.apache.maven.model.Model; import org.apache.maven.model.Organization; import org.apache.maven.model.Scm; -import org.apache.maven.model.building.DefaultModelBuilder; import org.apache.maven.model.building.DefaultModelBuildingRequest; import org.apache.maven.model.building.ModelBuilder; import org.apache.maven.model.building.ModelBuildingException; import org.apache.maven.model.building.ModelBuildingRequest; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; import javax.inject.Inject; @@ -67,41 +69,47 @@ import java.util.List; * deal with rather than being instantiated per-repository. * FIXME: instantiate one per repository and allocate permanently from a factory (which can be obtained within the session). * TODO: finish Maven 1 implementation to prove this API - * + * <p/> * The session is passed in as an argument to obtain any necessary resources, rather than the class being instantiated * within the session in the context of a single managed repository's resolution needs. - * + * <p/> * plexus.component role="org.apache.archiva.metadata.repository.storage.RepositoryStorage" role-hint="maven2" */ +@Service("repositoryStorage#maven2") public class Maven2RepositoryStorage implements RepositoryStorage { /** - * @plexus.requirement + * plexus.requirement */ - private ModelBuilder builders; + private ModelBuilder builder; /** * plexus.requirement */ - @Inject @Named(value = "archivaConfiguration#default") + @Inject + @Named( value = "archivaConfiguration#default" ) private ArchivaConfiguration archivaConfiguration; /** * plexus.requirement role-hint="maven2" */ - @Inject @Named(value = "repositoryPathTranslator#maven2") + @Inject + @Named( value = "repositoryPathTranslator#maven2" ) private RepositoryPathTranslator pathTranslator; private final static Logger log = LoggerFactory.getLogger( Maven2RepositoryStorage.class ); private static final String METADATA_FILENAME = "maven-metadata.xml"; + @Inject + private PlexusSisuBridge plexusSisuBridge; + @PostConstruct public void initialize() + throws ComponentLookupException { - // - ou ou + builder = plexusSisuBridge.lookup( ModelBuilder.class ); } public ProjectMetadata readProjectMetadata( String repoId, String namespace, String projectId ) @@ -122,8 +130,8 @@ public class Maven2RepositoryStorage File basedir = new File( repositoryConfiguration.getLocation() ); if ( VersionUtil.isSnapshot( projectVersion ) ) { - File metadataFile = pathTranslator.toFile( basedir, namespace, projectId, projectVersion, - METADATA_FILENAME ); + File metadataFile = + pathTranslator.toFile( basedir, namespace, projectId, projectVersion, METADATA_FILENAME ); try { MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read( metadataFile ); @@ -132,8 +140,8 @@ public class Maven2RepositoryStorage MavenRepositoryMetadata.Snapshot snapshotVersion = metadata.getSnapshotVersion(); if ( snapshotVersion != null ) { - artifactVersion = artifactVersion.substring( 0, artifactVersion.length() - - 8 ); // remove SNAPSHOT from end + artifactVersion = + artifactVersion.substring( 0, artifactVersion.length() - 8 ); // remove SNAPSHOT from end artifactVersion = artifactVersion + snapshotVersion.getTimestamp() + "-" + snapshotVersion.getBuildNumber(); } @@ -443,8 +451,8 @@ public class Maven2RepositoryStorage private ArtifactMetadata getArtifactFromFile( String repoId, String namespace, String projectId, String projectVersion, File file ) { - ArtifactMetadata metadata = pathTranslator.getArtifactFromId( repoId, namespace, projectId, projectVersion, - file.getName() ); + ArtifactMetadata metadata = + pathTranslator.getArtifactFromId( repoId, namespace, projectId, projectVersion, file.getName() ); populateArtifactMetadataFromFile( metadata, file ); diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacetFactory.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacetFactory.java index 002eaf755..89ceaeb7a 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacetFactory.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacetFactory.java @@ -21,10 +21,12 @@ package org.apache.archiva.metadata.repository.storage.maven2; import org.apache.archiva.metadata.model.MetadataFacet; import org.apache.archiva.metadata.model.MetadataFacetFactory; +import org.springframework.stereotype.Service; /** - * @plexus.component role="org.apache.archiva.metadata.model.MetadataFacetFactory" role-hint="org.apache.archiva.metadata.repository.storage.maven2.artifact" + * plexus.component role="org.apache.archiva.metadata.model.MetadataFacetFactory" role-hint="org.apache.archiva.metadata.repository.storage.maven2.artifact" */ +@Service("metadataFacetFactory#org.apache.archiva.metadata.repository.storage.maven2.artifact") public class MavenArtifactFacetFactory implements MetadataFacetFactory { diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java index 81a99b910..84e145300 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java @@ -21,10 +21,12 @@ package org.apache.archiva.metadata.repository.storage.maven2; import org.apache.archiva.metadata.model.MetadataFacet; import org.apache.archiva.metadata.model.MetadataFacetFactory; +import org.springframework.stereotype.Service; /** - * @plexus.component role="org.apache.archiva.metadata.model.MetadataFacetFactory" role-hint="org.apache.archiva.metadata.repository.storage.maven2.project" + * plexus.component role="org.apache.archiva.metadata.model.MetadataFacetFactory" role-hint="org.apache.archiva.metadata.repository.storage.maven2.project" */ +@Service( "metadataFacetFactory#org.apache.archiva.metadata.repository.storage.maven2.project" ) public class MavenProjectFacetFactory implements MetadataFacetFactory { diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java index 03fa407c3..d59ae0d09 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java @@ -6,6 +6,7 @@ import org.apache.maven.archiva.configuration.ConfigurationListener; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; import org.codehaus.plexus.registry.RegistryException; import org.codehaus.plexus.registry.RegistryListener; +import org.springframework.stereotype.Service; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -26,6 +27,7 @@ import org.codehaus.plexus.registry.RegistryListener; * under the License. */ +@Service("archivaConfiguration#test") public class TestConfiguration implements ArchivaConfiguration { diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTest.java index b0059ccb6..7a8a5282d 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTest.java @@ -19,6 +19,7 @@ package org.apache.archiva.dependency.tree.maven2; * under the License. */ +import junit.framework.TestCase; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; @@ -28,14 +29,25 @@ import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.shared.dependency.tree.DependencyNode; import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException; import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.easymock.MockControl; - +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import javax.inject.Inject; +import javax.inject.Named; +import java.io.File; import java.util.Collections; +@RunWith( SpringJUnit4ClassRunner.class ) +@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} ) public class DependencyTreeBuilderTest - extends PlexusInSpringTestCase + extends TestCase { + @Inject + @Named (value = "dependencyTreeBuilder#maven2") private DependencyTreeBuilder builder; private static final String TEST_REPO_ID = "test"; @@ -48,25 +60,26 @@ public class DependencyTreeBuilderTest private ArtifactFactory artifactFactory; - @Override - protected void setUp() + @Inject @Named(value = "archivaConfiguration#test") + ArchivaConfiguration config; + + @Before + public void setUp() throws Exception { super.setUp(); - ArchivaConfiguration config = (ArchivaConfiguration) lookup( ArchivaConfiguration.class ); - Configuration configuration = new Configuration(); ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration(); repoConfig.setId( TEST_REPO_ID ); - repoConfig.setLocation( getTestPath( "target/test-repository" ) ); + repoConfig.setLocation( new File( "target/test-repository" ).getAbsolutePath() ); configuration.addManagedRepository( repoConfig ); config.save( configuration ); - builder = (DependencyTreeBuilder) lookup( DependencyTreeBuilder.class, "maven2" ); - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.class ); + artifactFactory = ((DefaultDependencyTreeBuilder)this.builder).getFactory(); } + @Test public void testBuilder() throws DependencyTreeBuilderException { @@ -250,6 +263,7 @@ public class DependencyTreeBuilderTest return createArtifact( groupId, artifactId, version, Artifact.SCOPE_COMPILE ); } + @Test public void testBuilderMissingDependency() throws DependencyTreeBuilderException { diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java index 499223e17..3d5760765 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java @@ -24,6 +24,7 @@ import org.apache.archiva.metadata.model.MetadataFacet; import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionReference; +import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Collection; @@ -32,6 +33,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +@Service public class TestMetadataRepository implements MetadataRepository { diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataResolver.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataResolver.java index f220146d1..319df0f23 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataResolver.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataResolver.java @@ -22,10 +22,12 @@ package org.apache.archiva.metadata.repository; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionReference; +import org.springframework.stereotype.Service; import java.util.Collection; // FIXME: remove - this is useless, better to mock it or avoid needing it +@Service( "metadataResolver#test" ) public class TestMetadataResolver implements MetadataResolver { diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java index 4827e786d..531b90534 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java @@ -1,24 +1,26 @@ package org.apache.archiva.metadata.repository; -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.springframework.stereotype.Service; +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you 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. +*/ +@Service public class TestRepositorySessionFactory implements RepositorySessionFactory { diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java index ec07a00a8..65002297e 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java @@ -19,6 +19,7 @@ package org.apache.archiva.metadata.repository.storage.maven2; * under the License. */ +import junit.framework.TestCase; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.Dependency; import org.apache.archiva.metadata.model.License; @@ -27,14 +28,20 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.repository.filter.AllFilter; import org.apache.archiva.metadata.repository.filter.ExcludesFilter; import org.apache.archiva.metadata.repository.filter.Filter; -import org.apache.archiva.metadata.repository.storage.RepositoryStorage; import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException; import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; - +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import javax.inject.Inject; +import javax.inject.Named; +import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -42,11 +49,15 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +@RunWith( SpringJUnit4ClassRunner.class ) +@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} ) public class Maven2RepositoryMetadataResolverTest - extends PlexusInSpringTestCase + extends TestCase { private static final Filter<String> ALL = new AllFilter<String>(); + @Inject + @Named(value = "repositoryStorage#maven2") private Maven2RepositoryStorage storage; private static final String TEST_REPO_ID = "test"; @@ -61,22 +72,27 @@ public class Maven2RepositoryMetadataResolverTest private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709"; + @Inject + private ArchivaConfiguration configuration; + + @Before public void setUp() throws Exception { super.setUp(); - ArchivaConfiguration configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class ); + //ArchivaConfiguration configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class ); Configuration c = new Configuration(); ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration(); testRepo.setId( TEST_REPO_ID ); - testRepo.setLocation( getTestPath( "target/test-repository" ) ); + testRepo.setLocation( new File( "target/test-repository" ).getAbsolutePath() ); c.addManagedRepository( testRepo ); configuration.save( c ); - storage = (Maven2RepositoryStorage) lookup( RepositoryStorage.class, "maven2" ); + //storage = (Maven2RepositoryStorage) lookup( RepositoryStorage.class, "maven2" ); } + @Test public void testGetProjectVersionMetadata() throws Exception { @@ -131,6 +147,7 @@ public class Maven2RepositoryMetadataResolverTest assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" ); } + @Test public void testGetArtifactMetadata() throws Exception { @@ -173,6 +190,7 @@ public class Maven2RepositoryMetadataResolverTest assertEquals( "pom", facet.getType() ); } + @Test public void testGetArtifactMetadataSnapshots() throws Exception { @@ -256,6 +274,7 @@ public class Maven2RepositoryMetadataResolverTest assertNull( dependency.getSystemPath() ); } + @Test public void testGetProjectVersionMetadataForTimestampedSnapshot() throws Exception { @@ -293,6 +312,7 @@ public class Maven2RepositoryMetadataResolverTest assertEquals( Collections.<Dependency>emptyList(), metadata.getDependencies() ); } + @Test public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata() throws Exception { @@ -307,6 +327,7 @@ public class Maven2RepositoryMetadataResolverTest } } + @Test public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata() throws Exception { @@ -322,6 +343,7 @@ public class Maven2RepositoryMetadataResolverTest } } + @Test public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata() throws Exception { @@ -337,6 +359,7 @@ public class Maven2RepositoryMetadataResolverTest } } + @Test public void testGetProjectVersionMetadataForInvalidPom() throws Exception { @@ -351,6 +374,7 @@ public class Maven2RepositoryMetadataResolverTest } } + @Test public void testGetProjectVersionMetadataForMislocatedPom() throws Exception { @@ -365,6 +389,7 @@ public class Maven2RepositoryMetadataResolverTest } } + @Test public void testGetProjectVersionMetadataForMissingPom() throws Exception { @@ -379,11 +404,13 @@ public class Maven2RepositoryMetadataResolverTest } } + @Test public void testGetRootNamespaces() { assertEquals( Arrays.asList( "com", "org" ), storage.listRootNamespaces( TEST_REPO_ID, ALL ) ); } + @Test public void testGetNamespaces() { assertEquals( Arrays.asList( "example" ), storage.listNamespaces( TEST_REPO_ID, "com", ALL ) ); @@ -407,6 +434,7 @@ public class Maven2RepositoryMetadataResolverTest ALL ) ); } + @Test public void testGetProjects() { assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com", ALL ) ); @@ -427,6 +455,7 @@ public class Maven2RepositoryMetadataResolverTest "org.apache.maven.shared", ALL ) ); } + @Test public void testGetProjectVersions() { assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test", @@ -458,6 +487,7 @@ public class Maven2RepositoryMetadataResolverTest "maven-downloader", ALL ) ); } + @Test public void testGetArtifacts() { List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata( TEST_REPO_ID, @@ -480,6 +510,7 @@ public class Maven2RepositoryMetadataResolverTest "f83aa25f016212a551a4b2249985effc" ); } + @Test public void testGetArtifactsFiltered() { ExcludesFilter<String> filter = new ExcludesFilter<String>( Collections.singletonList( @@ -502,6 +533,7 @@ public class Maven2RepositoryMetadataResolverTest assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 ); } + @Test public void testGetArtifactsTimestampedSnapshots() { List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata( TEST_REPO_ID, diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MavenRepositoryMetadataReaderTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MavenRepositoryMetadataReaderTest.java index 87ce9351a..d2fb4b315 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MavenRepositoryMetadataReaderTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MavenRepositoryMetadataReaderTest.java @@ -19,8 +19,12 @@ package org.apache.archiva.metadata.repository.storage.maven2; * under the License. */ +import junit.framework.TestCase; import org.apache.maven.archiva.xml.XMLException; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import java.io.File; import java.util.Arrays; @@ -30,11 +34,13 @@ import java.util.Arrays; * * @version $Id$ */ +@RunWith( JUnit4.class ) public class MavenRepositoryMetadataReaderTest - extends PlexusInSpringTestCase + extends TestCase { private File defaultRepoDir; + @Test public void testGroupMetadata() throws XMLException { @@ -69,6 +75,7 @@ public class MavenRepositoryMetadataReaderTest assertEquals( Arrays.asList( cleanPlugin, compilerPlugin, surefirePlugin ), metadata.getPlugins() ); } + @Test public void testProjectMetadata() throws XMLException { @@ -86,6 +93,7 @@ public class MavenRepositoryMetadataReaderTest assertEquals( "20061212214311", metadata.getLastUpdated() ); } + @Test public void testProjectVersionMetadata() throws XMLException { @@ -105,10 +113,11 @@ public class MavenRepositoryMetadataReaderTest assertEquals( "20080801151215", metadata.getLastUpdated() ); } - protected void setUp() + @Before + public void setUp() throws Exception { super.setUp(); - defaultRepoDir = new File( getBasedir(), "target/test-repository" ); + defaultRepoDir = new File( "target/test-repository" ); } }
\ No newline at end of file |