aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-maven
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2020-02-13 22:20:35 +0100
committerMartin Stockhammer <martin_s@apache.org>2020-02-13 22:20:35 +0100
commit6823bb0371a3278cfb7bcb834792c21e623183b6 (patch)
tree98c10add81c294fb42e620da40ab7c5cb15ebbfe /archiva-modules/archiva-maven
parent84d9f5723fde9e72ab413d1ef739f1f728b84485 (diff)
downloadarchiva-6823bb0371a3278cfb7bcb834792c21e623183b6.tar.gz
archiva-6823bb0371a3278cfb7bcb834792c21e623183b6.zip
Adding selector interface for repository content
Diffstat (limited to 'archiva-modules/archiva-maven')
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java7
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java15
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java10
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/AbstractDefaultRepositoryContent.java41
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java2
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractDefaultRepositoryContentTestCase.java19
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java6
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/RemoteDefaultRepositoryContentTest.java6
8 files changed, 104 insertions, 2 deletions
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
index f26334577..881e90fea 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
@@ -28,6 +28,7 @@ import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.model.ProjectReference;
import org.apache.archiva.model.VersionedReference;
import org.apache.archiva.repository.*;
+import org.apache.archiva.repository.content.ItemSelector;
import org.apache.archiva.repository.storage.FilesystemStorage;
import org.apache.archiva.repository.storage.RepositoryStorage;
import org.apache.archiva.repository.storage.StorageAsset;
@@ -451,6 +452,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
}
@Override
+ public String toPath( ItemSelector selector )
+ {
+ return null;
+ }
+
+ @Override
public String toPath( ArchivaArtifact reference )
{
return null;
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java
index 4ab4a5aae..78fff18db 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java
@@ -25,6 +25,7 @@ import org.apache.archiva.model.RepositoryURL;
import org.apache.archiva.repository.LayoutException;
import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.RemoteRepositoryContent;
+import org.apache.archiva.repository.content.ItemSelector;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@@ -85,6 +86,20 @@ public class RemoteRepositoryContentMock implements RemoteRepositoryContent
}
@Override
+ public String toPath( ItemSelector selector )
+ {
+ String baseVersion;
+ if (!selector.hasVersion() && VersionUtil.isSnapshot(selector.getArtifactVersion())) {
+ baseVersion=VersionUtil.getBaseVersion(selector.getArtifactVersion());
+ } else {
+ baseVersion=selector.getVersion();
+ }
+ return selector.getNamespace().replaceAll("\\.", "/")+"/"+selector.getArtifactId()+"/"+baseVersion+"/"
+ +selector.getArtifactId()+"-"+selector.getVersion()+(
+ StringUtils.isNotEmpty(selector.getClassifier()) ? "-"+selector.getClassifier() : "")+"."+selector.getType();
+ }
+
+ @Override
public RepositoryURL toURL( ArtifactReference reference )
{
return null;
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java
index 7d728f9fc..eb72653c5 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java
@@ -24,6 +24,7 @@ import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.maven2.MavenArtifactFacet;
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
import org.apache.archiva.repository.storage.StorageAsset;
+import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@@ -140,12 +141,17 @@ public class Maven2RepositoryPathTranslator
private void appendNamespaceAndProject( StringBuilder path, String namespace, String projectId )
{
appendNamespace( path, namespace );
- path.append( projectId ).append( PATH_SEPARATOR );
+ if (StringUtils.isNotEmpty( projectId ))
+ {
+ path.append( projectId ).append( PATH_SEPARATOR );
+ }
}
private void appendNamespace( StringBuilder path, String namespace )
{
- path.append( formatAsDirectory( namespace ) ).append( PATH_SEPARATOR );
+ if ( StringUtils.isNotEmpty( namespace ) ) {
+ path.append( formatAsDirectory( namespace ) ).append( PATH_SEPARATOR );
+ }
}
@Override
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/AbstractDefaultRepositoryContent.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/AbstractDefaultRepositoryContent.java
index 0919fcadb..1713ec77c 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/AbstractDefaultRepositoryContent.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/AbstractDefaultRepositoryContent.java
@@ -29,7 +29,9 @@ import org.apache.archiva.model.ProjectReference;
import org.apache.archiva.model.VersionedReference;
import org.apache.archiva.repository.LayoutException;
import org.apache.archiva.repository.RepositoryContent;
+import org.apache.archiva.repository.content.ItemSelector;
import org.apache.archiva.repository.content.PathParser;
+import org.apache.archiva.repository.content.Version;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -86,6 +88,45 @@ public abstract class AbstractDefaultRepositoryContent implements RepositoryCont
return path.toString( );
}
+ @Override
+ public String toPath ( ItemSelector selector ) {
+ if (selector==null) {
+ throw new IllegalArgumentException( "ItemSelector must not be null." );
+ }
+ String projectId;
+ // Initialize the project id if not set
+ if (selector.hasProjectId()) {
+ projectId = selector.getProjectId( );
+ } else if (selector.hasArtifactId()) {
+ // projectId same as artifact id, if set
+ projectId = selector.getArtifactId( );
+ } else {
+ // we arrive here, if projectId && artifactId not set
+ return pathTranslator.toPath( selector.getNamespace(), "");
+ }
+ if ( !selector.hasArtifactId( )) {
+ return pathTranslator.toPath( selector.getNamespace( ), projectId );
+ }
+ // this part only, if projectId && artifactId is set
+ String artifactVersion = "";
+ String version = "";
+ if (selector.hasVersion() && selector.hasArtifactVersion() ) {
+ artifactVersion = selector.getArtifactVersion();
+ version = VersionUtil.getBaseVersion( selector.getVersion( ) );
+ } else if (!selector.hasVersion() && selector.hasArtifactVersion()) {
+ // we try to retrieve the base version, if artifact version is only set
+ version = VersionUtil.getBaseVersion( selector.getArtifactVersion( ) );
+ artifactVersion = selector.getArtifactVersion( );
+ } else if (selector.hasVersion() && !selector.hasArtifactVersion()) {
+ artifactVersion = selector.getVersion();
+ version = VersionUtil.getBaseVersion( selector.getVersion( ) );
+ }
+
+ return pathTranslator.toPath( selector.getNamespace(), projectId, version,
+ constructId( selector.getArtifactId(), artifactVersion, selector.getClassifier(), selector.getType() ) );
+
+ }
+
public String toMetadataPath( ProjectReference reference )
{
final StringBuilder path = new StringBuilder();
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java
index ba14ac075..cfb37a064 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java
@@ -34,6 +34,7 @@ import org.apache.archiva.repository.EditableManagedRepository;
import org.apache.archiva.repository.LayoutException;
import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.content.ItemSelector;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.commons.lang3.StringUtils;
@@ -572,6 +573,7 @@ public class ManagedDefaultRepositoryContent
}
}
+
// The variant with runtime exception for stream usage
private ArtifactReference toArtifactRef(String path) {
try {
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractDefaultRepositoryContentTestCase.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractDefaultRepositoryContentTestCase.java
index cd1044b97..d697815e5 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractDefaultRepositoryContentTestCase.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractDefaultRepositoryContentTestCase.java
@@ -22,6 +22,7 @@ package org.apache.archiva.metadata.repository.storage.maven2;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.repository.AbstractRepositoryLayerTestCase;
import org.apache.archiva.repository.LayoutException;
+import org.apache.archiva.repository.content.ItemSelector;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
@@ -415,6 +416,21 @@ public abstract class AbstractDefaultRepositoryContentTestCase
}
}
+ public void testToPathOnNullItemSelector()
+
+ {
+ try
+ {
+ ItemSelector selector = null;
+ toPath( selector );
+ fail( "Should have failed due to null artifact reference." );
+ }
+ catch ( IllegalArgumentException e )
+ {
+ /* expected path */
+ }
+ }
+
private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
String version, String classifier, String type )
{
@@ -488,4 +504,7 @@ public abstract class AbstractDefaultRepositoryContentTestCase
throws LayoutException;
protected abstract String toPath( ArtifactReference reference );
+
+
+ protected abstract String toPath( ItemSelector selector );
}
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java
index 03a9b428f..baa518e94 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java
@@ -29,6 +29,7 @@ import org.apache.archiva.model.ProjectReference;
import org.apache.archiva.model.VersionedReference;
import org.apache.archiva.repository.EditableManagedRepository;
import org.apache.archiva.repository.LayoutException;
+import org.apache.archiva.repository.content.ItemSelector;
import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent;
import org.apache.archiva.repository.maven2.MavenManagedRepository;
import org.apache.commons.io.FileUtils;
@@ -259,6 +260,11 @@ public class ManagedDefaultRepositoryContentTest
return repoContent.toPath( reference );
}
+ @Override
+ protected String toPath( ItemSelector selector ) {
+ return repoContent.toPath( selector );
+ }
+
private Path setupRepoCopy( String source, String target) throws IOException
{
Path defaultRepo = getRepositoryPath( source );
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/RemoteDefaultRepositoryContentTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/RemoteDefaultRepositoryContentTest.java
index 42a5b26a9..33f845687 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/RemoteDefaultRepositoryContentTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/RemoteDefaultRepositoryContentTest.java
@@ -23,6 +23,7 @@ import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.repository.LayoutException;
import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.RemoteRepositoryContent;
+import org.apache.archiva.repository.content.ItemSelector;
import org.apache.archiva.repository.content.maven2.RemoteDefaultRepositoryContent;
import org.junit.Before;
@@ -65,4 +66,9 @@ public class RemoteDefaultRepositoryContentTest
{
return repoContent.toPath( reference );
}
+
+ @Override
+ protected String toPath( ItemSelector selector ) {
+ return repoContent.toPath( selector );
+ }
}