*/
Version getVersion(ItemSelector versionCoordinates) throws ContentAccessException, IllegalArgumentException;
+
/**
* Returns the artifact object for the given coordinates.
*
*/
List<? extends Project> getProjects( Namespace namespace) throws ContentAccessException;
+ /**
+ * Returns the list of projects that match the given selector. The selector must at least specify a
+ * a namespace.
+ *
+ * @param selector the selector
+ * @return the list of projects that match the selector. A empty list of not project matches.
+ * @throws ContentAccessException if the access to the storage backend failed
+ * @throws IllegalArgumentException if the selector does not contain sufficient data for selecting projects
+ */
+ List<? extends Project> getProjects( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException;
+
/**
* Return the existing versions of the given project.
*
* @param project the project
* @return a list of versions or a empty list, if not versions are available for the specified project
+ * @throws ContentAccessException if the access to the underlying storage failed
*/
List<? extends Version> getVersions( Project project) throws ContentAccessException;
+
+ /**
+ * Return the versions that match the given selector. The selector must at least specify a namespace and a projectId.
+ *
+ * @param selector the item selector. At least namespace and projectId must be set.
+ * @return the list of version or a empty list, if no version matches the selector
+ * @throws ContentAccessException if the access to the backend failed
+ * @throws IllegalArgumentException if the selector does not contain enough information for selecting versions
+ */
+ List<? extends Version> getVersions( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException;
+
+
/**
* Return all the artifacts of a given content item (namespace, project, version)
*
return null;
}
+ @Override
+ public List<? extends Project> getProjects( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
+ {
+ return null;
+ }
+
@Override
public List<? extends Version> getVersions( Project project ) throws ContentAccessException
{
return null;
}
+ @Override
+ public List<? extends Version> getVersions( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
+ {
+ return null;
+ }
+
@Override
public List<? extends Artifact> getArtifacts( ContentItem item ) throws ContentAccessException
{
return null;
}
+ @Override
+ public List<? extends Project> getProjects( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
+ {
+ return null;
+ }
+
@Override
public List<? extends Version> getVersions( Project project ) throws ContentAccessException
{
return null;
}
+ @Override
+ public List<? extends Version> getVersions( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
+ {
+ return null;
+ }
+
@Override
public List<? extends Artifact> getArtifacts( ContentItem item ) throws ContentAccessException
{
return null;
}
+ @Override
+ public List<? extends Project> getProjects( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
+ {
+ return null;
+ }
+
@Override
public List<? extends Version> getVersions( Project project ) throws ContentAccessException
{
return null;
}
+ @Override
+ public List<? extends Version> getVersions( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
+ {
+ return null;
+ }
+
@Override
public List<? extends Artifact> getArtifacts( ContentItem item ) throws ContentAccessException
{
implements ManagedRepositoryContent
{
- public static final String METADATA_FILENAME = "maven-metadata.xml";
+ // attribute flag that marks version objects that point to a snapshot artifact version
+ public static final String SNAPSHOT_ARTIFACT_VERSION = "maven.snav";
+
private FileTypes filetypes;
public void setFileTypes(FileTypes fileTypes) {
private String type;
private String classifier;
private String contentType;
+ private StorageAsset asset;
}
private ArtifactInfo getArtifactInfoFromPath(String genericVersion, StorageAsset path) {
final ArtifactInfo info = new ArtifactInfo( );
+ info.asset = path;
info.id = path.getParent( ).getParent( ).getName( );
final String fileName = path.getName( );
if ( genericVersion.endsWith( "-" + SNAPSHOT ) )
return null;
}
- /*
- TBD
+ @Override
+ public List<? extends Project> getProjects( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
+ {
+ return null;
+ }
+
+ /**
+ * Returns a version object for each directory that is a direct child of the project directory.
+ * @param project the project for which the versions should be returned
+ * @return the list of versions or a empty list, if not version was found
*/
@Override
public List<? extends Version> getVersions( final Project project )
.collect( Collectors.toList( ) );
}
- /*
- TBD
+ /**
+ * If the selector specifies a version, all artifact versions are returned, which means for snapshot
+ * versions the artifact versions are returned too.
+ *
+ * @param selector the item selector. At least namespace and projectId must be set.
+ * @return the list of version objects or a empty list, if the selector does not match a version
+ * @throws ContentAccessException if the access to the underlying backend failed
+ * @throws IllegalArgumentException if the selector has no projectId specified
*/
@Override
+ public List<? extends Version> getVersions( final ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
+ {
+ if (StringUtils.isEmpty( selector.getProjectId() )) {
+ log.error( "Bad item selector for version list: {}", selector );
+ throw new IllegalArgumentException( "Project ID not set, while retrieving versions." );
+ }
+ final Project project = getProject( selector );
+ if (selector.hasVersion()) {
+ final StorageAsset asset = getAsset( selector.getNamespace( ), selector.getProjectId( ), selector.getVersion( ) );
+ return asset.list( ).stream( ).map( a -> getArtifactInfoFromPath( selector.getVersion( ), a ) )
+ .filter( ai -> StringUtils.isNotEmpty( ai.version ) )
+ .map( v -> ArchivaVersion.withAsset( v.asset.getParent() )
+ .withProject( project ).withVersion( v.version )
+ .withAttribute(SNAPSHOT_ARTIFACT_VERSION,"true").build() )
+ .distinct()
+ .collect( Collectors.toList( ) );
+ } else {
+ return getVersions( project );
+ }
+ }
+
+ /*
+ TBD
+ */
+ @Override
public List<? extends Artifact> getArtifacts( ContentItem item )
{
return null;
Set<String> testedVersionSet = repoContent.getVersions( reference );
// Sort the list (for asserts later)
+ final VersionComparator comparator = new VersionComparator( );
List<String> testedVersions = new ArrayList<>();
testedVersions.addAll( testedVersionSet );
- Collections.sort( testedVersions, new VersionComparator() );
+ Collections.sort( testedVersions, comparator );
// Test the expected array of versions, to the actual tested versions
assertEquals( "Assert Versions: length/size", expectedVersions.length, testedVersions.size() );
String actualVersion = testedVersions.get( i );
assertEquals( "Versions[" + i + "]", expectedVersions[i], actualVersion );
}
+
+
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "org.apache.archiva.metadata.tests" )
+ .withProjectId( artifactId )
+ .withVersion( version )
+ .build( );
+ List<String> versions = repoContent.getVersions( selector ).stream()
+ .map(v -> v.getVersion()).sorted( comparator ).collect( Collectors.toList());
+ assertArrayEquals( expectedVersions, versions.toArray( ) );
+
+
}