From 3d29a9d3f408a018c7dde25ab2a2edf766c370c4 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 13 Sep 2011 17:31:27 +0000 Subject: [PATCH] [MRM-1490] Expose Archiva services trough REST : search service more impl git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1170261 13f79535-47bb-0310-9956-ffa450edef68 --- .../indexer/search/NexusRepositorySearch.java | 12 + .../indexer/search/SearchResultHit.java | 162 ++++++++-- .../archiva/rest/api/model/Artifact.java | 276 +++++++++++++----- .../services/ManagedRepositoriesService.java | 6 +- .../rest/api/services/SearchService.java | 14 +- .../rest/services/AbstractRestService.java | 4 + .../DefaultManagedRepositoriesService.java | 45 ++- .../services/DefaultRepositoriesService.java | 2 + .../rest/services/DefaultSearchService.java | 78 ++++- .../rest/services/SearchServiceTest.java | 79 ++++- .../src/test/resources/log4j.xml | 4 +- 11 files changed, 543 insertions(+), 139 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java index f2db9cf3e..86f22a2cd 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java @@ -381,6 +381,18 @@ public class NexusRepositorySearch hit.setBundleExportService( artifactInfo.bundleExportService ); hit.setBundleSymbolicName( artifactInfo.bundleSymbolicName ); hit.setBundleVersion( artifactInfo.bundleVersion ); + hit.setBundleDescription( artifactInfo.bundleDescription ); + hit.setBundleDocUrl( artifactInfo.bundleDocUrl ); + + hit.setBundleRequireBundle( artifactInfo.bundleRequireBundle ); + hit.setBundleImportPackage( artifactInfo.bundleImportPackage ); + hit.setBundleLicense( artifactInfo.bundleLicense ); + hit.setBundleName( artifactInfo.bundleName ); + hit.setContext( artifactInfo.context ); + hit.setGoals( artifactInfo.goals ); + hit.setPrefix( artifactInfo.prefix ); + // sure ?? + hit.setUrl( artifactInfo.remoteUrl ); } results.addHit( id, hit ); diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java index 237c5d66f..5eaf33d38 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java @@ -40,42 +40,81 @@ public class SearchResultHit // Advanced hit, reference to artifactId. private String artifactId; - - // TODO: remove/deprecate this field! - private String version = ""; private String repositoryId = ""; private List versions = new ArrayList(); - + + /** + * Plugin goal prefix (only if packaging is "maven-plugin") + */ + public String prefix; + /** + * Plugin goals (only if packaging is "maven-plugin") + */ + public List goals; + /** * contains osgi metadata Bundle-Version if available - * * @since 1.4 */ - private String bundleVersion; + public String bundleVersion; /** * contains osgi metadata Bundle-SymbolicName if available - * * @since 1.4 */ - private String bundleSymbolicName; + public String bundleSymbolicName; /** * contains osgi metadata Export-Package if available - * * @since 1.4 */ - private String bundleExportPackage; + public String bundleExportPackage; /** * contains osgi metadata Export-Service if available - * * @since 1.4 */ - private String bundleExportService; + public String bundleExportService; + + /** + * contains osgi metadata Bundle-Description if available + * @since 1.4 + */ + public String bundleDescription; + + /** + * contains osgi metadata Bundle-Name if available + * @since 1.4 + */ + public String bundleName; + + /** + * contains osgi metadata Bundle-License if available + * @since 1.4 + */ + public String bundleLicense; + + /** + * contains osgi metadata Bundle-DocURL if available + * @since 1.4 + */ + public String bundleDocUrl; + + /** + * contains osgi metadata Import-Package if available + * @since 1.4 + */ + public String bundleImportPackage; + + /** + * contains osgi metadata Require-Bundle if available + * @since 1.4 + */ + public String bundleRequireBundle; + public String getContext() { @@ -122,16 +161,6 @@ public class SearchResultHit this.groupId = groupId; } - public String getVersion() - { - return version; - } - - public void setVersion(String version) - { - this.version = version; - } - public List getVersions() { return versions; @@ -197,6 +226,86 @@ public class SearchResultHit this.bundleExportService = bundleExportService; } + public String getPrefix() + { + return prefix; + } + + public void setPrefix( String prefix ) + { + this.prefix = prefix; + } + + public List getGoals() + { + return goals; + } + + public void setGoals( List goals ) + { + this.goals = goals; + } + + public String getBundleDescription() + { + return bundleDescription; + } + + public void setBundleDescription( String bundleDescription ) + { + this.bundleDescription = bundleDescription; + } + + public String getBundleName() + { + return bundleName; + } + + public void setBundleName( String bundleName ) + { + this.bundleName = bundleName; + } + + public String getBundleLicense() + { + return bundleLicense; + } + + public void setBundleLicense( String bundleLicense ) + { + this.bundleLicense = bundleLicense; + } + + public String getBundleDocUrl() + { + return bundleDocUrl; + } + + public void setBundleDocUrl( String bundleDocUrl ) + { + this.bundleDocUrl = bundleDocUrl; + } + + public String getBundleImportPackage() + { + return bundleImportPackage; + } + + public void setBundleImportPackage( String bundleImportPackage ) + { + this.bundleImportPackage = bundleImportPackage; + } + + public String getBundleRequireBundle() + { + return bundleRequireBundle; + } + + public void setBundleRequireBundle( String bundleRequireBundle ) + { + this.bundleRequireBundle = bundleRequireBundle; + } + @Override public String toString() { @@ -206,13 +315,20 @@ public class SearchResultHit sb.append( ", url='" ).append( url ).append( '\'' ); sb.append( ", groupId='" ).append( groupId ).append( '\'' ); sb.append( ", artifactId='" ).append( artifactId ).append( '\'' ); - sb.append( ", version='" ).append( version ).append( '\'' ); sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' ); sb.append( ", versions=" ).append( versions ); + sb.append( ", prefix='" ).append( prefix ).append( '\'' ); + sb.append( ", goals=" ).append( goals ); sb.append( ", bundleVersion='" ).append( bundleVersion ).append( '\'' ); sb.append( ", bundleSymbolicName='" ).append( bundleSymbolicName ).append( '\'' ); sb.append( ", bundleExportPackage='" ).append( bundleExportPackage ).append( '\'' ); sb.append( ", bundleExportService='" ).append( bundleExportService ).append( '\'' ); + sb.append( ", bundleDescription='" ).append( bundleDescription ).append( '\'' ); + sb.append( ", bundleName='" ).append( bundleName ).append( '\'' ); + sb.append( ", bundleLicense='" ).append( bundleLicense ).append( '\'' ); + sb.append( ", bundleDocUrl='" ).append( bundleDocUrl ).append( '\'' ); + sb.append( ", bundleImportPackage='" ).append( bundleImportPackage ).append( '\'' ); + sb.append( ", bundleRequireBundle='" ).append( bundleRequireBundle ).append( '\'' ); sb.append( '}' ); return sb.toString(); } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Artifact.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Artifact.java index e24666d92..001f5d7ea 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Artifact.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Artifact.java @@ -21,22 +21,37 @@ package org.apache.archiva.rest.api.model; import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; +import java.util.List; @XmlRootElement( name = "artifact" ) public class Artifact implements Serializable { - private String repositoryId; + // The (optional) context for this result. + private String context; + // Basic hit, direct to non-artifact resource. + private String url; + + // Advanced hit, reference to groupId. private String groupId; + // Advanced hit, reference to artifactId. private String artifactId; + private String repositoryId; + private String version; - private String type; + /** + * Plugin goal prefix (only if packaging is "maven-plugin") + */ + private String prefix; - private String url; + /** + * Plugin goals (only if packaging is "maven-plugin") + */ + private List goals; /** * contains osgi metadata Bundle-Version if available @@ -66,21 +81,54 @@ public class Artifact */ private String bundleExportService; + /** + * contains osgi metadata Bundle-Description if available + * + * @since 1.4 + */ + private String bundleDescription; + + /** + * contains osgi metadata Bundle-Name if available + * + * @since 1.4 + */ + private String bundleName; + + /** + * contains osgi metadata Bundle-License if available + * + * @since 1.4 + */ + private String bundleLicense; + + /** + * contains osgi metadata Bundle-DocURL if available + * + * @since 1.4 + */ + private String bundleDocUrl; + + /** + * contains osgi metadata Import-Package if available + * + * @since 1.4 + */ + private String bundleImportPackage; + + /** + * contains osgi metadata Require-Bundle if available + * + * @since 1.4 + */ + private String bundleRequireBundle; + public Artifact() { // no op } - public Artifact( String repositoryId, String groupId, String artifactId, String version, String type ) - { - this.repositoryId = repositoryId; - this.groupId = groupId; - this.artifactId = artifactId; - this.version = version; - this.type = type; - } - public String getGroupId() { return groupId; @@ -96,11 +144,6 @@ public class Artifact return version; } - public String getType() - { - return type; - } - public String getRepositoryId() { return repositoryId; @@ -121,63 +164,149 @@ public class Artifact this.version = version; } - public void setType( String type ) - { - this.type = type; - } - public void setRepositoryId( String repositoryId ) { this.repositoryId = repositoryId; } - @Override - public boolean equals( Object o ) + public String getContext() { - if ( this == o ) - { - return true; - } - if ( o == null || getClass() != o.getClass() ) - { - return false; - } - - Artifact artifact = (Artifact) o; - - if ( !artifactId.equals( artifact.artifactId ) ) - { - return false; - } - if ( !groupId.equals( artifact.groupId ) ) - { - return false; - } - if ( !repositoryId.equals( artifact.repositoryId ) ) - { - return false; - } - if ( type != null ? !type.equals( artifact.type ) : artifact.type != null ) - { - return false; - } - if ( !version.equals( artifact.version ) ) - { - return false; - } - - return true; + return context; } - @Override - public int hashCode() + public void setContext( String context ) { - int result = repositoryId.hashCode(); - result = 31 * result + groupId.hashCode(); - result = 31 * result + artifactId.hashCode(); - result = 31 * result + version.hashCode(); - result = 31 * result + ( type != null ? type.hashCode() : 0 ); - return result; + this.context = context; + } + + public String getUrl() + { + return url; + } + + public void setUrl( String url ) + { + this.url = url; + } + + public String getPrefix() + { + return prefix; + } + + public void setPrefix( String prefix ) + { + this.prefix = prefix; + } + + public List getGoals() + { + return goals; + } + + public void setGoals( List goals ) + { + this.goals = goals; + } + + public String getBundleVersion() + { + return bundleVersion; + } + + public void setBundleVersion( String bundleVersion ) + { + this.bundleVersion = bundleVersion; + } + + public String getBundleSymbolicName() + { + return bundleSymbolicName; + } + + public void setBundleSymbolicName( String bundleSymbolicName ) + { + this.bundleSymbolicName = bundleSymbolicName; + } + + public String getBundleExportPackage() + { + return bundleExportPackage; + } + + public void setBundleExportPackage( String bundleExportPackage ) + { + this.bundleExportPackage = bundleExportPackage; + } + + public String getBundleExportService() + { + return bundleExportService; + } + + public void setBundleExportService( String bundleExportService ) + { + this.bundleExportService = bundleExportService; + } + + public String getBundleDescription() + { + return bundleDescription; + } + + public void setBundleDescription( String bundleDescription ) + { + this.bundleDescription = bundleDescription; + } + + public String getBundleName() + { + return bundleName; + } + + public void setBundleName( String bundleName ) + { + this.bundleName = bundleName; + } + + public String getBundleLicense() + { + return bundleLicense; + } + + public void setBundleLicense( String bundleLicense ) + { + this.bundleLicense = bundleLicense; + } + + public String getBundleDocUrl() + { + return bundleDocUrl; + } + + public void setBundleDocUrl( String bundleDocUrl ) + { + this.bundleDocUrl = bundleDocUrl; + } + + public String getBundleImportPackage() + { + return bundleImportPackage; + } + + public void setBundleImportPackage( String bundleImportPackage ) + { + this.bundleImportPackage = bundleImportPackage; + } + + public String getBundleRequireBundle() + { + return bundleRequireBundle; + } + + public void setBundleRequireBundle( String bundleRequireBundle ) + { + this.bundleRequireBundle = bundleRequireBundle; } @Override @@ -185,11 +314,24 @@ public class Artifact { final StringBuilder sb = new StringBuilder(); sb.append( "Artifact" ); - sb.append( "{repositoryId='" ).append( repositoryId ).append( '\'' ); + sb.append( "{context='" ).append( context ).append( '\'' ); + sb.append( ", url='" ).append( url ).append( '\'' ); sb.append( ", groupId='" ).append( groupId ).append( '\'' ); sb.append( ", artifactId='" ).append( artifactId ).append( '\'' ); + sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' ); sb.append( ", version='" ).append( version ).append( '\'' ); - sb.append( ", type='" ).append( type ).append( '\'' ); + sb.append( ", prefix='" ).append( prefix ).append( '\'' ); + sb.append( ", goals=" ).append( goals ); + sb.append( ", bundleVersion='" ).append( bundleVersion ).append( '\'' ); + sb.append( ", bundleSymbolicName='" ).append( bundleSymbolicName ).append( '\'' ); + sb.append( ", bundleExportPackage='" ).append( bundleExportPackage ).append( '\'' ); + sb.append( ", bundleExportService='" ).append( bundleExportService ).append( '\'' ); + sb.append( ", bundleDescription='" ).append( bundleDescription ).append( '\'' ); + sb.append( ", bundleName='" ).append( bundleName ).append( '\'' ); + sb.append( ", bundleLicense='" ).append( bundleLicense ).append( '\'' ); + sb.append( ", bundleDocUrl='" ).append( bundleDocUrl ).append( '\'' ); + sb.append( ", bundleImportPackage='" ).append( bundleImportPackage ).append( '\'' ); + sb.append( ", bundleRequireBundle='" ).append( bundleRequireBundle ).append( '\'' ); sb.append( '}' ); return sb.toString(); } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java index af59a972f..04ac83801 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java @@ -60,7 +60,7 @@ public interface ManagedRepositoriesService @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) Boolean deleteManagedRepository( @QueryParam( "repositoryId" ) String repositoryId, @QueryParam( "deleteContent" ) boolean deleteContent ) - throws Exception; + throws ArchivaRestServiceException; @Path( "addManagedRepository" ) @@ -69,7 +69,7 @@ public interface ManagedRepositoriesService @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) Boolean addManagedRepository( ManagedRepository managedRepository ) - throws Exception; + throws ArchivaRestServiceException; @Path( "updateManagedRepository" ) @@ -78,7 +78,7 @@ public interface ManagedRepositoriesService @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) Boolean updateManagedRepository( ManagedRepository managedRepository ) - throws Exception; + throws ArchivaRestServiceException; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java index 12537b35d..a1542a851 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java @@ -50,13 +50,6 @@ public interface SearchService List quickSearch( @QueryParam( "queryString" ) String queryString ) throws ArchivaRestServiceException; - @Path( "getArtifactByChecksum" ) - @GET - @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) - @RedbackAuthorization( noPermission = true, noRestriction = true ) - List getArtifactByChecksum( @QueryParam( "checksum" ) String checksum ) - throws ArchivaRestServiceException; - @Path( "getArtifactVersions" ) @GET @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) @@ -74,4 +67,11 @@ public interface SearchService @QueryParam( "version" ) String version ) throws ArchivaRestServiceException; + @Path( "getArtifactByChecksum" ) + @GET + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) + @RedbackAuthorization( noPermission = true, noRestriction = true ) + List getArtifactByChecksum( @QueryParam( "checksum" ) String checksum ) + throws ArchivaRestServiceException; + } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java index dc968434a..86be24001 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java @@ -23,6 +23,8 @@ import org.apache.archiva.audit.AuditListener; import org.codehaus.plexus.redback.users.User; import org.codehaus.redback.rest.services.RedbackAuthenticationThreadLocal; import org.codehaus.redback.rest.services.RedbackRequestInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Inject; import java.util.ArrayList; @@ -37,6 +39,8 @@ import java.util.List; public abstract class AbstractRestService { + protected Logger log = LoggerFactory.getLogger( getClass() ); + @Inject private List auditListeners = new ArrayList(); diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java index f2fa197d4..a12282113 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java @@ -20,6 +20,7 @@ package org.apache.archiva.rest.services; import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; +import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.rest.api.model.ManagedRepository; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.ManagedRepositoriesService; @@ -43,6 +44,10 @@ public class DefaultManagedRepositoriesService @Inject private ManagedRepositoryAdmin managedRepositoryAdmin; + @Inject + private PlexusSisuBridge plexusSisuBridge; + + public List getManagedRepositories() throws ArchivaRestServiceException { @@ -87,14 +92,22 @@ public class DefaultManagedRepositoriesService public Boolean deleteManagedRepository( String repoId, boolean deleteContent ) - throws Exception + throws ArchivaRestServiceException { - return managedRepositoryAdmin.deleteManagedRepository( repoId, getAuditInformation(), deleteContent ); + try + { + return managedRepositoryAdmin.deleteManagedRepository( repoId, getAuditInformation(), deleteContent ); + } + catch ( RepositoryAdminException e ) + { + log.error( e.getMessage(), e ); + throw new ArchivaRestServiceException( e.getMessage() ); + } } public Boolean addManagedRepository( ManagedRepository managedRepository ) - throws Exception + throws ArchivaRestServiceException { org.apache.archiva.admin.model.managed.ManagedRepository repo = new org.apache.archiva.admin.model.managed.ManagedRepository(); @@ -106,13 +119,20 @@ public class DefaultManagedRepositoriesService repo.setName( managedRepository.getName() ); repo.setReleases( managedRepository.isReleases() ); repo.setSnapshots( managedRepository.isSnapshots() ); - return managedRepositoryAdmin.addManagedRepository( repo, managedRepository.isStageRepoNeeded(), - getAuditInformation() ); + try + { + return managedRepositoryAdmin.addManagedRepository( repo, managedRepository.isStageRepoNeeded(), + getAuditInformation() ); + } + catch ( RepositoryAdminException e ) + { + throw new ArchivaRestServiceException( e.getMessage() ); + } } public Boolean updateManagedRepository( ManagedRepository managedRepository ) - throws Exception + throws ArchivaRestServiceException { org.apache.archiva.admin.model.managed.ManagedRepository repo = new org.apache.archiva.admin.model.managed.ManagedRepository(); @@ -124,9 +144,16 @@ public class DefaultManagedRepositoriesService repo.setName( managedRepository.getName() ); repo.setReleases( managedRepository.isReleases() ); repo.setSnapshots( managedRepository.isSnapshots() ); - return managedRepositoryAdmin.updateManagedRepository( repo, managedRepository.isStageRepoNeeded(), - getAuditInformation(), - managedRepository.isResetStats() ); + try + { + return managedRepositoryAdmin.updateManagedRepository( repo, managedRepository.isStageRepoNeeded(), + getAuditInformation(), + managedRepository.isResetStats() ); + } + catch ( RepositoryAdminException e ) + { + throw new ArchivaRestServiceException( e.getMessage() ); + } } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java index a4a62e576..98e281826 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java @@ -126,6 +126,7 @@ public class DefaultRepositoriesService mavenIndexerUtils.getAllIndexCreators() ) ); ArtifactIndexingTask task = new ArtifactIndexingTask( repository, null, ArtifactIndexingTask.Action.FINISH, context ); + task.setExecuteOnEntireRepo( true ); task.setOnlyUpdate( false ); @@ -134,6 +135,7 @@ public class DefaultRepositoriesService } catch ( Exception e ) { + log.error( e.getMessage(), e ); throw new ArchivaRestServiceException( e.getMessage() ); } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java index a4d8cbfc8..7d49c83dd 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java @@ -21,6 +21,7 @@ package org.apache.archiva.rest.services; import net.sf.beanlib.provider.replicator.BeanReplicator; import org.apache.archiva.indexer.search.RepositorySearch; import org.apache.archiva.indexer.search.RepositorySearchException; +import org.apache.archiva.indexer.search.SearchFields; import org.apache.archiva.indexer.search.SearchResultHit; import org.apache.archiva.indexer.search.SearchResultLimits; import org.apache.archiva.indexer.search.SearchResults; @@ -85,16 +86,30 @@ public class DefaultSearchService } } - public List getArtifactByChecksum( String checksum ) - throws ArchivaRestServiceException - { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - public List getArtifactVersions( String groupId, String artifactId ) throws ArchivaRestServiceException { - return null; //To change body of implemented methods use File | Settings | File Templates. + if ( StringUtils.isBlank( groupId ) || StringUtils.isBlank( artifactId ) ) + { + return Collections.emptyList(); + } + SearchFields searchField = new SearchFields(); + searchField.setGroupId( groupId ); + searchField.setArtifactId( artifactId ); + SearchResultLimits limits = new SearchResultLimits( 0 ); + + try + { + SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, limits ); + return getArtifacts( searchResults ); + } + catch ( RepositorySearchException e ) + { + log.error( e.getMessage(), e ); + throw new ArchivaRestServiceException( e.getMessage() ); + } + + } public List getDependencies( String groupId, String artifactId, String version ) @@ -103,6 +118,12 @@ public class DefaultSearchService return null; //To change body of implemented methods use File | Settings | File Templates. } + public List getArtifactByChecksum( String checksum ) + throws ArchivaRestServiceException + { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + protected List getObservableRepos() { @@ -144,18 +165,45 @@ public class DefaultSearchService return Collections.emptyList(); } List artifacts = new ArrayList( searchResults.getReturnedHitsCount() ); - for ( SearchResultHit searchResultHit : searchResults.getHits() ) + for ( SearchResultHit hit : searchResults.getHits() ) { - Artifact artifact = new BeanReplicator().replicateBean( searchResultHit, Artifact.class ); - artifacts.add( artifact ); // duplicate Artifact one per available version - if ( searchResultHit.getVersions().size() > 1 ) + if ( hit.getVersions().size() > 0 ) { - for ( String version : searchResultHit.getVersions() ) + for ( String version : hit.getVersions() ) { - Artifact versionned = new BeanReplicator().replicateBean( searchResultHit, Artifact.class ); - versionned.setVersion( version ); - artifacts.add( versionned ); + /* + Artifact versionned = new Artifact( ); + versionned.setArtifactId( hit.getArtifactId()); + versionned.setGroupId( hit.getGroupId() ); + versionned.setRepositoryId(hit.getRepositoryId() ); + + + versionned.setBundleExportPackage( hit.getBundleExportPackage() ); + versionned.setBundleExportService( hit.getBundleExportService()); + versionned.setBundleSymbolicName(hit.getBundleSymbolicName() ); + versionned.setBundleVersion( artifactInfo.bundleVersion ); + versionned.setBundleDescription( artifactInfo.bundleDescription ); + versionned.setBundleDocUrl( artifactInfo.bundleDocUrl ); + + versionned.setBundleRequireBundle( artifactInfo.bundleRequireBundle ); + versionned.setBundleImportPackage( artifactInfo.bundleImportPackage ); + versionned.setBundleLicense( artifactInfo.bundleLicense ); + versionned.setBundleName( artifactInfo.bundleName ); + versionned.setContext( artifactInfo.context ); + versionned.setGoals( artifactInfo.goals ); + versionned.setPrefix( artifactInfo.prefix ); + // sure ?? + versionned.setUrl( artifactInfo.remoteUrl ); + */ + // FIXME archiva url ?? + + Artifact versionned = new BeanReplicator().replicateBean( hit, Artifact.class ); + if ( StringUtils.isNotBlank( version ) ) + { + versionned.setVersion( version ); + artifacts.add( versionned ); + } } } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java index 99eb661e9..38630a698 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java @@ -34,6 +34,8 @@ import java.util.List; public class SearchServiceTest extends AbstractArchivaRestTest { + + @Test public void quickSearchOnArtifactId() throws Exception @@ -46,28 +48,49 @@ public class SearchServiceTest assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); } - createAndIndexRepo( testRepoId ); + File targetRepo = createAndIndexRepo( testRepoId ); SearchService searchService = getSearchService( authorizationHeader ); List artifacts = searchService.quickSearch( "commons-logging" ); assertNotNull( artifacts ); - assertTrue( " empty results for commons-logging search", artifacts.size() > 0 ); - log.info( "artifacts for commons-logginf search {}", artifacts ); + assertTrue( " empty results for commons-logging search", artifacts.size() == 6 ); + log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts ); - deleteTestRepo( testRepoId ); + deleteTestRepo( testRepoId, targetRepo ); } - private void createAndIndexRepo( String testRepoId ) + @Test + public void searchArtifactVersions() + throws Exception + { + + String testRepoId = "test-repo"; + // force guest user creation if not exists + if ( getUserService( authorizationHeader ).getGuestUser() == null ) + { + assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); + } + + File targetRepo = createAndIndexRepo( testRepoId ); + + SearchService searchService = getSearchService( authorizationHeader ); + + List artifacts = searchService.getArtifactVersions( "commons-logging", "commons-logging" ); + + assertNotNull( artifacts ); + assertTrue( " empty results for commons-logging search", artifacts.size() == 6 ); + log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts ); + + deleteTestRepo( testRepoId, targetRepo ); + } + + private File createAndIndexRepo( String testRepoId ) throws Exception { File targetRepo = new File( System.getProperty( "targetDir", "./target" ), "test-repo" ); - - if ( targetRepo.exists() ) - { - FileUtils.deleteDirectory( targetRepo ); - } + cleanupFiles( targetRepo ); File sourceRepo = new File( "src/test/repo-with-osgi" ); @@ -76,24 +99,54 @@ public class SearchServiceTest ManagedRepository managedRepository = new ManagedRepository(); managedRepository.setId( testRepoId ); managedRepository.setName( "test repo" ); - managedRepository.setCronExpression( "* * * * * ?" ); - managedRepository.setScanned( false ); managedRepository.setLocation( targetRepo.getPath() ); ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader ); service.addManagedRepository( managedRepository ); + getRepositoriesService( authorizationHeader ).scanRepositoryNow( testRepoId, true ); + + return targetRepo; } - private void deleteTestRepo( String id ) + private void deleteTestRepo( String id, File targetRepo ) throws Exception { if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( id ) != null ) { getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( id, true ); } + cleanupFiles( targetRepo ); + + } + + private void cleanupFiles(File targetRepo) + throws Exception + { + + File indexerDir = new File( targetRepo, ".indexer" ); + + if ( targetRepo.exists() ) + { + FileUtils.deleteDirectory( targetRepo ); + } + + if ( indexerDir.exists() ) + { + FileUtils.deleteDirectory( indexerDir ); + } + + File lockFile = new File( indexerDir, "write.lock" ); + if ( lockFile.exists() ) + { + FileUtils.forceDelete( lockFile ); + } + + assertFalse( targetRepo.exists() ); + assertFalse( indexerDir.exists() ); + assertFalse( lockFile.exists() ); } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/log4j.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/log4j.xml index 43d8a8bbb..8451b6263 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/log4j.xml +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/log4j.xml @@ -38,14 +38,14 @@ - + - +