mirror of https://github.com/apache/archiva.git
Moving first client calls to new content repo API
This commit is contained in:
parent
ff7a102138
commit
b55ac5e29f
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in New Issue