]> source.dussan.org Git - archiva.git/commitdiff
Moving first client calls to new content repo API
authorMartin Stockhammer <martin_s@apache.org>
Sun, 29 Mar 2020 17:12:30 +0000 (19:12 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Sun, 29 Mar 2020 17:12:30 +0000 (19:12 +0200)
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java
archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/base/MetadataTools.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java
archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java
archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java

index 84a1d0f81b7e790fbe650d281918d83f901d970a..b7f590e3541ea88362dd04371bf9db2085c8a40c 100644 (file)
@@ -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<String> 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
-                    }
                 }
             }
 
index 20d0a670354c8590fed578cdf638553cd4c80aa2..ec62e7b557b1c5f295a37399d4e29475d730c40e 100644 (file)
@@ -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<String> getVersions( ProjectReference reference )
-        throws ContentNotFoundException, LayoutException, ContentAccessException;
-
-
 
     /**
      * <p>
@@ -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.
      *
index b875be6aeb90a9363db866d22d06f0485e9ca365..a8298e2ae0c7c27b30c1cc4075efd1124b8b81c0 100644 (file)
@@ -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<String> 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.
index bcb330f5eb3b0678c36ecd2f924f3d7d6bd72526..029fd14aa788c35ed80646de3ed47d5919ddf1de 100644 (file)
@@ -260,12 +260,6 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
         return repository;
     }
 
-    @Override
-    public Set<String> getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
-    {
-        return null;
-    }
-
     @Override
     public Set<String> 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
     {
index 34a3e809d89182acdb57089b10ce54d7ab4df0f9..6065a94498061e4070d0768f5b7758107c7e2ea0 100644 (file)
@@ -282,12 +282,6 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
         return repository;
     }
 
-    @Override
-    public Set<String> getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
-    {
-        return null;
-    }
-
     @Override
     public Set<String> 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
     {
index 81d240eeac210ef814b8af2818c788874145ffc6..f5036797bfc387cb339dc654c625b99a462aec99 100644 (file)
@@ -286,12 +286,6 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
         return repository;
     }
 
-    @Override
-    public Set<String> getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
-    {
-        return null;
-    }
-
     @Override
     public Set<String> 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
     {
index b79753cc717ce5becec716c192ce00bf26bea543..9a02dce94bfdaac7455687dbe0d26c4186d444c7 100644 (file)
@@ -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<String> 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<Path> 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<String> 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<String> versions = getVersions( reference );
-            return !versions.isEmpty();
-        }
-        catch ( ContentNotFoundException | LayoutException e )
-        {
-            return false;
-        }
-    }
-
     @Override
     public boolean hasContent( VersionedReference reference ) throws ContentAccessException
     {
index b19d336c0c19136439b9e3493b65ee973a2a1446..7587be30d129234e3bc3afb18fb9a6c4437ea608 100644 (file)
@@ -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<String> 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<String> testedVersionSet = repoContent.getVersions( reference );
-
-        // Sort the list (for asserts)
-        VersionComparator comparator = new VersionComparator( );
-        List<String> 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<String> 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
index 23b8d6fb6501607bccbe5d4c4b5ea3acbd213891..1cc78b252fc6c51881898707a1caf2c030464d49 100644 (file)
@@ -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 );