} | } | ||||
@Override | |||||
public ContentItem toItem( String path ) throws LayoutException | |||||
{ | |||||
return null; | |||||
} | |||||
@Override | |||||
public ContentItem toItem( StorageAsset assetPath ) throws LayoutException | |||||
{ | |||||
return null; | |||||
} | |||||
@Override | @Override | ||||
public void deleteGroupId( String groupId ) throws ContentNotFoundException, ContentAccessException | public void deleteGroupId( String groupId ) throws ContentNotFoundException, ContentAccessException |
public StorageAsset getAsset( String path ) | public StorageAsset getAsset( String path ) | ||||
{ | { | ||||
try { | try { | ||||
return new FilesystemAsset(this, path, getAssetPath(path)); | |||||
return new FilesystemAsset(this, path, getAssetPath(path), basePath); | |||||
} catch (IOException e) { | } catch (IOException e) { | ||||
throw new IllegalArgumentException("Path navigates outside of base directory "+path); | throw new IllegalArgumentException("Path navigates outside of base directory "+path); | ||||
} | } |
} | } | ||||
@Override | |||||
public ContentItem toItem( String path ) throws LayoutException | |||||
{ | |||||
return null; | |||||
} | |||||
@Override | |||||
public ContentItem toItem( StorageAsset assetPath ) throws LayoutException | |||||
{ | |||||
return null; | |||||
} | |||||
@Override | @Override | ||||
public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException | public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException | ||||
{ | { |
} | } | ||||
/** | |||||
* 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 | @Override | ||||
public void deleteItem( ContentItem item ) throws ItemNotFoundException, ContentAccessException | public void deleteItem( ContentItem item ) throws ItemNotFoundException, ContentAccessException | ||||
{ | { | ||||
} | } | ||||
} | } | ||||
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 | @Override | ||||
public Namespace getNamespace( final ItemSelector namespaceSelector ) throws ContentAccessException, IllegalArgumentException | public Namespace getNamespace( final ItemSelector namespaceSelector ) throws ContentAccessException, IllegalArgumentException | ||||
{ | { | ||||
final String artifactVersion = mavenContentHelper.getArtifactVersion( artifactDir, selector ); | final String artifactVersion = mavenContentHelper.getArtifactVersion( artifactDir, selector ); | ||||
final String classifier = MavenContentHelper.getClassifier( selector ); | final String classifier = MavenContentHelper.getClassifier( selector ); | ||||
final String extension = MavenContentHelper.getArtifactExtension( 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( ), | final StorageAsset path = getAsset( selector.getNamespace( ), selector.getProjectId( ), | ||||
selector.getVersion( ), fileName ); | selector.getVersion( ), fileName ); | ||||
return artifactMap.computeIfAbsent( path, artifactPath -> createArtifact( path, selector, classifier, extension ) ); | return artifactMap.computeIfAbsent( path, artifactPath -> createArtifact( path, selector, classifier, extension ) ); | ||||
return getItemFromPath( assetPath ); | 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 | @Override | ||||
public void deleteVersion( VersionedReference ref ) throws ContentNotFoundException, ContentAccessException | public void deleteVersion( VersionedReference ref ) throws ContentNotFoundException, ContentAccessException | ||||
{ | { |
import javax.inject.Inject; | import javax.inject.Inject; | ||||
import javax.inject.Named; | import javax.inject.Named; | ||||
import java.util.Comparator; | |||||
import java.util.LinkedList; | import java.util.LinkedList; | ||||
import java.util.regex.Pattern; | |||||
/** | /** | ||||
* Helper class that contains certain maven specific methods | * Helper class that contains certain maven specific methods | ||||
{ | { | ||||
private static final Logger log = LoggerFactory.getLogger( MavenContentHelper.class ); | 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 | @Inject | ||||
@Named( "metadataReader#maven" ) | @Named( "metadataReader#maven" ) | ||||
} | } | ||||
public void setMetadataReader( MavenMetadataReader metadataReader ) | |||||
{ | |||||
this.metadataReader = metadataReader; | |||||
} | |||||
/** | /** | ||||
* Returns the namespace string for a given path in the repository | * Returns the namespace string for a given path in the repository | ||||
* | * | ||||
StorageAsset current = namespacePath; | StorageAsset current = namespacePath; | ||||
while (current.hasParent()) { | while (current.hasParent()) { | ||||
names.addFirst( current.getName() ); | names.addFirst( current.getName() ); | ||||
current = current.getParent( ); | |||||
} | } | ||||
return String.join( ".", names ); | return String.join( ".", names ); | ||||
} | } | ||||
// re-adjust to timestamp if present, otherwise retain the original -SNAPSHOT filename | // re-adjust to timestamp if present, otherwise retain the original -SNAPSHOT filename | ||||
SnapshotVersion metadataVersion = metadata.getSnapshotVersion( ); | 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( 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 ) | catch ( RepositoryMetadataException e ) | ||||
{ | { | ||||
// unable to parse metadata - LOGGER it, and continue with the version as the original SNAPSHOT version | // unable to parse metadata - LOGGER it, and continue with the version as the original SNAPSHOT version | ||||
log.warn( "Invalid metadata: {} - {}", metadataFile, e.getMessage( ) ); | 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. | * 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 artifactVersion the artifactVersion | ||||
* @param classifier the artifact classifier | * @param classifier the artifact classifier | ||||
* @param extension the file extension | * @param extension the file extension | ||||
*/ | */ | ||||
static String getArtifactFileName( ItemSelector selector, String artifactVersion, | |||||
static String getArtifactFileName( String artifactId, String artifactVersion, | |||||
String classifier, String extension ) | String classifier, String extension ) | ||||
{ | { | ||||
StringBuilder fileName = new StringBuilder( selector.getArtifactId( ) ).append( "-" ); | |||||
StringBuilder fileName = new StringBuilder( artifactId ).append( "-" ); | |||||
fileName.append( artifactVersion ); | fileName.append( artifactVersion ); | ||||
if ( !StringUtils.isEmpty( classifier ) ) | if ( !StringUtils.isEmpty( classifier ) ) | ||||
{ | { | ||||
*/ | */ | ||||
static String getClassifierFromType( final String type ) | 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 ""; | |||||
} | } | ||||
} | } | ||||
/** | /** | ||||
{ | { | ||||
return "ejb-client"; | return "ejb-client"; | ||||
} | } | ||||
else if ( classifier.equals( "source" ) && extension.equals( "jar" ) ) | |||||
else if ( classifier.equals( "sources" ) && extension.equals( "jar" ) ) | |||||
{ | { | ||||
return "java-source"; | return "java-source"; | ||||
} | } | ||||
} | } | ||||
else if ( selector.hasType( ) ) | 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 | else |
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 */ | |||||
} | |||||
} | |||||
} |
/** | /** | ||||
* AbstractDefaultRepositoryContentTestCase | * AbstractDefaultRepositoryContentTestCase | ||||
*/ | */ | ||||
public abstract class AbstractDefaultRepositoryContentTestCase | |||||
public abstract class AbstractRepositoryContentTest | |||||
extends AbstractRepositoryLayerTestCase | extends AbstractRepositoryLayerTestCase | ||||
{ | { | ||||
@Test | @Test | ||||
public void testBadPathMissingType() | public void testBadPathMissingType() | ||||
{ | { | ||||
assertBadPath( "invalid/invalid/1/invalid-1", "missing type" ); | assertBadPath( "invalid/invalid/1/invalid-1", "missing type" ); | ||||
assertBadPathCi( "invalid/invalid/1/invalid-1", "missing type" ); | |||||
} | } | ||||
@Test | @Test | ||||
{ | { | ||||
assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", | assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", | ||||
"non snapshot artifact inside of a snapshot dir" ); | "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 | @Test | ||||
{ | { | ||||
assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar", | assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar", | ||||
"Timestamped Snapshot artifact not inside of an Snapshot dir" ); | "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 | @Test | ||||
} | } | ||||
} | } | ||||
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. | * Perform a roundtrip through the layout routines to determine success. | ||||
*/ | */ |
* ManagedDefaultRepositoryContentTest | * ManagedDefaultRepositoryContentTest | ||||
*/ | */ | ||||
public class ManagedDefaultRepositoryContentTest | public class ManagedDefaultRepositoryContentTest | ||||
extends AbstractDefaultRepositoryContentTestCase | |||||
extends AbstractManagedRepositoryContentTest | |||||
{ | { | ||||
private ManagedDefaultRepositoryContent repoContent; | private ManagedDefaultRepositoryContent repoContent; | ||||
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 ) ); | |||||
} | |||||
} |
import org.apache.archiva.repository.RemoteRepository; | import org.apache.archiva.repository.RemoteRepository; | ||||
import org.apache.archiva.repository.RemoteRepositoryContent; | import org.apache.archiva.repository.RemoteRepositoryContent; | ||||
import org.apache.archiva.repository.content.ItemSelector; | 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.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider; | ||||
import org.junit.Before; | import org.junit.Before; | ||||
* RemoteDefaultRepositoryContentTest | * RemoteDefaultRepositoryContentTest | ||||
*/ | */ | ||||
public class RemoteDefaultRepositoryContentTest | public class RemoteDefaultRepositoryContentTest | ||||
extends AbstractDefaultRepositoryContentTestCase | |||||
extends AbstractRepositoryContentTest | |||||
{ | { | ||||
@Inject | @Inject |