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.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 * Caches plugin class realms. <strong>Warning:</strong> This is an internal utility interface that is only public for
34 * technical reasons, it is not part of the public API. In particular, this interface can be changed or deleted without
35 * prior notice.
36 *
37 * @author Igor Fedorenko
38 * @author Benjamin Bentmann
39 */
40 public interface PluginRealmCache {
41 /**
42 * CacheRecord
43 */
44 class CacheRecord {
45 public ClassRealm getRealm() {
46 return realm;
47 }
48
49 public List<Artifact> getArtifacts() {
50 return artifacts;
51 }
52
53 private final ClassRealm realm;
54
55 private final List<Artifact> artifacts;
56
57 public CacheRecord(ClassRealm realm, List<Artifact> artifacts) {
58 this.realm = realm;
59 this.artifacts = artifacts;
60 }
61 }
62
63 /**
64 * A cache key.
65 */
66 interface Key {
67 // marker interface for cache keys
68 }
69
70 Key createKey(
71 Plugin plugin,
72 ClassLoader parentRealm,
73 Map<String, ClassLoader> foreignImports,
74 DependencyFilter dependencyFilter,
75 List<RemoteRepository> repositories,
76 RepositorySystemSession session);
77
78 CacheRecord get(Key key);
79
80 CacheRecord put(Key key, ClassRealm pluginRealm, List<Artifact> pluginArtifacts);
81
82 void flush();
83
84 /**
85 * Registers the specified cache record for usage with the given project. Integrators can use the information
86 * collected from this method in combination with a custom cache implementation to dispose unused records from the
87 * cache.
88 *
89 * @param project The project that employs the plugin realm, must not be {@code null}.
90 * @param record The cache record being used for the project, must not be {@code null}.
91 */
92 void register(MavenProject project, Key key, CacheRecord record);
93 }