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