* under the License.
*/
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.rest.api.model.BrowseResult;
import org.apache.archiva.rest.api.model.VersionsList;
import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
/**
BrowseResult browseGroupId( @PathParam( "groupId" ) String groupId )
throws ArchivaRestServiceException;
- @Path( "browseGroupId" )
+ @Path( "versionsList/{g}/{a}" )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization( noRestriction = true, noPermission = false )
- VersionsList getVersionsList( @QueryParam( "g" ) String groupId, @QueryParam( "a" ) String artifactId )
+ VersionsList getVersionsList( @PathParam( "g" ) String groupId, @PathParam( "a" ) String artifactId )
+ throws ArchivaRestServiceException;
+
+ @Path( "projectVersionMetadata/{g}/{a}" )
+ @GET
+ @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+ @RedbackAuthorization( noRestriction = true, noPermission = false )
+ ProjectVersionMetadata getProjectVersionMetadata( @PathParam( "g" ) String groupId,
+ @PathParam( "a" ) String artifactId )
throws ArchivaRestServiceException;
}
* under the License.
*/
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.repository.MetadataResolutionException;
import org.apache.archiva.metadata.repository.MetadataResolver;
import org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
import org.apache.archiva.rest.api.model.BrowseResult;
import org.apache.archiva.rest.api.model.BrowseResultEntry;
import org.apache.archiva.rest.api.model.VersionsList;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
import org.apache.archiva.rest.api.services.BrowseService;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import javax.ws.rs.core.Response;
return new VersionsList();
}
- RepositorySession repositorySession = repositorySessionFactory.createSession();
+ try
+ {
+ return new VersionsList( new ArrayList<String>( getVersions( selectedRepos, groupId, artifactId ) ) );
+ }
+ catch ( MetadataResolutionException e )
+ {
+ throw new ArchivaRestServiceException( e.getMessage(),
+ Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() );
+ }
+ }
+
+ private Set<String> getVersions( List<String> selectedRepos, String groupId, String artifactId )
+ throws MetadataResolutionException
+
+ {
+ RepositorySession repositorySession = repositorySessionFactory.createSession();
try
{
MetadataResolver metadataResolver = repositorySession.getResolver();
metadataResolver.resolveProjectVersions( repositorySession, repoId, groupId, artifactId ) );
}
- return new VersionsList( new ArrayList<String>( versions ) );
+ return versions;
+ }
+ finally
+ {
+ repositorySession.close();
+ }
+ }
+
+ public ProjectVersionMetadata getProjectVersionMetadata( String groupId, String artifactId )
+ throws ArchivaRestServiceException
+ {
+
+ List<String> selectedRepos = getObservableRepos();
+
+ if ( CollectionUtils.isEmpty( selectedRepos ) )
+ {
+ // FIXME 403 ???
+ return null;
+ }
+
+ RepositorySession repositorySession = null;
+ try
+ {
+
+ Set<String> projectVersions = getVersions( selectedRepos, groupId, artifactId );
+
+ repositorySession = repositorySessionFactory.createSession();
+
+ MetadataResolver metadataResolver = repositorySession.getResolver();
+
+ ProjectVersionMetadata sharedModel = new ProjectVersionMetadata();
+
+ MavenProjectFacet mavenFacet = new MavenProjectFacet();
+ mavenFacet.setGroupId( groupId );
+ mavenFacet.setArtifactId( artifactId );
+ sharedModel.addFacet( mavenFacet );
+
+ boolean isFirstVersion = true;
+
+ for ( String version : projectVersions )
+ {
+ ProjectVersionMetadata versionMetadata = null;
+ for ( String repoId : selectedRepos )
+ {
+ if ( versionMetadata == null )
+ {
+ try
+ {
+ versionMetadata =
+ metadataResolver.resolveProjectVersion( repositorySession, repoId, groupId, artifactId,
+ version );
+ }
+ catch ( MetadataResolutionException e )
+ {
+ log.error( "Skipping invalid metadata while compiling shared model for " + groupId + ":"
+ + artifactId + " in repo " + repoId + ": " + e.getMessage() );
+ }
+ }
+ }
+
+ if ( versionMetadata == null )
+ {
+ continue;
+ }
+
+ if ( isFirstVersion )
+ {
+ sharedModel = versionMetadata;
+ sharedModel.setId( null );
+ }
+ else
+ {
+ MavenProjectFacet versionMetadataMavenFacet =
+ (MavenProjectFacet) versionMetadata.getFacet( MavenProjectFacet.FACET_ID );
+ if ( versionMetadataMavenFacet != null )
+ {
+ if ( mavenFacet.getPackaging() != null && !StringUtils.equalsIgnoreCase(
+ mavenFacet.getPackaging(), versionMetadataMavenFacet.getPackaging() ) )
+ {
+ mavenFacet.setPackaging( null );
+ }
+ }
+
+ if ( sharedModel.getName() != null && !StringUtils.equalsIgnoreCase( sharedModel.getName(),
+ versionMetadata.getName() ) )
+ {
+ sharedModel.setName( "" );
+ }
+
+ if ( sharedModel.getDescription() != null && !StringUtils.equalsIgnoreCase(
+ sharedModel.getDescription(), versionMetadata.getDescription() ) )
+ {
+ sharedModel.setDescription( null );
+ }
+
+ if ( sharedModel.getIssueManagement() != null && versionMetadata.getIssueManagement() != null
+ && !StringUtils.equalsIgnoreCase( sharedModel.getIssueManagement().getUrl(),
+ versionMetadata.getIssueManagement().getUrl() ) )
+ {
+ sharedModel.setIssueManagement( null );
+ }
+
+ if ( sharedModel.getCiManagement() != null && versionMetadata.getCiManagement() != null
+ && !StringUtils.equalsIgnoreCase( sharedModel.getCiManagement().getUrl(),
+ versionMetadata.getCiManagement().getUrl() ) )
+ {
+ sharedModel.setCiManagement( null );
+ }
+
+ if ( sharedModel.getOrganization() != null && versionMetadata.getOrganization() != null
+ && !StringUtils.equalsIgnoreCase( sharedModel.getOrganization().getName(),
+ versionMetadata.getOrganization().getName() ) )
+ {
+ sharedModel.setOrganization( null );
+ }
+
+ if ( sharedModel.getUrl() != null && !StringUtils.equalsIgnoreCase( sharedModel.getUrl(),
+ versionMetadata.getUrl() ) )
+ {
+ sharedModel.setUrl( null );
+ }
+ }
+
+ isFirstVersion = false;
+ }
+ return sharedModel;
}
catch ( MetadataResolutionException e )
{
}
finally
{
- repositorySession.close();
+ if ( repositorySession != null )
+ {
+ repositorySession.close();
+ }
}
-
}
//---------------------------