use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project tycho by eclipse.
the class TestMojo method getFrameworkExtensions.
private List<File> getFrameworkExtensions() throws MojoExecutionException {
List<File> files = new ArrayList<>();
if (frameworkExtensions != null) {
for (Dependency frameworkExtension : frameworkExtensions) {
Artifact artifact = repositorySystem.createDependencyArtifact(frameworkExtension);
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(artifact);
request.setResolveRoot(true).setResolveTransitively(false);
request.setLocalRepository(session.getLocalRepository());
// XXX wrong repositories -- these are user artifacts, not plugin artifacts
request.setRemoteRepositories(project.getPluginArtifactRepositories());
request.setOffline(session.isOffline());
request.setForceUpdate(session.getRequest().isUpdateSnapshots());
ArtifactResolutionResult result = repositorySystem.resolve(request);
try {
resolutionErrorHandler.throwErrors(request, result);
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException("Failed to resolve framework extension " + frameworkExtension.getManagementKey(), e);
}
files.add(artifact.getFile());
}
}
return files;
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project maven-plugins by apache.
the class DoapMojo method getMavenProject.
// ----------------------------------------------------------------------
// Private methods
// ----------------------------------------------------------------------
/**
* @param artifact not null
* @return the maven project for the given doap artifact
* @since 1.1
*/
private MavenProject getMavenProject(DoapArtifact artifact) {
if (artifact == null) {
return null;
}
if (StringUtils.isEmpty(artifact.getGroupId()) || StringUtils.isEmpty(artifact.getArtifactId()) || StringUtils.isEmpty(artifact.getVersion())) {
getLog().warn("Missing groupId or artifactId or version in <artifact/> parameter, ignored it.");
return null;
}
getLog().info("Using artifact " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion());
try {
Artifact art = factory.createProjectArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), Artifact.SCOPE_COMPILE);
if (art.getFile() == null) {
MavenProject proj = mavenProjectBuilder.buildFromRepository(art, remoteRepositories, localRepository);
art = proj.getArtifact();
resolver.resolve(art, remoteRepositories, localRepository);
return proj;
}
} catch (ArtifactResolutionException e) {
getLog().error("ArtifactResolutionException: " + e.getMessage() + "\nIgnored <artifact/> parameter.");
} catch (ArtifactNotFoundException e) {
getLog().error("ArtifactNotFoundException: " + e.getMessage() + "\nIgnored <artifact/> parameter.");
} catch (ProjectBuildingException e) {
getLog().error("ProjectBuildingException: " + e.getMessage() + "\nIgnored <artifact/> parameter.");
}
return null;
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project maven-plugins by apache.
the class PurgeLocalRepositoryMojo method reResolveArtifacts.
private void reResolveArtifacts(MavenProject project, Set<Artifact> artifacts, ArtifactFilter filter) throws ArtifactResolutionException, ArtifactNotFoundException {
// because Maven 2 will not automatically re-resolve them when resolving the artifact
for (Artifact artifact : artifacts) {
try {
// CHECKSTYLE_OFF: LineLength
artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), org.apache.maven.shared.artifact.TransferUtils.toArtifactCoordinate(artifact));
// CHECKSTYLE_ON: LineLength
} catch (ArtifactResolverException e) {
verbose(e.getMessage());
}
}
List<Artifact> missingArtifacts = new ArrayList<Artifact>();
for (Artifact artifact : artifacts) {
verbose("Resolving artifact: " + artifact.getId());
try {
artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), artifact);
} catch (ArtifactResolverException e) {
verbose(e.getMessage());
missingArtifacts.add(artifact);
}
}
if (missingArtifacts.size() > 0) {
StringBuffer message = new StringBuffer("required artifacts missing:\n");
for (Artifact missingArtifact : missingArtifacts) {
message.append(" ").append(missingArtifact.getId()).append('\n');
}
message.append("\nfor the artifact:");
throw new ArtifactResolutionException(message.toString(), project.getArtifact(), project.getRemoteArtifactRepositories());
}
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project maven-plugins by apache.
the class PurgeLocalRepositoryMojo method purgeLocalRepository.
/**
* Purges the local repository for the dependencies in the given Maven project.
*
* @param project Maven project.
* @param resolvedArtifactsToPurge The artifacts that were already purged.
* @throws MojoFailureException in case of errors during the purge.
*/
private void purgeLocalRepository(MavenProject project, Set<Artifact> purgedArtifacts) throws MojoFailureException {
List<Dependency> dependencies = project.getDependencies();
TransformableFilter dependencyFilter = createPurgeArtifactsFilter(project, dependencies, purgedArtifacts);
Set<Artifact> resolvedArtifactsToPurge = getFilteredResolvedArtifacts(project, dependencies, 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);
purgedArtifacts.addAll(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 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 Map<String, Collection<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<>();
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);
}
}
Aggregations