Added: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java (added)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java Mon Oct 29 20:42:12 2012
@@ -0,0 +1,496 @@
+package org.apache.archiva.repository.content.maven2;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.admin.model.beans.ManagedRepository;
+import org.apache.archiva.common.utils.PathUtil;
+import org.apache.archiva.configuration.FileTypes;
+import org.apache.archiva.metadata.repository.storage.maven2.DefaultArtifactMappingProvider;
+import org.apache.archiva.model.ArchivaArtifact;
+import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.model.ProjectReference;
+import org.apache.archiva.model.VersionedReference;
+import org.apache.archiva.repository.ContentNotFoundException;
+import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.RepositoryException;
+import org.apache.archiva.repository.layout.LayoutException;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * ManagedDefaultRepositoryContent
+ */
+@Service ("managedRepositoryContent#default")
+@Scope ("prototype")
+public class ManagedDefaultRepositoryContent
+ extends AbstractDefaultRepositoryContent
+ implements ManagedRepositoryContent
+{
+ @Inject
+ @Named (value = "fileTypes")
+ private FileTypes filetypes;
+
+ private ManagedRepository repository;
+
+ public ManagedDefaultRepositoryContent()
+ {
+ // default to use if there are none supplied as components
+ this.artifactMappingProviders = Collections.singletonList( new DefaultArtifactMappingProvider() );
+ }
+
+ public void deleteVersion( VersionedReference reference )
+ {
+ String path = toMetadataPath( reference );
+ File projectPath = new File( getRepoRoot(), path );
+
+ File projectDir = projectPath.getParentFile();
+ if ( projectDir.exists() && projectDir.isDirectory() )
+ {
+ FileUtils.deleteQuietly( projectDir );
+ }
+ }
+
+ public void deleteProject( String namespace, String projectId )
+ throws RepositoryException, ContentNotFoundException
+ {
+ ArtifactReference artifactReference = new ArtifactReference();
+ artifactReference.setGroupId( namespace );
+ artifactReference.setArtifactId( projectId );
+ String path = toPath( artifactReference );
+ File directory = new File( getRepoRoot(), path );
+ if ( !directory.exists() )
+ {
+ throw new ContentNotFoundException( "cannot found project " + namespace + ":" + projectId );
+ }
+ if ( directory.isDirectory() )
+ {
+ try
+ {
+ FileUtils.deleteDirectory( directory );
+ }
+ catch ( IOException e )
+ {
+ throw new RepositoryException( e.getMessage(), e );
+ }
+ }
+ else
+ {
+ log.warn( "project {}:{} is not a directory", namespace, projectId );
+ }
+
+ }
+
+ public void deleteArtifact( ArtifactReference artifactReference )
+ {
+ String path = toPath( artifactReference );
+ File filePath = new File( getRepoRoot(), path );
+
+ if ( filePath.exists() )
+ {
+ FileUtils.deleteQuietly( filePath );
+ }
+
+ File filePathmd5 = new File( getRepoRoot(), path + ".md5" );
+
+ if ( filePathmd5.exists() )
+ {
+ FileUtils.deleteQuietly( filePathmd5 );
+ }
+
+ File filePathsha1 = new File( getRepoRoot(), path + ".sha1" );
+
+ if ( filePathsha1.exists() )
+ {
+ FileUtils.deleteQuietly( filePathsha1 );
+ }
+ }
+
+ public void deleteGroupId( String groupId )
+ throws ContentNotFoundException
+ {
+
+ String path = StringUtils.replaceChars( groupId, '.', '/' );
+
+ File directory = new File( getRepoRoot(), path );
+
+ if ( directory.exists() )
+ {
+ try
+ {
+ FileUtils.deleteDirectory( directory );
+ }
+ catch ( IOException e )
+ {
+ log.warn( "skip error deleting directory {}:", directory.getPath(), e );
+ }
+ }
+ }
+
+ public String getId()
+ {
+ return repository.getId();
+ }
+
+ public Set<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
+ throws ContentNotFoundException
+ {
+ File artifactFile = toFile( reference );
+ File repoDir = artifactFile.getParentFile();
+
+ if ( !repoDir.exists() )
+ {
+ throw new ContentNotFoundException(
+ "Unable to get related artifacts using a non-existant directory: " + repoDir.getAbsolutePath() );
+ }
+
+ if ( !repoDir.isDirectory() )
+ {
+ throw new ContentNotFoundException(
+ "Unable to get related artifacts using a non-directory: " + repoDir.getAbsolutePath() );
+ }
+
+ Set<ArtifactReference> foundArtifacts = new HashSet<ArtifactReference>();
+
+ // First gather up the versions found as artifacts in the managed repository.
+ File repoFiles[] = repoDir.listFiles();
+ for ( int i = 0; i < repoFiles.length; i++ )
+ {
+ if ( repoFiles[i].isDirectory() )
+ {
+ // Skip it. it's a directory.
+ continue;
+ }
+
+ String relativePath = PathUtil.getRelative( repository.getLocation(), repoFiles[i] );
+
+ if ( filetypes.matchesArtifactPattern( relativePath ) )
+ {
+ try
+ {
+ ArtifactReference artifact = toArtifactReference( relativePath );
+
+ // Test for related, groupId / artifactId / version must match.
+ if ( artifact.getGroupId().equals( reference.getGroupId() ) && artifact.getArtifactId().equals(
+ reference.getArtifactId() ) && artifact.getVersion().equals( reference.getVersion() ) )
+ {
+ foundArtifacts.add( artifact );
+ }
+ }
+ catch ( LayoutException e )
+ {
+ log.debug( "Not processing file that is not an artifact: {}", e.getMessage() );
+ }
+ }
+ }
+
+ return foundArtifacts;
+ }
+
+ public String getRepoRoot()
+ {
+ return repository.getLocation();
+ }
+
+ public ManagedRepository getRepository()
+ {
+ return repository;
+ }
+
+ /**
+ * Gather the Available Versions (on disk) for a specific Project Reference, based on filesystem
+ * information.
+ *
+ * @return the Set of available versions, based on the project reference.
+ * @throws org.apache.archiva.repository.layout.LayoutException
+ * @throws org.apache.archiva.repository.layout.LayoutException
+ */
+ public Set<String> getVersions( ProjectReference reference )
+ throws ContentNotFoundException, LayoutException
+ {
+ String path = toMetadataPath( reference );
+
+ int idx = path.lastIndexOf( '/' );
+ if ( idx > 0 )
+ {
+ path = path.substring( 0, idx );
+ }
+
+ File repoDir = new File( repository.getLocation(), path );
+
+ if ( !repoDir.exists() )
+ {
+ throw new ContentNotFoundException(
+ "Unable to get Versions on a non-existant directory: " + repoDir.getAbsolutePath() );
+ }
+
+ if ( !repoDir.isDirectory() )
+ {
+ throw new ContentNotFoundException(
+ "Unable to get Versions on a non-directory: " + repoDir.getAbsolutePath() );
+ }
+
+ Set<String> foundVersions = new HashSet<String>();
+ VersionedReference versionRef = new VersionedReference();
+ versionRef.setGroupId( reference.getGroupId() );
+ versionRef.setArtifactId( reference.getArtifactId() );
+
+ File repoFiles[] = repoDir.listFiles();
+ for ( int i = 0; i < repoFiles.length; i++ )
+ {
+ if ( !repoFiles[i].isDirectory() )
+ {
+ // Skip it. not a directory.
+ continue;
+ }
+
+ // Test if dir has an artifact, which proves to us that it is a valid version directory.
+ String version = repoFiles[i].getName();
+ versionRef.setVersion( version );
+
+ if ( hasArtifact( versionRef ) )
+ {
+ // Found an artifact, must be a valid version.
+ foundVersions.add( version );
+ }
+ }
+
+ return foundVersions;
+ }
+
+ public Set<String> getVersions( VersionedReference reference )
+ throws ContentNotFoundException
+ {
+ String path = toMetadataPath( reference );
+
+ int idx = path.lastIndexOf( '/' );
+ if ( idx > 0 )
+ {
+ path = path.substring( 0, idx );
+ }
+
+ File repoDir = new File( repository.getLocation(), path );
+
+ if ( !repoDir.exists() )
+ {
+ throw new ContentNotFoundException(
+ "Unable to get versions on a non-existant directory: " + repoDir.getAbsolutePath() );
+ }
+
+ if ( !repoDir.isDirectory() )
+ {
+ throw new ContentNotFoundException(
+ "Unable to get versions on a non-directory: " + repoDir.getAbsolutePath() );
+ }
+
+ Set<String> foundVersions = new HashSet<String>();
+
+ // First gather up the versions found as artifacts in the managed repository.
+ File repoFiles[] = repoDir.listFiles();
+ for ( int i = 0; i < repoFiles.length; i++ )
+ {
+ if ( repoFiles[i].isDirectory() )
+ {
+ // Skip it. it's a directory.
+ continue;
+ }
+
+ String relativePath = PathUtil.getRelative( repository.getLocation(), repoFiles[i] );
+
+ if ( filetypes.matchesDefaultExclusions( relativePath ) )
+ {
+ // Skip it, it's metadata or similar
+ continue;
+ }
+
+ if ( filetypes.matchesArtifactPattern( relativePath ) )
+ {
+ try
+ {
+ ArtifactReference artifact = toArtifactReference( relativePath );
+
+ foundVersions.add( artifact.getVersion() );
+ }
+ catch ( LayoutException e )
+ {
+ log.debug( "Not processing file that is not an artifact: {}", e.getMessage() );
+ }
+ }
+ }
+
+ return foundVersions;
+ }
+
+ public boolean hasContent( ArtifactReference reference )
+ {
+ File artifactFile = toFile( reference );
+ return artifactFile.exists() && artifactFile.isFile();
+ }
+
+ public boolean hasContent( ProjectReference reference )
+ {
+ try
+ {
+ Set<String> versions = getVersions( reference );
+ return !versions.isEmpty();
+ }
+ catch ( ContentNotFoundException e )
+ {
+ return false;
+ }
+ catch ( LayoutException e )
+ {
+ return false;
+ }
+ }
+
+ public boolean hasContent( VersionedReference reference )
+ {
+ try
+ {
+ return ( getFirstArtifact( reference ) != null );
+ }
+ catch ( IOException e )
+ {
+ return false;
+ }
+ catch ( LayoutException e )
+ {
+ return false;
+ }
+ }
+
+ public void setRepository( ManagedRepository repository )
+ {
+ this.repository = repository;
+ }
+
+ /**
+ * Convert a path to an artifact reference.
+ *
+ * @param path the path to convert. (relative or full location path)
+ * @throws org.apache.archiva.repository.layout.LayoutException if the path cannot be converted to an artifact reference.
+ */
+ @Override
+ public ArtifactReference toArtifactReference( String path )
+ throws LayoutException
+ {
+ if ( ( path != null ) && path.startsWith( repository.getLocation() ) && repository.getLocation().length() > 0 )
+ {
+ return super.toArtifactReference( path.substring( repository.getLocation().length() + 1 ) );
+ }
+
+ return super.toArtifactReference( path );
+ }
+
+ public File toFile( ArtifactReference reference )
+ {
+ return new File( repository.getLocation(), toPath( reference ) );
+ }
+
+ public File toFile( ArchivaArtifact reference )
+ {
+ return new File( repository.getLocation(), toPath( reference ) );
+ }
+
+ /**
+ * Get the first Artifact found in the provided VersionedReference location.
+ *
+ * @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.
+ * @throws java.io.IOException if the versioned reference is invalid (example: doesn't exist, or isn't a directory)
+ * @throws org.apache.archiva.repository.layout.LayoutException
+ */
+ private ArtifactReference getFirstArtifact( VersionedReference reference )
+ throws LayoutException, IOException
+ {
+ String path = toMetadataPath( reference );
+
+ int idx = path.lastIndexOf( '/' );
+ if ( idx > 0 )
+ {
+ path = path.substring( 0, idx );
+ }
+
+ File repoDir = new File( repository.getLocation(), path );
+
+ if ( !repoDir.exists() )
+ {
+ throw new IOException( "Unable to gather the list of snapshot versions on a non-existant directory: "
+ + repoDir.getAbsolutePath() );
+ }
+
+ if ( !repoDir.isDirectory() )
+ {
+ throw new IOException(
+ "Unable to gather the list of snapshot versions on a non-directory: " + repoDir.getAbsolutePath() );
+ }
+
+ File repoFiles[] = repoDir.listFiles();
+ for ( int i = 0; i < repoFiles.length; i++ )
+ {
+ if ( repoFiles[i].isDirectory() )
+ {
+ // Skip it. it's a directory.
+ continue;
+ }
+
+ String relativePath = PathUtil.getRelative( repository.getLocation(), repoFiles[i] );
+
+ if ( filetypes.matchesArtifactPattern( relativePath ) )
+ {
+ ArtifactReference artifact = toArtifactReference( relativePath );
+
+ return artifact;
+ }
+ }
+
+ // No artifact was found.
+ return null;
+ }
+
+ private boolean hasArtifact( VersionedReference reference )
+ throws LayoutException
+ {
+ try
+ {
+ return ( getFirstArtifact( reference ) != null );
+ }
+ catch ( IOException e )
+ {
+ return false;
+ }
+ }
+
+ public void setFiletypes( FileTypes filetypes )
+ {
+ this.filetypes = filetypes;
+ }
+}
Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/RemoteDefaultRepositoryContent.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/RemoteDefaultRepositoryContent.java?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/RemoteDefaultRepositoryContent.java (added)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/RemoteDefaultRepositoryContent.java Mon Oct 29 20:42:12 2012
@@ -0,0 +1,86 @@
+package org.apache.archiva.repository.content.maven2;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.admin.model.beans.RemoteRepository;
+import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.model.RepositoryURL;
+import org.apache.archiva.repository.RemoteRepositoryContent;
+import org.apache.archiva.repository.layout.LayoutException;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+
+/**
+ * RemoteDefaultRepositoryContent
+ *
+ *
+ */
+@Service( "remoteRepositoryContent#default" )
+@Scope( "prototype" )
+public class RemoteDefaultRepositoryContent
+ extends AbstractDefaultRepositoryContent
+ implements RemoteRepositoryContent
+{
+ private RemoteRepository repository;
+
+ public String getId()
+ {
+ return repository.getId();
+ }
+
+ public RemoteRepository getRepository()
+ {
+ return repository;
+ }
+
+ public RepositoryURL getURL()
+ {
+ return new RepositoryURL( repository.getUrl() );
+ }
+
+ public void setRepository( RemoteRepository repository )
+ {
+ this.repository = repository;
+ }
+
+ /**
+ * Convert a path to an artifact reference.
+ *
+ * @param path the path to convert. (relative or full url path)
+ * @throws org.apache.archiva.repository.layout.LayoutException if the path cannot be converted to an artifact reference.
+ */
+ @Override
+ public ArtifactReference toArtifactReference( String path )
+ throws LayoutException
+ {
+ if ( ( path != null ) && path.startsWith( repository.getUrl() ) )
+ {
+ return super.toArtifactReference( path.substring( repository.getUrl().length() ) );
+ }
+
+ return super.toArtifactReference( path );
+ }
+
+ public RepositoryURL toURL( ArtifactReference reference )
+ {
+ String url = repository.getUrl() + toPath( reference );
+ return new RepositoryURL( url );
+ }
+}
Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/RemoteDefaultRepositoryContent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/RemoteDefaultRepositoryContent.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/RepositoryRequest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/RepositoryRequest.java?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/RepositoryRequest.java (added)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/RepositoryRequest.java Mon Oct 29 20:42:12 2012
@@ -0,0 +1,287 @@
+package org.apache.archiva.repository.content.maven2;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.content.PathParser;
+import org.apache.archiva.repository.content.legacy.LegacyPathParser;
+import org.apache.archiva.repository.content.legacy.ManagedLegacyRepositoryContent;
+import org.apache.archiva.repository.layout.LayoutException;
+import org.apache.archiva.repository.metadata.MetadataTools;
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * RepositoryRequest is used to determine the type of request that is incoming, and convert it to an appropriate
+ * ArtifactReference.
+ * <p/>
+ * <p/>
+ * <p/>
+ */
+public class RepositoryRequest
+{
+ private PathParser defaultPathParser = new DefaultPathParser();
+
+ 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.
+ *
+ * @param requestedPath the relative path to the content.
+ * @return the ArtifactReference for the requestedPath.
+ * @throws org.apache.archiva.repository.layout.LayoutException if the request path is not layout valid.
+ */
+ public ArtifactReference toArtifactReference( String requestedPath )
+ throws LayoutException
+ {
+ if ( StringUtils.isBlank( requestedPath ) )
+ {
+ throw new LayoutException( "Blank request path is not a valid." );
+ }
+
+ String path = requestedPath;
+ while ( path.startsWith( "/" ) )
+ {
+ path = path.substring( 1 );
+
+ // Only slash? that's bad, mmm-kay?
+ if ( "/".equals( path ) )
+ {
+ throw new LayoutException( "Invalid request path: Slash only." );
+ }
+ }
+
+ if ( isDefault( path ) )
+ {
+ return defaultPathParser.toArtifactReference( path );
+ }
+ else if ( isLegacy( path ) )
+ {
+ return legacyPathParser.toArtifactReference( path );
+ }
+ else
+ {
+ throw new LayoutException( "Not a valid request path layout, too short." );
+ }
+ }
+
+ /**
+ * <p>
+ * Tests the path to see if it conforms to the expectations of a metadata request.
+ * </p>
+ * <p>
+ * NOTE: This does a cursory check on the path's last element. A result of true
+ * from this method is not a guarantee that the metadata is in a valid format, or
+ * that it even contains data.
+ * </p>
+ *
+ * @param requestedPath the path to test.
+ * @return true if the requestedPath is likely a metadata request.
+ */
+ public boolean isMetadata( String requestedPath )
+ {
+ return requestedPath.endsWith( "/" + MetadataTools.MAVEN_METADATA );
+ }
+
+ /**
+ * @param requestedPath
+ * @return true if the requestedPath is likely an archetype catalog request.
+ */
+ public boolean isArchetypeCatalog( String requestedPath )
+ {
+ return requestedPath.endsWith( "/" + MetadataTools.MAVEN_ARCHETYPE_CATALOG );
+ }
+
+ /**
+ * <p>
+ * Tests the path to see if it conforms to the expectations of a support file request.
+ * </p>
+ * <p>
+ * Tests for <code>.sha1</code>, <code>.md5</code>, <code>.asc</code>, and <code>.php</code>.
+ * </p>
+ * <p>
+ * NOTE: This does a cursory check on the path's extension only. A result of true
+ * from this method is not a guarantee that the support resource is in a valid format, or
+ * that it even contains data.
+ * </p>
+ *
+ * @param requestedPath the path to test.
+ * @return true if the requestedPath is likely that of a support file request.
+ */
+ public boolean isSupportFile( String requestedPath )
+ {
+ int idx = requestedPath.lastIndexOf( '.' );
+ if ( idx <= 0 )
+ {
+ return false;
+ }
+
+ String ext = requestedPath.substring( idx );
+ return ( ".sha1".equals( ext ) || ".md5".equals( ext ) || ".asc".equals( ext ) || ".pgp".equals( ext ) );
+ }
+
+ public boolean isMetadataSupportFile( String requestedPath )
+ {
+ if ( isSupportFile( requestedPath ) )
+ {
+ String basefilePath = StringUtils.substring( requestedPath, 0, requestedPath.lastIndexOf( '.' ) );
+ if ( isMetadata( basefilePath ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * <p>
+ * Tests the path to see if it conforms to the expectations of a default layout request.
+ * </p>
+ * <p>
+ * NOTE: This does a cursory check on the count of path elements only. A result of
+ * true from this method is not a guarantee that the path sections are valid and
+ * can be resolved to an artifact reference. use {@link #toArtifactReference(String)}
+ * if you want a more complete analysis of the validity of the path.
+ * </p>
+ *
+ * @param requestedPath the path to test.
+ * @return true if the requestedPath is likely that of a default layout request.
+ */
+ public boolean isDefault( String requestedPath )
+ {
+ if ( StringUtils.isBlank( requestedPath ) )
+ {
+ return false;
+ }
+
+ 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 ) )
+ {
+ return true;
+ }
+ else
+ {
+ // check if checksum of artifact-level metadata (ex. eclipse/jdtcore/maven-metadata.xml.sha1)
+ int idx = requestedPath.lastIndexOf( '.' );
+ if ( idx > 0 )
+ {
+ String base = requestedPath.substring( 0, idx );
+ if ( isMetadata( base ) && isSupportFile( requestedPath ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * <p>
+ * Tests the path to see if it conforms to the expectations of a legacy layout request.
+ * </p>
+ * <p>
+ * NOTE: This does a cursory check on the count of path elements only. A result of
+ * true from this method is not a guarantee that the path sections are valid and
+ * can be resolved to an artifact reference. use {@link #toArtifactReference(String)}
+ * if you want a more complete analysis of the validity of the path.
+ * </p>
+ *
+ * @param requestedPath the path to test.
+ * @return true if the requestedPath is likely that of a legacy layout request.
+ */
+ public boolean isLegacy( String requestedPath )
+ {
+ if ( StringUtils.isBlank( requestedPath ) )
+ {
+ return false;
+ }
+
+ String pathParts[] = StringUtils.splitPreserveAllTokens( requestedPath, '/' );
+ return pathParts.length == 3;
+ }
+
+ /**
+ * Adjust the requestedPath to conform to the native layout of the provided {@link org.apache.archiva.repository.ManagedRepositoryContent}.
+ *
+ * @param requestedPath the incoming requested path.
+ * @param repository the repository to adjust to.
+ * @return the adjusted (to native) path.
+ * @throws org.apache.archiva.repository.layout.LayoutException if the path cannot be parsed.
+ */
+ public String toNativePath( String requestedPath, ManagedRepositoryContent repository )
+ throws LayoutException
+ {
+ if ( StringUtils.isBlank( requestedPath ) )
+ {
+ throw new LayoutException( "Request Path is blank." );
+ }
+
+ String referencedResource = requestedPath;
+ // No checksum by default.
+ String supportfile = "";
+
+ // Figure out support file, and actual referencedResource.
+ if ( isSupportFile( requestedPath ) )
+ {
+ int idx = requestedPath.lastIndexOf( '.' );
+ referencedResource = requestedPath.substring( 0, idx );
+ supportfile = requestedPath.substring( idx );
+ }
+
+ if ( isMetadata( referencedResource ) )
+ {
+ if ( repository instanceof ManagedLegacyRepositoryContent )
+ {
+ throw new LayoutException( "Cannot translate metadata request to legacy layout." );
+ }
+
+ /* Nothing to translate.
+ * Default layout is the only layout that can contain maven-metadata.xml files, and
+ * if the managedRepository is layout legacy, this request would never occur.
+ */
+ return requestedPath;
+ }
+
+ // Treat as an artifact reference.
+ ArtifactReference ref = toArtifactReference( referencedResource );
+ String adjustedPath = repository.toPath( ref );
+ return adjustedPath + supportfile;
+ }
+}
Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/RepositoryRequest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/RepositoryRequest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractDefaultRepositoryContentTestCase.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractDefaultRepositoryContentTestCase.java?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractDefaultRepositoryContentTestCase.java (added)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractDefaultRepositoryContentTestCase.java Mon Oct 29 20:42:12 2012
@@ -0,0 +1,482 @@
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.repository.layout.LayoutException;
+import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
+import org.apache.commons.lang.StringUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+
+import static org.junit.Assert.*;
+
+/**
+ * AbstractDefaultRepositoryContentTestCase
+ *
+ *
+ */
+@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
+@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
+public abstract class AbstractDefaultRepositoryContentTestCase
+{
+ @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",
+ "wrong artifact id" );
+ }
+
+ /**
+ * [MRM-432] Oddball version spec.
+ * Example of an oddball / unusual version spec.
+ * @throws org.apache.archiva.repository.layout.LayoutException
+ */
+ @Test
+ public void testGoodButOddVersionSpecGanymedSsh2()
+ throws LayoutException
+ {
+ String groupId = "ch.ethz.ganymed";
+ String artifactId = "ganymed-ssh2";
+ String version = "build210";
+ String classifier = null;
+ String type = "jar";
+ String path = "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ /**
+ * [MRM-432] Oddball version spec.
+ * Example of an oddball / unusual version spec.
+ * @throws org.apache.archiva.repository.layout.LayoutException
+ */
+ @Test
+ public void testGoodButOddVersionSpecJavaxComm()
+ throws LayoutException
+ {
+ String groupId = "javax";
+ String artifactId = "comm";
+ String version = "3.0-u1";
+ String classifier = null;
+ String type = "jar";
+ String path = "javax/comm/3.0-u1/comm-3.0-u1.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ /**
+ * Test the ejb-client type spec.
+ * Type specs are not a 1 to 1 map to the extension.
+ * This tests that effect.
+ * @throws org.apache.archiva.repository.layout.LayoutException
+ */
+ /* TODO: Re-enabled in the future.
+ public void testGoodFooEjbClient()
+ throws LayoutException
+ {
+ String groupId = "com.foo";
+ String artifactId = "foo-client";
+ String version = "1.0";
+ String classifier = null;
+ String type = "ejb-client"; // oddball type-spec (should result in jar extension)
+ String path = "com/foo/foo-client/1.0/foo-client-1.0.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+ */
+
+ /**
+ * [MRM-432] Oddball version spec.
+ * Example of an oddball / unusual version spec.
+ * @throws org.apache.archiva.repository.layout.LayoutException
+ */
+ @Test
+ public void testGoodButOddVersionSpecJavaxPersistence()
+ throws LayoutException
+ {
+ String groupId = "javax.persistence";
+ String artifactId = "ejb";
+ String version = "3.0-public_review";
+ String classifier = null;
+ String type = "jar";
+ String path = "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar";
+
+ /*
+ * The version id of "public_review" can cause problems. is it part of
+ * the version spec? or the classifier?
+ * Since the path spec below shows it in the path, then it is really
+ * part of the version spec.
+ */
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ @Test
+ public void testGoodComFooTool()
+ throws LayoutException
+ {
+ String groupId = "com.foo";
+ String artifactId = "foo-tool";
+ String version = "1.0";
+ String classifier = null;
+ String type = "jar";
+ String path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ @Test
+ public void testGoodCommonsLang()
+ throws LayoutException
+ {
+ String groupId = "commons-lang";
+ String artifactId = "commons-lang";
+ String version = "2.1";
+ String classifier = null;
+ String type = "jar";
+ String path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ /**
+ * [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected"
+ */
+ @Test
+ public void testGoodDashedArtifactId()
+ throws LayoutException
+ {
+ String groupId = "test.maven-arch";
+ String artifactId = "test-arch";
+ String version = "2.0.3-SNAPSHOT";
+ String classifier = null;
+ String type = "pom";
+ String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ /**
+ * It may seem odd, but this is a valid artifact.
+ */
+ @Test
+ public void testGoodDotNotationArtifactId()
+ throws LayoutException
+ {
+ String groupId = "com.company.department";
+ String artifactId = "com.company.department";
+ String version = "0.2";
+ String classifier = null;
+ String type = "pom";
+ String path = "com/company/department/com.company.department/0.2/com.company.department-0.2.pom";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ /**
+ * It may seem odd, but this is a valid artifact.
+ */
+ @Test
+ public void testGoodDotNotationSameGroupIdAndArtifactId()
+ throws LayoutException
+ {
+ String groupId = "com.company.department";
+ String artifactId = "com.company.department.project";
+ String version = "0.3";
+ String classifier = null;
+ String type = "pom";
+ String path = "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ /**
+ * Test the classifier, and java-source type spec.
+ * @throws org.apache.archiva.repository.layout.LayoutException
+ */
+ @Test
+ public void testGoodFooLibSources()
+ throws LayoutException
+ {
+ String groupId = "com.foo.lib";
+ String artifactId = "foo-lib";
+ String version = "2.1-alpha-1";
+ String classifier = "sources";
+ String type = "java-source"; // oddball type-spec (should result in jar extension)
+ String path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ /**
+ * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
+ * @throws org.apache.archiva.repository.layout.LayoutException
+ */
+ @Test
+ public void testGoodSnapshotMavenTest()
+ throws LayoutException
+ {
+ String groupId = "org.apache.archiva.test";
+ String artifactId = "redonkulous";
+ String version = "3.1-beta-1-20050831.101112-42";
+ String classifier = null;
+ String type = "jar";
+ String path = "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ /**
+ * [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
+ {
+ String groupId = "maven";
+ String artifactId = "maven-test-plugin";
+ String version = "1.8.2";
+ String classifier = null;
+ String type = "pom";
+ String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ /**
+ * [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
+ {
+ String groupId = "maven";
+ String artifactId = "maven-test-plugin";
+ String version = "1.8.2";
+ String classifier = null;
+ String type = "maven-plugin";
+ String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ /**
+ * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
+ */
+ @Test
+ public void testGoodDetectCoberturaMavenPlugin()
+ throws LayoutException
+ {
+ String groupId = "org.codehaus.mojo";
+ String artifactId = "cobertura-maven-plugin";
+ String version = "2.1";
+ String classifier = null;
+ String type = "maven-plugin";
+ String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ @Test
+ public void testToArtifactOnEmptyPath()
+ {
+ try
+ {
+ toArtifactReference( "" );
+ fail( "Should have failed due to empty path." );
+ }
+ catch ( LayoutException e )
+ {
+ /* expected path */
+ }
+ }
+
+ @Test
+ public void testToArtifactOnNullPath()
+ {
+ try
+ {
+ toArtifactReference( null );
+ fail( "Should have failed due to null path." );
+ }
+ catch ( LayoutException e )
+ {
+ /* expected path */
+ }
+ }
+
+ @Test
+ public void testToArtifactReferenceOnEmptyPath()
+ {
+ try
+ {
+ toArtifactReference( "" );
+ fail( "Should have failed due to empty path." );
+ }
+ catch ( LayoutException e )
+ {
+ /* expected path */
+ }
+ }
+
+ @Test
+ public void testToArtifactReferenceOnNullPath()
+ {
+ try
+ {
+ toArtifactReference( null );
+ fail( "Should have failed due to null path." );
+ }
+ catch ( LayoutException e )
+ {
+ /* expected path */
+ }
+ }
+
+ @Test
+ public void testToPathOnNullArtifactReference()
+
+ {
+ try
+ {
+ ArtifactReference reference = null;
+ toPath( reference );
+ fail( "Should have failed due to null artifact reference." );
+ }
+ catch ( IllegalArgumentException e )
+ {
+ /* expected path */
+ }
+ }
+
+ private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
+ String version, String classifier, String type )
+ {
+ String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier
+ + ":" + type;
+
+ assertNotNull( expectedId + " - Should not be null.", actualReference );
+
+ assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
+ assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
+ if ( StringUtils.isNotBlank( classifier ) )
+ {
+ assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() );
+ }
+ assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
+ assertEquals( expectedId + " - Type", type, actualReference.getType() );
+ }
+
+ private void assertBadPath( String path, String reason )
+ {
+ try
+ {
+ toArtifactReference( path );
+ fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
+ }
+ catch ( LayoutException e )
+ {
+ /* expected path */
+ }
+ }
+
+ /**
+ * Perform a roundtrip through the layout routines to determine success.
+ */
+ private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
+ String type )
+ throws LayoutException
+ {
+ ArtifactReference expectedArtifact = createArtifact( groupId, artifactId, version, classifier, type );
+
+ // --- Artifact Tests.
+
+ // Artifact to Path
+ assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( expectedArtifact ) );
+
+ // --- Artifact Reference Tests
+
+ // Path to Artifact Reference.
+ ArtifactReference testReference = toArtifactReference( path );
+ assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
+
+ // And back again, using test Reference from previous step.
+ assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( testReference ) );
+ }
+
+ private ArtifactReference createArtifact( String groupId, String artifactId, String version, String classifier,
+ String type )
+ {
+ ArtifactReference artifact = new ArtifactReference();
+ artifact.setGroupId( groupId );
+ artifact.setArtifactId( artifactId );
+ artifact.setVersion( version );
+ artifact.setClassifier( classifier );
+ artifact.setType( type );
+ assertNotNull( artifact );
+ return artifact;
+ }
+
+ protected abstract ArtifactReference toArtifactReference( String path )
+ throws LayoutException;
+
+ protected abstract String toPath( ArtifactReference reference );
+}
Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractDefaultRepositoryContentTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractDefaultRepositoryContentTestCase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractLegacyRepositoryContentTestCase.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractLegacyRepositoryContentTestCase.java?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractLegacyRepositoryContentTestCase.java (added)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractLegacyRepositoryContentTestCase.java Mon Oct 29 20:42:12 2012
@@ -0,0 +1,436 @@
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.repository.layout.LayoutException;
+import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+
+import static org.junit.Assert.*;
+
+/**
+ * AbstractLegacyRepositoryContentTestCase
+ *
+ *
+ */
+@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
+@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
+public abstract class AbstractLegacyRepositoryContentTestCase
+{
+ @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" );
+ }
+
+ /**
+ * [MRM-432] Oddball version spec.
+ * Example of an oddball / unusual version spec.
+ * @throws org.apache.archiva.repository.layout.LayoutException
+ */
+ @Test
+ public void testGoodButOddVersionSpecGanymedSsh2()
+ throws LayoutException
+ {
+ String groupId = "ch.ethz.ganymed";
+ String artifactId = "ganymed-ssh2";
+ String version = "build210";
+ String type = "jar";
+ String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar";
+
+ assertLayout( path, groupId, artifactId, version, null, type );
+ }
+
+ /**
+ * [MRM-432] Oddball version spec.
+ * Example of an oddball / unusual version spec.
+ * @throws org.apache.archiva.repository.layout.LayoutException
+ */
+ @Test
+ public void testGoodButOddVersionSpecJavaxComm()
+ throws LayoutException
+ {
+ String groupId = "javax";
+ String artifactId = "comm";
+ String version = "3.0-u1";
+ String type = "jar";
+ String path = "javax/jars/comm-3.0-u1.jar";
+
+ assertLayout( path, groupId, artifactId, version, null, type );
+ }
+
+ /**
+ * [MRM-432] Oddball version spec.
+ * Example of an oddball / unusual version spec.
+ * @throws org.apache.archiva.repository.layout.LayoutException
+ */
+ @Test
+ public void testGoodButOddVersionSpecJavaxPersistence()
+ throws LayoutException
+ {
+ String groupId = "javax.persistence";
+ String artifactId = "ejb";
+ String version = "3.0-public_review";
+ String type = "jar";
+ String path = "javax.persistence/jars/ejb-3.0-public_review.jar";
+
+ /*
+ * The version id of "public_review" can cause problems. is it part of
+ * the version spec? or the classifier?
+ */
+
+ assertLayout( path, groupId, artifactId, version, null, type );
+ }
+
+ @Test
+ public void testGoodCommonsLang()
+ throws LayoutException
+ {
+ String groupId = "commons-lang";
+ String artifactId = "commons-lang";
+ String version = "2.1";
+ String type = "jar";
+ String path = "commons-lang/jars/commons-lang-2.1.jar";
+
+ assertLayout( path, groupId, artifactId, version, null, type );
+ }
+
+ @Test
+ public void testGoodDerby()
+ throws LayoutException
+ {
+ String groupId = "org.apache.derby";
+ String artifactId = "derby";
+ String version = "10.2.2.0";
+ String type = "jar";
+ String path = "org.apache.derby/jars/derby-10.2.2.0.jar";
+
+ assertLayout( path, groupId, artifactId, version, null, type );
+ }
+
+ /**
+ * Test the ejb-client type spec.
+ * Type specs are not a 1 to 1 map to the extension.
+ * This tests that effect.
+ * @throws org.apache.archiva.repository.layout.LayoutException
+ */
+ /* TODO: Re-enabled in the future.
+ public void testGoodFooEjbClient()
+ throws LayoutException
+ {
+ String groupId = "com.foo";
+ String artifactId = "foo-client";
+ String version = "1.0";
+ String type = "ejb"; // oddball type-spec (should result in jar extension)
+ String path = "com.foo/ejbs/foo-client-1.0.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+ */
+
+ /**
+ * Test the classifier.
+ * @throws org.apache.archiva.repository.layout.LayoutException
+ */
+ @Test
+ public void testGoodFooLibJavadoc()
+ throws LayoutException
+ {
+ String groupId = "com.foo.lib";
+ String artifactId = "foo-lib";
+ String version = "2.1-alpha-1";
+ String type = "javadoc";
+ String classifier = "javadoc";
+ String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ /**
+ * Test the classifier, and java-source type spec.
+ * @throws org.apache.archiva.repository.layout.LayoutException
+ */
+ @Test
+ public void testGoodFooLibSources()
+ throws LayoutException
+ {
+ String groupId = "com.foo.lib";
+ 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 path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ @Test
+ public void testGoodFooTool()
+ throws LayoutException
+ {
+ String groupId = "com.foo";
+ String artifactId = "foo-tool";
+ String version = "1.0";
+ String type = "jar";
+ String path = "com.foo/jars/foo-tool-1.0.jar";
+
+ assertLayout( path, groupId, artifactId, version, null, type );
+ }
+
+ @Test
+ public void testGoodGeronimoEjbSpec()
+ throws LayoutException
+ {
+ String groupId = "org.apache.geronimo.specs";
+ String artifactId = "geronimo-ejb_2.1_spec";
+ String version = "1.0.1";
+ String type = "jar";
+ String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar";
+
+ assertLayout( path, groupId, artifactId, version, null, type );
+ }
+
+ @Test
+ public void testGoodLdapClientsPom()
+ throws LayoutException
+ {
+ String groupId = "directory-clients";
+ String artifactId = "ldap-clients";
+ String version = "0.9.1-SNAPSHOT";
+ String type = "pom";
+ String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
+
+ assertLayout( path, groupId, artifactId, version, null, type );
+ }
+
+ /**
+ * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
+ * @throws org.apache.archiva.repository.layout.LayoutException
+ */
+ @Test
+ public void testGoodSnapshotMavenTest()
+ throws LayoutException
+ {
+ String groupId = "org.apache.archiva.test";
+ String artifactId = "redonkulous";
+ String version = "3.1-beta-1-20050831.101112-42";
+ String type = "jar";
+ String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
+
+ assertLayout( path, groupId, artifactId, version, null, type );
+ }
+
+ /**
+ * [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
+ {
+ String groupId = "maven";
+ String artifactId = "maven-test-plugin";
+ String version = "1.8.2";
+ String type = "pom";
+
+ String path = "maven/poms/maven-test-plugin-1.8.2.pom";
+
+ assertLayout( path, groupId, artifactId, version, null, type );
+ }
+
+ /**
+ * [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
+ {
+ String groupId = "maven";
+ String artifactId = "maven-test-plugin";
+ String version = "1.8.2";
+ String type = "maven-one-plugin";
+ String path = "maven/plugins/maven-test-plugin-1.8.2.jar";
+
+ assertLayout( path, groupId, artifactId, version, null, type );
+ }
+
+ /**
+ * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
+ */
+ @Test
+ public void testGoodDetectPluginAvalonMeta()
+ throws LayoutException
+ {
+ String groupId = "avalon-meta";
+ String artifactId = "avalon-meta-plugin";
+ String version = "1.1";
+ String type = "maven-one-plugin";
+ String path = "avalon-meta/plugins/avalon-meta-plugin-1.1.jar";
+
+ assertLayout( path, groupId, artifactId, version, null, type );
+ }
+
+ /**
+ * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
+ */
+ @Test
+ public void testGoodDetectPluginCactusMaven()
+ throws LayoutException
+ {
+ String groupId = "cactus";
+ String artifactId = "cactus-maven";
+ String version = "1.7dev-20040815";
+ String type = "maven-one-plugin";
+ String path = "cactus/plugins/cactus-maven-1.7dev-20040815.jar";
+
+ assertLayout( path, groupId, artifactId, version, null, type );
+ }
+
+ /**
+ * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
+ */
+ @Test
+ public void testGoodDetectPluginGeronimoPackaging()
+ throws LayoutException
+ {
+ String groupId = "geronimo";
+ String artifactId = "geronimo-packaging-plugin";
+ String version = "1.0.1";
+ String type = "maven-one-plugin";
+ String path = "geronimo/plugins/geronimo-packaging-plugin-1.0.1.jar";
+
+ assertLayout( path, groupId, artifactId, version, null, type );
+ }
+
+ /**
+ * [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
+ {
+ String groupId = "com.sun.tools.xjc.maven2";
+ String artifactId = "maven-jaxb-plugin";
+ String version = "1.1";
+ String type = "maven-plugin";
+ String path = "com.sun.tools.xjc.maven2/maven-plugins/maven-jaxb-plugin-1.1.jar";
+
+ assertLayout( path, groupId, artifactId, version, null, type );
+ }
+
+ /**
+ * Perform a roundtrip through the layout routines to determine success.
+ * @param classifier TODO
+ */
+ private void assertLayout( String path, String groupId, String artifactId, String version, String classifier, String type )
+ throws LayoutException
+ {
+ ArtifactReference expectedArtifact = createArtifact( groupId, artifactId, version, classifier, type );
+
+ // --- Artifact Tests.
+ // Artifact to Path
+ assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( expectedArtifact ) );
+
+ // --- Artifact Reference Tests
+
+ // Path to Artifact Reference.
+ ArtifactReference testReference = toArtifactReference( path );
+ assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
+
+ // And back again, using test Reference from previous step.
+ assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( testReference ) );
+ }
+
+ private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
+ String version, String classifier, String type )
+ {
+ String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + type;
+
+ assertNotNull( expectedId + " - Should not be null.", actualReference );
+
+ assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
+ assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
+ assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
+ assertEquals( expectedId + " - classifier", classifier, actualReference.getClassifier() );
+ assertEquals( expectedId + " - Type", type, actualReference.getType() );
+ }
+
+ protected ArtifactReference createArtifact( String groupId, String artifactId, String version, String classifier, String type )
+ {
+ ArtifactReference artifact = new ArtifactReference();
+ artifact.setGroupId( groupId );
+ artifact.setArtifactId( artifactId );
+ artifact.setVersion( version );
+ artifact.setClassifier( classifier );
+ artifact.setType( type );
+ assertNotNull( artifact );
+ return artifact;
+ }
+
+ private void assertBadPath( String path, String reason )
+ {
+ try
+ {
+ toArtifactReference( path );
+ fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
+ }
+ catch ( LayoutException e )
+ {
+ /* expected path */
+ }
+ }
+
+
+ protected abstract ArtifactReference toArtifactReference( String path )
+ throws LayoutException;
+
+ protected abstract String toPath( ArtifactReference reference );
+
+}
Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractLegacyRepositoryContentTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractLegacyRepositoryContentTestCase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractRepositoryLayerTestCase.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractRepositoryLayerTestCase.java?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractRepositoryLayerTestCase.java (added)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractRepositoryLayerTestCase.java Mon Oct 29 20:42:12 2012
@@ -0,0 +1,101 @@
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.admin.model.beans.ManagedRepository;
+import org.apache.archiva.admin.model.beans.RemoteRepository;
+import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.RemoteRepositoryContent;
+import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+import org.junit.runner.RunWith;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+
+import javax.inject.Inject;
+import java.io.File;
+
+/**
+ * AbstractRepositoryLayerTestCase
+ *
+ *
+ */
+@RunWith( ArchivaSpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
+public abstract class AbstractRepositoryLayerTestCase
+{
+ @Rule
+ public TestName name = new TestName();
+
+ @Inject
+ protected ApplicationContext applicationContext;
+
+ protected ManagedRepository createRepository( String id, String name, File location )
+ {
+ ManagedRepository repo = new ManagedRepository();
+ repo.setId( id );
+ repo.setName( name );
+ repo.setLocation( location.getAbsolutePath() );
+ return repo;
+ }
+
+ protected RemoteRepository createRemoteRepository( String id, String name, String url )
+ {
+ RemoteRepository repo = new RemoteRepository();
+ repo.setId( id );
+ repo.setName( name );
+ repo.setUrl( url );
+ return repo;
+ }
+
+ protected ManagedRepositoryContent createManagedRepositoryContent( String id, String name, File location,
+ String layout )
+ throws Exception
+ {
+ ManagedRepository repo = new ManagedRepository();
+ repo.setId( id );
+ repo.setName( name );
+ repo.setLocation( location.getAbsolutePath() );
+ repo.setLayout( layout );
+
+ ManagedRepositoryContent repoContent =
+ applicationContext.getBean( "managedRepositoryContent#" + layout, ManagedRepositoryContent.class );
+ repoContent.setRepository( repo );
+
+ return repoContent;
+ }
+
+ protected RemoteRepositoryContent createRemoteRepositoryContent( String id, String name, String url, String layout )
+ throws Exception
+ {
+ RemoteRepository repo = new RemoteRepository();
+ repo.setId( id );
+ repo.setName( name );
+ repo.setUrl( url );
+ repo.setLayout( layout );
+
+ RemoteRepositoryContent repoContent =
+ applicationContext.getBean( "remoteRepositoryContent#" + layout, RemoteRepositoryContent.class );
+ repoContent.setRepository( repo );
+
+ return repoContent;
+ }
+}
Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractRepositoryLayerTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractRepositoryLayerTestCase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java (added)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java Mon Oct 29 20:42:12 2012
@@ -0,0 +1,247 @@
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.admin.model.beans.ManagedRepository;
+import org.apache.archiva.common.utils.VersionComparator;
+import org.apache.archiva.configuration.ArchivaConfiguration;
+import org.apache.archiva.configuration.FileType;
+import org.apache.archiva.configuration.FileTypes;
+import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.model.ProjectReference;
+import org.apache.archiva.model.VersionedReference;
+import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.layout.LayoutException;
+import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * ManagedDefaultRepositoryContentTest
+ *
+ *
+ */
+@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
+@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
+public class ManagedDefaultRepositoryContentTest
+ extends AbstractRepositoryLayerTestCase
+{
+ @Inject
+ @Named( value = "managedRepositoryContent#default" )
+ private ManagedRepositoryContent repoContent;
+
+ @Inject
+ FileTypes fileTypes;
+
+ @Inject @Named(value = "archivaConfiguration#default")
+ ArchivaConfiguration archivaConfiguration;
+
+ @Before
+ public void setUp()
+ throws Exception
+ {
+ File repoDir = new File( "src/test/repositories/default-repository" );
+
+ ManagedRepository 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" } );
+ }
+
+ @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" } );
+ }
+
+ @Test
+ public void testToMetadataPathFromProjectReference()
+ {
+ ProjectReference reference = new ProjectReference();
+ reference.setGroupId( "com.foo" );
+ reference.setArtifactId( "foo-tool" );
+
+ assertEquals( "com/foo/foo-tool/maven-metadata.xml", repoContent.toMetadataPath( reference ) );
+ }
+
+ @Test
+ public void testToMetadataPathFromVersionReference()
+ {
+ VersionedReference reference = new VersionedReference();
+ reference.setGroupId( "com.foo" );
+ reference.setArtifactId( "foo-tool" );
+ reference.setVersion( "1.0" );
+
+ assertEquals( "com/foo/foo-tool/1.0/maven-metadata.xml", repoContent.toMetadataPath( reference ) );
+ }
+
+ @Test
+ public void testToPathOnNullArtifactReference()
+ {
+ try
+ {
+ ArtifactReference reference = null;
+ repoContent.toPath( reference );
+ fail( "Should have failed due to null artifact reference." );
+ }
+ catch ( IllegalArgumentException e )
+ {
+ /* expected path */
+ }
+ }
+
+ @Test
+ public void testExcludeMetadataFile()
+ throws Exception
+ {
+ assertVersions( "include_xml", "1.0", new String[]{ "1.0" } );
+ }
+
+ private void assertGetVersions( String artifactId, List<String> expectedVersions )
+ throws Exception
+ {
+ ProjectReference reference = new ProjectReference();
+ reference.setGroupId( "org.apache.archiva.metadata.tests" );
+ reference.setArtifactId( artifactId );
+
+ // Use the test metadata-repository, which is already setup for
+ // These kind of version tests.
+ File repoDir = new File( "src/test/repositories/metadata-repository" );
+ repoContent.getRepository().setLocation( repoDir.getAbsolutePath() );
+
+ // Request the versions.
+ Set<String> testedVersionSet = repoContent.getVersions( reference );
+
+ // Sort the list (for asserts)
+ List<String> testedVersions = new ArrayList<String>();
+ testedVersions.addAll( testedVersionSet );
+ Collections.sort( testedVersions, new VersionComparator() );
+
+ // Test the expected array of versions, to the actual tested versions
+ assertEquals( "available versions", expectedVersions, testedVersions );
+ }
+
+ private void assertVersions( String artifactId, String version, String[] expectedVersions )
+ throws Exception
+ {
+ VersionedReference reference = new VersionedReference();
+ reference.setGroupId( "org.apache.archiva.metadata.tests" );
+ reference.setArtifactId( artifactId );
+ reference.setVersion( version );
+
+ // Use the test metadata-repository, which is already setup for
+ // These kind of version tests.
+ File repoDir = new File( "src/test/repositories/metadata-repository" );
+ repoContent.getRepository().setLocation( repoDir.getAbsolutePath() );
+
+ // Request the versions.
+ Set<String> testedVersionSet = repoContent.getVersions( reference );
+
+ // Sort the list (for asserts later)
+ List<String> testedVersions = new ArrayList<String>();
+ testedVersions.addAll( testedVersionSet );
+ Collections.sort( testedVersions, new VersionComparator() );
+
+ // Test the expected array of versions, to the actual tested versions
+ assertEquals( "Assert Versions: length/size", expectedVersions.length, testedVersions.size() );
+
+ for ( int i = 0; i < expectedVersions.length; i++ )
+ {
+ String actualVersion = testedVersions.get( i );
+ assertEquals( "Versions[" + i + "]", expectedVersions[i], actualVersion );
+ }
+ }
+
+
+ @Override
+ protected ArtifactReference toArtifactReference( String path )
+ throws LayoutException
+ {
+ return repoContent.toArtifactReference( path );
+ }
+
+ @Override
+ protected String toPath( ArtifactReference reference )
+ {
+ return repoContent.toPath( reference );
+ }
+}
Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
|