Example usage for org.apache.maven.project DependencyResolutionResult getResolutionErrors

List of usage examples for org.apache.maven.project DependencyResolutionResult getResolutionErrors

Introduction

In this page you can find the example usage for org.apache.maven.project DependencyResolutionResult getResolutionErrors.

Prototype

List<Exception> getResolutionErrors(Dependency dependency);

Source Link

Document

Gets the errors that occurred while resolving the specified dependency.

Usage

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

License:Open Source License

public void addMarkers(IResource pomResource, String type, MavenExecutionResult result) {
    SourceLocation defaultSourceLocation = new SourceLocation(1, 0, 0);
    List<MavenProblemInfo> allProblems = new ArrayList<MavenProblemInfo>();

    allProblems.addAll(toMavenProblemInfos(pomResource, defaultSourceLocation, result.getExceptions()));

    MavenProject mavenProject = result.getProject();
    DependencyResolutionResult resolutionResult = result.getDependencyResolutionResult();
    if (resolutionResult != null) {
        allProblems.addAll(toMavenProblemInfos(pomResource, defaultSourceLocation,
                resolutionResult.getCollectionErrors()));
        for (org.sonatype.aether.graph.Dependency dependency : resolutionResult.getUnresolvedDependencies()) {
            List<Exception> exceptions = resolutionResult.getResolutionErrors(dependency);
            if (exceptions != null && exceptions.size() > 0) {
                SourceLocation sourceLocation = SourceLocationHelper.findLocation(mavenProject, dependency);
                allProblems.addAll(toMavenProblemInfos(pomResource, sourceLocation, exceptions));
            }/*  www.ja va  2  s .  com*/
        }
    }

    if (mavenProject != null) {
        addMissingArtifactProblemInfos(mavenProject, defaultSourceLocation, allProblems);
    }

    addErrorMarkers(pomResource, type, allProblems);
}

From source file:org.springframework.cloud.function.compiler.java.DependencyResolver.java

License:Apache License

public List<Dependency> dependencies(final Resource resource, final Properties properties) {
    initialize();//from  w  w  w .j a v a2s .  co m
    try {
        ProjectBuildingRequest request = getProjectBuildingRequest(properties);
        request.setResolveDependencies(true);
        synchronized (DependencyResolver.class) {
            ProjectBuildingResult result = this.projectBuilder
                    .build(new PropertiesModelSource(properties, resource), request);
            DependencyResolver.globals = null;
            DependencyResolutionResult dependencies = result.getDependencyResolutionResult();
            if (!dependencies.getUnresolvedDependencies().isEmpty()) {
                StringBuilder builder = new StringBuilder();
                for (Dependency dependency : dependencies.getUnresolvedDependencies()) {
                    List<Exception> errors = dependencies.getResolutionErrors(dependency);
                    for (Exception exception : errors) {
                        if (builder.length() > 0) {
                            builder.append("\n");
                        }
                        builder.append(exception.getMessage());
                    }
                }
                throw new RuntimeException(builder.toString());
            }
            return runtime(dependencies.getDependencies());
        }
    } catch (ProjectBuildingException | NoLocalRepositoryManagerException e) {
        throw new IllegalStateException("Cannot build model", e);
    }
}