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.project.artifact;
20  
21  import java.util.Collection;
22  import java.util.Set;
23  import org.apache.maven.artifact.Artifact;
24  import org.apache.maven.lifecycle.LifecycleExecutionException;
25  import org.apache.maven.project.MavenProject;
26  import org.eclipse.aether.RepositorySystemSession;
27  
28  /**
29   * Caches project artifacts. <strong>Warning:</strong> This is an internal utility interface that is only public for
30   * technical reasons, it is not part of the public API. In particular, this interface can be changed or deleted without
31   * prior notice.
32   *
33   * @author Igor Fedorenko
34   * @author Benjamin Bentmann
35   * @author Anton Tanasenko
36   */
37  public interface ProjectArtifactsCache {
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          public Set<Artifact> getArtifacts() {
52              return artifacts;
53          }
54  
55          private final Set<Artifact> artifacts;
56  
57          public LifecycleExecutionException getException() {
58              return exception;
59          }
60  
61          private final LifecycleExecutionException exception;
62  
63          CacheRecord(Set<Artifact> artifacts) {
64              this.artifacts = artifacts;
65              this.exception = null;
66          }
67  
68          CacheRecord(LifecycleExecutionException exception) {
69              this.artifacts = null;
70              this.exception = exception;
71          }
72      }
73  
74      Key createKey(
75              MavenProject project,
76              Collection<String> scopesToCollect,
77              Collection<String> scopesToResolve,
78              boolean aggregating,
79              RepositorySystemSession session);
80  
81      CacheRecord get(Key key) throws LifecycleExecutionException;
82  
83      CacheRecord put(Key key, Set<Artifact> pluginArtifacts);
84  
85      CacheRecord put(Key key, LifecycleExecutionException e);
86  
87      void flush();
88  
89      /**
90       * Registers the specified cache record for usage with the given project. Integrators can use the information
91       * collected from this method in combination with a custom cache implementation to dispose unused records from the
92       * cache.
93       *
94       * @param project The project that employs the plugin realm, must not be {@code null}.
95       * @param record The cache record being used for the project, must not be {@code null}.
96       */
97      void register(MavenProject project, Key cacheKey, CacheRecord record);
98  }