Search in sources :

Example 26 with ManagedRepository

use of org.apache.archiva.repository.ManagedRepository in project archiva by apache.

the class AbstractArchivaRepositoryScanningTaskExecutorTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    Path sourceRepoDir = Paths.get("src/test/repositories/default-repository");
    repoDir = Paths.get("target/default-repository");
    org.apache.archiva.common.utils.FileUtils.deleteDirectory(repoDir);
    assertFalse("Default Test Repository should not exist.", Files.exists(repoDir));
    Files.createDirectories(repoDir);
    FileUtils.copyDirectoryStructure(sourceRepoDir.toFile(), repoDir.toFile());
    // set the timestamps to a time well in the past
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.YEAR, -1);
    try (Stream<Path> stream = Files.walk(repoDir, FileVisitOption.FOLLOW_LINKS)) {
        stream.forEach(path -> {
            try {
                Files.setLastModifiedTime(path, FileTime.fromMillis(cal.getTimeInMillis()));
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
    }
    PathMatcher m = FileSystems.getDefault().getPathMatcher("glob:**/.svn");
    Files.walk(repoDir, FileVisitOption.FOLLOW_LINKS).filter(Files::isDirectory).sorted(Comparator.reverseOrder()).filter(path -> m.matches(path)).forEach(path -> org.apache.archiva.common.utils.FileUtils.deleteQuietly(path));
    assertTrue("Default Test Repository should exist.", Files.exists(repoDir) && Files.isDirectory(repoDir));
    assertNotNull(archivaConfig);
    // Create it
    ManagedRepositoryConfiguration repositoryConfiguration = new ManagedRepositoryConfiguration();
    repositoryConfiguration.setId(TEST_REPO_ID);
    repositoryConfiguration.setName("Test Repository");
    repositoryConfiguration.setLocation(repoDir.toAbsolutePath().toString());
    for (ManagedRepository repo : repositoryRegistry.getManagedRepositories()) {
        repositoryRegistry.removeRepository(repo);
    }
    repositoryRegistry.putRepository(repositoryConfiguration);
    metadataRepository = mock(MetadataRepository.class);
    factory.setRepository(metadataRepository);
}
Also used : Path(java.nio.file.Path) DirtiesContext(org.springframework.test.annotation.DirtiesContext) MockRepositorySessionFactory(org.apache.archiva.mock.MockRepositorySessionFactory) RunWith(org.junit.runner.RunWith) FileTime(java.nio.file.attribute.FileTime) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) Inject(javax.inject.Inject) Calendar(java.util.Calendar) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) After(org.junit.After) PathMatcher(java.nio.file.PathMatcher) TestCase(junit.framework.TestCase) Named(javax.inject.Named) Path(java.nio.file.Path) Before(org.junit.Before) Files(java.nio.file.Files) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArchivaSpringJUnit4ClassRunner(org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner) IOException(java.io.IOException) RepositoryTask(org.apache.archiva.scheduler.repository.model.RepositoryTask) ManagedRepository(org.apache.archiva.repository.ManagedRepository) TaskExecutor(org.apache.archiva.redback.components.taskqueue.execution.TaskExecutor) FileUtils(org.codehaus.plexus.util.FileUtils) Stream(java.util.stream.Stream) FileVisitOption(java.nio.file.FileVisitOption) Paths(java.nio.file.Paths) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Comparator(java.util.Comparator) FileSystems(java.nio.file.FileSystems) RepositoryStatisticsManager(org.apache.archiva.metadata.repository.stats.model.RepositoryStatisticsManager) Mockito.mock(org.mockito.Mockito.mock) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) PathMatcher(java.nio.file.PathMatcher) ManagedRepository(org.apache.archiva.repository.ManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) Calendar(java.util.Calendar) IOException(java.io.IOException) Before(org.junit.Before)

Example 27 with ManagedRepository

use of org.apache.archiva.repository.ManagedRepository in project archiva by apache.

the class ArchivaIndexManagerMock method createContext.

@Override
public ArchivaIndexingContext createContext(Repository repository) throws IndexCreationFailedException {
    log.debug("Creating context for repo {}, type: {}", repository.getId(), repository.getType());
    if (repository.getType() != RepositoryType.MAVEN) {
        throw new UnsupportedRepositoryTypeException(repository.getType());
    }
    IndexingContext mvnCtx = null;
    try {
        if (repository instanceof RemoteRepository) {
            mvnCtx = createRemoteContext((RemoteRepository) repository);
        } else if (repository instanceof ManagedRepository) {
            mvnCtx = createManagedContext((ManagedRepository) repository);
        }
    } catch (IOException e) {
        log.error("IOException during context creation " + e.getMessage(), e);
        throw new IndexCreationFailedException("Could not create index context for repository " + repository.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""), e);
    }
    MavenIndexContextMock context = new MavenIndexContextMock(repository, mvnCtx);
    return context;
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) RemoteRepository(org.apache.archiva.repository.RemoteRepository) IOException(java.io.IOException) UnsupportedRepositoryTypeException(org.apache.archiva.repository.UnsupportedRepositoryTypeException)

Aggregations

ManagedRepository (org.apache.archiva.repository.ManagedRepository)27 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)13 Path (java.nio.file.Path)11 InvalidRepositoryContentConsumer (org.apache.archiva.consumers.InvalidRepositoryContentConsumer)9 KnownRepositoryContentConsumer (org.apache.archiva.consumers.KnownRepositoryContentConsumer)9 BasicManagedRepository (org.apache.archiva.repository.BasicManagedRepository)9 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)8 IOException (java.io.IOException)7 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)5 RemoteRepository (org.apache.archiva.repository.RemoteRepository)5 IndexingContext (org.apache.maven.index.context.IndexingContext)5 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)4 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)3 IndexCreationFailedException (org.apache.archiva.indexer.IndexCreationFailedException)3 RepositoryRegistry (org.apache.archiva.repository.RepositoryRegistry)3 DavException (org.apache.jackrabbit.webdav.DavException)3 Date (java.util.Date)2 Inject (javax.inject.Inject)2 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)2