Search in sources :

Example 11 with IndexCreationFeature

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

the class DefaultRemoteRepositoryAdmin method convertRepo.

/*
 * Conversion between the repository from the registry and the serialized DTO for the admin API
 */
private org.apache.archiva.admin.model.beans.RemoteRepository convertRepo(RemoteRepository repo) {
    if (repo == null) {
        return null;
    }
    org.apache.archiva.admin.model.beans.RemoteRepository adminRepo = new org.apache.archiva.admin.model.beans.RemoteRepository(getArchivaConfiguration().getDefaultLocale());
    setBaseRepoAttributes(adminRepo, repo);
    adminRepo.setUrl(convertUriToString(repo.getLocation()));
    adminRepo.setCronExpression(repo.getSchedulingDefinition());
    adminRepo.setCheckPath(repo.getCheckPath());
    adminRepo.setExtraHeaders(repo.getExtraHeaders());
    adminRepo.setExtraParameters(repo.getExtraParameters());
    adminRepo.setTimeout((int) repo.getTimeout().getSeconds());
    RepositoryCredentials creds = repo.getLoginCredentials();
    if (creds != null && creds instanceof PasswordCredentials) {
        PasswordCredentials pCreds = (PasswordCredentials) creds;
        adminRepo.setUserName(pCreds.getUsername());
        adminRepo.setPassword(new String(pCreds.getPassword() != null ? pCreds.getPassword() : new char[0]));
    }
    if (repo.supportsFeature(RemoteIndexFeature.class)) {
        RemoteIndexFeature rif = repo.getFeature(RemoteIndexFeature.class).get();
        adminRepo.setRemoteIndexUrl(convertUriToString(rif.getIndexUri()));
        adminRepo.setDownloadRemoteIndex(rif.isDownloadRemoteIndex());
        adminRepo.setRemoteDownloadNetworkProxyId(rif.getProxyId());
        adminRepo.setDownloadRemoteIndexOnStartup(rif.isDownloadRemoteIndexOnStartup());
        adminRepo.setRemoteDownloadTimeout((int) rif.getDownloadTimeout().getSeconds());
    }
    if (repo.supportsFeature(IndexCreationFeature.class)) {
        IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
        adminRepo.setIndexDirectory(PathUtil.getPathFromUri(icf.getIndexPath()).toString());
    }
    adminRepo.setDescription(repo.getDescription());
    return adminRepo;
}
Also used : RepositoryCredentials(org.apache.archiva.repository.RepositoryCredentials) PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) RemoteRepository(org.apache.archiva.repository.RemoteRepository) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature)

Example 12 with IndexCreationFeature

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

the class ArchivaIndexingTaskExecutor method finishIndexingTask.

private void finishIndexingTask(ArtifactIndexingTask indexingTask, ManagedRepository repository, IndexingContext context) throws TaskExecutionException {
    try {
        log.debug("Finishing indexing");
        context.optimize();
        if (repository.supportsFeature(IndexCreationFeature.class)) {
            IndexCreationFeature icf = repository.getFeature(IndexCreationFeature.class).get();
            if (!icf.isSkipPackedIndexCreation() && icf.getLocalPackedIndexPath() != null) {
                log.debug("Creating packed index from {} on {}", context.getIndexDirectoryFile(), icf.getLocalPackedIndexPath());
                IndexPackingRequest request = new // 
                IndexPackingRequest(// 
                context, context.acquireIndexSearcher().getIndexReader(), icf.getLocalPackedIndexPath().toFile());
                indexPacker.packIndex(request);
                context.updateTimestamp(true);
                log.debug("Index file packed at '{}'.", icf.getLocalPackedIndexPath());
            } else {
                log.debug("skip packed index creation");
            }
        } else {
            log.debug("skip packed index creation");
        }
    } catch (IOException e) {
        log.error("Error occurred while executing indexing task '{}': {}", indexingTask, e.getMessage());
        throw new TaskExecutionException("Error occurred while executing indexing task '" + indexingTask + "'", e);
    }
}
Also used : TaskExecutionException(org.apache.archiva.redback.components.taskqueue.execution.TaskExecutionException) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) IndexPackingRequest(org.apache.maven.index.packer.IndexPackingRequest) IOException(java.io.IOException)

