From: Martin Stockhammer Date: Sun, 29 Mar 2020 17:12:30 +0000 (+0200) Subject: Moving first client calls to new content repo API X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b55ac5e29f81d58971c714e561ed6e4423f829b0;p=archiva.git Moving first client calls to new content repo API --- diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java index 84a1d0f81..b7f590e35 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java @@ -34,6 +34,10 @@ import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.metadata.audit.RepositoryListener; +import org.apache.archiva.repository.content.ItemSelector; +import org.apache.archiva.repository.content.Project; +import org.apache.archiva.repository.content.Version; +import org.apache.archiva.repository.content.base.ArchivaItemSelector; import org.apache.archiva.repository.metadata.base.MetadataTools; import org.apache.archiva.repository.metadata.RepositoryMetadataException; @@ -105,9 +109,11 @@ public class CleanupReleasedSnapshotsRepositoryPurge return; } - ProjectReference reference = new ProjectReference( ); - reference.setGroupId( artifactRef.getGroupId( ) ); - reference.setArtifactId( artifactRef.getArtifactId( ) ); + ItemSelector selector = ArchivaItemSelector.builder( ) + .withNamespace( artifactRef.getGroupId( ) ) + .withProjectId( artifactRef.getArtifactId( ) ) + .build(); + // Gether the released versions List releasedVersions = new ArrayList<>( ); @@ -118,21 +124,15 @@ public class CleanupReleasedSnapshotsRepositoryPurge if ( repo.getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE )) { - try + ManagedRepositoryContent repoContent = repo.getContent(); + Project proj = repoContent.getProject( selector ); + for ( Version version : repoContent.getVersions( proj ) ) { - ManagedRepositoryContent repoContent = repo.getContent(); - for ( String version : repoContent.getVersions( reference ) ) + if ( !VersionUtil.isSnapshot( version.getVersion() ) ) { - if ( !VersionUtil.isSnapshot( version ) ) - { - releasedVersions.add( version ); - } + releasedVersions.add( version.getVersion() ); } } - catch ( RepositoryException e ) - { - // swallow - } } } diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java index 20d0a6703..ec62e7b55 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java @@ -484,19 +484,6 @@ public interface ManagedRepositoryContent extends RepositoryContent */ ManagedRepository getRepository(); - /** - * Given a specific {@link ProjectReference}, return the list of available versions for - * that project reference. - * - * @param reference the project reference to work off of. - * @return the list of versions found for that project reference. - * @throws ContentNotFoundException if the project reference does nto exist within the repository. - * @throws LayoutException - */ - Set getVersions( ProjectReference reference ) - throws ContentNotFoundException, LayoutException, ContentAccessException; - - /** *

