@Override public void beginScan( ManagedRepository repo, Date whenGathered ) throws ConsumerException { repoId = repo.getId(); this.whenGathered = whenGathered; }
@Override public String toString() { return "ArtifactIndexingTask [action=" + action + ", repositoryId=" + repository.getId() + ", resourceFile=" + resourceFile + "]"; }
@Override public String getId() { return repository.getId(); }
private void deleteSilently( Path path ) { try { Files.deleteIfExists( path ); triggerAuditEvent( repository.getRepository( ).getId( ), path.toString( ), AuditEvent.PURGE_FILE ); } catch ( IOException e ) { log.error( "Error occured during file deletion {}: {} ", path, e.getMessage( ), e ); } }
@Override public void execute( RepositoryContentConsumer input ) { RepositoryContentConsumer consumer = (RepositoryContentConsumer) input; consumer.completeScan( executeOnEntireRepo ); log.debug( "Consumer [{}] completed for repository [{}]", consumer.getId( ), repository.getId( ) ); } }
@Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (!isRunning) { isRunning = true; this.basePath = dir; log.info( "Walk Started: [{}] {}", this.repository.getId(), this.repository.getLocation() ); stats.triggerStart(); } return FileVisitResult.CONTINUE; }
@Override public void beginScan( ManagedRepository repo, Date whenGathered ) throws ConsumerException { repoId = repo.getId(); this.repositoryDir = Paths.get( repo.getLocation() ); repositorySession = repositorySessionFactory.createSession(); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + action.hashCode(); result = prime * result + repository.getId().hashCode(); result = prime * result + ( ( resourceFile == null ) ? 0 : resourceFile.hashCode() ); return result; }
public void removeRepository(ManagedRepository managedRepository, Configuration configuration) throws RepositoryException { final String id = managedRepository.getId(); ManagedRepository repo = getManagedRepository( id ); if (repo!=null) { rwLock.writeLock().lock(); try { repo = managedRepositories.remove( id ); if (repo!=null) { repo.close(); ManagedRepositoryConfiguration cfg = configuration.findManagedRepositoryById( id ); if (cfg!=null) { configuration.removeManagedRepository( cfg ); } } } finally { rwLock.writeLock().unlock(); } } }
@Override public void beginScan( ManagedRepository repoConfig, Date whenGathered ) throws ConsumerException { try { ManagedRepository repo = repositoryRegistry.getManagedRepository( repoConfig.getId( ) ); if (repo==null) { throw new RepositoryNotFoundException( "Repository not found: "+repoConfig.getId() ); } this.repository = repo.getContent(); if (this.repository==null) { throw new RepositoryNotFoundException( "Repository content not found: "+repoConfig.getId() ); } this.repositoryDir = Paths.get( repository.getRepoRoot( ) ); this.scanStartTimestamp = System.currentTimeMillis( ); } catch ( RepositoryException e ) { throw new ConsumerException( e.getMessage( ), e ); } }
@Override public Boolean alreadyScanning( String repositoryId ) { // check queue first to make sure it doesn't get dequeued between calls if ( repositoryTaskScheduler.isProcessingRepositoryTask( repositoryId ) ) { return true; } for ( RepositoryScannerInstance scan : repoScanner.getInProgressScans() ) { if ( scan.getRepository().getId().equals( repositoryId ) ) { return true; } } return false; }
public ManagedRepositoryContent getManagedRepositoryContent( org.apache.archiva.repository.ManagedRepository mRepo ) throws RepositoryException { final String id = mRepo.getId(); ManagedRepositoryContent content = managedContentMap.get( id ); if ( content != null && content.getRepository()==mRepo) { return content; } RepositoryContentProvider contentProvider = getProvider( mRepo.getLayout( ), mRepo.getType( ) ); content = contentProvider.createManagedContent( mRepo ); if (content==null) { throw new RepositoryException( "Could not create repository content instance for "+mRepo.getId() ); } ManagedRepositoryContent previousContent = managedContentMap.put( id, content ); if (previousContent!=null) { previousContent.setRepository( null ); } return content; }
private String getLogicalResource( ArchivaDavResourceLocator archivaLocator, org.apache.archiva.repository.ManagedRepository managedRepository, boolean useOrigResourcePath ) { // FIXME remove this hack // but currently managedRepository can be null in case of group String layout = managedRepository == null ? "default" : managedRepository.getLayout(); RepositoryStorage repositoryStorage = this.applicationContext.getBean( "repositoryStorage#" + layout, RepositoryStorage.class ); String path = repositoryStorage.getFilePath( useOrigResourcePath ? archivaLocator.getOrigResourcePath() : archivaLocator.getResourcePath(), managedRepository ); log.debug( "found path {} for resourcePath: '{}' with managedRepo '{}' and layout '{}'", path, archivaLocator.getResourcePath(), managedRepository == null ? "null" : managedRepository.getId(), layout ); return path; }
private void queueRepositoryTask( Path localFile ) { RepositoryTask task = new RepositoryTask(); task.setRepositoryId( repository.getId() ); task.setResourceFile( localFile ); task.setUpdateRelatedArtifacts( false ); task.setScanAll( false ); try { scheduler.queueTask( task ); } catch ( TaskQueueException e ) { log.error( "Unable to queue repository task to execute consumers on resource file ['{}" + "'].", localFile.getFileName() ); } } }
private void finishWalk() { this.isRunning = false; TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure( repository, true ); IterableUtils.forEach( knownConsumers, scanCompletedClosure ); IterableUtils.forEach( invalidConsumers, scanCompletedClosure ); stats.setConsumerTimings( consumerTimings ); stats.setConsumerCounts( consumerCounts ); log.info( "Walk Finished: [{}] {}", this.repository.getId(), this.repository.getLocation() ); stats.triggerFinished(); this.basePath = null; } }
@Override public void beginScan( ManagedRepository repository, Date whenGathered ) throws ConsumerException { this.repository = repository; managedRepository = PathUtil.getPathFromUri( repository.getLocation() ); try { log.info( "Creating indexing context for repo : {}", repository.getId() ); if (repository.getType()== RepositoryType.MAVEN) { indexingContext = repository.getIndexingContext().getBaseContext(IndexingContext.class); } else { indexingContext= null; } } catch (UnsupportedBaseContextException e) { log.error("Bad repository type. Not nexus indexer compatible."); throw new ConsumerException("Bad repository type "+repository.getType()); } }
@Override public List<RepositoryScannerStatistics> getRepositoryScannerStatistics() throws ArchivaRestServiceException { Set<RepositoryScannerInstance> repositoryScannerInstances = scanner.getInProgressScans(); if ( repositoryScannerInstances.isEmpty() ) { return Collections.emptyList(); } List<RepositoryScannerStatistics> repositoryScannerStatisticsList = new ArrayList<RepositoryScannerStatistics>( repositoryScannerInstances.size() ); for ( RepositoryScannerInstance instance : repositoryScannerInstances ) { RepositoryScannerStatistics repositoryScannerStatistics = new RepositoryScannerStatistics(); repositoryScannerStatisticsList.add( repositoryScannerStatistics ); try { repositoryScannerStatistics.setManagedRepository( managedRepositoryAdmin.getManagedRepository( instance.getRepository().getId()) ); } catch ( RepositoryAdminException e ) { log.error("Could not retrieve repository '{}'", instance.getRepository().getId()); } repositoryScannerStatistics.setNewFileCount( instance.getStats().getNewFileCount() ); repositoryScannerStatistics.setTotalFileCount( instance.getStats().getTotalFileCount() ); repositoryScannerStatistics.setConsumerScanningStatistics( mapConsumerScanningStatistics( instance ) ); } return repositoryScannerStatisticsList; }
@SuppressWarnings( "unchecked" ) private void updateRepositoryReferences(RepositoryProvider provider, ManagedRepository repo, ManagedRepositoryConfiguration cfg, Configuration configuration) throws RepositoryException { log.debug("Updating references of repo {}",repo.getId()); if ( repo.supportsFeature( StagingRepositoryFeature.class ) ) { StagingRepositoryFeature feature = repo.getFeature( StagingRepositoryFeature.class ).get( ); if ( feature.isStageRepoNeeded( ) && feature.getStagingRepository() == null) { ManagedRepository stageRepo = getStagingRepository( provider, cfg, configuration); managedRepositories.put(stageRepo.getId(), stageRepo); feature.setStagingRepository( stageRepo ); if (configuration!=null) { replaceOrAddRepositoryConfig( provider.getManagedConfiguration( stageRepo ), configuration ); } } } if ( repo instanceof EditableManagedRepository) { EditableManagedRepository editableRepo = (EditableManagedRepository) repo; if (repo.getContent()==null) { editableRepo.setContent(repositoryContentFactory.getManagedRepositoryContent(repo)); } log.debug("Index repo: "+repo.hasIndex()); if (repo.hasIndex() && repo.getIndexingContext()==null) { log.debug("Creating indexing context for {}", repo.getId()); createIndexingContext(editableRepo); } } }
public RepositoryScannerInstance( ManagedRepository repository, List<KnownRepositoryContentConsumer> knownConsumerList, List<InvalidRepositoryContentConsumer> invalidConsumerList ) { this.repository = repository; this.knownConsumers = knownConsumerList; this.invalidConsumers = invalidConsumerList; addFileNameIncludePattern("**/*"); consumerTimings = new HashMap<>(); consumerCounts = new HashMap<>(); this.consumerProcessFile = new ConsumerProcessFileClosure(); consumerProcessFile.setExecuteOnEntireRepo( true ); consumerProcessFile.setConsumerTimings( consumerTimings ); consumerProcessFile.setConsumerCounts( consumerCounts ); this.consumerWantsFile = new ConsumerWantsFilePredicate( repository ); stats = new RepositoryScanStatistics(); stats.setRepositoryId( repository.getId() ); Closure<RepositoryContentConsumer> triggerBeginScan = new TriggerBeginScanClosure( repository, new Date( System.currentTimeMillis() ), true ); IterableUtils.forEach( knownConsumerList, triggerBeginScan ); IterableUtils.forEach( invalidConsumerList, triggerBeginScan ); if ( SystemUtils.IS_OS_WINDOWS ) { consumerWantsFile.setCaseSensitive( false ); } }
@Override public ManagedRepositoryConfiguration getManagedConfiguration( ManagedRepository managedRepository ) { ManagedRepositoryConfiguration configuration = new ManagedRepositoryConfiguration( ); configuration.setId( managedRepository.getId( ) ); configuration.setName(managedRepository.getName()); configuration.setLocation( managedRepository.getLocation( ) == null ? "" : managedRepository.getLocation().toString( ) ); configuration.setBlockRedeployments( managedRepository.blocksRedeployments( ) ); configuration.setDescription( managedRepository.getDescription( ) ); configuration.setScanned( managedRepository.isScanned( ) ); configuration.setRefreshCronExpression( managedRepository.getSchedulingDefinition( ) ); configuration.setReleases( managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE) ); configuration.setSnapshots( managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT) ); configuration.setLayout( managedRepository.getLayout() ); ArtifactCleanupFeature acf = managedRepository.getFeature( ArtifactCleanupFeature.class ).get( ); configuration.setRetentionPeriod( acf.getRetentionPeriod( ).getDays( ) ); configuration.setDeleteReleasedSnapshots( acf.isDeleteReleasedSnapshots( ) ); configuration.setRetentionCount( acf.getRetentionCount( ) ); IndexCreationFeature icf = managedRepository.getFeature( IndexCreationFeature.class ).get( ); configuration.setSkipPackedIndexCreation( icf.isSkipPackedIndexCreation( ) ); configuration.setIndexDir( icf.getIndexPath( ) == null ? "" : icf.getIndexPath().toString( ) ); StagingRepositoryFeature srf = managedRepository.getFeature( StagingRepositoryFeature.class ).get( ); configuration.setStageRepoNeeded( srf.isStageRepoNeeded( ) ); return configuration; }