Search in sources :

Example 16 with RemoteRepository

use of org.apache.archiva.repository.RemoteRepository 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 17 with RemoteRepository

use of org.apache.archiva.repository.RemoteRepository in project archiva by apache.

the class RemoteDefaultRepositoryContentTest method setUp.

@Before
public void setUp() throws Exception {
    RemoteRepository repository = createRemoteRepository("testRemoteRepo", "Unit Test Remote Repo", "http://repo1.maven.org/maven2/");
    repoContent = new RemoteDefaultRepositoryContent(artifactMappingProviders);
    // repoContent = (RemoteRepositoryContent) lookup( RemoteRepositoryContent.class, "default" );
    repoContent.setRepository(repository);
}
Also used : RemoteDefaultRepositoryContent(org.apache.archiva.repository.content.maven2.RemoteDefaultRepositoryContent) RemoteRepository(org.apache.archiva.repository.RemoteRepository) Before(org.junit.Before)

Example 18 with RemoteRepository

use of org.apache.archiva.repository.RemoteRepository in project archiva by apache.

the class RepositoryModelResolver method resolveModel.

@Override
public ModelSource resolveModel(String groupId, String artifactId, String version) throws UnresolvableModelException {
    String filename = artifactId + "-" + version + ".pom";
    // TODO: we need to convert 1.0-20091120.112233-1 type paths to baseVersion for the below call - add a test
    Path model = pathTranslator.toFile(basedir, groupId, artifactId, version, filename);
    if (!Files.exists(model)) {
        // is a SNAPSHOT ? so we can try to find locally before asking remote repositories.
        if (StringUtils.contains(version, VersionUtil.SNAPSHOT)) {
            Path localSnapshotModel = findTimeStampedSnapshotPom(groupId, artifactId, version, model.getParent().toString());
            if (localSnapshotModel != null) {
                return new FileModelSource(localSnapshotModel.toFile());
            }
        }
        for (RemoteRepository remoteRepository : remoteRepositories) {
            try {
                boolean success = getModelFromProxy(remoteRepository, groupId, artifactId, version, filename);
                if (success && Files.exists(model)) {
                    log.info("Model '{}' successfully retrieved from remote repository '{}'", model.toAbsolutePath(), remoteRepository.getId());
                    break;
                }
            } catch (ResourceDoesNotExistException e) {
                log.info("An exception was caught while attempting to retrieve model '{}' from remote repository '{}'.Reason:{}", model.toAbsolutePath(), remoteRepository.getId(), e.getMessage());
            } catch (Exception e) {
                log.warn("An exception was caught while attempting to retrieve model '{}' from remote repository '{}'.Reason:{}", model.toAbsolutePath(), remoteRepository.getId(), e.getMessage());
                continue;
            }
        }
    }
    return new FileModelSource(model.toFile());
}
Also used : Path(java.nio.file.Path) FileModelSource(org.apache.maven.model.building.FileModelSource) RemoteRepository(org.apache.archiva.repository.RemoteRepository) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) InvalidRepositoryException(org.apache.maven.model.resolution.InvalidRepositoryException) UnresolvableModelException(org.apache.maven.model.resolution.UnresolvableModelException) XMLException(org.apache.archiva.xml.XMLException) WagonFactoryException(org.apache.archiva.proxy.common.WagonFactoryException) TransferFailedException(org.apache.maven.wagon.TransferFailedException) ConnectionException(org.apache.maven.wagon.ConnectionException) AuthorizationException(org.apache.maven.wagon.authorization.AuthorizationException) IOException(java.io.IOException) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException)

Aggregations

RemoteRepository (org.apache.archiva.repository.RemoteRepository)18 IOException (java.io.IOException)8 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)7 ManagedRepository (org.apache.archiva.repository.ManagedRepository)7 PasswordCredentials (org.apache.archiva.repository.PasswordCredentials)7 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)7 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)7 Path (java.nio.file.Path)6 NetworkProxy (org.apache.archiva.admin.model.beans.NetworkProxy)6 ConnectionException (org.apache.maven.wagon.ConnectionException)6 AuthenticationException (org.apache.maven.wagon.authentication.AuthenticationException)6 AuthenticationInfo (org.apache.maven.wagon.authentication.AuthenticationInfo)6 IndexingContext (org.apache.maven.index.context.IndexingContext)5 WagonFactoryException (org.apache.archiva.proxy.common.WagonFactoryException)4 WagonFactoryRequest (org.apache.archiva.proxy.common.WagonFactoryRequest)4 IndexUpdateRequest (org.apache.maven.index.updater.IndexUpdateRequest)4 ResourceFetcher (org.apache.maven.index.updater.ResourceFetcher)4 MalformedURLException (java.net.MalformedURLException)3 URI (java.net.URI)3 Configuration (org.apache.archiva.configuration.Configuration)3