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  
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.lifecycle.LifecycleExecutionException;
26  import org.apache.maven.project.MavenProject;
27  import org.eclipse.aether.RepositorySystemSession;
28  
29  /**
30   * Caches project 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   * @author Anton Tanasenko
37   */
38  public interface ProjectArtifactsCache {
39  
40      /**
41       * A cache key.
42       */
43      interface Key {
44          // marker interface for cache keys
45      }
46  
47      /**
48       * CacheRecord
49       */
50      class CacheRecord {
51  
52          public Set<Artifact> getArtifacts() {
53              return artifacts;
54          }
55  
56          private final Set<Artifact> artifacts;
57  
58          public LifecycleExecutionException getException() {
59              return exception;
60          }
61  
62          private final LifecycleExecutionException exception;
63  
64          CacheRecord(Set<Artifact> artifacts) {
65              this.artifacts = artifacts;
66              this.exception = null;
67          }
68  
69          CacheRecord(LifecycleExecutionException exception) {
70              this.artifacts = null;
71              this.exception = exception;
72          }
73      }
74  
75      Key createKey(
76              MavenProject project,
77              Collection<String> scopesToCollect,
78              Collection<String> scopesToResolve,
79              boolean aggregating,
80              RepositorySystemSession session);
81  
82      CacheRecord get(Key key) throws LifecycleExecutionException;
83  
84      CacheRecord put(Key key, Set<Artifact> pluginArtifacts);
85  
86      CacheRecord put(Key key, LifecycleExecutionException e);
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 cacheKey, CacheRecord record);
99  }