Example usage for org.apache.maven.artifact.resolver ArtifactNotFoundException getArtifact

List of usage examples for org.apache.maven.artifact.resolver ArtifactNotFoundException getArtifact

Introduction

In this page you can find the example usage for org.apache.maven.artifact.resolver ArtifactNotFoundException getArtifact.

Prototype

public Artifact getArtifact() 

Source Link

Usage

From source file:org.codehaus.mojo.license.api.DefaultThirdPartyTool.java

License:Open Source License

/**
 * @param project         not null/*from ww w .  j av a  2 s  .  c o  m*/
 * @param localRepository not null
 * @param repositories    not null
 * @return the resolved site descriptor
 * @throws IOException                 if any
 * @throws ArtifactResolutionException if any
 * @throws ArtifactNotFoundException   if any
 */
private File resolveThirdPartyDescriptor(MavenProject project, ArtifactRepository localRepository,
        List<ArtifactRepository> repositories)
        throws IOException, ArtifactResolutionException, ArtifactNotFoundException {
    File result;
    try {
        result = resolveArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(),
                DESCRIPTOR_TYPE, DESCRIPTOR_CLASSIFIER, localRepository, repositories);

        // we use zero length files to avoid re-resolution (see below)
        if (result.length() == 0) {
            getLogger().debug("Skipped third party descriptor");
        }
    } catch (ArtifactNotFoundException e) {
        getLogger().debug("Unable to locate third party files descriptor : " + e);

        // we can afford to write an empty descriptor here as we don't expect it to turn up later in the remote
        // repository, because the parent was already released (and snapshots are updated automatically if changed)
        result = new File(localRepository.getBasedir(), localRepository.pathOf(e.getArtifact()));

        FileUtil.createNewFile(result);
    }

    return result;
}

From source file:org.eclipse.m2e.core.internal.markers.MavenMarkerManager.java

License:Open Source License

private List<MavenProblemInfo> toMavenProblemInfos(IResource pomResource, SourceLocation location,
        List<? extends Throwable> exceptions) {
    List<MavenProblemInfo> result = new ArrayList<MavenProblemInfo>();
    if (exceptions == null) {
        return result;
    }/*  ww  w.  j a  v  a 2  s.  c o m*/

    for (Throwable ex : exceptions) {
        if (ex instanceof org.sonatype.aether.transfer.ArtifactNotFoundException) {
            org.sonatype.aether.transfer.ArtifactNotFoundException artifactNotFoundException = (org.sonatype.aether.transfer.ArtifactNotFoundException) ex;
            ArtifactNotFoundProblemInfo problem = new ArtifactNotFoundProblemInfo(
                    artifactNotFoundException.getArtifact(), mavenConfiguration.isOffline(), location);
            result.add(problem);
        } else if (ex instanceof AbstractArtifactResolutionException) {
            AbstractArtifactResolutionException abstractArtifactResolutionException = (AbstractArtifactResolutionException) ex;
            String errorMessage = getArtifactId(abstractArtifactResolutionException) + " " //$NON-NLS-1$
                    + getRootErrorMessage(ex);
            result.add(new MavenProblemInfo(errorMessage, location));
        } else if (ex instanceof ProjectBuildingException) {
            Throwable cause = ex.getCause();
            if (cause instanceof ModelBuildingException) {
                ModelBuildingException mbe = (ModelBuildingException) cause;
                for (ModelProblem problem : mbe.getProblems()) {
                    String message = NLS.bind(Messages.pluginMarkerBuildError, problem.getMessage());
                    int severity = (Severity.WARNING == problem.getSeverity()) ? IMarker.SEVERITY_WARNING
                            : IMarker.SEVERITY_ERROR;
                    SourceLocation problemLocation = SourceLocationHelper.findLocation(pomResource, problem);
                    result.add(new MavenProblemInfo(message, severity, problemLocation));
                }
            } else {
                result.add(new MavenProblemInfo(getErrorMessage(ex), location));
            }
        } else {
            result.add(new MavenProblemInfo(getErrorMessage(ex), location));
        }
    }

    return result;
}