Search in sources :

Example 1 with RemoteRepository

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

the class Maven3DependencyTreeBuilder method resolve.

private void resolve(ResolveRequest resolveRequest) {
    RepositorySystem system = newRepositorySystem();
    RepositorySystemSession session = newRepositorySystemSession(system, resolveRequest.localRepoDir);
    org.sonatype.aether.artifact.Artifact artifact = new DefaultArtifact(resolveRequest.groupId + ":" + resolveRequest.artifactId + ":" + resolveRequest.version);
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, ""));
    // add remote repositories
    for (RemoteRepository remoteRepository : resolveRequest.remoteRepositories) {
        collectRequest.addRepository(new org.sonatype.aether.repository.RemoteRepository(remoteRepository.getId(), "default", remoteRepository.getUrl()));
    }
    collectRequest.setRequestContext("project");
    try {
        CollectResult collectResult = system.collectDependencies(session, collectRequest);
        collectResult.getRoot().accept(resolveRequest.dependencyVisitor);
        log.debug("test");
    } catch (DependencyCollectionException e) {
        log.error(e.getMessage(), e);
    }
}
Also used : MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) DependencyCollectionException(org.sonatype.aether.collection.DependencyCollectionException) CollectResult(org.sonatype.aether.collection.CollectResult) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) RepositorySystem(org.sonatype.aether.RepositorySystem) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 2 with RemoteRepository

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

the class MockRepoAdmin method getRemoteRepositories.

@Override
public List<RemoteRepository> getRemoteRepositories() throws RepositoryAdminException {
    List<RemoteRepository> remoteRepositories = new ArrayList<>(archivaConfiguration.getConfiguration().getRemoteRepositories().size());
    for (RemoteRepositoryConfiguration repositoryConfiguration : archivaConfiguration.getConfiguration().getRemoteRepositories()) {
        RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault(), repositoryConfiguration.getId(), repositoryConfiguration.getName(), repositoryConfiguration.getUrl(), repositoryConfiguration.getLayout(), repositoryConfiguration.getUsername(), repositoryConfiguration.getPassword(), repositoryConfiguration.getTimeout());
        remoteRepository.setDownloadRemoteIndex(repositoryConfiguration.isDownloadRemoteIndex());
        remoteRepository.setRemoteIndexUrl(repositoryConfiguration.getRemoteIndexUrl());
        remoteRepository.setCronExpression(repositoryConfiguration.getRefreshCronExpression());
        remoteRepository.setIndexDirectory(repositoryConfiguration.getIndexDir());
        remoteRepository.setRemoteDownloadNetworkProxyId(repositoryConfiguration.getRemoteDownloadNetworkProxyId());
        remoteRepository.setRemoteDownloadTimeout(repositoryConfiguration.getRemoteDownloadTimeout());
        remoteRepository.setDownloadRemoteIndexOnStartup(repositoryConfiguration.isDownloadRemoteIndexOnStartup());
        remoteRepositories.add(remoteRepository);
    }
    return remoteRepositories;
}
Also used : ArrayList(java.util.ArrayList) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository)

Example 3 with RemoteRepository

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

the class AbstractRepositoryAdminTest method getRemoteRepository.

protected RemoteRepository getRemoteRepository(String id) {
    RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
    remoteRepository.setUrl("http://foo.com/maven-it-rocks");
    remoteRepository.setTimeout(10);
    remoteRepository.setName("maven foo");
    remoteRepository.setUserName("foo-name");
    remoteRepository.setPassword("toto");
    remoteRepository.setId(id);
    remoteRepository.setRemoteDownloadNetworkProxyId("foo");
    remoteRepository.setDescription("cool apache repo");
    Map<String, String> extraParameters = new HashMap<>();
    extraParameters.put("foo", "bar");
    remoteRepository.setExtraParameters(extraParameters);
    Map<String, String> extraHeaders = new HashMap<>();
    extraHeaders.put("beer", "wine");
    remoteRepository.setExtraHeaders(extraHeaders);
    return remoteRepository;
}
Also used : HashMap(java.util.HashMap) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository)

Example 4 with RemoteRepository

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

the class ProxyConnectorRuleAdminTest method addProxyConnectorRuleWithTwoProxyConnectors.

@Test
public void addProxyConnectorRuleWithTwoProxyConnectors() throws Exception {
    RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
    remoteRepository.setId("archiva");
    remoteRepository.setName("archiva rocks");
    remoteRepository.setUrl("http://wine.org");
    remoteRepositoryAdmin.addRemoteRepository(remoteRepository, getFakeAuditInformation());
    int size = proxyConnectorRuleAdmin.getProxyConnectorRules().size();
    assertEquals(0, size);
    ProxyConnector proxyConnector1 = new ProxyConnector();
    proxyConnector1.setSourceRepoId("snapshots");
    proxyConnector1.setTargetRepoId("central");
    proxyConnectorAdmin.addProxyConnector(proxyConnector1, getFakeAuditInformation());
    ProxyConnector proxyConnector2 = new ProxyConnector();
    proxyConnector2.setSourceRepoId("snapshots");
    proxyConnector2.setTargetRepoId("archiva");
    proxyConnectorAdmin.addProxyConnector(proxyConnector2, getFakeAuditInformation());
    ProxyConnectorRule rule = new ProxyConnectorRule("org/apache/maven", ProxyConnectorRuleType.BLACK_LIST, Arrays.asList(proxyConnector1, proxyConnector2));
    try {
        proxyConnectorRuleAdmin.addProxyConnectorRule(rule, getFakeAuditInformation());
        assertEquals(size + 1, proxyConnectorRuleAdmin.getProxyConnectorRules().size());
        rule = proxyConnectorRuleAdmin.getProxyConnectorRules().get(0);
        assertEquals("org/apache/maven", rule.getPattern());
        assertEquals(2, rule.getProxyConnectors().size());
        assertEquals(ProxyConnectorRuleType.BLACK_LIST, rule.getProxyConnectorRuleType());
    } finally {
        proxyConnectorRuleAdmin.deleteProxyConnectorRule(rule, getFakeAuditInformation());
        proxyConnectorAdmin.deleteProxyConnector(proxyConnector1, getFakeAuditInformation());
        proxyConnectorAdmin.deleteProxyConnector(proxyConnector2, getFakeAuditInformation());
        remoteRepositoryAdmin.deleteRemoteRepository(remoteRepository.getId(), getFakeAuditInformation());
    }
}
Also used : ProxyConnectorRule(org.apache.archiva.admin.model.beans.ProxyConnectorRule) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector) AbstractRepositoryAdminTest(org.apache.archiva.admin.repository.AbstractRepositoryAdminTest) Test(org.junit.Test)

