Search in sources :

Example 1 with Repository

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

the class MavenIndexManager method reset.

@Override
public ArchivaIndexingContext reset(ArchivaIndexingContext context) throws IndexUpdateFailedException {
    ArchivaIndexingContext ctx;
    executeUpdateFunction(context, indexingContext -> {
        try {
            indexingContext.close(true);
        } catch (IOException e) {
            log.warn("Index close failed");
        }
        try {
            FileUtils.deleteDirectory(Paths.get(context.getPath()));
        } catch (IOException e) {
            throw new IndexUpdateFailedException("Could not delete index files");
        }
    });
    try {
        Repository repo = context.getRepository();
        ctx = createContext(context.getRepository());
        if (repo instanceof EditableRepository) {
            ((EditableRepository) repo).setIndexingContext(ctx);
        }
    } catch (IndexCreationFailedException e) {
        throw new IndexUpdateFailedException("Could not create index");
    }
    return ctx;
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableRepository(org.apache.archiva.repository.EditableRepository) Repository(org.apache.archiva.repository.Repository) RemoteRepository(org.apache.archiva.repository.RemoteRepository) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) IOException(java.io.IOException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) EditableRepository(org.apache.archiva.repository.EditableRepository)

Example 2 with Repository

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

the class MavenRepositorySearch method getIndexingContext.

private IndexingContext getIndexingContext(String id) {
    String repoId;
    if (StringUtils.startsWith(id, "remote-")) {
        repoId = StringUtils.substringAfter(id, "remote-");
    } else {
        repoId = id;
    }
    Repository repo = repositoryRegistry.getRepository(repoId);
    if (repo == null) {
        return null;
    } else {
        if (repo.getIndexingContext() != null) {
            try {
                return repo.getIndexingContext().getBaseContext(IndexingContext.class);
            } catch (UnsupportedBaseContextException e) {
                return null;
            }
        } else {
            return null;
        }
    }
}
Also used : UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) Repository(org.apache.archiva.repository.Repository) RemoteRepository(org.apache.archiva.repository.RemoteRepository)

Example 3 with Repository

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

Example 4 with Repository

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

the class ArchivaIndexManagerMock method reset.

@Override
public ArchivaIndexingContext reset(ArchivaIndexingContext context) throws IndexUpdateFailedException {
    ArchivaIndexingContext ctx;
    executeUpdateFunction(context, indexingContext -> {
        try {
            indexingContext.close(true);
        } catch (IOException e) {
            log.warn("Index close failed");
        }
        try {
            FileUtils.deleteDirectory(Paths.get(context.getPath()));
        } catch (IOException e) {
            throw new IndexUpdateFailedException("Could not delete index files");
        }
    });
    try {
        Repository repo = context.getRepository();
        ctx = createContext(context.getRepository());
        if (repo instanceof EditableRepository) {
            ((EditableRepository) repo).setIndexingContext(ctx);
        }
    } catch (IndexCreationFailedException e) {
        throw new IndexUpdateFailedException("Could not create index");
    }
    return ctx;
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableRepository(org.apache.archiva.repository.EditableRepository) Repository(org.apache.archiva.repository.Repository) RemoteRepository(org.apache.archiva.repository.RemoteRepository) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) IOException(java.io.IOException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) EditableRepository(org.apache.archiva.repository.EditableRepository)

Example 5 with Repository

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

the class MavenRepositorySearch method addIndexingContexts.

/**
 * @param selectedRepos
 * @return indexing contextId used
 */
private List<String> addIndexingContexts(List<String> selectedRepos) {
    Set<String> indexingContextIds = new HashSet<>();
    for (String repo : selectedRepos) {
        try {
            Repository rRepo = repositoryRegistry.getRepository(repo);
            if (rRepo != null) {
                if (rRepo.getType().equals(RepositoryType.MAVEN)) {
                    assert rRepo.getIndexingContext() != null;
                    IndexingContext context = rRepo.getIndexingContext().getBaseContext(IndexingContext.class);
                    if (context.isSearchable()) {
                        indexingContextIds.addAll(getRemoteIndexingContextIds(repo));
                        indexingContextIds.add(context.getId());
                    } else {
                        log.warn("indexingContext with id {} not searchable", rRepo.getId());
                    }
                }
            } else {
                log.warn("Repository '{}' not found in configuration.", repo);
            }
        } catch (RepositorySearchException e) {
            log.warn("RepositorySearchException occured while accessing index of repository '{}' : {}", repo, e.getMessage());
            continue;
        } catch (UnsupportedBaseContextException e) {
            log.error("Fatal situation: Maven repository without IndexingContext found.");
            continue;
        }
    }
    return new ArrayList<>(indexingContextIds);
}
Also used : UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) Repository(org.apache.archiva.repository.Repository) RemoteRepository(org.apache.archiva.repository.RemoteRepository) ArrayList(java.util.ArrayList) IndexingContext(org.apache.maven.index.context.IndexingContext) RepositorySearchException(org.apache.archiva.indexer.search.RepositorySearchException) HashSet(java.util.HashSet)

Aggregations

Repository (org.apache.archiva.repository.Repository)7 RemoteRepository (org.apache.archiva.repository.RemoteRepository)5 IOException (java.io.IOException)3 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)3 IndexCreationFailedException (org.apache.archiva.indexer.IndexCreationFailedException)3 IndexUpdateFailedException (org.apache.archiva.indexer.IndexUpdateFailedException)3 EditableRepository (org.apache.archiva.repository.EditableRepository)3 ManagedRepository (org.apache.archiva.repository.ManagedRepository)3 UnsupportedBaseContextException (org.apache.archiva.indexer.UnsupportedBaseContextException)2 IndexingContext (org.apache.maven.index.context.IndexingContext)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)1 RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)1 AbstractRepositoryAdminTest (org.apache.archiva.admin.repository.AbstractRepositoryAdminTest)1 RepositorySearchException (org.apache.archiva.indexer.search.RepositorySearchException)1 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)1 ArtifactContext (org.apache.maven.index.ArtifactContext)1 DefaultScannerListener (org.apache.maven.index.DefaultScannerListener)1