Search in sources :

Example 21 with RemoteRepositoryConfiguration

use of org.apache.archiva.configuration.RemoteRepositoryConfiguration in project archiva by apache.

the class RepositoryRegistryTest method putRemoteRepositoryFromConfig.

@Test
public void putRemoteRepositoryFromConfig() throws Exception {
    RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
    cfg.setId("test002");
    cfg.setName("This is test 002");
    RemoteRepository repo = repositoryRegistry.putRepository(cfg);
    assertNotNull(repo);
    assertEquals("test002", repo.getId());
    assertEquals("This is test 002", repo.getName());
    assertNotNull(repo.getContent());
    archivaConfiguration.reload();
    Collection<RemoteRepository> repos = repositoryRegistry.getRemoteRepositories();
    assertEquals(2, repos.size());
    RemoteRepository internalRepo = repositoryRegistry.getRemoteRepository("central");
    cfg = new RemoteRepositoryConfiguration();
    cfg.setId("central");
    cfg.setName("This is central test 002");
    repo = repositoryRegistry.putRepository(cfg);
    assertTrue(internalRepo == repo);
    assertEquals("This is central test 002", repo.getName());
    assertEquals(2, repositoryRegistry.getRemoteRepositories().size());
    repositoryRegistry.reload();
    assertEquals(2, repositoryRegistry.getRemoteRepositories().size());
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Test(org.junit.Test)

Example 22 with RemoteRepositoryConfiguration

use of org.apache.archiva.configuration.RemoteRepositoryConfiguration in project archiva by apache.

the class RepositoryProviderMock method getRemoteConfiguration.

@Override
public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException {
    RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration();
    configuration.setId(remoteRepository.getId());
    configuration.setName(remoteRepository.getName());
    configuration.setDescription(remoteRepository.getDescription());
    configuration.setLayout(remoteRepository.getLayout());
    configuration.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
    configuration.setCheckPath(remoteRepository.getCheckPath());
    configuration.setExtraHeaders(remoteRepository.getExtraHeaders());
    configuration.setExtraParameters(remoteRepository.getExtraParameters());
    configuration.setTimeout((int) remoteRepository.getTimeout().getSeconds());
    RepositoryCredentials creds = remoteRepository.getLoginCredentials();
    if (creds != null) {
        PasswordCredentials pwdCreds = (PasswordCredentials) creds;
        configuration.setUsername(pwdCreds.getUsername());
        configuration.setPassword(new String(pwdCreds.getPassword()));
    }
    configuration.setUrl(remoteRepository.getLocation() == null ? "" : remoteRepository.getLocation().toString());
    RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get();
    configuration.setDownloadRemoteIndex(rif.isDownloadRemoteIndex());
    configuration.setDownloadRemoteIndexOnStartup(rif.isDownloadRemoteIndexOnStartup());
    configuration.setIndexDir(rif.getIndexUri() == null ? "" : rif.getIndexUri().toString());
    configuration.setRemoteDownloadNetworkProxyId(rif.getProxyId());
    return configuration;
}
Also used : RepositoryCredentials(org.apache.archiva.repository.RepositoryCredentials) PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature)

Example 23 with RemoteRepositoryConfiguration

use of org.apache.archiva.configuration.RemoteRepositoryConfiguration in project archiva by apache.

the class MavenRepositoryProviderTest method createRemoteInstance.