Example 5 with RemoteRepository

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

the class ProxyConnectorRuleAdminTest method updateProxyConnectorRuleWithTwoProxyConnectors.

@Test
public void updateProxyConnectorRuleWithTwoProxyConnectors() throws Exception {
    RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
    remoteRepository.setId("archiva");
    remoteRepository.setName("archiva rocks");
    remoteRepository.setUrl("http://wine.org");
    remoteRepositoryAdmin.addRemoteRepository(remoteRepository, getFakeAuditInformation());
    int size = proxyConnectorRuleAdmin.getProxyConnectorRules().size();
    assertEquals(0, size);
    ProxyConnector proxyConnector1 = new ProxyConnector();
    proxyConnector1.setSourceRepoId("snapshots");
    proxyConnector1.setTargetRepoId("central");
    proxyConnectorAdmin.addProxyConnector(proxyConnector1, getFakeAuditInformation());
    ProxyConnector proxyConnector2 = new ProxyConnector();
    proxyConnector2.setSourceRepoId("snapshots");
    proxyConnector2.setTargetRepoId("archiva");
    proxyConnectorAdmin.addProxyConnector(proxyConnector2, getFakeAuditInformation());
    ProxyConnectorRule rule = new ProxyConnectorRule("org/apache/maven", ProxyConnectorRuleType.BLACK_LIST, Arrays.asList(proxyConnector1, proxyConnector2));
    try {
        proxyConnectorRuleAdmin.addProxyConnectorRule(rule, getFakeAuditInformation());
        assertEquals(size + 1, proxyConnectorRuleAdmin.getProxyConnectorRules().size());
        rule = proxyConnectorRuleAdmin.getProxyConnectorRules().get(0);
        assertEquals("org/apache/maven", rule.getPattern());
        assertEquals(2, rule.getProxyConnectors().size());
        // assertEquals( "snapshots", rule.getProxyConnectors().get( 0 ).getSourceRepoId() );
        // assertEquals( "central", rule.getProxyConnectors().get( 0 ).getTargetRepoId() );
        assertEquals(ProxyConnectorRuleType.BLACK_LIST, rule.getProxyConnectorRuleType());
        rule.setProxyConnectors(Arrays.asList(proxyConnector1));
        proxyConnectorRuleAdmin.updateProxyConnectorRule(rule, getFakeAuditInformation());
        assertEquals(size + 1, proxyConnectorRuleAdmin.getProxyConnectorRules().size());
        rule = proxyConnectorRuleAdmin.getProxyConnectorRules().get(0);
        assertEquals("org/apache/maven", rule.getPattern());
        assertEquals(1, rule.getProxyConnectors().size());
        assertEquals("snapshots", rule.getProxyConnectors().get(0).getSourceRepoId());
        assertEquals("central", rule.getProxyConnectors().get(0).getTargetRepoId());
    } finally {
        proxyConnectorRuleAdmin.deleteProxyConnectorRule(rule, getFakeAuditInformation());
        proxyConnectorAdmin.deleteProxyConnector(proxyConnector1, getFakeAuditInformation());
        proxyConnectorAdmin.deleteProxyConnector(proxyConnector2, getFakeAuditInformation());
        remoteRepositoryAdmin.deleteRemoteRepository(remoteRepository.getId(), getFakeAuditInformation());
    }
}
Also used : ProxyConnectorRule(org.apache.archiva.admin.model.beans.ProxyConnectorRule) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector) AbstractRepositoryAdminTest(org.apache.archiva.admin.repository.AbstractRepositoryAdminTest) Test(org.junit.Test)

Aggregations

RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)23 Test (org.junit.Test)16 AbstractRepositoryAdminTest (org.apache.archiva.admin.repository.AbstractRepositoryAdminTest)7 Path (java.nio.file.Path)6 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)6 RemoteRepositoriesService (org.apache.archiva.rest.api.services.RemoteRepositoriesService)5 ArrayList (java.util.ArrayList)3 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)3 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)3 NetworkProxy (org.apache.archiva.admin.model.beans.NetworkProxy)3 HashMap (java.util.HashMap)2 ProxyConnectorRule (org.apache.archiva.admin.model.beans.ProxyConnectorRule)2 RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)2 Artifact (org.apache.archiva.maven2.model.Artifact)2 SearchRequest (org.apache.archiva.rest.api.model.SearchRequest)2 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)2 ProxyConnectorService (org.apache.archiva.rest.api.services.ProxyConnectorService)2 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)2 RepositoryGroupService (org.apache.archiva.rest.api.services.RepositoryGroupService)2 SearchService (org.apache.archiva.rest.api.services.SearchService)2