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