Search in sources :

Example 16 with ManagedRepository

use of org.apache.archiva.repository.ManagedRepository in project archiva by apache.

the class CleanupReleasedSnapshotsRepositoryPurgeTest method testNonArtifactFile.

@Test
public void testNonArtifactFile() throws Exception {
    RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class);
    ManagedRepository managedRepository = repositoryRegistry.getManagedRepository(TEST_REPO_ID);
    repositoryRegistry.removeRepository(managedRepository);
    repositoryRegistry.putRepository(getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME));
    String repoRoot = prepareTestRepos();
    // test listeners for the correct artifacts
    listenerControl.replay();
    Path file = Paths.get(repoRoot, INDEX_PATH);
    if (!Files.exists(file)) {
        // help windauze to create directory with .
        Files.createDirectories(file.getParent());
        Files.createFile(file);
    }
    assertTrue(Files.exists(file));
    repoPurge.process(INDEX_PATH);
    listenerControl.verify();
    assertTrue(Files.exists(file));
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.repository.ManagedRepository) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) Test(org.junit.Test)

Example 17 with ManagedRepository

use of org.apache.archiva.repository.ManagedRepository in project archiva by apache.

the class CleanupReleasedSnapshotsRepositoryPurgeTest method testHigherSnapshotExistsInSameRepo.

@Test
public void testHigherSnapshotExistsInSameRepo() throws Exception {
    RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class);
    ManagedRepository managedRepository = repositoryRegistry.getManagedRepository(TEST_REPO_ID);
    repositoryRegistry.removeRepository(TEST_REPO_ID);
    repositoryRegistry.putRepository(getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME));
    String repoRoot = prepareTestRepos();
    String projectNs = "org.apache.maven.plugins";
    String projectPath = projectNs.replaceAll("\\.", "/");
    String projectName = "maven-source-plugin";
    String projectVersion = "2.0.2";
    String projectRoot = repoRoot + "/" + projectPath + "/" + projectName;
    Path repo = getTestRepoRootPath();
    Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
    Path vDir2 = repo.resolve(projectPath).resolve(projectName).resolve("2.0.3-SNAPSHOT");
    Path vDir3 = repo.resolve(projectPath).resolve(projectName).resolve("2.0.4-SNAPSHOT");
    // test listeners for the correct artifacts - no deletions
    listenerControl.replay();
    // Provide the metadata list
    List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, projectVersion)).thenReturn(ml);
    List<ArtifactMetadata> m2 = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir2);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, "2.0.3-SNAPSHOT")).thenReturn(ml);
    List<ArtifactMetadata> m3 = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir3);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, "2.0.4-SNAPSHOT")).thenReturn(ml);
    repoPurge.process(CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_HIGHER_SNAPSHOT_EXISTS_IN_SAME_REPO);
    listenerControl.verify();
    // Verify the metadataRepository invocations
    // No removal
    verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
    verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq("2.0.3-SNAPSHOT"));
    verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq("2.0.4-SNAPSHOT"));
    verify(metadataRepository, never()).removeArtifact(any(ArtifactMetadata.class), any(String.class));
    verify(metadataRepository, never()).removeArtifact(any(String.class), any(String.class), any(String.class), any(String.class), any(MetadataFacet.class));
    // check if the snapshot was not removed
    assertExists(projectRoot + "/2.0.3-SNAPSHOT");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar.md5");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar.sha1");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom.md5");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom.sha1");
    // check if the released version was not removed
    assertExists(projectRoot + "/2.0.4-SNAPSHOT");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar.md5");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar.sha1");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom.md5");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom.sha1");
    // check if metadata file was not updated (because nothing was removed)
    Path artifactMetadataFile = Paths.get(projectRoot + "/maven-metadata.xml");
    String metadataXml = org.apache.archiva.common.utils.FileUtils.readFileToString(artifactMetadataFile, Charset.defaultCharset());
    String expectedVersions = "<expected><versions><version>2.0.3-SNAPSHOT</version>" + "<version>2.0.4-SNAPSHOT</version></versions></expected>";
    XMLAssert.assertXpathEvaluatesTo("2.0.4-SNAPSHOT", "//metadata/versioning/latest", metadataXml);
    XMLAssert.assertXpathsEqual("//expected/versions/version", expectedVersions, "//metadata/versioning/versions/version", metadataXml);
    XMLAssert.assertXpathEvaluatesTo("20070427033345", "//metadata/versioning/lastUpdated", metadataXml);
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.repository.ManagedRepository) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 18 with ManagedRepository

use of org.apache.archiva.repository.ManagedRepository in project archiva by apache.

the class MetadataUpdaterConsumer method beginScan.

@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);
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) RepositoryException(org.apache.archiva.repository.RepositoryException) ConsumerException(org.apache.archiva.consumers.ConsumerException) RepositoryNotFoundException(org.apache.archiva.repository.RepositoryNotFoundException)

Example 19 with ManagedRepository

use of org.apache.archiva.repository.ManagedRepository 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)

Example 20 with ManagedRepository

use of org.apache.archiva.repository.ManagedRepository in project archiva by apache.

the class RepositoryScannerTest method testTimestampRepositoryScannerFreshScan.

@Test
public void testTimestampRepositoryScannerFreshScan() throws Exception {
    ManagedRepository repository = createSimpleRepository();
    List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<>();
    KnownScanConsumer consumer = new KnownScanConsumer();
    consumer.setIncludes(ARTIFACT_PATTERNS);
    knownConsumers.add(consumer);
    List<InvalidRepositoryContentConsumer> invalidConsumers = new ArrayList<>();
    InvalidScanConsumer badconsumer = new InvalidScanConsumer();
    invalidConsumers.add(badconsumer);
    RepositoryScanner scanner = lookupRepositoryScanner();
    RepositoryScanStatistics stats = scanner.scan(repository, knownConsumers, invalidConsumers, getIgnoreList(), RepositoryScanner.FRESH_SCAN);
    assertNotNull("Stats should not be null.", stats);
    assertEquals("Stats.totalFileCount", 4, stats.getTotalFileCount());
    assertEquals("Stats.newFileCount", 4, stats.getNewFileCount());
    assertEquals("Processed Count", 3, consumer.getProcessCount());
    assertEquals("Processed Count (of invalid items)", 1, badconsumer.getProcessCount());
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) ArrayList(java.util.ArrayList) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer) Test(org.junit.Test)

Aggregations

ManagedRepository (org.apache.archiva.repository.ManagedRepository)27 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)13 Path (java.nio.file.Path)11 InvalidRepositoryContentConsumer (org.apache.archiva.consumers.InvalidRepositoryContentConsumer)9 KnownRepositoryContentConsumer (org.apache.archiva.consumers.KnownRepositoryContentConsumer)9 BasicManagedRepository (org.apache.archiva.repository.BasicManagedRepository)9 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)8 IOException (java.io.IOException)7 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)5 RemoteRepository (org.apache.archiva.repository.RemoteRepository)5 IndexingContext (org.apache.maven.index.context.IndexingContext)5 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)4 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)3 IndexCreationFailedException (org.apache.archiva.indexer.IndexCreationFailedException)3 RepositoryRegistry (org.apache.archiva.repository.RepositoryRegistry)3 DavException (org.apache.jackrabbit.webdav.DavException)3 Date (java.util.Date)2 Inject (javax.inject.Inject)2 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)2