1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
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
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
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 }