diff options
author | Olivier Lamy <olamy@apache.org> | 2011-05-25 15:31:30 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2011-05-25 15:31:30 +0000 |
commit | 971dcc2f3570136a52c1d938527b1714231ed2b9 (patch) | |
tree | c8058637d6f3e86431bdacc6e2873e52046ceb56 /archiva-modules/archiva-base/archiva-repository-layer | |
parent | b0a37ac3863a846fa9652de7246fb06fa2f2f80e (diff) | |
download | archiva-971dcc2f3570136a52c1d938527b1714231ed2b9.tar.gz archiva-971dcc2f3570136a52c1d938527b1714231ed2b9.zip |
[MRM-1473] remove use of plexus-spring
move archiva-repository-layer to full spring
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1127555 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base/archiva-repository-layer')
30 files changed, 832 insertions, 535 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/pom.xml b/archiva-modules/archiva-base/archiva-repository-layer/pom.xml index 7b3812b5d..fa0c0a2e3 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/pom.xml +++ b/archiva-modules/archiva-base/archiva-repository-layer/pom.xml @@ -59,11 +59,6 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.codehaus.redback.components</groupId> - <artifactId>plexus-spring</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <scope>test</scope> @@ -77,20 +72,4 @@ <artifactId>maven2-repository</artifactId> </dependency> </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-component-metadata</artifactId> - <executions> - <execution> - <id>descriptor</id> - <goals> - <goal>generate-metadata</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> </project> diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/RepositoryContentFactory.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/RepositoryContentFactory.java index e035b48e7..47afff64b 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/RepositoryContentFactory.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/RepositoryContentFactory.java @@ -23,55 +23,55 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationNames; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.context.Context; -import org.codehaus.plexus.context.ContextException; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; -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.springframework.context.ApplicationContext; +import org.springframework.stereotype.Service; -import java.util.HashMap; +import javax.annotation.PostConstruct; +import javax.inject.Inject; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** - * RepositoryContentRequest + * RepositoryContentRequest * * @version $Id$ - * - * @plexus.component - * role="org.apache.maven.archiva.repository.RepositoryContentFactory" + * <p/> + * plexus.component + * role="org.apache.maven.archiva.repository.RepositoryContentFactory" */ +@Service( "repositoryContentFactory#default" ) public class RepositoryContentFactory - implements Contextualizable, RegistryListener, Initializable + implements RegistryListener { /** - * @plexus.requirement + * plexus.requirement */ + @Inject private ArchivaConfiguration archivaConfiguration; + @Inject + private ApplicationContext applicationContext; + private final Map<String, ManagedRepositoryContent> managedContentMap; private final Map<String, RemoteRepositoryContent> remoteContentMap; - private PlexusContainer container; public RepositoryContentFactory() { - managedContentMap = new HashMap<String, ManagedRepositoryContent>(); - remoteContentMap = new HashMap<String, RemoteRepositoryContent>(); + managedContentMap = new ConcurrentHashMap<String, ManagedRepositoryContent>(); + remoteContentMap = new ConcurrentHashMap<String, RemoteRepositoryContent>(); } /** * Get the ManagedRepositoryContent object for the repository Id specified. - * + * * @param repoId the repository id to fetch. * @return the ManagedRepositoryContent object associated with the repository id. * @throws RepositoryNotFoundException if the repository id does not exist within the configuration. - * @throws RepositoryException the repository content object cannot be loaded due to configuration issue. + * @throws RepositoryException the repository content object cannot be loaded due to configuration issue. */ public ManagedRepositoryContent getManagedRepositoryContent( String repoId ) throws RepositoryNotFoundException, RepositoryException @@ -83,24 +83,17 @@ public class RepositoryContentFactory return repo; } - ManagedRepositoryConfiguration repoConfig = archivaConfiguration.getConfiguration() - .findManagedRepositoryById( repoId ); + ManagedRepositoryConfiguration repoConfig = + archivaConfiguration.getConfiguration().findManagedRepositoryById( repoId ); if ( repoConfig == null ) { throw new RepositoryNotFoundException( "Unable to find managed repository configuration for id:" + repoId ); } - try - { - repo = (ManagedRepositoryContent) container.lookup( ManagedRepositoryContent.class, repoConfig.getLayout() ); - repo.setRepository( repoConfig ); - managedContentMap.put( repoId, repo ); - } - catch ( ComponentLookupException e ) - { - throw new RepositoryException( "Specified layout [" + repoConfig.getLayout() - + "] on managed repository id [" + repoId + "] is not valid.", e ); - } + repo = applicationContext.getBean( "managedRepositoryContent#" + repoConfig.getLayout(), + ManagedRepositoryContent.class ); + repo.setRepository( repoConfig ); + managedContentMap.put( repoId, repo ); return repo; } @@ -115,38 +108,26 @@ public class RepositoryContentFactory return repo; } - RemoteRepositoryConfiguration repoConfig = archivaConfiguration.getConfiguration() - .findRemoteRepositoryById( repoId ); + RemoteRepositoryConfiguration repoConfig = + archivaConfiguration.getConfiguration().findRemoteRepositoryById( repoId ); if ( repoConfig == null ) { throw new RepositoryNotFoundException( "Unable to find remote repository configuration for id:" + repoId ); } - try - { - repo = (RemoteRepositoryContent) container.lookup( RemoteRepositoryContent.class, repoConfig.getLayout() ); - repo.setRepository( repoConfig ); - remoteContentMap.put( repoId, repo ); - } - catch ( ComponentLookupException e ) - { - throw new RepositoryException( "Specified layout [" + repoConfig.getLayout() - + "] on remote repository id [" + repoId + "] is not valid.", e ); - } + repo = applicationContext.getBean( "RemoteRepositoryContent#" + repoConfig.getLayout(), + RemoteRepositoryContent.class ); + repo.setRepository( repoConfig ); + remoteContentMap.put( repoId, repo ); return repo; } - public void contextualize( Context context ) - throws ContextException - { - container = (PlexusContainer) context.get( "plexus" ); - } public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) { - if ( ConfigurationNames.isManagedRepositories( propertyName ) - || ConfigurationNames.isRemoteRepositories( propertyName ) ) + if ( ConfigurationNames.isManagedRepositories( propertyName ) || ConfigurationNames.isRemoteRepositories( + propertyName ) ) { initMaps(); } @@ -157,50 +138,33 @@ public class RepositoryContentFactory /* do nothing */ } + @PostConstruct public void initialize() - throws InitializationException { archivaConfiguration.addChangeListener( this ); } private void initMaps() { - synchronized ( managedContentMap ) - { - // First, return any references to the container. - for ( ManagedRepositoryContent repo : managedContentMap.values() ) - { - try - { - container.release( repo ); - } - catch ( ComponentLifecycleException e ) - { - /* ignore */ - } - } - - // Next clear the map. - managedContentMap.clear(); - } + // olamy we use concurent so no need of synchronize + //synchronized ( managedContentMap ) + //{ + managedContentMap.clear(); + //} + + //synchronized ( remoteContentMap ) + //{ + remoteContentMap.clear(); + //} + } - synchronized ( remoteContentMap ) - { - // First, return any references to the container. - for ( RemoteRepositoryContent repo : remoteContentMap.values() ) - { - try - { - container.release( repo ); - } - catch ( ComponentLifecycleException e ) - { - /* ignore */ - } - } - - // Next clear the map. - remoteContentMap.clear(); - } + public ArchivaConfiguration getArchivaConfiguration() + { + return archivaConfiguration; + } + + public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration ) + { + this.archivaConfiguration = archivaConfiguration; } } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/connector/RepositoryConnector.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/connector/RepositoryConnector.java index 317794e3a..c6d8655d9 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/connector/RepositoryConnector.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/connector/RepositoryConnector.java @@ -31,15 +31,15 @@ import java.util.List; */ public interface RepositoryConnector { - public ManagedRepositoryContent getSourceRepository(); + ManagedRepositoryContent getSourceRepository(); - public RemoteRepositoryContent getTargetRepository(); + RemoteRepositoryContent getTargetRepository(); - public List<String> getBlacklist(); + List<String> getBlacklist(); - public List<String> getWhitelist(); + List<String> getWhitelist(); - public boolean isDisabled(); + boolean isDisabled(); - public void setDisabled(boolean disabled); + void setDisabled(boolean disabled); } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java index db5e13659..07b02005a 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java @@ -31,7 +31,11 @@ import org.apache.maven.archiva.model.VersionedReference; import org.apache.maven.archiva.repository.layout.LayoutException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationContext; +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import java.util.ArrayList; import java.util.List; /** @@ -41,7 +45,7 @@ import java.util.List; */ public abstract class AbstractDefaultRepositoryContent { - protected Logger log = LoggerFactory.getLogger( AbstractDefaultRepositoryContent.class ); + protected Logger log = LoggerFactory.getLogger( getClass() ); public static final String MAVEN_METADATA = "maven-metadata.xml"; @@ -56,10 +60,20 @@ public abstract class AbstractDefaultRepositoryContent private PathParser defaultPathParser = new DefaultPathParser(); /** - * @plexus.requirement role="org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider" + * plexus.requirement role="org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider" */ protected List<? extends ArtifactMappingProvider> artifactMappingProviders; + @Inject + protected ApplicationContext applicationContext; + + @PostConstruct + protected void initialize() + { + artifactMappingProviders = new ArrayList<ArtifactMappingProvider>( + applicationContext.getBeansOfType( ArtifactMappingProvider.class ).values() ); + } + public ArtifactReference toArtifactReference( String path ) throws LayoutException { @@ -127,8 +141,8 @@ public abstract class AbstractDefaultRepositoryContent { if ( baseVersion != null ) { - return pathTranslator.toPath( groupId, artifactId, baseVersion, constructId( artifactId, version, - classifier, type ) ); + return pathTranslator.toPath( groupId, artifactId, baseVersion, + constructId( artifactId, version, classifier, type ) ); } else { diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java index 23f435a90..fb8e79ad7 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java @@ -24,6 +24,8 @@ import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.layout.LayoutException; +import javax.inject.Inject; +import javax.inject.Named; import java.util.HashMap; import java.util.Map; @@ -49,8 +51,10 @@ public abstract class AbstractLegacyRepositoryContent } /** - * @plexus.requirement role-hint="legacy" + * plexus.requirement role-hint="legacy" */ + @Inject + @Named( value = "pathParser#legacy" ) private PathParser legacyPathParser; public ArtifactReference toArtifactReference( String path ) @@ -66,8 +70,8 @@ public abstract class AbstractLegacyRepositoryContent throw new IllegalArgumentException( "Artifact reference cannot be null" ); } - return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference - .getClassifier(), reference.getType() ); + return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), + reference.getClassifier(), reference.getType() ); } public String toPath( ArtifactReference reference ) @@ -77,8 +81,8 @@ public abstract class AbstractLegacyRepositoryContent throw new IllegalArgumentException( "Artifact reference cannot be null" ); } - return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference - .getClassifier(), reference.getType() ); + return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), + reference.getClassifier(), reference.getType() ); } private String toPath( String groupId, String artifactId, String version, String classifier, String type ) @@ -115,7 +119,7 @@ public abstract class AbstractLegacyRepositoryContent // Default process. return type + "s"; } - + public void setLegacyPathParser( PathParser parser ) { this.legacyPathParser = parser; diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java index 0246b1384..525043f6c 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java @@ -28,6 +28,7 @@ import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.layout.LayoutException; +import org.springframework.stereotype.Service; import java.util.Collections; @@ -39,6 +40,7 @@ import java.util.Collections; * * @version $Id$ */ +@Service( "pathParser#default" ) public class DefaultPathParser implements PathParser { diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java index 53b9e145c..8574793e5 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java @@ -19,33 +19,33 @@ package org.apache.maven.archiva.repository.content; * under the License. */ -import java.util.Collection; - import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.LegacyArtifactPath; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.layout.LayoutException; +import java.util.Collection; + /** * LegacyPathParser is a parser for maven 1 (legacy layout) paths to * ArtifactReference. * * @version $Id$ - * @plexus.component role="org.apache.maven.archiva.repository.content.PathParser" - * role-hint="legacy" */ public class LegacyPathParser implements PathParser { private static final String INVALID_ARTIFACT_PATH = "Invalid path to Artifact: "; - /** - * @todo pass these in on construction instead, since this can't be long lived (no config listener), then no need to be a component - * @plexus.requirement - */ protected ArchivaConfiguration configuration; + public LegacyPathParser( ArchivaConfiguration configuration ) + { + this.configuration = configuration; + } + + /** * {@inheritDoc} * @@ -61,12 +61,12 @@ public class LegacyPathParser for ( LegacyArtifactPath legacyPath : legacy ) { if ( legacyPath.match( path ) ) - { - artifact.setGroupId( legacyPath.getGroupId() ); - artifact.setArtifactId( legacyPath.getArtifactId() ); - artifact.setClassifier( legacyPath.getClassifier() ); - artifact.setVersion( legacyPath.getVersion() ); - artifact.setType( legacyPath.getType() ); + { + artifact.setGroupId( legacyPath.getGroupId() ); + artifact.setArtifactId( legacyPath.getArtifactId() ); + artifact.setClassifier( legacyPath.getClassifier() ); + artifact.setVersion( legacyPath.getVersion() ); + artifact.setType( legacyPath.getType() ); return artifact; } } @@ -87,8 +87,8 @@ public class LegacyPathParser { // Illegal Path Parts Length. throw new LayoutException( INVALID_ARTIFACT_PATH - + "legacy paths should only have 3 parts [groupId]/[type]s/[artifactId]-[version].[type], found " - + pathParts.length + " instead." ); + + "legacy paths should only have 3 parts [groupId]/[type]s/[artifactId]-[version].[type], found " + + pathParts.length + " instead." ); } // The Group ID. @@ -101,7 +101,7 @@ public class LegacyPathParser if ( !expectedType.endsWith( "s" ) ) { throw new LayoutException( INVALID_ARTIFACT_PATH - + "legacy paths should have an expected type ending in [s] in the second part of the path." ); + + "legacy paths should have an expected type ending in [s] in the second part of the path." ); } // The Filename. @@ -164,9 +164,10 @@ public class LegacyPathParser if ( classifier != null ) { String version = artifact.getVersion(); - if ( ! version.endsWith( "-" + classifier ) ) + if ( !version.endsWith( "-" + classifier ) ) { - throw new LayoutException( INVALID_ARTIFACT_PATH + expectedType + " artifacts must use the classifier " + classifier ); + throw new LayoutException( + INVALID_ARTIFACT_PATH + expectedType + " artifacts must use the classifier " + classifier ); } version = version.substring( 0, version.length() - classifier.length() - 1 ); artifact.setVersion( version ); @@ -198,9 +199,10 @@ public class LegacyPathParser if ( !expectedExtension.equals( extension ) ) { - throw new LayoutException( INVALID_ARTIFACT_PATH + "mismatch on extension [" + extension - + "] and layout specified type [" + artifact.getType() + "] (which maps to extension: [" - + expectedExtension + "]) on path [" + path + "]" ); + throw new LayoutException( + INVALID_ARTIFACT_PATH + "mismatch on extension [" + extension + "] and layout specified type [" + + artifact.getType() + "] (which maps to extension: [" + expectedExtension + "]) on path [" + + path + "]" ); } } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java index acc540c04..ea7e47795 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java @@ -31,7 +31,10 @@ import org.apache.maven.archiva.model.VersionedReference; import org.apache.maven.archiva.repository.ContentNotFoundException; import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.layout.LayoutException; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; +import javax.inject.Inject; import java.io.File; import java.io.IOException; import java.util.Collections; @@ -43,18 +46,18 @@ import java.util.Set; * * @version $Id$ * - * @plexus.component + * plexus.component * role="org.apache.maven.archiva.repository.ManagedRepositoryContent" * role-hint="default" * instantiation-strategy="per-lookup" */ +@Service("managedRepositoryContent#default") +@Scope("prototype") public class ManagedDefaultRepositoryContent extends AbstractDefaultRepositoryContent implements ManagedRepositoryContent { - /** - * @plexus.requirement - */ + @Inject private FileTypes filetypes; private ManagedRepositoryConfiguration repository; @@ -352,7 +355,6 @@ public class ManagedDefaultRepositoryContent /** * Get the first Artifact found in the provided VersionedReference location. * - * @param managedRepository the repository to search within. * @param reference the reference to the versioned reference to search within * @return the ArtifactReference to the first artifact located within the versioned reference. or null if * no artifact was found within the versioned reference. diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContent.java index ba98e445e..0ba6d1869 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContent.java @@ -31,7 +31,10 @@ import org.apache.maven.archiva.model.VersionedReference; import org.apache.maven.archiva.repository.ContentNotFoundException; import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.layout.LayoutException; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; +import javax.inject.Inject; import java.io.File; import java.util.HashSet; import java.util.Set; @@ -48,13 +51,16 @@ import java.util.Set; * role-hint="legacy" * instantiation-strategy="per-lookup" */ +@Service("managedRepositoryContent#legacy") +@Scope("prototype") public class ManagedLegacyRepositoryContent extends AbstractLegacyRepositoryContent implements ManagedRepositoryContent { /** - * @plexus.requirement + * plexus.requirement */ + @Inject private FileTypes filetypes; private ManagedRepositoryConfiguration repository; diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/PathParser.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/PathParser.java index 307f0edce..83c4c440f 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/PathParser.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/PathParser.java @@ -24,7 +24,7 @@ import org.apache.maven.archiva.repository.layout.LayoutException; /** * PathParser interface. - * + * * @version $Id$ */ public interface PathParser @@ -32,12 +32,12 @@ public interface PathParser /** * Take a path and get the ArtifactReference associated with it. - * + * * @param path the relative path to parse. * @return the ArtifactReference for the provided path. (never null) * @throws LayoutException if there was a problem parsing the path. */ - public ArtifactReference toArtifactReference( String path ) + ArtifactReference toArtifactReference( String path ) throws LayoutException; } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteDefaultRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteDefaultRepositoryContent.java index fe634488d..62448eb6a 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteDefaultRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteDefaultRepositoryContent.java @@ -24,17 +24,21 @@ import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.model.RepositoryURL; import org.apache.maven.archiva.repository.RemoteRepositoryContent; import org.apache.maven.archiva.repository.layout.LayoutException; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; /** - * RemoteDefaultRepositoryContent + * RemoteDefaultRepositoryContent * * @version $Id$ - * - * @plexus.component - * role="org.apache.maven.archiva.repository.RemoteRepositoryContent" - * role-hint="default" - * instantiation-strategy="per-lookup" + * <p/> + * plexus.component + * role="org.apache.maven.archiva.repository.RemoteRepositoryContent" + * role-hint="default" + * instantiation-strategy="per-lookup" */ +@Service( "remoteRepositoryContent#default" ) +@Scope( "prototype" ) public class RemoteDefaultRepositoryContent extends AbstractDefaultRepositoryContent implements RemoteRepositoryContent @@ -63,7 +67,7 @@ public class RemoteDefaultRepositoryContent /** * Convert a path to an artifact reference. - * + * * @param path the path to convert. (relative or full url path) * @throws LayoutException if the path cannot be converted to an artifact reference. */ diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteLegacyRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteLegacyRepositoryContent.java index 993b27572..d93d0de4e 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteLegacyRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteLegacyRepositoryContent.java @@ -24,19 +24,20 @@ import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.model.RepositoryURL; import org.apache.maven.archiva.repository.RemoteRepositoryContent; import org.apache.maven.archiva.repository.layout.LayoutException; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; /** - * RemoteLegacyRepositoryContent + * RemoteLegacyRepositoryContent * * @version $Id$ - * * @todo no need to be a component once legacy path parser is not - * - * @plexus.component - * role="org.apache.maven.archiva.repository.RemoteRepositoryContent" - * role-hint="legacy" - * instantiation-strategy="per-lookup" + * plexus.component role="org.apache.maven.archiva.repository.RemoteRepositoryContent" + * role-hint="legacy" + * instantiation-strategy="per-lookup" */ +@Service( "remoteRepositoryContent#legacy" ) +@Scope( "prototype" ) public class RemoteLegacyRepositoryContent extends AbstractLegacyRepositoryContent implements RemoteRepositoryContent @@ -65,7 +66,7 @@ public class RemoteLegacyRepositoryContent /** * Convert a path to an artifact reference. - * + * * @param path the path to convert. (relative or full url path) * @throws LayoutException if the path cannot be converted to an artifact reference. */ diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java index e39b56494..f6b44c2d4 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java @@ -24,27 +24,30 @@ import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.layout.LayoutException; import org.apache.maven.archiva.repository.metadata.MetadataTools; +import org.springframework.stereotype.Service; + +import javax.inject.Inject; +import javax.inject.Named; /** * RepositoryRequest is used to determine the type of request that is incoming, and convert it to an appropriate * ArtifactReference. * * @version $Id$ - * * @todo no need to be a component once legacy path parser is not - * - * @plexus.component - * role="org.apache.maven.archiva.repository.content.RepositoryRequest" + * <p/> */ public class RepositoryRequest { private PathParser defaultPathParser = new DefaultPathParser(); - /** - * @plexus.requirement role-hint="legacy" - */ private PathParser legacyPathParser; + public RepositoryRequest (LegacyPathParser legacyPathParser) + { + this.legacyPathParser = legacyPathParser; + } + /** * Takes an incoming requested path (in "/" format) and gleans the layout * and ArtifactReference appropriate for that content. @@ -135,18 +138,18 @@ public class RepositoryRequest public boolean isMetadataSupportFile( String requestedPath ) { - if( isSupportFile( requestedPath ) ) + if ( isSupportFile( requestedPath ) ) { String basefilePath = StringUtils.substring( requestedPath, 0, requestedPath.lastIndexOf( '.' ) ); - if( isMetadata( basefilePath ) ) + if ( isMetadata( basefilePath ) ) { return true; } } - + return false; } - + /** * <p> * Tests the path to see if it conforms to the expectations of a default layout request. @@ -168,31 +171,31 @@ public class RepositoryRequest return false; } - String pathParts[] = StringUtils.splitPreserveAllTokens( requestedPath, '/' ); - if( pathParts.length > 3 ) + String pathParts[] = StringUtils.splitPreserveAllTokens( requestedPath, '/' ); + if ( pathParts.length > 3 ) { return true; } else if ( pathParts.length == 3 ) - { + { // check if artifact-level metadata (ex. eclipse/jdtcore/maven-metadata.xml) - if( isMetadata( requestedPath ) ) + if ( isMetadata( requestedPath ) ) { return true; } - else + else { // check if checksum of artifact-level metadata (ex. eclipse/jdtcore/maven-metadata.xml.sha1) - int idx = requestedPath.lastIndexOf( '.' ); + int idx = requestedPath.lastIndexOf( '.' ); if ( idx > 0 ) { String base = requestedPath.substring( 0, idx ); - if( isMetadata( base ) && isSupportFile( requestedPath ) ) + if ( isMetadata( base ) && isSupportFile( requestedPath ) ) { return true; } } - + return false; } } @@ -231,11 +234,12 @@ public class RepositoryRequest * Adjust the requestedPath to conform to the native layout of the provided {@link ManagedRepositoryContent}. * * @param requestedPath the incoming requested path. - * @param repository the repository to adjust to. + * @param repository the repository to adjust to. * @return the adjusted (to native) path. * @throws LayoutException if the path cannot be parsed. */ - public String toNativePath( String requestedPath, ManagedRepositoryContent repository ) throws LayoutException + public String toNativePath( String requestedPath, ManagedRepositoryContent repository ) + throws LayoutException { if ( StringUtils.isBlank( requestedPath ) ) { @@ -247,7 +251,7 @@ public class RepositoryRequest String supportfile = ""; // Figure out support file, and actual referencedResource. - if( isSupportFile( requestedPath ) ) + if ( isSupportFile( requestedPath ) ) { int idx = requestedPath.lastIndexOf( '.' ); referencedResource = requestedPath.substring( 0, idx ); diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/MetadataTools.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/MetadataTools.java index 59629946c..becf93038 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/MetadataTools.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/MetadataTools.java @@ -22,6 +22,7 @@ package org.apache.maven.archiva.repository.metadata; import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.checksum.ChecksummedFile; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang.time.DateUtils; @@ -42,13 +43,15 @@ import org.apache.maven.archiva.repository.ContentNotFoundException; import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.RemoteRepositoryContent; import org.apache.maven.archiva.repository.layout.LayoutException; -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.stereotype.Service; +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.inject.Named; import java.io.File; import java.io.IOException; import java.text.ParseException; @@ -66,19 +69,19 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Matcher; -import org.apache.commons.io.FileUtils; /** * MetadataTools * * @version $Id$ - * - * @plexus.component role="org.apache.maven.archiva.repository.metadata.MetadataTools" + * <p/> + * plexus.component role="org.apache.maven.archiva.repository.metadata.MetadataTools" */ +@Service( "metadataTools#default" ) public class MetadataTools - implements RegistryListener, Initializable + implements RegistryListener { - private static Logger log = LoggerFactory.getLogger( MetadataTools.class ); + private Logger log = LoggerFactory.getLogger( getClass() ); public static final String MAVEN_METADATA = "maven-metadata.xml"; @@ -87,22 +90,25 @@ public class MetadataTools private static final char GROUP_SEPARATOR = '.'; /** - * @plexus.requirement + * plexus.requirement */ + @Inject + @Named( value = "archivaConfiguration#default" ) private ArchivaConfiguration configuration; /** - * @plexus.requirement + * plexus.requirement */ + @Inject private FileTypes filetypes; - - private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[] { ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 }; - + + private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 }; + private List<String> artifactPatterns; private Map<String, Set<String>> proxies; - private static final char NUMS[] = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; + private static final char NUMS[] = new char[]{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; private SimpleDateFormat lastUpdatedFormat; @@ -130,9 +136,10 @@ public class MetadataTools * * @return the Set of snapshot artifact versions found. * @throws LayoutException - * @throws ContentNotFoundException + * @throws ContentNotFoundException */ - public Set<String> gatherSnapshotVersions( ManagedRepositoryContent managedRepository, VersionedReference reference ) + public Set<String> gatherSnapshotVersions( ManagedRepositoryContent managedRepository, + VersionedReference reference ) throws LayoutException, IOException, ContentNotFoundException { Set<String> foundVersions = managedRepository.getVersions( reference ); @@ -209,7 +216,7 @@ public class MetadataTools { // Scary check, but without it, all paths are version references; throw new RepositoryMetadataException( - "Not a versioned reference, as version id on path has no number in it." ); + "Not a versioned reference, as version id on path has no number in it." ); } reference.setArtifactId( pathParts[artifactIdOffset] ); @@ -336,8 +343,8 @@ public class MetadataTools return ret.toString(); } + @PostConstruct public void initialize() - throws InitializationException { this.artifactPatterns = new ArrayList<String>(); this.proxies = new HashMap<String, Set<String>>(); @@ -351,7 +358,7 @@ public class MetadataTools { String metadataPath = getRepositorySpecificName( proxyId, toPath( reference ) ); File metadataFile = new File( managedRepository.getRepoRoot(), metadataPath ); - + if ( !metadataFile.exists() || !metadataFile.isFile() ) { // Nothing to do. return null. @@ -370,13 +377,13 @@ public class MetadataTools return null; } } - + public ArchivaRepositoryMetadata readProxyMetadata( ManagedRepositoryContent managedRepository, String logicalResource, String proxyId ) { String metadataPath = getRepositorySpecificName( proxyId, logicalResource ); File metadataFile = new File( managedRepository.getRepoRoot(), metadataPath ); - + if ( !metadataFile.exists() || !metadataFile.isFile() ) { // Nothing to do. return null. @@ -401,7 +408,7 @@ public class MetadataTools { String metadataPath = getRepositorySpecificName( proxyId, toPath( reference ) ); File metadataFile = new File( managedRepository.getRepoRoot(), metadataPath ); - + if ( !metadataFile.exists() || !metadataFile.isFile() ) { // Nothing to do. return null. @@ -420,112 +427,116 @@ public class MetadataTools return null; } } - - public void updateMetadata( ManagedRepositoryContent managedRepository, String logicalResource) throws RepositoryMetadataException + + public void updateMetadata( ManagedRepositoryContent managedRepository, String logicalResource ) + throws RepositoryMetadataException { - final File metadataFile = new File(managedRepository.getRepoRoot(), logicalResource); + final File metadataFile = new File( managedRepository.getRepoRoot(), logicalResource ); ArchivaRepositoryMetadata metadata = null; - + //Gather and merge all metadata available - List<ArchivaRepositoryMetadata> metadatas = getMetadatasForManagedRepository(managedRepository, logicalResource); - for (ArchivaRepositoryMetadata proxiedMetadata : metadatas) + List<ArchivaRepositoryMetadata> metadatas = + getMetadatasForManagedRepository( managedRepository, logicalResource ); + for ( ArchivaRepositoryMetadata proxiedMetadata : metadatas ) { - if (metadata == null) + if ( metadata == null ) { metadata = proxiedMetadata; continue; } - metadata = RepositoryMetadataMerge.merge(metadata, proxiedMetadata); + metadata = RepositoryMetadataMerge.merge( metadata, proxiedMetadata ); } - - if (metadata == null) + + if ( metadata == null ) { - log.debug("No metadata to update for " + logicalResource); + log.debug( "No metadata to update for " + logicalResource ); return; } - + Set<String> availableVersions = new HashSet<String>(); List<String> metadataAvailableVersions = metadata.getAvailableVersions(); - if (metadataAvailableVersions != null) + if ( metadataAvailableVersions != null ) { - availableVersions.addAll(metadataAvailableVersions); + availableVersions.addAll( metadataAvailableVersions ); } - availableVersions = findPossibleVersions(availableVersions, metadataFile.getParentFile()); + availableVersions = findPossibleVersions( availableVersions, metadataFile.getParentFile() ); - if (availableVersions.size() > 0) + if ( availableVersions.size() > 0 ) { - updateMetadataVersions(availableVersions, metadata); + updateMetadataVersions( availableVersions, metadata ); } - - RepositoryMetadataWriter.write(metadata, metadataFile); - + + RepositoryMetadataWriter.write( metadata, metadataFile ); + ChecksummedFile checksum = new ChecksummedFile( metadataFile ); checksum.fixChecksums( algorithms ); } - + /** - * Skims the parent directory of a metadata in vain hope of finding + * Skims the parent directory of a metadata in vain hope of finding * subdirectories that contain poms. - * + * * @param metadataParentDirectory * @return origional set plus newley found versions */ - private Set<String> findPossibleVersions(Set<String> versions, File metadataParentDirectory) + private Set<String> findPossibleVersions( Set<String> versions, File metadataParentDirectory ) { - Set<String> result = new HashSet<String>(versions); - for (File directory : metadataParentDirectory.listFiles()) + Set<String> result = new HashSet<String>( versions ); + for ( File directory : metadataParentDirectory.listFiles() ) { - if (directory.isDirectory()) + if ( directory.isDirectory() ) { - for (File possiblePom : directory.listFiles()) + for ( File possiblePom : directory.listFiles() ) { - if (possiblePom.getName().endsWith(".pom")) + if ( possiblePom.getName().endsWith( ".pom" ) ) { - result.add(directory.getName()); + result.add( directory.getName() ); } } } } return result; } - - private List<ArchivaRepositoryMetadata> getMetadatasForManagedRepository( ManagedRepositoryContent managedRepository, String logicalResource ) + + private List<ArchivaRepositoryMetadata> getMetadatasForManagedRepository( + ManagedRepositoryContent managedRepository, String logicalResource ) { List<ArchivaRepositoryMetadata> metadatas = new ArrayList<ArchivaRepositoryMetadata>(); - File file = new File(managedRepository.getRepoRoot(), logicalResource); - if (file.exists()) + File file = new File( managedRepository.getRepoRoot(), logicalResource ); + if ( file.exists() ) { try { - ArchivaRepositoryMetadata existingMetadata = RepositoryMetadataReader.read(file); - if (existingMetadata != null) - { - metadatas.add(existingMetadata); - } + ArchivaRepositoryMetadata existingMetadata = RepositoryMetadataReader.read( file ); + if ( existingMetadata != null ) + { + metadatas.add( existingMetadata ); + } } - catch (RepositoryMetadataException e) + catch ( RepositoryMetadataException e ) { - log.debug("Could not read metadata at " + file.getAbsolutePath() + ". Metadata will be removed."); - FileUtils.deleteQuietly(file); + log.debug( "Could not read metadata at " + file.getAbsolutePath() + ". Metadata will be removed." ); + FileUtils.deleteQuietly( file ); } } - - Set<String> proxyIds = proxies.get(managedRepository.getId()); - if (proxyIds != null) + + Set<String> proxyIds = proxies.get( managedRepository.getId() ); + if ( proxyIds != null ) { - for (String proxyId : proxyIds) + for ( String proxyId : proxyIds ) { - ArchivaRepositoryMetadata proxyMetadata = readProxyMetadata( managedRepository, logicalResource, proxyId ); - if (proxyMetadata != null) + ArchivaRepositoryMetadata proxyMetadata = + readProxyMetadata( managedRepository, logicalResource, proxyId ); + if ( proxyMetadata != null ) { - metadatas.add(proxyMetadata); + metadatas.add( proxyMetadata ); } } } - + return metadatas; } - + /** * Update the metadata to represent the all versions/plugins of @@ -533,16 +544,16 @@ public class MetadataTools * based off of information present in the repository, * the maven-metadata.xml files, and the proxy/repository specific * metadata file contents. - * + * <p/> * We must treat this as a group or a project metadata file as there is no way to know in advance * - * @deprecated * @param managedRepository the managed repository where the metadata is kept. * @param reference the reference to update. * @throws LayoutException * @throws RepositoryMetadataException * @throws IOException - * @throws ContentNotFoundException + * @throws ContentNotFoundException + * @deprecated */ public void updateMetadata( ManagedRepositoryContent managedRepository, ProjectReference reference ) throws LayoutException, RepositoryMetadataException, IOException, ContentNotFoundException @@ -596,7 +607,7 @@ public class MetadataTools if ( !allVersions.isEmpty() ) { - updateMetadataVersions( allVersions ,metadata ); + updateMetadataVersions( allVersions, metadata ); } else { @@ -619,44 +630,44 @@ public class MetadataTools checksum.fixChecksums( algorithms ); } - private void updateMetadataVersions(Collection<String> allVersions, ArchivaRepositoryMetadata metadata) + private void updateMetadataVersions( Collection<String> allVersions, ArchivaRepositoryMetadata metadata ) { // Sort the versions - List<String> sortedVersions = new ArrayList<String>(allVersions); - Collections.sort(sortedVersions, VersionComparator.getInstance()); + List<String> sortedVersions = new ArrayList<String>( allVersions ); + Collections.sort( sortedVersions, VersionComparator.getInstance() ); // Split the versions into released and snapshots. List<String> releasedVersions = new ArrayList<String>(); List<String> snapshotVersions = new ArrayList<String>(); - for (String version : sortedVersions) + for ( String version : sortedVersions ) { - if (VersionUtil.isSnapshot(version)) + if ( VersionUtil.isSnapshot( version ) ) { - snapshotVersions.add(version); + snapshotVersions.add( version ); } - else + else { - releasedVersions.add(version); + releasedVersions.add( version ); } } - Collections.sort(releasedVersions, VersionComparator.getInstance()); - Collections.sort(snapshotVersions, VersionComparator.getInstance()); + Collections.sort( releasedVersions, VersionComparator.getInstance() ); + Collections.sort( snapshotVersions, VersionComparator.getInstance() ); - String latestVersion = sortedVersions.get(sortedVersions.size() - 1); + String latestVersion = sortedVersions.get( sortedVersions.size() - 1 ); String releaseVersion = null; - if (CollectionUtils.isNotEmpty(releasedVersions)) + if ( CollectionUtils.isNotEmpty( releasedVersions ) ) { - releaseVersion = releasedVersions.get(releasedVersions.size() - 1); + releaseVersion = releasedVersions.get( releasedVersions.size() - 1 ); } // Add the versions to the metadata model. - metadata.setAvailableVersions(sortedVersions); + metadata.setAvailableVersions( sortedVersions ); - metadata.setLatestVersion(latestVersion); - metadata.setReleasedVersion(releaseVersion); + metadata.setLatestVersion( latestVersion ); + metadata.setReleasedVersion( releaseVersion ); } private Date toLastUpdatedDate( long lastUpdated ) @@ -666,7 +677,7 @@ public class MetadataTools return cal.getTime(); } - + private long toLastUpdatedLong( String timestampString ) { try @@ -739,13 +750,13 @@ public class MetadataTools * 2) If this is a RELEASE reference, and the metadata file does not exist, then * create the metadata file with contents required of the VersionedReference * - * @deprecated * @param managedRepository the managed repository where the metadata is kept. * @param reference the versioned reference to update * @throws LayoutException * @throws RepositoryMetadataException * @throws IOException - * @throws ContentNotFoundException + * @throws ContentNotFoundException + * @deprecated */ public void updateMetadata( ManagedRepositoryContent managedRepository, VersionedReference reference ) throws LayoutException, RepositoryMetadataException, IOException, ContentNotFoundException @@ -757,7 +768,7 @@ public class MetadataTools ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata(); metadata.setGroupId( reference.getGroupId() ); metadata.setArtifactId( reference.getArtifactId() ); - + if ( VersionUtil.isSnapshot( reference.getVersion() ) ) { // Do SNAPSHOT handling. @@ -769,8 +780,8 @@ public class MetadataTools if ( snapshotVersions.isEmpty() ) { - throw new ContentNotFoundException( "No snapshot versions found on reference [" - + VersionedReference.toKey( reference ) + "]." ); + throw new ContentNotFoundException( + "No snapshot versions found on reference [" + VersionedReference.toKey( reference ) + "]." ); } // sort the list to determine to aide in determining the Latest version. @@ -797,11 +808,11 @@ public class MetadataTools { String tsDate = mtimestamp.group( 1 ); String tsTime = mtimestamp.group( 2 ); - + long snapshotLastUpdated = toLastUpdatedLong( tsDate + tsTime ); - + lastUpdated = Math.max( lastUpdated, snapshotLastUpdated ); - + metadata.getSnapshotVersion().setTimestamp( m.group( 2 ) ); } } @@ -837,8 +848,8 @@ public class MetadataTools } else { - throw new RepositoryMetadataException( "Unable to process snapshot version <" + latestVersion - + "> reference <" + reference + ">" ); + throw new RepositoryMetadataException( + "Unable to process snapshot version <" + latestVersion + "> reference <" + reference + ">" ); } } else @@ -873,7 +884,7 @@ public class MetadataTools this.proxies.clear(); List<ProxyConnectorConfiguration> proxyConfigs = configuration.getConfiguration().getProxyConnectors(); - for( ProxyConnectorConfiguration proxyConfig: proxyConfigs ) + for ( ProxyConnectorConfiguration proxyConfig : proxyConfigs ) { String key = proxyConfig.getSourceRepoId(); @@ -901,7 +912,8 @@ public class MetadataTools * @throws IOException if the versioned reference is invalid (example: doesn't exist, or isn't a directory) * @throws LayoutException */ - public ArtifactReference getFirstArtifact( ManagedRepositoryContent managedRepository, VersionedReference reference ) + public ArtifactReference getFirstArtifact( ManagedRepositoryContent managedRepository, + VersionedReference reference ) throws LayoutException, IOException { String path = toPath( reference ); @@ -917,13 +929,13 @@ public class MetadataTools if ( !repoDir.exists() ) { throw new IOException( "Unable to gather the list of snapshot versions on a non-existant directory: " - + repoDir.getAbsolutePath() ); + + repoDir.getAbsolutePath() ); } if ( !repoDir.isDirectory() ) { - throw new IOException( "Unable to gather the list of snapshot versions on a non-directory: " - + repoDir.getAbsolutePath() ); + throw new IOException( + "Unable to gather the list of snapshot versions on a non-directory: " + repoDir.getAbsolutePath() ); } File repoFiles[] = repoDir.listFiles(); @@ -948,4 +960,24 @@ public class MetadataTools // No artifact was found. return null; } + + public ArchivaConfiguration getConfiguration() + { + return configuration; + } + + public void setConfiguration( ArchivaConfiguration configuration ) + { + this.configuration = configuration; + } + + public FileTypes getFiletypes() + { + return filetypes; + } + + public void setFiletypes( FileTypes filetypes ) + { + this.filetypes = filetypes; + } } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/AbstractRepositoryLayerTestCase.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/AbstractRepositoryLayerTestCase.java index 1947204f3..7697905b7 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/AbstractRepositoryLayerTestCase.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/AbstractRepositoryLayerTestCase.java @@ -19,10 +19,15 @@ package org.apache.maven.archiva.repository; * under the License. */ +import junit.framework.TestCase; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; +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; /** @@ -30,18 +35,14 @@ import java.io.File; * * @version $Id$ */ +@RunWith( SpringJUnit4ClassRunner.class ) +@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) public abstract class AbstractRepositoryLayerTestCase - extends PlexusInSpringTestCase + extends TestCase { - /** - * {@inheritDoc} - * @see org.codehaus.plexus.spring.PlexusInSpringTestCase#getSpringConfigLocation() - */ - @Override - protected String getSpringConfigLocation() - { - return "org/apache/maven/archiva/repository/spring-context.xml"; - } + + @Inject + protected ApplicationContext applicationContext; protected ManagedRepositoryConfiguration createRepository( String id, String name, File location ) { @@ -61,7 +62,8 @@ public abstract class AbstractRepositoryLayerTestCase return repo; } - protected ManagedRepositoryContent createManagedRepositoryContent( String id, String name, File location, String layout ) + protected ManagedRepositoryContent createManagedRepositoryContent( String id, String name, File location, + String layout ) throws Exception { ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration(); @@ -70,7 +72,8 @@ public abstract class AbstractRepositoryLayerTestCase repo.setLocation( location.getAbsolutePath() ); repo.setLayout( layout ); - ManagedRepositoryContent repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, layout ); + ManagedRepositoryContent repoContent = + applicationContext.getBean( "managedRepositoryContent#" + layout, ManagedRepositoryContent.class ); repoContent.setRepository( repo ); return repoContent; @@ -85,7 +88,8 @@ public abstract class AbstractRepositoryLayerTestCase repo.setUrl( url ); repo.setLayout( layout ); - RemoteRepositoryContent repoContent = (RemoteRepositoryContent) lookup( RemoteRepositoryContent.class, layout ); + RemoteRepositoryContent repoContent = + applicationContext.getBean( "remoteRepositoryContent#" + layout, RemoteRepositoryContent.class ); repoContent.setRepository( repo ); return repoContent; diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/MockConfiguration.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/MockConfiguration.java index 63edd8b4c..713d5bb13 100755 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/MockConfiguration.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/MockConfiguration.java @@ -26,6 +26,7 @@ import org.codehaus.plexus.registry.Registry; import org.codehaus.plexus.registry.RegistryException; import org.codehaus.plexus.registry.RegistryListener; import org.easymock.MockControl; +import org.springframework.stereotype.Service; import java.util.HashSet; import java.util.Set; @@ -35,9 +36,10 @@ import java.util.Set; * * @version $Id$ * - * @plexus.component role="org.apache.maven.archiva.configuration.ArchivaConfiguration" + * plexus.component role="org.apache.maven.archiva.configuration.ArchivaConfiguration" * role-hint="mock" */ +@Service("archivaConfiguration#mock") public class MockConfiguration implements ArchivaConfiguration { diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContentTestCase.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContentTestCase.java index bdbb6cc20..a1434ae26 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContentTestCase.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContentTestCase.java @@ -23,6 +23,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase; import org.apache.maven.archiva.repository.layout.LayoutException; +import org.junit.Test; /** * AbstractDefaultRepositoryContentTestCase @@ -32,37 +33,44 @@ import org.apache.maven.archiva.repository.layout.LayoutException; public abstract class AbstractDefaultRepositoryContentTestCase extends AbstractRepositoryLayerTestCase { + @Test public void testBadPathMissingType() { assertBadPath( "invalid/invalid/1/invalid-1", "missing type" ); } + @Test public void testBadPathReleaseInSnapshotDir() { assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", "non snapshot artifact inside of a snapshot dir" ); } + @Test public void testBadPathTimestampedSnapshotNotInSnapshotDir() { assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar", "Timestamped Snapshot artifact not inside of an Snapshot dir" ); } + @Test public void testBadPathTooShort() { assertBadPath( "invalid/invalid-1.0.jar", "path is too short" ); } + @Test public void testBadPathVersionMismatchA() { assertBadPath( "invalid/invalid/1.0/invalid-2.0.jar", "version mismatch between path and artifact" ); } + @Test public void testBadPathVersionMismatchB() { assertBadPath( "invalid/invalid/1.0/invalid-1.0b.jar", "version mismatch between path and artifact" ); } + @Test public void testBadPathWrongArtifactId() { assertBadPath( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar", @@ -74,6 +82,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase * Example of an oddball / unusual version spec. * @throws LayoutException */ + @Test public void testGoodButOddVersionSpecGanymedSsh2() throws LayoutException { @@ -92,6 +101,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase * Example of an oddball / unusual version spec. * @throws LayoutException */ + @Test public void testGoodButOddVersionSpecJavaxComm() throws LayoutException { @@ -131,6 +141,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase * Example of an oddball / unusual version spec. * @throws LayoutException */ + @Test public void testGoodButOddVersionSpecJavaxPersistence() throws LayoutException { @@ -151,6 +162,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase assertLayout( path, groupId, artifactId, version, classifier, type ); } + @Test public void testGoodComFooTool() throws LayoutException { @@ -164,6 +176,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase assertLayout( path, groupId, artifactId, version, classifier, type ); } + @Test public void testGoodCommonsLang() throws LayoutException { @@ -180,6 +193,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase /** * [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected" */ + @Test public void testGoodDashedArtifactId() throws LayoutException { @@ -196,6 +210,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase /** * It may seem odd, but this is a valid artifact. */ + @Test public void testGoodDotNotationArtifactId() throws LayoutException { @@ -212,6 +227,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase /** * It may seem odd, but this is a valid artifact. */ + @Test public void testGoodDotNotationSameGroupIdAndArtifactId() throws LayoutException { @@ -229,6 +245,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase * Test the classifier, and java-source type spec. * @throws LayoutException */ + @Test public void testGoodFooLibSources() throws LayoutException { @@ -246,6 +263,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory. * @throws LayoutException */ + @Test public void testGoodSnapshotMavenTest() throws LayoutException { @@ -263,6 +281,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase * [MRM-519] version identifiers within filename cause misidentification of version. * Example uses "test" in artifact Id, which is also part of the versionKeyword list. */ + @Test public void testGoodVersionKeywordInArtifactId() throws LayoutException { @@ -280,6 +299,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. * Example uses "test" in artifact Id, which is also part of the versionKeyword list. */ + @Test public void testGoodDetectMavenTestPlugin() throws LayoutException { @@ -296,6 +316,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase /** * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. */ + @Test public void testGoodDetectCoberturaMavenPlugin() throws LayoutException { @@ -309,6 +330,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase assertLayout( path, groupId, artifactId, version, classifier, type ); } + @Test public void testToArtifactOnEmptyPath() { try @@ -322,6 +344,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase } } + @Test public void testToArtifactOnNullPath() { try @@ -335,6 +358,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase } } + @Test public void testToArtifactReferenceOnEmptyPath() { try @@ -348,6 +372,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase } } + @Test public void testToArtifactReferenceOnNullPath() { try @@ -361,6 +386,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase } } + @Test public void testToPathOnNullArtifactReference() { diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java index c5cfa9b6a..83f3f9344 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java @@ -22,6 +22,7 @@ package org.apache.maven.archiva.repository.content; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase; import org.apache.maven.archiva.repository.layout.LayoutException; +import org.junit.Test; /** * AbstractLegacyRepositoryContentTestCase @@ -31,27 +32,32 @@ import org.apache.maven.archiva.repository.layout.LayoutException; public abstract class AbstractLegacyRepositoryContentTestCase extends AbstractRepositoryLayerTestCase { + @Test public void testBadPathArtifactIdMissingA() { assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" ); } + @Test public void testBadPathArtifactIdMissingB() { assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" ); } + @Test public void testBadPathMissingType() { assertBadPath( "invalid/invalid/1/invalid-1", "missing type" ); } + @Test public void testBadPathTooShort() { // NEW assertBadPath( "invalid/invalid-1.0.jar", "path is too short" ); } + @Test public void testBadPathWrongPackageExtension() { assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" ); @@ -62,6 +68,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase * Example of an oddball / unusual version spec. * @throws LayoutException */ + @Test public void testGoodButOddVersionSpecGanymedSsh2() throws LayoutException { @@ -79,6 +86,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase * Example of an oddball / unusual version spec. * @throws LayoutException */ + @Test public void testGoodButOddVersionSpecJavaxComm() throws LayoutException { @@ -96,6 +104,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase * Example of an oddball / unusual version spec. * @throws LayoutException */ + @Test public void testGoodButOddVersionSpecJavaxPersistence() throws LayoutException { @@ -113,6 +122,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase assertLayout( path, groupId, artifactId, version, null, type ); } + @Test public void testGoodCommonsLang() throws LayoutException { @@ -125,6 +135,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase assertLayout( path, groupId, artifactId, version, null, type ); } + @Test public void testGoodDerby() throws LayoutException { @@ -161,6 +172,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase * Test the classifier. * @throws LayoutException */ + @Test public void testGoodFooLibJavadoc() throws LayoutException { @@ -178,6 +190,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase * Test the classifier, and java-source type spec. * @throws LayoutException */ + @Test public void testGoodFooLibSources() throws LayoutException { @@ -191,6 +204,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase assertLayout( path, groupId, artifactId, version, classifier, type ); } + @Test public void testGoodFooTool() throws LayoutException { @@ -203,6 +217,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase assertLayout( path, groupId, artifactId, version, null, type ); } + @Test public void testGoodGeronimoEjbSpec() throws LayoutException { @@ -215,6 +230,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase assertLayout( path, groupId, artifactId, version, null, type ); } + @Test public void testGoodLdapClientsPom() throws LayoutException { @@ -231,6 +247,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory. * @throws LayoutException */ + @Test public void testGoodSnapshotMavenTest() throws LayoutException { @@ -247,6 +264,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase * [MRM-519] version identifiers within filename cause misidentification of version. * Example uses "test" in artifact Id, which is also part of the versionKeyword list. */ + @Test public void testGoodVersionKeywordInArtifactId() throws LayoutException { @@ -264,6 +282,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. * Example uses "test" in artifact Id, which is also part of the versionKeyword list. */ + @Test public void testGoodDetectPluginMavenTest() throws LayoutException { @@ -279,6 +298,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase /** * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. */ + @Test public void testGoodDetectPluginAvalonMeta() throws LayoutException { @@ -294,6 +314,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase /** * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. */ + @Test public void testGoodDetectPluginCactusMaven() throws LayoutException { @@ -309,6 +330,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase /** * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. */ + @Test public void testGoodDetectPluginGeronimoPackaging() throws LayoutException { @@ -325,6 +347,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase * [MRM-768] Artifact type "maven-plugin" does not distinguish maven1 and maven2 plugins. * This produces conflicts when m2 plugins are stored in legacy-layout repository */ + @Test public void testMaven1Maven2PluginTypeDistinc() throws Exception { diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMappingTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMappingTest.java index 3201b4833..13355032a 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMappingTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMappingTest.java @@ -25,6 +25,7 @@ import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProv import org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryPathTranslator; import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase; +import org.junit.Test; import java.util.Collections; @@ -39,6 +40,7 @@ public class ArtifactExtensionMappingTest private RepositoryPathTranslator pathTranslator = new Maven2RepositoryPathTranslator( Collections.<ArtifactMappingProvider>emptyList() ); + @Test public void testIsMavenPlugin() { assertMavenPlugin( "maven-test-plugin" ); diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java index 0d1a48756..b9534f36f 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java @@ -23,6 +23,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase; import org.apache.maven.archiva.repository.layout.LayoutException; +import org.junit.Test; /** * DefaultPathParserTest @@ -36,39 +37,46 @@ public class DefaultPathParserTest { private PathParser parser = new DefaultPathParser(); + @Test public void testBadPathMissingType() { // TODO: should we allow this instead? assertBadPath( "invalid/invalid/1/invalid-1", "missing type" ); } + @Test public void testBadPathReleaseInSnapshotDir() { assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", "non snapshot artifact inside of a snapshot dir" ); } + @Test public void testBadPathTimestampedSnapshotNotInSnapshotDir() { assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar", "Timestamped Snapshot artifact not inside of an Snapshot dir" ); } + @Test public void testBadPathTooShort() { assertBadPath( "invalid/invalid-1.0.jar", "path is too short" ); } + @Test public void testBadPathVersionMismatchA() { assertBadPath( "invalid/invalid/1.0/invalid-2.0.jar", "version mismatch between path and artifact" ); } + @Test public void testBadPathVersionMismatchB() { assertBadPath( "invalid/invalid/1.0/invalid-1.0b.jar", "version mismatch between path and artifact" ); } + @Test public void testBadPathWrongArtifactId() { assertBadPath( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar", @@ -78,6 +86,7 @@ public class DefaultPathParserTest /** * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error */ + @Test public void testGoodButDualExtensions() throws LayoutException { @@ -91,6 +100,7 @@ public class DefaultPathParserTest assertLayout( path, groupId, artifactId, version, classifier, type ); } + @Test public void testGoodButDualExtensionsWithClassifier() throws LayoutException { @@ -104,6 +114,7 @@ public class DefaultPathParserTest assertLayout( path, groupId, artifactId, version, classifier, type ); } + @Test public void testGoodButDualExtensionsTarGz() throws LayoutException { @@ -117,6 +128,7 @@ public class DefaultPathParserTest assertLayout( path, groupId, artifactId, version, classifier, type ); } + @Test public void testGoodButDualExtensionsTarGzAndClassifier() throws LayoutException { @@ -136,6 +148,7 @@ public class DefaultPathParserTest * * @throws LayoutException */ + @Test public void testGoodButOddVersionSpecGanymedSsh2() throws LayoutException { @@ -155,6 +168,7 @@ public class DefaultPathParserTest * * @throws LayoutException */ + @Test public void testGoodButOddVersionSpecJavaxComm() throws LayoutException { @@ -195,6 +209,7 @@ public class DefaultPathParserTest * * @throws LayoutException */ + @Test public void testGoodButOddVersionSpecJavaxPersistence() throws LayoutException { @@ -215,6 +230,7 @@ public class DefaultPathParserTest assertLayout( path, groupId, artifactId, version, classifier, type ); } + @Test public void testGoodComFooTool() throws LayoutException { @@ -228,6 +244,7 @@ public class DefaultPathParserTest assertLayout( path, groupId, artifactId, version, classifier, type ); } + @Test public void testGoodCommonsLang() throws LayoutException { @@ -241,6 +258,7 @@ public class DefaultPathParserTest assertLayout( path, groupId, artifactId, version, classifier, type ); } + @Test public void testWindowsPathSeparator() throws LayoutException { @@ -257,6 +275,7 @@ public class DefaultPathParserTest /** * [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected" */ + @Test public void testGoodDashedArtifactId() throws LayoutException { @@ -273,6 +292,7 @@ public class DefaultPathParserTest /** * It may seem odd, but this is a valid artifact. */ + @Test public void testGoodDotNotationArtifactId() throws LayoutException { @@ -289,6 +309,7 @@ public class DefaultPathParserTest /** * It may seem odd, but this is a valid artifact. */ + @Test public void testGoodDotNotationSameGroupIdAndArtifactId() throws LayoutException { @@ -308,6 +329,7 @@ public class DefaultPathParserTest * * @throws LayoutException */ + @Test public void testGoodFooLibSources() throws LayoutException { @@ -326,6 +348,7 @@ public class DefaultPathParserTest * * @throws LayoutException */ + @Test public void testGoodSnapshotMavenTest() throws LayoutException { @@ -345,6 +368,7 @@ public class DefaultPathParserTest * * @throws LayoutException */ + @Test public void testGoodLongSnapshotMavenTest() throws LayoutException { @@ -361,6 +385,7 @@ public class DefaultPathParserTest /** * A timestamped versioned artifact but without release version part. Like on axiom trunk. */ + @Test public void testBadSnapshotWithoutReleasePart() { assertBadPath( "org/apache/ws/commons/axiom/axiom/SNAPSHOT/axiom-20070912.093446-2.pom", @@ -372,6 +397,7 @@ public class DefaultPathParserTest * * @throws LayoutException */ + @Test public void testClassifiedSnapshotMavenTest() throws LayoutException { @@ -389,6 +415,7 @@ public class DefaultPathParserTest * [MRM-519] version identifiers within filename cause misidentification of version. * Example uses "test" in artifact Id, which is also part of the versionKeyword list. */ + @Test public void testGoodVersionKeywordInArtifactId() throws LayoutException { @@ -406,6 +433,7 @@ public class DefaultPathParserTest * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. * Example uses "test" in artifact Id, which is also part of the versionKeyword list. */ + @Test public void testGoodDetectMavenTestPlugin() throws LayoutException { @@ -422,6 +450,7 @@ public class DefaultPathParserTest /** * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. */ + @Test public void testGoodDetectCoberturaMavenPlugin() throws LayoutException { @@ -435,6 +464,7 @@ public class DefaultPathParserTest assertLayout( path, groupId, artifactId, version, classifier, type ); } + @Test public void testToArtifactOnEmptyPath() { try @@ -448,6 +478,7 @@ public class DefaultPathParserTest } } + @Test public void testToArtifactOnNullPath() { try @@ -461,6 +492,7 @@ public class DefaultPathParserTest } } + @Test public void testToArtifactReferenceOnEmptyPath() { try @@ -474,6 +506,7 @@ public class DefaultPathParserTest } } + @Test public void testToArtifactReferenceOnNullPath() { try diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/FilenameParserTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/FilenameParserTest.java index f8b8265cd..7321f13df 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/FilenameParserTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/FilenameParserTest.java @@ -20,15 +20,20 @@ package org.apache.maven.archiva.repository.content; */ import junit.framework.TestCase; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; /** * FilenameParserTest * * @version $Id$ */ +@RunWith( JUnit4.class ) public class FilenameParserTest extends TestCase { + @Test public void testNameExtensionJar() { FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" ); @@ -37,6 +42,7 @@ public class FilenameParserTest assertEquals( "jar", parser.getExtension() ); } + @Test public void testNameExtensionTarGz() { FilenameParser parser = new FilenameParser( "archiva-1.0-beta-2-bin.tar.gz" ); @@ -45,6 +51,7 @@ public class FilenameParserTest assertEquals( "tar.gz", parser.getExtension() ); } + @Test public void testNameExtensionTarBz2() { FilenameParser parser = new FilenameParser( "archiva-1.0-SNAPSHOT-src.tar.bz2" ); @@ -53,6 +60,7 @@ public class FilenameParserTest assertEquals( "tar.bz2", parser.getExtension() ); } + @Test public void testNameExtensionCapitolizedTarGz() { FilenameParser parser = new FilenameParser( "ARCHIVA-1.0-BETA-2-BIN.TAR.GZ" ); @@ -61,6 +69,7 @@ public class FilenameParserTest assertEquals( "TAR.GZ", parser.getExtension() ); } + @Test public void testNext() { FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" ); @@ -75,6 +84,7 @@ public class FilenameParserTest assertNull( parser.next() ); } + @Test public void testExpect() { FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" ); @@ -87,6 +97,7 @@ public class FilenameParserTest assertNull( parser.expect( "jar" ) ); } + @Test public void testExpectWithRemaining() { FilenameParser parser = new FilenameParser( "ganymede-ssh2-build250-sources.jar" ); @@ -102,6 +113,7 @@ public class FilenameParserTest assertNull( parser.expect( "jar" ) ); } + @Test public void testExpectWithRemainingDualExtensions() { FilenameParser parser = new FilenameParser( "example-presentation-3.2.xml.zip" ); @@ -116,6 +128,7 @@ public class FilenameParserTest } + @Test public void testNextNonVersion() { FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" ); @@ -124,6 +137,7 @@ public class FilenameParserTest assertEquals( "1.8.3", parser.remaining() ); } + @Test public void testNextArbitraryNonVersion() { FilenameParser parser = new FilenameParser( "maven-jdk-1.4-plugin-1.0-20070828.123456-42.jar" ); @@ -132,6 +146,7 @@ public class FilenameParserTest assertEquals( "1.0-20070828.123456-42", parser.remaining() ); } + @Test public void testNextJython() { FilenameParser parser = new FilenameParser( "jython-20020827-no-oro.jar" ); @@ -141,6 +156,7 @@ public class FilenameParserTest assertEquals( "no-oro", parser.remaining() ); } + @Test public void testLongExtension() { FilenameParser parser = new FilenameParser( "libfobs4jmf-0.4.1.4-20080217.211715-4.jnilib" ); @@ -149,6 +165,7 @@ public class FilenameParserTest assertEquals( "jnilib", parser.getExtension() ); } + @Test public void testInterveningVersion() { FilenameParser parser = new FilenameParser( "artifact-id-1.0-abc-1.1-20080221.062205-9.pom" ); @@ -160,6 +177,7 @@ public class FilenameParserTest assertEquals( "pom", parser.getExtension() ); } + @Test public void testExpectWrongSnapshot() { FilenameParser parser = new FilenameParser( "artifact-id-1.0-20080221.062205-9.pom" ); @@ -168,6 +186,7 @@ public class FilenameParserTest assertNull( parser.expect( "2.0-SNAPSHOT" ) ); } + @Test public void testExpectWrongSnapshot2() { // tests parsing axiom snapshots without exceptions @@ -177,6 +196,7 @@ public class FilenameParserTest assertNull( parser.expect( "SNAPSHOT" ) ); } + @Test public void testClassifier() { FilenameParser parser = new FilenameParser( "artifact-id-1.0-20070219.171202-34-test-sources.jar" ); @@ -188,6 +208,7 @@ public class FilenameParserTest assertEquals( "jar", parser.getExtension() ); } + @Test public void testNoExtension() { FilenameParser parser = new FilenameParser( "foo_bar" ); diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java index 9bde4fd65..e09805f0e 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java @@ -25,6 +25,11 @@ import org.apache.maven.archiva.configuration.LegacyArtifactPath; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase; import org.apache.maven.archiva.repository.layout.LayoutException; +import org.junit.Before; +import org.junit.Test; + +import javax.inject.Inject; +import javax.inject.Named; /** * LegacyPathParserTest @@ -34,18 +39,23 @@ import org.apache.maven.archiva.repository.layout.LayoutException; public class LegacyPathParserTest extends AbstractRepositoryLayerTestCase { - private LegacyPathParser parser = new LegacyPathParser(); + private LegacyPathParser parser; + + @Inject + @Named( value = "archivaConfiguration#default" ) + ArchivaConfiguration config; /** * Configure the ArchivaConfiguration * {@inheritDoc} - * @see org.codehaus.plexus.PlexusTestCase#setUp() */ - protected void setUp() + @Before + public void setUp() throws Exception { super.setUp(); - ArchivaConfiguration config = (ArchivaConfiguration) lookup( ArchivaConfiguration.class ); + + parser = new LegacyPathParser( config ); LegacyArtifactPath jaxen = new LegacyArtifactPath(); jaxen.setPath( "jaxen/jars/jaxen-1.0-FCS-full.jar" ); jaxen.setArtifact( "jaxen:jaxen:1.0-FCS:full:jar" ); @@ -53,28 +63,32 @@ public class LegacyPathParserTest parser.configuration = config; } - + @Test public void testBadPathArtifactIdMissingA() { assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" ); } + @Test public void testBadPathArtifactIdMissingB() { assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" ); } + @Test public void testBadPathMissingType() { assertBadPath( "invalid/invalid/1/invalid-1", "missing type" ); } + @Test public void testBadPathTooShort() { // NEW assertBadPath( "invalid/invalid-1.0.jar", "path is too short" ); } + @Test public void testBadPathWrongPackageExtension() { assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" ); @@ -83,6 +97,7 @@ public class LegacyPathParserTest /** * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error */ + @Test public void testGoodButDualExtensions() throws LayoutException { @@ -98,8 +113,10 @@ public class LegacyPathParserTest /** * [MRM-432] Oddball version spec. * Example of an oddball / unusual version spec. + * * @throws LayoutException */ + @Test public void testGoodButOddVersionSpecGanymedSsh2() throws LayoutException { @@ -115,8 +132,10 @@ public class LegacyPathParserTest /** * [MRM-432] Oddball version spec. * Example of an oddball / unusual version spec. + * * @throws LayoutException */ + @Test public void testGoodButOddVersionSpecJavaxComm() throws LayoutException { @@ -132,8 +151,10 @@ public class LegacyPathParserTest /** * [MRM-432] Oddball version spec. * Example of an oddball / unusual version spec. + * * @throws LayoutException */ + @Test public void testGoodButOddVersionSpecJavaxPersistence() throws LayoutException { @@ -151,6 +172,7 @@ public class LegacyPathParserTest assertLayout( path, groupId, artifactId, version, null, type ); } + @Test public void testGoodCommonsLang() throws LayoutException { @@ -163,6 +185,7 @@ public class LegacyPathParserTest assertLayout( path, groupId, artifactId, version, null, type ); } + @Test public void testGoodDerby() throws LayoutException { @@ -197,8 +220,10 @@ public class LegacyPathParserTest /** * Test the classifier. + * * @throws LayoutException */ + @Test public void testGoodFooLibJavadoc() throws LayoutException { @@ -211,13 +236,16 @@ public class LegacyPathParserTest assertLayout( path, groupId, artifactId, version, classifier, type ); - assertLayout( "com.foo.lib/javadocs/foo-lib-2.1-alpha-1-javadoc.jar", "com.foo.lib", "foo-lib", "2.1-alpha-1", "javadoc", "javadoc" ); + assertLayout( "com.foo.lib/javadocs/foo-lib-2.1-alpha-1-javadoc.jar", "com.foo.lib", "foo-lib", "2.1-alpha-1", + "javadoc", "javadoc" ); } /** * Test the classifier, and java-source type spec. + * * @throws LayoutException */ + @Test public void testGoodFooLibSources() throws LayoutException { @@ -225,7 +253,7 @@ public class LegacyPathParserTest String artifactId = "foo-lib"; String version = "2.1-alpha-1"; String type = "java-source"; // oddball type-spec (should result in jar extension) - String classifier= "sources"; + String classifier = "sources"; String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar"; assertLayout( path, groupId, artifactId, version, classifier, type ); @@ -233,8 +261,10 @@ public class LegacyPathParserTest /** * Test the classifier, and java-source type spec. + * * @throws LayoutException */ + @Test public void testBadClassifierFooLibSources() throws LayoutException { @@ -245,8 +275,10 @@ public class LegacyPathParserTest /** * Test the classifier, and java-source type spec. + * * @throws LayoutException */ + @Test public void testGoodFooLibTestSources() throws LayoutException { @@ -260,6 +292,7 @@ public class LegacyPathParserTest assertLayout( path, groupId, artifactId, version, classifier, type ); } + @Test public void testGoodFooTool() throws LayoutException { @@ -272,6 +305,7 @@ public class LegacyPathParserTest assertLayout( path, groupId, artifactId, version, null, type ); } + @Test public void testGoodGeronimoEjbSpec() throws LayoutException { @@ -284,6 +318,7 @@ public class LegacyPathParserTest assertLayout( path, groupId, artifactId, version, null, type ); } + @Test public void testGoodLdapClientsPom() throws LayoutException { @@ -298,8 +333,10 @@ public class LegacyPathParserTest /** * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory. + * * @throws LayoutException */ + @Test public void testGoodSnapshotMavenTest() throws LayoutException { @@ -316,6 +353,7 @@ public class LegacyPathParserTest * [MRM-519] version identifiers within filename cause misidentification of version. * Example uses "test" in artifact Id, which is also part of the versionKeyword list. */ + @Test public void testGoodVersionKeywordInArtifactId() throws LayoutException { @@ -333,6 +371,7 @@ public class LegacyPathParserTest * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. * Example uses "test" in artifact Id, which is also part of the versionKeyword list. */ + @Test public void testGoodDetectPluginMavenTest() throws LayoutException { @@ -348,6 +387,7 @@ public class LegacyPathParserTest /** * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. */ + @Test public void testGoodDetectPluginAvalonMeta() throws LayoutException { @@ -363,6 +403,7 @@ public class LegacyPathParserTest /** * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. */ + @Test public void testGoodDetectPluginCactusMaven() throws LayoutException { @@ -378,6 +419,7 @@ public class LegacyPathParserTest /** * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. */ + @Test public void testGoodDetectPluginGeronimoPackaging() throws LayoutException { @@ -392,8 +434,10 @@ public class LegacyPathParserTest /** * [MRM-594] add some hook in LegacyPathParser to allow exceptions in artifact resolution - * @since 1.1 + * + * @since 1.1 */ + @Test public void testCustomExceptionsInArtifactResolution() throws LayoutException { @@ -410,7 +454,8 @@ public class LegacyPathParserTest /** * Perform a path to artifact reference lookup, and verify the results. */ - private void assertLayout( String path, String groupId, String artifactId, String version, String classifier, String type ) + private void assertLayout( String path, String groupId, String artifactId, String version, String classifier, + String type ) throws LayoutException { // Path to Artifact Reference. @@ -421,7 +466,8 @@ public class LegacyPathParserTest private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId, String version, String classifier, String type ) { - String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type; + String expectedId = + "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type; assertNotNull( expectedId + " - Should not be null.", actualReference ); @@ -437,7 +483,8 @@ public class LegacyPathParserTest try { parser.toArtifactReference( path ); - fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" ); + fail( + "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" ); } catch ( LayoutException e ) { diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContentTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContentTest.java index c525d9424..671bc8aec 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContentTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContentTest.java @@ -29,7 +29,11 @@ import org.apache.maven.archiva.model.ProjectReference; import org.apache.maven.archiva.model.VersionedReference; import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.layout.LayoutException; +import org.junit.Before; +import org.junit.Test; +import javax.inject.Inject; +import javax.inject.Named; import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -38,59 +42,92 @@ import java.util.List; import java.util.Set; /** - * ManagedDefaultRepositoryContentTest + * ManagedDefaultRepositoryContentTest * * @version $Id$ */ public class ManagedDefaultRepositoryContentTest extends AbstractDefaultRepositoryContentTestCase { + @Inject + @Named( value = "managedRepositoryContent#default" ) private ManagedRepositoryContent repoContent; + @Inject + FileTypes fileTypes; + + @Inject @Named(value = "archivaConfiguration#default") + ArchivaConfiguration archivaConfiguration; + + @Before + public void setUp() + throws Exception + { + super.setUp(); + + File repoDir = new File( "src/test/repositories/default-repository" ); + + ManagedRepositoryConfiguration repository = createRepository( "testRepo", "Unit Test Repo", repoDir ); + + + FileType fileType = + (FileType) archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 ); + fileType.addPattern( "**/*.xml" ); + assertEquals( FileTypes.ARTIFACTS, fileType.getId() ); + + fileTypes.afterConfigurationChange( null, "fileType", null ); + + //repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "default" ); + repoContent.setRepository( repository ); + } + + @Test public void testGetVersionsBadArtifact() throws Exception { assertGetVersions( "bad_artifact", Collections.<String>emptyList() ); } + @Test public void testGetVersionsMissingMultipleVersions() throws Exception { assertGetVersions( "missing_metadata_b", Arrays.asList( "1.0", "1.0.1", "2.0", "2.0.1", "2.0-20070821-dev" ) ); } + @Test public void testGetVersionsSimple() throws Exception { - assertVersions( "proxied_multi", "2.1", new String[] { "2.1" } ); + assertVersions( "proxied_multi", "2.1", new String[]{ "2.1" } ); } + @Test public void testGetVersionsSimpleYetIncomplete() throws Exception { assertGetVersions( "incomplete_metadata_a", Collections.singletonList( "1.0" ) ); } + @Test public void testGetVersionsSimpleYetMissing() throws Exception { assertGetVersions( "missing_metadata_a", Collections.singletonList( "1.0" ) ); } + @Test public void testGetVersionsSnapshotA() throws Exception { - assertVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", new String[] { - "1.0-alpha-11-SNAPSHOT", - "1.0-alpha-11-20070221.194724-2", - "1.0-alpha-11-20070302.212723-3", - "1.0-alpha-11-20070303.152828-4", - "1.0-alpha-11-20070305.215149-5", - "1.0-alpha-11-20070307.170909-6", - "1.0-alpha-11-20070314.211405-9", - "1.0-alpha-11-20070316.175232-11" } ); + assertVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", + new String[]{ "1.0-alpha-11-SNAPSHOT", "1.0-alpha-11-20070221.194724-2", + "1.0-alpha-11-20070302.212723-3", "1.0-alpha-11-20070303.152828-4", + "1.0-alpha-11-20070305.215149-5", "1.0-alpha-11-20070307.170909-6", + "1.0-alpha-11-20070314.211405-9", "1.0-alpha-11-20070316.175232-11" } ); } + @Test public void testToMetadataPathFromProjectReference() { ProjectReference reference = new ProjectReference(); @@ -100,6 +137,7 @@ public class ManagedDefaultRepositoryContentTest assertEquals( "com/foo/foo-tool/maven-metadata.xml", repoContent.toMetadataPath( reference ) ); } + @Test public void testToMetadataPathFromVersionReference() { VersionedReference reference = new VersionedReference(); @@ -110,6 +148,7 @@ public class ManagedDefaultRepositoryContentTest assertEquals( "com/foo/foo-tool/1.0/maven-metadata.xml", repoContent.toMetadataPath( reference ) ); } + @Test public void testToPathOnNullArtifactReference() { try @@ -124,10 +163,11 @@ public class ManagedDefaultRepositoryContentTest } } + @Test public void testExcludeMetadataFile() throws Exception { - assertVersions( "include_xml", "1.0", new String[] { "1.0" } ); + assertVersions( "include_xml", "1.0", new String[]{ "1.0" } ); } private void assertGetVersions( String artifactId, List<String> expectedVersions ) @@ -139,7 +179,7 @@ public class ManagedDefaultRepositoryContentTest // Use the test metadata-repository, which is already setup for // These kind of version tests. - File repoDir = getTestFile( "src/test/repositories/metadata-repository" ); + File repoDir = new File( "src/test/repositories/metadata-repository" ); repoContent.getRepository().setLocation( repoDir.getAbsolutePath() ); // Request the versions. @@ -164,7 +204,7 @@ public class ManagedDefaultRepositoryContentTest // Use the test metadata-repository, which is already setup for // These kind of version tests. - File repoDir = getTestFile( "src/test/repositories/metadata-repository" ); + File repoDir = new File( "src/test/repositories/metadata-repository" ); repoContent.getRepository().setLocation( repoDir.getAbsolutePath() ); // Request the versions. @@ -185,27 +225,6 @@ public class ManagedDefaultRepositoryContentTest } } - @Override - protected void setUp() - throws Exception - { - super.setUp(); - - File repoDir = getTestFile( "src/test/repositories/default-repository" ); - - ManagedRepositoryConfiguration repository = createRepository( "testRepo", "Unit Test Repo", repoDir ); - - ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.ROLE ); - FileType fileType = (FileType) archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 ); - fileType.addPattern( "**/*.xml" ); - assertEquals( FileTypes.ARTIFACTS, fileType.getId() ); - - FileTypes fileTypes = (FileTypes) lookup( FileTypes.class ); - fileTypes.afterConfigurationChange( null, "fileType", null ); - - repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "default" ); - repoContent.setRepository( repository ); - } @Override protected ArtifactReference toArtifactReference( String path ) diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContentTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContentTest.java index faa5951c5..388442937 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContentTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContentTest.java @@ -26,7 +26,11 @@ import org.apache.maven.archiva.model.ProjectReference; import org.apache.maven.archiva.model.VersionedReference; import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.layout.LayoutException; +import org.junit.Before; +import org.junit.Test; +import javax.inject.Inject; +import javax.inject.Named; import java.io.File; import java.util.ArrayList; import java.util.Collections; @@ -41,27 +45,43 @@ import java.util.Set; public class ManagedLegacyRepositoryContentTest extends AbstractLegacyRepositoryContentTestCase { + @Inject + @Named( value = "managedRepositoryContent#legacy" ) private ManagedRepositoryContent repoContent; + @Before + public void setUp() + throws Exception + { + super.setUp(); + + File repoDir = new File( "src/test/repositories/legacy-repository" ); + + ManagedRepositoryConfiguration repository = createRepository( "testRepo", "Unit Test Repo", repoDir ); + repository.setLayout( "legacy" ); + + //repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "legacy" ); + repoContent.setRepository( repository ); + } + + @Test public void testGetVersionsFromProjectReference() throws Exception { - assertVersions( "org.apache.maven", "testing", new String[] { - "UNKNOWN", + assertVersions( "org.apache.maven", "testing", new String[]{ "UNKNOWN", // "1.0-javadoc", // "1.0-sources", - "1.0", - "1.0-20050611.112233-1" } ); + "1.0", "1.0-20050611.112233-1" } ); } + @Test public void testGetVersionsFromVersionedReference() throws Exception { - assertVersions( "org.apache.maven", "testing", "1.0", new String[] { + assertVersions( "org.apache.maven", "testing", "1.0", new String[]{ // "1.0-javadoc", // "1.0-sources", - "1.0", - "1.0-20050611.112233-1" } ); + "1.0", "1.0-20050611.112233-1" } ); } private void assertVersions( String groupId, String artifactId, String[] expectedVersions ) @@ -115,6 +135,7 @@ public class ManagedLegacyRepositoryContentTest } } + @Test public void testGetRelatedArtifacts() throws Exception { @@ -123,13 +144,10 @@ public class ManagedLegacyRepositoryContentTest Set<ArtifactReference> related = repoContent.getRelatedArtifacts( reference ); assertNotNull( related ); - String expected[] = new String[] { - "org.apache.maven/jars/testing-1.0.jar", + String expected[] = new String[]{ "org.apache.maven/jars/testing-1.0.jar", "org.apache.maven/java-sources/testing-1.0-sources.jar", - "org.apache.maven/jars/testing-1.0-20050611.112233-1.jar", - "org.apache.maven/poms/testing-1.0.pom", - "org.apache.maven/distributions/testing-1.0.tar.gz", - "org.apache.maven/distributions/testing-1.0.zip", + "org.apache.maven/jars/testing-1.0-20050611.112233-1.jar", "org.apache.maven/poms/testing-1.0.pom", + "org.apache.maven/distributions/testing-1.0.tar.gz", "org.apache.maven/distributions/testing-1.0.zip", "org.apache.maven/javadoc.jars/testing-1.0-javadoc.jar" }; StringBuffer relatedDebugString = new StringBuffer(); @@ -156,26 +174,12 @@ public class ManagedLegacyRepositoryContentTest if ( !found ) { fail( "Unable to find expected artifact [" + expectedPath + "] in list of related artifacts. " - + "Related <" + relatedDebugString + ">" ); + + "Related <" + relatedDebugString + ">" ); } } assertEquals( "Related <" + relatedDebugString + ">:", expected.length, related.size() ); } - @Override - protected void setUp() - throws Exception - { - super.setUp(); - - File repoDir = getTestFile( "src/test/repositories/legacy-repository" ); - - ManagedRepositoryConfiguration repository = createRepository( "testRepo", "Unit Test Repo", repoDir ); - repository.setLayout( "legacy" ); - - repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "legacy" ); - repoContent.setRepository( repository ); - } @Override protected ArtifactReference toArtifactReference( String path ) diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RemoteDefaultRepositoryContentTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RemoteDefaultRepositoryContentTest.java index eb2a92d39..ddc1f22e7 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RemoteDefaultRepositoryContentTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RemoteDefaultRepositoryContentTest.java @@ -23,6 +23,10 @@ import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.RemoteRepositoryContent; import org.apache.maven.archiva.repository.layout.LayoutException; +import org.junit.Before; + +import javax.inject.Inject; +import javax.inject.Named; /** * RemoteDefaultRepositoryContentTest @@ -32,10 +36,11 @@ import org.apache.maven.archiva.repository.layout.LayoutException; public class RemoteDefaultRepositoryContentTest extends AbstractDefaultRepositoryContentTestCase { + @Inject @Named(value = "remoteRepositoryContent#default") private RemoteRepositoryContent repoContent; - @Override - protected void setUp() + @Before + public void setUp() throws Exception { super.setUp(); @@ -43,7 +48,7 @@ public class RemoteDefaultRepositoryContentTest RemoteRepositoryConfiguration repository = createRemoteRepository( "testRemoteRepo", "Unit Test Remote Repo", "http://repo1.maven.org/maven2/" ); - repoContent = (RemoteRepositoryContent) lookup( RemoteRepositoryContent.class, "default" ); + //repoContent = (RemoteRepositoryContent) lookup( RemoteRepositoryContent.class, "default" ); repoContent.setRepository( repository ); } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RemoteLegacyRepositoryContentTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RemoteLegacyRepositoryContentTest.java index 8873026f5..d3aa0f13a 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RemoteLegacyRepositoryContentTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RemoteLegacyRepositoryContentTest.java @@ -23,29 +23,35 @@ import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.RemoteRepositoryContent; import org.apache.maven.archiva.repository.layout.LayoutException; +import org.junit.Before; + +import javax.inject.Inject; +import javax.inject.Named; /** - * RemoteLegacyRepositoryContentTest + * RemoteLegacyRepositoryContentTest * * @version $Id$ */ public class RemoteLegacyRepositoryContentTest extends AbstractLegacyRepositoryContentTestCase { + @Inject + @Named( value = "remoteRepositoryContent#legacy" ) private RemoteRepositoryContent repoContent; - @Override - protected void setUp() + @Before + public void setUp() throws Exception { super.setUp(); - RemoteRepositoryConfiguration repository = createRemoteRepository( "testRemoteLegacyRepo", - "Unit Test Remote Legacy Repo", - "http://repo1.maven.org/maven/" ); + RemoteRepositoryConfiguration repository = + createRemoteRepository( "testRemoteLegacyRepo", "Unit Test Remote Legacy Repo", + "http://repo1.maven.org/maven/" ); repository.setLayout( "legacy" ); - repoContent = (RemoteRepositoryContent) lookup( RemoteRepositoryContent.class, "legacy" ); + //repoContent = (RemoteRepositoryContent) lookup( RemoteRepositoryContent.class, "legacy" ); repoContent.setRepository( repository ); } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java index a7d282cf3..f99e71830 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java @@ -20,11 +20,17 @@ package org.apache.maven.archiva.repository.content; */ import org.apache.commons.lang.StringUtils; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase; import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.layout.LayoutException; +import org.junit.Before; +import org.junit.Test; +import org.springframework.test.context.ContextConfiguration; +import javax.inject.Inject; +import javax.inject.Named; import java.io.File; /** @@ -32,39 +38,63 @@ import java.io.File; * * @version $Id$ */ +@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-repo-request-test.xml" } ) public class RepositoryRequestTest extends AbstractRepositoryLayerTestCase { + + @Inject @Named(value = "archivaConfiguration#repo-request-test") + private ArchivaConfiguration archivaConfiguration; + + private RepositoryRequest repoRequest; + + @Before + public void setUp() + throws Exception + { + super.setUp(); + + LegacyPathParser legacyPathParser = new LegacyPathParser( archivaConfiguration ); + repoRequest = new RepositoryRequest( legacyPathParser ); + } + + @Test public void testInvalidRequestEmptyPath() { assertInvalidRequest( "" ); } - + + @Test public void testInvalidRequestSlashOnly() { assertInvalidRequest( "//" ); } - + + @Test public void testInvalidRequestNoArtifactId() { assertInvalidRequest( "groupId/jars/-1.0.jar" ); } + @Test public void testInvalidLegacyRequestBadLocation() { assertInvalidRequest( "org.apache.maven.test/jars/artifactId-1.0.war" ); } + @Test public void testInvalidRequestTooShort() { assertInvalidRequest( "org.apache.maven.test/artifactId-2.0.jar" ); } + @Test public void testInvalidDefaultRequestBadLocation() { assertInvalidRequest( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" ); } + @Test public void testValidLegacyGanymed() throws Exception { @@ -72,6 +102,7 @@ public class RepositoryRequestTest null, "jar" ); } + @Test public void testValidDefaultGanymed() throws Exception { @@ -79,18 +110,21 @@ public class RepositoryRequestTest "ganymed-ssh2", "build210", null, "jar" ); } + @Test public void testValidLegacyJavaxComm() throws Exception { assertValid( "javax/jars/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" ); } + @Test public void testValidDefaultJavaxComm() throws Exception { assertValid( "javax/comm/3.0-u1/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" ); } + @Test public void testValidLegacyJavaxPersistence() throws Exception { @@ -98,6 +132,7 @@ public class RepositoryRequestTest "3.0-public_review", null, "jar" ); } + @Test public void testValidDefaultJavaxPersistence() throws Exception { @@ -105,19 +140,22 @@ public class RepositoryRequestTest "3.0-public_review", null, "jar" ); } + @Test public void testValidLegacyMavenTestPlugin() throws Exception { assertValid( "maven/jars/maven-test-plugin-1.8.2.jar", "maven", "maven-test-plugin", "1.8.2", null, "jar" ); } + @Test public void testValidDefaultMavenTestPlugin() throws Exception { - assertValid( "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom", "maven", "maven-test-plugin", - "1.8.2", null, "pom" ); + assertValid( "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom", "maven", "maven-test-plugin", "1.8.2", + null, "pom" ); } + @Test public void testValidLegacyCommonsLangJavadoc() throws Exception { @@ -125,6 +163,7 @@ public class RepositoryRequestTest "javadoc", "javadoc" ); } + @Test public void testValidDefaultCommonsLangJavadoc() throws Exception { @@ -132,14 +171,17 @@ public class RepositoryRequestTest "2.1", "javadoc", "javadoc" ); } + @Test public void testValidLegacyDerbyPom() throws Exception { assertValid( "org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, "pom" ); // Starting slash should not prevent detection. - assertValid( "/org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, "pom" ); + assertValid( "/org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, + "pom" ); } + @Test public void testValidDefaultDerbyPom() throws Exception { @@ -147,6 +189,7 @@ public class RepositoryRequestTest null, "pom" ); } + @Test public void testValidLegacyGeronimoEjbSpec() throws Exception { @@ -154,6 +197,7 @@ public class RepositoryRequestTest "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" ); } + @Test public void testValidDefaultGeronimoEjbSpec() throws Exception { @@ -161,6 +205,7 @@ public class RepositoryRequestTest "org.apache.geronimo.specs", "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" ); } + @Test public void testValidLegacyLdapSnapshot() throws Exception { @@ -168,6 +213,7 @@ public class RepositoryRequestTest "0.9.1-SNAPSHOT", null, "pom" ); } + @Test public void testValidDefaultLdapSnapshot() throws Exception { @@ -175,6 +221,7 @@ public class RepositoryRequestTest "directory-clients", "ldap-clients", "0.9.1-SNAPSHOT", null, "pom" ); } + @Test public void testValidLegacyTestArchSnapshot() throws Exception { @@ -182,6 +229,7 @@ public class RepositoryRequestTest "2.0.3-SNAPSHOT", null, "pom" ); } + @Test public void testValidDefaultTestArchSnapshot() throws Exception { @@ -189,6 +237,7 @@ public class RepositoryRequestTest "test-arch", "2.0.3-SNAPSHOT", null, "pom" ); } + @Test public void testValidLegacyOddDottedArtifactId() throws Exception { @@ -196,6 +245,7 @@ public class RepositoryRequestTest "com.company.department.project", "0.2", null, "pom" ); } + @Test public void testValidDefaultOddDottedArtifactId() throws Exception { @@ -203,6 +253,7 @@ public class RepositoryRequestTest "com.company.department", "com.company.department.project", "0.2", null, "pom" ); } + @Test public void testValidLegacyTimestampedSnapshot() throws Exception { @@ -210,14 +261,16 @@ public class RepositoryRequestTest "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" ); } + @Test public void testValidDefaultTimestampedSnapshot() throws Exception { assertValid( - "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar", - "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" ); + "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar", + "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" ); } + @Test public void testIsSupportFile() { assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) ); @@ -228,42 +281,50 @@ public class RepositoryRequestTest assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) ); assertFalse( repoRequest.isSupportFile( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) ); - assertFalse( repoRequest.isSupportFile( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) ); + assertFalse( + repoRequest.isSupportFile( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) ); assertFalse( repoRequest.isSupportFile( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) ); assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) ); assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) ); assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/maven-metadata.xml" ) ); } + @Test public void testIsMetadata() { - assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" )); - assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/maven-metadata.xml" )); + assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) ); + assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/maven-metadata.xml" ) ); assertFalse( repoRequest.isMetadata( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) ); - assertFalse( repoRequest.isMetadata( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) ); + assertFalse( + repoRequest.isMetadata( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) ); assertFalse( repoRequest.isMetadata( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) ); assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) ); assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) ); assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) ); } - + + @Test public void testIsMetadataSupportFile() { - assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" )); - assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml" )); - assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml.sha1" )); - assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml.md5" )); + assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) ); + assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml" ) ); + assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml.sha1" ) ); + assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml.md5" ) ); assertFalse( repoRequest.isMetadataSupportFile( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) ); - assertFalse( repoRequest.isMetadataSupportFile( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) ); - assertFalse( repoRequest.isMetadataSupportFile( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) ); + assertFalse( repoRequest.isMetadataSupportFile( + "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) ); + assertFalse( + repoRequest.isMetadataSupportFile( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) ); assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) ); - assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) ); + assertFalse( + repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) ); assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) ); - assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) ); + assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) ); } + @Test public void testIsDefault() { assertFalse( repoRequest.isDefault( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) ); @@ -285,6 +346,7 @@ public class RepositoryRequestTest assertFalse( repoRequest.isDefault( "some.short/path" ) ); } + @Test public void testIsLegacy() { assertTrue( repoRequest.isLegacy( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) ); @@ -305,26 +367,29 @@ public class RepositoryRequestTest private ManagedRepositoryContent createManagedRepo( String layout ) throws Exception { - File repoRoot = getTestFile( "target/test-repo" ); + File repoRoot = new File( "target/test-repo" ); return createManagedRepositoryContent( "test-internal", "Internal Test Repo", repoRoot, layout ); } /** * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error */ + @Test public void testToNativePathArtifactDefaultToDefaultDualExtension() throws Exception { ManagedRepositoryContent repository = createManagedRepo( "default" ); // Test (artifact) default to default - dual extension - assertEquals( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", repoRequest - .toNativePath( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", repository ) ); + assertEquals( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", + repoRequest.toNativePath( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", + repository ) ); } /** * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error */ + @Test public void testToNativePathArtifactLegacyToDefaultDualExtension() throws Exception { @@ -334,20 +399,23 @@ public class RepositoryRequestTest // Test (artifact) legacy to default - dual extension // NOTE: The detection of a dual extension is flawed. - assertEquals( "org/project/example-presentation/3.2.xml/example-presentation-3.2.xml.zip", repoRequest - .toNativePath( "org.project/zips/example-presentation-3.2.xml.zip", repository ) ); + assertEquals( "org/project/example-presentation/3.2.xml/example-presentation-3.2.xml.zip", + repoRequest.toNativePath( "org.project/zips/example-presentation-3.2.xml.zip", repository ) ); } + @Test public void testToNativePathMetadataDefaultToDefault() throws Exception { ManagedRepositoryContent repository = createManagedRepo( "default" ); // Test (metadata) default to default - assertEquals( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1", repoRequest - .toNativePath( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1", repository ) ); + assertEquals( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1", + repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1", + repository ) ); } + @Test public void testNativePathPomLegacyToDefault() throws Exception { @@ -358,6 +426,7 @@ public class RepositoryRequestTest repoRequest.toNativePath( "org.apache.derby/poms/derby-10.2.2.0.pom", repository ) ); } + @Test public void testNativePathPomLegacyToLegacy() throws Exception { @@ -368,6 +437,7 @@ public class RepositoryRequestTest repoRequest.toNativePath( "org.apache.derby/poms/derby-10.2.2.0.pom", repository ) ); } + @Test public void testNativePathPomLegacyToDefaultEjb() throws Exception { @@ -378,6 +448,7 @@ public class RepositoryRequestTest repoRequest.toNativePath( "mygroup/ejbs/myejb-1.0.jar", repository ) ); } + @Test public void testNativePathPomLegacyToLegacyEjb() throws Exception { @@ -388,6 +459,7 @@ public class RepositoryRequestTest repoRequest.toNativePath( "mygroup/ejbs/myejb-1.0.jar", repository ) ); } + @Test public void testNativePathPomLegacyToLegacyStrutsModule() throws Exception { @@ -398,16 +470,18 @@ public class RepositoryRequestTest repoRequest.toNativePath( "WebPortal/struts-modules/eventsDB-1.2.3.struts-module", repository ) ); } + @Test public void testNativePathSupportFileLegacyToDefault() throws Exception { ManagedRepositoryContent repository = createManagedRepo( "default" ); // Test (supportfile) legacy to default - assertEquals( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.jar.sha1", repoRequest - .toNativePath( "org.apache.derby/jars/derby-10.2.2.0.jar.sha1", repository ) ); + assertEquals( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.jar.sha1", + repoRequest.toNativePath( "org.apache.derby/jars/derby-10.2.2.0.jar.sha1", repository ) ); } + @Test public void testNativePathBadRequestTooShort() throws Exception { @@ -425,6 +499,7 @@ public class RepositoryRequestTest } } + @Test public void testNativePathBadRequestBlank() throws Exception { @@ -442,6 +517,7 @@ public class RepositoryRequestTest } } + @Test public void testNativePathBadRequestNull() throws Exception { @@ -459,6 +535,7 @@ public class RepositoryRequestTest } } + @Test public void testNativePathBadRequestUnknownType() throws Exception { @@ -476,6 +553,7 @@ public class RepositoryRequestTest } } + @Test public void testToNativePathLegacyMetadataDefaultToLegacy() throws Exception { @@ -487,32 +565,35 @@ public class RepositoryRequestTest try { repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml", repository ); - fail("Should have thrown a LayoutException, can't translate a maven-metadata.xml to a legacy layout."); + fail( "Should have thrown a LayoutException, can't translate a maven-metadata.xml to a legacy layout." ); } - catch(LayoutException e) + catch ( LayoutException e ) { // expected path. } } + @Test public void testNativePathPomDefaultToLegacy() throws Exception { ManagedRepositoryContent repository = createManagedRepo( "legacy" ); // Test (pom) default to legacy - assertEquals( "org.apache.derby/poms/derby-10.2.2.0.pom", repoRequest - .toNativePath( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", repository ) ); + assertEquals( "org.apache.derby/poms/derby-10.2.2.0.pom", + repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", repository ) ); } + @Test public void testNativePathSupportFileDefaultToLegacy() throws Exception { ManagedRepositoryContent repository = createManagedRepo( "legacy" ); // Test (supportfile) default to legacy - assertEquals( "org.apache.derby/jars/derby-10.2.2.0.jar.sha1", repoRequest - .toNativePath( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.jar.sha1", repository ) ); + assertEquals( "org.apache.derby/jars/derby-10.2.2.0.jar.sha1", + repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.jar.sha1", + repository ) ); } private void assertValid( String path, String groupId, String artifactId, String version, String classifier, @@ -549,14 +630,4 @@ public class RepositoryRequestTest } } - private RepositoryRequest repoRequest; - - @Override - protected void setUp() - throws Exception - { - super.setUp(); - - repoRequest = (RepositoryRequest) lookup( RepositoryRequest.class ); - } } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java index fec4d0150..f1a342546 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java @@ -22,7 +22,6 @@ package org.apache.maven.archiva.repository.metadata; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.common.utils.VersionComparator; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.apache.maven.archiva.model.ProjectReference; @@ -38,8 +37,12 @@ import org.apache.maven.archiva.repository.RemoteRepositoryContent; import org.apache.maven.archiva.repository.layout.LayoutException; import org.custommonkey.xmlunit.DetailedDiff; import org.custommonkey.xmlunit.Diff; +import org.junit.Test; +import org.springframework.test.context.ContextConfiguration; import org.xml.sax.SAXException; +import javax.inject.Inject; +import javax.inject.Named; import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.IOException; @@ -53,27 +56,30 @@ import java.util.Set; * * @version $Id$ */ +@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-metadata-tools-test.xml" } ) public class MetadataToolsTest extends AbstractRepositoryLayerTestCase { + @Inject @Named(value = "metadataTools#test") private MetadataTools tools; + @Inject + @Named( value = "archivaConfiguration#mock" ) protected MockConfiguration config; + + @Test public void testGatherSnapshotVersionsA() throws Exception { - assertSnapshotVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", new String[] { - "1.0-alpha-11-SNAPSHOT", - "1.0-alpha-11-20070221.194724-2", - "1.0-alpha-11-20070302.212723-3", - "1.0-alpha-11-20070303.152828-4", - "1.0-alpha-11-20070305.215149-5", - "1.0-alpha-11-20070307.170909-6", - "1.0-alpha-11-20070314.211405-9", - "1.0-alpha-11-20070316.175232-11" } ); + assertSnapshotVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", + new String[]{ "1.0-alpha-11-SNAPSHOT", "1.0-alpha-11-20070221.194724-2", + "1.0-alpha-11-20070302.212723-3", "1.0-alpha-11-20070303.152828-4", + "1.0-alpha-11-20070305.215149-5", "1.0-alpha-11-20070307.170909-6", + "1.0-alpha-11-20070314.211405-9", "1.0-alpha-11-20070316.175232-11" } ); } + @Test public void testGatherSnapshotVersionsAWithProxies() throws Exception { @@ -83,31 +89,28 @@ public class MetadataToolsTest createProxyConnector( "test-repo", "internal-snapshots" ); createProxyConnector( "test-repo", "snapshots.codehaus.org" ); - assertSnapshotVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", new String[] { - "1.0-alpha-11-SNAPSHOT", - "1.0-alpha-11-20070221.194724-2", - "1.0-alpha-11-20070302.212723-3", - "1.0-alpha-11-20070303.152828-4", - "1.0-alpha-11-20070305.215149-5", - "1.0-alpha-11-20070307.170909-6", - "1.0-alpha-11-20070314.211405-9", - "1.0-alpha-11-20070315.033030-10" /* Arrives in via snapshots.codehaus.org proxy */, - "1.0-alpha-11-20070316.175232-11" } ); + assertSnapshotVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", + new String[]{ "1.0-alpha-11-SNAPSHOT", "1.0-alpha-11-20070221.194724-2", + "1.0-alpha-11-20070302.212723-3", "1.0-alpha-11-20070303.152828-4", + "1.0-alpha-11-20070305.215149-5", "1.0-alpha-11-20070307.170909-6", + "1.0-alpha-11-20070314.211405-9", "1.0-alpha-11-20070315.033030-10" + /* Arrives in via snapshots.codehaus.org proxy */, + "1.0-alpha-11-20070316.175232-11" } ); } + @Test public void testGetRepositorySpecificName() throws Exception { - RemoteRepositoryContent repoJavaNet = createRemoteRepositoryContent( "maven2-repository.dev.java.net", - "Java.net Repository for Maven 2", - "http://download.java.net/maven/2/", - "default" ); - RemoteRepositoryContent repoCentral = createRemoteRepositoryContent( "central", "Central Global Repository", - "http://repo1.maven.org/maven2/", - "default" ); + RemoteRepositoryContent repoJavaNet = + createRemoteRepositoryContent( "maven2-repository.dev.java.net", "Java.net Repository for Maven 2", + "http://download.java.net/maven/2/", "default" ); + RemoteRepositoryContent repoCentral = + createRemoteRepositoryContent( "central", "Central Global Repository", "http://repo1.maven.org/maven2/", + "default" ); - String convertedName = tools.getRepositorySpecificName( repoJavaNet, - "commons-lang/commons-lang/maven-metadata.xml" ); + String convertedName = + tools.getRepositorySpecificName( repoJavaNet, "commons-lang/commons-lang/maven-metadata.xml" ); assertMetadataPath( "commons-lang/commons-lang/maven-metadata-maven2-repository.dev.java.net.xml", convertedName ); @@ -130,6 +133,7 @@ public class MetadataToolsTest // } // } + @Test public void testUpdateProjectNonExistingVersion() throws Exception { @@ -139,32 +143,28 @@ public class MetadataToolsTest reference.setArtifactId( "missing_artifact" ); prepTestRepo( testRepo, reference ); - + // check metadata prior to update -- should contain the non-existing artifact version - assertProjectMetadata( testRepo, reference, "missing_artifact", new String[] { - "1.0-SNAPSHOT", - "1.1-SNAPSHOT", - "1.2-SNAPSHOT" }, "1.2-SNAPSHOT" , null ); + assertProjectMetadata( testRepo, reference, "missing_artifact", + new String[]{ "1.0-SNAPSHOT", "1.1-SNAPSHOT", "1.2-SNAPSHOT" }, "1.2-SNAPSHOT", null ); tools.updateMetadata( testRepo, reference ); - + // metadata should not contain the non-existing artifact version -- 1.1-SNAPSHOT - assertProjectMetadata( testRepo, reference, "missing_artifact", new String[] { - "1.0-SNAPSHOT", - "1.2-SNAPSHOT" }, "1.2-SNAPSHOT" , null ); + assertProjectMetadata( testRepo, reference, "missing_artifact", new String[]{ "1.0-SNAPSHOT", "1.2-SNAPSHOT" }, + "1.2-SNAPSHOT", null ); } + @Test public void testUpdateProjectMissingMultipleVersions() throws Exception { - assertUpdatedProjectMetadata( "missing_metadata_b", new String[] { - "1.0", - "1.0.1", - "2.0", - "2.0.1", - "2.0-20070821-dev" }, "2.0-20070821-dev" , "2.0-20070821-dev" ); + assertUpdatedProjectMetadata( "missing_metadata_b", + new String[]{ "1.0", "1.0.1", "2.0", "2.0.1", "2.0-20070821-dev" }, + "2.0-20070821-dev", "2.0-20070821-dev" ); } + @Test public void testUpdateProjectMissingMultipleVersionsWithProxies() throws Exception { @@ -174,56 +174,58 @@ public class MetadataToolsTest createProxyConnector( "test-repo", "central" ); createProxyConnector( "test-repo", "java.net" ); - assertUpdatedProjectMetadata( "proxied_multi", new String[] { - "1.0-spec" /* in java.net */, - "1.0" /* in managed, and central */, - "1.0.1" /* in central */, - "1.1" /* in managed */, - "2.0-proposal-beta" /* in java.net */, - "2.0-spec" /* in java.net */, - "2.0" /* in central, and java.net */, - "2.0.1" /* in java.net */, - "2.1" /* in managed */, - "3.0" /* in central */, - "3.1" /* in central */}, "3.1", "3.1" ); + assertUpdatedProjectMetadata( "proxied_multi", + new String[]{ "1.0-spec" /* in java.net */, "1.0" /* in managed, and central */, + "1.0.1" /* in central */, "1.1" /* in managed */, "2.0-proposal-beta" + /* in java.net */, "2.0-spec" /* in java.net */, "2.0" + /* in central, and java.net */, "2.0.1" /* in java.net */, "2.1" + /* in managed */, "3.0" /* in central */, "3.1" /* in central */ }, "3.1", + "3.1" ); } + @Test public void testUpdateProjectSimpleYetIncomplete() throws Exception { - assertUpdatedProjectMetadata( "incomplete_metadata_a", new String[] { "1.0" }, "1.0", "1.0" ); + assertUpdatedProjectMetadata( "incomplete_metadata_a", new String[]{ "1.0" }, "1.0", "1.0" ); } + @Test public void testUpdateProjectSimpleYetMissing() throws Exception { - assertUpdatedProjectMetadata( "missing_metadata_a", new String[] { "1.0" }, "1.0", "1.0" ); + assertUpdatedProjectMetadata( "missing_metadata_a", new String[]{ "1.0" }, "1.0", "1.0" ); } + @Test public void testUpdateVersionSimple10() throws Exception { assertUpdatedReleaseVersionMetadata( "missing_metadata_a", "1.0" ); } + @Test public void testUpdateVersionSimple20() throws Exception { assertUpdatedReleaseVersionMetadata( "missing_metadata_b", "2.0" ); } + @Test public void testUpdateVersionSimple20NotSnapshot() throws Exception { assertUpdatedReleaseVersionMetadata( "missing_metadata_b", "2.0-20070821-dev" ); } + @Test public void testUpdateVersionSnapshotA() throws Exception { assertUpdatedSnapshotVersionMetadata( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", "20070316", "175232", "11" ); } + @Test public void testToPathFromVersionReference() { VersionedReference reference = new VersionedReference(); @@ -234,6 +236,7 @@ public class MetadataToolsTest assertEquals( "com/foo/foo-tool/1.0/maven-metadata.xml", tools.toPath( reference ) ); } + @Test public void testToPathFromProjectReference() { ProjectReference reference = new ProjectReference(); @@ -243,12 +246,14 @@ public class MetadataToolsTest assertEquals( "com/foo/foo-tool/maven-metadata.xml", tools.toPath( reference ) ); } + @Test public void testToProjectReferenceFooTools() throws RepositoryMetadataException { assertProjectReference( "com.foo", "foo-tools", "com/foo/foo-tools/maven-metadata.xml" ); } + @Test public void testToProjectReferenceAReallyLongPath() throws RepositoryMetadataException { @@ -259,6 +264,7 @@ public class MetadataToolsTest assertProjectReference( groupId, artifactId, path ); } + @Test public void testToProjectReferenceCommonsLang() throws RepositoryMetadataException { @@ -279,6 +285,7 @@ public class MetadataToolsTest assertEquals( "ProjectReference.artifactId", artifactId, reference.getArtifactId() ); } + @Test public void testToVersionedReferenceFooTool() throws RepositoryMetadataException { @@ -290,6 +297,7 @@ public class MetadataToolsTest assertVersionedReference( groupId, artifactId, version, path ); } + @Test public void testToVersionedReferenceAReallyLongPath() throws RepositoryMetadataException { @@ -301,6 +309,7 @@ public class MetadataToolsTest assertVersionedReference( groupId, artifactId, version, path ); } + @Test public void testToVersionedReferenceCommonsLang() throws RepositoryMetadataException { @@ -312,6 +321,7 @@ public class MetadataToolsTest assertVersionedReference( groupId, artifactId, version, path ); } + @Test public void testToVersionedReferenceSnapshot() throws RepositoryMetadataException { @@ -344,10 +354,10 @@ public class MetadataToolsTest reference.setArtifactId( artifactId ); reference.setVersion( version ); - ManagedRepositoryConfiguration repo = createRepository( "test-repo", "Test Repository: " + getName(), - repoRootDir ); - ManagedRepositoryContent repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, - "default" ); + ManagedRepositoryConfiguration repo = + createRepository( "test-repo", "Test Repository: " + getName(), repoRootDir ); + ManagedRepositoryContent repoContent = + applicationContext.getBean( "managedRepositoryContent#default", ManagedRepositoryContent.class ); repoContent.setRepository( repo ); Set<String> testedVersionSet = tools.gatherSnapshotVersions( repoContent, reference ); @@ -446,15 +456,16 @@ public class MetadataToolsTest assertMetadata( buf.toString(), testRepo, reference ); } - private void assertProjectMetadata( ManagedRepositoryContent testRepo, ProjectReference reference, String artifactId, - String[] expectedVersions, String latestVersion, String releaseVersion ) + private void assertProjectMetadata( ManagedRepositoryContent testRepo, ProjectReference reference, + String artifactId, String[] expectedVersions, String latestVersion, + String releaseVersion ) throws Exception { StringBuilder buf = new StringBuilder(); buf.append( "<metadata>\n" ); buf.append( " <groupId>" ).append( reference.getGroupId() ).append( "</groupId>\n" ); buf.append( " <artifactId>" ).append( reference.getArtifactId() ).append( "</artifactId>\n" ); - + if ( expectedVersions != null ) { buf.append( " <versioning>\n" ); @@ -571,11 +582,11 @@ public class MetadataToolsTest repoRoot.mkdirs(); - ManagedRepositoryConfiguration repoConfig = createRepository( "test-repo", "Test Repository: " + getName(), - repoRoot ); + ManagedRepositoryConfiguration repoConfig = + createRepository( "test-repo", "Test Repository: " + getName(), repoRoot ); - ManagedRepositoryContent repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, - "default" ); + ManagedRepositoryContent repoContent = + applicationContext.getBean( "managedRepositoryContent#default", ManagedRepositoryContent.class ); repoContent.setRepository( repoConfig ); return repoContent; } @@ -606,12 +617,5 @@ public class MetadataToolsTest prepTestRepo( repo, projectRef ); } - protected void setUp() - throws Exception - { - super.setUp(); - config = (MockConfiguration) lookup( ArchivaConfiguration.class.getName(), "mock" ); - tools = (MetadataTools) lookup( MetadataTools.class ); - } } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataReaderTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataReaderTest.java index a3da9ac78..96b586719 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataReaderTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataReaderTest.java @@ -19,21 +19,28 @@ package org.apache.maven.archiva.repository.metadata; * under the License. */ +import junit.framework.TestCase; import org.apache.maven.archiva.model.ArchivaRepositoryMetadata; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import java.io.File; /** - * RepositoryMetadataReaderTest + * RepositoryMetadataReaderTest * * @version $Id$ */ -public class RepositoryMetadataReaderTest extends PlexusInSpringTestCase +@RunWith( JUnit4.class ) +public class RepositoryMetadataReaderTest + extends TestCase { - public void testLoadSimple() throws RepositoryMetadataException + @Test + public void testLoadSimple() + throws RepositoryMetadataException { - File defaultRepoDir = new File( getBasedir(), "src/test/repositories/default-repository" ); + File defaultRepoDir = new File( "src/test/repositories/default-repository" ); File metadataFile = new File( defaultRepoDir, "org/apache/maven/shared/maven-downloader/maven-metadata.xml" ); ArchivaRepositoryMetadata metadata = RepositoryMetadataReader.read( metadataFile ); @@ -46,10 +53,12 @@ public class RepositoryMetadataReaderTest extends PlexusInSpringTestCase assertTrue( "Available version 1.0", metadata.getAvailableVersions().contains( "1.0" ) ); assertTrue( "Available version 1.1", metadata.getAvailableVersions().contains( "1.1" ) ); } - - public void testLoadComplex() throws RepositoryMetadataException + + @Test + public void testLoadComplex() + throws RepositoryMetadataException { - File defaultRepoDir = new File( getBasedir(), "src/test/repositories/default-repository" ); + File defaultRepoDir = new File( "src/test/repositories/default-repository" ); File metadataFile = new File( defaultRepoDir, "org/apache/maven/samplejar/maven-metadata.xml" ); ArchivaRepositoryMetadata metadata = RepositoryMetadataReader.read( metadataFile ); @@ -60,7 +69,8 @@ public class RepositoryMetadataReaderTest extends PlexusInSpringTestCase assertEquals( "Released Version", "2.0", metadata.getReleasedVersion() ); assertEquals( "Latest Version", "6.0-SNAPSHOT", metadata.getLatestVersion() ); assertEquals( "List of Available Versions", 18, metadata.getAvailableVersions().size() ); - assertTrue( "Available version 6.0-20060311.183228-10", metadata.getAvailableVersions().contains( "6.0-20060311.183228-10" ) ); + assertTrue( "Available version 6.0-20060311.183228-10", + metadata.getAvailableVersions().contains( "6.0-20060311.183228-10" ) ); assertTrue( "Available version 6.0-SNAPSHOT", metadata.getAvailableVersions().contains( "6.0-SNAPSHOT" ) ); } } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataWriterTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataWriterTest.java index 61880e951..dee2d8d54 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataWriterTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataWriterTest.java @@ -19,10 +19,13 @@ package org.apache.maven.archiva.repository.metadata; * under the License. */ +import junit.framework.TestCase; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.model.ArchivaRepositoryMetadata; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.custommonkey.xmlunit.XMLAssert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import java.io.File; import java.io.StringWriter; @@ -32,13 +35,16 @@ import java.io.StringWriter; * * @version $Id$ */ +@RunWith( JUnit4.class ) public class RepositoryMetadataWriterTest - extends PlexusInSpringTestCase + extends TestCase { + + @Test public void testWriteSimple() throws Exception { - File defaultRepoDir = new File( getBasedir(), "src/test/repositories/default-repository" ); + File defaultRepoDir = new File( "src/test/repositories/default-repository" ); File expectedFile = new File( defaultRepoDir, "org/apache/maven/shared/maven-downloader/maven-metadata.xml" ); String expectedContent = FileUtils.readFileToString( expectedFile, null ); |