aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2020-06-16 10:32:06 +0200
committerMartin Stockhammer <martin_s@apache.org>2020-06-16 10:32:06 +0200
commit7a9803bf0f648db101ff9e76ef6a0f0bb2ecf09d (patch)
tree8ad8ae8ea3380acbec222a862562a0ec6c6f396a /archiva-modules
parentfbca0e89f9db5d20dcb096d2fbf7391160f48fd2 (diff)
downloadarchiva-7a9803bf0f648db101ff9e76ef6a0f0bb2ecf09d.tar.gz
archiva-7a9803bf0f648db101ff9e76ef6a0f0bb2ecf09d.zip
Switching to itemselector for repository API
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContent.java9
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java7
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java7
-rw-r--r--archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java7
-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/repository/maven/content/AbstractDefaultRepositoryContent.java19
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java21
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java3
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java34
10 files changed, 33 insertions, 96 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContent.java
index c30550eb3..a4e98da9f 100644
--- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContent.java
+++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContent.java
@@ -31,15 +31,6 @@ public interface RepositoryContent
/**
- * Given an {@link ArtifactReference}, return the relative path to the artifact.
- *
- * @param reference the artifact reference to use.
- * @return the relative path to the artifact.
- */
- String toPath( ArtifactReference reference );
-
-
- /**
* Return the path, that represents the item specified by the selector.
* @param selector the selector with the artifact coordinates
* @return the path to the content item
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
index ebb043aea..e0ba18035 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
@@ -19,7 +19,6 @@ package org.apache.archiva.repository.mock;
* under the License.
*/
-import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.repository.ContentAccessException;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.ItemDeleteStatus;
@@ -328,12 +327,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout
}
@Override
- public String toPath( ArtifactReference reference )
- {
- return null;
- }
-
- @Override
public String toPath( ItemSelector selector )
{
return null;
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java
index 3fc507a6f..e9410c460 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java
@@ -19,7 +19,6 @@ package org.apache.archiva.repository.mock;
* under the License.
*/
-import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.model.RepositoryURL;
import org.apache.archiva.repository.LayoutException;
import org.apache.archiva.repository.RemoteRepository;
@@ -60,12 +59,6 @@ public class RemoteRepositoryContentMock implements RemoteRepositoryContent
}
@Override
- public String toPath( ArtifactReference reference )
- {
- return null;
- }
-
- @Override
public String toPath( ItemSelector selector )
{
return null;
diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java
index acc4204ca..ec32d1d24 100644
--- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java
+++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java
@@ -40,7 +40,6 @@ import org.apache.archiva.repository.content.base.ArchivaProject;
import org.apache.archiva.repository.content.base.ArchivaVersion;
import org.apache.archiva.repository.storage.fs.FilesystemStorage;
import org.apache.archiva.repository.storage.StorageAsset;
-import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.nio.file.Path;
@@ -511,12 +510,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout
}
@Override
- public String toPath( ArtifactReference reference )
- {
- return null;
- }
-
- @Override
public String toPath( ItemSelector selector )
{
return null;
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 11a7bf06f..bc506b15d 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
@@ -43,7 +43,6 @@ import org.apache.archiva.repository.content.base.ArchivaVersion;
import org.apache.archiva.repository.storage.fs.FilesystemStorage;
import org.apache.archiva.repository.storage.RepositoryStorage;
import org.apache.archiva.repository.storage.StorageAsset;
-import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.io.IOException;
@@ -544,12 +543,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout
}
@Override
- public String toPath( ArtifactReference reference )
- {
- return null;
- }
-
- @Override
public String toPath( ItemSelector selector )
{
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 9312aaa68..6e51de0c0 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
@@ -20,7 +20,6 @@ package org.apache.archiva.repository.mock;
*/
import org.apache.archiva.common.utils.VersionUtil;
-import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.model.RepositoryURL;
import org.apache.archiva.repository.LayoutException;
import org.apache.archiva.repository.RemoteRepository;
@@ -66,20 +65,6 @@ public class RemoteRepositoryContentMock implements RemoteRepositoryContent
}
@Override
- public String toPath( ArtifactReference reference )
- {
- String baseVersion;
- if (VersionUtil.isSnapshot(reference.getVersion())) {
- baseVersion=VersionUtil.getBaseVersion(reference.getVersion());
- } else {
- baseVersion=reference.getVersion();
- }
- return reference.getGroupId().replaceAll("\\.", "/")+"/"+reference.getArtifactId()+"/"+baseVersion+"/"
- +reference.getArtifactId()+"-"+reference.getVersion()+(
- StringUtils.isNotEmpty(reference.getClassifier()) ? "-"+reference.getClassifier() : "")+"."+reference.getType();
- }
-
- @Override
public String toPath( ItemSelector selector )
{
String baseVersion;
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/AbstractDefaultRepositoryContent.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/AbstractDefaultRepositoryContent.java
index 01949dea0..be7ae29ba 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/AbstractDefaultRepositoryContent.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/AbstractDefaultRepositoryContent.java
@@ -22,7 +22,6 @@ import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
import org.apache.archiva.repository.content.base.ArchivaItemSelector;
import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
-import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.repository.LayoutException;
import org.apache.archiva.repository.RepositoryContent;
import org.apache.archiva.repository.content.ItemSelector;
@@ -310,24 +309,6 @@ public abstract class AbstractDefaultRepositoryContent implements RepositoryCont
return formatAsDirectory( namespace );
}
- @Override
- public String toPath( ArtifactReference reference )
- {
- if ( reference == null )
- {
- throw new IllegalArgumentException( "Artifact reference cannot be null" );
- }
- if ( reference.getVersion() != null )
- {
- String baseVersion = VersionUtil.getBaseVersion( reference.getVersion() );
- return toPath( reference.getGroupId(), reference.getArtifactId(), baseVersion, reference.getVersion(),
- reference.getClassifier(), reference.getType() );
- }
- return toPath( reference.getGroupId(), reference.getArtifactId(), null, null,
- reference.getClassifier(), reference.getType() );
- }
-
-
protected String formatAsDirectory( String directory )
{
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java
index cfc7354c8..07affa7c4 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java
@@ -796,17 +796,28 @@ public class ManagedDefaultRepositoryContent
}
@Override
- public Artifact getArtifact( final ItemSelector selector ) throws ContentAccessException
+ public Artifact getArtifact( final ItemSelector selectorArg ) throws ContentAccessException
{
- if ( !selector.hasProjectId( ) )
+ ItemSelector selector = selectorArg;
+ if ( !selectorArg.hasProjectId( ) )
{
throw new IllegalArgumentException( "Project id must be set" );
}
- if ( !selector.hasVersion( ) )
+ if ( !selectorArg.hasVersion( ) )
{
- throw new IllegalArgumentException( "Version must be set" );
+ if (selectorArg.hasArtifactVersion() && VersionUtil.isSnapshot( selectorArg.getArtifactVersion() )) {
+ selector = ArchivaItemSelector.builder( ).withSelector( selectorArg )
+ .withVersion( VersionUtil.getBaseVersion( selectorArg.getArtifactVersion( ) ) ).build();
+ } else if (selectorArg.hasArtifactVersion()) {
+ selector = ArchivaItemSelector.builder( ).withSelector( selectorArg )
+ .withVersion( selectorArg.getArtifactVersion( ) ).build();
+
+ } else
+ {
+ throw new IllegalArgumentException( "Version must be set" );
+ }
}
- if ( !selector.hasArtifactId( ) )
+ if ( !selectorArg.hasArtifactId( ) )
{
throw new IllegalArgumentException( "Artifact id must be set" );
}
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java
index 3344df005..279a26c5d 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java
@@ -154,7 +154,7 @@ public class ManagedDefaultRepositoryContentTest
{
try
{
- ArtifactReference reference = null;
+ ItemSelector reference = null;
repoContent.toPath( reference );
fail( "Should have failed due to null artifact reference." );
}
@@ -297,7 +297,6 @@ public class ManagedDefaultRepositoryContentTest
.withNamespace( "org.apache.maven" )
.withProjectId( "shared" )
.withArtifactId( "shared" )
- .withArtifactVersion("1.0")
.build();
try
{
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
index 60467bcc7..bf10591f1 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
@@ -54,6 +54,7 @@ import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.content.ContentItem;
import org.apache.archiva.repository.content.ItemNotFoundException;
+import org.apache.archiva.repository.content.ItemSelector;
import org.apache.archiva.repository.content.Version;
import org.apache.archiva.repository.content.base.ArchivaItemSelector;
import org.apache.archiva.repository.storage.fs.FsStorageUtil;
@@ -361,13 +362,16 @@ public class DefaultRepositoriesService
// sounds good we can continue !
- ArtifactReference artifactReference = new ArtifactReference();
- artifactReference.setArtifactId( artifactTransferRequest.getArtifactId() );
- artifactReference.setGroupId( artifactTransferRequest.getGroupId() );
- artifactReference.setVersion( artifactTransferRequest.getVersion() );
- artifactReference.setClassifier( artifactTransferRequest.getClassifier() );
String packaging = StringUtils.trim( artifactTransferRequest.getPackaging() );
- artifactReference.setType( StringUtils.isEmpty( packaging ) ? "jar" : packaging );
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withProjectId( artifactTransferRequest.getArtifactId( ) )
+ .withArtifactId( artifactTransferRequest.getArtifactId( ) )
+ .withNamespace( artifactTransferRequest.getGroupId( ) )
+ .withArtifactVersion( artifactTransferRequest.getVersion( ) )
+ .withClassifier( artifactTransferRequest.getClassifier( ) )
+ .withExtension( StringUtils.isEmpty( packaging ) ? "jar" : packaging )
+ .build( );
+
try
{
@@ -375,28 +379,22 @@ public class DefaultRepositoriesService
ManagedRepositoryContent sourceRepository =
getManagedRepositoryContent( artifactTransferRequest.getRepositoryId() );
BaseRepositoryContentLayout layout = sourceRepository.getLayout( BaseRepositoryContentLayout.class );
- String artifactSourcePath = sourceRepository.toPath( artifactReference );
+ // String artifactSourcePath = sourceRepository.toPath( selector );
+ org.apache.archiva.repository.content.Artifact sourceArtifact = layout.getArtifact( selector );
- if ( StringUtils.isEmpty( artifactSourcePath ) )
+ if ( !sourceArtifact.exists() )
{
log.error( "cannot find artifact {}", artifactTransferRequest );
throw new ArchivaRestServiceException( "cannot find artifact " + artifactTransferRequest.toString(),
null );
}
- StorageAsset artifactFile = source.getAsset( artifactSourcePath );
-
- if ( !artifactFile.exists() )
- {
- log.error( "cannot find artifact {}", artifactTransferRequest );
- throw new ArchivaRestServiceException( "cannot find artifact " + artifactTransferRequest.toString(),
- null );
- }
+ StorageAsset artifactFile = sourceArtifact.getAsset( );
ManagedRepositoryContent targetRepository =
getManagedRepositoryContent( artifactTransferRequest.getTargetRepositoryId() );
- String artifactPath = sourceRepository.toPath( artifactReference );
+ String artifactPath = artifactFile.getPath( );
int lastIndex = artifactPath.lastIndexOf( '/' );
@@ -444,7 +442,7 @@ public class DefaultRepositoriesService
pomFilename = FilenameUtils.removeExtension( pomFilename ) + ".pom";
StorageAsset pomFile = source.getAsset(
- artifactSourcePath.substring( 0, artifactPath.lastIndexOf( '/' ) )+"/"+ pomFilename );
+ artifactPath.substring( 0, artifactPath.lastIndexOf( '/' ) )+"/"+ pomFilename );
if ( pomFile != null && pomFile.exists() )
{