View Javadoc
1   package org.apache.maven.model.building;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.building.Source;
23  
24  /**
25   * Caches auxiliary data used during model building like already processed raw/effective models. The data in the cache
26   * is meant for exclusive consumption by the model builder and is opaque to the cache implementation. The cache key is
27   * formed by a combination of group id, artifact id, version and tag. The first three components generally refer to the
28   * identify of a model. The tag allows for further classification of the associated data on the sole discretion of the
29   * model builder.
30   *
31   * @author Benjamin Bentmann
32   * @author Robert Scholte
33   */
34  public interface ModelCache
35  {
36      /**
37       * Puts the specified data into the cache.
38       *
39       * @param path The path of the cache record, must not be {@code null}.
40       * @param tag The tag of the cache record, must not be {@code null}.
41       * @param data The data to store in the cache, must not be {@code null}.
42       * @since 4.0.0
43       */
44      default void put( Source path, String tag, Object data )
45      {
46          // only useful for ReactorModelCache
47      }
48  
49      /**
50       * Gets the specified data from the cache.
51       *
52       * @param path The path of the cache record, must not be {@code null}.
53       * @param tag The tag of the cache record, must not be {@code null}.
54       * @return The requested data or {@code null} if none was present in the cache.
55       * @since 4.0.0
56       */
57      default Object get( Source path, String tag )
58      {
59          // only useful for ReactorModelCache
60          return null;
61      }
62  
63      /**
64       * Puts the specified data into the cache.
65       *
66       * @param groupId The group id of the cache record, must not be {@code null}.
67       * @param artifactId The artifact id of the cache record, must not be {@code null}.
68       * @param version The version of the cache record, must not be {@code null}.
69       * @param tag The tag of the cache record, must not be {@code null}.
70       * @param data The data to store in the cache, must not be {@code null}.
71       */
72      void put( String groupId, String artifactId, String version, String tag, Object data );
73  
74      /**
75       * Gets the specified data from the cache.
76       *
77       * @param groupId The group id of the cache record, must not be {@code null}.
78       * @param artifactId The artifact id of the cache record, must not be {@code null}.
79       * @param version The version of the cache record, must not be {@code null}.
80       * @param tag The tag of the cache record, must not be {@code null}.
81       * @return The requested data or {@code null} if none was present in the cache.
82       */
83      Object get( String groupId, String artifactId, String version, String tag );
84  
85      /**
86       * Puts the specified data into the cache.
87       *
88       * @param path The path of the cache record, must not be {@code null}.
89       * @param tag The tag of the cache record, must not be {@code null}.
90       * @param data The data to store in the cache, must not be {@code null}.
91       * @since 4.0.0
92       */
93      default <T> void put( Source path, ModelCacheTag<T> tag, T data )
94      {
95          put( path, tag.getName(), tag.intoCache( data ) );
96      }
97  
98      /**
99       * Gets the specified data from the cache.
100      *
101      * @param path The path of the cache record, must not be {@code null}.
102      * @param tag The tag of the cache record, must not be {@code null}.
103      * @return The requested data or {@code null} if none was present in the cache.
104      * @since 4.0.0
105      */
106     default <T> T get( Source path, ModelCacheTag<T> tag )
107     {
108         Object obj = get( path, tag.getName() );
109         return ( obj != null ) ? tag.fromCache( tag.getType().cast( obj ) ) : null;
110     }
111 
112     /**
113      * Puts the specified data into the cache.
114      *
115      * @param groupId The group id of the cache record, must not be {@code null}.
116      * @param artifactId The artifact id of the cache record, must not be {@code null}.
117      * @param version The version of the cache record, must not be {@code null}.
118      * @param tag The tag of the cache record, must not be {@code null}.
119      * @param data The data to store in the cache, must not be {@code null}.
120      */
121     default <T> void put( String groupId, String artifactId, String version, ModelCacheTag<T> tag, T data )
122     {
123         put( groupId, artifactId, version, tag.getName(), tag.intoCache( data ) );
124     }
125 
126     /**
127      * Gets the specified data from the cache.
128      *
129      * @param groupId The group id of the cache record, must not be {@code null}.
130      * @param artifactId The artifact id of the cache record, must not be {@code null}.
131      * @param version The version of the cache record, must not be {@code null}.
132      * @param tag The tag of the cache record, must not be {@code null}.
133      * @return The requested data or {@code null} if none was present in the cache.
134      */
135     default <T> T get( String groupId, String artifactId, String version, ModelCacheTag<T> tag )
136     {
137         Object obj = get( groupId, artifactId, version, tag.getName() );
138         return ( obj != null ) ? tag.fromCache( tag.getType().cast( obj ) ) : null;
139     }
140 
141 }