use of org.apache.archiva.repository.RepositoryException in project archiva by apache.
the class MavenRepositoryProvider method getURIFromString.
private URI getURIFromString(String uriStr) throws RepositoryException {
URI uri;
try {
if (StringUtils.isEmpty(uriStr)) {
return new URI("");
}
if (uriStr.startsWith("/")) {
// only absolute paths are prepended with file scheme
uri = new URI("file://" + uriStr);
} else {
uri = new URI(uriStr);
}
if (uri.getScheme() != null && !"file".equals(uri.getScheme())) {
log.error("Bad URI scheme found: {}, URI={}", uri.getScheme(), uri);
throw new RepositoryException("The uri " + uriStr + " is not valid. Only file:// URI is allowed for maven.");
}
} catch (URISyntaxException e) {
String newCfg = "file://" + uriStr;
try {
uri = new URI(newCfg);
} catch (URISyntaxException e1) {
log.error("Could not create URI from {} -> ", uriStr, newCfg);
throw new RepositoryException("The config entry " + uriStr + " cannot be converted to URI.");
}
}
log.debug("Setting location uri: {}", uri);
return uri;
}
use of org.apache.archiva.repository.RepositoryException 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;
}
use of org.apache.archiva.repository.RepositoryException in project archiva by apache.
the class ManagedDefaultRepositoryContent method deleteProject.
@Override
public void deleteProject(String namespace, String projectId) throws RepositoryException {
ArtifactReference artifactReference = new ArtifactReference();
artifactReference.setGroupId(namespace);
artifactReference.setArtifactId(projectId);
String path = toPath(artifactReference);
Path directory = Paths.get(getRepoRoot(), path);
if (!Files.exists(directory)) {
throw new ContentNotFoundException("cannot found project " + namespace + ":" + projectId);
}
if (Files.isDirectory(directory)) {
try {
org.apache.archiva.common.utils.FileUtils.deleteDirectory(directory);
} catch (IOException e) {
throw new RepositoryException(e.getMessage(), e);
}
} else {
log.warn("project {}:{} is not a directory", namespace, projectId);
}
}
Aggregations