use of org.apache.archiva.repository.RepositoryException in project archiva by apache.
the class DefaultBrowseService method getArtifactContentText.
@Override
public ArtifactContent getArtifactContentText(String groupId, String artifactId, String version, String classifier, String type, String path, String repositoryId) throws ArchivaRestServiceException {
List<String> selectedRepos = getSelectedRepos(repositoryId);
try {
for (String repoId : selectedRepos) {
ManagedRepositoryContent managedRepositoryContent = null;
try {
managedRepositoryContent = getManagedRepositoryContent(repoId);
} catch (RepositoryException e) {
log.error("No repository content found for " + repoId);
continue;
}
ArchivaArtifact archivaArtifact = new ArchivaArtifact(groupId, artifactId, version, classifier, StringUtils.isEmpty(type) ? "jar" : type, repoId);
Path file = managedRepositoryContent.toFile(archivaArtifact);
if (!Files.exists(file)) {
log.debug("file: {} not exists for repository: {} try next repository", file, repoId);
continue;
}
if (StringUtils.isNotBlank(path)) {
// zip entry of the path -> path must a real file entry of the archive
JarFile jarFile = new JarFile(file.toFile());
ZipEntry zipEntry = jarFile.getEntry(path);
try (InputStream inputStream = jarFile.getInputStream(zipEntry)) {
return new ArtifactContent(IOUtils.toString(inputStream, ARTIFACT_CONTENT_ENCODING), repoId);
} finally {
closeQuietly(jarFile);
}
}
return new ArtifactContent(new String(Files.readAllBytes(file), ARTIFACT_CONTENT_ENCODING), repoId);
}
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
}
log.debug("artifact: {}:{}:{}:{}:{} not found", groupId, artifactId, version, classifier, type);
// 404 ?
return new ArtifactContent();
}
use of org.apache.archiva.repository.RepositoryException in project archiva by apache.
the class MetadataUpdaterConsumer method beginScan.
@Override
public void beginScan(ManagedRepository repoConfig, Date whenGathered) throws ConsumerException {
try {
ManagedRepository repo = repositoryRegistry.getManagedRepository(repoConfig.getId());
if (repo == null) {
throw new RepositoryNotFoundException("Repository not found: " + repoConfig.getId());
}
this.repository = repo.getContent();
if (this.repository == null) {
throw new RepositoryNotFoundException("Repository content not found: " + repoConfig.getId());
}
this.repositoryDir = Paths.get(repository.getRepoRoot());
this.scanStartTimestamp = System.currentTimeMillis();
} catch (RepositoryException e) {
throw new ConsumerException(e.getMessage(), e);
}
}
use of org.apache.archiva.repository.RepositoryException in project archiva by apache.
the class DefaultNetworkProxyAdmin method deleteNetworkProxy.
@Override
public void deleteNetworkProxy(String networkProxyId, AuditInformation auditInformation) throws RepositoryAdminException {
NetworkProxy networkProxy = getNetworkProxy(networkProxyId);
if (networkProxy == null) {
throw new RepositoryAdminException("cannot delete NetworkProxy with id " + networkProxyId + " as not exist");
}
Configuration configuration = getArchivaConfiguration().getConfiguration();
NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration(networkProxy);
configuration.removeNetworkProxy(networkProxyConfiguration);
for (RemoteRepository repo : repositoryRegistry.getRemoteRepositories()) {
if (repo.supportsFeature(RemoteIndexFeature.class)) {
RemoteIndexFeature rif = repo.getFeature(RemoteIndexFeature.class).get();
if (networkProxyId.equals(rif.getProxyId())) {
rif.setProxyId(null);
try {
repositoryRegistry.putRepository(repo, configuration);
} catch (RepositoryException e) {
log.error("Could not update repository {}", repo.getId(), e);
}
}
}
}
triggerAuditEvent(networkProxy.getId(), null, AuditEvent.DELETE_NETWORK_PROXY, auditInformation);
saveConfiguration(configuration);
}
use of org.apache.archiva.repository.RepositoryException in project archiva by apache.
the class DefaultRemoteRepositoryAdmin method deleteRemoteRepository.
@Override
public Boolean deleteRemoteRepository(String repositoryId, AuditInformation auditInformation) throws RepositoryAdminException {
triggerAuditEvent(repositoryId, null, AuditEvent.DELETE_REMOTE_REPO, auditInformation);
Configuration configuration = getArchivaConfiguration().getConfiguration();
RemoteRepository repo = repositoryRegistry.getRemoteRepository(repositoryId);
if (repo == null) {
throw new RepositoryAdminException("Could not delete repository " + repositoryId + ". The repository does not exist.");
}
try {
repositoryRegistry.removeRepository(repo, configuration);
} catch (RepositoryException e) {
log.error("Deletion of remote repository failed {}: {}", repo.getId(), e.getMessage(), e);
throw new RepositoryAdminException("Could not delete remote repository" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
}
saveConfiguration(configuration);
return Boolean.TRUE;
}
use of org.apache.archiva.repository.RepositoryException in project archiva by apache.
the class DefaultManagedRepositoryAdmin method deleteManagedRepository.
@Override
public Boolean deleteManagedRepository(String repositoryId, AuditInformation auditInformation, boolean deleteContent) throws RepositoryAdminException {
Configuration config = getArchivaConfiguration().getConfiguration();
ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById(repositoryId);
if (repoConfig != null) {
log.debug("Repo location " + repoConfig.getLocation());
org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository(repositoryId);
org.apache.archiva.repository.ManagedRepository stagingRepository = null;
if (repo != null) {
try {
if (repo.supportsFeature(StagingRepositoryFeature.class)) {
stagingRepository = repo.getFeature(StagingRepositoryFeature.class).get().getStagingRepository();
}
repositoryRegistry.removeRepository(repo, config);
} catch (RepositoryException e) {
log.error("Removal of repository {} failed: {}", repositoryId, e.getMessage(), e);
throw new RepositoryAdminException("Removal of repository " + repositoryId + " failed.");
}
} else {
throw new RepositoryAdminException("A repository with that id does not exist");
}
triggerAuditEvent(repositoryId, null, AuditEvent.DELETE_MANAGED_REPO, auditInformation);
if (repoConfig != null) {
deleteManagedRepository(repoConfig, deleteContent, config, false);
}
// stage repo exists ?
if (stagingRepository != null) {
// do not trigger event when deleting the staged one
ManagedRepositoryConfiguration stagingRepositoryConfig = config.findManagedRepositoryById(stagingRepository.getId());
try {
repositoryRegistry.removeRepository(stagingRepository);
if (stagingRepositoryConfig != null) {
deleteManagedRepository(stagingRepositoryConfig, deleteContent, config, true);
}
} catch (RepositoryException e) {
log.error("Removal of staging repository {} failed: {}", stagingRepository.getId(), e.getMessage(), e);
}
}
try {
saveConfiguration(config);
} catch (Exception e) {
throw new RepositoryAdminException("Error saving configuration for delete action" + e.getMessage(), e);
}
return Boolean.TRUE;
} else {
return Boolean.FALSE;
}
}
Aggregations