aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web/archiva-rest
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2020-05-30 19:58:46 +0200
committerMartin Stockhammer <martin_s@apache.org>2020-05-30 20:00:22 +0200
commit6d7a510dea283ff8c4b1e6ae54a395dbe386e4a5 (patch)
tree706add65520704a887961e65c5d2b7d31ac34e46 /archiva-modules/archiva-web/archiva-rest
parentac25c7a86fe77f5b0f005f03d9d28dc1f6f8580e (diff)
downloadarchiva-6d7a510dea283ff8c4b1e6ae54a395dbe386e4a5.tar.gz
archiva-6d7a510dea283ff8c4b1e6ae54a395dbe386e4a5.zip
Refactoring of content interfaces. Adding layout for repository content.
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rest')
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java2
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java39
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java53
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactBuilder.java15
4 files changed, 72 insertions, 37 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java
index 5e69784c5..f5b85353d 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java
@@ -36,8 +36,8 @@ import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import org.apache.archiva.redback.rest.services.RedbackAuthenticationThreadLocal;
import org.apache.archiva.redback.rest.services.RedbackRequestInformation;
import org.apache.archiva.redback.users.User;
-import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.metadata.audit.AuditListener;
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
index 9fb193eba..76fd075c0 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
@@ -21,6 +21,8 @@ package org.apache.archiva.rest.services;
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.common.utils.VersionComparator;
import org.apache.archiva.common.utils.VersionUtil;
+import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.content.base.ArchivaItemSelector;
import org.apache.archiva.repository.maven.dependency.tree.DependencyTreeBuilder;
import org.apache.archiva.maven2.model.Artifact;
import org.apache.archiva.maven2.model.TreeEntry;
@@ -32,12 +34,10 @@ import org.apache.archiva.metadata.model.ProjectVersionReference;
import org.apache.archiva.metadata.repository.*;
import org.apache.archiva.repository.maven.metadata.storage.ArtifactMetadataVersionComparator;
import org.apache.archiva.repository.maven.metadata.storage.MavenProjectFacet;
-import org.apache.archiva.model.ArchivaArtifact;
import org.apache.archiva.model.ArchivaRepositoryMetadata;
import org.apache.archiva.proxy.ProxyRegistry;
import org.apache.archiva.proxy.model.RepositoryProxyHandler;
import org.apache.archiva.components.cache.Cache;
-import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryNotFoundException;
@@ -93,7 +93,7 @@ public class DefaultBrowseService
@Named( value = "browse#versionMetadata" )
private Cache<String, ProjectVersionMetadata> versionMetadataCache;
- private ManagedRepositoryContent getManagedRepositoryContent(String id) throws RepositoryException
+ private ManagedRepositoryContent getManagedRepositoryContent( String id) throws RepositoryException
{
org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository( id );
if (repo==null) {
@@ -746,10 +746,12 @@ public class DefaultBrowseService
ManagedRepositoryContent managedRepositoryContent =
getManagedRepositoryContent( repoId );
- ArchivaArtifact archivaArtifact = new ArchivaArtifact( groupId, artifactId, version, classifier,
- StringUtils.isEmpty( type ) ? "jar" : type,
- repoId );
- StorageAsset file = managedRepositoryContent.toFile( archivaArtifact );
+ ArchivaItemSelector itemSelector = ArchivaItemSelector.builder( ).withNamespace( groupId )
+ .withProjectId( artifactId ).withVersion( version ).withClassifier( classifier )
+ .withType( StringUtils.isEmpty( type ) ? "jar" : type )
+ .withArtifactId( artifactId ).build();
+ org.apache.archiva.repository.content.Artifact archivaArtifact = managedRepositoryContent.getItem( itemSelector ).adapt( org.apache.archiva.repository.content.Artifact.class );
+ StorageAsset file = archivaArtifact.getAsset();
if ( file.exists() )
{
return readFileEntries( file, path, repoId );
@@ -835,10 +837,12 @@ public class DefaultBrowseService
log.error("No repository content found for "+repoId);
continue;
}
- ArchivaArtifact archivaArtifact = new ArchivaArtifact( groupId, artifactId, version, classifier,
- StringUtils.isEmpty( type ) ? "jar" : type,
- repoId );
- StorageAsset file = managedRepositoryContent.toFile( archivaArtifact );
+ ArchivaItemSelector itemSelector = ArchivaItemSelector.builder( ).withNamespace( groupId )
+ .withProjectId( artifactId ).withVersion( version ).withClassifier( classifier )
+ .withType( StringUtils.isEmpty( type ) ? "jar" : type )
+ .withArtifactId( artifactId ).build();
+ org.apache.archiva.repository.content.Artifact archivaArtifact = managedRepositoryContent.getItem( itemSelector ).adapt( org.apache.archiva.repository.content.Artifact.class );
+ StorageAsset file = archivaArtifact.getAsset( );
if ( !file.exists() )
{
log.debug( "file: {} not exists for repository: {} try next repository", file, repoId );
@@ -905,11 +909,14 @@ public class DefaultBrowseService
ManagedRepositoryContent managedRepositoryContent = getManagedRepositoryContent( repoId );
// FIXME default to jar which can be wrong for war zip etc....
- ArchivaArtifact archivaArtifact = new ArchivaArtifact( groupId, artifactId, version,
- StringUtils.isEmpty( classifier )
- ? ""
- : classifier, "jar", repoId );
- StorageAsset file = managedRepositoryContent.toFile( archivaArtifact );
+ ArchivaItemSelector itemSelector = ArchivaItemSelector.builder( ).withNamespace( groupId )
+ .withProjectId( artifactId ).withVersion( version ).withClassifier( StringUtils.isEmpty( classifier )
+ ? ""
+ : classifier )
+ .withType( "jar" )
+ .withArtifactId( artifactId ).build();
+ org.apache.archiva.repository.content.Artifact archivaArtifact = managedRepositoryContent.getItem( itemSelector ).adapt( org.apache.archiva.repository.content.Artifact.class );
+ StorageAsset file = archivaArtifact.getAsset( );
if ( file != null && file.exists() )
{
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 6c0f7c124..f6d11dcbc 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
@@ -44,13 +44,15 @@ import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.archiva.repository.ContentNotFoundException;
+import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.LayoutException;
import org.apache.archiva.repository.ManagedRepository;
-import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.BaseRepositoryContentLayout;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryNotFoundException;
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.Version;
import org.apache.archiva.repository.content.base.ArchivaItemSelector;
@@ -189,7 +191,7 @@ public class DefaultRepositoriesService
}
}
- private ManagedRepositoryContent getManagedRepositoryContent(String id) throws RepositoryException
+ private ManagedRepositoryContent getManagedRepositoryContent( String id) throws RepositoryException
{
org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository( id );
if (repo==null) {
@@ -372,8 +374,8 @@ public class DefaultRepositoriesService
ManagedRepositoryContent sourceRepository =
getManagedRepositoryContent( artifactTransferRequest.getRepositoryId() );
-
- String artifactSourcePath = sourceRepository.toPath( artifactReference );
+ BaseRepositoryContentLayout layout = sourceRepository.getLayout( BaseRepositoryContentLayout.class );
+ String artifactSourcePath = layout.toPath( artifactReference );
if ( StringUtils.isEmpty( artifactSourcePath ) )
{
@@ -394,7 +396,7 @@ public class DefaultRepositoriesService
ManagedRepositoryContent targetRepository =
getManagedRepositoryContent( artifactTransferRequest.getTargetRepositoryId() );
- String artifactPath = targetRepository.toPath( artifactReference );
+ String artifactPath = layout.toPath( artifactReference );
int lastIndex = artifactPath.lastIndexOf( '/' );
@@ -469,7 +471,7 @@ public class DefaultRepositoriesService
log.debug("copyArtifact {}", msg);
}
- catch ( RepositoryException e )
+ catch ( RepositoryException | LayoutException e )
{
log.error( "RepositoryException: {}", e.getMessage(), e );
throw new ArchivaRestServiceException( e.getMessage(), e );
@@ -663,14 +665,14 @@ public class DefaultRepositoriesService
try
{
ManagedRepositoryContent repository = getManagedRepositoryContent( repositoryId );
-
+ BaseRepositoryContentLayout layout = repository.getLayout( BaseRepositoryContentLayout.class );
ArchivaItemSelector selector = ArchivaItemSelector.builder( )
.withNamespace( namespace )
.withProjectId( projectId )
.withVersion( version )
.build( );
- Version versionItem = repository.getVersion( selector );
+ Version versionItem = layout.getVersion( selector );
if (versionItem!=null && versionItem.exists()) {
repository.deleteItem( versionItem );
}
@@ -687,7 +689,7 @@ public class DefaultRepositoriesService
metadataRepository.removeProjectVersion(repositorySession , repositoryId, namespace, projectId, version );
}
- catch ( MetadataRepositoryException | MetadataResolutionException | RepositoryException | ItemNotFoundException e )
+ catch ( MetadataRepositoryException | MetadataResolutionException | RepositoryException | ItemNotFoundException | LayoutException e )
{
throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
}
@@ -773,6 +775,7 @@ public class DefaultRepositoriesService
ref.setVersion( artifact.getVersion() );
ManagedRepositoryContent repository = getManagedRepositoryContent( repositoryId );
+ BaseRepositoryContentLayout layout = repository.getLayout( BaseRepositoryContentLayout.class );
ArtifactReference artifactReference = new ArtifactReference();
artifactReference.setArtifactId( artifact.getArtifactId() );
@@ -793,7 +796,7 @@ public class DefaultRepositoriesService
MetadataRepository metadataRepository = repositorySession.getRepository();
- String path = repository.toMetadataPath( ref );
+ String path = layout.toMetadataPath( ref );
if ( StringUtils.isNotBlank( artifact.getClassifier() ) )
{
@@ -802,7 +805,7 @@ public class DefaultRepositoriesService
throw new ArchivaRestServiceException( "You must configure a type/packaging when using classifier",
400, null );
}
- List<? extends org.apache.archiva.repository.content.Artifact> artifactItems = repository.getArtifacts( selector );
+ List<? extends org.apache.archiva.repository.content.Artifact> artifactItems = layout.getArtifacts( selector );
for ( org.apache.archiva.repository.content.Artifact aRef : artifactItems ) {
try
{
@@ -834,19 +837,19 @@ public class DefaultRepositoriesService
// delete from file system
if ( !snapshotVersion )
{
- repository.deleteVersion( ref );
+ layout.deleteVersion( ref );
}
else
{
// We are deleting all version related artifacts for a snapshot version
- VersionedReference versionRef = repository.toVersion( artifactReference );
- List<ArtifactReference> related = repository.getRelatedArtifacts( versionRef );
+ VersionedReference versionRef = layout.toVersion( artifactReference );
+ List<ArtifactReference> related = layout.getRelatedArtifacts( versionRef );
log.debug( "related: {}", related );
for ( ArtifactReference artifactRef : related )
{
try
{
- repository.deleteArtifact( artifactRef );
+ layout.deleteArtifact( artifactRef );
} catch (ContentNotFoundException e) {
log.warn( "Artifact that should be deleted, was not found: {}", artifactRef );
}
@@ -1014,8 +1017,9 @@ public class DefaultRepositoriesService
try
{
ManagedRepositoryContent repository = getManagedRepositoryContent( repositoryId );
-
- repository.deleteGroupId( groupId );
+ ArchivaItemSelector itemselector = ArchivaItemSelector.builder( ).withNamespace( groupId ).build();
+ ContentItem item = repository.getItem( itemselector );
+ repository.deleteItem( item );
MetadataRepository metadataRepository = repositorySession.getRepository();
@@ -1038,6 +1042,11 @@ public class DefaultRepositoriesService
log.error( e.getMessage(), e );
throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
}
+ catch ( ItemNotFoundException e )
+ {
+ log.error( "Item not found {}", e.getMessage(), e );
+ throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
+ }
finally
{
@@ -1083,8 +1092,11 @@ public class DefaultRepositoriesService
try
{
ManagedRepositoryContent repository = getManagedRepositoryContent( repositoryId );
+ ArchivaItemSelector itemSelector = ArchivaItemSelector.builder( ).withNamespace( groupId )
+ .withProjectId( projectId ).build( );
+ ContentItem item = repository.getItem( itemSelector );
- repository.deleteProject( groupId, projectId );
+ repository.deleteItem( item );
}
catch ( ContentNotFoundException e )
{
@@ -1095,6 +1107,11 @@ public class DefaultRepositoriesService
log.error( e.getMessage(), e );
throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
}
+ catch ( ItemNotFoundException e )
+ {
+ log.error( "Item not found {}", e.getMessage(), e );
+ throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
+ }
try
{
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactBuilder.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactBuilder.java
index 3a9c75051..b449d3abb 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactBuilder.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactBuilder.java
@@ -22,7 +22,9 @@ import org.apache.archiva.maven2.model.Artifact;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.maven.model.MavenArtifactFacet;
import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.repository.BaseRepositoryContentLayout;
import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.LayoutException;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.repository.storage.util.StorageUtil;
@@ -79,7 +81,16 @@ public class ArtifactBuilder
ref.setClassifier( classifier );
ref.setType( type );
- StorageAsset file = managedRepositoryContent.toFile( ref );
+ BaseRepositoryContentLayout layout;
+ try
+ {
+ layout = managedRepositoryContent.getLayout( BaseRepositoryContentLayout.class );
+ }
+ catch ( LayoutException e )
+ {
+ throw new RuntimeException( "Could not convert to layout " + e.getMessage( ) );
+ }
+ StorageAsset file = layout.toFile( ref );
String extension = getExtensionFromFile(file);
@@ -89,7 +100,7 @@ public class ArtifactBuilder
artifact.setPackaging( type );
artifact.setType( type );
artifact.setFileExtension( extension );
- artifact.setPath( managedRepositoryContent.toPath( ref ) );
+ artifact.setPath( layout.toPath( ref ) );
// TODO: find a reusable formatter for this
double s = this.artifactMetadata.getSize();
String symbol = "b";