use of org.apache.maven.artifact.versioning.ArtifactVersion in project intellij-community by JetBrains.
the class Maven3ServerEmbedder method retrieveAvailableVersions.
@NotNull
@Override
public List<String> retrieveAvailableVersions(@NotNull String groupId, @NotNull String artifactId, @NotNull List<MavenRemoteRepository> remoteRepositories) throws RemoteException {
try {
Artifact artifact = new DefaultArtifact(groupId, artifactId, "", Artifact.SCOPE_COMPILE, "pom", null, new DefaultArtifactHandler("pom"));
List<ArtifactVersion> versions = getComponent(ArtifactMetadataSource.class).retrieveAvailableVersions(artifact, getLocalRepository(), convertRepositories(remoteRepositories));
return ContainerUtil.map(versions, new Function<ArtifactVersion, String>() {
@Override
public String fun(ArtifactVersion version) {
return version.toString();
}
});
} catch (Exception e) {
Maven3ServerGlobals.getLogger().info(e);
}
return Collections.emptyList();
}
use of org.apache.maven.artifact.versioning.ArtifactVersion in project maven-plugins by apache.
the class AbstractJavadocMojo method populateCompileArtifactMap.
/**
* Method to put the artifacts in the hashmap.
*
* @param compileArtifactMap the hashmap that will contain the artifacts
* @param artifactList the list of artifacts that will be put in the map
* @throws MavenReportException if any
*/
private void populateCompileArtifactMap(Map<String, Artifact> compileArtifactMap, Collection<Artifact> artifactList) throws MavenReportException {
if (artifactList == null) {
return;
}
for (Artifact newArtifact : artifactList) {
File file = newArtifact.getFile();
if (file == null) {
throw new MavenReportException("Error in plugin descriptor - " + "dependency was not resolved for artifact: " + newArtifact.getGroupId() + ":" + newArtifact.getArtifactId() + ":" + newArtifact.getVersion());
}
if (compileArtifactMap.get(newArtifact.getDependencyConflictId()) != null) {
Artifact oldArtifact = compileArtifactMap.get(newArtifact.getDependencyConflictId());
ArtifactVersion oldVersion = new DefaultArtifactVersion(oldArtifact.getVersion());
ArtifactVersion newVersion = new DefaultArtifactVersion(newArtifact.getVersion());
if (newVersion.compareTo(oldVersion) > 0) {
compileArtifactMap.put(newArtifact.getDependencyConflictId(), newArtifact);
}
} else {
compileArtifactMap.put(newArtifact.getDependencyConflictId(), newArtifact);
}
}
}
use of org.apache.maven.artifact.versioning.ArtifactVersion in project maven-plugins by apache.
the class DependencyManagementRenderer method getDependencyRow.
@SuppressWarnings("unchecked")
private String[] getDependencyRow(Dependency dependency, boolean hasClassifier) {
Artifact artifact = artifactFactory.createProjectArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
StringBuilder licensesBuffer = new StringBuilder();
String url = null;
try {
VersionRange range = VersionRange.createFromVersionSpec(dependency.getVersion());
if (range.getRecommendedVersion() == null) {
// MPIR-216: no direct version but version range: need to choose one precise version
log.debug("Resolving range for DependencyManagement on " + artifact.getId());
List<ArtifactVersion> versions = artifactMetadataSource.retrieveAvailableVersions(artifact, localRepository, remoteRepositories);
// only use versions from range
for (Iterator<ArtifactVersion> iter = versions.iterator(); iter.hasNext(); ) {
if (!range.containsVersion(iter.next())) {
iter.remove();
}
}
// select latest, assuming pom information will be the most accurate
if (versions.size() > 0) {
ArtifactVersion maxArtifactVersion = Collections.max(versions);
artifact.setVersion(maxArtifactVersion.toString());
log.debug("DependencyManagement resolved: " + artifact.getId());
}
}
url = ProjectInfoReportUtils.getArtifactUrl(artifactFactory, artifact, mavenProjectBuilder, remoteRepositories, localRepository);
MavenProject artifactProject = repoUtils.getMavenProjectFromRepository(artifact);
List<License> licenses = artifactProject.getLicenses();
for (License license : licenses) {
String licenseCell = ProjectInfoReportUtils.getArtifactIdCell(license.getName(), license.getUrl());
if (licensesBuffer.length() > 0) {
licensesBuffer.append(", ");
}
licensesBuffer.append(licenseCell);
}
} catch (InvalidVersionSpecificationException e) {
log.warn("Unable to parse version for " + artifact.getId(), e);
} catch (ArtifactMetadataRetrievalException e) {
log.warn("Unable to retrieve versions for " + artifact.getId() + " from repository.", e);
} catch (ProjectBuildingException e) {
log.warn("Unable to create Maven project for " + artifact.getId() + " from repository.", e);
}
String artifactIdCell = ProjectInfoReportUtils.getArtifactIdCell(artifact.getArtifactId(), url);
if (hasClassifier) {
return new String[] { dependency.getGroupId(), artifactIdCell, dependency.getVersion(), dependency.getClassifier(), dependency.getType(), licensesBuffer.toString() };
}
return new String[] { dependency.getGroupId(), artifactIdCell, dependency.getVersion(), dependency.getType(), licensesBuffer.toString() };
}
use of org.apache.maven.artifact.versioning.ArtifactVersion in project sling by apache.
the class AbstractBundleListMojo method getArtifact.
/**
* Get a resolved Artifact from the coordinates provided
*
* @return the artifact, which has been resolved.
* @throws MojoExecutionException
*/
protected Artifact getArtifact(String groupId, String artifactId, String version, String type, String classifier) throws MojoExecutionException {
Artifact artifact;
VersionRange vr;
try {
vr = VersionRange.createFromVersionSpec(version);
} catch (InvalidVersionSpecificationException e) {
vr = VersionRange.createFromVersion(version);
}
if (StringUtils.isEmpty(classifier)) {
artifact = factory.createDependencyArtifact(groupId, artifactId, vr, type, null, Artifact.SCOPE_COMPILE);
} else {
artifact = factory.createDependencyArtifact(groupId, artifactId, vr, type, classifier, Artifact.SCOPE_COMPILE);
}
// This code kicks in when the version specifier is a range.
if (vr.getRecommendedVersion() == null) {
try {
List<ArtifactVersion> availVersions = metadataSource.retrieveAvailableVersions(artifact, local, remoteRepos);
ArtifactVersion resolvedVersion = vr.matchVersion(availVersions);
artifact.setVersion(resolvedVersion.toString());
} catch (ArtifactMetadataRetrievalException e) {
throw new MojoExecutionException("Unable to find version for artifact", e);
}
}
try {
resolver.resolve(artifact, remoteRepos, local);
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException("Unable to resolve artifact.", e);
} catch (ArtifactNotFoundException e) {
throw new MojoExecutionException("Unable to find artifact.", e);
}
return artifact;
}
Aggregations