diff options
author | Olivier Lamy <olamy@apache.org> | 2012-03-09 23:44:11 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2012-03-09 23:44:11 +0000 |
commit | 33577da0f917199c65dc2ed7951141ebcf2c5545 (patch) | |
tree | 913272c348d3f60f9326a8ff786af950eb154b5e /archiva-modules/archiva-web | |
parent | 6ab573edc1057d993529aea349651c9405099155 (diff) | |
download | archiva-33577da0f917199c65dc2ed7951141ebcf2c5545.tar.gz archiva-33577da0f917199c65dc2ed7951141ebcf2c5545.zip |
add REST method to really scan repositories
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1299102 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-web')
4 files changed, 54 insertions, 4 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml index b0478d5a8..c2d6afd46 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml @@ -51,6 +51,11 @@ </dependency> <dependency> + <groupId>org.apache.archiva</groupId> + <artifactId>archiva-repository-scanner</artifactId> + </dependency> + + <dependency> <groupId>org.codehaus.redback</groupId> <artifactId>redback-authorization-api</artifactId> <exclusions> diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java index 6f3a3a7d6..c747d73f6 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java @@ -19,6 +19,7 @@ package org.apache.archiva.rest.api.services; * under the License. */ +import org.apache.archiva.repository.scanner.RepositoryScanStatistics; import org.apache.archiva.rest.api.model.Artifact; import org.apache.archiva.rest.api.model.ArtifactTransferRequest; import org.apache.archiva.security.common.ArchivaRoleConstants; @@ -45,11 +46,26 @@ public interface RepositoriesService @GET @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_RUN_INDEXER ) + /** + * index repository + */ Boolean scanRepository( @QueryParam( "repositoryId" ) String repositoryId, @QueryParam( "fullScan" ) boolean fullScan ) throws ArchivaRestServiceException; + @Path( "scanRepositoryDirectories/{repositoryId}" ) + @GET + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) + @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_RUN_INDEXER ) + /** + * scan directories + * @since 1.4-M3 + */ + RepositoryScanStatistics scanRepositoryDirectories( @PathParam( "repositoryId" ) String repositoryId ) + throws ArchivaRestServiceException; + + @Path( "alreadyScanning/{repositoryId}" ) @GET @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml index 8ec24f8e8..3311f8c94 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml @@ -74,6 +74,10 @@ <artifactId>archiva-repository-layer</artifactId> </dependency> <dependency> + <groupId>org.apache.archiva</groupId> + <artifactId>archiva-repository-scanner</artifactId> + </dependency> + <dependency> <groupId>org.codehaus.redback</groupId> <artifactId>redback-authorization-api</artifactId> <exclusions> 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 7c85aa08c..936f57e69 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 @@ -51,6 +51,9 @@ import org.apache.archiva.repository.metadata.MetadataTools; import org.apache.archiva.repository.metadata.RepositoryMetadataException; import org.apache.archiva.repository.metadata.RepositoryMetadataReader; import org.apache.archiva.repository.metadata.RepositoryMetadataWriter; +import org.apache.archiva.repository.scanner.RepositoryScanStatistics; +import org.apache.archiva.repository.scanner.RepositoryScanner; +import org.apache.archiva.repository.scanner.RepositoryScannerException; import org.apache.archiva.rest.api.model.Artifact; import org.apache.archiva.rest.api.model.ArtifactTransferRequest; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; @@ -146,6 +149,9 @@ public class DefaultRepositoriesService @Inject protected List<RepositoryListener> listeners = new ArrayList<RepositoryListener>(); + @Inject + private RepositoryScanner repoScanner; + private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 }; public Boolean scanRepository( String repositoryId, boolean fullScan ) @@ -735,19 +741,19 @@ public class DefaultRepositoriesService } catch ( RepositoryException e ) { - throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 400 ); + throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500 ); } catch ( MetadataResolutionException e ) { - throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 400 ); + throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500 ); } catch ( MetadataRepositoryException e ) { - throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 400 ); + throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500 ); } catch ( RepositoryAdminException e ) { - throw new ArchivaRestServiceException( "RepositoryAdmin exception: " + e.getMessage(), 400 ); + throw new ArchivaRestServiceException( "RepositoryAdmin exception: " + e.getMessage(), 500 ); } finally @@ -757,6 +763,25 @@ public class DefaultRepositoriesService return Boolean.TRUE; } + public RepositoryScanStatistics scanRepositoryDirectories( String repositoryId ) + throws ArchivaRestServiceException + { + long sinceWhen = RepositoryScanner.FRESH_SCAN; + try + { + return repoScanner.scan( getManagedRepositoryAdmin().getManagedRepository( repositoryId ), sinceWhen ); + } + catch ( RepositoryScannerException e ) + { + log.error( e.getMessage(), e ); + throw new ArchivaRestServiceException( "RepositoryScannerException exception: " + e.getMessage(), 500 ); + } + catch ( RepositoryAdminException e ) + { + log.error( e.getMessage(), e ); + throw new ArchivaRestServiceException( "RepositoryScannerException exception: " + e.getMessage(), 500 ); + } + } /** * Update artifact level metadata. Creates one if metadata does not exist after artifact deletion. |