1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin;
20
21 import java.util.List;
22 import java.util.Map;
23
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.model.Plugin;
26 import org.apache.maven.project.MavenProject;
27 import org.codehaus.plexus.classworlds.realm.ClassRealm;
28 import org.eclipse.aether.RepositorySystemSession;
29 import org.eclipse.aether.graph.DependencyFilter;
30 import org.eclipse.aether.repository.RemoteRepository;
31
32
33
34
35
36
37
38 public interface PluginRealmCache {
39
40
41
42 class CacheRecord {
43 public ClassRealm getRealm() {
44 return realm;
45 }
46
47 public List<Artifact> getArtifacts() {
48 return artifacts;
49 }
50
51 private final ClassRealm realm;
52
53 private final List<Artifact> artifacts;
54
55 public CacheRecord(ClassRealm realm, List<Artifact> artifacts) {
56 this.realm = realm;
57 this.artifacts = artifacts;
58 }
59 }
60
61
62
63
64 interface Key {
65
66 }
67
68 @FunctionalInterface
69 interface PluginRealmSupplier {
70 CacheRecord load() throws PluginResolutionException, PluginContainerException;
71 }
72
73 Key createKey(
74 Plugin plugin,
75 ClassLoader parentRealm,
76 Map<String, ClassLoader> foreignImports,
77 DependencyFilter dependencyFilter,
78 List<RemoteRepository> repositories,
79 RepositorySystemSession session);
80
81 CacheRecord get(Key key);
82
83 default CacheRecord get(Key key, PluginRealmSupplier supplier)
84 throws PluginResolutionException, PluginContainerException {
85 CacheRecord cr = get(key);
86 if (cr == null) {
87 CacheRecord tcr = supplier.load();
88 cr = put(key, tcr.getRealm(), tcr.getArtifacts());
89 }
90 return cr;
91 }
92
93 CacheRecord put(Key key, ClassRealm pluginRealm, List<Artifact> pluginArtifacts);
94
95 void flush();
96
97
98
99
100
101
102
103
104
105 void register(MavenProject project, Key key, CacheRecord record);
106 }