use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project maven-plugins by apache.
the class AbstractJavadocMojo method getDependencySourcePaths.
/**
* Resolve dependency sources so they can be included directly in the javadoc process. To customize this,
* override {@link AbstractJavadocMojo#configureDependencySourceResolution(SourceResolverConfig)}.
* @return List of source paths.
* @throws MavenReportException {@link MavenReportException}
*/
protected final List<String> getDependencySourcePaths() throws MavenReportException {
try {
if (sourceDependencyCacheDir.exists()) {
FileUtils.forceDelete(sourceDependencyCacheDir);
sourceDependencyCacheDir.mkdirs();
}
} catch (IOException e) {
throw new MavenReportException("Failed to delete cache directory: " + sourceDependencyCacheDir + "\nReason: " + e.getMessage(), e);
}
final SourceResolverConfig config = getDependencySourceResolverConfig();
final List<TransformableFilter> andFilters = new ArrayList<TransformableFilter>();
final List<String> dependencyIncludes = dependencySourceIncludes;
final List<String> dependencyExcludes = dependencySourceExcludes;
if (!includeTransitiveDependencySources || isNotEmpty(dependencyIncludes) || isNotEmpty(dependencyExcludes)) {
if (!includeTransitiveDependencySources) {
andFilters.add(createDependencyArtifactFilter());
}
if (isNotEmpty(dependencyIncludes)) {
andFilters.add(new PatternInclusionsFilter(dependencyIncludes));
}
if (isNotEmpty(dependencyExcludes)) {
andFilters.add(new PatternExclusionsFilter(dependencyExcludes));
}
config.withFilter(new AndFilter(andFilters));
}
try {
return resourceResolver.resolveDependencySourcePaths(config);
} catch (final ArtifactResolutionException e) {
throw new MavenReportException("Failed to resolve one or more javadoc source/resource artifacts:\n\n" + e.getMessage(), e);
} catch (final ArtifactNotFoundException e) {
throw new MavenReportException("Failed to resolve one or more javadoc source/resource artifacts:\n\n" + e.getMessage(), e);
}
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project maven-plugins by apache.
the class PurgeLocalRepositoryMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (isSkip()) {
getLog().info("Skipping plugin execution");
return;
}
if (!StringUtils.isEmpty(manualInclude)) {
manualIncludes = this.parseIncludes(manualInclude);
}
// If it's a manual purge, the only step is to delete from the local repo
if (manualIncludes != null && manualIncludes.size() > 0) {
manualPurge(manualIncludes);
return;
}
Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
TransformableFilter dependencyFilter = createPurgeArtifactsFilter(dependencyArtifacts);
Set<Artifact> resolvedArtifactsToPurge = getFilteredResolvedArtifacts(project, dependencyArtifacts, dependencyFilter);
if (resolvedArtifactsToPurge.isEmpty()) {
getLog().info("No artifacts included for purge for project: " + project.getId());
return;
}
verbose("Purging dependencies for project: " + project.getId());
purgeArtifacts(resolvedArtifactsToPurge);
if (reResolve) {
ArtifactFilter artifactFilter = dependencyFilter.transform(new ArtifactIncludeFilterTransformer());
try {
reResolveArtifacts(project, resolvedArtifactsToPurge, artifactFilter);
} catch (ArtifactResolutionException e) {
String failureMessage = "Failed to refresh project dependencies for: " + project.getId();
MojoFailureException failure = new MojoFailureException(failureMessage);
failure.initCause(e);
throw failure;
} catch (ArtifactNotFoundException e) {
String failureMessage = "Failed to refresh project dependencies for: " + project.getId();
MojoFailureException failure = new MojoFailureException(failureMessage);
failure.initCause(e);
throw failure;
}
}
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project sling by apache.
the class ModelUtils method getArtifact.
/**
* Get a resolved Artifact from the coordinates provided
*
* @return the artifact, which has been resolved.
* @throws MojoExecutionException
*/
public static Artifact getArtifact(final MavenProject project, final MavenSession session, final ArtifactHandlerManager artifactHandlerManager, final ArtifactResolver resolver, final String groupId, final String artifactId, final String version, final String type, final String classifier) throws MojoExecutionException {
final Set<Artifact> artifacts = project.getDependencyArtifacts();
for (final Artifact artifact : artifacts) {
if (artifact.getGroupId().equals(groupId) && artifact.getArtifactId().equals(artifactId) && artifact.getVersion().equals(version) && artifact.getType().equals(type) && ((classifier == null && artifact.getClassifier() == null) || (classifier != null && classifier.equals(artifact.getClassifier())))) {
return artifact;
}
}
final Artifact prjArtifact = new DefaultArtifact(groupId, artifactId, VersionRange.createFromVersion(version), Artifact.SCOPE_PROVIDED, type, classifier, artifactHandlerManager.getArtifactHandler(type));
try {
resolver.resolve(prjArtifact, project.getRemoteArtifactRepositories(), session.getLocalRepository());
} catch (final ArtifactResolutionException e) {
throw new MojoExecutionException("Unable to get artifact for " + groupId + ":" + artifactId + ":" + version, e);
} catch (final ArtifactNotFoundException e) {
throw new MojoExecutionException("Unable to get artifact for " + groupId + ":" + artifactId + ":" + version, e);
}
return prjArtifact;
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionException 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;
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project felix by apache.
the class AbstractBaselinePlugin method getPreviousArtifact.
private Artifact getPreviousArtifact() throws MojoFailureException, MojoExecutionException {
// Find the previous version JAR and resolve it, and it's dependencies
final VersionRange range;
try {
range = VersionRange.createFromVersionSpec(comparisonVersion);
} catch (InvalidVersionSpecificationException e) {
throw new MojoFailureException("Invalid comparison version: " + e.getMessage());
}
final Artifact previousArtifact;
try {
previousArtifact = factory.createDependencyArtifact(comparisonGroupId, comparisonArtifactId, range, comparisonPackaging, comparisonClassifier, Artifact.SCOPE_COMPILE);
if (!previousArtifact.getVersionRange().isSelectedVersionKnown(previousArtifact)) {
getLog().debug("Searching for versions in range: " + previousArtifact.getVersionRange());
@SuppressWarnings("unchecked") List<ArtifactVersion> // type is konwn
availableVersions = metadataSource.retrieveAvailableVersions(previousArtifact, session.getLocalRepository(), project.getRemoteArtifactRepositories());
filterSnapshots(availableVersions);
ArtifactVersion version = range.matchVersion(availableVersions);
if (version != null) {
previousArtifact.selectVersion(version.toString());
}
}
} catch (OverConstrainedVersionException ocve) {
throw new MojoFailureException("Invalid comparison version: " + ocve.getMessage());
} catch (ArtifactMetadataRetrievalException amre) {
throw new MojoExecutionException("Error determining previous version: " + amre.getMessage(), amre);
}
if (previousArtifact.getVersion() == null) {
getLog().info("Unable to find a previous version of the project in the repository");
return null;
}
try {
resolver.resolve(previousArtifact, project.getRemoteArtifactRepositories(), session.getLocalRepository());
} catch (ArtifactResolutionException are) {
throw new MojoExecutionException("Artifact " + previousArtifact + " cannot be resolved : " + are.getMessage(), are);
} catch (ArtifactNotFoundException anfe) {
throw new MojoExecutionException("Artifact " + previousArtifact + " does not exist on local/remote repositories", anfe);
}
return previousArtifact;
}
Aggregations