Broke out metadata handling from BidirectionalRepositoryLayout into recent MetadataTools class. Simplified test cases for default and legacy layout. Test cases now perform round-trip for each example: reference -> path -> reference git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@574120 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-1.0-beta-2
@@ -54,11 +54,11 @@ public class LegacyArtifactExtensionMapping | |||
} | |||
else if ( normalizedName.endsWith( "-sources.jar" ) ) | |||
{ | |||
return "jar"; | |||
return "java-source"; | |||
} | |||
else if ( normalizedName.endsWith( "-javadoc.jar" ) ) | |||
{ | |||
return "jar"; | |||
return "javadoc.jar"; | |||
} | |||
else | |||
{ |
@@ -21,7 +21,6 @@ package org.apache.maven.archiva.repository.layout; | |||
import org.apache.maven.archiva.model.ArchivaArtifact; | |||
import org.apache.maven.archiva.model.ArtifactReference; | |||
import org.apache.maven.archiva.model.ProjectReference; | |||
import org.apache.maven.archiva.model.VersionedReference; | |||
/** | |||
@@ -62,22 +61,6 @@ public interface BidirectionalRepositoryLayout | |||
*/ | |||
public String toPath( ArtifactReference reference ); | |||
/** | |||
* Given an {@link VersionedReference}, return the relative path to that reference. | |||
* | |||
* @param reference the versioned project reference to use. | |||
* @return the relative path to the project reference. | |||
*/ | |||
public String toPath( VersionedReference reference ); | |||
/** | |||
* Given an ProjectReference, return the relative path to that reference. | |||
* | |||
* @param reference the project reference to use. | |||
* @return the relative path to the project reference. | |||
*/ | |||
public String toPath( ProjectReference reference ); | |||
/** | |||
* Given a repository relative path to a filename, return the {@link ArchivaArtifact} object suitable for the path. | |||
* | |||
@@ -89,28 +72,6 @@ public interface BidirectionalRepositoryLayout | |||
public ArchivaArtifact toArtifact( String path ) | |||
throws LayoutException; | |||
/** | |||
* Given a repository relative path to a filename, return the {@link ProjectReference} object suitable for the path. | |||
* | |||
* @param path the path relative to the repository base dir for the artifact. | |||
* @return the {@link ProjectReference} representing the path. (or null if path cannot be converted to | |||
* a {@link ProjectReference}) | |||
* @throws LayoutException if there was a problem converting the path to an artifact. | |||
*/ | |||
public ProjectReference toProjectReference( String path ) | |||
throws LayoutException; | |||
/** | |||
* Given a repository relative path to a filename, return the {@link VersionedReference} object suitable for the path. | |||
* | |||
* @param path the path relative to the repository base dir for the artifact. | |||
* @return the {@link VersionedReference} representing the path. (or null if path cannot be converted to | |||
* a {@link VersionedReference}) | |||
* @throws LayoutException if there was a problem converting the path to an artifact. | |||
*/ | |||
public VersionedReference toVersionedReference( String path ) | |||
throws LayoutException; | |||
/** | |||
* Given a repository relative path to a filename, return the {@link VersionedReference} object suitable for the path. | |||
* |
@@ -23,8 +23,6 @@ import org.apache.commons.lang.StringUtils; | |||
import org.apache.maven.archiva.common.utils.VersionUtil; | |||
import org.apache.maven.archiva.model.ArchivaArtifact; | |||
import org.apache.maven.archiva.model.ArtifactReference; | |||
import org.apache.maven.archiva.model.ProjectReference; | |||
import org.apache.maven.archiva.model.VersionedReference; | |||
import org.apache.maven.archiva.repository.content.DefaultArtifactExtensionMapping; | |||
/** | |||
@@ -37,8 +35,6 @@ import org.apache.maven.archiva.repository.content.DefaultArtifactExtensionMappi | |||
public class DefaultBidirectionalRepositoryLayout | |||
implements BidirectionalRepositoryLayout | |||
{ | |||
private static final String MAVEN_METADATA = "maven-metadata.xml"; | |||
class PathReferences | |||
{ | |||
public String groupId; | |||
@@ -79,7 +75,7 @@ public class DefaultBidirectionalRepositoryLayout | |||
public ArchivaArtifact toArtifact( String path ) | |||
throws LayoutException | |||
{ | |||
PathReferences pathrefs = toPathReferences( path, true ); | |||
PathReferences pathrefs = toPathReferences( path ); | |||
ArchivaArtifact artifact = new ArchivaArtifact( pathrefs.groupId, pathrefs.artifactId, | |||
pathrefs.fileParts.version, pathrefs.fileParts.classifier, | |||
@@ -91,7 +87,7 @@ public class DefaultBidirectionalRepositoryLayout | |||
public ArtifactReference toArtifactReference( String path ) | |||
throws LayoutException | |||
{ | |||
PathReferences pathrefs = toPathReferences( path, true ); | |||
PathReferences pathrefs = toPathReferences( path ); | |||
ArtifactReference reference = new ArtifactReference(); | |||
reference.setGroupId( pathrefs.groupId ); | |||
@@ -105,78 +101,25 @@ public class DefaultBidirectionalRepositoryLayout | |||
public String toPath( ArchivaArtifact artifact ) | |||
{ | |||
return toPath( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact | |||
.getVersion(), artifact.getClassifier(), artifact.getType() ); | |||
} | |||
public String toPath( ArtifactReference reference ) | |||
{ | |||
String baseVersion = VersionUtil.getBaseVersion( reference.getVersion() ); | |||
return toPath( reference.getGroupId(), reference.getArtifactId(), baseVersion, reference.getVersion(), | |||
reference.getClassifier(), reference.getType() ); | |||
} | |||
public String toPath( ProjectReference reference ) | |||
{ | |||
StringBuffer path = new StringBuffer(); | |||
path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR ); | |||
path.append( reference.getArtifactId() ).append( PATH_SEPARATOR ); | |||
path.append( MAVEN_METADATA ); | |||
return path.toString(); | |||
} | |||
public String toPath( VersionedReference reference ) | |||
{ | |||
StringBuffer path = new StringBuffer(); | |||
path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR ); | |||
path.append( reference.getArtifactId() ).append( PATH_SEPARATOR ); | |||
if ( reference.getVersion() != null ) | |||
if ( artifact == null ) | |||
{ | |||
// add the version only if it is present | |||
path.append( VersionUtil.getBaseVersion( reference.getVersion() ) ).append( PATH_SEPARATOR ); | |||
throw new IllegalArgumentException( "Artifact cannot be null" ); | |||
} | |||
path.append( MAVEN_METADATA ); | |||
return path.toString(); | |||
} | |||
public ProjectReference toProjectReference( String path ) | |||
throws LayoutException | |||
{ | |||
if ( !path.endsWith( "/maven-metadata.xml" ) ) | |||
{ | |||
throw new LayoutException( | |||
"Only paths ending in '/maven-metadata.xml' can be " + "converted to a ProjectReference." ); | |||
} | |||
PathReferences pathrefs = toPathReferences( path, false ); | |||
ProjectReference reference = new ProjectReference(); | |||
reference.setGroupId( pathrefs.groupId ); | |||
reference.setArtifactId( pathrefs.artifactId ); | |||
return reference; | |||
return toPath( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact | |||
.getVersion(), artifact.getClassifier(), artifact.getType() ); | |||
} | |||
public VersionedReference toVersionedReference( String path ) | |||
throws LayoutException | |||
public String toPath( ArtifactReference reference ) | |||
{ | |||
if ( !path.endsWith( "/maven-metadata.xml" ) ) | |||
if ( reference == null ) | |||
{ | |||
throw new LayoutException( | |||
"Only paths ending in '/maven-metadata.xml' can be " + "converted to a VersionedReference." ); | |||
throw new IllegalArgumentException( "Artifact reference cannot be null" ); | |||
} | |||
PathReferences pathrefs = toPathReferences( path, false ); | |||
VersionedReference reference = new VersionedReference(); | |||
reference.setGroupId( pathrefs.groupId ); | |||
reference.setArtifactId( pathrefs.artifactId ); | |||
reference.setVersion( pathrefs.baseVersion ); | |||
return reference; | |||
String baseVersion = VersionUtil.getBaseVersion( reference.getVersion() ); | |||
return toPath( reference.getGroupId(), reference.getArtifactId(), baseVersion, reference.getVersion(), | |||
reference.getClassifier(), reference.getType() ); | |||
} | |||
private String formatAsDirectory( String directory ) | |||
@@ -215,7 +158,7 @@ public class DefaultBidirectionalRepositoryLayout | |||
{ | |||
try | |||
{ | |||
toPathReferences( path, false ); | |||
toPathReferences( path ); | |||
return true; | |||
} | |||
catch ( LayoutException e ) | |||
@@ -224,13 +167,17 @@ public class DefaultBidirectionalRepositoryLayout | |||
} | |||
} | |||
private PathReferences toPathReferences( String path, boolean parseFilename ) | |||
private PathReferences toPathReferences( String path ) | |||
throws LayoutException | |||
{ | |||
if ( StringUtils.isBlank( path ) ) | |||
{ | |||
throw new LayoutException( "Unable to convert blank path." ); | |||
} | |||
PathReferences prefs = new PathReferences(); | |||
String normalizedPath = StringUtils.replace( path, "\\", "/" ); | |||
String pathParts[] = StringUtils.split( normalizedPath, '/' ); | |||
/* Minimum parts. | |||
@@ -245,8 +192,8 @@ public class DefaultBidirectionalRepositoryLayout | |||
if ( pathParts.length < 4 ) | |||
{ | |||
// Illegal Path Parts Length. | |||
throw new LayoutException( "Not enough parts to the path [" + path + | |||
"] to construct an ArchivaArtifact from. (Requires at least 4 parts)" ); | |||
throw new LayoutException( "Not enough parts to the path [" + path | |||
+ "] to construct an ArchivaArtifact from. (Requires at least 4 parts)" ); | |||
} | |||
// Maven 2.x path. | |||
@@ -259,17 +206,6 @@ public class DefaultBidirectionalRepositoryLayout | |||
// Second to last is the baseVersion (the directory version) | |||
prefs.baseVersion = pathParts[baseVersionPos]; | |||
if ( "maven-metadata.xml".equals( pathParts[filenamePos] ) ) | |||
{ | |||
if ( !VersionUtil.isVersion( prefs.baseVersion ) ) | |||
{ | |||
// We have a simple path without a version identifier. | |||
prefs.baseVersion = null; | |||
artifactIdPos++; | |||
groupIdPos++; | |||
} | |||
} | |||
// Third to last is the artifact Id. | |||
prefs.artifactId = pathParts[artifactIdPos]; | |||
@@ -287,25 +223,84 @@ public class DefaultBidirectionalRepositoryLayout | |||
// Now we need to parse the filename to get the artifact version Id. | |||
prefs.fileParts = RepositoryLayoutUtils.splitFilename( filename, prefs.artifactId ); | |||
/* If classifier is discovered, see if it deserves to be. | |||
* | |||
* Filenames like "comm-3.0-u1.jar" might be identified as having a version of "3.0" | |||
* and a classifier of "u1". | |||
* | |||
* This routine will take the version + classifier and compare it to the prefs.baseVersion and | |||
* move the classifierensure that | |||
* | |||
* javax/comm/3.0-u1/comm-3.0-u1.jar | |||
*/ | |||
if ( StringUtils.isNotBlank( prefs.fileParts.classifier ) ) | |||
{ | |||
String conjoinedVersion = prefs.fileParts.version + "-" + prefs.fileParts.classifier; | |||
if( StringUtils.equals( prefs.baseVersion, conjoinedVersion ) ) | |||
{ | |||
prefs.fileParts.version = conjoinedVersion; | |||
prefs.fileParts.classifier = null; | |||
} | |||
} | |||
prefs.type = extensionMapper.getType( filename ); | |||
} | |||
catch ( LayoutException e ) | |||
{ | |||
if ( parseFilename ) | |||
{ | |||
throw e; | |||
} | |||
throw e; | |||
} | |||
// Sanity Checks. | |||
if ( prefs.fileParts != null ) | |||
{ | |||
String artifactBaseVersion = VersionUtil.getBaseVersion( prefs.fileParts.version ); | |||
if ( !artifactBaseVersion.equals( prefs.baseVersion ) ) | |||
/* Compare artifact version to path baseversion. | |||
* | |||
* Version naming in the wild can be strange at times. | |||
* Sometimes what is seen as a classifier is actually part of the version id. | |||
* | |||
* To compensate for this, the path is checked against the artifact.version and | |||
* the concatenation of the artifact.version + "-" + artifact.classifier | |||
*/ | |||
String pathVersion = prefs.baseVersion; | |||
String artifactVersion = prefs.fileParts.version; | |||
// Do we have a snapshot version? | |||
if ( VersionUtil.isSnapshot( artifactVersion ) ) | |||
{ | |||
// Rules are different for SNAPSHOTS | |||
if ( !VersionUtil.isGenericSnapshot( pathVersion ) ) | |||
{ | |||
String baseVersion = VersionUtil.getBaseVersion( prefs.fileParts.version ); | |||
throw new LayoutException( "Invalid snapshot artifact location, version directory should be " | |||
+ baseVersion ); | |||
} | |||
} | |||
else | |||
{ | |||
throw new LayoutException( "Invalid artifact location, version directory and filename mismatch." ); | |||
// Non SNAPSHOT rules. | |||
// Do we pass the simple test? | |||
if ( !StringUtils.equals( pathVersion, artifactVersion ) ) | |||
{ | |||
// Do we have a classifier? If so, test the conjoined case. | |||
if ( StringUtils.isNotBlank( prefs.fileParts.classifier ) ) | |||
{ | |||
String artifactLongVersion = artifactVersion + "-" + prefs.fileParts.classifier; | |||
if ( !StringUtils.equals( pathVersion, artifactLongVersion ) ) | |||
{ | |||
throw new LayoutException( "Invalid artifact: version declared in directory path does" | |||
+ " not match what was found in the artifact filename." ); | |||
} | |||
} | |||
else | |||
{ | |||
throw new LayoutException( "Invalid artifact: version declared in directory path does" | |||
+ " not match what was found in the artifact filename." ); | |||
} | |||
} | |||
} | |||
// Test if the artifactId present on the directory path is the same as the artifactId filename. | |||
if ( !prefs.artifactId.equals( prefs.fileParts.artifactId ) ) | |||
{ | |||
throw new LayoutException( "Invalid artifact Id" ); |
@@ -22,8 +22,6 @@ package org.apache.maven.archiva.repository.layout; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.apache.maven.archiva.model.ArchivaArtifact; | |||
import org.apache.maven.archiva.model.ArtifactReference; | |||
import org.apache.maven.archiva.model.ProjectReference; | |||
import org.apache.maven.archiva.model.VersionedReference; | |||
import org.apache.maven.archiva.repository.content.LegacyArtifactExtensionMapping; | |||
import java.util.HashMap; | |||
@@ -39,7 +37,9 @@ import java.util.Map; | |||
public class LegacyBidirectionalRepositoryLayout | |||
implements BidirectionalRepositoryLayout | |||
{ | |||
private static final String MAVEN_METADATA = "maven-metadata.xml"; | |||
private static final String DIR_JAVADOC = "javadoc.jars"; | |||
private static final String DIR_JAVA_SOURCE = "java-sources"; | |||
private static final String PATH_SEPARATOR = "/"; | |||
@@ -62,31 +62,8 @@ public class LegacyBidirectionalRepositoryLayout | |||
public String toPath( ArchivaArtifact artifact ) | |||
{ | |||
return toPath( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getClassifier(), | |||
artifact.getType() ); | |||
} | |||
public String toPath( ProjectReference reference ) | |||
{ | |||
StringBuffer path = new StringBuffer(); | |||
path.append( reference.getGroupId() ).append( PATH_SEPARATOR ); | |||
path.append( getDirectory( null, "jar" ) ).append( PATH_SEPARATOR ); | |||
path.append( MAVEN_METADATA ); | |||
return path.toString(); | |||
} | |||
public String toPath( VersionedReference reference ) | |||
{ | |||
// NOTE: A legacy repository cannot contain a versioned reference to the metadata. | |||
StringBuffer path = new StringBuffer(); | |||
path.append( reference.getGroupId() ).append( PATH_SEPARATOR ); | |||
path.append( getDirectory( null, "jar" ) ).append( PATH_SEPARATOR ); | |||
path.append( MAVEN_METADATA ); | |||
return path.toString(); | |||
return toPath( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), | |||
artifact.getClassifier(), artifact.getType() ); | |||
} | |||
public String toPath( ArtifactReference reference ) | |||
@@ -124,12 +101,12 @@ public class LegacyBidirectionalRepositoryLayout | |||
{ | |||
if ( "sources".equals( classifier ) ) | |||
{ | |||
return "source.jars"; | |||
return DIR_JAVA_SOURCE; | |||
} | |||
if ( "javadoc".equals( classifier ) ) | |||
{ | |||
return "javadoc.jars"; | |||
return DIR_JAVADOC; | |||
} | |||
} | |||
@@ -156,7 +133,7 @@ public class LegacyBidirectionalRepositoryLayout | |||
public FilenameParts fileParts; | |||
} | |||
private PathReferences toPathReferences( String path, boolean parseFilename ) | |||
private PathReferences toPathReferences( String path ) | |||
throws LayoutException | |||
{ | |||
PathReferences prefs = new PathReferences(); | |||
@@ -176,8 +153,8 @@ public class LegacyBidirectionalRepositoryLayout | |||
if ( pathParts.length != 3 ) | |||
{ | |||
// Illegal Path Parts Length. | |||
throw new LayoutException( "Invalid number of parts to the path [" + path + | |||
"] to construct an ArchivaArtifact from. (Required to be 3 parts)" ); | |||
throw new LayoutException( "Invalid number of parts to the path [" + path | |||
+ "] to construct an ArchivaArtifact from. (Required to be 3 parts)" ); | |||
} | |||
// The Group ID. | |||
@@ -186,43 +163,46 @@ public class LegacyBidirectionalRepositoryLayout | |||
// The Expected Type. | |||
prefs.pathType = pathParts[1]; | |||
if ( parseFilename ) | |||
{ | |||
// The Filename. | |||
String filename = pathParts[2]; | |||
// The Filename. | |||
String filename = pathParts[2]; | |||
prefs.fileParts = RepositoryLayoutUtils.splitFilename( filename, null ); | |||
prefs.fileParts = RepositoryLayoutUtils.splitFilename( filename, null ); | |||
prefs.type = extensionMapper.getType( prefs.pathType, filename ); | |||
String trimPathType = prefs.pathType.substring( 0, prefs.pathType.length() - 1 ); | |||
prefs.type = extensionMapper.getType( trimPathType, filename ); | |||
// Sanity Checks. | |||
if ( StringUtils.isEmpty( prefs.fileParts.extension ) ) | |||
{ | |||
throw new LayoutException( "Invalid artifact, no extension." ); | |||
} | |||
// Sanity Check: does it have an extension? | |||
if ( StringUtils.isEmpty( prefs.fileParts.extension ) ) | |||
{ | |||
throw new LayoutException( "Invalid artifact, no extension." ); | |||
} | |||
if ( !prefs.type.equals( prefs.fileParts.extension ) ) | |||
{ | |||
throw new LayoutException( "Invalid artifact, mismatch on extension <" + prefs.fileParts.extension + | |||
"> and expected layout specified type <" + prefs.pathType + "> (mapped type: <" + prefs.type + | |||
">) on path <" + path + ">" ); | |||
} | |||
// Sanity Check: pathType should end in "s". | |||
if ( !prefs.pathType.toLowerCase().endsWith( "s" ) ) | |||
{ | |||
throw new LayoutException( "Invalid path, the type specified in the path <" + prefs.pathType | |||
+ "> does not end in the letter <s>." ); | |||
} | |||
return prefs; | |||
} | |||
// Sanity Check: does extension match pathType on path? | |||
String expectedExtension = extensionMapper.getExtension( trimPathType ); | |||
String actualExtension = prefs.fileParts.extension; | |||
public ProjectReference toProjectReference( String path ) | |||
throws LayoutException | |||
{ | |||
throw new LayoutException( "Cannot parse legacy paths to a Project Reference." ); | |||
if ( !expectedExtension.equals( actualExtension ) ) | |||
{ | |||
throw new LayoutException( "Invalid artifact, mismatch on extension <" + prefs.fileParts.extension | |||
+ "> and layout specified type <" + prefs.pathType + "> (which maps to extension: <" | |||
+ expectedExtension + ">) on path <" + path + ">" ); | |||
} | |||
return prefs; | |||
} | |||
public boolean isValidPath( String path ) | |||
{ | |||
try | |||
{ | |||
toPathReferences( path, false ); | |||
toPathReferences( path ); | |||
return true; | |||
} | |||
catch ( LayoutException e ) | |||
@@ -234,7 +214,7 @@ public class LegacyBidirectionalRepositoryLayout | |||
public ArchivaArtifact toArtifact( String path ) | |||
throws LayoutException | |||
{ | |||
PathReferences pathrefs = toPathReferences( path, true ); | |||
PathReferences pathrefs = toPathReferences( path ); | |||
ArchivaArtifact artifact = new ArchivaArtifact( pathrefs.groupId, pathrefs.fileParts.artifactId, | |||
pathrefs.fileParts.version, pathrefs.fileParts.classifier, | |||
@@ -246,7 +226,7 @@ public class LegacyBidirectionalRepositoryLayout | |||
public ArtifactReference toArtifactReference( String path ) | |||
throws LayoutException | |||
{ | |||
PathReferences pathrefs = toPathReferences( path, true ); | |||
PathReferences pathrefs = toPathReferences( path ); | |||
ArtifactReference reference = new ArtifactReference(); | |||
@@ -258,11 +238,4 @@ public class LegacyBidirectionalRepositoryLayout | |||
return reference; | |||
} | |||
public VersionedReference toVersionedReference( String path ) | |||
throws LayoutException | |||
{ | |||
return null; | |||
} | |||
} |
@@ -141,7 +141,17 @@ public class RepositoryLayoutUtils | |||
if ( versionStart < 0 ) | |||
{ | |||
throw new LayoutException( "Unable to determine version from filename " + filename ); | |||
// Assume rest of string is the version Id. | |||
if ( fileParts.length > 0 ) | |||
{ | |||
versionStart = 0; | |||
versionEnd = fileParts.length; | |||
} | |||
else | |||
{ | |||
throw new LayoutException( "Unable to determine version from filename " + filename ); | |||
} | |||
} | |||
// Gather up the ArtifactID - Version - Classifier pieces found. |
@@ -71,6 +71,12 @@ public class MetadataTools | |||
*/ | |||
private static Logger log = LoggerFactory.getLogger( MetadataTools.class ); | |||
public static final String MAVEN_METADATA = "maven-metadata.xml"; | |||
private static final char PATH_SEPARATOR = '/'; | |||
private static final char GROUP_SEPARATOR = '.'; | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
@@ -90,6 +96,8 @@ public class MetadataTools | |||
private Map<String, Set<String>> proxies; | |||
private static final char NUMS[] = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; | |||
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) | |||
{ | |||
if ( ConfigurationNames.isProxyConnector( propertyName ) ) | |||
@@ -113,8 +121,7 @@ public class MetadataTools | |||
public Set<String> gatherAvailableVersions( ArchivaRepository managedRepository, ProjectReference reference ) | |||
throws LayoutException, IOException | |||
{ | |||
BidirectionalRepositoryLayout layout = layoutFactory.getLayout( managedRepository.getLayoutType() ); | |||
String path = layout.toPath( reference ); | |||
String path = toPath( reference ); | |||
int idx = path.lastIndexOf( '/' ); | |||
if ( idx > 0 ) | |||
@@ -191,7 +198,7 @@ public class MetadataTools | |||
throws LayoutException, IOException | |||
{ | |||
BidirectionalRepositoryLayout layout = layoutFactory.getLayout( managedRepository.getLayoutType() ); | |||
String path = layout.toPath( reference ); | |||
String path = toPath( reference ); | |||
int idx = path.lastIndexOf( '/' ); | |||
if ( idx > 0 ) | |||
@@ -246,7 +253,7 @@ public class MetadataTools | |||
throws LayoutException, IOException | |||
{ | |||
BidirectionalRepositoryLayout layout = layoutFactory.getLayout( managedRepository.getLayoutType() ); | |||
String path = layout.toPath( reference ); | |||
String path = toPath( reference ); | |||
int idx = path.lastIndexOf( '/' ); | |||
if ( idx > 0 ) | |||
@@ -336,6 +343,127 @@ public class MetadataTools | |||
return foundVersions; | |||
} | |||
/** | |||
* Take a path to a maven-metadata.xml, and attempt to translate it to a VersionedReference. | |||
* | |||
* @param path | |||
* @return | |||
*/ | |||
public VersionedReference toVersionedReference( String path ) | |||
throws RepositoryMetadataException | |||
{ | |||
if ( !path.endsWith( "/" + MAVEN_METADATA ) ) | |||
{ | |||
throw new RepositoryMetadataException( "Cannot convert to versioned reference, not a metadata file. " ); | |||
} | |||
VersionedReference reference = new VersionedReference(); | |||
String normalizedPath = StringUtils.replace( path, "\\", "/" ); | |||
String pathParts[] = StringUtils.split( normalizedPath, '/' ); | |||
int versionOffset = pathParts.length - 2; | |||
int artifactIdOffset = versionOffset - 1; | |||
int groupIdEnd = artifactIdOffset - 1; | |||
reference.setVersion( pathParts[versionOffset] ); | |||
if ( !hasNumberAnywhere( reference.getVersion() ) ) | |||
{ | |||
// 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." ); | |||
} | |||
reference.setArtifactId( pathParts[artifactIdOffset] ); | |||
StringBuffer gid = new StringBuffer(); | |||
for ( int i = 0; i <= groupIdEnd; i++ ) | |||
{ | |||
if ( i > 0 ) | |||
{ | |||
gid.append( "." ); | |||
} | |||
gid.append( pathParts[i] ); | |||
} | |||
reference.setGroupId( gid.toString() ); | |||
return reference; | |||
} | |||
private boolean hasNumberAnywhere( String version ) | |||
{ | |||
return StringUtils.indexOfAny( version, NUMS ) != ( -1 ); | |||
} | |||
public ProjectReference toProjectReference( String path ) | |||
throws RepositoryMetadataException | |||
{ | |||
if ( !path.endsWith( "/" + MAVEN_METADATA ) ) | |||
{ | |||
throw new RepositoryMetadataException( "Cannot convert to versioned reference, not a metadata file. " ); | |||
} | |||
ProjectReference reference = new ProjectReference(); | |||
String normalizedPath = StringUtils.replace( path, "\\", "/" ); | |||
String pathParts[] = StringUtils.split( normalizedPath, '/' ); | |||
// Assume last part of the path is the version. | |||
int artifactIdOffset = pathParts.length - 2; | |||
int groupIdEnd = artifactIdOffset - 1; | |||
reference.setArtifactId( pathParts[artifactIdOffset] ); | |||
StringBuffer gid = new StringBuffer(); | |||
for ( int i = 0; i <= groupIdEnd; i++ ) | |||
{ | |||
if ( i > 0 ) | |||
{ | |||
gid.append( "." ); | |||
} | |||
gid.append( pathParts[i] ); | |||
} | |||
reference.setGroupId( gid.toString() ); | |||
return reference; | |||
} | |||
public String toPath( ProjectReference reference ) | |||
{ | |||
StringBuffer path = new StringBuffer(); | |||
path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR ); | |||
path.append( reference.getArtifactId() ).append( PATH_SEPARATOR ); | |||
path.append( MAVEN_METADATA ); | |||
return path.toString(); | |||
} | |||
public String toPath( VersionedReference reference ) | |||
{ | |||
StringBuffer path = new StringBuffer(); | |||
path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR ); | |||
path.append( reference.getArtifactId() ).append( PATH_SEPARATOR ); | |||
if ( reference.getVersion() != null ) | |||
{ | |||
// add the version only if it is present | |||
path.append( VersionUtil.getBaseVersion( reference.getVersion() ) ).append( PATH_SEPARATOR ); | |||
} | |||
path.append( MAVEN_METADATA ); | |||
return path.toString(); | |||
} | |||
private String formatAsDirectory( String directory ) | |||
{ | |||
return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR ); | |||
} | |||
private boolean matchesArtifactPattern( String relativePath ) | |||
{ | |||
Iterator<String> it = this.artifactPatterns.iterator(); | |||
@@ -402,10 +530,8 @@ public class MetadataTools | |||
public ArchivaRepositoryMetadata readProxyMetadata( ArchivaRepository managedRepository, | |||
ProjectReference reference, String proxyId ) | |||
throws LayoutException | |||
{ | |||
BidirectionalRepositoryLayout layout = layoutFactory.getLayout( managedRepository.getLayoutType() ); | |||
String metadataPath = getRepositorySpecificName( proxyId, layout.toPath( reference ) ); | |||
String metadataPath = getRepositorySpecificName( proxyId, toPath( reference ) ); | |||
File metadataFile = new File( managedRepository.getUrl().getPath(), metadataPath ); | |||
try | |||
@@ -423,10 +549,8 @@ public class MetadataTools | |||
public ArchivaRepositoryMetadata readProxyMetadata( ArchivaRepository managedRepository, | |||
VersionedReference reference, String proxyId ) | |||
throws LayoutException | |||
{ | |||
BidirectionalRepositoryLayout layout = layoutFactory.getLayout( managedRepository.getLayoutType() ); | |||
String metadataPath = getRepositorySpecificName( proxyId, layout.toPath( reference ) ); | |||
String metadataPath = getRepositorySpecificName( proxyId, toPath( reference ) ); | |||
File metadataFile = new File( managedRepository.getUrl().getPath(), metadataPath ); | |||
try | |||
@@ -458,8 +582,7 @@ public class MetadataTools | |||
public void updateMetadata( ArchivaRepository managedRepository, ProjectReference reference ) | |||
throws LayoutException, RepositoryMetadataException, IOException | |||
{ | |||
BidirectionalRepositoryLayout layout = layoutFactory.getLayout( managedRepository.getLayoutType() ); | |||
File metadataFile = new File( managedRepository.getUrl().getPath(), layout.toPath( reference ) ); | |||
File metadataFile = new File( managedRepository.getUrl().getPath(), toPath( reference ) ); | |||
ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata(); | |||
metadata.setGroupId( reference.getGroupId() ); | |||
@@ -525,7 +648,7 @@ public class MetadataTools | |||
throws LayoutException, RepositoryMetadataException, IOException | |||
{ | |||
BidirectionalRepositoryLayout layout = layoutFactory.getLayout( managedRepository.getLayoutType() ); | |||
File metadataFile = new File( managedRepository.getUrl().getPath(), layout.toPath( reference ) ); | |||
File metadataFile = new File( managedRepository.getUrl().getPath(), toPath( reference ) ); | |||
ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata(); | |||
metadata.setGroupId( reference.getGroupId() ); |
@@ -81,19 +81,14 @@ public class AbstractBidirectionalRepositoryLayoutTestCase | |||
assertNotNull( expectedId + " - Should not be null.", actualArtifact ); | |||
String expectedType = type; | |||
// Special Case. | |||
if ( "ejb-client".equals( type ) ) | |||
{ | |||
expectedType = "jar"; | |||
} | |||
assertEquals( expectedId + " - Group ID", groupId, actualArtifact.getGroupId() ); | |||
assertEquals( expectedId + " - Artifact ID", artifactId, actualArtifact.getArtifactId() ); | |||
if ( StringUtils.isNotBlank( classifier ) ) | |||
{ | |||
assertEquals( expectedId + " - Classifier", classifier, actualArtifact.getClassifier() ); | |||
} | |||
assertEquals( expectedId + " - Version ID", version, actualArtifact.getVersion() ); | |||
assertEquals( expectedId + " - Classifier", classifier, actualArtifact.getClassifier() ); | |||
assertEquals( expectedId + " - Type", expectedType, actualArtifact.getType() ); | |||
assertEquals( expectedId + " - Type", type, actualArtifact.getType() ); | |||
} | |||
protected void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId, | |||
@@ -104,19 +99,14 @@ public class AbstractBidirectionalRepositoryLayoutTestCase | |||
assertNotNull( expectedId + " - Should not be null.", actualReference ); | |||
String expectedType = type; | |||
// Special Case. | |||
if ( "ejb-client".equals( type ) ) | |||
{ | |||
expectedType = "jar"; | |||
} | |||
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 + " - Classifier", classifier, actualReference.getClassifier() ); | |||
assertEquals( expectedId + " - Type", expectedType, actualReference.getType() ); | |||
assertEquals( expectedId + " - Type", type, actualReference.getType() ); | |||
} | |||
protected void assertVersionedReference( VersionedReference actualReference, String groupId, String artifactId, |
@@ -19,15 +19,8 @@ package org.apache.maven.archiva.repository.layout; | |||
* under the License. | |||
*/ | |||
import org.apache.commons.lang.StringUtils; | |||
import org.apache.maven.archiva.model.ArchivaArtifact; | |||
import org.apache.maven.archiva.model.ArtifactReference; | |||
import org.apache.maven.archiva.model.ProjectReference; | |||
import org.apache.maven.archiva.model.VersionedReference; | |||
import java.util.ArrayList; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
/** | |||
* DefaultBidirectionalRepositoryLayoutTest | |||
@@ -38,479 +31,306 @@ import java.util.List; | |||
public class DefaultBidirectionalRepositoryLayoutTest | |||
extends AbstractBidirectionalRepositoryLayoutTestCase | |||
{ | |||
class LayoutExample | |||
{ | |||
public String groupId; | |||
public String artifactId; | |||
public String version; | |||
public String classifier; | |||
public String type; | |||
public String pathArtifact; | |||
public String pathVersiond; | |||
public String pathProjectd; | |||
public LayoutExample( String groupId, String artifactId, String version, String classifier, String type ) | |||
{ | |||
super(); | |||
this.groupId = groupId; | |||
this.artifactId = artifactId; | |||
this.version = version; | |||
this.classifier = classifier; | |||
this.type = type; | |||
} | |||
public void setDelimitedPath( String delimPath ) | |||
{ | |||
// Silly Test Writer! Don't end the path with a slash! | |||
if ( delimPath.endsWith( "/" ) ) | |||
{ | |||
delimPath = delimPath.substring( 0, delimPath.length() - 1 ); | |||
} | |||
String parts[] = StringUtils.split( delimPath, '|' ); | |||
switch ( parts.length ) | |||
{ | |||
case 3: | |||
this.pathArtifact = parts[0] + "/" + parts[1] + "/" + parts[2]; | |||
case 2: | |||
this.pathVersiond = parts[0] + "/" + parts[1] + "/maven-metadata.xml"; | |||
case 1: | |||
this.pathProjectd = parts[0] + "/maven-metadata.xml"; | |||
break; | |||
default: | |||
fail( "Unknown number of path pieces, expected between 1 and 3, got <" + parts.length + "> on <" | |||
+ delimPath + ">" ); | |||
} | |||
} | |||
public boolean isSuitableForArtifactTest() | |||
{ | |||
return ( this.type != null ) && ( this.classifier != null ) && ( this.version != null ); | |||
} | |||
public boolean isSuitableForVersionedTest() | |||
{ | |||
return ( this.type == null ) && ( this.classifier == null ) && ( this.version != null ); | |||
} | |||
private BidirectionalRepositoryLayout layout; | |||
public boolean isSuitableForProjectTest() | |||
{ | |||
return ( this.type == null ) && ( this.classifier == null ) && ( this.version == null ); | |||
} | |||
public void testBadPathMissingType() | |||
{ | |||
assertBadPath( "invalid/invalid/1/invalid-1", "missing type" ); | |||
} | |||
class InvalidExample | |||
public void testBadPathReleaseInSnapshotDir() | |||
{ | |||
public String path; | |||
public String reason; | |||
public boolean hasFilename; | |||
public InvalidExample( String path, boolean hasFilename, String reason ) | |||
{ | |||
super(); | |||
this.path = path; | |||
this.hasFilename = hasFilename; | |||
this.reason = reason; | |||
} | |||
assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", "non snapshot artifact inside of a snapshot dir" ); | |||
} | |||
private BidirectionalRepositoryLayout layout; | |||
public List /*<LayoutExample>*/getGoodExamples() | |||
public void testBadPathTimestampedSnapshotNotInSnapshotDir() | |||
{ | |||
List ret = new ArrayList(); | |||
LayoutExample example; | |||
// Artifact References | |||
example = new LayoutExample( "com.foo", "foo-tool", "1.0", null, "jar" ); | |||
example.setDelimitedPath( "com/foo/foo-tool|1.0|foo-tool-1.0.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "com.foo", "foo-client", "1.0", null, "ejb-client" ); | |||
example.setDelimitedPath( "com/foo/foo-client|1.0|foo-client-1.0.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "com.foo.lib", "foo-lib", "2.1-alpha-1", "sources", "java-source" ); | |||
example.setDelimitedPath( "com/foo/lib/foo-lib|2.1-alpha-1|foo-lib-2.1-alpha-1-sources.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "com.foo", "foo-connector", "2.1-20060822.123456-35", null, "jar" ); | |||
example.setDelimitedPath( "com/foo/foo-connector/2.1-SNAPSHOT/foo-connector-2.1-20060822.123456-35.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "org.apache.maven.test", "get-metadata-snapshot", "1.0-20050831.101112-1", null, | |||
"jar" ); | |||
example | |||
.setDelimitedPath( "org/apache/maven/test/get-metadata-snapshot|1.0-SNAPSHOT|get-metadata-snapshot-1.0-20050831.101112-1.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "commons-lang", "commons-lang", "2.1", null, "jar" ); | |||
example.setDelimitedPath( "commons-lang/commons-lang|2.1|commons-lang-2.1.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "com.foo", "foo-tool", "1.0", null, "jar" ); | |||
example.setDelimitedPath( "com/foo/foo-tool|1.0|foo-tool-1.0.jar" ); | |||
ret.add( example ); | |||
// Versioned References (done here by setting classifier and type to null) | |||
example = new LayoutExample( "com.foo", "foo-tool", "1.0", null, null ); | |||
example.setDelimitedPath( "com/foo/foo-tool|1.0" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "net.i.have.a.really.long.path.just.for.the.hell.of.it", "a", "1.1-alpha-1", null, | |||
null ); | |||
example.setDelimitedPath( "net/i/have/a/really/long/path/just/for/the/hell/of/it/a|1.1-alpha-1" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "com.foo", "foo-connector", "2.1-20060822.123456-35", null, null ); | |||
example.setDelimitedPath( "com/foo/foo-connector|2.1-SNAPSHOT" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "com.foo", "foo-connector", "2.1-SNAPSHOT", null, null ); | |||
example.setDelimitedPath( "com/foo/foo-connector|2.1-SNAPSHOT" ); | |||
ret.add( example ); | |||
// Project References (done here by setting version, classifier, and type to null) | |||
example = new LayoutExample( "com.foo", "foo-tool", null, null, null ); | |||
example.setDelimitedPath( "com/foo/foo-tool/" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "net.i.have.a.really.long.path.just.for.the.hell.of.it", "a", null, null, null ); | |||
example.setDelimitedPath( "net/i/have/a/really/long/path/just/for/the/hell/of/it/a/" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "com.foo", "foo-connector", null, null, null ); | |||
example.setDelimitedPath( "com/foo/foo-connector" ); | |||
ret.add( example ); | |||
return ret; | |||
assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar", | |||
"Timestamped Snapshot artifact not inside of an Snapshot dir" ); | |||
} | |||
public List /*<InvalidExample>*/getInvalidPaths() | |||
public void testBadPathTooShort() | |||
{ | |||
List ret = new ArrayList(); | |||
InvalidExample example; | |||
example = new InvalidExample( "invalid/invalid/1/invalid-1", false, "missing type" ); | |||
ret.add( example ); | |||
example = new InvalidExample( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", true, | |||
"non snapshot artifact inside of a snapshot dir" ); | |||
ret.add( example ); | |||
example = new InvalidExample( "invalid/invalid-1.0.jar", true, "path is too short" ); | |||
ret.add( example ); | |||
example = new InvalidExample( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar", true, | |||
"Timestamped Snapshot artifact not inside of an Snapshot dir" ); | |||
ret.add( example ); | |||
assertBadPath( "invalid/invalid-1.0.jar", "path is too short" ); | |||
} | |||
example = new InvalidExample( "invalid/invalid/1.0/invalid-2.0.jar", true, | |||
"version mismatch between path and artifact" ); | |||
ret.add( example ); | |||
public void testBadPathVersionMismatchA() | |||
{ | |||
assertBadPath( "invalid/invalid/1.0/invalid-2.0.jar", "version mismatch between path and artifact" ); | |||
} | |||
example = new InvalidExample( "invalid/invalid/1.0/invalid-1.0b.jar", true, | |||
"version mismatch between path and artifact" ); | |||
ret.add( example ); | |||
public void testBadPathVersionMismatchB() | |||
{ | |||
assertBadPath( "invalid/invalid/1.0/invalid-1.0b.jar", "version mismatch between path and artifact" ); | |||
} | |||
example = new InvalidExample( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar", | |||
true, "wrong artifact id" ); | |||
public void testBadPathWrongArtifactId() | |||
{ | |||
assertBadPath( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar", | |||
"wrong artifact id" ); | |||
} | |||
return ret; | |||
/** | |||
* [MRM-432] Oddball version spec. | |||
* Example of an oddball / unusual version spec. | |||
* @throws LayoutException | |||
*/ | |||
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 ); | |||
} | |||
public void testArtifactToPath() | |||
/** | |||
* [MRM-432] Oddball version spec. | |||
* Example of an oddball / unusual version spec. | |||
* @throws LayoutException | |||
*/ | |||
public void testGoodButOddVersionSpecJavaxComm() | |||
throws LayoutException | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForArtifactTest() ) | |||
{ | |||
ArchivaArtifact artifact = createArtifact( example.groupId, example.artifactId, example.version, | |||
example.classifier, example.type ); | |||
assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, layout.toPath( artifact ) ); | |||
} | |||
} | |||
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 ); | |||
} | |||
public void testArtifactReferenceToPath() | |||
/** | |||
* [MRM-432] Oddball version spec. | |||
* Example of an oddball / unusual version spec. | |||
* @throws LayoutException | |||
*/ | |||
public void testGoodButOddVersionSpecJavaxPersistence() | |||
throws LayoutException | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForArtifactTest() ) | |||
{ | |||
ArtifactReference reference = new ArtifactReference(); | |||
reference.setGroupId( example.groupId ); | |||
reference.setArtifactId( example.artifactId ); | |||
reference.setVersion( example.version ); | |||
reference.setClassifier( example.classifier ); | |||
reference.setType( example.type ); | |||
assertEquals( "ArtifactReference <" + reference + "> to path:", example.pathArtifact, layout | |||
.toPath( reference ) ); | |||
} | |||
} | |||
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 ); | |||
} | |||
public void testVersionedReferenceToPath() | |||
public void testGoodComFooTool() | |||
throws LayoutException | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForVersionedTest() || example.isSuitableForArtifactTest() ) | |||
{ | |||
VersionedReference reference = new VersionedReference(); | |||
reference.setGroupId( example.groupId ); | |||
reference.setArtifactId( example.artifactId ); | |||
reference.setVersion( example.version ); | |||
assertEquals( "VersionedReference <" + reference + "> to path:", example.pathVersiond, layout | |||
.toPath( reference ) ); | |||
} | |||
} | |||
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 ); | |||
} | |||
public void testProjectReferenceToPath() | |||
public void testGoodCommonsLang() | |||
throws LayoutException | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForProjectTest() || example.isSuitableForVersionedTest() | |||
|| example.isSuitableForArtifactTest() ) | |||
{ | |||
ProjectReference reference = new ProjectReference(); | |||
reference.setGroupId( example.groupId ); | |||
reference.setArtifactId( example.artifactId ); | |||
assertEquals( "ProjectReference <" + reference + "> to path:", example.pathProjectd, layout | |||
.toPath( reference ) ); | |||
} | |||
} | |||
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 ); | |||
} | |||
public void testInvalidPathToArtifact() | |||
/** | |||
* Test the ejb-client type spec. | |||
* Type specs are not a 1 to 1 map to the extension. | |||
* This tests that effect. | |||
* @throws LayoutException | |||
*/ | |||
public void testGoodFooEjbClient() | |||
throws LayoutException | |||
{ | |||
Iterator it = getInvalidPaths().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
InvalidExample example = (InvalidExample) it.next(); | |||
try | |||
{ | |||
layout.toArtifact( example.path ); | |||
fail( "Should have thrown a LayoutException on the invalid path [" + example.path + "] because of [" | |||
+ example.reason + "]" ); | |||
} | |||
catch ( LayoutException e ) | |||
{ | |||
/* expected path */ | |||
} | |||
} | |||
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 ); | |||
} | |||
public void testInvalidPathToArtifactReference() | |||
/** | |||
* Test the classifier, and java-source type spec. | |||
* @throws LayoutException | |||
*/ | |||
public void testGoodFooLibSources() | |||
throws LayoutException | |||
{ | |||
Iterator it = getInvalidPaths().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
InvalidExample example = (InvalidExample) it.next(); | |||
try | |||
{ | |||
layout.toArtifactReference( example.path ); | |||
fail( "Should have thrown a LayoutException on the invalid path [" + example.path + "] because of [" | |||
+ example.reason + "]" ); | |||
} | |||
catch ( LayoutException e ) | |||
{ | |||
/* expected path */ | |||
} | |||
} | |||
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 ); | |||
} | |||
public void testInvalidPathToVersionedReference() | |||
/** | |||
* A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory. | |||
* @throws LayoutException | |||
*/ | |||
public void testGoodSnapshotMavenTest() | |||
throws LayoutException | |||
{ | |||
Iterator it = getInvalidPaths().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
InvalidExample example = (InvalidExample) it.next(); | |||
try | |||
{ | |||
layout.toVersionedReference( example.path ); | |||
if ( example.hasFilename ) | |||
{ | |||
fail( "Should have thrown a LayoutException on the invalid path [" + example.path | |||
+ "] because of [" + example.reason + "]" ); | |||
} | |||
} | |||
catch ( LayoutException e ) | |||
{ | |||
/* expected path */ | |||
} | |||
} | |||
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 ); | |||
} | |||
public void testInvalidPathToProjectReference() | |||
public void testToArtifactOnEmptyPath() | |||
{ | |||
Iterator it = getInvalidPaths().iterator(); | |||
while ( it.hasNext() ) | |||
try | |||
{ | |||
layout.toArtifact( "" ); | |||
fail( "Should have failed due to empty path." ); | |||
} | |||
catch ( LayoutException e ) | |||
{ | |||
InvalidExample example = (InvalidExample) it.next(); | |||
try | |||
{ | |||
layout.toProjectReference( example.path ); | |||
if ( example.hasFilename ) | |||
{ | |||
fail( "Should have thrown a LayoutException on the invalid path [" + example.path | |||
+ "] because of [" + example.reason + "]" ); | |||
} | |||
} | |||
catch ( LayoutException e ) | |||
{ | |||
/* expected path */ | |||
} | |||
/* expected path */ | |||
} | |||
} | |||
public void testPathToArtifact() | |||
throws LayoutException | |||
public void testToArtifactOnNullPath() | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
try | |||
{ | |||
layout.toArtifact( null ); | |||
fail( "Should have failed due to null path." ); | |||
} | |||
catch ( LayoutException e ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForArtifactTest() ) | |||
{ | |||
ArchivaArtifact artifact = layout.toArtifact( example.pathArtifact ); | |||
assertArtifact( artifact, example.groupId, example.artifactId, example.version, example.classifier, | |||
example.type ); | |||
} | |||
/* expected path */ | |||
} | |||
} | |||
public void testPathToArtifactReference() | |||
throws LayoutException | |||
public void testToArtifactReferenceOnEmptyPath() | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
try | |||
{ | |||
layout.toArtifactReference( "" ); | |||
fail( "Should have failed due to empty path." ); | |||
} | |||
catch ( LayoutException e ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForArtifactTest() ) | |||
{ | |||
ArtifactReference reference = layout.toArtifactReference( example.pathArtifact ); | |||
assertArtifactReference( reference, example.groupId, example.artifactId, example.version, | |||
example.classifier, example.type ); | |||
} | |||
/* expected path */ | |||
} | |||
} | |||
public void testPathToVersionedReference() | |||
throws LayoutException | |||
public void testToArtifactReferenceOnNullPath() | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
try | |||
{ | |||
layout.toArtifactReference( null ); | |||
fail( "Should have failed due to null path." ); | |||
} | |||
catch ( LayoutException e ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForVersionedTest() ) | |||
{ | |||
VersionedReference reference = layout.toVersionedReference( example.pathVersiond ); | |||
String baseVersion = reference.getVersion(); | |||
assertVersionedReference( reference, example.groupId, example.artifactId, baseVersion ); | |||
} | |||
/* expected path */ | |||
} | |||
} | |||
public void testPathToProjectReference() | |||
throws LayoutException | |||
public void testToPathOnNullArtifactReference() | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
try | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForProjectTest() ) | |||
{ | |||
ProjectReference reference = layout.toProjectReference( example.pathProjectd ); | |||
assertProjectReference( reference, example.groupId, example.artifactId ); | |||
} | |||
ArtifactReference reference = null; | |||
layout.toPath( reference ); | |||
fail( "Should have failed due to null artifact reference." ); | |||
} | |||
catch ( IllegalArgumentException e ) | |||
{ | |||
/* expected path */ | |||
} | |||
} | |||
public void testRoundtripArtifactToPathToArtifact() | |||
throws LayoutException | |||
public void testToPathOnNullArtifact() | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
try | |||
{ | |||
ArchivaArtifact artifact = null; | |||
layout.toPath( artifact ); | |||
fail( "Should have failed due to null artifact." ); | |||
} | |||
catch ( IllegalArgumentException e ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForArtifactTest() ) | |||
{ | |||
ArchivaArtifact artifact = createArtifact( example.groupId, example.artifactId, example.version, | |||
example.classifier, example.type ); | |||
String testPath = layout.toPath( artifact ); | |||
assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, testPath ); | |||
ArchivaArtifact testArtifact = layout.toArtifact( testPath ); | |||
assertArtifact( testArtifact, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), | |||
artifact.getClassifier(), artifact.getType() ); | |||
} | |||
/* expected path */ | |||
} | |||
} | |||
public void testRoundtripPathToArtifactToPath() | |||
throws LayoutException | |||
protected void assertBadPath( String path, String reason ) | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
try | |||
{ | |||
layout.toArtifact( path ); | |||
fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" ); | |||
} | |||
catch ( LayoutException e ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForArtifactTest() ) | |||
{ | |||
ArchivaArtifact artifact = layout.toArtifact( example.pathArtifact ); | |||
assertArtifact( artifact, example.groupId, example.artifactId, example.version, example.classifier, | |||
example.type ); | |||
String testPath = layout.toPath( artifact ); | |||
assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, testPath ); | |||
} | |||
/* expected path */ | |||
} | |||
} | |||
public void testTimestampedSnapshotRoundtrip() | |||
/** | |||
* 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 | |||
{ | |||
String originalPath = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar"; | |||
ArchivaArtifact artifact = layout.toArtifact( originalPath ); | |||
assertArtifact( artifact, "org.apache.maven.test", "get-metadata-snapshot", "1.0-20050831.101112-1", "", "jar" ); | |||
ArchivaArtifact expectedArtifact = createArtifact( groupId, artifactId, version, classifier, type ); | |||
// --- Artifact Tests. | |||
// Artifact to Path | |||
assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( expectedArtifact ) ); | |||
// Path to Artifact. | |||
ArchivaArtifact testArtifact = layout.toArtifact( path ); | |||
assertArtifact( testArtifact, groupId, artifactId, version, classifier, type ); | |||
// And back again, using test Artifact from previous step. | |||
assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( testArtifact ) ); | |||
assertEquals( originalPath, layout.toPath( artifact ) ); | |||
// --- Artifact Reference Tests | |||
ArtifactReference aref = new ArtifactReference(); | |||
aref.setGroupId( artifact.getGroupId() ); | |||
aref.setArtifactId( artifact.getArtifactId() ); | |||
aref.setVersion( artifact.getVersion() ); | |||
aref.setClassifier( artifact.getClassifier() ); | |||
aref.setType( artifact.getType() ); | |||
// Path to Artifact Reference. | |||
ArtifactReference testReference = layout.toArtifactReference( path ); | |||
assertArtifactReference( testReference, groupId, artifactId, version, classifier, type ); | |||
assertEquals( originalPath, layout.toPath( aref ) ); | |||
// And back again, using test Reference from previous step. | |||
assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( testReference ) ); | |||
} | |||
protected void setUp() |
@@ -19,15 +19,8 @@ package org.apache.maven.archiva.repository.layout; | |||
* under the License. | |||
*/ | |||
import org.apache.commons.lang.StringUtils; | |||
import org.apache.maven.archiva.model.ArchivaArtifact; | |||
import org.apache.maven.archiva.model.ArtifactReference; | |||
import org.apache.maven.archiva.model.ProjectReference; | |||
import org.apache.maven.archiva.model.VersionedReference; | |||
import java.util.ArrayList; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
/** | |||
* LegacyBidirectionalRepositoryLayoutTest | |||
@@ -38,474 +31,279 @@ import java.util.List; | |||
public class LegacyBidirectionalRepositoryLayoutTest | |||
extends AbstractBidirectionalRepositoryLayoutTestCase | |||
{ | |||
class LayoutExample | |||
{ | |||
public String groupId; | |||
public String artifactId; | |||
public String version; | |||
public String classifier; | |||
public String type; | |||
public String pathArtifact; | |||
public String pathVersiond; | |||
public String pathProjectd; | |||
public LayoutExample( String groupId, String artifactId, String version, String classifier, String type ) | |||
{ | |||
super(); | |||
this.groupId = groupId; | |||
this.artifactId = artifactId; | |||
this.version = version; | |||
this.classifier = classifier; | |||
this.type = type; | |||
} | |||
public void setDelimitedPath( String delimPath ) | |||
{ | |||
// Silly Test Writer! Don't end the path with a slash! | |||
if ( delimPath.endsWith( "/" ) ) | |||
{ | |||
delimPath = delimPath.substring( 0, delimPath.length() - 1 ); | |||
} | |||
String parts[] = StringUtils.split( delimPath, '|' ); | |||
switch ( parts.length ) | |||
{ | |||
case 3: | |||
this.pathArtifact = parts[0] + "/" + parts[1] + "/" + parts[2]; | |||
case 2: | |||
this.pathVersiond = parts[0] + "/jars/maven-metadata.xml"; | |||
case 1: | |||
this.pathProjectd = parts[0] + "/jars/maven-metadata.xml"; | |||
break; | |||
default: | |||
fail( "Unknown number of path pieces, expected between 1 and 3, got <" + parts.length + "> on <" | |||
+ delimPath + ">" ); | |||
} | |||
} | |||
public boolean isSuitableForArtifactTest() | |||
{ | |||
return ( this.type != null ) && ( this.classifier != null ) && ( this.version != null ); | |||
} | |||
public boolean isSuitableForVersionedTest() | |||
{ | |||
return ( this.type == null ) && ( this.classifier == null ) && ( this.version != null ); | |||
} | |||
private BidirectionalRepositoryLayout layout; | |||
public boolean isSuitableForProjectTest() | |||
{ | |||
return ( this.type == null ) && ( this.classifier == null ) && ( this.version == null ); | |||
} | |||
public void testBadPathArtifactIdMissingA() | |||
{ | |||
assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" ); | |||
} | |||
class InvalidExample | |||
public void testBadPathArtifactIdMissingB() | |||
{ | |||
public String path; | |||
public String reason; | |||
public boolean suitableForArtifactTests = true; | |||
public boolean suitableForVersionedTests = false; | |||
public boolean suitableForProjectTests = false; | |||
public InvalidExample( String path, String reason ) | |||
{ | |||
super(); | |||
this.path = path; | |||
this.reason = reason; | |||
} | |||
assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" ); | |||
} | |||
private BidirectionalRepositoryLayout layout; | |||
protected void setUp() | |||
throws Exception | |||
public void testBadPathMissingType() | |||
{ | |||
super.setUp(); | |||
layout = (BidirectionalRepositoryLayout) lookup( BidirectionalRepositoryLayout.class.getName(), "legacy" ); | |||
assertBadPath( "invalid/invalid/1/invalid-1", "missing type" ); | |||
} | |||
public List /*<LayoutExample>*/getGoodExamples() | |||
public void testBadPathTooShort() | |||
{ | |||
List ret = new ArrayList(); | |||
LayoutExample example; | |||
// Artifact References | |||
example = new LayoutExample( "com.foo", "foo-tool", "1.0", null, "jar" ); | |||
example.setDelimitedPath( "com.foo|jars|foo-tool-1.0.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "com.foo", "foo-client", "1.0", null, "ejb-client" ); | |||
example.setDelimitedPath( "com.foo|ejbs|foo-client-1.0.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "com.foo.lib", "foo-lib", "2.1-alpha-1", "sources", "jar" ); | |||
example.setDelimitedPath( "com.foo.lib|source.jars|foo-lib-2.1-alpha-1-sources.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "com.foo.lib", "foo-lib", "2.1-alpha-1", "javadoc", "jar" ); | |||
example.setDelimitedPath( "com.foo.lib|javadoc.jars|foo-lib-2.1-alpha-1-javadoc.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "com.foo", "foo-connector", "2.1-20060822.123456-35", null, "jar" ); | |||
example.setDelimitedPath( "com.foo|jars|foo-connector-2.1-20060822.123456-35.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "org.apache.maven.test", "get-metadata-snapshot", "1.0-20050831.101112-1", null, | |||
"jar" ); | |||
example.setDelimitedPath( "org.apache.maven.test|jars|get-metadata-snapshot-1.0-20050831.101112-1.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "commons-lang", "commons-lang", "2.1", null, "jar" ); | |||
example.setDelimitedPath( "commons-lang|jars|commons-lang-2.1.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "org.apache.derby", "derby", "10.2.2.0", null, "jar" ); | |||
example.setDelimitedPath( "org.apache.derby|jars|derby-10.2.2.0.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "org.apache.geronimo.specs", "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" ); | |||
example.setDelimitedPath( "org.apache.geronimo.specs|jars|geronimo-ejb_2.1_spec-1.0.1.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "org.apache.beehive", "beehive-ejb-control", "1.0.1", null, "jar" ); | |||
example.setDelimitedPath( "org.apache.beehive|jars|beehive-ejb-control-1.0.1.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "commons-lang", "commons-lang", "2.3", "sources", "jar" ); | |||
example.setDelimitedPath( "commons-lang|source.jars|commons-lang-2.3-sources.jar" ); | |||
ret.add( example ); | |||
example = new LayoutExample( "directory-clients", "ldap-clients", "0.9.1-SNAPSHOT", null, "pom" ); | |||
example.setDelimitedPath( "directory-clients|poms|ldap-clients-0.9.1-SNAPSHOT.pom" ); | |||
ret.add( example ); | |||
// Versioned References (done here by setting classifier and type to null) | |||
// TODO: Not sure how to represent a VersionedReference as a legacy path. | |||
// Project References (done here by setting version, classifier, and type to null) | |||
// TODO: Not sure how to represent a ProjectReference as a legacy path. | |||
// NEW | |||
assertBadPath( "invalid/invalid-1.0.jar", "path is too short" ); | |||
} | |||
return ret; | |||
public void testBadPathWrongPackageExtension() | |||
{ | |||
assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" ); | |||
} | |||
public List /*<InvalidExample>*/getInvalidPaths() | |||
/** | |||
* [MRM-432] Oddball version spec. | |||
* Example of an oddball / unusual version spec. | |||
* @throws LayoutException | |||
*/ | |||
/* TODO: MRM-432 - Needs to be fixed | |||
public void testGoodButOddVersionSpecGanymedSsh2() | |||
throws LayoutException | |||
{ | |||
List ret = new ArrayList(); | |||
InvalidExample example; | |||
example = new InvalidExample( "invalid/invalid/1/invalid-1", "missing type" ); | |||
example.suitableForArtifactTests = true; | |||
example.suitableForVersionedTests = false; | |||
example.suitableForProjectTests = true; | |||
ret.add( example ); | |||
example = new InvalidExample( "org.apache.maven.test/jars/artifactId-1.0.jar.md5", "wrong package extension" ); | |||
example.suitableForArtifactTests = true; | |||
example.suitableForVersionedTests = false; | |||
example.suitableForProjectTests = false; | |||
ret.add( example ); | |||
example = new InvalidExample( "groupId/jars/-1.0.jar", "artifactId is missing" ); | |||
example.suitableForArtifactTests = true; | |||
example.suitableForVersionedTests = false; | |||
example.suitableForProjectTests = true; | |||
ret.add( example ); | |||
example = new InvalidExample( "groupId/jars/1.0.jar", "artifactId is missing" ); | |||
example.suitableForArtifactTests = true; | |||
example.suitableForVersionedTests = false; | |||
example.suitableForProjectTests = true; | |||
ret.add( example ); | |||
return ret; | |||
String groupId = "ch.ethz.ganymed"; | |||
String artifactId = "ganymed-ssh2"; | |||
String version = "build210"; | |||
String classifier = null; | |||
String type = "jar"; | |||
String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar"; | |||
assertLayout( path, groupId, artifactId, version, classifier, type ); | |||
} | |||
public void testArtifactToPath() | |||
*/ | |||
/** | |||
* [MRM-432] Oddball version spec. | |||
* Example of an oddball / unusual version spec. | |||
* @throws LayoutException | |||
*/ | |||
public void testGoodButOddVersionSpecJavaxComm() | |||
throws LayoutException | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForArtifactTest() ) | |||
{ | |||
ArchivaArtifact artifact = createArtifact( example.groupId, example.artifactId, example.version, | |||
example.classifier, example.type ); | |||
assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, layout.toPath( artifact ) ); | |||
} | |||
} | |||
String groupId = "javax"; | |||
String artifactId = "comm"; | |||
String version = "3.0-u1"; | |||
String classifier = null; | |||
String type = "jar"; | |||
String path = "javax/jars/comm-3.0-u1.jar"; | |||
assertLayout( path, groupId, artifactId, version, classifier, type ); | |||
} | |||
public void testArtifactReferenceToPath() | |||
/** | |||
* [MRM-432] Oddball version spec. | |||
* Example of an oddball / unusual version spec. | |||
* @throws LayoutException | |||
*/ | |||
public void testGoodButOddVersionSpecJavaxPersistence() | |||
throws LayoutException | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForArtifactTest() ) | |||
{ | |||
ArtifactReference reference = new ArtifactReference(); | |||
reference.setGroupId( example.groupId ); | |||
reference.setArtifactId( example.artifactId ); | |||
reference.setVersion( example.version ); | |||
reference.setClassifier( example.classifier ); | |||
reference.setType( example.type ); | |||
assertEquals( "ArtifactReference <" + reference + "> to path:", example.pathArtifact, layout | |||
.toPath( reference ) ); | |||
} | |||
} | |||
String groupId = "javax.persistence"; | |||
String artifactId = "ejb"; | |||
String version = "3.0-public_review"; | |||
String classifier = null; | |||
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, classifier, type ); | |||
} | |||
public void testVersionedReferenceToPath() | |||
public void testGoodCommonsLang() | |||
throws LayoutException | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForVersionedTest() || example.isSuitableForArtifactTest() ) | |||
{ | |||
VersionedReference reference = new VersionedReference(); | |||
reference.setGroupId( example.groupId ); | |||
reference.setArtifactId( example.artifactId ); | |||
reference.setVersion( example.version ); | |||
assertEquals( "VersionedReference <" + reference + "> to path:", example.pathVersiond, layout | |||
.toPath( reference ) ); | |||
} | |||
} | |||
String groupId = "commons-lang"; | |||
String artifactId = "commons-lang"; | |||
String version = "2.1"; | |||
String classifier = null; | |||
String type = "jar"; | |||
String path = "commons-lang/jars/commons-lang-2.1.jar"; | |||
assertLayout( path, groupId, artifactId, version, classifier, type ); | |||
} | |||
public void testProjectReferenceToPath() | |||
public void testGoodDerby() | |||
throws LayoutException | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForProjectTest() || example.isSuitableForVersionedTest() | |||
|| example.isSuitableForArtifactTest() ) | |||
{ | |||
ProjectReference reference = new ProjectReference(); | |||
reference.setGroupId( example.groupId ); | |||
reference.setArtifactId( example.artifactId ); | |||
assertEquals( "ProjectReference <" + reference + "> to path:", example.pathProjectd, layout | |||
.toPath( reference ) ); | |||
} | |||
} | |||
String groupId = "org.apache.derby"; | |||
String artifactId = "derby"; | |||
String version = "10.2.2.0"; | |||
String classifier = null; | |||
String type = "jar"; | |||
String path = "org.apache.derby/jars/derby-10.2.2.0.jar"; | |||
assertLayout( path, groupId, artifactId, version, classifier, type ); | |||
} | |||
public void testInvalidPathToArtifact() | |||
/** | |||
* Test the ejb-client type spec. | |||
* Type specs are not a 1 to 1 map to the extension. | |||
* This tests that effect. | |||
* @throws LayoutException | |||
*/ | |||
public void testGoodFooEjbClient() | |||
throws LayoutException | |||
{ | |||
Iterator it = getInvalidPaths().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
InvalidExample example = (InvalidExample) it.next(); | |||
try | |||
{ | |||
layout.toArtifact( example.path ); | |||
fail( "Should have thrown a LayoutException on the invalid path [" + example.path + "] because of [" | |||
+ example.reason + "]" ); | |||
} | |||
catch ( LayoutException e ) | |||
{ | |||
/* expected path */ | |||
} | |||
} | |||
String groupId = "com.foo"; | |||
String artifactId = "foo-client"; | |||
String version = "1.0"; | |||
String classifier = null; | |||
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 ); | |||
} | |||
public void testInvalidPathToArtifactReference() | |||
/** | |||
* Test the classifier. | |||
* @throws LayoutException | |||
*/ | |||
public void testGoodFooLibJavadoc() | |||
throws LayoutException | |||
{ | |||
Iterator it = getInvalidPaths().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
InvalidExample example = (InvalidExample) it.next(); | |||
if( !example.suitableForArtifactTests ) | |||
{ | |||
continue; | |||
} | |||
try | |||
{ | |||
layout.toArtifactReference( example.path ); | |||
fail( "Should have thrown a LayoutException on the invalid path [" + example.path + "] because of [" | |||
+ example.reason + "]" ); | |||
} | |||
catch ( LayoutException e ) | |||
{ | |||
/* expected path */ | |||
} | |||
} | |||
String groupId = "com.foo.lib"; | |||
String artifactId = "foo-lib"; | |||
String version = "2.1-alpha-1"; | |||
String classifier = "javadoc"; | |||
String type = "javadoc.jar"; | |||
String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar"; | |||
assertLayout( path, groupId, artifactId, version, classifier, type ); | |||
} | |||
public void testInvalidPathToVersionedReference() | |||
/** | |||
* Test the classifier, and java-source type spec. | |||
* @throws LayoutException | |||
*/ | |||
public void testGoodFooLibSources() | |||
throws LayoutException | |||
{ | |||
Iterator it = getInvalidPaths().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
InvalidExample example = (InvalidExample) it.next(); | |||
if( !example.suitableForVersionedTests ) | |||
{ | |||
continue; | |||
} | |||
try | |||
{ | |||
layout.toVersionedReference( example.path ); | |||
fail( "Should have thrown a LayoutException on the invalid path [" + example.path | |||
+ "] because of [" + example.reason + "]" ); | |||
} | |||
catch ( LayoutException e ) | |||
{ | |||
/* expected path */ | |||
} | |||
} | |||
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/java-sources/foo-lib-2.1-alpha-1-sources.jar"; | |||
assertLayout( path, groupId, artifactId, version, classifier, type ); | |||
} | |||
public void testInvalidPathToProjectReference() | |||
public void testGoodFooTool() | |||
throws LayoutException | |||
{ | |||
Iterator it = getInvalidPaths().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
InvalidExample example = (InvalidExample) it.next(); | |||
if( !example.suitableForProjectTests ) | |||
{ | |||
continue; | |||
} | |||
try | |||
{ | |||
layout.toProjectReference( example.path ); | |||
fail( "Should have thrown a LayoutException on the invalid path [" + example.path | |||
+ "] because of [" + example.reason + "]" ); | |||
} | |||
catch ( LayoutException e ) | |||
{ | |||
/* expected path */ | |||
} | |||
} | |||
String groupId = "com.foo"; | |||
String artifactId = "foo-tool"; | |||
String version = "1.0"; | |||
String classifier = null; | |||
String type = "jar"; | |||
String path = "com.foo/jars/foo-tool-1.0.jar"; | |||
assertLayout( path, groupId, artifactId, version, classifier, type ); | |||
} | |||
public void testPathToArtifact() | |||
public void testGoodGeronimoEjbSpec() | |||
throws LayoutException | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForArtifactTest() ) | |||
{ | |||
ArchivaArtifact artifact = layout.toArtifact( example.pathArtifact ); | |||
assertArtifact( artifact, example.groupId, example.artifactId, example.version, example.classifier, | |||
example.type ); | |||
} | |||
} | |||
String groupId = "org.apache.geronimo.specs"; | |||
String artifactId = "geronimo-ejb_2.1_spec"; | |||
String version = "1.0.1"; | |||
String classifier = null; | |||
String type = "jar"; | |||
String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar"; | |||
assertLayout( path, groupId, artifactId, version, classifier, type ); | |||
} | |||
public void testPathToArtifactReference() | |||
public void testGoodLdapClientsPom() | |||
throws LayoutException | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForArtifactTest() ) | |||
{ | |||
ArtifactReference reference = layout.toArtifactReference( example.pathArtifact ); | |||
assertArtifactReference( reference, example.groupId, example.artifactId, example.version, | |||
example.classifier, example.type ); | |||
} | |||
} | |||
String groupId = "directory-clients"; | |||
String artifactId = "ldap-clients"; | |||
String version = "0.9.1-SNAPSHOT"; | |||
String classifier = null; | |||
String type = "pom"; | |||
String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom"; | |||
assertLayout( path, groupId, artifactId, version, classifier, type ); | |||
} | |||
public void testPathToVersionedReference() | |||
/** | |||
* A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory. | |||
* @throws LayoutException | |||
*/ | |||
public void testGoodSnapshotMavenTest() | |||
throws LayoutException | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForVersionedTest() ) | |||
{ | |||
VersionedReference reference = layout.toVersionedReference( example.pathVersiond ); | |||
String baseVersion = reference.getVersion(); | |||
assertVersionedReference( reference, example.groupId, example.artifactId, baseVersion ); | |||
} | |||
} | |||
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/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar"; | |||
assertLayout( path, groupId, artifactId, version, classifier, type ); | |||
} | |||
public void testPathToProjectReference() | |||
/** | |||
* 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 | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForProjectTest() ) | |||
{ | |||
ProjectReference reference = layout.toProjectReference( example.pathProjectd ); | |||
ArchivaArtifact expectedArtifact = createArtifact( groupId, artifactId, version, classifier, type ); | |||
assertProjectReference( reference, example.groupId, example.artifactId ); | |||
} | |||
} | |||
// --- Artifact Tests. | |||
// Artifact to Path | |||
assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( expectedArtifact ) ); | |||
// Path to Artifact. | |||
ArchivaArtifact testArtifact = layout.toArtifact( path ); | |||
assertArtifact( testArtifact, groupId, artifactId, version, classifier, type ); | |||
// And back again, using test Artifact from previous step. | |||
assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( testArtifact ) ); | |||
// --- Artifact Reference Tests | |||
// Path to Artifact Reference. | |||
ArtifactReference testReference = layout.toArtifactReference( path ); | |||
assertArtifactReference( testReference, groupId, artifactId, version, classifier, type ); | |||
// And back again, using test Reference from previous step. | |||
assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( testReference ) ); | |||
} | |||
public void testRoundtripArtifactToPathToArtifact() | |||
throws LayoutException | |||
protected void assertBadPath( String path, String reason ) | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
try | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForArtifactTest() ) | |||
{ | |||
ArchivaArtifact artifact = createArtifact( example.groupId, example.artifactId, example.version, | |||
example.classifier, example.type ); | |||
String testPath = layout.toPath( artifact ); | |||
assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, testPath ); | |||
ArchivaArtifact testArtifact = layout.toArtifact( testPath ); | |||
assertArtifact( testArtifact, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), | |||
artifact.getClassifier(), artifact.getType() ); | |||
} | |||
layout.toArtifact( path ); | |||
fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" ); | |||
} | |||
} | |||
public void testRoundtripPathToArtifactToPath() | |||
throws LayoutException | |||
{ | |||
Iterator it = getGoodExamples().iterator(); | |||
while ( it.hasNext() ) | |||
catch ( LayoutException e ) | |||
{ | |||
LayoutExample example = (LayoutExample) it.next(); | |||
if ( example.isSuitableForArtifactTest() ) | |||
{ | |||
ArchivaArtifact artifact = layout.toArtifact( example.pathArtifact ); | |||
assertArtifact( artifact, example.groupId, example.artifactId, example.version, example.classifier, | |||
example.type ); | |||
String testPath = layout.toPath( artifact ); | |||
assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, testPath ); | |||
} | |||
/* expected path */ | |||
} | |||
} | |||
protected void setUp() | |||
throws Exception | |||
{ | |||
super.setUp(); | |||
layout = (BidirectionalRepositoryLayout) lookup( BidirectionalRepositoryLayout.class.getName(), "legacy" ); | |||
} | |||
} |
@@ -29,8 +29,6 @@ import org.apache.maven.archiva.policies.CachedFailuresPolicy; | |||
import org.apache.maven.archiva.policies.ChecksumPolicy; | |||
import org.apache.maven.archiva.policies.ReleasesPolicy; | |||
import org.apache.maven.archiva.policies.SnapshotsPolicy; | |||
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; | |||
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory; | |||
import org.apache.maven.archiva.repository.layout.LayoutException; | |||
import org.codehaus.plexus.PlexusTestCase; | |||
import org.custommonkey.xmlunit.DetailedDiff; | |||
@@ -56,8 +54,6 @@ import javax.xml.parsers.ParserConfigurationException; | |||
public class MetadataToolsTest | |||
extends PlexusTestCase | |||
{ | |||
private BidirectionalRepositoryLayoutFactory layoutFactory; | |||
private MetadataTools tools; | |||
protected MockConfiguration config; | |||
@@ -228,6 +224,116 @@ public class MetadataToolsTest | |||
assertUpdatedSnapshotVersionMetadata( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", "20070316", "175232", "11" ); | |||
} | |||
public void testToPathFromVersionReference() | |||
{ | |||
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", tools.toPath( reference ) ); | |||
} | |||
public void testToPathFromProjectReference() | |||
{ | |||
ProjectReference reference = new ProjectReference(); | |||
reference.setGroupId( "com.foo" ); | |||
reference.setArtifactId( "foo-tool" ); | |||
assertEquals( "com/foo/foo-tool/maven-metadata.xml", tools.toPath( reference ) ); | |||
} | |||
public void testToProjectReferenceFooTools() | |||
throws RepositoryMetadataException | |||
{ | |||
assertProjectReference( "com.foo", "foo-tools", "com/foo/foo-tools/maven-metadata.xml" ); | |||
} | |||
public void testToProjectReferenceAReallyLongPath() | |||
throws RepositoryMetadataException | |||
{ | |||
String groupId = "net.i.have.a.really.long.path.just.for.the.hell.of.it"; | |||
String artifactId = "a"; | |||
String path = "net/i/have/a/really/long/path/just/for/the/hell/of/it/a/maven-metadata.xml"; | |||
assertProjectReference( groupId, artifactId, path ); | |||
} | |||
public void testToProjectReferenceCommonsLang() | |||
throws RepositoryMetadataException | |||
{ | |||
String groupId = "commons-lang"; | |||
String artifactId = "commons-lang"; | |||
String path = "commons-lang/commons-lang/maven-metadata.xml"; | |||
assertProjectReference( groupId, artifactId, path ); | |||
} | |||
private void assertProjectReference( String groupId, String artifactId, String path ) | |||
throws RepositoryMetadataException | |||
{ | |||
ProjectReference reference = tools.toProjectReference( path ); | |||
assertNotNull( "Reference should not be null.", reference ); | |||
assertEquals( "ProjectReference.groupId", groupId, reference.getGroupId() ); | |||
assertEquals( "ProjectReference.artifactId", artifactId, reference.getArtifactId() ); | |||
} | |||
public void testToVersionedReferenceFooTool() | |||
throws RepositoryMetadataException | |||
{ | |||
String groupId = "com.foo"; | |||
String artifactId = "foo-tool"; | |||
String version = "1.0"; | |||
String path = "com/foo/foo-tool/1.0/maven-metadata.xml"; | |||
assertVersionedReference( groupId, artifactId, version, path ); | |||
} | |||
public void testToVersionedReferenceAReallyLongPath() | |||
throws RepositoryMetadataException | |||
{ | |||
String groupId = "net.i.have.a.really.long.path.just.for.the.hell.of.it"; | |||
String artifactId = "a"; | |||
String version = "1.1-alpha-1"; | |||
String path = "net/i/have/a/really/long/path/just/for/the/hell/of/it/a/1.1-alpha-1/maven-metadata.xml"; | |||
assertVersionedReference( groupId, artifactId, version, path ); | |||
} | |||
public void testToVersionedReferenceCommonsLang() | |||
throws RepositoryMetadataException | |||
{ | |||
String groupId = "commons-lang"; | |||
String artifactId = "commons-lang"; | |||
String version = "2.1"; | |||
String path = "commons-lang/commons-lang/2.1/maven-metadata.xml"; | |||
assertVersionedReference( groupId, artifactId, version, path ); | |||
} | |||
public void testToVersionedReferenceSnapshot() | |||
throws RepositoryMetadataException | |||
{ | |||
String groupId = "com.foo"; | |||
String artifactId = "foo-connector"; | |||
String version = "2.1-SNAPSHOT"; | |||
String path = "com/foo/foo-connector/2.1-SNAPSHOT/maven-metadata.xml"; | |||
assertVersionedReference( groupId, artifactId, version, path ); | |||
} | |||
private void assertVersionedReference( String groupId, String artifactId, String version, String path ) | |||
throws RepositoryMetadataException | |||
{ | |||
VersionedReference reference = tools.toVersionedReference( path ); | |||
assertNotNull( "Reference should not be null.", reference ); | |||
assertEquals( "VersionedReference.groupId", groupId, reference.getGroupId() ); | |||
assertEquals( "VersionedReference.artifactId", artifactId, reference.getArtifactId() ); | |||
assertEquals( "VersionedReference.version", version, reference.getVersion() ); | |||
} | |||
private void assertAvailableVersions( String artifactId, String[] expectedVersions ) | |||
throws Exception | |||
{ | |||
@@ -290,8 +396,7 @@ public class MetadataToolsTest | |||
private void assertMetadata( String expectedMetadata, ArchivaRepository repository, ProjectReference reference ) | |||
throws LayoutException, IOException, SAXException, ParserConfigurationException | |||
{ | |||
BidirectionalRepositoryLayout layout = layoutFactory.getLayout( repository.getLayoutType() ); | |||
File metadataFile = new File( repository.getUrl().getPath(), layout.toPath( reference ) ); | |||
File metadataFile = new File( repository.getUrl().getPath(), tools.toPath( reference ) ); | |||
String actualMetadata = FileUtils.readFileToString( metadataFile, null ); | |||
XMLAssert.assertXMLEqual( expectedMetadata, actualMetadata ); | |||
@@ -300,17 +405,15 @@ public class MetadataToolsTest | |||
private void assertMetadata( String expectedMetadata, ArchivaRepository repository, VersionedReference reference ) | |||
throws LayoutException, IOException, SAXException, ParserConfigurationException | |||
{ | |||
BidirectionalRepositoryLayout layout = layoutFactory.getLayout( repository.getLayoutType() ); | |||
File metadataFile = new File( repository.getUrl().getPath(), layout.toPath( reference ) ); | |||
File metadataFile = new File( repository.getUrl().getPath(), tools.toPath( reference ) ); | |||
String actualMetadata = FileUtils.readFileToString( metadataFile, null ); | |||
DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadata, actualMetadata ) ); | |||
if ( !detailedDiff.similar() ) | |||
{ | |||
// If it isn't similar, dump the difference. | |||
assertEquals( expectedMetadata, actualMetadata ); | |||
} | |||
// assertTrue( "Metadata is similar: " + detailedDiff, detailedDiff.similar() ); | |||
// XMLAssert.assertXMLEqual( expectedMetadata, actualMetadata ); | |||
} | |||
private void assertMetadataPath( String expected, String actual ) | |||
@@ -485,7 +588,6 @@ public class MetadataToolsTest | |||
{ | |||
super.setUp(); | |||
layoutFactory = (BidirectionalRepositoryLayoutFactory) lookup( BidirectionalRepositoryLayoutFactory.class ); | |||
config = (MockConfiguration) lookup( ArchivaConfiguration.class.getName(), "mock" ); | |||
tools = (MetadataTools) lookup( MetadataTools.class ); | |||
} |