Example 13 with IndexCreationFeature

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

the class ArchivaIndexingTaskExecutorTest method testPackagedIndex.

@Test
public void testPackagedIndex() throws Exception {
    Path basePath = repo.getLocalPath();
    IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
    Path packedIndexDirectory = icf.getLocalPackedIndexPath();
    Path indexerDirectory = icf.getLocalIndexPath();
    Files.list(packedIndexDirectory).filter(path -> path.getFileName().toString().startsWith("nexus-maven-repository-index")).forEach(path -> {
        try {
            System.err.println("Deleting " + path);
            Files.delete(path);
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
    Path artifactFile = basePath.resolve("org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar");
    ArtifactIndexingTask task = new ArtifactIndexingTask(repo, artifactFile, ArtifactIndexingTask.Action.ADD, repo.getIndexingContext());
    task.setExecuteOnEntireRepo(false);
    indexingExecutor.executeTask(task);
    task = new ArtifactIndexingTask(repo, null, ArtifactIndexingTask.Action.FINISH, repo.getIndexingContext());
    task.setExecuteOnEntireRepo(false);
    indexingExecutor.executeTask(task);
    assertTrue(Files.exists(packedIndexDirectory));
    assertTrue(Files.exists(indexerDirectory));
    // test packed index file creation
    // no more zip
    // Assertions.assertThat(new File( indexerDirectory, "nexus-maven-repository-index.zip" )).exists();
    Assertions.assertThat(Files.exists(packedIndexDirectory.resolve("nexus-maven-repository-index.properties")));
    Assertions.assertThat(Files.exists(packedIndexDirectory.resolve("nexus-maven-repository-index.gz")));
    assertFalse(Files.exists(packedIndexDirectory.resolve("nexus-maven-repository-index.1.gz")));
    // unpack .zip index
    // unzipIndex( indexerDirectory.getPath(), destDir.getPath() );
    DefaultIndexUpdater.FileFetcher fetcher = new DefaultIndexUpdater.FileFetcher(packedIndexDirectory.toFile());
    IndexUpdateRequest updateRequest = new IndexUpdateRequest(getIndexingContext(), fetcher);
    // updateRequest.setLocalIndexCacheDir( indexerDirectory );
    indexUpdater.fetchAndUpdateIndex(updateRequest);
    BooleanQuery.Builder qb = new BooleanQuery.Builder();
    qb.add(indexer.constructQuery(MAVEN.GROUP_ID, new StringSearchExpression("org.apache.archiva")), BooleanClause.Occur.SHOULD);
    qb.add(indexer.constructQuery(MAVEN.ARTIFACT_ID, new StringSearchExpression("archiva-index-methods-jar-test")), BooleanClause.Occur.SHOULD);
    FlatSearchRequest request = new FlatSearchRequest(qb.build(), getIndexingContext());
    FlatSearchResponse response = indexer.searchFlat(request);
    assertEquals(1, response.getTotalHitsCount());
    Set<ArtifactInfo> results = response.getResults();
    ArtifactInfo artifactInfo = results.iterator().next();
    assertEquals("org.apache.archiva", artifactInfo.getGroupId());
    assertEquals("archiva-index-methods-jar-test", artifactInfo.getArtifactId());
    assertEquals("test-repo", artifactInfo.getRepository());
}
Also used : Path(java.nio.file.Path) UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) RunWith(org.junit.runner.RunWith) ArtifactInfo(org.apache.maven.index.ArtifactInfo) DefaultIndexUpdater(org.apache.maven.index.updater.DefaultIndexUpdater) IndexUpdater(org.apache.maven.index.updater.IndexUpdater) Inject(javax.inject.Inject) FlatSearchResponse(org.apache.maven.index.FlatSearchResponse) ReleaseScheme(org.apache.archiva.repository.ReleaseScheme) After(org.junit.After) MAVEN(org.apache.maven.index.MAVEN) TopDocs(org.apache.maven.index_shaded.lucene.search.TopDocs) Assertions(org.assertj.core.api.Assertions) TestCase(junit.framework.TestCase) Path(java.nio.file.Path) Before(org.junit.Before) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) Files(java.nio.file.Files) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) BooleanClause(org.apache.maven.index_shaded.lucene.search.BooleanClause) Set(java.util.Set) ArchivaSpringJUnit4ClassRunner(org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner) BooleanQuery(org.apache.maven.index_shaded.lucene.search.BooleanQuery) Test(org.junit.Test) IOException(java.io.IOException) SourcedSearchExpression(org.apache.maven.index.expr.SourcedSearchExpression) Indexer(org.apache.maven.index.Indexer) ManagedRepository(org.apache.archiva.repository.ManagedRepository) IndexUpdateRequest(org.apache.maven.index.updater.IndexUpdateRequest) IndexingContext(org.apache.maven.index.context.IndexingContext) Paths(java.nio.file.Paths) ContextConfiguration(org.springframework.test.context.ContextConfiguration) IndexSearcher(org.apache.maven.index_shaded.lucene.search.IndexSearcher) FlatSearchRequest(org.apache.maven.index.FlatSearchRequest) BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) StringSearchExpression(org.apache.maven.index.expr.StringSearchExpression) BooleanQuery(org.apache.maven.index_shaded.lucene.search.BooleanQuery) FlatSearchResponse(org.apache.maven.index.FlatSearchResponse) IndexUpdateRequest(org.apache.maven.index.updater.IndexUpdateRequest) IOException(java.io.IOException) FlatSearchRequest(org.apache.maven.index.FlatSearchRequest) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ArtifactInfo(org.apache.maven.index.ArtifactInfo) DefaultIndexUpdater(org.apache.maven.index.updater.DefaultIndexUpdater) StringSearchExpression(org.apache.maven.index.expr.StringSearchExpression) Test(org.junit.Test)

