use of org.apache.maven.artifact.versioning.InvalidVersionSpecificationException 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.InvalidVersionSpecificationException 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