Search in sources :

Example 36 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class RepositoriesServiceTest method initSnapshotRepo.

protected Path initSnapshotRepo() throws Exception {
    Path targetRepo = getBasedir().resolve("target/repo-with-snapshots");
    if (Files.exists(targetRepo)) {
        org.apache.archiva.common.utils.FileUtils.deleteDirectory(targetRepo);
    }
    assertFalse(Files.exists(targetRepo));
    FileUtils.copyDirectoryToDirectory(getBasedir().resolve("src/test/repo-with-snapshots").toFile(), targetRepo.getParent().toFile());
    if (getManagedRepositoriesService(authorizationHeader).getManagedRepository(SNAPSHOT_REPO_ID) != null) {
        getManagedRepositoriesService(authorizationHeader).deleteManagedRepository(SNAPSHOT_REPO_ID, true);
        assertNull(getManagedRepositoriesService(authorizationHeader).getManagedRepository(SNAPSHOT_REPO_ID));
    }
    ManagedRepository managedRepository = getTestManagedRepository(SNAPSHOT_REPO_ID, "repo-with-snapshots");
    /*managedRepository.setId( SNAPSHOT_REPO_ID );
        managedRepository.setLocation( );
        managedRepository.setCronExpression( "* * * * * ?" );*/
    getManagedRepositoriesService(authorizationHeader).addManagedRepository(managedRepository);
    assertNotNull(getManagedRepositoriesService(authorizationHeader).getManagedRepository(SNAPSHOT_REPO_ID));
    return targetRepo;
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository)

Example 37 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class RepositoryServletTest method testGetRepositoryAfterDelete.

@Test
public void testGetRepositoryAfterDelete() throws Exception {
    RepositoryServlet servlet = RepositoryServlet.class.cast(findServlet("repository"));
    assertNotNull(servlet);
    ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
    Configuration c = archivaConfiguration.getConfiguration();
    c.removeManagedRepository(c.findManagedRepositoryById(REPOID_INTERNAL));
    saveConfiguration(archivaConfiguration);
    ManagedRepository repository = servlet.getRepository(REPOID_INTERNAL);
    assertNull(repository);
}
Also used : 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) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) Test(org.junit.Test)

Example 38 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class Maven3DependencyTreeBuilder method buildDependencyTree.

@Override
public void buildDependencyTree(List<String> repositoryIds, String groupId, String artifactId, String version, DependencyVisitor dependencyVisitor) throws DependencyTreeBuilderException {
    Artifact projectArtifact = factory.createProjectArtifact(groupId, artifactId, version);
    ManagedRepository repository = null;
    try {
        repository = findArtifactInRepositories(repositoryIds, projectArtifact);
    } catch (RepositoryAdminException e) {
        // FIXME better exception
        throw new DependencyTreeBuilderException("Cannot build project dependency tree " + e.getMessage(), e);
    }
    if (repository == null) {
        // metadata could not be resolved
        return;
    }
    List<RemoteRepository> remoteRepositories = new ArrayList<>();
    Map<String, NetworkProxy> networkProxies = new HashMap<>();
    try {
        // MRM-1411
        // TODO: this is a workaround for a lack of proxy capability in the resolvers - replace when it can all be
        // handled there. It doesn't cache anything locally!
        Map<String, List<ProxyConnector>> proxyConnectorsMap = proxyConnectorAdmin.getProxyConnectorAsMap();
        List<ProxyConnector> proxyConnectors = proxyConnectorsMap.get(repository.getId());
        if (proxyConnectors != null) {
            for (ProxyConnector proxyConnector : proxyConnectors) {
                remoteRepositories.add(remoteRepositoryAdmin.getRemoteRepository(proxyConnector.getTargetRepoId()));
                NetworkProxy networkProxyConfig = networkProxyAdmin.getNetworkProxy(proxyConnector.getProxyId());
                if (networkProxyConfig != null) {
                    // key/value: remote repo ID/proxy info
                    networkProxies.put(proxyConnector.getTargetRepoId(), networkProxyConfig);
                }
            }
        }
    } catch (RepositoryAdminException e) {
        throw new DependencyTreeBuilderException(e.getMessage(), e);
    }
    // FIXME take care of relative path
    ResolveRequest resolveRequest = new ResolveRequest();
    resolveRequest.dependencyVisitor = dependencyVisitor;
    resolveRequest.localRepoDir = repository.getLocation();
    resolveRequest.groupId = groupId;
    resolveRequest.artifactId = artifactId;
    resolveRequest.version = version;
    resolveRequest.remoteRepositories = remoteRepositories;
    resolveRequest.networkProxies = networkProxies;
    resolve(resolveRequest);
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) NetworkProxy(org.apache.archiva.admin.model.beans.NetworkProxy) List(java.util.List) ArrayList(java.util.ArrayList) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector)

Example 39 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class RepositoryGroupAdminTest method testAddAndUpdateGroupWithInvalidMergedIndexTtl.

@Test(expected = RepositoryAdminException.class)
public void testAddAndUpdateGroupWithInvalidMergedIndexTtl() 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());
        // verify if default values were saved
        assertEquals(30, repositoryGroupAdmin.getRepositoriesGroups().get(0).getMergedIndexTtl());
        assertEquals(".indexer", repositoryGroupAdmin.getRepositoriesGroups().get(0).getMergedIndexPath());
        repositoryGroup = repositoryGroupAdmin.getRepositoryGroup("repo-group-one");
        assertNotNull(repositoryGroup);
        repositoryGroup.mergedIndexTtl(-1);
        repositoryGroupAdmin.updateRepositoryGroup(repositoryGroup, getFakeAuditInformation());
    } finally {
        mockAuditListener.clearEvents();
        managedRepositoryAdmin.deleteManagedRepository("test-new-one", getFakeAuditInformation(), true);
        managedRepositoryAdmin.deleteManagedRepository("test-new-two", getFakeAuditInformation(), true);
    }
}
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 40 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class RepositoryGroupAdminTest method addAndDeleteGroup.

@Test
public void addAndDeleteGroup() throws Exception {
    try {
        Repository repo = repositoryRegistry.getRepository("test-new-one");
        if (repo != null) {
            repositoryRegistry.removeRepository(repo);
        }
        repo = repositoryRegistry.getRepository("test-new-two");
        if (repo != null) {
            repositoryRegistry.removeRepository(repo);
        }
        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"));
        // repositoryGroupAdmin.deleteRepositoryGroup("repo-group-one", null);
        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());
        // verify if default values were saved
        assertEquals(30, repositoryGroupAdmin.getRepositoriesGroups().get(0).getMergedIndexTtl());
        assertEquals(".indexer", repositoryGroupAdmin.getRepositoriesGroups().get(0).getMergedIndexPath());
        repositoryGroupAdmin.deleteRepositoryGroup("repo-group-one", getFakeAuditInformation());
        assertEquals(0, repositoryGroupAdmin.getRepositoriesGroups().size());
        assertEquals(2, mockAuditListener.getAuditEvents().size());
        assertEquals(AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get(0).getAction());
        assertEquals(AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get(1).getAction());
    } finally {
        mockAuditListener.clearEvents();
        repositoryRegistry.removeRepository(repositoryRegistry.getManagedRepository("test-new-one"));
        repositoryRegistry.removeRepository(repositoryRegistry.getManagedRepository("test-new-two"));
    }
}
Also used : Repository(org.apache.archiva.repository.Repository) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) 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)

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