Search in sources :

Example 21 with ArtifactResolutionException

use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project maven-dependency-plugin by apache.

the class PurgeLocalRepositoryMojo method reResolveArtifacts.

private void reResolveArtifacts(MavenProject theProject, 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(), theProject.getArtifact(), theProject.getRemoteArtifactRepositories());
    }
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact)

Example 22 with ArtifactResolutionException

use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project maven-dependency-plugin by apache.

the class PurgeLocalRepositoryMojo method purgeLocalRepository.

/**
 * Purges the local repository for the dependencies in the given Maven project.
 *
 * @param theProject Maven project.
 * @param resolvedArtifactsToPurge The artifacts that were already purged.
 * @throws MojoFailureException in case of errors during the purge.
 */
private void purgeLocalRepository(MavenProject theProject, Set<Artifact> purgedArtifacts) throws MojoFailureException {
    List<Dependency> dependencies = theProject.getDependencies();
    TransformableFilter dependencyFilter = createPurgeArtifactsFilter(theProject, dependencies, purgedArtifacts);
    Set<Artifact> resolvedArtifactsToPurge = getFilteredResolvedArtifacts(theProject, dependencies, dependencyFilter);
    if (resolvedArtifactsToPurge.isEmpty()) {
        getLog().info("No artifacts included for purge for project: " + theProject.getId());
        return;
    }
    verbose("Purging dependencies for project: " + theProject.getId());
    purgeArtifacts(resolvedArtifactsToPurge);
    purgedArtifacts.addAll(resolvedArtifactsToPurge);
    if (reResolve) {
        ArtifactFilter artifactFilter = dependencyFilter.transform(new ArtifactIncludeFilterTransformer());
        try {
            reResolveArtifacts(theProject, resolvedArtifactsToPurge, artifactFilter);
        } catch (ArtifactResolutionException e) {
            String failureMessage = "Failed to refresh project dependencies for: " + theProject.getId();
            MojoFailureException failure = new MojoFailureException(failureMessage);
            failure.initCause(e);
            throw failure;
        } catch (ArtifactNotFoundException e) {
            String failureMessage = "Failed to refresh project dependencies for: " + theProject.getId();
            MojoFailureException failure = new MojoFailureException(failureMessage);
            failure.initCause(e);
            throw failure;
        }
    }
}
Also used : ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) TransformableFilter(org.apache.maven.shared.artifact.filter.resolve.TransformableFilter) ArtifactIncludeFilterTransformer(org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Dependency(org.apache.maven.model.Dependency) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) Artifact(org.apache.maven.artifact.Artifact)

Example 23 with ArtifactResolutionException

use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project m2e-nar by maven-nar.

the class AbstractDependencyMojo method downloadAttachedNars.

@SuppressWarnings("deprecation")
public final void downloadAttachedNars(final List<AttachedNarArtifact> dependencies) throws MojoExecutionException, MojoFailureException {
    getLog().debug("Download for NarDependencies {");
    for (final AttachedNarArtifact attachedNarArtifact : dependencies) {
        getLog().debug("  - " + attachedNarArtifact);
    }
    getLog().debug("}");
    for (final AttachedNarArtifact attachedNarArtifact : dependencies) {
        try {
            getLog().debug("Resolving " + attachedNarArtifact);
            this.artifactResolver.resolve(attachedNarArtifact, this.remoteArtifactRepositories, getLocalRepository());
        } catch (final ArtifactNotFoundException e) {
            final String message = "nar not found " + attachedNarArtifact.getId();
            throw new MojoExecutionException(message, e);
        } catch (final ArtifactResolutionException e) {
            final String message = "nar cannot resolve " + attachedNarArtifact.getId();
            throw new MojoExecutionException(message, e);
        }
    }
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException)

Example 24 with ArtifactResolutionException

use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project tomee by apache.

the class AbstractTomEEMojo method getAdditionalClasspath.

/**
 * Gets additional classpath.
 *
 * @return the additional classpath
 */
protected String getAdditionalClasspath() {
    if (!classpaths.isEmpty()) {
        final StringBuilder cpBuilder = new StringBuilder();
        for (final String cp : classpaths) {
            final String[] split = cp.split(":");
            if (split.length >= 3) /*GAV*/
            {
                final FileWithMavenMeta jar;
                try {
                    jar = resolve(split[0], split[1], split[2], split.length > 4 ? split[4] : null, split.length > 3 ? split[3] : "jar");
                } catch (final ArtifactResolutionException | ArtifactNotFoundException e) {
                    throw new IllegalArgumentException(e);
                }
                final File classpathRoot = new File(catalinaBase, "boot");
                if (!classpathRoot.isDirectory()) {
                    mkdirs(classpathRoot);
                }
                final File target = new File(classpathRoot, stripVersion ? jar.stripVersion(true) : jar.resolved.getName());
                try {
                    IO.copy(jar.resolved, target);
                } catch (final IOException e) {
                    throw new IllegalArgumentException(e);
                }
                cpBuilder.append("${openejb.base}/boot/").append(target.getName());
            } else {
                // else plain path
                cpBuilder.append(cp);
            }
            if (classpathSeparator == null) {
                classpathSeparator = File.pathSeparator;
            }
            cpBuilder.append(classpathSeparator);
        }
        // Dump the final path separator
        return cpBuilder.substring(0, cpBuilder.length() - 1);
    }
    return null;
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) IOException(java.io.IOException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 25 with ArtifactResolutionException

use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project tycho by eclipse.

the class TychoOsgiRuntimeLocator method resolveDependency.

public Artifact resolveDependency(MavenSession session, Dependency dependency) throws MavenExecutionException {
    Artifact artifact = repositorySystem.createArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getType());
    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);
    request.setResolveRoot(true).setResolveTransitively(false);
    request.setLocalRepository(session.getLocalRepository());
    request.setRemoteRepositories(getPluginRepositories(session));
    request.setCache(session.getRepositoryCache());
    request.setOffline(session.isOffline());
    request.setProxies(session.getSettings().getProxies());
    request.setForceUpdate(session.getRequest().isUpdateSnapshots());
    ArtifactResolutionResult result = repositorySystem.resolve(request);
    try {
        resolutionErrorHandler.throwErrors(request, result);
    } catch (ArtifactResolutionException e) {
        throw new MavenExecutionException("Could not resolve artifact for Tycho's OSGi runtime", e);
    }
    return artifact;
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MavenExecutionException(org.apache.maven.MavenExecutionException) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)35 Artifact (org.apache.maven.artifact.Artifact)27 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)27 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)15 ArrayList (java.util.ArrayList)12 File (java.io.File)10 IOException (java.io.IOException)8 ArtifactIncludeFilterTransformer (org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer)7 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)6 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)5 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)5 MojoFailureException (org.apache.maven.plugin.MojoFailureException)5 TransformableFilter (org.apache.maven.shared.artifact.filter.resolve.TransformableFilter)5 VersionRange (org.apache.maven.artifact.versioning.VersionRange)4 Dependency (org.apache.maven.model.Dependency)4 HashMap (java.util.HashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 ArtifactMetadataRetrievalException (org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)3 MavenProject (org.apache.maven.project.MavenProject)3 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)3