Search in sources :

Example 1 with RepositoryScannerException

use of org.apache.archiva.repository.scanner.RepositoryScannerException in project archiva by apache.

the class DefaultLegacyRepositoryConverter method convertLegacyRepository.

@Override
public void convertLegacyRepository(Path legacyRepositoryDirectory, Path repositoryDirectory, List<String> fileExclusionPatterns) throws RepositoryConversionException {
    try {
        String defaultRepositoryUrl = PathUtil.toUrl(repositoryDirectory);
        BasicManagedRepository legacyRepository = new BasicManagedRepository("legacy", "Legacy Repository", repositoryDirectory.getParent());
        legacyRepository.setLocation(legacyRepositoryDirectory.toAbsolutePath().toUri());
        legacyRepository.setLayout("legacy");
        ArtifactRepository repository = artifactRepositoryFactory.createArtifactRepository("default", defaultRepositoryUrl, defaultLayout, null, null);
        legacyConverterConsumer.setExcludes(fileExclusionPatterns);
        legacyConverterConsumer.setDestinationRepository(repository);
        List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<>(1);
        knownConsumers.add(legacyConverterConsumer);
        List<InvalidRepositoryContentConsumer> invalidConsumers = Collections.emptyList();
        List<String> ignoredContent = new ArrayList<String>(Arrays.asList(RepositoryScanner.IGNORABLE_CONTENT));
        repoScanner.scan(legacyRepository, knownConsumers, invalidConsumers, ignoredContent, RepositoryScanner.FRESH_SCAN);
    } catch (RepositoryScannerException e) {
        throw new RepositoryConversionException("Error convering legacy repository.", e);
    }
}
Also used : BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) RepositoryScannerException(org.apache.archiva.repository.scanner.RepositoryScannerException) RepositoryConversionException(org.apache.archiva.converter.RepositoryConversionException) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer)

Example 2 with RepositoryScannerException

use of org.apache.archiva.repository.scanner.RepositoryScannerException in project archiva by apache.

the class ArchivaCli method doScan.

private void doScan(String path, String[] consumers) throws ConsumerException, MalformedURLException {
    BasicManagedRepository repo = new BasicManagedRepository(Paths.get(path).getFileName().toString(), "Archiva CLI Provided Repo", Paths.get(path).getParent());
    repo.setLocation(Paths.get(path).toUri());
    List<KnownRepositoryContentConsumer> knownConsumerList = new ArrayList<>();
    knownConsumerList.addAll(getConsumerList(consumers));
    List<InvalidRepositoryContentConsumer> invalidConsumerList = Collections.emptyList();
    List<String> ignoredContent = new ArrayList<>();
    ignoredContent.addAll(Arrays.asList(RepositoryScanner.IGNORABLE_CONTENT));
    RepositoryScanner scanner = applicationContext.getBean(RepositoryScanner.class);
    try {
        RepositoryScanStatistics stats = scanner.scan(repo, knownConsumerList, invalidConsumerList, ignoredContent, RepositoryScanner.FRESH_SCAN);
        LOGGER.info(stats.toDump(repo));
    } catch (RepositoryScannerException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) RepositoryScanner(org.apache.archiva.repository.scanner.RepositoryScanner) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) RepositoryScanStatistics(org.apache.archiva.repository.scanner.RepositoryScanStatistics) ArrayList(java.util.ArrayList) RepositoryScannerException(org.apache.archiva.repository.scanner.RepositoryScannerException) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer)

Example 3 with RepositoryScannerException

use of org.apache.archiva.repository.scanner.RepositoryScannerException in project archiva by apache.

the class ArchivaRepositoryScanningTaskExecutor method executeTask.

