Search in sources :

Example 11 with StagingRepositoryFeature

use of org.apache.archiva.repository.features.StagingRepositoryFeature in project archiva by apache.

the class AbstractRepository method close.

@Override
public void close() {
    ArchivaIndexingContext ctx = getIndexingContext();
    if (ctx != null) {
        try {
            ctx.close();
        } catch (IOException e) {
            log.warn("Error during index context close.", e);
        }
    }
    if (supportsFeature(StagingRepositoryFeature.class)) {
        StagingRepositoryFeature sf = getFeature(StagingRepositoryFeature.class).get();
        if (sf.getStagingRepository() != null) {
            sf.getStagingRepository().close();
        }
    }
    clearListeners();
}
Also used : IOException(java.io.IOException) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext)

Example 12 with StagingRepositoryFeature

use of org.apache.archiva.repository.features.StagingRepositoryFeature 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 13 with StagingRepositoryFeature

use of org.apache.archiva.repository.features.StagingRepositoryFeature in project archiva by apache.

the class MavenRepositoryProvider method getManagedConfiguration.

@Override
public ManagedRepositoryConfiguration getManagedConfiguration(ManagedRepository managedRepository) throws RepositoryException {
    if (!(managedRepository instanceof MavenManagedRepository || managedRepository instanceof BasicManagedRepository)) {
        log.error("Wrong remote repository type " + managedRepository.getClass().getName());
        throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + managedRepository.getClass().getName());
    }
    ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
    cfg.setType(managedRepository.getType().toString());
    cfg.setId(managedRepository.getId());
    cfg.setName(managedRepository.getName());
    cfg.setDescription(managedRepository.getDescription());
    cfg.setLocation(convertUriToPath(managedRepository.getLocation()));
    cfg.setLayout(managedRepository.getLayout());
    cfg.setRefreshCronExpression(managedRepository.getSchedulingDefinition());
    cfg.setScanned(managedRepository.isScanned());
    cfg.setBlockRedeployments(managedRepository.blocksRedeployments());
    StagingRepositoryFeature stagingRepositoryFeature = managedRepository.getFeature(StagingRepositoryFeature.class).get();
    cfg.setStageRepoNeeded(stagingRepositoryFeature.isStageRepoNeeded());
    IndexCreationFeature indexCreationFeature = managedRepository.getFeature(IndexCreationFeature.class).get();
    cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
    cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
    cfg.setSkipPackedIndexCreation(indexCreationFeature.isSkipPackedIndexCreation());
    ArtifactCleanupFeature artifactCleanupFeature = managedRepository.getFeature(ArtifactCleanupFeature.class).get();
    cfg.setRetentionCount(artifactCleanupFeature.getRetentionCount());
    cfg.setRetentionPeriod(artifactCleanupFeature.getRetentionPeriod().getDays());
    cfg.setDeleteReleasedSnapshots(artifactCleanupFeature.isDeleteReleasedSnapshots());
    if (managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE)) {
        cfg.setReleases(true);
    } else {
        cfg.setReleases(false);
    }
    if (managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT)) {
        cfg.setSnapshots(true);
    } else {
        cfg.setSnapshots(false);
    }
    return cfg;
}
Also used : BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RepositoryException(org.apache.archiva.repository.RepositoryException) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature)

Aggregations

StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)13 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)10 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)10 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)6 RepositoryException (org.apache.archiva.repository.RepositoryException)5 IOException (java.io.IOException)3 URI (java.net.URI)3 Test (org.junit.Test)3 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)1 Configuration (org.apache.archiva.configuration.Configuration)1 IndeterminateConfigurationException (org.apache.archiva.configuration.IndeterminateConfigurationException)1 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)1 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)1 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)1 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)1 IndexUpdateFailedException (org.apache.archiva.indexer.IndexUpdateFailedException)1 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)1