use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.
the class RepositoryServletTest method testGetRepositoryAfterAdd.
@Test
public void testGetRepositoryAfterAdd() throws Exception {
RepositoryServlet servlet = RepositoryServlet.class.cast(findServlet("repository"));
assertNotNull(servlet);
ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
Configuration c = archivaConfiguration.getConfiguration();
ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
repo.setId(NEW_REPOSITORY_ID);
repo.setName(NEW_REPOSITORY_NAME);
Path repoRoot = Paths.get("target/test-repository-root");
if (!Files.exists(repoRoot)) {
Files.createDirectories(repoRoot);
}
repo.setLocation(repoRoot.toAbsolutePath().toString());
c.addManagedRepository(repo);
saveConfiguration(archivaConfiguration);
ManagedRepository repository = servlet.getRepository(NEW_REPOSITORY_ID);
assertNotNull(repository);
assertEquals(NEW_REPOSITORY_NAME, repository.getName());
// check other is still intact
assertRepositoryValid(servlet, REPOID_INTERNAL);
}
use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.
the class Maven3DependencyTreeBuilder method findArtifactInRepositories.
private ManagedRepository findArtifactInRepositories(List<String> repositoryIds, Artifact projectArtifact) throws RepositoryAdminException {
for (String repoId : repositoryIds) {
ManagedRepository managedRepository = managedRepositoryAdmin.getManagedRepository(repoId);
Path repoDir = Paths.get(managedRepository.getLocation());
Path file = pathTranslator.toFile(repoDir, projectArtifact.getGroupId(), projectArtifact.getArtifactId(), projectArtifact.getBaseVersion(), projectArtifact.getArtifactId() + "-" + projectArtifact.getVersion() + ".pom");
if (Files.exists(file)) {
return managedRepository;
}
// try with snapshot version
if (StringUtils.endsWith(projectArtifact.getBaseVersion(), VersionUtil.SNAPSHOT)) {
Path metadataFile = file.getParent().resolve(MetadataTools.MAVEN_METADATA);
if (Files.exists(metadataFile)) {
try {
ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read(metadataFile);
int buildNumber = archivaRepositoryMetadata.getSnapshotVersion().getBuildNumber();
String timeStamp = archivaRepositoryMetadata.getSnapshotVersion().getTimestamp();
// rebuild file name with timestamped version and build number
String timeStampFileName = new StringBuilder(projectArtifact.getArtifactId()).append('-').append(StringUtils.remove(projectArtifact.getBaseVersion(), "-" + VersionUtil.SNAPSHOT)).append('-').append(timeStamp).append('-').append(Integer.toString(buildNumber)).append(".pom").toString();
Path timeStampFile = file.getParent().resolve(timeStampFileName);
log.debug("try to find timestamped snapshot version file: {}", timeStampFile);
if (Files.exists(timeStampFile)) {
return managedRepository;
}
} catch (XMLException e) {
log.warn("skip fail to find timestamped snapshot pom: {}", e.getMessage());
}
}
}
}
return null;
}
use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.
the class RepositoryGroupAdminTest method testAddGroupWithInvalidMergedIndexTtl.
@Test(expected = RepositoryAdminException.class)
public void testAddGroupWithInvalidMergedIndexTtl() throws Exception {
try {
ManagedRepository managedRepositoryOne = getTestManagedRepository("test-new-one", Paths.get(APPSERVER_BASE_PATH, "test-new-one").toString());
ManagedRepository managedRepositoryTwo = getTestManagedRepository("test-new-two", Paths.get(APPSERVER_BASE_PATH, "test-new-two").toString());
managedRepositoryAdmin.addManagedRepository(managedRepositoryOne, false, getFakeAuditInformation());
managedRepositoryAdmin.addManagedRepository(managedRepositoryTwo, false, getFakeAuditInformation());
RepositoryGroup repositoryGroup = new RepositoryGroup("repo-group-one", Arrays.asList("test-new-one", "test-new-two")).mergedIndexTtl(-1);
mockAuditListener.clearEvents();
repositoryGroupAdmin.addRepositoryGroup(repositoryGroup, getFakeAuditInformation());
} finally {
mockAuditListener.clearEvents();
repositoryRegistry.removeRepository(repositoryRegistry.getRepository("test-new-one"));
repositoryRegistry.removeRepository(repositoryRegistry.getRepository("test-new-two"));
}
}
use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.
the class RepositoryGroupAdminTest method addAndDeleteGroupWithRemovedManagedRepo.
@Test
public void addAndDeleteGroupWithRemovedManagedRepo() throws Exception {
try {
ManagedRepository managedRepositoryOne = getTestManagedRepository("test-new-one", Paths.get(APPSERVER_BASE_PATH, "test-new-one").toString());
ManagedRepository managedRepositoryTwo = getTestManagedRepository("test-new-two", Paths.get(APPSERVER_BASE_PATH, "test-new-two").toString());
managedRepositoryAdmin.addManagedRepository(managedRepositoryOne, false, getFakeAuditInformation());
managedRepositoryAdmin.addManagedRepository(managedRepositoryTwo, false, getFakeAuditInformation());
RepositoryGroup repositoryGroup = new RepositoryGroup("repo-group-one", Arrays.asList("test-new-one", "test-new-two"));
mockAuditListener.clearEvents();
repositoryGroupAdmin.addRepositoryGroup(repositoryGroup, getFakeAuditInformation());
assertEquals(1, repositoryGroupAdmin.getRepositoriesGroups().size());
assertEquals("repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get(0).getId());
assertEquals(2, repositoryGroupAdmin.getRepositoriesGroups().get(0).getRepositories().size());
assertEquals(Arrays.asList("test-new-one", "test-new-two"), repositoryGroupAdmin.getRepositoriesGroups().get(0).getRepositories());
// deleting a managed repo to validate repogroup correctly updated !
managedRepositoryAdmin.deleteManagedRepository("test-new-one", getFakeAuditInformation(), true);
assertEquals(1, repositoryGroupAdmin.getRepositoriesGroups().size());
assertEquals("repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get(0).getId());
assertEquals(1, repositoryGroupAdmin.getRepositoriesGroups().get(0).getRepositories().size());
assertEquals(Arrays.asList("test-new-two"), repositoryGroupAdmin.getRepositoriesGroups().get(0).getRepositories());
repositoryGroupAdmin.deleteRepositoryGroup("repo-group-one", getFakeAuditInformation());
assertEquals(0, repositoryGroupAdmin.getRepositoriesGroups().size());
assertEquals(3, mockAuditListener.getAuditEvents().size());
assertEquals(AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get(0).getAction());
assertEquals(AuditEvent.DELETE_MANAGED_REPO, mockAuditListener.getAuditEvents().get(1).getAction());
assertEquals(AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get(2).getAction());
} finally {
mockAuditListener.clearEvents();
repositoryRegistry.removeRepository(repositoryRegistry.getRepository("test-new-two"));
}
}
use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.
the class DefaultManagedRepositoryAdmin method initialize.
@PostConstruct
public void initialize() throws RepositoryAdminException, RoleManagerException {
// initialize index context on start and check roles here
for (ManagedRepository managedRepository : getManagedRepositories()) {
log.debug("Initializating {}", managedRepository.getId());
addRepositoryRoles(managedRepository.getId());
}
}
Aggregations