View Javadoc
1   package org.apache.maven.reporting.exec;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import javax.inject.Inject;
23  import javax.inject.Named;
24  import javax.inject.Singleton;
25  
26  import java.util.List;
27  
28  import org.apache.maven.execution.MavenSession;
29  import org.apache.maven.model.Plugin;
30  import org.apache.maven.plugin.InvalidPluginDescriptorException;
31  import org.apache.maven.plugin.MavenPluginManager;
32  import org.apache.maven.plugin.PluginContainerException;
33  import org.apache.maven.plugin.PluginDescriptorParsingException;
34  import org.apache.maven.plugin.PluginResolutionException;
35  import org.apache.maven.plugin.descriptor.PluginDescriptor;
36  import org.eclipse.aether.RepositorySystemSession;
37  import org.eclipse.aether.graph.DependencyFilter;
38  import org.eclipse.aether.repository.RemoteRepository;
39  import org.eclipse.aether.util.filter.ExclusionsDependencyFilter;
40  
41  import static java.util.Objects.requireNonNull;
42  
43  /**
44   * <p>DefaultMavenPluginManagerHelper class.</p>
45   */
46  @Singleton
47  @Named
48  public class DefaultMavenPluginManagerHelper
49      implements MavenPluginManagerHelper
50  {
51      private final MavenPluginManager mavenPluginManager;
52  
53      @Inject
54      public DefaultMavenPluginManagerHelper( MavenPluginManager mavenPluginManager )
55      {
56          this.mavenPluginManager = requireNonNull( mavenPluginManager );
57      }
58  
59      private DependencyFilter createExclusionsDependencyFilter( List<String> artifactIdsList )
60      {
61          return new ExclusionsDependencyFilter( artifactIdsList );
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public PluginDescriptor getPluginDescriptor( Plugin plugin, MavenSession session )
67          throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException
68      {
69          RepositorySystemSession repositorySystemSession = session.getRepositorySession();
70          List<RemoteRepository> remoteRepositories = session.getCurrentProject().getRemotePluginRepositories();
71  
72          return mavenPluginManager.getPluginDescriptor( plugin, remoteRepositories, repositorySystemSession );
73      }
74  
75      /** {@inheritDoc} */
76      @Override
77      public void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,
78                                    List<String> imports, List<String> excludeArtifactIds )
79          throws PluginResolutionException, PluginContainerException
80      {
81          mavenPluginManager.setupPluginRealm(
82              pluginDescriptor, session, parent, imports, createExclusionsDependencyFilter( excludeArtifactIds ) );
83      }
84  }