Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.apache.maven.plugin.internal;
  
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
  *
  *   http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
  */
 
 import java.util.List;
 import java.util.Map;
 
Assists in resolving the dependencies of a plugin. Warning: This is an internal utility class that is only public for technical reasons, it is not part of the public API. In particular, this class can be changed or deleted without prior notice.

Author(s):
Benjamin Bentmann
Since:
3.0
 
     implements PluginDependenciesResolver
 {
 
     private static final String REPOSITORY_CONTEXT = "plugin";
 
     @Requirement
     private Logger logger;
 
     @Requirement
 
     @Requirement
     private RepositorySystem repoSystem;
 
     private Artifact toArtifactPlugin pluginRepositorySystemSession session )
     {
         return new DefaultArtifactplugin.getGroupId(), plugin.getArtifactId(), null"jar"plugin.getVersion(),
                                     session.getArtifactTypeRegistry().get"maven-plugin" ) );
     }
 
     public Artifact resolvePlugin pluginList<RemoteRepositoryrepositoriesRepositorySystemSession session )
         throws PluginResolutionException
     {
         RequestTrace trace = RequestTrace.newChildnullplugin );
 
         Artifact pluginArtifact = toArtifactpluginsession );
 
        try
        {
            DefaultRepositorySystemSession pluginSession = new DefaultRepositorySystemSessionsession );
            pluginSession.setArtifactDescriptorPolicynew SimpleArtifactDescriptorPolicytruefalse ) );
            ArtifactDescriptorRequest request =
                new ArtifactDescriptorRequestpluginArtifactrepositories );
            request.setTracetrace );
            ArtifactDescriptorResult result = .readArtifactDescriptorpluginSessionrequest );
            pluginArtifact = result.getArtifact();
            String requiredMavenVersion = (Stringresult.getProperties().get"prerequisites.maven" );
            if ( requiredMavenVersion != null )
            {
                Map<StringStringprops = new LinkedHashMap<StringString>( pluginArtifact.getProperties() );
                props.put"requiredMavenVersion"requiredMavenVersion );
                pluginArtifact = pluginArtifact.setPropertiesprops );
            }
        }
        catch ( ArtifactDescriptorException e )
        {
            throw new PluginResolutionExceptionplugine );
        }
        try
        {
            ArtifactRequest request = new ArtifactRequestpluginArtifactrepositories );
            request.setTracetrace );
            pluginArtifact = .resolveArtifactsessionrequest ).getArtifact();
        }
        catch ( ArtifactResolutionException e )
        {
            throw new PluginResolutionExceptionplugine );
        }
        return pluginArtifact;
    }
    public DependencyNode resolvePlugin pluginArtifact pluginArtifactDependencyFilter dependencyFilter,
                                   List<RemoteRepositoryrepositoriesRepositorySystemSession session )
        throws PluginResolutionException
    {
        RequestTrace trace = RequestTrace.newChildnullplugin );
        if ( pluginArtifact == null )
        {
            pluginArtifact = toArtifactpluginsession );
        }
        DependencyFilter collectionFilter = new ScopeDependencyFilter"provided""test" );
        DependencyFilter resolutionFilter =
        resolutionFilter = AndDependencyFilter.newInstanceresolutionFilterdependencyFilter );
        resolutionFilter = new AndDependencyFiltercollectionFilterresolutionFilter );
        DependencyNode node;
        try
        {
            DependencySelector selector =
                AndDependencySelector.newInstancesession.getDependencySelector(), new WagonExcluder() );
            DependencyGraphTransformer transformer =
                ChainedDependencyGraphTransformer.newInstancesession.getDependencyGraphTransformer(),
                                                               new PlexusUtilsInjector() );
            DefaultRepositorySystemSession pluginSession = new DefaultRepositorySystemSessionsession );
            pluginSession.setDependencySelectorselector );
            pluginSession.setDependencyGraphTransformertransformer );
            CollectRequest request = new CollectRequest();
            request.setRequestContext );
            request.setRepositoriesrepositories );
            request.setRootnew org.eclipse.aether.graph.DependencypluginArtifactnull ) );
            for ( Dependency dependency : plugin.getDependencies() )
            {
                org.eclipse.aether.graph.Dependency pluginDep =
                    RepositoryUtils.toDependencydependencysession.getArtifactTypeRegistry() );
                if ( !..equalspluginDep.getScope() ) )
                {
                    pluginDep = pluginDep.setScope. );
                }
                request.addDependencypluginDep );
            }
            DependencyRequest depRequest = new DependencyRequestrequestresolutionFilter );
            depRequest.setTracetrace );
            request.setTrace( RequestTrace.newChildtracedepRequest ) );
            node = .collectDependenciespluginSessionrequest ).getRoot();
            if ( .isDebugEnabled() )
            {
                node.acceptnew GraphLogger() );
            }
            depRequest.setRootnode );
            .resolveDependenciessessiondepRequest );
        }
        catch ( DependencyCollectionException e )
        {
            throw new PluginResolutionExceptionplugine );
        }
        catch ( DependencyResolutionException e )
        {
            throw new PluginResolutionExceptionplugine.getCause() );
        }
        return node;
    }
    class GraphLogger
        implements DependencyVisitor
    {
        private String indent = "";
        public boolean visitEnterDependencyNode node )
        {
            StringBuilder buffer = new StringBuilder( 128 );
            buffer.append );
            org.eclipse.aether.graph.Dependency dep = node.getDependency();
            if ( dep != null )
            {
                org.eclipse.aether.artifact.Artifact art = dep.getArtifact();
                buffer.appendart );
                buffer.append':' ).appenddep.getScope() );
            }
            .debugbuffer.toString() );
             += "   ";
            return true;
        }
        public boolean visitLeaveDependencyNode node )
        {
             = .substring( 0, .length() - 3 );
            return true;
        }
    }
New to GrepCode? Check out our FAQ X