use of org.apache.archiva.repository.RepositoryException 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()));
}
use of org.apache.archiva.repository.RepositoryException in project archiva by apache.
the class RepositoryProviderMock method updateRemoteInstance.
@Override
public void updateRemoteInstance(EditableRemoteRepository remoteRepository, RemoteRepositoryConfiguration configuration) throws RepositoryException {
try {
remoteRepository.setName(remoteRepository.getPrimaryLocale(), configuration.getName());
remoteRepository.setBaseUri(new URI(""));
remoteRepository.setDescription(remoteRepository.getPrimaryLocale(), configuration.getDescription());
remoteRepository.setLayout(configuration.getLayout());
remoteRepository.setSchedulingDefinition(configuration.getRefreshCronExpression());
remoteRepository.setCheckPath(configuration.getCheckPath());
remoteRepository.setExtraHeaders(configuration.getExtraHeaders());
remoteRepository.setExtraParameters(configuration.getExtraParameters());
remoteRepository.setTimeout(Duration.ofSeconds(configuration.getTimeout()));
char[] pwd = configuration.getPassword() == null ? "".toCharArray() : configuration.getPassword().toCharArray();
remoteRepository.setCredentials(new PasswordCredentials(configuration.getUsername(), pwd));
remoteRepository.setLocation(new URI(configuration.getUrl() == null ? "" : configuration.getUrl()));
RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get();
rif.setDownloadRemoteIndexOnStartup(configuration.isDownloadRemoteIndexOnStartup());
rif.setDownloadRemoteIndex(configuration.isDownloadRemoteIndex());
rif.setIndexUri(new URI(configuration.getIndexDir()));
rif.setDownloadTimeout(Duration.ofSeconds(configuration.getRemoteDownloadTimeout()));
rif.setProxyId(configuration.getRemoteDownloadNetworkProxyId());
} catch (Exception e) {
throw new RepositoryException("Error", e);
}
}
use of org.apache.archiva.repository.RepositoryException in project archiva by apache.
the class CleanupReleasedSnapshotsRepositoryPurge method process.
@Override
public void process(String path) throws RepositoryPurgeException {
try {
Path artifactFile = Paths.get(repository.getRepoRoot(), path);
if (!Files.exists(artifactFile)) {
// Nothing to do here, file doesn't exist, skip it.
return;
}
ArtifactReference artifactRef = repository.toArtifactReference(path);
if (!VersionUtil.isSnapshot(artifactRef.getVersion())) {
// Nothing to do here, not a snapshot, skip it.
return;
}
ProjectReference reference = new ProjectReference();
reference.setGroupId(artifactRef.getGroupId());
reference.setArtifactId(artifactRef.getArtifactId());
// Gether the released versions
List<String> releasedVersions = new ArrayList<>();
Collection<org.apache.archiva.repository.ManagedRepository> repos = repositoryRegistry.getManagedRepositories();
for (org.apache.archiva.repository.ManagedRepository repo : repos) {
if (repo.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE)) {
try {
ManagedRepositoryContent repoContent = repo.getContent();
for (String version : repoContent.getVersions(reference)) {
if (!VersionUtil.isSnapshot(version)) {
releasedVersions.add(version);
}
}
} catch (RepositoryException e) {
// swallow
}
}
}
Collections.sort(releasedVersions, VersionComparator.getInstance());
// Now clean out any version that is earlier than the highest released version.
boolean needsMetadataUpdate = false;
VersionedReference versionRef = new VersionedReference();
versionRef.setGroupId(artifactRef.getGroupId());
versionRef.setArtifactId(artifactRef.getArtifactId());
MetadataRepository metadataRepository = repositorySession.getRepository();
if (releasedVersions.contains(VersionUtil.getReleaseVersion(artifactRef.getVersion()))) {
versionRef.setVersion(artifactRef.getVersion());
repository.deleteVersion(versionRef);
for (RepositoryListener listener : listeners) {
listener.deleteArtifact(metadataRepository, repository.getId(), artifactRef.getGroupId(), artifactRef.getArtifactId(), artifactRef.getVersion(), artifactFile.getFileName().toString());
}
metadataRepository.removeProjectVersion(repository.getId(), artifactRef.getGroupId(), artifactRef.getArtifactId(), artifactRef.getVersion());
needsMetadataUpdate = true;
}
if (needsMetadataUpdate) {
updateMetadata(artifactRef);
}
} catch (LayoutException e) {
log.debug("Not processing file that is not an artifact: {}", e.getMessage());
} catch (ContentNotFoundException e) {
throw new RepositoryPurgeException(e.getMessage(), e);
} catch (MetadataRepositoryException e) {
log.error("Could not remove metadata during cleanup of released snapshots of {}", path, e);
}
}
use of org.apache.archiva.repository.RepositoryException in project archiva by apache.
the class Maven2RepositoryMerger method merge.
@Override
public void merge(MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId) throws RepositoryMergerException {
try {
List<ArtifactMetadata> artifactsInSourceRepo = metadataRepository.getArtifacts(sourceRepoId);
for (ArtifactMetadata artifactMetadata : artifactsInSourceRepo) {
artifactMetadata.setRepositoryId(targetRepoId);
createFolderStructure(sourceRepoId, targetRepoId, artifactMetadata);
}
} catch (MetadataRepositoryException e) {
throw new RepositoryMergerException(e.getMessage(), e);
} catch (IOException e) {
throw new RepositoryMergerException(e.getMessage(), e);
} catch (RepositoryException e) {
throw new RepositoryMergerException(e.getMessage(), e);
}
}
use of org.apache.archiva.repository.RepositoryException in project archiva by apache.
the class DefaultRemoteRepositoryAdmin method updateRemoteRepository.
@Override
public Boolean updateRemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository, AuditInformation auditInformation) throws RepositoryAdminException {
String repositoryId = remoteRepository.getId();
triggerAuditEvent(repositoryId, null, AuditEvent.MODIFY_REMOTE_REPO, auditInformation);
// update means : remove and add
Configuration configuration = getArchivaConfiguration().getConfiguration();
RemoteRepositoryConfiguration remoteRepositoryConfiguration = getRepositoryConfiguration(remoteRepository);
try {
repositoryRegistry.putRepository(remoteRepositoryConfiguration, configuration);
} catch (RepositoryException e) {
log.error("Could not update remote repository {}: {}", remoteRepositoryConfiguration.getId(), e.getMessage(), e);
throw new RepositoryAdminException("Update of remote repository failed" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
}
saveConfiguration(configuration);
return Boolean.TRUE;
}
Aggregations