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