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