@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_RUN_INDEXER )
Boolean scanRepository( @QueryParam( "repositoryId" ) String repositoryId,
- @QueryParam( "fullScan" ) boolean fullScan );
+ @QueryParam( "fullScan" ) boolean fullScan )
+ throws ArchivaRestServiceException;
@Path( "alreadyScanning/{repositoryId}" )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_RUN_INDEXER )
- Boolean alreadyScanning( @PathParam( "repositoryId" ) String repositoryId );
+ Boolean alreadyScanning( @PathParam( "repositoryId" ) String repositoryId )
+ throws ArchivaRestServiceException;
@Path( "removeScanningTaskFromQueue/{repositoryId}" )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_RUN_INDEXER )
- Boolean removeScanningTaskFromQueue( @PathParam( "repositoryId" ) String repositoryId );
+ Boolean removeScanningTaskFromQueue( @PathParam( "repositoryId" ) String repositoryId )
+ throws ArchivaRestServiceException;
+
+ @Path( "scanRepositoryNow" )
+ @GET
+ @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+ @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_RUN_INDEXER )
+ Boolean scanRepositoryNow( @QueryParam( "repositoryId" ) String repositoryId,
+ @QueryParam( "fullScan" ) boolean fullScan )
+ throws ArchivaRestServiceException;
}
<artifactId>archiva-configuration</artifactId>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-scheduler-indexing</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>audit</artifactId>
* under the License.
*/
+import org.apache.archiva.admin.model.managed.ManagedRepository;
+import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
+import org.apache.archiva.common.plexusbridge.MavenIndexerUtils;
+import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
+import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
import org.apache.archiva.rest.api.services.RepositoriesService;
+import org.apache.archiva.scheduler.indexing.ArchivaIndexingTaskExecutor;
+import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask;
import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
import org.apache.archiva.scheduler.repository.RepositoryTask;
-import org.codehaus.plexus.redback.role.RoleManager;
+import org.apache.maven.index.NexusIndexer;
+import org.apache.maven.index.context.IndexCreator;
+import org.apache.maven.index.context.IndexingContext;
import org.codehaus.plexus.taskqueue.TaskQueueException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.PathParam;
+import java.util.ArrayList;
/**
* @author Olivier Lamy
{
private Logger log = LoggerFactory.getLogger( getClass() );
- @Inject
- protected RoleManager roleManager;
-
@Inject
@Named( value = "archivaTaskScheduler#repository" )
private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
+ @Inject
+ @Named( value = "taskExecutor#indexing" )
+ private ArchivaIndexingTaskExecutor archivaIndexingTaskExecutor;
+
+ @Inject
+ private ManagedRepositoryAdmin managedRepositoryAdmin;
+
+ @Inject
+ private PlexusSisuBridge plexusSisuBridge;
+
+ @Inject
+ private MavenIndexerUtils mavenIndexerUtils;
// FIXME olamy move this to repository admin component !
public Boolean scanRepository( String repositoryId, boolean fullScan )
return false;
}
}
+
+ public Boolean scanRepositoryNow( String repositoryId, boolean fullScan )
+ throws ArchivaRestServiceException
+ {
+
+ try
+ {
+ ManagedRepository repository = managedRepositoryAdmin.getManagedRepository( repositoryId );
+
+ IndexingContext context =
+ ArtifactIndexingTask.createContext( repository, plexusSisuBridge.lookup( NexusIndexer.class ),
+ new ArrayList<IndexCreator>(
+ mavenIndexerUtils.getAllIndexCreators() ) );
+ ArtifactIndexingTask task =
+ new ArtifactIndexingTask( repository, null, ArtifactIndexingTask.Action.FINISH, context );
+ task.setExecuteOnEntireRepo( true );
+ task.setOnlyUpdate( false );
+
+ archivaIndexingTaskExecutor.executeTask( task );
+ return Boolean.TRUE;
+ }
+ catch ( Exception e )
+ {
+ throw new ArchivaRestServiceException( e.getMessage() );
+ }
+ }
}
throws Exception
{
- // olamy temporary disabled due to huge refactoring
- if (true)
- {
- return;
- }
-
String testRepoId = "test-repo";
// force guest user creation if not exists
if ( getUserService( authorizationHeader ).getGuestUser() == null )
assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
}
+ createAndIndexRepo( testRepoId );
+
+ SearchService searchService = getSearchService( authorizationHeader );
+
+ List<Artifact> 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 );
+
+ deleteTestRepo( testRepoId );
+ }
+
+ private void createAndIndexRepo( String testRepoId )
+ throws Exception
+ {
File targetRepo = new File( System.getProperty( "targetDir", "./target" ), "test-repo" );
if ( targetRepo.exists() )
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 ).scanRepository( testRepoId, true );
-
- while ( getRepositoriesService( authorizationHeader ).alreadyScanning( testRepoId ) )
- {
- Thread.sleep( 1000 );
- }
-
- SearchService searchService = getSearchService( authorizationHeader );
-
- List<Artifact> 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 );
-
- deleteTestRepo( testRepoId );
+ getRepositoriesService( authorizationHeader ).scanRepositoryNow( testRepoId, true );
}
private void deleteTestRepo( String id )