Search in sources :

Example 26 with IndexCreationFeature

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

the class MavenRepositoryProvider method updateRemoteInstance.

@Override
public void updateRemoteInstance(EditableRemoteRepository repo, RemoteRepositoryConfiguration cfg) throws RepositoryException {
    setBaseConfig(repo, cfg);
    repo.setCheckPath(cfg.getCheckPath());
    repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
    try {
        repo.setLocation(new URI(cfg.getUrl()));
    } catch (UnsupportedURIException | URISyntaxException e) {
        log.error("Could not set remote url " + cfg.getUrl());
        throw new RepositoryException("The url config is not a valid uri: " + cfg.getUrl());
    }
    repo.setTimeout(Duration.ofSeconds(cfg.getTimeout()));
    RemoteIndexFeature remoteIndexFeature = repo.getFeature(RemoteIndexFeature.class).get();
    remoteIndexFeature.setDownloadRemoteIndex(cfg.isDownloadRemoteIndex());
    remoteIndexFeature.setDownloadRemoteIndexOnStartup(cfg.isDownloadRemoteIndexOnStartup());
    remoteIndexFeature.setDownloadTimeout(Duration.ofSeconds(cfg.getRemoteDownloadTimeout()));
    remoteIndexFeature.setProxyId(cfg.getRemoteDownloadNetworkProxyId());
    if (cfg.isDownloadRemoteIndex()) {
        try {
            remoteIndexFeature.setIndexUri(new URI(cfg.getRemoteIndexUrl()));
        } catch (URISyntaxException e) {
            log.error("Could not set remote index url " + cfg.getRemoteIndexUrl());
            remoteIndexFeature.setDownloadRemoteIndex(false);
            remoteIndexFeature.setDownloadRemoteIndexOnStartup(false);
        }
    }
    for (Object key : cfg.getExtraHeaders().keySet()) {
        repo.addExtraHeader(key.toString(), cfg.getExtraHeaders().get(key).toString());
    }
    for (Object key : cfg.getExtraParameters().keySet()) {
        repo.addExtraParameter(key.toString(), cfg.getExtraParameters().get(key).toString());
    }
    PasswordCredentials credentials = new PasswordCredentials("", new char[0]);
    if (cfg.getPassword() != null && cfg.getUsername() != null) {
        credentials.setPassword(cfg.getPassword().toCharArray());
        credentials.setUsername(cfg.getUsername());
        repo.setCredentials(credentials);
    } else {
        credentials.setPassword(new char[0]);
    }
    IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
    if (cfg.getIndexDir() != null) {
        indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir()));
    }
    if (cfg.getPackedIndexDir() != null) {
        indexCreationFeature.setPackedIndexPath(getURIFromString(cfg.getPackedIndexDir()));
    }
    log.debug("Updated remote instance {}", repo);
}
Also used : PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) UnsupportedURIException(org.apache.archiva.repository.UnsupportedURIException) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RepositoryException(org.apache.archiva.repository.RepositoryException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 27 with IndexCreationFeature

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

IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)27 URI (java.net.URI)11 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)10 StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)10 Path (java.nio.file.Path)9 RepositoryException (org.apache.archiva.repository.RepositoryException)6 IOException (java.io.IOException)5 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)5 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)5 Test (org.junit.Test)5 PasswordCredentials (org.apache.archiva.repository.PasswordCredentials)4 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)3 ManagedRepository (org.apache.archiva.repository.ManagedRepository)3 BasicManagedRepository (org.apache.archiva.repository.BasicManagedRepository)2 RemoteRepository (org.apache.archiva.repository.RemoteRepository)2 RepositoryCredentials (org.apache.archiva.repository.RepositoryCredentials)2 UnsupportedURIException (org.apache.archiva.repository.UnsupportedURIException)2 IndexingContext (org.apache.maven.index.context.IndexingContext)2 URISyntaxException (java.net.URISyntaxException)1 Files (java.nio.file.Files)1