Search in sources :

Example 16 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException 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;
        }
    }
}
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) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) Artifact(org.apache.maven.artifact.Artifact)

Example 17 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException 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;
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MavenProject(org.apache.maven.project.MavenProject) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) DoapArtifact(org.apache.maven.plugin.doap.options.DoapArtifact) Artifact(org.apache.maven.artifact.Artifact)

Example 18 with ArtifactNotFoundException

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

the class AbstractTomEEMojo method getAdditionalClasspath.

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 19 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException 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;
}
Also used : ArtifactMetadataRetrievalException(org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) VersionRange(org.apache.maven.artifact.versioning.VersionRange) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) Artifact(org.apache.maven.artifact.Artifact)

Example 20 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException 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;
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Aggregations

ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)20 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)20 Artifact (org.apache.maven.artifact.Artifact)15 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 File (java.io.File)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)2 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)2 ArtifactMetadataRetrievalException (org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)2 SnapshotArtifactRepositoryMetadata (org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata)2 AbstractArtifactResolutionException (org.apache.maven.artifact.resolver.AbstractArtifactResolutionException)2 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)2 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)2 VersionRange (org.apache.maven.artifact.versioning.VersionRange)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 MavenProject (org.apache.maven.project.MavenProject)2 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)2 MavenReportException (org.apache.maven.reporting.MavenReportException)2 TransformableFilter (org.apache.maven.shared.artifact.filter.resolve.TransformableFilter)2