Search in sources :

Example 6 with IndexCreationFeature

use of org.apache.archiva.repository.features.IndexCreationFeature in project archiva by apache.

the class RepositoryProviderMock method getManagedConfiguration.

@Override
public ManagedRepositoryConfiguration getManagedConfiguration(ManagedRepository managedRepository) throws RepositoryException {
    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.setLayout(managedRepository.getLayout());
    configuration.setScanned(managedRepository.isScanned());
    configuration.setRefreshCronExpression(managedRepository.getSchedulingDefinition());
    configuration.setReleases(managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE));
    configuration.setSnapshots(managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT));
    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;
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature)

Example 7 with IndexCreationFeature

use of org.apache.archiva.repository.features.IndexCreationFeature in project archiva by apache.

the class MavenIndexManager method getIndexPath.

private Path getIndexPath(Repository repo) throws IOException {
    IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
    Path repoDir = repo.getLocalPath();
    URI indexDir = icf.getIndexPath();
    Path indexDirectory = null;
    if (!StringUtils.isEmpty(indexDir.toString())) {
        indexDirectory = PathUtil.getPathFromUri(indexDir);
        // not absolute so create it in repository directory
        if (!indexDirectory.isAbsolute()) {
            indexDirectory = repoDir.resolve(indexDirectory);
        }
    } else {
        indexDirectory = repoDir.resolve(DEFAULT_INDEXER_DIR);
    }
    if (!Files.exists(indexDirectory)) {
        Files.createDirectories(indexDirectory);
    }
    return indexDirectory;
}
Also used : Path(java.nio.file.Path) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) URI(java.net.URI)

Example 8 with IndexCreationFeature

use of org.apache.archiva.repository.features.IndexCreationFeature in project archiva by apache.

the class MavenIndexManager method updateLocalIndexPath.

@Override
public void updateLocalIndexPath(Repository repo) {
    if (repo.supportsFeature(IndexCreationFeature.class)) {
        IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
        try {
            icf.setLocalIndexPath(getIndexPath(repo));
            icf.setLocalPackedIndexPath(getPackedIndexPath(repo));
        } catch (IOException e) {
            log.error("Could not set local index path for {}. New URI: {}", repo.getId(), icf.getIndexPath());
        }
    }
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) IOException(java.io.IOException)

Example 9 with IndexCreationFeature

use of org.apache.archiva.repository.features.IndexCreationFeature in project archiva by apache.

the class MavenIndexManager method getPackedIndexPath.

private Path getPackedIndexPath(Repository repo) throws IOException {
    IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
    Path repoDir = repo.getLocalPath();
    URI indexDir = icf.getPackedIndexPath();
    Path indexDirectory = null;
    if (!StringUtils.isEmpty(indexDir.toString())) {
        indexDirectory = PathUtil.getPathFromUri(indexDir);
        // not absolute so create it in repository directory
        if (!indexDirectory.isAbsolute()) {
            indexDirectory = repoDir.resolve(indexDirectory);
        }
    } else {
        indexDirectory = repoDir.resolve(DEFAULT_PACKED_INDEX_DIR);
    }
    if (!Files.exists(indexDirectory)) {
        Files.createDirectories(indexDirectory);
    }
    return indexDirectory;
}
Also used : Path(java.nio.file.Path) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) URI(java.net.URI)

Example 10 with IndexCreationFeature

use of org.apache.archiva.repository.features.IndexCreationFeature in project archiva by apache.

the class AbstractMavenRepositorySearch method createIndex.

protected void createIndex(String repository, List<Path> filesToBeIndexed, boolean scan, Path indexDir) throws Exception {
    Repository rRepo = repositoryRegistry.getRepository(repository);
    IndexCreationFeature icf = rRepo.getFeature(IndexCreationFeature.class).get();
    IndexingContext context = rRepo.getIndexingContext().getBaseContext(IndexingContext.class);
    if (context != null) {
        context.close(true);
    }
    Path repoDir = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir()).resolve("target").resolve("repos").resolve(repository);
    Path indexerDirectory = repoDir.resolve(".indexer");
    if (Files.exists(indexerDirectory)) {
        FileUtils.deleteDirectory(indexerDirectory);
    }
    assertFalse(Files.exists(indexerDirectory));
    Path lockFile = repoDir.resolve(".indexer/write.lock");
    if (Files.exists(lockFile)) {
        Files.delete(lockFile);
    }
    assertFalse(Files.exists(lockFile));
    Path repo = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + repository);
    assertTrue(Files.exists(repo));
    org.apache.commons.io.FileUtils.copyDirectory(repo.toFile(), repoDir.toFile());
    if (indexDir == null) {
        Path indexDirectory = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/index/test-" + Long.toString(System.currentTimeMillis()));
        indexDirectory.toFile().deleteOnExit();
        FileUtils.deleteDirectory(indexDirectory);
        icf.setIndexPath(indexDirectory.toUri());
    } else {
        icf.setIndexPath(indexDir.toUri());
    }
    context = rRepo.getIndexingContext().getBaseContext(IndexingContext.class);
    // context.getIndexWriter().setRAMBufferSizeMB( 1 );
    for (Path artifactFile : filesToBeIndexed) {
        assertTrue("file not exists " + artifactFile, Files.exists(artifactFile));
        ArtifactContext ac = artifactContextProducer.getArtifactContext(context, artifactFile.toFile());
        if (artifactFile.toString().endsWith(".pom")) {
            ac.getArtifactInfo().setFileExtension("pom");
            ac.getArtifactInfo().setPackaging("pom");
            ac.getArtifactInfo().setClassifier("pom");
        }
        indexer.addArtifactToIndex(ac, context);
        context.updateTimestamp(true);
    }
    if (scan) {
        DefaultScannerListener listener = new DefaultScannerListener(context, indexerEngine, true, new ArtifactScanListener());
        ScanningRequest req = new ScanningRequest(context, listener);
        scanner.scan(req);
        context.commit();
    }
    // force flushing
    context.commit();
    // context.getIndexWriter().commit();
    context.setSearchable(true);
}
Also used : Path(java.nio.file.Path) ScanningRequest(org.apache.maven.index.ScanningRequest) Repository(org.apache.archiva.repository.Repository) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) DefaultScannerListener(org.apache.maven.index.DefaultScannerListener) IndexingContext(org.apache.maven.index.context.IndexingContext) ArtifactContext(org.apache.maven.index.ArtifactContext)

Aggregations

IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)27 URI (java.net.URI)11 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)10 StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)10 Path (java.nio.file.Path)9 RepositoryException (org.apache.archiva.repository.RepositoryException)6 IOException (java.io.IOException)5 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)5 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)5 Test (org.junit.Test)5 PasswordCredentials (org.apache.archiva.repository.PasswordCredentials)4 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)3 ManagedRepository (org.apache.archiva.repository.ManagedRepository)3 BasicManagedRepository (org.apache.archiva.repository.BasicManagedRepository)2 RemoteRepository (org.apache.archiva.repository.RemoteRepository)2 RepositoryCredentials (org.apache.archiva.repository.RepositoryCredentials)2 UnsupportedURIException (org.apache.archiva.repository.UnsupportedURIException)2 IndexingContext (org.apache.maven.index.context.IndexingContext)2 URISyntaxException (java.net.URISyntaxException)1 Files (java.nio.file.Files)1