From 6da94b8031cdbbb7a30fb5515397623c604d5ed6 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 19 Apr 2007 20:54:27 +0000 Subject: [PATCH] Beefing up BidirectionalRepositoryLayout for use in webapp and proxy. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@530543 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractArtifactExtensionMapping.java | 3 +- .../content/ArtifactExtensionMapping.java | 34 -- .../DefaultArtifactExtensionMapping.java | 4 - .../LegacyArtifactExtensionMapping.java | 28 +- .../DefaultBidirectionalRepositoryLayout.java | 57 +- .../LegacyBidirectionalRepositoryLayout.java | 86 ++- .../layout/RepositoryLayoutUtils.java | 26 +- ...aultBidirectionalRepositoryLayoutTest.java | 129 +++-- ...gacyBidirectionalRepositoryLayoutTest.java | 491 +++++++++++++++--- 9 files changed, 626 insertions(+), 232 deletions(-) delete mode 100644 archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractArtifactExtensionMapping.java b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractArtifactExtensionMapping.java index 509e29338..fde5da7e3 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractArtifactExtensionMapping.java +++ b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractArtifactExtensionMapping.java @@ -29,7 +29,6 @@ import java.util.Map; * @version $Id$ */ public abstract class AbstractArtifactExtensionMapping - implements ArtifactExtensionMapping { protected final Map typeToExtensionMap; @@ -41,6 +40,8 @@ public abstract class AbstractArtifactExtensionMapping typeToExtensionMap.put( "distribution-tgz", "tar.gz" ); typeToExtensionMap.put( "distribution-zip", "zip" ); typeToExtensionMap.put( "java-source", "jar" ); + typeToExtensionMap.put( "javadoc.jar", "jar" ); + typeToExtensionMap.put( "javadoc", "jar" ); typeToExtensionMap.put( "aspect", "jar" ); typeToExtensionMap.put( "uberjar", "jar" ); typeToExtensionMap.put( "maven-plugin", "jar" ); diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java deleted file mode 100644 index c2088377f..000000000 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apache.maven.archiva.repository.content; - -/* - * 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. - */ - -/** - * ArtifactExtensionMapping - Utility to provide the mapping between an Artifact's extension and it's type and - * vice versa. - * - * @author Joakim Erdfelt - * @version $Id$ - */ -public interface ArtifactExtensionMapping -{ - public String getExtension( String type ); - - public String getType( String filename ); -} diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultArtifactExtensionMapping.java b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultArtifactExtensionMapping.java index 70f036259..56bfeae60 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultArtifactExtensionMapping.java +++ b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultArtifactExtensionMapping.java @@ -26,12 +26,8 @@ import org.apache.commons.lang.StringUtils; * * @author Joakim Erdfelt * @version $Id$ - * - * @plexus.component role="org.apache.maven.archiva.repository.content.ArtifactExtensionMapping" - * role-hint="default" */ public class DefaultArtifactExtensionMapping extends AbstractArtifactExtensionMapping - implements ArtifactExtensionMapping { public DefaultArtifactExtensionMapping() { diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyArtifactExtensionMapping.java b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyArtifactExtensionMapping.java index 10fd815c8..84c3af024 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyArtifactExtensionMapping.java +++ b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyArtifactExtensionMapping.java @@ -26,23 +26,20 @@ import org.apache.commons.lang.StringUtils; * * @author Joakim Erdfelt * @version $Id$ - * - * @plexus.component role="org.apache.maven.archiva.repository.content.ArtifactExtensionMapping" - * role-hint="legacy" */ -public class LegacyArtifactExtensionMapping extends AbstractArtifactExtensionMapping - implements ArtifactExtensionMapping +public class LegacyArtifactExtensionMapping + extends AbstractArtifactExtensionMapping { public LegacyArtifactExtensionMapping() { super(); } - public String getType( String filename ) + public String getType( String pathType, String filename ) { if ( StringUtils.isBlank( filename ) ) { - return null; + return pathType; } String normalizedName = filename.toLowerCase().trim(); @@ -57,20 +54,15 @@ public class LegacyArtifactExtensionMapping extends AbstractArtifactExtensionMap } else if ( normalizedName.endsWith( "-sources.jar" ) ) { - return "java-source"; + return "jar"; + } + else if ( normalizedName.endsWith( "-javadoc.jar" ) ) + { + return "jar"; } - // TODO: handle type for -javadoc.jar ? else { - int index = normalizedName.lastIndexOf( '.' ); - if ( index >= 0 ) - { - return normalizedName.substring( index + 1 ); - } - else - { - throw new IllegalArgumentException( "Filename " + filename + " does not have an extension." ); - } + return pathType; } } } diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java index 771297177..ae309dd52 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java +++ b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java @@ -25,7 +25,6 @@ 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.ArtifactExtensionMapping; import org.apache.maven.archiva.repository.content.DefaultArtifactExtensionMapping; /** @@ -39,6 +38,8 @@ 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; @@ -69,7 +70,7 @@ public class DefaultBidirectionalRepositoryLayout private static final char ARTIFACT_SEPARATOR = '-'; - private ArtifactExtensionMapping extensionMapper = new DefaultArtifactExtensionMapping(); + private DefaultArtifactExtensionMapping extensionMapper = new DefaultArtifactExtensionMapping(); public String getId() { @@ -118,17 +119,36 @@ public class DefaultBidirectionalRepositoryLayout public String toPath( ProjectReference reference ) { - return toPath( reference.getGroupId(), reference.getArtifactId(), null, null, null, null ); + 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 ) { - return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), null, null, null ); + StringBuffer path = new StringBuffer(); + + path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR ); + path.append( reference.getArtifactId() ).append( PATH_SEPARATOR ); + path.append( VersionUtil.getBaseVersion( reference.getVersion() ) ).append( PATH_SEPARATOR ); + 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 ); @@ -140,6 +160,12 @@ public class DefaultBidirectionalRepositoryLayout public VersionedReference toVersionedReference( 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 VersionedReference." ); + } + PathReferences pathrefs = toPathReferences( path, false ); VersionedReference reference = new VersionedReference(); @@ -209,15 +235,30 @@ public class DefaultBidirectionalRepositoryLayout // Maven 2.x path. int partCount = pathParts.length; + int filenamePos = partCount - 1; + int baseVersionPos = partCount - 2; + int artifactIdPos = partCount - 3; + int groupIdPos = partCount - 4; // Second to last is the baseVersion (the directory version) - prefs.baseVersion = pathParts[partCount - 2]; + 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[partCount - 3]; + prefs.artifactId = pathParts[artifactIdPos]; // Remaining pieces are the groupId. - for ( int i = 0; i <= partCount - 4; i++ ) + for ( int i = 0; i <= groupIdPos; i++ ) { prefs.appendGroupId( pathParts[i] ); } @@ -225,7 +266,7 @@ public class DefaultBidirectionalRepositoryLayout try { // Last part is the filename - String filename = pathParts[partCount - 1]; + String filename = pathParts[filenamePos]; // Now we need to parse the filename to get the artifact version Id. prefs.fileParts = RepositoryLayoutUtils.splitFilename( filename, prefs.artifactId ); diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java index efa98e08c..6bc332366 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java +++ b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java @@ -24,7 +24,6 @@ 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.ArtifactExtensionMapping; import org.apache.maven.archiva.repository.content.LegacyArtifactExtensionMapping; import java.util.HashMap; @@ -41,9 +40,11 @@ import java.util.Map; public class LegacyBidirectionalRepositoryLayout implements BidirectionalRepositoryLayout { + private static final String MAVEN_METADATA = "maven-metadata.xml"; + private static final String PATH_SEPARATOR = "/"; - private ArtifactExtensionMapping extensionMapper = new LegacyArtifactExtensionMapping(); + private LegacyArtifactExtensionMapping extensionMapper = new LegacyArtifactExtensionMapping(); private Map typeToDirectoryMap; @@ -62,25 +63,37 @@ public class LegacyBidirectionalRepositoryLayout public String toPath( ArchivaArtifact artifact ) { - return toPath( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact - .getClassifier(), artifact.getType() ); + return toPath( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), + artifact.getClassifier(), artifact.getType() ); } public String toPath( ProjectReference reference ) { - // TODO: Verify type - return toPath( reference.getGroupId(), reference.getArtifactId(), null, null, "metadata-xml" ); + 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 ) { - return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), null, "metadata-xml" ); + // 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(); } public String toPath( ArtifactReference reference ) { - return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), - reference.getClassifier(), reference.getType() ); + return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference + .getClassifier(), reference.getType() ); } private String toPath( String groupId, String artifactId, String version, String classifier, String type ) @@ -107,10 +120,18 @@ public class LegacyBidirectionalRepositoryLayout private String getDirectory( String classifier, String type ) { - // Special Cases involving classifiers and type. - if ( "jar".equals( type ) && "sources".equals( classifier ) ) + // Special Cases involving type + classifier + if ( "jar".equals( type ) && StringUtils.isNotBlank( classifier ) ) { - return "javadoc.jars"; + if ( "sources".equals( classifier ) ) + { + return "source.jars"; + } + + if ( "javadoc".equals( classifier ) ) + { + return "javadoc.jars"; + } } // Special Cases involving only type. @@ -173,7 +194,20 @@ public class LegacyBidirectionalRepositoryLayout prefs.fileParts = RepositoryLayoutUtils.splitFilename( filename, null ); - prefs.type = extensionMapper.getType( filename ); + prefs.type = extensionMapper.getType( prefs.pathType, filename ); + + // Sanity Checks. + 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.type + + "> (mapped from actual path provided type <" + prefs.pathType + ">)" ); + } } return prefs; @@ -194,32 +228,28 @@ public class LegacyBidirectionalRepositoryLayout pathrefs.fileParts.version, pathrefs.fileParts.classifier, pathrefs.type ); - // Sanity Checks. - if ( StringUtils.isEmpty( pathrefs.fileParts.extension ) ) - { - throw new LayoutException( "Invalid artifact, no extension." ); - } - - if ( !pathrefs.pathType.equals( pathrefs.fileParts.extension + "s" ) ) - { - throw new LayoutException( "Invalid artifact, mismatch on extension <" + pathrefs.fileParts.extension - + "> and layout specified type<" + pathrefs.pathType + ">." ); - } - return artifact; } public ArtifactReference toArtifactReference( String path ) throws LayoutException { - // TODO Auto-generated method stub - return null; + PathReferences pathrefs = toPathReferences( path, true ); + + ArtifactReference reference = new ArtifactReference(); + + reference.setGroupId( pathrefs.groupId ); + reference.setArtifactId( pathrefs.fileParts.artifactId ); + reference.setVersion( pathrefs.fileParts.version ); + reference.setClassifier( pathrefs.fileParts.classifier ); + reference.setType( pathrefs.type ); + + return reference; } public VersionedReference toVersionedReference( String path ) throws LayoutException { - // TODO Auto-generated method stub return null; } diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java index e9d28e933..da75099a0 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java +++ b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java @@ -20,9 +20,7 @@ package org.apache.maven.archiva.repository.layout; */ import org.apache.commons.lang.StringUtils; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import org.apache.maven.archiva.common.utils.VersionUtil; /** * RepositoryLayoutUtils - utility methods common for most BidirectionalRepositoryLayout implementation. @@ -38,18 +36,6 @@ public class RepositoryLayoutUtils */ private static final String ComplexExtensions[] = new String[] { "tar.gz", "tar.bz2" }; - /** - * These are the version patterns found in the filenames of the various artifact's versions IDs. - * These patterns are all tackling lowercase version IDs. - */ - private static final String VersionPatterns[] = - new String[] { "(snapshot)", "([0-9][_.0-9a-z]*)", "(g?[_.0-9ab]*(pre|rc|g|m)[_.0-9]*)", "(dev[_.0-9]*)", - "(alpha[_.0-9]*)", "(beta[_.0-9]*)", "(rc[_.0-9]*)", "(test[_.0-9]*)", "(debug[_.0-9]*)", - "(unofficial[_.0-9]*)", "(current)", "(latest)", "(fcs)", "(release[_.0-9]*)", "(nightly)", "(final)", - "(incubating)", "(incubator)", "([ab][_.0-9]*)" }; - - private static final String VersionMegaPattern = StringUtils.join( VersionPatterns, '|' ); - /** * Filename Parsing Mode - Artifact Id. */ @@ -137,17 +123,13 @@ public class RepositoryLayoutUtils int versionStart = -1; int versionEnd = -1; - Pattern pat = Pattern.compile( VersionMegaPattern, Pattern.CASE_INSENSITIVE ); - Matcher mat; - for ( int i = 0; i < fileParts.length; i++ ) { String part = fileParts[i]; - mat = pat.matcher( part ); - - if ( mat.matches() ) + + if ( VersionUtil.isSimpleVersionKeyword( part ) ) { - // It is a potential verion part. + // It is a potential version part. if ( versionStart < 0 ) { versionStart = i; diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayoutTest.java b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayoutTest.java index ec3ae2a7c..07c68c67c 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayoutTest.java +++ b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayoutTest.java @@ -19,19 +19,15 @@ 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 org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; -import org.apache.maven.archiva.repository.layout.LayoutException; import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; /** * DefaultBidirectionalRepositoryLayoutTest @@ -54,7 +50,11 @@ public class DefaultBidirectionalRepositoryLayoutTest public String type; - public String path; + public String pathArtifact; + + public String pathVersiond; + + public String pathProjectd; public LayoutExample( String groupId, String artifactId, String version, String classifier, String type ) { @@ -66,6 +66,30 @@ public class DefaultBidirectionalRepositoryLayoutTest 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 ); @@ -108,58 +132,65 @@ public class DefaultBidirectionalRepositoryLayoutTest LayoutExample example; // Artifact References - example = new LayoutExample( "com.foo", "foo-tool", "1.0", "", "jar" ); - example.path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar"; + 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", "", "ejb-client" ); - example.path = "com/foo/foo-client/1.0/foo-client-1.0.jar"; + 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.path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar"; + 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", "", "jar" ); - example.path = "com/foo/foo-connector/2.1-SNAPSHOT/foo-connector-2.1-20060822.123456-35.jar"; + 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", "", + example = new LayoutExample( "org.apache.maven.test", "get-metadata-snapshot", "1.0-20050831.101112-1", null, "jar" ); - example.path = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.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", "", "jar" ); - example.path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar"; + 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", "", "jar" ); - example.path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar"; + 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.path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar"; + example.setDelimitedPath( "com/foo/foo-tool|1.0" ); ret.add( example ); - example = new LayoutExample( "com.foo", "foo-tool", "1.0", null, null ); - example.path = "com/foo/foo-tool/1.0/"; + 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-tool", "1.0", null, null ); - example.path = "com/foo/foo-tool/1.0"; + 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-20060822.123456-35", null, null ); - example.path = "com/foo/foo-connector/2.1-SNAPSHOT/foo-connector-2.1-20060822.123456-35.jar"; + example = new LayoutExample( "com.foo", "foo-connector", "2.1-SNAPSHOT", null, null ); + example.setDelimitedPath( "com/foo/foo-connector|2.1-SNAPSHOT" ); ret.add( example ); - example = new LayoutExample( "com.foo", "foo-connector", "2.1-20060822.123456-35", null, null ); - example.path = "com/foo/foo-connector/2.1-SNAPSHOT/"; + // 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( "com.foo", "foo-connector", "2.1-20060822.123456-35", null, null ); - example.path = "com/foo/foo-connector/2.1-SNAPSHOT"; + 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; @@ -209,7 +240,7 @@ public class DefaultBidirectionalRepositoryLayoutTest { ArchivaArtifact artifact = createArtifact( example.groupId, example.artifactId, example.version, example.classifier, example.type ); - assertEquals( "Artifact <" + artifact + "> to path:", example.path, layout.toPath( artifact ) ); + assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, layout.toPath( artifact ) ); } } } @@ -229,7 +260,8 @@ public class DefaultBidirectionalRepositoryLayoutTest reference.setClassifier( example.classifier ); reference.setType( example.type ); - assertEquals( "ArtifactReference <" + reference + "> to path:", example.path, layout.toPath( reference ) ); + assertEquals( "ArtifactReference <" + reference + "> to path:", example.pathArtifact, layout + .toPath( reference ) ); } } } @@ -240,14 +272,14 @@ public class DefaultBidirectionalRepositoryLayoutTest while ( it.hasNext() ) { LayoutExample example = (LayoutExample) it.next(); - if ( example.isSuitableForVersionedTest() && example.isSuitableForArtifactTest() ) + 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.path, layout + assertEquals( "VersionedReference <" + reference + "> to path:", example.pathVersiond, layout .toPath( reference ) ); } } @@ -259,14 +291,15 @@ public class DefaultBidirectionalRepositoryLayoutTest while ( it.hasNext() ) { LayoutExample example = (LayoutExample) it.next(); - if ( example.isSuitableForProjectTest() && example.isSuitableForVersionedTest() - && example.isSuitableForArtifactTest() ) + 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.path, layout.toPath( reference ) ); + assertEquals( "ProjectReference <" + reference + "> to path:", example.pathProjectd, layout + .toPath( reference ) ); } } } @@ -366,14 +399,13 @@ public class DefaultBidirectionalRepositoryLayoutTest LayoutExample example = (LayoutExample) it.next(); if ( example.isSuitableForArtifactTest() ) { - ArchivaArtifact artifact = layout.toArtifact( example.path ); + ArchivaArtifact artifact = layout.toArtifact( example.pathArtifact ); assertArtifact( artifact, example.groupId, example.artifactId, example.version, example.classifier, example.type ); } } } - /* TODO: Fix layout object to pass test. public void testPathToArtifactReference() throws LayoutException { @@ -383,15 +415,13 @@ public class DefaultBidirectionalRepositoryLayoutTest LayoutExample example = (LayoutExample) it.next(); if ( example.isSuitableForArtifactTest() ) { - ArtifactReference reference = layout.toArtifactReference( example.path ); + ArtifactReference reference = layout.toArtifactReference( example.pathArtifact ); assertArtifactReference( reference, example.groupId, example.artifactId, example.version, example.classifier, example.type ); } } } - */ - /* TODO: Fix layout object to pass test. public void testPathToVersionedReference() throws LayoutException { @@ -401,13 +431,14 @@ public class DefaultBidirectionalRepositoryLayoutTest LayoutExample example = (LayoutExample) it.next(); if ( example.isSuitableForVersionedTest() ) { - VersionedReference reference = layout.toVersionedReference( example.path ); + VersionedReference reference = layout.toVersionedReference( example.pathVersiond ); + + String baseVersion = reference.getVersion(); - assertVersionedReference( reference, example.groupId, example.artifactId, example.version ); + assertVersionedReference( reference, example.groupId, example.artifactId, baseVersion ); } } } - */ public void testPathToProjectReference() throws LayoutException @@ -418,7 +449,7 @@ public class DefaultBidirectionalRepositoryLayoutTest LayoutExample example = (LayoutExample) it.next(); if ( example.isSuitableForProjectTest() ) { - ProjectReference reference = layout.toProjectReference( example.path ); + ProjectReference reference = layout.toProjectReference( example.pathProjectd ); assertProjectReference( reference, example.groupId, example.artifactId ); } @@ -437,7 +468,7 @@ public class DefaultBidirectionalRepositoryLayoutTest ArchivaArtifact artifact = createArtifact( example.groupId, example.artifactId, example.version, example.classifier, example.type ); String testPath = layout.toPath( artifact ); - assertEquals( "Artifact <" + artifact + "> to path:", example.path, testPath ); + 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() ); @@ -454,11 +485,11 @@ public class DefaultBidirectionalRepositoryLayoutTest LayoutExample example = (LayoutExample) it.next(); if ( example.isSuitableForArtifactTest() ) { - ArchivaArtifact artifact = layout.toArtifact( example.path ); + 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.path, testPath ); + assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, testPath ); } } } diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayoutTest.java b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayoutTest.java index 169ec3e53..66a33f410 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayoutTest.java +++ b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayoutTest.java @@ -19,8 +19,15 @@ 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.repository.layout.BidirectionalRepositoryLayout; +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 @@ -28,129 +35,477 @@ import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; * @author Joakim Erdfelt * @version $Id$ */ -public class LegacyBidirectionalRepositoryLayoutTest extends AbstractBidirectionalRepositoryLayoutTestCase +public class LegacyBidirectionalRepositoryLayoutTest + extends AbstractBidirectionalRepositoryLayoutTestCase { - private BidirectionalRepositoryLayout layout; - - protected void setUp() throws Exception + class LayoutExample { - super.setUp(); + public String groupId; - layout = (BidirectionalRepositoryLayout) lookup( BidirectionalRepositoryLayout.class.getName(), "legacy" ); - } + public String artifactId; - public void testToPathBasic() - { - ArchivaArtifact artifact = createArtifact( "com.foo", "foo-tool", "1.0", "", "jar" ); + public String version; - assertEquals( "com.foo/jars/foo-tool-1.0.jar", layout.toPath( artifact ) ); + 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 ); + } + + public boolean isSuitableForProjectTest() + { + return ( this.type == null ) && ( this.classifier == null ) && ( this.version == null ); + } } - public void testToPathEjbClient() + class InvalidExample { - ArchivaArtifact artifact = createArtifact( "com.foo", "foo-client", "1.0", "", "ejb-client" ); + public String path; - assertEquals( "com.foo/ejbs/foo-client-1.0.jar", layout.toPath( artifact ) ); + 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; + } } - public void testToPathWithClassifier() + private BidirectionalRepositoryLayout layout; + + protected void setUp() + throws Exception { - ArchivaArtifact artifact = createArtifact( "com.foo.lib", "foo-lib", "2.1-alpha-1", "sources", "jar" ); + super.setUp(); - assertEquals( "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-sources.jar", layout.toPath( artifact ) ); + layout = (BidirectionalRepositoryLayout) lookup( BidirectionalRepositoryLayout.class.getName(), "legacy" ); } - public void testToPathUsingUniqueSnapshot() + public List /**/getGoodExamples() { - ArchivaArtifact artifact = createArtifact( "com.foo", "foo-connector", "2.1-20060822.123456-35", "", "jar" ); + 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 ); - assertEquals( "com.foo/jars/foo-connector-2.1-20060822.123456-35.jar", layout.toPath( artifact ) ); + 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. + + return ret; } + + public List /**/getInvalidPaths() + { + List ret = new ArrayList(); - public void testToArtifactBasicSimpleGroupId() throws LayoutException + 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; + } + + public void testArtifactToPath() { - ArchivaArtifact artifact = layout.toArtifact( "commons-lang/jars/commons-lang-2.1.jar" ); - assertArtifact( artifact, "commons-lang", "commons-lang", "2.1", "", "jar" ); + 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 ) ); + } + } } - public void testToArtifactBasicLongGroupId() throws LayoutException + public void testArtifactReferenceToPath() { - ArchivaArtifact artifact = layout.toArtifact( "org.apache.derby/jars/derby-10.2.2.0.jar" ); - assertArtifact( artifact, "org.apache.derby", "derby", "10.2.2.0", "", "jar" ); + 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 ) ); + } + } } - public void testToArtifactLongGroupId() throws LayoutException + public void testVersionedReferenceToPath() { - ArchivaArtifact artifact = layout.toArtifact( "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar" ); - assertArtifact( artifact, "org.apache.geronimo.specs", "geronimo-ejb_2.1_spec", "1.0.1", "", "jar" ); + 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 ) ); + } + } } - public void testToArtifactEjbClient() throws LayoutException + public void testProjectReferenceToPath() { - ArchivaArtifact artifact = layout.toArtifact( "org.apache.beehive/jars/beehive-ejb-control-1.0.1.jar" ); - // The type is correct. as we cannot possibly know this is an ejb client without parsing the pom - assertArtifact( artifact, "org.apache.beehive", "beehive-ejb-control", "1.0.1", "", "jar" ); + 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 ) ); + } + } } - public void testToArtifactWithClassifier() throws LayoutException + public void testInvalidPathToArtifact() { - ArchivaArtifact artifact = layout.toArtifact( "commons-lang/jars/commons-lang-2.3-sources.jar" ); - // The 'java-source' type is correct. You might be thinking of extension, which we are not testing here. - assertArtifact( artifact, "commons-lang", "commons-lang", "2.3", "sources", "java-source" ); + 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 */ + } + } } - public void testToArtifactSnapshot() throws LayoutException + public void testInvalidPathToArtifactReference() { - ArchivaArtifact artifact = layout.toArtifact( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ); - assertSnapshotArtifact( artifact, "directory-clients", "ldap-clients", "0.9.1-SNAPSHOT", "", "pom" ); + 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 */ + } + } } - - public void testInvalidNoType() + + public void testInvalidPathToVersionedReference() { - try + Iterator it = getInvalidPaths().iterator(); + while ( it.hasNext() ) { - layout.toArtifact( "invalid/invalid/1/invalid-1" ); - fail( "Should have detected no type." ); + 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 */ + } } - catch ( LayoutException e ) + } + + public void testInvalidPathToProjectReference() + { + Iterator it = getInvalidPaths().iterator(); + while ( it.hasNext() ) { - /* expected path */ + 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 */ + } } } - - public void testInvalidArtifactPackaging() + + public void testPathToArtifact() + throws LayoutException { - try + Iterator it = getGoodExamples().iterator(); + while ( it.hasNext() ) { - layout.toArtifact( "org.apache.maven.test/jars/artifactId-1.0.jar.md5" ); - fail( "Should have detected wrong package extension." ); + 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 ); + } } - catch ( LayoutException e ) + } + + public void testPathToArtifactReference() + throws LayoutException + { + Iterator it = getGoodExamples().iterator(); + while ( it.hasNext() ) { - /* expected path */ + 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 ); + } } } - - public void testInvalidNoArtifactId() + + public void testPathToVersionedReference() + throws LayoutException { - try + Iterator it = getGoodExamples().iterator(); + while ( it.hasNext() ) { - layout.toArtifact( "groupId/jars/-1.0.jar" ); - fail( "Should have detected artifactId is missing" ); + 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 ); + } } - catch ( LayoutException e ) + } + + public void testPathToProjectReference() + throws LayoutException + { + Iterator it = getGoodExamples().iterator(); + while ( it.hasNext() ) { - /* expected path */ + LayoutExample example = (LayoutExample) it.next(); + if ( example.isSuitableForProjectTest() ) + { + ProjectReference reference = layout.toProjectReference( example.pathProjectd ); + + assertProjectReference( reference, example.groupId, example.artifactId ); + } } - - try + } + + public void testRoundtripArtifactToPathToArtifact() + throws LayoutException + { + Iterator it = getGoodExamples().iterator(); + while ( it.hasNext() ) { - layout.toArtifact( "groupId/jars/1.0.jar" ); - fail( "Should have detected artifactId is missing" ); + 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() ); + } } - catch ( LayoutException e ) + } + + public void testRoundtripPathToArtifactToPath() + throws LayoutException + { + Iterator it = getGoodExamples().iterator(); + while ( it.hasNext() ) { - /* expected path */ + 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 ); + } } } + + } -- 2.39.5