@Test
public void createRemoteInstance() throws Exception {
    RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration();
    repo.setUsername("testuser001");
    repo.setPassword("pwd0000abc");
    repo.setCheckPath("test/check.html");
    repo.setTimeout(50);
    repo.setUrl("https://repo.maven.apache.org/maven2/test");
    repo.setDownloadRemoteIndex(true);
    repo.setDownloadRemoteIndexOnStartup(true);
    Map<String, String> header = new HashMap<>();
    header.put("header1", "value1");
    header.put("header2", "value2");
    repo.setExtraHeaders(header);
    Map<String, String> params = new HashMap<>();
    params.put("param1", "pval1");
    params.put("param2", "pval2");
    repo.setExtraParameters(params);
    repo.setRefreshCronExpression("0 1 07 ? * MON");
    repo.setRemoteDownloadTimeout(333);
    repo.setRemoteIndexUrl("testremote/.index");
    repo.setDescription("This is a test");
    repo.setId("test001");
    repo.setName("Remote Test Repo 001");
    repo.setIndexDir("testindex/.index");
    repo.setLayout("maven2");
    repo.setType(RepositoryType.MAVEN.toString());
    repo.setIndexDir("local/.index");
    RemoteRepository mr = provider.createRemoteInstance(repo);
    assertEquals("test001", mr.getId());
    assertEquals("This is a test", mr.getDescription());
    assertNotNull(mr.getLocation());
    assertEquals("https://repo.maven.apache.org/maven2/test", mr.getLocation().toString());
    assertEquals("Remote Test Repo 001", mr.getName());
    assertEquals("test001", mr.getId());
    assertEquals("0 1 07 ? * MON", mr.getSchedulingDefinition());
    assertEquals(50, mr.getTimeout().get(ChronoUnit.SECONDS));
    assertTrue(mr.isScanned());
    assertNotNull(mr.getLoginCredentials());
    assertTrue(mr.getLoginCredentials() instanceof PasswordCredentials);
    PasswordCredentials creds = (PasswordCredentials) mr.getLoginCredentials();
    assertEquals("testuser001", creds.getUsername());
    assertEquals("pwd0000abc", new String(creds.getPassword()));
    assertEquals("value1", mr.getExtraHeaders().get("header1"));
    assertEquals("pval2", mr.getExtraParameters().get("param2"));
    assertEquals("maven2", mr.getLayout());
    try {
        ArtifactCleanupFeature artifactCleanupFeature = mr.getFeature(ArtifactCleanupFeature.class).get();
        throw new Exception("artifactCleanupFeature should not be available");
    } catch (UnsupportedFeatureException e) {
    // correct
    }
    IndexCreationFeature indexCreationFeature = mr.getFeature(IndexCreationFeature.class).get();
    assertEquals("local/.index", indexCreationFeature.getIndexPath().toString());
    try {
        StagingRepositoryFeature stagingRepositoryFeature = mr.getFeature(StagingRepositoryFeature.class).get();
        throw new Exception("stagingRepositoryFeature should not be available");
    } catch (UnsupportedFeatureException e) {
    // correct
    }
    RemoteIndexFeature remoteIndexFeature = mr.getFeature(RemoteIndexFeature.class).get();
    assertNull(remoteIndexFeature.getProxyId());
}
Also used : PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) UnsupportedFeatureException(org.apache.archiva.repository.UnsupportedFeatureException) HashMap(java.util.HashMap) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RemoteRepository(org.apache.archiva.repository.RemoteRepository) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) UnsupportedFeatureException(org.apache.archiva.repository.UnsupportedFeatureException) Test(org.junit.Test)

Example 24 with RemoteRepositoryConfiguration

use of org.apache.archiva.configuration.RemoteRepositoryConfiguration in project archiva by apache.

