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;
}
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;
}
}
}
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);
}
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;
}
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);
}
Aggregations