Search in sources :

Example 6 with StorageAsset

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));
}
Also used : StorageAsset(org.apache.archiva.repository.storage.StorageAsset) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with StorageAsset

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);
}
Also used : StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Properties(java.util.Properties) Test(org.junit.Test)

Example 8 with StorageAsset

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);
}
Also used : StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Properties(java.util.Properties) Test(org.junit.Test)

Example 9 with StorageAsset

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");
    }
}
Also used : Path(java.nio.file.Path) IndexFormatTooOldException(org.apache.maven.index_shaded.lucene.index.IndexFormatTooOldException) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) IOException(java.io.IOException)

Example 10 with StorageAsset

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());
}
Also used : Path(java.nio.file.Path) ArtifactIndexingTask(org.apache.archiva.scheduler.indexing.ArtifactIndexingTask) UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) RunWith(org.junit.runner.RunWith) ArtifactInfo(org.apache.maven.index.ArtifactInfo) ArchivaRepositoryRegistry(org.apache.archiva.repository.base.ArchivaRepositoryRegistry) RepositoryHandlerDependencies(org.apache.archiva.repository.base.RepositoryHandlerDependencies) DefaultIndexUpdater(org.apache.maven.index.updater.DefaultIndexUpdater) IndexUpdater(org.apache.maven.index.updater.IndexUpdater) Inject(javax.inject.Inject) FlatSearchResponse(org.apache.maven.index.FlatSearchResponse) ReleaseScheme(org.apache.archiva.repository.ReleaseScheme) After(org.junit.After) MAVEN(org.apache.maven.index.MAVEN) TopDocs(org.apache.maven.index_shaded.lucene.search.TopDocs) Assertions(org.assertj.core.api.Assertions) TestCase(junit.framework.TestCase) Path(java.nio.file.Path) Before(org.junit.Before) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) Files(java.nio.file.Files) BooleanClause(org.apache.maven.index_shaded.lucene.search.BooleanClause) Set(java.util.Set) ArchivaSpringJUnit4ClassRunner(org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner) BooleanQuery(org.apache.maven.index_shaded.lucene.search.BooleanQuery) Test(org.junit.Test) IOException(java.io.IOException) SourcedSearchExpression(org.apache.maven.index.expr.SourcedSearchExpression) Indexer(org.apache.maven.index.Indexer) ManagedRepository(org.apache.archiva.repository.ManagedRepository) IndexUpdateRequest(org.apache.maven.index.updater.IndexUpdateRequest) IndexingContext(org.apache.maven.index.context.IndexingContext) Paths(java.nio.file.Paths) ContextConfiguration(org.springframework.test.context.ContextConfiguration) IndexSearcher(org.apache.maven.index_shaded.lucene.search.IndexSearcher) FlatSearchRequest(org.apache.maven.index.FlatSearchRequest) BasicManagedRepository(org.apache.archiva.repository.base.managed.BasicManagedRepository) StringSearchExpression(org.apache.maven.index.expr.StringSearchExpression) BooleanQuery(org.apache.maven.index_shaded.lucene.search.BooleanQuery) ArtifactIndexingTask(org.apache.archiva.scheduler.indexing.ArtifactIndexingTask) FlatSearchResponse(org.apache.maven.index.FlatSearchResponse) IndexUpdateRequest(org.apache.maven.index.updater.IndexUpdateRequest) IOException(java.io.IOException) FlatSearchRequest(org.apache.maven.index.FlatSearchRequest) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ArtifactInfo(org.apache.maven.index.ArtifactInfo) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) DefaultIndexUpdater(org.apache.maven.index.updater.DefaultIndexUpdater) StringSearchExpression(org.apache.maven.index.expr.StringSearchExpression) Test(org.junit.Test)

Aggregations

StorageAsset (org.apache.archiva.repository.storage.StorageAsset)191 Path (java.nio.file.Path)91 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)61 IOException (java.io.IOException)59 Test (org.junit.Test)59 Artifact (org.apache.archiva.repository.content.Artifact)54 ManagedRepository (org.apache.archiva.repository.ManagedRepository)27 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)22 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)22 List (java.util.List)20 Inject (javax.inject.Inject)20 RepositoryMetadataException (org.apache.archiva.repository.metadata.RepositoryMetadataException)20 Collectors (java.util.stream.Collectors)19 RemoteRepository (org.apache.archiva.repository.RemoteRepository)19 IndexingContext (org.apache.maven.index.context.IndexingContext)19 FilesystemStorage (org.apache.archiva.repository.storage.fs.FilesystemStorage)18 StringUtils (org.apache.commons.lang3.StringUtils)18 Logger (org.slf4j.Logger)18 LoggerFactory (org.slf4j.LoggerFactory)18 Map (java.util.Map)17