use of org.apache.archiva.rest.api.model.ArtifactContent 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();
}
Aggregations