From 84f7fdad794712820950be6c2e18cadf9693238e Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 26 May 2011 20:54:42 +0000 Subject: [PATCH] [MRM-1473] remove of plexus-spring : fix archiva converter git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1128081 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva-base/archiva-converter/pom.xml | 4 ++ .../DefaultLegacyRepositoryConverter.java | 52 ++++++++++++------- .../LegacyConverterArtifactConsumer.java | 41 +++++++++------ .../converter/RepositoryConverterTest.java | 50 ++++++++++++------ .../src/test/resources/spring-context.xml | 31 +++++++++++ 5 files changed, 127 insertions(+), 51 deletions(-) create mode 100644 archiva-modules/archiva-base/archiva-converter/src/test/resources/spring-context.xml diff --git a/archiva-modules/archiva-base/archiva-converter/pom.xml b/archiva-modules/archiva-base/archiva-converter/pom.xml index 0552ef742..25b1888e0 100644 --- a/archiva-modules/archiva-base/archiva-converter/pom.xml +++ b/archiva-modules/archiva-base/archiva-converter/pom.xml @@ -44,6 +44,10 @@ org.apache.archiva archiva-repository-scanner + + org.apache.archiva + archiva-plexus-bridge + org.codehaus.plexus plexus-i18n diff --git a/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java b/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java index ddeafce7a..402bb70cc 100644 --- a/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java +++ b/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java @@ -19,12 +19,7 @@ package org.apache.maven.archiva.converter.legacy; * under the License. */ -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - +import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.repository.scanner.RepositoryScanner; import org.apache.archiva.repository.scanner.RepositoryScannerException; import org.apache.maven.archiva.common.utils.PathUtil; @@ -35,39 +30,59 @@ import org.apache.maven.archiva.converter.RepositoryConversionException; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.springframework.stereotype.Service; +import javax.inject.Inject; +import javax.inject.Named; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + /** - * DefaultLegacyRepositoryConverter + * DefaultLegacyRepositoryConverter * * @version $Id$ - * plexus.component + * plexus.component */ -@Service("legacyRepositoryConverter#default") +@Service( "legacyRepositoryConverter#default" ) public class DefaultLegacyRepositoryConverter implements LegacyRepositoryConverter { /** - * @plexus.requirement + * plexus.requirement */ private ArtifactRepositoryFactory artifactRepositoryFactory; /** - * @plexus.requirement role-hint="default" + * plexus.requirement role-hint="default" */ private ArtifactRepositoryLayout defaultLayout; /** - * @plexus.requirement role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" - * role-hint="artifact-legacy-to-default-converter" + * plexus.requirement role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" + * role-hint="artifact-legacy-to-default-converter" */ + @Inject + @Named( value = "knownRepositoryContentConsumer#artifact-legacy-to-default-converter" ) private LegacyConverterArtifactConsumer legacyConverterConsumer; /** - * @plexus.requirement + * plexus.requirement */ + @Inject private RepositoryScanner repoScanner; + @Inject + public DefaultLegacyRepositoryConverter( PlexusSisuBridge plexusSisuBridge ) + throws ComponentLookupException + { + artifactRepositoryFactory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class ); + defaultLayout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" ); + } + public void convertLegacyRepository( File legacyRepositoryDirectory, File repositoryDirectory, List fileExclusionPatterns ) throws RepositoryConversionException @@ -77,15 +92,14 @@ public class DefaultLegacyRepositoryConverter String defaultRepositoryUrl = PathUtil.toUrl( repositoryDirectory ); ManagedRepositoryConfiguration legacyRepository = new ManagedRepositoryConfiguration(); - legacyRepository.setId( "legacy"); + legacyRepository.setId( "legacy" ); legacyRepository.setName( "Legacy Repository" ); legacyRepository.setLocation( legacyRepositoryDirectory.getAbsolutePath() ); legacyRepository.setLayout( "legacy" ); - ArtifactRepository repository = artifactRepositoryFactory.createArtifactRepository( "default", - defaultRepositoryUrl, - defaultLayout, null, - null ); + ArtifactRepository repository = + artifactRepositoryFactory.createArtifactRepository( "default", defaultRepositoryUrl, defaultLayout, + null, null ); legacyConverterConsumer.setExcludes( fileExclusionPatterns ); legacyConverterConsumer.setDestinationRepository( repository ); diff --git a/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyConverterArtifactConsumer.java b/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyConverterArtifactConsumer.java index a7f73843d..5a9c41812 100644 --- a/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyConverterArtifactConsumer.java +++ b/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyConverterArtifactConsumer.java @@ -19,10 +19,7 @@ package org.apache.maven.archiva.converter.legacy; * under the License. */ -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - +import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; import org.apache.maven.archiva.consumers.ConsumerException; @@ -36,53 +33,63 @@ import org.apache.maven.archiva.repository.layout.LayoutException; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + /** * LegacyConverterArtifactConsumer - convert artifacts as they are found - * into the destination repository. + * into the destination repository. * * @version $Id$ - * - * plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" - * role-hint="artifact-legacy-to-default-converter" - * instantiation-strategy="per-lookup" + *

+ * plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" + * role-hint="artifact-legacy-to-default-converter" + * instantiation-strategy="per-lookup" */ -@Service("knownRepositoryContentConsumer#artifact-legacy-to-default-converter") -@Scope("prototype") +@Service( "knownRepositoryContentConsumer#artifact-legacy-to-default-converter" ) +@Scope( "prototype" ) public class LegacyConverterArtifactConsumer extends AbstractMonitoredConsumer implements KnownRepositoryContentConsumer { private Logger log = LoggerFactory.getLogger( LegacyConverterArtifactConsumer.class ); - + /** - * @plexus.requirement role-hint="legacy-to-default" + * plexus.requirement role-hint="legacy-to-default" */ + @Inject private ArtifactConverter artifactConverter; /** - * @plexus.requirement + * plexus.requirement */ private ArtifactFactory artifactFactory; private ManagedRepositoryContent managedRepository; - + private ArtifactRepository destinationRepository; private List includes; private List excludes; - public LegacyConverterArtifactConsumer() + @Inject + public LegacyConverterArtifactConsumer( PlexusSisuBridge plexusSisuBridge ) + throws ComponentLookupException { includes = new ArrayList(); includes.add( "**/*.jar" ); includes.add( "**/*.ear" ); includes.add( "**/*.war" ); + artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class ); } public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered ) @@ -100,7 +107,7 @@ public class LegacyConverterArtifactConsumer public void completeScan() { - + // no op } public void completeScan( boolean executeOnEntireRepo ) diff --git a/archiva-modules/archiva-base/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java b/archiva-modules/archiva-base/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java index e8da73550..3113639cf 100644 --- a/archiva-modules/archiva-base/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java +++ b/archiva-modules/archiva-base/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java @@ -19,18 +19,26 @@ package org.apache.maven.archiva.converter; * under the License. */ -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - +import junit.framework.TestCase; +import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.converter.legacy.LegacyRepositoryConverter; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -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.io.IOException; +import java.util.ArrayList; +import java.util.List; /** * Test the repository converter. @@ -40,32 +48,43 @@ import org.codehaus.plexus.spring.PlexusInSpringTestCase; * @todo should reject if dependencies are missing - rely on reporting? * @todo group metadata */ +@RunWith( SpringJUnit4ClassRunner.class ) +@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} ) public class RepositoryConverterTest - extends PlexusInSpringTestCase + extends TestCase { private ArtifactRepository sourceRepository; private ManagedRepositoryConfiguration targetRepository; + @Inject + @Named(value = "legacyRepositoryConverter#default") private LegacyRepositoryConverter repositoryConverter; - protected void setUp() + @Inject + PlexusSisuBridge plexusSisuBridge; + + @Before + public void setUp() throws Exception { super.setUp(); - ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class ); + //(ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); + ArtifactRepositoryLayout layout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "legacy" ); + //(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); - File sourceBase = getTestFile( "src/test/source-repository" ); + File sourceBase = new File( "src/test/source-repository" ); sourceRepository = factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null, null ); - layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); + layout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" ); + //(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - File targetBase = getTestFile( "target/test-target-repository" ); - copyDirectoryStructure( getTestFile( "src/test/target-repository" ), targetBase ); + File targetBase = new File( "target/test-target-repository" ); + copyDirectoryStructure( new File( "src/test/target-repository" ), targetBase ); targetRepository = new ManagedRepositoryConfiguration(); targetRepository.setId( "target" ); @@ -73,7 +92,7 @@ public class RepositoryConverterTest targetRepository.setLocation( targetBase.getAbsolutePath() ); targetRepository.setLayout( "default" ); - repositoryConverter = (LegacyRepositoryConverter) lookup( LegacyRepositoryConverter.ROLE, "default" ); + //repositoryConverter = (LegacyRepositoryConverter) lookup( LegacyRepositoryConverter.ROLE, "default" ); } protected void tearDown() @@ -129,6 +148,7 @@ public class RepositoryConverterTest } } + @Test public void testLegacyConversion() throws IOException, RepositoryConversionException { diff --git a/archiva-modules/archiva-base/archiva-converter/src/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-converter/src/test/resources/spring-context.xml new file mode 100644 index 000000000..60142d781 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-converter/src/test/resources/spring-context.xml @@ -0,0 +1,31 @@ + + + + + + + \ No newline at end of file