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);
}
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;
}
Aggregations