Search in sources :

Example 1 with UnsupportedURIException

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

the class MavenRepositoryProvider method updateManagedInstance.

@Override
public void updateManagedInstance(EditableManagedRepository repo, ManagedRepositoryConfiguration cfg) throws RepositoryException {
    try {
        repo.setLocation(getURIFromString(cfg.getLocation()));
    } catch (UnsupportedURIException e) {
        throw new RepositoryException("The location entry is not a valid uri: " + cfg.getLocation());
    }
    setBaseConfig(repo, cfg);
    Path repoDir = repo.getLocalPath();
    if (!Files.exists(repoDir)) {
        log.debug("Creating repo directory {}", repoDir);
        try {
            Files.createDirectories(repoDir);
        } catch (IOException e) {
            log.error("Could not create directory {} for repository {}", repo.getLocalPath(), repo.getId(), e);
            throw new RepositoryException("Could not create directory for repository " + repo.getLocalPath());
        }
    }
    repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
    repo.setBlocksRedeployment(cfg.isBlockRedeployments());
    repo.setScanned(cfg.isScanned());
    if (cfg.isReleases()) {
        repo.addActiveReleaseScheme(ReleaseScheme.RELEASE);
    }
    if (cfg.isSnapshots()) {
        repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
    }
    StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature(StagingRepositoryFeature.class).get();
    stagingRepositoryFeature.setStageRepoNeeded(cfg.isStageRepoNeeded());
    IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
    indexCreationFeature.setSkipPackedIndexCreation(cfg.isSkipPackedIndexCreation());
    indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir()));
    indexCreationFeature.setPackedIndexPath(getURIFromString(cfg.getPackedIndexDir()));
    /* -> Should be created by MavenIndexProvider

        Path indexPath;
        if (indexCreationFeature.getIndexPath().getScheme() == null) {
            indexPath = Paths.get(indexCreationFeature.getIndexPath().getPath());
        } else {
            indexPath = Paths.get(indexCreationFeature.getIndexPath());
        }
        Path absoluteIndexPath;
        if (indexPath.isAbsolute()) {
            absoluteIndexPath = indexPath;
        } else {
            absoluteIndexPath = PathUtil.getPathFromUri(repo.getLocation()).resolve(indexCreationFeature.getIndexPath().getPath());
        }
        try {
            Files.createDirectories(absoluteIndexPath);
        } catch (IOException e) {
            log.error("Could not create index directory {}", absoluteIndexPath);
            throw new RepositoryException("Could not create index directory " + absoluteIndexPath);
        }*/
    ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature(ArtifactCleanupFeature.class).get();
    artifactCleanupFeature.setDeleteReleasedSnapshots(cfg.isDeleteReleasedSnapshots());
    artifactCleanupFeature.setRetentionCount(cfg.getRetentionCount());
    artifactCleanupFeature.setRetentionPeriod(Period.ofDays(cfg.getRetentionPeriod()));
}
Also used : Path(java.nio.file.Path) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) UnsupportedURIException(org.apache.archiva.repository.UnsupportedURIException) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature)

Example 2 with UnsupportedURIException

use of org.apache.archiva.repository.UnsupportedURIException 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)

Aggregations

RepositoryException (org.apache.archiva.repository.RepositoryException)2 UnsupportedURIException (org.apache.archiva.repository.UnsupportedURIException)2 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Path (java.nio.file.Path)1 PasswordCredentials (org.apache.archiva.repository.PasswordCredentials)1 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)1 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)1 StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)1