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