aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/plugins/problem-reports
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2011-05-26 20:56:19 +0000
committerOlivier Lamy <olamy@apache.org>2011-05-26 20:56:19 +0000
commitabe408f63f48b307be759a3af9619f348d65c730 (patch)
treeab53765faef99429eea0b8281f565aae986d00d5 /archiva-modules/plugins/problem-reports
parent5bc6009a398e097660aaf8cb49cd5fe16ddc9a0a (diff)
downloadarchiva-abe408f63f48b307be759a3af9619f348d65c730.tar.gz
archiva-abe408f63f48b307be759a3af9619f348d65c730.zip
[MRM-1473] remove of plexus-spring : fix problem-reports module
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1128084 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/plugins/problem-reports')
-rw-r--r--archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java10
-rw-r--r--archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemFacetFactory.java4
-rw-r--r--archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java54
-rw-r--r--archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java56
4 files changed, 81 insertions, 43 deletions
diff --git a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java
index 575af1e82..84127521a 100644
--- a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java
+++ b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java
@@ -27,12 +27,14 @@ import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataE
import org.apache.archiva.repository.events.RepositoryListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
/**
* Process repository management events and respond appropriately.
- *
- * @plexus.component role="org.apache.archiva.repository.events.RepositoryListener" role-hint="problem-reports"
+ * <p/>
+ * plexus.component role="org.apache.archiva.repository.events.RepositoryListener" role-hint="problem-reports"
*/
+@Service( "repositoryListener#problem-reports" )
public class RepositoryProblemEventListener
implements RepositoryListener
{
@@ -68,8 +70,8 @@ public class RepositoryProblemEventListener
}
catch ( MetadataRepositoryException e )
{
- log.warn( "Unable to remove repository problem facets for the version being corrected in the repository: " +
- e.getMessage(), e );
+ log.warn( "Unable to remove repository problem facets for the version being corrected in the repository: "
+ + e.getMessage(), e );
}
}
diff --git a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemFacetFactory.java b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemFacetFactory.java
index 5f95f1496..e39077c1e 100644
--- a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemFacetFactory.java
+++ b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemFacetFactory.java
@@ -21,10 +21,12 @@ package org.apache.archiva.reports;
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.reports"
+ * plexus.component role="org.apache.archiva.metadata.model.MetadataFacetFactory" role-hint="org.apache.archiva.reports"
*/
+@Service( "metadataFacetFactory#org.apache.archiva.reports" )
public class RepositoryProblemFacetFactory
implements MetadataFacetFactory
{
diff --git a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java
index ee77dcd96..592457d43 100644
--- a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java
+++ b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java
@@ -36,13 +36,16 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
import org.apache.maven.archiva.consumers.ConsumerException;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Named;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -52,45 +55,50 @@ import java.util.List;
/**
* Search the database of known SHA1 Checksums for potential duplicate artifacts.
- *
+ * <p/>
* TODO: no need for this to be a scanner - we can just query the database / content repository to get a full list
*
* @version $Id$
- * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
- * role-hint="duplicate-artifacts"
- * instantiation-strategy="per-lookup"
+ * plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
+ * role-hint="duplicate-artifacts"
+ * instantiation-strategy="per-lookup"
*/
+@Service( "knownRepositoryContentConsumer#duplicate-artifacts" )
+@Scope( "prototype" )
public class DuplicateArtifactsConsumer
extends AbstractMonitoredConsumer
- implements KnownRepositoryContentConsumer, RegistryListener, Initializable
+ implements KnownRepositoryContentConsumer, RegistryListener
{
private Logger log = LoggerFactory.getLogger( DuplicateArtifactsConsumer.class );
/**
- * @plexus.configuration default-value="duplicate-artifacts"
+ * plexus.configuration default-value="duplicate-artifacts"
*/
- private String id;
+ private String id = "duplicate-artifacts";
/**
- * @plexus.configuration default-value="Check for Duplicate Artifacts via SHA1 Checksums"
+ * plexus.configuration default-value="Check for Duplicate Artifacts via SHA1 Checksums"
*/
- private String description;
+ private String description = "Check for Duplicate Artifacts via SHA1 Checksums";
/**
- * @plexus.requirement
+ * plexus.requirement
*/
+ @Inject
private ArchivaConfiguration configuration;
/**
- * @plexus.requirement
+ * plexus.requirement
*/
+ @Inject
private FileTypes filetypes;
/**
* FIXME: can be of other types
- *
- * @plexus.requirement
+ * <p/>
+ * plexus.requirement
*/
+ @Inject
private RepositorySessionFactory repositorySessionFactory;
private List<String> includes = new ArrayList<String>();
@@ -101,9 +109,11 @@ public class DuplicateArtifactsConsumer
/**
* FIXME: needs to be selected based on the repository in question
- *
- * @plexus.requirement role-hint="maven2"
+ * <p/>
+ * plexus.requirement role-hint="maven2"
*/
+ @Inject
+ @Named( value = "repositoryPathTranslator#maven2" )
private RepositoryPathTranslator pathTranslator;
private RepositorySession repositorySession;
@@ -195,10 +205,10 @@ public class DuplicateArtifactsConsumer
for ( ArtifactMetadata dupArtifact : results )
{
String id = path.substring( path.lastIndexOf( "/" ) + 1 );
- if ( dupArtifact.getId().equals( id ) && dupArtifact.getNamespace().equals(
- originalArtifact.getNamespace() ) && dupArtifact.getProject().equals(
- originalArtifact.getProject() ) && dupArtifact.getVersion().equals(
- originalArtifact.getVersion() ) )
+ if ( dupArtifact.getId().equals( id )
+ && dupArtifact.getNamespace().equals( originalArtifact.getNamespace() )
+ && dupArtifact.getProject().equals( originalArtifact.getProject() )
+ && dupArtifact.getVersion().equals( originalArtifact.getVersion() ) )
{
// Skip reference to itself.
if ( log.isDebugEnabled() )
@@ -270,8 +280,8 @@ public class DuplicateArtifactsConsumer
includes.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) );
}
+ @PostConstruct
public void initialize()
- throws InitializationException
{
initIncludes();
configuration.addChangeListener( this );
diff --git a/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java b/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java
index 5dedab00b..359f7a499 100644
--- a/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java
+++ b/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java
@@ -19,6 +19,7 @@ package org.apache.archiva.reports.consumers;
* under the License.
*/
+import junit.framework.TestCase;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.MetadataFacet;
import org.apache.archiva.metadata.repository.MetadataRepository;
@@ -28,21 +29,32 @@ import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
import org.apache.archiva.reports.RepositoryProblemFacet;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.consumers.ConsumerException;
-import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Matchers;
+import org.springframework.context.ApplicationContext;
+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.FileNotFoundException;
import java.util.Arrays;
import java.util.Date;
import static org.mockito.Mockito.*;
-@SuppressWarnings( {"ThrowableInstanceNeverThrown"} )
+@SuppressWarnings( { "ThrowableInstanceNeverThrown" } )
+@RunWith( SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
public class DuplicateArtifactsConsumerTest
- extends PlexusInSpringTestCase
+ extends TestCase
{
+ @Inject
+ @Named( value = "knownRepositoryContentConsumer#duplicate-artifacts" )
private DuplicateArtifactsConsumer consumer;
private ManagedRepositoryConfiguration config;
@@ -64,37 +76,44 @@ public class DuplicateArtifactsConsumerTest
private static final ArtifactMetadata TEST_METADATA = createMetadata( TEST_VERSION );
+ @Inject
+ @Named( value = "repositoryPathTranslator#maven2" )
private RepositoryPathTranslator pathTranslator;
+ @Inject
+ ApplicationContext applicationContext;
+
+
+ @Before
public void setUp()
throws Exception
{
super.setUp();
- consumer = (DuplicateArtifactsConsumer) lookup( KnownRepositoryContentConsumer.class, "duplicate-artifacts" );
assertNotNull( consumer );
config = new ManagedRepositoryConfiguration();
config.setId( TEST_REPO );
- config.setLocation( getTestFile( "target/test-repository" ).getAbsolutePath() );
+ config.setLocation( new File( "target/test-repository" ).getAbsolutePath() );
metadataRepository = mock( MetadataRepository.class );
RepositorySession session = mock( RepositorySession.class );
when( session.getRepository() ).thenReturn( metadataRepository );
- RepositorySessionFactory factory = (RepositorySessionFactory) lookup( RepositorySessionFactory.class );
+ RepositorySessionFactory factory = applicationContext.getBean( RepositorySessionFactory.class );
+ //(RepositorySessionFactory) lookup( RepositorySessionFactory.class );
when( factory.createSession() ).thenReturn( session );
- pathTranslator = (RepositoryPathTranslator) lookup( RepositoryPathTranslator.class, "maven2" );
when( pathTranslator.getArtifactForPath( TEST_REPO, TEST_FILE ) ).thenReturn( TEST_METADATA );
}
+ @Test
public void testConsumerArtifactNotDuplicated()
throws Exception
{
- when( metadataRepository.getArtifactsByChecksum( TEST_REPO, TEST_CHECKSUM ) ).thenReturn( Arrays.asList(
- TEST_METADATA ) );
+ when( metadataRepository.getArtifactsByChecksum( TEST_REPO, TEST_CHECKSUM ) ).thenReturn(
+ Arrays.asList( TEST_METADATA ) );
consumer.beginScan( config, new Date() );
consumer.processFile( TEST_FILE );
@@ -117,11 +136,12 @@ public class DuplicateArtifactsConsumerTest
// verify( metadataRepository, never() ).addMetadataFacet( eq( TEST_REPO ), Matchers.<MetadataFacet>anyObject() );
// }
+ @Test
public void testConsumerArtifactDuplicated()
throws Exception
{
- when( metadataRepository.getArtifactsByChecksum( TEST_REPO, TEST_CHECKSUM ) ).thenReturn( Arrays.asList(
- TEST_METADATA, createMetadata( "1.0" ) ) );
+ when( metadataRepository.getArtifactsByChecksum( TEST_REPO, TEST_CHECKSUM ) ).thenReturn(
+ Arrays.asList( TEST_METADATA, createMetadata( "1.0" ) ) );
consumer.beginScan( config, new Date() );
consumer.processFile( TEST_FILE );
@@ -133,11 +153,12 @@ public class DuplicateArtifactsConsumerTest
assertProblem( problem );
}
+ @Test
public void testConsumerArtifactDuplicatedButSelfNotInMetadataRepository()
throws Exception
{
- when( metadataRepository.getArtifactsByChecksum( TEST_REPO, TEST_CHECKSUM ) ).thenReturn( Arrays.asList(
- createMetadata( "1.0" ) ) );
+ when( metadataRepository.getArtifactsByChecksum( TEST_REPO, TEST_CHECKSUM ) ).thenReturn(
+ Arrays.asList( createMetadata( "1.0" ) ) );
consumer.beginScan( config, new Date() );
consumer.processFile( TEST_FILE );
@@ -149,6 +170,7 @@ public class DuplicateArtifactsConsumerTest
assertProblem( problem );
}
+ @Test
public void testConsumerArtifactFileNotExist()
throws Exception
{
@@ -170,6 +192,7 @@ public class DuplicateArtifactsConsumerTest
verify( metadataRepository, never() ).addMetadataFacet( eq( TEST_REPO ), Matchers.<MetadataFacet>anyObject() );
}
+ @Test
public void testConsumerArtifactNotAnArtifactPathNoResults()
throws Exception
{
@@ -181,11 +204,12 @@ public class DuplicateArtifactsConsumerTest
verify( metadataRepository, never() ).addMetadataFacet( eq( TEST_REPO ), Matchers.<MetadataFacet>anyObject() );
}
+ @Test
public void testConsumerArtifactNotAnArtifactPathResults()
throws Exception
{
- when( metadataRepository.getArtifactsByChecksum( eq( TEST_REPO ), anyString() ) ).thenReturn( Arrays.asList(
- TEST_METADATA, createMetadata( "1.0" ) ) );
+ when( metadataRepository.getArtifactsByChecksum( eq( TEST_REPO ), anyString() ) ).thenReturn(
+ Arrays.asList( TEST_METADATA, createMetadata( "1.0" ) ) );
// override, this feels a little overspecified though
when( pathTranslator.getArtifactForPath( TEST_REPO, "com/example/invalid-artifact.txt" ) ).thenThrow(