@@ -522,14 +509,6 @@ public interface ManagedRepositoryContent extends RepositoryContent */ boolean hasContent( ArtifactReference reference ) throws ContentAccessException; - /** - * Determines if the project referenced exists in the repository. - * - * @param reference the project reference to check for. - * @return true it the project referenced exists. - */ - boolean hasContent( ProjectReference reference ) throws ContentAccessException; - /** * Determines if the version reference exists in the repository. * diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/base/MetadataTools.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/base/MetadataTools.java index b875be6ae..a8298e2ae 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/base/MetadataTools.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/base/MetadataTools.java @@ -45,6 +45,9 @@ import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.RemoteRepositoryContent; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.RepositoryType; +import org.apache.archiva.repository.content.ItemSelector; +import org.apache.archiva.repository.content.Project; +import org.apache.archiva.repository.content.base.ArchivaItemSelector; import org.apache.archiva.repository.metadata.MetadataReader; import org.apache.archiva.repository.metadata.RepositoryMetadataException; import org.apache.archiva.repository.storage.StorageAsset; @@ -66,6 +69,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.regex.Matcher; +import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -525,14 +529,21 @@ public class MetadataTools metadata.setArtifactId( reference.getArtifactId() ); // Gather up all versions found in the managed repository. + ItemSelector selector = ArchivaItemSelector.builder( ) + .withNamespace( reference.getGroupId( ) ) + .withProjectId( reference.getArtifactId( ) ) + .build(); Set allVersions = null; try { - allVersions = managedRepository.getVersions( reference ); + Project project = managedRepository.getProject( selector ); + allVersions = managedRepository.getVersions( project ).stream() + .map( v -> v.getVersion() ).collect( Collectors.toSet()); } catch ( org.apache.archiva.repository.ContentAccessException e ) { - e.printStackTrace( ); + log.error( "Error while accessing repository: {}", e.getMessage( ), e ); + throw new RepositoryMetadataException( "Error while accessing repository " + e.getMessage( ), e ); } // Gather up all plugins found in the managed repository. 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 bcb330f5e..029fd14aa 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 @@ -260,12 +260,6 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent return repository; } - @Override - public Set getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException - { - return null; - } - @Override public Set getVersions( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException, LayoutException { @@ -278,12 +272,6 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent return false; } - @Override - public boolean hasContent( ProjectReference reference ) throws ContentAccessException - { - return false; - } - @Override public boolean hasContent( VersionedReference reference ) throws ContentAccessException { 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 34a3e809d..6065a9449 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 @@ -282,12 +282,6 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent return repository; } - @Override - public Set getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException - { - return null; - } - @Override public Set getVersions( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException, LayoutException { @@ -300,12 +294,6 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent return false; } - @Override - public boolean hasContent( ProjectReference reference ) throws ContentAccessException - { - return false; - } - @Override public boolean hasContent( VersionedReference reference ) throws ContentAccessException { 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 81d240eea..f5036797b 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 @@ -286,12 +286,6 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent return repository; } - @Override - public Set getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException - { - return null; - } - @Override public Set getVersions( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException, LayoutException { @@ -304,12 +298,6 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent return false; } - @Override - public boolean hasContent( ProjectReference reference ) throws ContentAccessException - { - return false; - } - @Override public boolean hasContent( VersionedReference reference ) throws ContentAccessException { 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 b79753cc7..9a02dce94 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 @@ -173,7 +173,7 @@ public class ManagedDefaultRepositoryContent } - /// ************* End of new generation interface ****************** + /// ************* Start of new generation interface ****************** /** * Removes the item from the filesystem. For namespaces, projects and versions it deletes @@ -1245,59 +1245,6 @@ public class ManagedDefaultRepositoryContent return repository; } - /** - * Gather the Available Versions (on disk) for a specific Project Reference, based on filesystem - * information. - * - * @return the Set of available versions, based on the project reference. - * @throws LayoutException - */ - @Override - public Set getVersions( ProjectReference reference ) - throws ContentNotFoundException, LayoutException, ContentAccessException - { - final String path = toPath( reference ); - final Path projDir = getRepoDir().resolve(toPath(reference)); - if ( !Files.exists(projDir) ) - { - throw new ContentNotFoundException( - "Unable to get Versions on a non-existant directory for repository "+getId()+": " + path ); - } - - if ( !Files.isDirectory(projDir) ) - { - throw new ContentNotFoundException( - "Unable to get Versions on a non-directory for repository "+getId()+": " + path ); - } - - final String groupId = reference.getGroupId(); - final String artifactId = reference.getArtifactId(); - try(Stream stream = Files.list(projDir)) { - return stream.filter(Files::isDirectory).map( - p -> toVersion(groupId, artifactId, p.getFileName().toString()) - ).filter(this::hasArtifact).map(ref -> ref.getVersion()) - .collect(Collectors.toSet()); - } catch (IOException e) { - log.error("Could not read directory {}: {}", projDir, e.getMessage(), e); - throw new ContentAccessException( "Could not read path for repository "+getId()+": "+ path, e ); - } catch (RuntimeException e) { - Throwable cause = e.getCause( ); - if (cause!=null) - { - if ( cause instanceof LayoutException ) - { - throw (LayoutException) cause; - } else { - log.error("Could not read directory {}: {}", projDir, cause.getMessage(), cause); - throw new ContentAccessException( "Could not read path for repository "+getId()+": "+ path, cause ); - } - } else { - log.error("Could not read directory {}: {}", projDir, e.getMessage(), e); - throw new ContentAccessException( "Could not read path for repository "+getId()+": "+ path, cause ); - } - } - } - @Override public Set getVersions( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException, LayoutException @@ -1321,20 +1268,6 @@ public class ManagedDefaultRepositoryContent return artifactFile.exists() && !artifactFile.isContainer(); } - @Override - public boolean hasContent( ProjectReference reference ) throws ContentAccessException - { - try - { - Set versions = getVersions( reference ); - return !versions.isEmpty(); - } - catch ( ContentNotFoundException | LayoutException e ) - { - return false; - } - } - @Override public boolean hasContent( VersionedReference reference ) throws ContentAccessException { 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 b19d336c0..7587be30d 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 @@ -123,41 +123,6 @@ public class ManagedDefaultRepositoryContentTest //repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "default" ); } - @Test - public void testGetVersionsBadArtifact() - throws Exception - { - assertGetVersions( "bad_artifact", Collections.emptyList() ); - } - - @Test - public void testGetVersionsMissingMultipleVersions() - throws Exception - { - assertGetVersions( "missing_metadata_b", Arrays.asList( "1.0", "1.0.1", "2.0", "2.0.1", "2.0-20070821-dev" ) ); - } - - @Test - public void testGetVersionsSimple() - throws Exception - { - assertVersions( "proxied_multi", "2.1", new String[]{ "2.1" } ); - } - - @Test - public void testGetVersionsSimpleYetIncomplete() - throws Exception - { - assertGetVersions( "incomplete_metadata_a", Collections.singletonList( "1.0" ) ); - } - - @Test - public void testGetVersionsSimpleYetMissing() - throws Exception - { - assertGetVersions( "missing_metadata_a", Collections.singletonList( "1.0" ) ); - } - @Test public void testGetVersionsSnapshotA() throws Exception @@ -213,39 +178,6 @@ public class ManagedDefaultRepositoryContentTest assertVersions( "include_xml", "1.0", new String[]{ "1.0" } ); } - private void assertGetVersions( String artifactId, List expectedVersions ) - throws Exception - { - ProjectReference reference = new ProjectReference(); - reference.setGroupId( "org.apache.archiva.metadata.tests" ); - reference.setArtifactId( artifactId ); - - // Use the test metadata-repository, which is already setup for - // These kind of version tests. - Path repoDir = getRepositoryPath( "metadata-repository" ); - (( EditableManagedRepository)repoContent.getRepository()).setLocation( repoDir.toAbsolutePath().toUri() ); - - // Request the versions. - Set testedVersionSet = repoContent.getVersions( reference ); - - // Sort the list (for asserts) - VersionComparator comparator = new VersionComparator( ); - List testedVersions = new ArrayList<>(); - testedVersions.addAll( testedVersionSet ); - Collections.sort( testedVersions, comparator ); - - // Test the expected array of versions, to the actual tested versions - assertEquals( "available versions", expectedVersions, testedVersions ); - - ItemSelector selector = ArchivaItemSelector.builder( ) - .withNamespace( "org.apache.archiva.metadata.tests" ) - .withProjectId( artifactId ) - .build( ); - Project project = repoContent.getProject( selector ); - assertNotNull( project ); - List versions = repoContent.getVersions( project ).stream().map(v -> v.getVersion()).sorted( comparator ).collect( Collectors.toList()); - assertArrayEquals( expectedVersions.toArray(), versions.toArray( ) ); - } private void assertVersions( String artifactId, String version, String[] expectedVersions ) throws Exception 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 23b8d6fb6..1cc78b252 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 @@ -668,13 +668,6 @@ public class DefaultRepositoriesService repository.deleteVersion( ref ); - /* - ProjectReference projectReference = new ProjectReference(); - projectReference.setGroupId( namespace ); - projectReference.setArtifactId( projectId ); - - repository.getVersions( ) - */ ArtifactReference artifactReference = new ArtifactReference(); artifactReference.setGroupId( namespace );