@@ -180,6 +180,18 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent | |||
} | |||
@Override | |||
public ContentItem toItem( String path ) throws LayoutException | |||
{ | |||
return null; | |||
} | |||
@Override | |||
public ContentItem toItem( StorageAsset assetPath ) throws LayoutException | |||
{ | |||
return null; | |||
} | |||
@Override | |||
public void deleteGroupId( String groupId ) throws ContentNotFoundException, ContentAccessException |
@@ -321,7 +321,7 @@ public class FilesystemStorage implements RepositoryStorage { | |||
public StorageAsset getAsset( String path ) | |||
{ | |||
try { | |||
return new FilesystemAsset(this, path, getAssetPath(path)); | |||
return new FilesystemAsset(this, path, getAssetPath(path), basePath); | |||
} catch (IOException e) { | |||
throw new IllegalArgumentException("Path navigates outside of base directory "+path); | |||
} |
@@ -185,6 +185,18 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent | |||
} | |||
@Override | |||
public ContentItem toItem( String path ) throws LayoutException | |||
{ | |||
return null; | |||
} | |||
@Override | |||
public ContentItem toItem( StorageAsset assetPath ) throws LayoutException | |||
{ | |||
return null; | |||
} | |||
@Override | |||
public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException | |||
{ |
@@ -141,38 +141,32 @@ public class ManagedDefaultRepositoryContent | |||
} | |||
/** | |||
* Returns a version reference from the coordinates | |||
* @param groupId the group id | |||
* @param artifactId the artifact id | |||
* @param version the version | |||
* @return the versioned reference object | |||
*/ | |||
@Override | |||
public VersionedReference toVersion( String groupId, String artifactId, String version ) { | |||
return new VersionedReference().groupId( groupId ).artifactId( artifactId ).version( version ); | |||
private StorageAsset getAssetByPath(String assetPath) { | |||
return getStorage( ).getAsset( assetPath ); | |||
} | |||
@Override | |||
public VersionedReference toGenericVersion( ArtifactReference artifactReference ) | |||
{ | |||
return toVersion( artifactReference.getGroupId( ), artifactReference.getArtifactId( ), VersionUtil.getBaseVersion( artifactReference.getVersion( ) )); | |||
private StorageAsset getAsset(String namespace) { | |||
String namespacePath = formatAsDirectory( namespace.trim() ); | |||
if (StringUtils.isEmpty( namespacePath )) { | |||
namespacePath = ""; | |||
} | |||
return getAssetByPath(namespacePath); | |||
} | |||
/** | |||
* Return the version the artifact is part of | |||
* @param artifactReference | |||
* @return | |||
*/ | |||
public VersionedReference toVersion( ArtifactReference artifactReference) { | |||
return toVersion( artifactReference.getGroupId( ), artifactReference.getArtifactId( ), artifactReference.getVersion( ) ); | |||
private StorageAsset getAsset(String namespace, String project) { | |||
return getAsset( namespace ).resolve( project ); | |||
} | |||
@Override | |||
public ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier) { | |||
return new ArtifactReference( ).groupId( groupId ).artifactId( artifactId ).version( version ).type( type ).classifier( classifier ); | |||
private StorageAsset getAsset(String namespace, String project, String version) { | |||
return getAsset( namespace, project ).resolve( version ); | |||
} | |||
private StorageAsset getAsset(String namespace, String project, String version, String fileName) { | |||
return getAsset( namespace, project, version ).resolve( fileName ); | |||
} | |||
/// ************* End of new generation interface ****************** | |||
@Override | |||
public void deleteItem( ContentItem item ) throws ItemNotFoundException, ContentAccessException | |||
{ | |||
@@ -205,31 +199,6 @@ public class ManagedDefaultRepositoryContent | |||
} | |||
} | |||
private StorageAsset getAssetByPath(String assetPath) { | |||
return getStorage( ).getAsset( assetPath ); | |||
} | |||
private StorageAsset getAsset(String namespace) { | |||
String namespacePath = formatAsDirectory( namespace.trim() ); | |||
if (StringUtils.isEmpty( namespacePath )) { | |||
namespacePath = ""; | |||
} | |||
return getAssetByPath(namespacePath); | |||
} | |||
private StorageAsset getAsset(String namespace, String project) { | |||
return getAsset( namespace ).resolve( project ); | |||
} | |||
private StorageAsset getAsset(String namespace, String project, String version) { | |||
return getAsset( namespace, project ).resolve( version ); | |||
} | |||
private StorageAsset getAsset(String namespace, String project, String version, String fileName) { | |||
return getAsset( namespace, project, version ).resolve( fileName ); | |||
} | |||
@Override | |||
public Namespace getNamespace( final ItemSelector namespaceSelector ) throws ContentAccessException, IllegalArgumentException | |||
{ | |||
@@ -501,7 +470,8 @@ public class ManagedDefaultRepositoryContent | |||
final String artifactVersion = mavenContentHelper.getArtifactVersion( artifactDir, selector ); | |||
final String classifier = MavenContentHelper.getClassifier( selector ); | |||
final String extension = MavenContentHelper.getArtifactExtension( selector ); | |||
final String fileName = MavenContentHelper.getArtifactFileName( selector, artifactVersion, classifier, extension ); | |||
final String artifactId = StringUtils.isEmpty( selector.getArtifactId( ) ) ? selector.getProjectId( ) : selector.getArtifactId( ); | |||
final String fileName = MavenContentHelper.getArtifactFileName( artifactId, artifactVersion, classifier, extension ); | |||
final StorageAsset path = getAsset( selector.getNamespace( ), selector.getProjectId( ), | |||
selector.getVersion( ), fileName ); | |||
return artifactMap.computeIfAbsent( path, artifactPath -> createArtifact( path, selector, classifier, extension ) ); | |||
@@ -659,6 +629,41 @@ public class ManagedDefaultRepositoryContent | |||
return getItemFromPath( assetPath ); | |||
} | |||
/// ************* End of new generation interface ****************** | |||
/** | |||
* Returns a version reference from the coordinates | |||
* @param groupId the group id | |||
* @param artifactId the artifact id | |||
* @param version the version | |||
* @return the versioned reference object | |||
*/ | |||
@Override | |||
public VersionedReference toVersion( String groupId, String artifactId, String version ) { | |||
return new VersionedReference().groupId( groupId ).artifactId( artifactId ).version( version ); | |||
} | |||
@Override | |||
public VersionedReference toGenericVersion( ArtifactReference artifactReference ) | |||
{ | |||
return toVersion( artifactReference.getGroupId( ), artifactReference.getArtifactId( ), VersionUtil.getBaseVersion( artifactReference.getVersion( ) )); | |||
} | |||
/** | |||
* Return the version the artifact is part of | |||
* @param artifactReference | |||
* @return | |||
*/ | |||
public VersionedReference toVersion( ArtifactReference artifactReference) { | |||
return toVersion( artifactReference.getGroupId( ), artifactReference.getArtifactId( ), artifactReference.getVersion( ) ); | |||
} | |||
@Override | |||
public ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier) { | |||
return new ArtifactReference( ).groupId( groupId ).artifactId( artifactId ).version( version ).type( type ).classifier( classifier ); | |||
} | |||
@Override | |||
public void deleteVersion( VersionedReference ref ) throws ContentNotFoundException, ContentAccessException | |||
{ |
@@ -32,7 +32,9 @@ import org.springframework.stereotype.Service; | |||
import javax.inject.Inject; | |||
import javax.inject.Named; | |||
import java.util.Comparator; | |||
import java.util.LinkedList; | |||
import java.util.regex.Pattern; | |||
/** | |||
* Helper class that contains certain maven specific methods | |||
@@ -42,6 +44,8 @@ public class MavenContentHelper | |||
{ | |||
private static final Logger log = LoggerFactory.getLogger( MavenContentHelper.class ); | |||
public static final Pattern UNIQUE_SNAPSHOT_NUMBER_PATTERN = Pattern.compile( "^([0-9]{8}\\.[0-9]{6}-[0-9]+)(.*)" ); | |||
@Inject | |||
@Named( "metadataReader#maven" ) | |||
@@ -53,6 +57,11 @@ public class MavenContentHelper | |||
} | |||
public void setMetadataReader( MavenMetadataReader metadataReader ) | |||
{ | |||
this.metadataReader = metadataReader; | |||
} | |||
/** | |||
* Returns the namespace string for a given path in the repository | |||
* | |||
@@ -64,6 +73,7 @@ public class MavenContentHelper | |||
StorageAsset current = namespacePath; | |||
while (current.hasParent()) { | |||
names.addFirst( current.getName() ); | |||
current = current.getParent( ); | |||
} | |||
return String.join( ".", names ); | |||
} | |||
@@ -103,33 +113,40 @@ public class MavenContentHelper | |||
// re-adjust to timestamp if present, otherwise retain the original -SNAPSHOT filename | |||
SnapshotVersion metadataVersion = metadata.getSnapshotVersion( ); | |||
if ( metadataVersion != null ) | |||
if ( metadataVersion != null && StringUtils.isNotEmpty( metadataVersion.getTimestamp( ) ) ) | |||
{ | |||
version.append( snapshotVersion, 0, snapshotVersion.length( ) - 8 ); // remove SNAPSHOT from end | |||
version.append( metadataVersion.getTimestamp( )).append("-").append( metadataVersion.getBuildNumber( ) ); | |||
version.append( metadataVersion.getTimestamp( ) ).append( "-" ).append( metadataVersion.getBuildNumber( ) ); | |||
return version.toString( ); | |||
} | |||
return version.toString( ); | |||
} | |||
catch ( RepositoryMetadataException e ) | |||
{ | |||
// unable to parse metadata - LOGGER it, and continue with the version as the original SNAPSHOT version | |||
log.warn( "Invalid metadata: {} - {}", metadataFile, e.getMessage( ) ); | |||
return snapshotVersion; | |||
} | |||
final String baseVersion = StringUtils.removeEnd( snapshotVersion, "-SNAPSHOT" ); | |||
final String prefix = metadataFile.getParent( ).getParent( ).getName( ) + "-"+baseVersion+"-"; | |||
return artifactDir.list( ).stream( ).filter( a -> a.getName( ).startsWith( prefix ) ) | |||
.map( a -> StringUtils.removeStart( a.getName( ), prefix ) ) | |||
.map( n -> UNIQUE_SNAPSHOT_NUMBER_PATTERN.matcher( n ) ) | |||
.filter( m -> m.matches( ) ) | |||
.map( m -> baseVersion+"-"+m.group( 1 ) ) | |||
.sorted( Comparator.reverseOrder() ).findFirst().orElse( snapshotVersion ); | |||
} | |||
/** | |||
* Returns a artifact filename that corresponds to the given data. | |||
* @param selector the selector data | |||
* @param artifactId the selector data | |||
* @param artifactVersion the artifactVersion | |||
* @param classifier the artifact classifier | |||
* @param extension the file extension | |||
*/ | |||
static String getArtifactFileName( ItemSelector selector, String artifactVersion, | |||
static String getArtifactFileName( String artifactId, String artifactVersion, | |||
String classifier, String extension ) | |||
{ | |||
StringBuilder fileName = new StringBuilder( selector.getArtifactId( ) ).append( "-" ); | |||
StringBuilder fileName = new StringBuilder( artifactId ).append( "-" ); | |||
fileName.append( artifactVersion ); | |||
if ( !StringUtils.isEmpty( classifier ) ) | |||
{ | |||
@@ -171,33 +188,30 @@ public class MavenContentHelper | |||
*/ | |||
static String getClassifierFromType( final String type ) | |||
{ | |||
if ( "pom".equalsIgnoreCase( type ) || "jar".equalsIgnoreCase( type ) | |||
|| "maven-plugin".equalsIgnoreCase( type ) | |||
|| "ejb".equalsIgnoreCase( type ) | |||
|| "ear".equalsIgnoreCase( type ) | |||
|| "war".equalsIgnoreCase( type ) | |||
|| "rar".equalsIgnoreCase( type ) | |||
) return ""; | |||
if ( "test-jar".equalsIgnoreCase( type ) ) | |||
{ | |||
return "tests"; | |||
} | |||
else if ( "ejb-client".equalsIgnoreCase( type ) ) | |||
{ | |||
return "client"; | |||
} | |||
else if ( "java-source".equalsIgnoreCase( type ) ) | |||
{ | |||
return "sources"; | |||
} | |||
else if ( "javadoc".equalsIgnoreCase( type ) ) | |||
{ | |||
return "javadoc"; | |||
} | |||
else | |||
String testType = type.trim( ).toLowerCase( ); | |||
switch (testType.length( )) | |||
{ | |||
return ""; | |||
case 7: | |||
if ("javadoc".equals(testType)) { | |||
return "javadoc"; | |||
} | |||
case 8: | |||
if ("test-jar".equals(testType)) | |||
{ | |||
return "tests"; | |||
} | |||
case 10: | |||
if ("ejb-client".equals(testType)) { | |||
return "client"; | |||
} | |||
case 11: | |||
if ("java-source".equals(testType)) { | |||
return "sources"; | |||
} | |||
default: | |||
return ""; | |||
} | |||
} | |||
/** | |||
@@ -227,7 +241,7 @@ public class MavenContentHelper | |||
{ | |||
return "ejb-client"; | |||
} | |||
else if ( classifier.equals( "source" ) && extension.equals( "jar" ) ) | |||
else if ( classifier.equals( "sources" ) && extension.equals( "jar" ) ) | |||
{ | |||
return "java-source"; | |||
} | |||
@@ -256,26 +270,15 @@ public class MavenContentHelper | |||
} | |||
else if ( selector.hasType( ) ) | |||
{ | |||
String type = selector.getType( ).toLowerCase( ); | |||
if ( "test-jar".equals( type ) ) | |||
{ | |||
return "jar"; | |||
} | |||
else if ( "ejb-client".equals( type ) ) | |||
{ | |||
return "jar"; | |||
} | |||
else if ( "java-source".equals( type ) ) | |||
{ | |||
return "jar"; | |||
} | |||
else if ( "javadoc".equals( type ) ) | |||
{ | |||
return "jar"; | |||
} | |||
else | |||
{ | |||
return "jar"; | |||
final String type = selector.getType( ).trim().toLowerCase( ); | |||
switch (type.length()) { | |||
case 3: | |||
if ("pom".equals(type) || "war".equals(type) || "ear".equals(type) || "rar".equals(type)) { | |||
return type; | |||
} | |||
default: | |||
return "jar"; | |||
} | |||
} | |||
else |
@@ -0,0 +1,46 @@ | |||
package org.apache.archiva.repository.maven.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. | |||
*/ | |||
import org.apache.archiva.repository.LayoutException; | |||
import static org.junit.Assert.fail; | |||
/** | |||
* @author Martin Stockhammer <martin_s@apache.org> | |||
*/ | |||
public abstract class AbstractManagedRepositoryContentTest extends AbstractRepositoryContentTest | |||
{ | |||
@Override | |||
protected void assertBadPathCi( String path, String reason ) | |||
{ | |||
super.assertBadPathCi( path, reason ); | |||
try | |||
{ | |||
getManaged().toItem( path ); | |||
fail( | |||
"Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" ); | |||
} | |||
catch ( LayoutException e ) | |||
{ | |||
/* expected path */ | |||
} | |||
} | |||
} |
@@ -36,13 +36,14 @@ import static org.junit.Assert.*; | |||
/** | |||
* AbstractDefaultRepositoryContentTestCase | |||
*/ | |||
public abstract class AbstractDefaultRepositoryContentTestCase | |||
public abstract class AbstractRepositoryContentTest | |||
extends AbstractRepositoryLayerTestCase | |||
{ | |||
@Test | |||
public void testBadPathMissingType() | |||
{ | |||
assertBadPath( "invalid/invalid/1/invalid-1", "missing type" ); | |||
assertBadPathCi( "invalid/invalid/1/invalid-1", "missing type" ); | |||
} | |||
@Test | |||
@@ -50,6 +51,9 @@ public abstract class AbstractDefaultRepositoryContentTestCase | |||
{ | |||
assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", | |||
"non snapshot artifact inside of a snapshot dir" ); | |||
assertBadPathCi( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", | |||
"non snapshot artifact inside of a snapshot dir" ); | |||
} | |||
@Test | |||
@@ -57,6 +61,8 @@ public abstract class AbstractDefaultRepositoryContentTestCase | |||
{ | |||
assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar", | |||
"Timestamped Snapshot artifact not inside of an Snapshot dir" ); | |||
assertBadPathCi( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar", | |||
"Timestamped Snapshot artifact not inside of an Snapshot dir" ); | |||
} | |||
@Test | |||
@@ -503,6 +509,20 @@ public abstract class AbstractDefaultRepositoryContentTestCase | |||
} | |||
} | |||
protected void assertBadPathCi( String path, String reason ) | |||
{ | |||
try | |||
{ | |||
toItemSelector( path ); | |||
fail( | |||
"Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" ); | |||
} | |||
catch ( LayoutException e ) | |||
{ | |||
/* expected path */ | |||
} | |||
} | |||
/** | |||
* Perform a roundtrip through the layout routines to determine success. | |||
*/ |
@@ -55,7 +55,7 @@ import static org.junit.Assert.*; | |||
* ManagedDefaultRepositoryContentTest | |||
*/ | |||
public class ManagedDefaultRepositoryContentTest | |||
extends AbstractDefaultRepositoryContentTestCase | |||
extends AbstractManagedRepositoryContentTest | |||
{ | |||
private ManagedDefaultRepositoryContent repoContent; | |||
@@ -0,0 +1,209 @@ | |||
package org.apache.archiva.repository.maven.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. | |||
*/ | |||
import org.apache.archiva.common.filelock.DefaultFileLockManager; | |||
import org.apache.archiva.maven2.metadata.MavenMetadataReader; | |||
import org.apache.archiva.repository.content.ItemSelector; | |||
import org.apache.archiva.repository.content.base.ArchivaItemSelector; | |||
import org.apache.archiva.repository.storage.StorageAsset; | |||
import org.apache.archiva.repository.storage.fs.FilesystemStorage; | |||
import org.junit.jupiter.api.AfterAll; | |||
import org.junit.jupiter.api.BeforeAll; | |||
import org.junit.jupiter.api.Test; | |||
import java.io.IOException; | |||
import java.net.URISyntaxException; | |||
import java.nio.file.Files; | |||
import java.nio.file.Path; | |||
import java.nio.file.Paths; | |||
import static org.junit.jupiter.api.Assertions.assertEquals; | |||
import static org.junit.jupiter.api.Assertions.assertNotNull; | |||
/** | |||
* @author Martin Stockhammer <martin_s@apache.org> | |||
*/ | |||
class MavenContentHelperTest | |||
{ | |||
private static FilesystemStorage storage; | |||
private static Path tempDir; | |||
@BeforeAll | |||
static void setUp() throws IOException | |||
{ | |||
tempDir = Files.createTempDirectory( "archivamaventest" ); | |||
storage = new FilesystemStorage( tempDir, new DefaultFileLockManager() ); | |||
} | |||
@AfterAll | |||
static void tearDown() { | |||
try | |||
{ | |||
Files.deleteIfExists( tempDir ); | |||
} | |||
catch ( IOException e ) | |||
{ | |||
System.err.println( "Could not delete " + tempDir ); | |||
} | |||
} | |||
@Test | |||
void getNamespaceFromNamespacePath( ) | |||
{ | |||
StorageAsset asset = storage.getAsset( "org/apache/archiva" ); | |||
String ns = MavenContentHelper.getNamespaceFromNamespacePath( asset ); | |||
assertNotNull( ns ); | |||
assertEquals( "org.apache.archiva", ns ); | |||
asset = storage.getAsset( "" ); | |||
ns = MavenContentHelper.getNamespaceFromNamespacePath( asset ); | |||
assertNotNull( ns ); | |||
assertEquals( "", ns ); | |||
} | |||
@Test | |||
void getArtifactVersion( ) throws IOException, URISyntaxException | |||
{ | |||
MavenContentHelper mavenContentHelper = new MavenContentHelper( ); | |||
MavenMetadataReader reader = new MavenMetadataReader( ); | |||
mavenContentHelper.setMetadataReader( reader ); | |||
Path testRepoPath = Paths.get( Thread.currentThread( ).getContextClassLoader( ).getResource( "repositories/metadata-repository" ).toURI() ); | |||
FilesystemStorage storage = new FilesystemStorage( testRepoPath, new DefaultFileLockManager( ) ); | |||
assertArtifactVersion( mavenContentHelper, "1.0-alpha-11-SNAPSHOT", storage.getAsset( "org/apache/archiva/metadata/tests/snap_shots_1/1.0-alpha-11-SNAPSHOT" ) | |||
, "1.0-alpha-11-SNAPSHOT", "1.0-alpha-11-SNAPSHOT"); | |||
assertArtifactVersion( mavenContentHelper, "1.0-alpha-11-20070316.175232-11", storage.getAsset( "org/apache/archiva/metadata/tests/snap_shots_a/1.0-alpha-11-SNAPSHOT" ) | |||
, "", "1.0-alpha-11-SNAPSHOT"); | |||
assertArtifactVersion( mavenContentHelper, "2.2-20070316.153953-10", storage.getAsset( "org/apache/archiva/metadata/tests/snap_shots_b/2.2-SNAPSHOT" ) | |||
, "", "2.2-SNAPSHOT"); | |||
} | |||
private void assertArtifactVersion(MavenContentHelper mavenContentHelper, String expectedVersion, StorageAsset dir, String selectorArtifactVersion, String selectorVersion) { | |||
ItemSelector selector = ArchivaItemSelector.builder( ) | |||
.withVersion( selectorVersion ) | |||
.withArtifactVersion( selectorArtifactVersion ) | |||
.build( ); | |||
assertEquals( expectedVersion, mavenContentHelper.getArtifactVersion( dir, selector ) ); | |||
} | |||
@Test | |||
void getLatestArtifactSnapshotVersion( ) throws URISyntaxException, IOException | |||
{ | |||
MavenContentHelper mavenContentHelper = new MavenContentHelper( ); | |||
MavenMetadataReader reader = new MavenMetadataReader( ); | |||
mavenContentHelper.setMetadataReader( reader ); | |||
Path testRepoPath = Paths.get( Thread.currentThread( ).getContextClassLoader( ).getResource( "repositories/default-repository" ).toURI() ); | |||
FilesystemStorage storage = new FilesystemStorage( testRepoPath, new DefaultFileLockManager( ) ); | |||
// Directory without metadata file | |||
assertEquals( "2.1-20090808.085535-2", mavenContentHelper.getLatestArtifactSnapshotVersion( storage.getAsset( "org/apache/archiva/sample-parent/2.1-SNAPSHOT" ), "2.1-SNAPSHOT" ) ); | |||
// Directory with metadata file | |||
assertEquals( "1.3-20070802.113139-29", mavenContentHelper.getLatestArtifactSnapshotVersion( storage.getAsset( "org/apache/axis2/axis2/1.3-SNAPSHOT" ), "1.3-SNAPSHOT" ) ); | |||
} | |||
@Test | |||
void getArtifactFileName( ) | |||
{ | |||
assertFileName( "test-1.0.jar", "test", "", "1.0", "jar" ); | |||
assertFileName( "test-1.1-client.jar", "test", "client", "1.1", "jar" ); | |||
assertFileName( "te445st-2.1-sources.jar", "te445st", "sources", "2.1", "jar" ); | |||
assertFileName( "abcde-8888.994894.48484-10.jar", "abcde", "", "8888.994894.48484-10", "jar" ); | |||
assertFileName( "testarchive-5.0.war", "testarchive", "", "5.0", "war" ); | |||
} | |||
private void assertFileName(String expectedFilename, String artifactId, String classifier, String version, String extension) { | |||
assertEquals( expectedFilename, MavenContentHelper.getArtifactFileName( artifactId, version, classifier, extension ) ); | |||
} | |||
@Test | |||
void getClassifier( ) | |||
{ | |||
assertClassifier( "sources", "","java-source" ); | |||
assertClassifier( "tests", "", "test-jar" ); | |||
assertClassifier( "client", "","ejb-client" ); | |||
assertClassifier( "javadoc", "","javadoc" ); | |||
assertClassifier( "", "","test" ); | |||
assertClassifier( "test1", "test1","java-source" ); | |||
assertClassifier( "test2", "test2", "test-jar" ); | |||
assertClassifier( "test3", "test3","ejb-client" ); | |||
assertClassifier( "test4", "test4","javadoc" ); | |||
assertClassifier( "test5", "test5","test" ); | |||
} | |||
private void assertClassifier(String expectedClassifier, String classifier, String type) { | |||
ItemSelector selector = ArchivaItemSelector.builder( ) | |||
.withClassifier( classifier ) | |||
.withType( type ).build(); | |||
assertEquals( expectedClassifier, MavenContentHelper.getClassifier( selector ) ); | |||
} | |||
@Test | |||
void getClassifierFromType( ) | |||
{ | |||
assertClassifier( "sources", "java-source" ); | |||
assertClassifier( "tests", "test-jar" ); | |||
assertClassifier( "client", "ejb-client" ); | |||
assertClassifier( "javadoc", "javadoc" ); | |||
assertClassifier( "", "test" ); | |||
} | |||
private void assertClassifier(String expectedClassifier, String type) { | |||
assertEquals( expectedClassifier, MavenContentHelper.getClassifierFromType( type ) ); | |||
} | |||
@Test | |||
void getTypeFromClassifierAndExtension( ) | |||
{ | |||
assertType( "javadoc", "javadoc", "jar" ); | |||
assertType( "war", "", "war" ); | |||
assertType( "ear", "", "ear" ); | |||
assertType( "rar", "", "rar" ); | |||
assertType( "java-source", "sources", "jar" ); | |||
assertType( "ejb-client", "client", "jar" ); | |||
assertType( "pom", "", "pom" ); | |||
assertType( "test-jar", "tests", "jar" ); | |||
} | |||
private void assertType(String expectedType, String classifier, String extension) { | |||
assertEquals( expectedType, MavenContentHelper.getTypeFromClassifierAndExtension( classifier, extension ) ); | |||
} | |||
@Test | |||
void getArtifactExtension( ) | |||
{ | |||
assertExtension( "test", "", "test" ); | |||
assertExtension( "jar", "javadoc", "" ); | |||
assertExtension( "war", "war", "" ); | |||
assertExtension( "ear", "ear", "" ); | |||
assertExtension( "rar", "rar", "" ); | |||
assertExtension( "jar", "", "" ); | |||
} | |||
private void assertExtension( String expectedExtension, String type, String extension ) | |||
{ | |||
ItemSelector selector = ArchivaItemSelector.builder( ) | |||
.withType( type ).withExtension( extension ).build(); | |||
assertEquals( expectedExtension, MavenContentHelper.getArtifactExtension( selector ) ); | |||
} | |||
} |
@@ -24,8 +24,6 @@ import org.apache.archiva.repository.ManagedRepositoryContent; | |||
import org.apache.archiva.repository.RemoteRepository; | |||
import org.apache.archiva.repository.RemoteRepositoryContent; | |||
import org.apache.archiva.repository.content.ItemSelector; | |||
import org.apache.archiva.repository.maven.content.AbstractDefaultRepositoryContentTestCase; | |||
import org.apache.archiva.repository.maven.content.RemoteDefaultRepositoryContent; | |||
import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider; | |||
import org.junit.Before; | |||
@@ -36,7 +34,7 @@ import java.util.List; | |||
* RemoteDefaultRepositoryContentTest | |||
*/ | |||
public class RemoteDefaultRepositoryContentTest | |||
extends AbstractDefaultRepositoryContentTestCase | |||
extends AbstractRepositoryContentTest | |||
{ | |||
@Inject |