git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1293423 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-1.4-M3
@@ -45,6 +45,10 @@ | |||
<artifactId>archiva-policies</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>metadata-model</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.codehaus.redback</groupId> |
@@ -18,6 +18,7 @@ package org.apache.archiva.rest.api.services; | |||
* 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; | |||
@@ -26,7 +27,6 @@ import javax.ws.rs.GET; | |||
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; | |||
/** | |||
@@ -50,10 +50,18 @@ public interface BrowseService | |||
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; | |||
} |
@@ -44,6 +44,10 @@ | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>archiva-repository-admin-api</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>metadata-model</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>archiva-configuration</artifactId> |
@@ -18,15 +18,18 @@ package org.apache.archiva.rest.services; | |||
* 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; | |||
@@ -170,8 +173,23 @@ public class DefaultBrowseService | |||
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(); | |||
@@ -184,7 +202,132 @@ public class DefaultBrowseService | |||
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 ) | |||
{ | |||
@@ -193,9 +336,11 @@ public class DefaultBrowseService | |||
} | |||
finally | |||
{ | |||
repositorySession.close(); | |||
if ( repositorySession != null ) | |||
{ | |||
repositorySession.close(); | |||
} | |||
} | |||
} | |||
//--------------------------- |
@@ -42,7 +42,7 @@ $(function() { | |||
displayProjectEntry=function(id){ | |||
$.log("displayProjectEntry:"+id); | |||
var url = "restServices/archivaServices/browseService/browseGroupId?g=org.apache.maven&a=maven-archiver"; | |||
var url = "restServices/archivaServices/browseService/versionsList/org.apache.maven/maven-archiver"; | |||
$.ajax(url, { | |||
type: "GET", | |||
@@ -50,7 +50,18 @@ $(function() { | |||
success: function(data) { | |||
} | |||
}); | |||
}); | |||
url = "restServices/archivaServices/browseService/projectVersionMetadata/org.apache.maven/maven-archiver"; | |||
$.ajax(url, { | |||
type: "GET", | |||
dataType: 'json', | |||
success: function(data) { | |||
} | |||
}); | |||
} | |||
breadCrumbEntries=function(){ |
@@ -19,11 +19,14 @@ package org.apache.archiva.metadata.model; | |||
* under the License. | |||
*/ | |||
import javax.xml.bind.annotation.XmlRootElement; | |||
/** | |||
* Information about the CI system used by the project. | |||
* | |||
* @todo considering moving this to a facet - avoid referring to it externally | |||
*/ | |||
@XmlRootElement( name = "ciManagement" ) | |||
public class CiManagement | |||
{ | |||
/** |
@@ -19,11 +19,14 @@ package org.apache.archiva.metadata.model; | |||
* under the License. | |||
*/ | |||
import javax.xml.bind.annotation.XmlRootElement; | |||
/** | |||
* Information about a dependency that this project has on another project or artifact. | |||
* | |||
* @todo will be reviewing what is appropriate for the base here - rest should be in a maven dependency facet - avoid details on it externally | |||
*/ | |||
@XmlRootElement( name = "dependency" ) | |||
public class Dependency | |||
{ | |||
/** |
@@ -19,6 +19,7 @@ package org.apache.archiva.metadata.model; | |||
* under the License. | |||
*/ | |||
import javax.xml.bind.annotation.XmlElement; | |||
import java.util.Collection; | |||
import java.util.Collections; | |||
import java.util.HashMap; | |||
@@ -77,7 +78,7 @@ public abstract class FacetedMetadata | |||
/** | |||
* Get all available facets as a Map (typically used by bean rendering, such as in Archiva's JSPs). | |||
* | |||
* @return the map of facets | |||
* @see #facets | |||
*/ |
@@ -19,11 +19,14 @@ package org.apache.archiva.metadata.model; | |||
* under the License. | |||
*/ | |||
import javax.xml.bind.annotation.XmlRootElement; | |||
/** | |||
* Information about the issue management system used by the project. | |||
* | |||
* @todo considering moving this to a facet - avoid referring to it externally | |||
*/ | |||
@XmlRootElement( name = "issueManagement" ) | |||
public class IssueManagement | |||
{ | |||
/** |
@@ -19,9 +19,12 @@ package org.apache.archiva.metadata.model; | |||
* under the License. | |||
*/ | |||
import javax.xml.bind.annotation.XmlRootElement; | |||
/** | |||
* A description of a particular license used by a project. | |||
*/ | |||
@XmlRootElement( name = "license" ) | |||
public class License | |||
{ | |||
/** |
@@ -1,5 +1,6 @@ | |||
package org.apache.archiva.metadata.model; | |||
import javax.xml.bind.annotation.XmlRootElement; | |||
import java.util.List; | |||
/* | |||
@@ -26,6 +27,7 @@ import java.util.List; | |||
* | |||
* @todo considering moving this to a facet - avoid referring to it externally | |||
*/ | |||
@XmlRootElement( name = "mailingList" ) | |||
public class MailingList | |||
{ | |||
/** |
@@ -19,14 +19,20 @@ package org.apache.archiva.metadata.model; | |||
* under the License. | |||
*/ | |||
import javax.xml.bind.annotation.XmlElement; | |||
import javax.xml.bind.annotation.XmlRootElement; | |||
import java.util.Map; | |||
@XmlRootElement( name = "metadataFacet" ) | |||
public interface MetadataFacet | |||
{ | |||
@XmlElement(name = "facetId") | |||
String getFacetId(); | |||
@XmlElement(name = "name") | |||
String getName(); | |||
@XmlElement(name = "properties") | |||
Map<String, String> toProperties(); | |||
void fromProperties( Map<String, String> properties ); |
@@ -19,6 +19,9 @@ package org.apache.archiva.metadata.model; | |||
* under the License. | |||
*/ | |||
import javax.xml.bind.annotation.XmlRootElement; | |||
@XmlRootElement( name = "organization" ) | |||
public class Organization | |||
{ | |||
private String name; |
@@ -19,9 +19,11 @@ package org.apache.archiva.metadata.model; | |||
* under the License. | |||
*/ | |||
import javax.xml.bind.annotation.XmlRootElement; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
@XmlRootElement( name = "projectVersionMetadata" ) | |||
public class ProjectVersionMetadata | |||
extends FacetedMetadata | |||
{ |
@@ -19,6 +19,9 @@ package org.apache.archiva.metadata.model; | |||
* under the License. | |||
*/ | |||
import javax.xml.bind.annotation.XmlRootElement; | |||
@XmlRootElement( name = "scm" ) | |||
public class Scm | |||
{ | |||
private String connection; |