Search in sources :

Example 1 with ManagedRepository

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);
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) Test(org.junit.Test)

Example 2 with ManagedRepository

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;
}
Also used : Path(java.nio.file.Path) XMLException(org.apache.archiva.xml.XMLException) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata)

Example 3 with ManagedRepository

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"));
    }
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) RepositoryGroup(org.apache.archiva.admin.model.beans.RepositoryGroup) AbstractRepositoryAdminTest(org.apache.archiva.admin.repository.AbstractRepositoryAdminTest) Test(org.junit.Test)

Example 4 with ManagedRepository

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"));
    }
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) RepositoryGroup(org.apache.archiva.admin.model.beans.RepositoryGroup) AbstractRepositoryAdminTest(org.apache.archiva.admin.repository.AbstractRepositoryAdminTest) Test(org.junit.Test)

Example 5 with ManagedRepository

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());
    }
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)46 Test (org.junit.Test)23 Path (java.nio.file.Path)20 AbstractRepositoryAdminTest (org.apache.archiva.admin.repository.AbstractRepositoryAdminTest)11 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)10 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)10 RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)9 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)8 ArrayList (java.util.ArrayList)7 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)7 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)5 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)5 RepositoryException (org.apache.archiva.repository.RepositoryException)5 IOException (java.io.IOException)4 Date (java.util.Date)4 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)4 ArtifactReference (org.apache.archiva.model.ArtifactReference)4 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)3 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)3 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)3