Example 14 with IndexCreationFeature

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

the class BasicManagedRepository method initFeatures.

private void initFeatures() {
    IndexCreationFeature indexCreationFeature = new IndexCreationFeature(this, this);
    addFeature(artifactCleanupFeature);
    addFeature(indexCreationFeature);
    addFeature(stagingRepositoryFeature);
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature)

Example 15 with IndexCreationFeature

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

the class RepositoryProviderMock method updateManagedInstance.

@Override
public void updateManagedInstance(EditableManagedRepository managedRepository, ManagedRepositoryConfiguration configuration) throws RepositoryException {
    try {
        managedRepository.setName(managedRepository.getPrimaryLocale(), configuration.getName());
        managedRepository.setLocation(new URI(configuration.getLocation() == null ? "" : configuration.getLocation()));
        managedRepository.setBaseUri(new URI(""));
        managedRepository.setBlocksRedeployment(configuration.isBlockRedeployments());
        managedRepository.setDescription(managedRepository.getPrimaryLocale(), configuration.getDescription());
        managedRepository.setLayout(configuration.getLayout());
        managedRepository.setScanned(configuration.isScanned());
        managedRepository.setSchedulingDefinition(configuration.getRefreshCronExpression());
        if (configuration.isReleases()) {
            managedRepository.addActiveReleaseScheme(ReleaseScheme.RELEASE);
        }
        if (configuration.isSnapshots()) {
            managedRepository.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
        }
        ArtifactCleanupFeature acf = managedRepository.getFeature(ArtifactCleanupFeature.class).get();
        acf.setRetentionPeriod(Period.ofDays(configuration.getRetentionPeriod()));
        acf.setDeleteReleasedSnapshots(configuration.isDeleteReleasedSnapshots());
        acf.setRetentionCount(configuration.getRetentionCount());
        IndexCreationFeature icf = managedRepository.getFeature(IndexCreationFeature.class).get();
        icf.setIndexPath(new URI(configuration.getIndexDir()));
        icf.setSkipPackedIndexCreation(configuration.isSkipPackedIndexCreation());
        StagingRepositoryFeature srf = managedRepository.getFeature(StagingRepositoryFeature.class).get();
        srf.setStageRepoNeeded(configuration.isStageRepoNeeded());
    } catch (Exception e) {
        throw new RepositoryException("Error", e);
    }
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) RepositoryException(org.apache.archiva.repository.RepositoryException) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) URI(java.net.URI) RepositoryException(org.apache.archiva.repository.RepositoryException)

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