@SuppressWarnings("unchecked")
@Override
public void executeTask(RepositoryTask task) throws TaskExecutionException {
    try {
        // TODO: replace this whole class with the prescribed content scanning service/action
        // - scan repository for artifacts that do not have corresponding metadata or have been updated and
        // send events for each
        // - scan metadata for artifacts that have been removed and send events for each
        // - scan metadata for missing plugin data
        // - store information so that it can restart upon failure (publish event on the server recovery
        // queue, remove it on successful completion)
        this.task = task;
        String repoId = task.getRepositoryId();
        if (StringUtils.isBlank(repoId)) {
            throw new TaskExecutionException("Unable to execute RepositoryTask with blank repository Id.");
        }
        ManagedRepository arepo = repositoryRegistry.getManagedRepository(repoId);
        // execute consumers on resource file if set
        if (task.getResourceFile() != null) {
            log.debug("Executing task from queue with job name: {}", task);
            consumers.executeConsumers(arepo, task.getResourceFile(), task.isUpdateRelatedArtifacts());
        } else {
            log.info("Executing task from queue with job name: {}", task);
            // otherwise, execute consumers on whole repository
            if (arepo == null) {
                throw new TaskExecutionException("Unable to execute RepositoryTask with invalid repository id: " + repoId);
            }
            long sinceWhen = RepositoryScanner.FRESH_SCAN;
            long previousFileCount = 0;
            RepositorySession repositorySession = repositorySessionFactory.createSession();
            MetadataRepository metadataRepository = repositorySession.getRepository();
            try {
                if (!task.isScanAll()) {
                    RepositoryStatistics previousStats = repositoryStatisticsManager.getLastStatistics(metadataRepository, repoId);
                    if (previousStats != null) {
                        sinceWhen = previousStats.getScanStartTime().getTime();
                        previousFileCount = previousStats.getTotalFileCount();
                    }
                }
                RepositoryScanStatistics stats;
                try {
                    stats = repoScanner.scan(arepo, sinceWhen);
                } catch (RepositoryScannerException e) {
                    throw new TaskExecutionException("Repository error when executing repository job.", e);
                }
                log.info("Finished first scan: {}", stats.toDump(arepo));
                // further statistics will be populated by the following method
                Date endTime = new Date(stats.getWhenGathered().getTime() + stats.getDuration());
                log.info("Gathering repository statistics");
                repositoryStatisticsManager.addStatisticsAfterScan(metadataRepository, repoId, stats.getWhenGathered(), endTime, stats.getTotalFileCount(), stats.getTotalFileCount() - previousFileCount);
                repositorySession.save();
            } catch (MetadataRepositoryException e) {
                throw new TaskExecutionException("Unable to store updated statistics: " + e.getMessage(), e);
            } finally {
                repositorySession.close();
            }
            // log.info( "Scanning for removed repository content" );
            // metadataRepository.findAllProjects();
            // FIXME: do something
            log.info("Finished repository task: {}", task);
            this.task = null;
        }
    } catch (RepositoryAdminException e) {
        log.error(e.getMessage(), e);
        throw new TaskExecutionException(e.getMessage(), e);
    }
}
Also used : TaskExecutionException(org.apache.archiva.redback.components.taskqueue.execution.TaskExecutionException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ManagedRepository(org.apache.archiva.repository.ManagedRepository) RepositoryScanStatistics(org.apache.archiva.repository.scanner.RepositoryScanStatistics) RepositoryScannerException(org.apache.archiva.repository.scanner.RepositoryScannerException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics) Date(java.util.Date)

Aggregations

RepositoryScannerException (org.apache.archiva.repository.scanner.RepositoryScannerException)3 ArrayList (java.util.ArrayList)2 InvalidRepositoryContentConsumer (org.apache.archiva.consumers.InvalidRepositoryContentConsumer)2 KnownRepositoryContentConsumer (org.apache.archiva.consumers.KnownRepositoryContentConsumer)2 BasicManagedRepository (org.apache.archiva.repository.BasicManagedRepository)2 RepositoryScanStatistics (org.apache.archiva.repository.scanner.RepositoryScanStatistics)2 Date (java.util.Date)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 RepositoryConversionException (org.apache.archiva.converter.RepositoryConversionException)1 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)1 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)1 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)1 RepositoryStatistics (org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics)1 TaskExecutionException (org.apache.archiva.redback.components.taskqueue.execution.TaskExecutionException)1 ManagedRepository (org.apache.archiva.repository.ManagedRepository)1 RepositoryScanner (org.apache.archiva.repository.scanner.RepositoryScanner)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1