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;
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<>( );
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
- }
}
}
*/
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>
*/
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.
*
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;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
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.
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
{
return false;
}
- @Override
- public boolean hasContent( ProjectReference reference ) throws ContentAccessException
- {
- return false;
- }
-
@Override
public boolean hasContent( VersionedReference reference ) throws ContentAccessException
{
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
{
return false;
}
- @Override
- public boolean hasContent( ProjectReference reference ) throws ContentAccessException
- {
- return false;
- }
-
@Override
public boolean hasContent( VersionedReference reference ) throws ContentAccessException
{
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
{
return false;
}
- @Override
- public boolean hasContent( ProjectReference reference ) throws ContentAccessException
- {
- return false;
- }
-
@Override
public boolean hasContent( VersionedReference reference ) throws ContentAccessException
{
}
- /// ************* End of new generation interface ******************
+ /// ************* Start of new generation interface ******************
/**
* Removes the item from the filesystem. For namespaces, projects and versions it deletes
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
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
{
//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
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
repository.deleteVersion( ref );
- /*
- ProjectReference projectReference = new ProjectReference();
- projectReference.setGroupId( namespace );
- projectReference.setArtifactId( projectId );
-
- repository.getVersions( )
- */
ArtifactReference artifactReference = new ArtifactReference();
artifactReference.setGroupId( namespace );