[MRM-1473] remove use of plexus-spring

ok for archiva-artifact-converter
introduce a new bridge tru sisu-guice to be able to use maven apis components

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1128078 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-05-26 20:53:32 +00:00
parent 2fdf7359b3
commit 22961f8dc4
14 changed files with 628 additions and 165 deletions

View File

@ -41,10 +41,18 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-plexus-bridge</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-transaction</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-model-converter</artifactId>
@ -54,19 +62,22 @@
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<executions>
<execution>
<goals>
<goal>generate-metadata</goal>
</goals>
</execution>
</executions>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<basedir>${basedir}</basedir>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

View File

@ -19,19 +19,7 @@ package org.apache.maven.archiva.converter.artifact;
* under the License.
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.maven.archiva.transaction.FileTransaction;
@ -54,30 +42,52 @@ import org.apache.maven.model.Relocation;
import org.apache.maven.model.converter.ModelConverter;
import org.apache.maven.model.converter.PomTranslationException;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.digest.Digester;
import org.codehaus.plexus.digest.DigesterException;
import org.codehaus.plexus.digest.Md5Digester;
import org.codehaus.plexus.digest.Sha1Digester;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
/**
* LegacyToDefaultConverter
* LegacyToDefaultConverter
*
* @version $Id$
*
* @plexus.component role="org.apache.maven.archiva.converter.artifact.ArtifactConverter"
* role-hint="legacy-to-default"
* @plexus.component role="org.apache.maven.archiva.converter.artifact.ArtifactConverter"
* role-hint="legacy-to-default"
*/
@Service( "artifactConverter#legacy-to-default" )
public class LegacyToDefaultConverter
implements ArtifactConverter
{
/**
* {@link List}&lt;{@link Digester}>
*
* @plexus.requirement role="org.codehaus.plexus.digest.Digester"
* {@link List}&lt;{@link Digester}
* plexus.requirement role="org.codehaus.plexus.digest.Digester"
*/
private List<Digester> digesters;
@Inject
private PlexusSisuBridge plexusSisuBridge;
/**
* @plexus.requirement
* plexus.requirement
*/
private ModelConverter translator;
@ -92,16 +102,26 @@ public class LegacyToDefaultConverter
private ArtifactHandlerManager artifactHandlerManager;
/**
* @plexus.configuration default-value="false"
* plexus.configuration default-value="false"
*/
private boolean force;
/**
* @plexus.configuration default-value="false"
* plexus.configuration default-value="false"
*/
private boolean dryrun;
private Map<Artifact,List<String>> warnings = new HashMap<Artifact,List<String>>();
private Map<Artifact, List<String>> warnings = new HashMap<Artifact, List<String>>();
@PostConstruct
public void initialize()
throws ComponentLookupException
{
this.digesters = plexusSisuBridge.lookupList( Digester.class );
translator = plexusSisuBridge.lookup( ModelConverter.class );
artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class );
artifactHandlerManager = plexusSisuBridge.lookup( ArtifactHandlerManager.class );
}
public void convert( Artifact artifact, ArtifactRepository targetRepository )
throws ArtifactConversionException
@ -162,17 +182,18 @@ public class LegacyToDefaultConverter
}
catch ( TransactionException e )
{
throw new ArtifactConversionException( Messages.getString( "transaction.failure", e.getMessage() ), e ); //$NON-NLS-1$
throw new ArtifactConversionException( Messages.getString( "transaction.failure", e.getMessage() ),
e ); //$NON-NLS-1$
}
}
}
@SuppressWarnings("unchecked")
@SuppressWarnings( "unchecked" )
private boolean copyPom( Artifact artifact, ArtifactRepository targetRepository, FileTransaction transaction )
throws ArtifactConversionException
{
Artifact pom = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact
.getVersion() );
Artifact pom = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion() );
pom.setBaseVersion( artifact.getBaseVersion() );
ArtifactRepository repository = artifact.getRepository();
File file = new File( repository.getBasedir(), repository.pathOf( pom ) );
@ -197,7 +218,7 @@ public class LegacyToDefaultConverter
catch ( IOException e )
{
throw new ArtifactConversionException(
Messages.getString( "unable.to.read.source.pom", e.getMessage() ), e ); //$NON-NLS-1$
Messages.getString( "unable.to.read.source.pom", e.getMessage() ), e ); //$NON-NLS-1$
}
if ( checksumsValid && contents.indexOf( "modelVersion" ) >= 0 ) //$NON-NLS-1$
@ -218,8 +239,8 @@ public class LegacyToDefaultConverter
}
catch ( IOException e )
{
throw new ArtifactConversionException( Messages
.getString( "unable.to.write.target.pom", e.getMessage() ), e ); //$NON-NLS-1$
throw new ArtifactConversionException(
Messages.getString( "unable.to.write.target.pom", e.getMessage() ), e ); //$NON-NLS-1$
}
}
else
@ -229,20 +250,22 @@ public class LegacyToDefaultConverter
StringWriter writer = null;
try
{
org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader v3Reader = new org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader();
org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader v3Reader =
new org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader();
org.apache.maven.model.v3_0_0.Model v3Model = v3Reader.read( stringReader );
if ( doRelocation( artifact, v3Model, targetRepository, transaction ) )
{
Artifact relocatedPom = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact
.getArtifactId(), artifact.getVersion() );
Artifact relocatedPom =
artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion() );
targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( relocatedPom ) );
}
Model v4Model = translator.translate( v3Model );
translator.validateV4Basics( v4Model, v3Model.getGroupId(), v3Model.getArtifactId(), v3Model
.getVersion(), v3Model.getPackage() );
translator.validateV4Basics( v4Model, v3Model.getGroupId(), v3Model.getArtifactId(),
v3Model.getVersion(), v3Model.getPackage() );
writer = new StringWriter();
MavenXpp3Writer Xpp3Writer = new MavenXpp3Writer();
@ -264,7 +287,8 @@ public class LegacyToDefaultConverter
}
catch ( IOException e )
{
throw new ArtifactConversionException( Messages.getString( "unable.to.write.converted.pom" ), e ); //$NON-NLS-1$
throw new ArtifactConversionException( Messages.getString( "unable.to.write.converted.pom" ),
e ); //$NON-NLS-1$
}
catch ( PomTranslationException e )
{
@ -290,8 +314,10 @@ public class LegacyToDefaultConverter
boolean result = true;
for ( Digester digester : digesters )
{
result &= verifyChecksum( file, file.getName() + "." + getDigesterFileExtension( digester ), digester, //$NON-NLS-1$
artifact, "failure.incorrect." + getDigesterFileExtension( digester ) ); //$NON-NLS-1$
result &= verifyChecksum( file, file.getName() + "." + getDigesterFileExtension( digester ), digester,
//$NON-NLS-1$
artifact,
"failure.incorrect." + getDigesterFileExtension( digester ) ); //$NON-NLS-1$
}
return result;
}
@ -395,15 +421,18 @@ public class LegacyToDefaultConverter
}
catch ( FileNotFoundException e )
{
throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ), e ); //$NON-NLS-1$
throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ),
e ); //$NON-NLS-1$
}
catch ( IOException e )
{
throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ), e ); //$NON-NLS-1$
throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ),
e ); //$NON-NLS-1$
}
catch ( XmlPullParserException e )
{
throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ), e ); //$NON-NLS-1$
throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ),
e ); //$NON-NLS-1$
}
finally
{
@ -420,7 +449,8 @@ public class LegacyToDefaultConverter
boolean result = true;
RepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact );
File file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) );
File file =
new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) );
if ( file.exists() )
{
Metadata metadata = readMetadata( file );
@ -438,7 +468,7 @@ public class LegacyToDefaultConverter
return result;
}
@SuppressWarnings("unchecked")
@SuppressWarnings( "unchecked" )
private boolean validateMetadata( Metadata metadata, RepositoryMetadata repositoryMetadata, Artifact artifact )
{
String groupIdKey;
@ -544,8 +574,8 @@ public class LegacyToDefaultConverter
Metadata newMetadata, FileTransaction transaction )
throws ArtifactConversionException
{
File file = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
File file = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
Metadata metadata;
boolean changed;
@ -576,7 +606,8 @@ public class LegacyToDefaultConverter
}
catch ( IOException e )
{
throw new ArtifactConversionException( Messages.getString( "error.writing.target.metadata" ), e ); //$NON-NLS-1$
throw new ArtifactConversionException( Messages.getString( "error.writing.target.metadata" ),
e ); //$NON-NLS-1$
}
finally
{
@ -590,13 +621,15 @@ public class LegacyToDefaultConverter
throws IOException
{
Properties properties = v3Model.getProperties();
if ( properties.containsKey( "relocated.groupId" ) || properties.containsKey( "relocated.artifactId" ) //$NON-NLS-1$ //$NON-NLS-2$
if ( properties.containsKey( "relocated.groupId" ) || properties.containsKey( "relocated.artifactId" )
//$NON-NLS-1$ //$NON-NLS-2$
|| properties.containsKey( "relocated.version" ) ) //$NON-NLS-1$
{
String newGroupId = properties.getProperty( "relocated.groupId", v3Model.getGroupId() ); //$NON-NLS-1$
properties.remove( "relocated.groupId" ); //$NON-NLS-1$
String newArtifactId = properties.getProperty( "relocated.artifactId", v3Model.getArtifactId() ); //$NON-NLS-1$
String newArtifactId =
properties.getProperty( "relocated.artifactId", v3Model.getArtifactId() ); //$NON-NLS-1$
properties.remove( "relocated.artifactId" ); //$NON-NLS-1$
String newVersion = properties.getProperty( "relocated.version", v3Model.getVersion() ); //$NON-NLS-1$
@ -684,4 +717,65 @@ public class LegacyToDefaultConverter
{
return warnings;
}
public List<Digester> getDigesters()
{
return digesters;
}
public void setDigesters( List<Digester> digesters )
{
this.digesters = digesters;
}
public ModelConverter getTranslator()
{
return translator;
}
public void setTranslator( ModelConverter translator )
{
this.translator = translator;
}
public ArtifactFactory getArtifactFactory()
{
return artifactFactory;
}
public void setArtifactFactory( ArtifactFactory artifactFactory )
{
this.artifactFactory = artifactFactory;
}
public ArtifactHandlerManager getArtifactHandlerManager()
{
return artifactHandlerManager;
}
public void setArtifactHandlerManager( ArtifactHandlerManager artifactHandlerManager )
{
this.artifactHandlerManager = artifactHandlerManager;
}
public boolean isForce()
{
return force;
}
public void setForce( boolean force )
{
this.force = force;
}
public boolean isDryrun()
{
return dryrun;
}
public void setDryrun( boolean dryrun )
{
this.dryrun = dryrun;
}
}

View File

@ -36,6 +36,7 @@ public class Messages
private Messages()
{
// no op
}
public static String getString( String key )

View File

@ -0,0 +1,33 @@
<?xml version="1.0"?>
<!--
~ 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
default-lazy-init="true">
<context:annotation-config/>
<context:component-scan base-package="org.apache.maven.archiva.converter.artifact"/>
</beans>

View File

@ -19,15 +19,8 @@ package org.apache.maven.archiva.converter.artifact;
* under the License.
*/
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import junit.framework.TestCase;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
@ -37,15 +30,32 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
/**
* LegacyToDefaultConverterTest
* LegacyToDefaultConverterTest
*
* @version $Id$
*/
@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
public class LegacyToDefaultConverterTest
extends PlexusInSpringTestCase
extends TestCase
{
private ArtifactRepository sourceRepository;
@ -55,38 +65,58 @@ public class LegacyToDefaultConverterTest
private ArtifactFactory artifactFactory;
@Inject
private PlexusSisuBridge plexusSisuBridge;
@Inject
private ApplicationContext applicationContext;
private static final int SLEEP_MILLIS = 100;
protected void setUp()
@Before
public void init()
throws Exception
{
super.setUp();
ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
ArtifactRepositoryLayout layout =
(ArtifactRepositoryLayout) plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "legacy" );
File sourceBase = getTestFile( "src/test/source-repository" );
sourceRepository = factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null,
null );
sourceRepository =
factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null, null );
layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
layout = (ArtifactRepositoryLayout) plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" );
File targetBase = getTestFile( "target/test-target-repository" );
copyDirectoryStructure( getTestFile( "src/test/target-repository" ), targetBase );
targetRepository = factory.createArtifactRepository( "target", targetBase.toURL().toString(), layout, null,
null );
targetRepository =
factory.createArtifactRepository( "target", targetBase.toURL().toString(), layout, null, null );
artifactConverter = (ArtifactConverter) lookup( ArtifactConverter.ROLE, "legacy-to-default" );
artifactConverter =
applicationContext.getBean( "artifactConverter#legacy-to-default", ArtifactConverter.class );
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
artifactConverter.clearWarnings();
artifactFactory = (ArtifactFactory) plexusSisuBridge.lookup( ArtifactFactory.class );
}
protected void tearDown()
throws Exception
public static File getTestFile( String path )
{
super.tearDown();
return new File( getBasedir(), path );
}
public static String getBasedir()
{
String basedir = System.getProperty( "basedir" );
if ( basedir == null )
{
basedir = new File( "" ).getAbsolutePath();
}
return basedir;
}
private void copyDirectoryStructure( File sourceDirectory, File destinationDirectory )
@ -123,8 +153,8 @@ public class LegacyToDefaultConverterTest
{
if ( !destination.exists() && !destination.mkdirs() )
{
throw new IOException( "Could not create destination directory '"
+ destination.getAbsolutePath() + "'." );
throw new IOException(
"Could not create destination directory '" + destination.getAbsolutePath() + "'." );
}
copyDirectoryStructure( file, destination );
}
@ -136,6 +166,7 @@ public class LegacyToDefaultConverterTest
}
}
@Test
public void testV4PomConvert()
throws Exception
{
@ -143,13 +174,13 @@ public class LegacyToDefaultConverterTest
Artifact artifact = createArtifact( "test", "v4artifact", "1.0.0" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
File artifactMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
File versionMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( versionMetadata ) );
File versionMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) );
versionMetadataFile.delete();
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
@ -181,6 +212,7 @@ public class LegacyToDefaultConverterTest
compareFiles( expectedMetadataFile, versionMetadataFile );
}
@Test
public void testV3PomConvert()
throws Exception
{
@ -188,13 +220,13 @@ public class LegacyToDefaultConverterTest
Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
File artifactMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
File versionMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( versionMetadata ) );
File versionMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) );
versionMetadataFile.delete();
artifactConverter.convert( artifact, targetRepository );
@ -224,18 +256,19 @@ public class LegacyToDefaultConverterTest
compareFiles( expectedMetadataFile, versionMetadataFile );
}
@Test
public void testV3PomConvertWithRelocation()
throws Exception
{
Artifact artifact = createArtifact( "test", "relocated-v3artifact", "1.0.0" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
File artifactMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
File versionMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( versionMetadata ) );
File versionMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) );
versionMetadataFile.delete();
artifactConverter.convert( artifact, targetRepository );
@ -243,7 +276,8 @@ public class LegacyToDefaultConverterTest
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
assertTrue( "Check if relocated artifact created", artifactFile.exists() );
assertTrue( "Check if relocated artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
assertTrue( "Check if relocated artifact matches",
FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
Artifact pomArtifact = createArtifact( "relocated-test", "relocated-v3artifact", "1.0.0", "1.0.0", "pom" );
File pomFile = getTestFile( "src/test/expected-files/" + targetRepository.pathOf( pomArtifact ) );
File testFile = getTestFile( "target/test-target-repository/" + targetRepository.pathOf( pomArtifact ) );
@ -256,6 +290,7 @@ public class LegacyToDefaultConverterTest
compareFiles( artifactFile, testFile );
}
@Test
public void testV3PomWarningsOnConvert()
throws Exception
{
@ -263,13 +298,13 @@ public class LegacyToDefaultConverterTest
Artifact artifact = createArtifact( "test", "v3-warnings-artifact", "1.0.0" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
File artifactMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
File versionMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( versionMetadata ) );
File versionMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) );
versionMetadataFile.delete();
artifactConverter.convert( artifact, targetRepository );
@ -296,13 +331,13 @@ public class LegacyToDefaultConverterTest
Artifact artifact = createArtifact( "test", "v4artifact", version );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
File artifactMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
File snapshotMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
File snapshotMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
snapshotMetadataFile.delete();
artifactConverter.convert( artifact, targetRepository );
@ -332,6 +367,7 @@ public class LegacyToDefaultConverterTest
compareFiles( expectedMetadataFile, snapshotMetadataFile );
}
@Test
public void testV3SnapshotPomConvert()
throws Exception
{
@ -339,13 +375,13 @@ public class LegacyToDefaultConverterTest
Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0-SNAPSHOT" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
File artifactMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
File snapshotMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
File snapshotMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
snapshotMetadataFile.delete();
artifactConverter.convert( artifact, targetRepository );
@ -375,6 +411,7 @@ public class LegacyToDefaultConverterTest
compareFiles( expectedMetadataFile, snapshotMetadataFile );
}
@Test
public void testV4SnapshotPomConvert()
throws Exception
{
@ -383,6 +420,7 @@ public class LegacyToDefaultConverterTest
assertTrue( true );
}
@Test
public void testV4TimestampedSnapshotPomConvert()
throws Exception
{
@ -392,12 +430,14 @@ public class LegacyToDefaultConverterTest
assertTrue( true );
}
@Test
public void testMavenOnePluginConversion()
throws Exception
{
Artifact artifact = createArtifact( "org.apache.maven.plugins", "maven-foo-plugin", "1.0", "1.0",
"maven-plugin" );
artifact.setFile( new File( getBasedir(), "src/test/source-repository/test/plugins/maven-foo-plugin-1.0.jar" ) );
Artifact artifact =
createArtifact( "org.apache.maven.plugins", "maven-foo-plugin", "1.0", "1.0", "maven-plugin" );
artifact.setFile(
new File( getBasedir(), "src/test/source-repository/test/plugins/maven-foo-plugin-1.0.jar" ) );
artifactConverter.convert( artifact, targetRepository );
// There is a warning but I can't figure out how to look at it. Eyeballing the results it appears
// the plugin is being coverted correctly.
@ -418,6 +458,7 @@ public class LegacyToDefaultConverterTest
*/
}
@Test
public void testV3TimestampedSnapshotPomConvert()
throws Exception
{
@ -425,13 +466,13 @@ public class LegacyToDefaultConverterTest
Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0-20060105.130101-3" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
File artifactMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
File snapshotMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
File snapshotMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
snapshotMetadataFile.delete();
artifactConverter.convert( artifact, targetRepository );
@ -461,6 +502,7 @@ public class LegacyToDefaultConverterTest
compareFiles( expectedMetadataFile, snapshotMetadataFile );
}
@Test
public void testNoPomConvert()
throws Exception
{
@ -484,6 +526,7 @@ public class LegacyToDefaultConverterTest
assertFalse( "No source POM", sourcePomFile.exists() );
}
@Test
public void testIncorrectSourceChecksumMd5()
throws Exception
{
@ -501,11 +544,12 @@ public class LegacyToDefaultConverterTest
assertFalse( "Check artifact not created", file.exists() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
File metadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( metadata ) );
File metadataFile =
new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
@Test
public void testIncorrectSourceChecksumSha1()
throws Exception
{
@ -523,11 +567,12 @@ public class LegacyToDefaultConverterTest
assertFalse( "Check artifact not created", file.exists() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
File metadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( metadata ) );
File metadataFile =
new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
@Test
public void testUnmodifiedArtifact()
throws Exception, InterruptedException
{
@ -563,6 +608,7 @@ public class LegacyToDefaultConverterTest
assertEquals( "Check POM unmodified", origPomTime, targetPomFile.lastModified() );
}
@Test
public void testModifedArtifactFails()
throws Exception
{
@ -598,17 +644,19 @@ public class LegacyToDefaultConverterTest
assertEquals( "Check unmodified", origPomTime, targetPomFile.lastModified() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
File metadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( metadata ) );
File metadataFile =
new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
@Test
public void testForcedUnmodifiedArtifact()
throws Exception
{
// test unmodified artifact is still converted when set to force
artifactConverter = (ArtifactConverter) lookup( ArtifactConverter.ROLE, "force-repository-converter" );
artifactConverter =
applicationContext.getBean( "artifactConverter#force-repository-converter", ArtifactConverter.class );
Artifact artifact = createArtifact( "test", "unmodified-artifact", "1.0.0" );
Artifact pomArtifact = createPomArtifact( artifact );
@ -636,17 +684,19 @@ public class LegacyToDefaultConverterTest
assertFalse( "Check modified", origTime == targetPomFile.lastModified() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
File metadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( metadata ) );
File metadataFile =
new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
assertTrue( "Check metadata created", metadataFile.exists() );
}
@Test
public void testDryRunSuccess()
throws Exception
{
// test dry run does nothing on a run that will be successful, and returns success
artifactConverter = (ArtifactConverter) lookup( ArtifactConverter.ROLE, "dryrun-repository-converter" );
artifactConverter =
applicationContext.getBean( "artifactConverter#dryrun-repository-converter", ArtifactConverter.class );
Artifact artifact = createArtifact( "test", "dryrun-artifact", "1.0.0" );
Artifact pomArtifact = createPomArtifact( artifact );
@ -666,17 +716,19 @@ public class LegacyToDefaultConverterTest
assertFalse( "Check target POM doesn't exist", targetPomFile.exists() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
File metadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( metadata ) );
File metadataFile =
new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
@Test
public void testDryRunFailure()
throws Exception
{
// test dry run does nothing on a run that will fail, and returns failure
artifactConverter = (ArtifactConverter) lookup( ArtifactConverter.ROLE, "dryrun-repository-converter" );
artifactConverter =
applicationContext.getBean( "artifactConverter#dryrun-repository-converter", ArtifactConverter.class );
Artifact artifact = createArtifact( "test", "modified-artifact", "1.0.0" );
Artifact pomArtifact = createPomArtifact( artifact );
@ -707,11 +759,12 @@ public class LegacyToDefaultConverterTest
assertEquals( "Check unmodified", origPomTime, targetPomFile.lastModified() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
File metadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( metadata ) );
File metadataFile =
new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
@Test
public void testRollbackArtifactCreated()
throws Exception
{
@ -719,13 +772,13 @@ public class LegacyToDefaultConverterTest
Artifact artifact = createArtifact( "test", "rollback-created-artifact", "1.0.0" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
File artifactMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
FileUtils.deleteDirectory( artifactMetadataFile.getParentFile() );
ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
File versionMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( versionMetadata ) );
File versionMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) );
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
@ -744,7 +797,7 @@ public class LegacyToDefaultConverterTest
break;
}
}
if ( found )
{
break;
@ -758,6 +811,7 @@ public class LegacyToDefaultConverterTest
assertFalse( "check metadata rolled back", versionMetadataFile.exists() );
}
@Test
public void testMultipleArtifacts()
throws Exception
{
@ -782,14 +836,15 @@ public class LegacyToDefaultConverterTest
artifact = createPomArtifact( artifact );
File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
File expectedPomFile = getTestFile( "src/test/expected-files/converted-" + artifact.getArtifactId()
+ ".pom" );
File expectedPomFile =
getTestFile( "src/test/expected-files/converted-" + artifact.getArtifactId() + ".pom" );
assertTrue( "Check POM created", pomFile.exists() );
compareFiles( expectedPomFile, pomFile );
}
}
@Test
public void testInvalidSourceArtifactMetadata()
throws Exception
{
@ -804,16 +859,18 @@ public class LegacyToDefaultConverterTest
artifactConverter.convert( artifact, targetRepository );
checkWarnings( artifactConverter, 2 );
assertHasWarningReason( artifactConverter, Messages.getString( "failure.incorrect.artifactMetadata.versions" ) );
assertHasWarningReason( artifactConverter,
Messages.getString( "failure.incorrect.artifactMetadata.versions" ) );
assertFalse( "Check artifact not created", file.exists() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
File metadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( metadata ) );
File metadataFile =
new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
@Test
public void testInvalidSourceSnapshotMetadata()
throws Exception
{
@ -828,16 +885,18 @@ public class LegacyToDefaultConverterTest
artifactConverter.convert( artifact, targetRepository );
checkWarnings( artifactConverter, 2 );
assertHasWarningReason( artifactConverter, Messages.getString( "failure.incorrect.snapshotMetadata.snapshot" ) );
assertHasWarningReason( artifactConverter,
Messages.getString( "failure.incorrect.snapshotMetadata.snapshot" ) );
assertFalse( "Check artifact not created", file.exists() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
File metadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( metadata ) );
File metadataFile =
new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
@Test
public void testMergeArtifactMetadata()
throws Exception
{
@ -859,8 +918,8 @@ public class LegacyToDefaultConverterTest
compareFiles( sourcePomFile, pomFile );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
File artifactMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() );
File expectedMetadataFile = getTestFile( "src/test/expected-files/newversion-artifact-metadata.xml" );
@ -868,15 +927,17 @@ public class LegacyToDefaultConverterTest
compareFiles( expectedMetadataFile, artifactMetadataFile );
}
@Test
public void testSourceAndTargetRepositoriesMatch()
throws Exception
{
// test that it fails if the same
ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
sourceRepository = factory.createArtifactRepository( "source", targetRepository.getUrl(), targetRepository
.getLayout(), null, null );
sourceRepository =
factory.createArtifactRepository( "source", targetRepository.getUrl(), targetRepository.getLayout(), null,
null );
Artifact artifact = createArtifact( "test", "repository-artifact", "1.0" );
@ -908,7 +969,8 @@ public class LegacyToDefaultConverterTest
return createArtifact( groupId, artifactId, baseVersion, version, "jar" );
}
private Artifact createArtifact( String groupId, String artifactId, String baseVersion, String version, String type )
private Artifact createArtifact( String groupId, String artifactId, String baseVersion, String version,
String type )
{
Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, type );
artifact.setBaseVersion( baseVersion );
@ -919,21 +981,24 @@ public class LegacyToDefaultConverterTest
private Artifact createPomArtifact( Artifact artifact )
{
return createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact
.getVersion(), "pom" );
return createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(),
artifact.getVersion(), "pom" );
}
private static void compareFiles( File expectedPomFile, File pomFile )
throws IOException
{
String expectedContent = normalizeString( org.apache.commons.io.FileUtils.readFileToString( expectedPomFile, null ) );
String expectedContent =
normalizeString( org.apache.commons.io.FileUtils.readFileToString( expectedPomFile, null ) );
String targetContent = normalizeString( org.apache.commons.io.FileUtils.readFileToString( pomFile, null ) );
assertEquals( "Check file match between " + expectedPomFile + " and " + pomFile, expectedContent, targetContent );
assertEquals( "Check file match between " + expectedPomFile + " and " + pomFile, expectedContent,
targetContent );
}
private static String normalizeString( String path )
{
return path.trim().replaceAll( "\r\n", "\n" ).replace( '\r', '\n' ).replaceAll( "<\\?xml .+\\?>", "" ).replaceAll("^\\s+", "");
return path.trim().replaceAll( "\r\n", "\n" ).replace( '\r', '\n' ).replaceAll( "<\\?xml .+\\?>",
"" ).replaceAll( "^\\s+", "" );
}
private void checkSuccess( ArtifactConverter converter )
@ -974,11 +1039,11 @@ public class LegacyToDefaultConverterTest
/* didn't find it. */
for ( Map.Entry<Artifact,List<String>> entry : converter.getWarnings().entrySet() )
for ( Map.Entry<Artifact, List<String>> entry : converter.getWarnings().entrySet() )
{
Artifact artifact = (Artifact) entry.getKey();
System.out.println( "-Artifact: " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
+ artifact.getVersion() );
System.out.println(
"-Artifact: " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() );
List<String> messages = entry.getValue();
for ( String message : messages )
{
@ -991,12 +1056,12 @@ public class LegacyToDefaultConverterTest
private void createModernSourceRepository()
throws Exception
{
ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
ArtifactRepositoryLayout layout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" );
File sourceBase = getTestFile( "src/test/source-modern-repository" );
sourceRepository = factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null,
null );
sourceRepository =
factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null, null );
}
}

