use of se.light.assembly64.model.Artifact in project archiva by apache.
the class DependencyTreeBuilderTestMaven3 method testBuilderDependencies.
@Test
public void testBuilderDependencies() throws Exception {
List<TreeEntry> treeEntries = builder.buildDependencyTree(Collections.singletonList(TEST_REPO_ID), TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION);
Artifact artifact = new Artifact(TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "", "");
artifact.setFileExtension("jar");
assertThat(treeEntries).isNotNull().isNotEmpty().contains(new TreeEntry(artifact));
artifact = new Artifact("commons-lang", "commons-lang", "2.2", "compile", "");
artifact.setFileExtension("jar");
assertThat(treeEntries.get(0).getChilds()).isNotNull().isNotEmpty().contains(new TreeEntry(artifact));
}
use of se.light.assembly64.model.Artifact in project archiva by apache.
the class DefaultSearchService method redirectToArtifactFile.
@Override
public Response redirectToArtifactFile(String repositoryId, String groupId, String artifactId, String version, String packaging, String classifier) throws ArchivaRestServiceException {
try {
if (StringUtils.isEmpty(groupId)) {
return Response.status(new Response.StatusType() {
@Override
public int getStatusCode() {
return Response.Status.BAD_REQUEST.getStatusCode();
}
@Override
public Response.Status.Family getFamily() {
return Response.Status.BAD_REQUEST.getFamily();
}
@Override
public String getReasonPhrase() {
return "groupId mandatory";
}
}).build();
}
if (StringUtils.isEmpty(version)) {
return Response.status(new Response.StatusType() {
@Override
public int getStatusCode() {
return Response.Status.BAD_REQUEST.getStatusCode();
}
@Override
public Response.Status.Family getFamily() {
return Response.Status.BAD_REQUEST.getFamily();
}
@Override
public String getReasonPhrase() {
return "version mandatory";
}
}).build();
}
if (StringUtils.isEmpty(artifactId)) {
return Response.status(new Response.StatusType() {
@Override
public int getStatusCode() {
return Response.Status.BAD_REQUEST.getStatusCode();
}
@Override
public Response.Status.Family getFamily() {
return Response.Status.BAD_REQUEST.getFamily();
}
@Override
public String getReasonPhrase() {
return "artifactId mandatory";
}
}).build();
}
SearchFields searchField = new SearchFields();
searchField.setGroupId(groupId);
searchField.setArtifactId(artifactId);
searchField.setPackaging(StringUtils.isBlank(packaging) ? "jar" : packaging);
if (!StringUtils.equals(version, LATEST_KEYWORD)) {
searchField.setVersion(version);
}
searchField.setClassifier(classifier);
List<String> userRepos = getObservablesRepoIds().getStrings();
searchField.setRepositories(StringUtils.isEmpty(repositoryId) ? userRepos : Arrays.asList(repositoryId));
searchField.setExactSearch(true);
SearchResults searchResults = repositorySearch.search(getPrincipal(), searchField, null);
List<Artifact> artifacts = getArtifacts(searchResults);
if (artifacts.isEmpty()) {
return Response.status(new Response.StatusType() {
@Override
public int getStatusCode() {
return Response.Status.NO_CONTENT.getStatusCode();
}
@Override
public Response.Status.Family getFamily() {
return Response.Status.NO_CONTENT.getFamily();
}
@Override
public String getReasonPhrase() {
return "your query doesn't return any artifact";
}
}).build();
}
// so simple loop and retain only artifact with null classifier
if (classifier == null) {
List<Artifact> filteredArtifacts = new ArrayList<>(artifacts.size());
for (Artifact artifact : artifacts) {
if (artifact.getClassifier() == null) {
filteredArtifacts.add(artifact);
}
}
artifacts = filteredArtifacts;
}
// TODO return json result of the query ?
if (artifacts.size() > 1 && !StringUtils.equals(version, LATEST_KEYWORD)) {
return Response.status(new Response.StatusType() {
@Override
public int getStatusCode() {
return Response.Status.BAD_REQUEST.getStatusCode();
}
@Override
public Response.Status.Family getFamily() {
return Response.Status.BAD_REQUEST.getFamily();
}
@Override
public String getReasonPhrase() {
return "your query return more than one artifact";
}
}).build();
}
// version is LATEST so we have to find the latest one from the result
if (artifacts.size() > 1 && StringUtils.equals(version, LATEST_KEYWORD)) {
TreeMap<String, Artifact> artifactPerVersion = new TreeMap<>(VersionComparator.getInstance());
for (Artifact artifact : artifacts) {
artifactPerVersion.put(artifact.getVersion(), artifact);
}
return Response.temporaryRedirect(new URI(artifactPerVersion.lastEntry().getValue().getUrl())).build();
}
Artifact artifact = artifacts.get(0);
return Response.temporaryRedirect(new URI(artifact.getUrl())).build();
} catch (Exception e) {
throw new ArchivaRestServiceException(e.getMessage(), e);
}
}
use of se.light.assembly64.model.Artifact in project archiva by apache.
the class DefaultSearchService method getArtifactByChecksum.
public List<Artifact> getArtifactByChecksum(ChecksumSearch checksumSearch) throws ArchivaRestServiceException {
// if no repos set we use ones available for the user
if (checksumSearch.getRepositories() == null || checksumSearch.getRepositories().isEmpty()) {
checksumSearch.setRepositories(getObservableRepos());
}
RepositorySession repositorySession = repositorySessionFactory.createSession();
MetadataRepository metadataRepository = repositorySession.getRepository();
Set<Artifact> artifactSet = new HashSet<>();
try {
for (String repoId : checksumSearch.getRepositories()) {
Collection<ArtifactMetadata> artifactMetadatas = metadataRepository.getArtifactsByChecksum(repoId, checksumSearch.getChecksum());
artifactSet.addAll(buildArtifacts(artifactMetadatas, repoId));
}
return new ArrayList<>(artifactSet);
} catch (MetadataRepositoryException e) {
log.error(e.getMessage(), e);
throw new ArchivaRestServiceException(e.getMessage(), e);
} finally {
repositorySession.closeQuietly();
}
}
use of se.light.assembly64.model.Artifact in project archiva by apache.
the class DefaultSearchService method getArtifacts.
// -------------------------------------
// internal
// -------------------------------------
protected List<Artifact> getArtifacts(SearchResults searchResults) throws ArchivaRestServiceException {
if (searchResults == null || searchResults.isEmpty()) {
return Collections.emptyList();
}
List<Artifact> artifacts = new ArrayList<>(searchResults.getReturnedHitsCount());
for (SearchResultHit hit : searchResults.getHits()) {
// duplicate Artifact one per available version
if (hit.getVersions().size() > 0) {
for (String version : hit.getVersions()) {
Artifact versionned = getModelMapper().map(hit, Artifact.class);
if (StringUtils.isNotBlank(version)) {
versionned.setVersion(version);
versionned.setUrl(getArtifactUrl(versionned));
artifacts.add(versionned);
}
}
}
}
return artifacts;
}
use of se.light.assembly64.model.Artifact in project archiva by apache.
the class ArtifactBuilder method build.
public Artifact build() {
ArtifactReference ref = new ArtifactReference();
ref.setArtifactId(artifactMetadata.getProject());
ref.setGroupId(artifactMetadata.getNamespace());
ref.setVersion(artifactMetadata.getVersion());
String type = null, classifier = null;
MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
if (facet != null) {
type = facet.getType();
classifier = facet.getClassifier();
}
ref.setClassifier(classifier);
ref.setType(type);
Path file = managedRepositoryContent.toFile(ref);
String extension = getExtensionFromFile(file);
Artifact artifact = new Artifact(ref.getGroupId(), ref.getArtifactId(), ref.getVersion());
artifact.setRepositoryId(artifactMetadata.getRepositoryId());
artifact.setClassifier(classifier);
artifact.setPackaging(type);
artifact.setType(type);
artifact.setFileExtension(extension);
artifact.setPath(managedRepositoryContent.toPath(ref));
// TODO: find a reusable formatter for this
double s = this.artifactMetadata.getSize();
String symbol = "b";
if (s > 1024) {
symbol = "K";
s /= 1024;
if (s > 1024) {
symbol = "M";
s /= 1024;
if (s > 1024) {
symbol = "G";
s /= 1024;
}
}
}
artifact.setContext(managedRepositoryContent.getId());
DecimalFormat df = new DecimalFormat("#,###.##", new DecimalFormatSymbols(Locale.US));
artifact.setSize(df.format(s) + " " + symbol);
artifact.setId(ref.getArtifactId() + "-" + ref.getVersion() + "." + ref.getType());
return artifact;
}
Aggregations