Java 类org.apache.maven.project.DependencyResolutionException 实例源码

项目:incubator-taverna-osgi    文件:MavenOsgiUtils.java   
public Set<BundleArtifact> getBundleDependencies(String... scopes)
        throws MojoExecutionException {
    ScopeDependencyFilter scopeFilter = new ScopeDependencyFilter(Arrays.asList(scopes), null);

    DefaultDependencyResolutionRequest dependencyResolutionRequest = new DefaultDependencyResolutionRequest(
            project, repositorySystemSession);
    dependencyResolutionRequest.setResolutionFilter(scopeFilter);

    DependencyResolutionResult dependencyResolutionResult;
    try {
        dependencyResolutionResult = projectDependenciesResolver
                .resolve(dependencyResolutionRequest);
    } catch (DependencyResolutionException ex) {
        throw new MojoExecutionException(ex.getMessage(), ex);
    }

    DependencyNode dependencyGraph = dependencyResolutionResult.getDependencyGraph();
    if (dependencyGraph != null) {
        checkBundleDependencies(dependencyGraph.getChildren());
        return getBundleArtifacts(dependencyGraph.getChildren());
    } else {
        return new HashSet<BundleArtifact>();
    }
}
项目:license-audit-maven-plugin    文件:AbstractLicensingMojo.java   
protected void resolveDependencies() throws MojoExecutionException {
    DependencyResolutionResult depRes;
    try {
        DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession(mavenSession.getRepositorySession());
        ((DefaultRepositorySystemSession)repositorySession).setDependencySelector(newRootScopeDependencySelector(repositorySession.getDependencySelector(), 0));
        DefaultDependencyResolutionRequest depReq = new DefaultDependencyResolutionRequest(project, repositorySession);
        depRes = depsResolver.resolve(depReq);
    } catch (DependencyResolutionException e) {
        throw new MojoExecutionException("Cannot resolve dependencies for "+project, e);
    }
    rootDependencyGraph = depRes.getDependencyGraph();
    getLog().debug("Dependency graph with scopes "+includeDependencyScopes+":");
    dump("", rootDependencyGraph);

    projectByIdCache.put(Coords.of(project).normal(), project);
    collectDeps(rootDependencyGraph, project, 0);
}
项目:oceano    文件:ProjectDependenciesResolverStub.java   
public DependencyResolutionResult resolve( DependencyResolutionRequest request )
    throws DependencyResolutionException
{
    return new DependencyResolutionResult()
    {

        public List<Dependency> getUnresolvedDependencies()
        {
            return Collections.emptyList();
        }

        public List<Dependency> getResolvedDependencies()
        {
            return Collections.emptyList();
        }

        public List<Exception> getResolutionErrors( Dependency dependency )
        {
            return Collections.emptyList();
        }

        public DependencyNode getDependencyGraph()
        {
            return new DefaultDependencyNode( (Dependency) null );
        }

        public List<Dependency> getDependencies()
        {
            return Collections.emptyList();
        }

        public List<Exception> getCollectionErrors()
        {
            return Collections.emptyList();
        }
    };
}
项目:maven-parallel-resolver    文件:SynchronizedProjectDependenciesResolver.java   
public DependencyResolutionResult resolve( DependencyResolutionRequest request )
    throws DependencyResolutionException
{
    synchronized ( SynchronizedProjectDependenciesResolver.class )
    {
        return super.resolve( request );
    }
}
项目:gitflow-helper-maven-plugin    文件:UpdateStageDependenciesMojo.java   
@Override
protected void execute(GitBranchType type, String gitBranch, String branchPattern) throws MojoExecutionException, MojoFailureException {
    getLog().debug("update-stage-dependencies setting up Repository session...");

    DefaultRepositorySystemSession reresolveSession = new DefaultRepositorySystemSession(session);
    reresolveSession.setUpdatePolicy(org.eclipse.aether.repository.RepositoryPolicy.UPDATE_POLICY_ALWAYS);
    reresolveSession.setCache(new DefaultRepositoryCache());

    LocalRepositoryManager localRepositoryManager = reresolveSession.getLocalRepositoryManager();

    getLog().debug("configuring stage as the remote repository for artifact resolution requests...");
    List<RemoteRepository> stageRepo = Arrays.asList(getRepository(stageDeploymentRepository));

    boolean itemsPurged = false;

    try {
        DependencyResolutionResult depencencyResult = dependenciesResolver.resolve(
                new DefaultDependencyResolutionRequest(project, reresolveSession));

        for (Dependency dependency : depencencyResult.getResolvedDependencies()) {
            if (!dependency.getArtifact().isSnapshot()) {
                // Find the artifact in the local repo, and if it came from the 'stageRepo', populate that info
                // as the 'repository' on the artifact.
                LocalArtifactResult localResult = localRepositoryManager.find(reresolveSession,
                        new LocalArtifactRequest(dependency.getArtifact(), stageRepo, null));

                // If the result has a file... and the getRepository() matched the stage repo id...
                if (localResult.getFile() != null && localResult.getRepository() != null) {
                    getLog().info("Purging: " + dependency + " from remote repository: " + localResult.getRepository() + ".");
                    File deleteTarget = new File(localRepositoryManager.getRepository().getBasedir(), localRepositoryManager.getPathForLocalArtifact(dependency.getArtifact()));

                    if (deleteTarget.isDirectory()) {
                        try {
                            FileUtils.deleteDirectory(deleteTarget);
                        } catch (IOException ioe) {
                            getLog().warn("Failed to purge stage artifact from local repository: " + deleteTarget, ioe);
                        }
                    } else if (!deleteTarget.delete()) {
                        getLog().warn("Failed to purge stage artifact from local repository: " + deleteTarget);
                    }
                    itemsPurged = true;
                }
            }
        }
    } catch (DependencyResolutionException dre) {
        throw new MojoExecutionException("Initial dependency resolution to resolve dependencies which may have been provided by the 'stage' repository failed.", dre);
    }


    if (itemsPurged) {
        try {
            getLog().info("Resolving purged dependencies...");
            dependenciesResolver.resolve(new DefaultDependencyResolutionRequest(project, reresolveSession));
            getLog().info("All stage dependencies purged and re-resolved.");
        } catch (DependencyResolutionException e) {
            throw new MojoExecutionException("Post-purge dependency resolution failed!", e);
        }
    }
}
项目:oceano    文件:LifecycleDependencyResolver.java   
private Set<Artifact> getDependencies( MavenProject project, Collection<String> scopesToCollect,
                                       Collection<String> scopesToResolve, MavenSession session,
                                       boolean aggregating, Set<Artifact> projectArtifacts )
    throws LifecycleExecutionException
{
    if ( scopesToCollect == null )
    {
        scopesToCollect = Collections.emptySet();
    }
    if ( scopesToResolve == null )
    {
        scopesToResolve = Collections.emptySet();
    }

    if ( scopesToCollect.isEmpty() && scopesToResolve.isEmpty() )
    {
        return new LinkedHashSet<Artifact>();
    }

    scopesToCollect = new HashSet<String>( scopesToCollect );
    scopesToCollect.addAll( scopesToResolve );

    DependencyFilter collectionFilter = new ScopeDependencyFilter( null, negate( scopesToCollect ) );
    DependencyFilter resolutionFilter = new ScopeDependencyFilter( null, negate( scopesToResolve ) );
    resolutionFilter = AndDependencyFilter.newInstance( collectionFilter, resolutionFilter );
    resolutionFilter =
        AndDependencyFilter.newInstance( resolutionFilter, new ReactorDependencyFilter( projectArtifacts ) );

    DependencyResolutionResult result;
    try
    {
        DefaultDependencyResolutionRequest request =
            new DefaultDependencyResolutionRequest( project, session.getRepositorySession() );
        request.setResolutionFilter( resolutionFilter );

        eventSpyDispatcher.onEvent( request );

        result = dependenciesResolver.resolve( request );
    }
    catch ( DependencyResolutionException e )
    {
        result = e.getResult();

        /*
         * MNG-2277, the check below compensates for our bad plugin support where we ended up with aggregator
         * plugins that require dependency resolution although they usually run in phases of the build where project
         * artifacts haven't been assembled yet. The prime example of this is "mvn release:prepare".
         */
        if ( aggregating && areAllDependenciesInReactor( session.getProjects(), result.getUnresolvedDependencies() ) )
        {
            logger.warn( "The following dependencies could not be resolved at this point of the build"
                + " but seem to be part of the reactor:" );

            for ( Dependency dependency : result.getUnresolvedDependencies() )
            {
                logger.warn( "o " + dependency );
            }

            logger.warn( "Try running the build up to the lifecycle phase \"package\"" );
        }
        else
        {
            throw new LifecycleExecutionException( null, project, e );
        }
    }

    eventSpyDispatcher.onEvent( result );

    Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
    if ( result.getDependencyGraph() != null && !result.getDependencyGraph().getChildren().isEmpty() )
    {
        RepositoryUtils.toArtifacts( artifacts, result.getDependencyGraph().getChildren(),
                                     Collections.singletonList( project.getArtifact().getId() ), collectionFilter );
    }
    return artifacts;
}