View File

@ -0,0 +1,39 @@
<?xml version="1.0"?>
<!--
~ 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean name="artifactConverter#force-repository-converter" class="org.apache.maven.archiva.converter.artifact.LegacyToDefaultConverter">
<property name="force" value="true"/>
<property name="dryrun" value="false"/>
</bean>
<bean name="artifactConverter#dryrun-repository-converter" class="org.apache.maven.archiva.converter.artifact.LegacyToDefaultConverter">
<property name="force" value="false"/>
<property name="dryrun" value="true"/>
</bean>
</beans>

View File

@ -35,13 +35,15 @@ 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.springframework.stereotype.Service;
/**
* DefaultLegacyRepositoryConverter
*
* @version $Id$
* @plexus.component
* plexus.component
*/
@Service("legacyRepositoryConverter#default")
public class DefaultLegacyRepositoryConverter
implements LegacyRepositoryConverter
{

View File

@ -38,6 +38,8 @@ import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
/**
* LegacyConverterArtifactConsumer - convert artifacts as they are found
@ -45,10 +47,12 @@ import org.slf4j.LoggerFactory;
*
* @version $Id$
*
* @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
* 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")
public class LegacyConverterArtifactConsumer
extends AbstractMonitoredConsumer
implements KnownRepositoryContentConsumer

View File

@ -0,0 +1,33 @@
<?xml version="1.0"?>
<!--
~ 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
default-lazy-init="true">
<context:annotation-config/>
<context:component-scan base-package="org.apache.maven.archiva.converter.legacy"/>
</beans>

View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-base</artifactId>
<version>1.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>archiva-plexus-bridge</artifactId>
<name>Archiva Base :: Plexus Bridge</name>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-inject-plexus</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.redback.components</groupId>
<artifactId>spring-utils</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,95 @@
package org.apache.archiva.common.plexusbridge;
/*
* 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.codehaus.plexus.DefaultContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.net.URL;
import java.util.List;
/**
* Simple component which will initiate the plexus shim component
* to see plexus components inside a guice container.<br/>
* So move all of this here to be able to change quickly if needed.
*
* @author Olivier Lamy
*/
@Service("plexusSisuBridge")
public class PlexusSisuBridge
{
private boolean containerAutoWiring = false;
private String containerClassPathScanning = PlexusConstants.SCANNING_OFF;
private String containerComponentVisibility = PlexusConstants.REALM_VISIBILITY;
private URL overridingComponentsXml;
private DefaultPlexusContainer plexusContainer;
@PostConstruct
public void initialize()
throws PlexusContainerException
{
DefaultContainerConfiguration conf = new DefaultContainerConfiguration();
conf.setAutoWiring( containerAutoWiring );
conf.setClassPathScanning( containerClassPathScanning );
conf.setComponentVisibility( containerComponentVisibility );
conf.setContainerConfigurationURL( overridingComponentsXml );
ClassWorld classWorld = new ClassWorld();
ClassRealm classRealm = new ClassRealm( classWorld, "maven", Thread.currentThread().getContextClassLoader() );
conf.setRealm( classRealm );
conf.setClassWorld( classWorld );
plexusContainer = new DefaultPlexusContainer( conf );
}
public <T> T lookup( Class<T> clazz )
throws ComponentLookupException
{
return plexusContainer.lookup( clazz );
}
public <T> T lookup( Class<T> clazz, String hint )
throws ComponentLookupException
{
return plexusContainer.lookup( clazz, hint );
}
public <T> List<T> lookupList( Class<T> clazz )
throws ComponentLookupException
{
return plexusContainer.lookupList( clazz );
}
}

View File

@ -0,0 +1,31 @@
<?xml version="1.0"?>
<!--
~ 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config/>
<context:component-scan base-package="org.apache.archiva.common.plexusbridge"/>
</beans>

View File

@ -33,6 +33,7 @@
<modules>
<module>archiva-checksum</module>
<module>archiva-common</module>
<module>archiva-plexus-bridge</module>
<module>archiva-policies</module>
<module>archiva-configuration</module>
<module>archiva-consumers</module>

View File

@ -455,6 +455,11 @@
<artifactId>archiva-lucene-consumers</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-plexus-bridge</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-model</artifactId>