the class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    c = new Configuration();
    testRepo = new ManagedRepositoryConfiguration();
    testRepo.setId(TEST_REPO_ID);
    testRepo.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString());
    testRepo.setReleases(true);
    testRepo.setSnapshots(false);
    c.addManagedRepository(testRepo);
    testRepoS = new ManagedRepositoryConfiguration();
    testRepoS.setId(TEST_SNAP_REPO_ID);
    testRepoS.setLocation(Paths.get("target/test-repositorys").toAbsolutePath().toString());
    testRepoS.setReleases(false);
    testRepoS.setSnapshots(true);
    c.addManagedRepository(testRepoS);
    RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
    testRemoteRepo.setId(TEST_REMOTE_REPO_ID);
    testRemoteRepo.setLayout("default");
    testRemoteRepo.setName("Central Repository");
    testRemoteRepo.setUrl("http://central.repo.com/maven2");
    testRemoteRepo.setTimeout(10);
    c.addRemoteRepository(testRemoteRepo);
    ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
    proxyConnector.setSourceRepoId(TEST_REPO_ID);
    proxyConnector.setTargetRepoId(TEST_REMOTE_REPO_ID);
    proxyConnector.setDisabled(false);
    c.addProxyConnector(proxyConnector);
    ProxyConnectorConfiguration proxyConnectors = new ProxyConnectorConfiguration();
    proxyConnectors.setSourceRepoId(TEST_SNAP_REPO_ID);
    proxyConnectors.setTargetRepoId(TEST_REMOTE_REPO_ID);
    proxyConnectors.setDisabled(false);
    c.addProxyConnector(proxyConnectors);
    List<String> repos = new ArrayList<>();
    repos.add(TEST_REPO_ID);
    repos.add(TEST_SNAP_REPO_ID);
    RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
    repoGroup.setId(TEST_REPO_GROUP_ID);
    repoGroup.setRepositories(repos);
    c.addRepositoryGroup(repoGroup);
    configuration.save(c);
    repositoryRegistry.reload();
    assertFalse(c.getManagedRepositories().get(0).isSnapshots());
    assertTrue(c.getManagedRepositories().get(0).isReleases());
    assertTrue(c.getManagedRepositories().get(1).isSnapshots());
    assertFalse(c.getManagedRepositories().get(1).isReleases());
    wagonFactory = mock(WagonFactory.class);
    storage.setWagonFactory(wagonFactory);
    Wagon wagon = new MockWagon();
    when(wagonFactory.getWagon(new WagonFactoryRequest().protocol("wagon#http"))).thenReturn(wagon);
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.RepositoryGroupConfiguration) WagonFactoryRequest(org.apache.archiva.proxy.common.WagonFactoryRequest) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.RepositoryGroupConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArrayList(java.util.ArrayList) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) WagonFactory(org.apache.archiva.proxy.common.WagonFactory) Wagon(org.apache.maven.wagon.Wagon) Before(org.junit.Before)

Example 25 with RemoteRepositoryConfiguration

use of org.apache.archiva.configuration.RemoteRepositoryConfiguration in project archiva by apache.

the class Maven2RepositoryMetadataResolverMRM1411Test method testGetProjectVersionMetadataWithParentNoRemoteReposConfigured.

@Test
public void testGetProjectVersionMetadataWithParentNoRemoteReposConfigured() throws Exception {
    // remove configuration
    Configuration config = configuration.getConfiguration();
    RemoteRepositoryConfiguration remoteRepo = config.findRemoteRepositoryById(TEST_REMOTE_REPO_ID);
    config.removeRemoteRepository(remoteRepo);
    configuration.save(config);
    copyTestArtifactWithParent("target/test-classes/com/example/test/test-artifact-module-a", "target/test-repository/com/example/test/test-artifact-module-a");
    ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "test-artifact-module-a", "1.0"));
    assertEquals("1.0", metadata.getId());
    MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet(MavenProjectFacet.FACET_ID);
    assertNotNull(facet);
    assertEquals("com.example.test", facet.getGroupId());
    assertEquals("test-artifact-module-a", facet.getArtifactId());
    assertEquals("jar", facet.getPackaging());
    List<String> paths = new ArrayList<>();
    paths.add("target/test-repository/com/example/test/test-artifact-module-a");
    paths.add("target/test-repository/com/example/test/test-artifact-parent");
    paths.add("target/test-repository/com/example/test/test-artifact-root");
    deleteTestArtifactWithParent(paths);
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArrayList(java.util.ArrayList) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Test(org.junit.Test)

Aggregations

RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)26 Configuration (org.apache.archiva.configuration.Configuration)9 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)8 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)7 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)7 Test (org.junit.Test)6 ContextConfiguration (org.springframework.test.context.ContextConfiguration)6 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)5 ArrayList (java.util.ArrayList)4 PasswordCredentials (org.apache.archiva.repository.PasswordCredentials)4 Before (org.junit.Before)4 IndeterminateConfigurationException (org.apache.archiva.configuration.IndeterminateConfigurationException)3 WagonFactory (org.apache.archiva.proxy.common.WagonFactory)3 WagonFactoryRequest (org.apache.archiva.proxy.common.WagonFactoryRequest)3 RegistryException (org.apache.archiva.redback.components.registry.RegistryException)3 RepositoryCredentials (org.apache.archiva.repository.RepositoryCredentials)3 RepositoryException (org.apache.archiva.repository.RepositoryException)3 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)3 Wagon (org.apache.maven.wagon.Wagon)3 URI (java.net.URI)2