use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class PropagateErrorsOnUpdateDownloadPolicyTest method testPolicyStop.
@Test
public void testPolicyStop() throws Exception {
DownloadErrorPolicy policy = lookupPolicy();
StorageAsset localFile = getFile();
Properties request = createRequest();
Exception ex = new RuntimeException();
Map<String, Exception> exMap = new HashMap<>();
assertTrue(policy.applyPolicy(PropagateErrorsOnUpdateDownloadPolicy.ALWAYS, request, localFile, ex, exMap));
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class CachedFailuresPolicyTest method testPolicyYes.
@Test(expected = PolicyViolationException.class)
public void testPolicyYes() throws Exception {
DownloadPolicy policy = lookupPolicy();
StorageAsset localFile = getFile();
Properties request = createRequest();
// make unique name
String url = "http://a.bad.hostname.maven.org/path/to/resource" + System.currentTimeMillis() + ".txt";
request.setProperty("url", url);
// should not fail
try {
policy.applyPolicy(CachedFailuresPolicy.YES, request, localFile);
} catch (PolicyViolationException e) {
// Converting to runtime exception, because it should be thrown later
throw new RuntimeException(e);
}
// status Yes Not In cache
// Yes in Cache
urlFailureCache.cacheFailure(url);
request.setProperty("url", url);
policy.applyPolicy(CachedFailuresPolicy.YES, request, localFile);
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class CachedFailuresPolicyTest method testPolicyNo.
@Test
public void testPolicyNo() throws Exception {
DownloadPolicy policy = lookupPolicy();
StorageAsset localFile = getFile();
Properties request = createRequest();
request.setProperty("url", "http://a.bad.hostname.maven.org/path/to/resource.txt");
policy.applyPolicy(CachedFailuresPolicy.NO, request, localFile);
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class ArchivaIndexManagerMock method createRemoteContext.
private IndexingContext createRemoteContext(RemoteRepository remoteRepository) throws IOException {
Path appServerBase = archivaConfiguration.getAppServerBaseDir();
String contextKey = "remote-" + remoteRepository.getId();
// create remote repository path
Path repoDir = remoteRepository.getRoot().getFilePath();
if (!Files.exists(repoDir)) {
Files.createDirectories(repoDir);
}
StorageAsset indexDirectory = null;
// is there configured indexDirectory ?
if (remoteRepository.supportsFeature(RemoteIndexFeature.class)) {
RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class);
indexDirectory = getIndexPath(remoteRepository);
String remoteIndexUrl = calculateIndexRemoteUrl(remoteRepository.getLocation(), rif);
try {
return getIndexingContext(remoteRepository, contextKey, repoDir, indexDirectory, remoteIndexUrl);
} catch (IndexFormatTooOldException e) {
// existing index with an old lucene format so we need to delete it!!!
// delete it first then recreate it.
//
log.warn(//
"the index of repository {} is too old we have to delete and recreate it", remoteRepository.getId());
org.apache.archiva.common.utils.FileUtils.deleteDirectory(indexDirectory.getFilePath());
return getIndexingContext(remoteRepository, contextKey, repoDir, indexDirectory, remoteIndexUrl);
}
} else {
throw new IOException("No remote index defined");
}
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class ArchivaIndexingTaskExecutorTest method testPackagedIndex.
@Test
public void testPackagedIndex() throws Exception {
Path basePath = repo.getRoot().getFilePath();
IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class);
StorageAsset packedIndexDirectory = icf.getLocalPackedIndexPath();
StorageAsset indexerDirectory = icf.getLocalIndexPath();
for (StorageAsset dir : new StorageAsset[] { packedIndexDirectory, indexerDirectory }) {
if (dir.getFilePath() != null) {
Path localDirPath = dir.getFilePath();
Files.list(localDirPath).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.getFilePath()));
assertTrue(Files.exists(indexerDirectory.getFilePath()));
// test packed index file creation
// no more zip
// Assertions.assertThat(new File( indexerDirectory, "nexus-maven-repository-index.zip" )).exists();
Assertions.assertThat(Files.exists(packedIndexDirectory.getFilePath().resolve("nexus-maven-repository-index.properties")));
Assertions.assertThat(Files.exists(packedIndexDirectory.getFilePath().resolve("nexus-maven-repository-index.gz")));
assertFalse(Files.exists(packedIndexDirectory.getFilePath().resolve("nexus-maven-repository-index.1.gz")));
// unpack .zip index
// unzipIndex( indexerDirectory.getPath(), destDir.getPath() );
DefaultIndexUpdater.FileFetcher fetcher = new DefaultIndexUpdater.FileFetcher(packedIndexDirectory.getFilePath().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());
}
Aggregations