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