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.model.DependencyManagement;
23  import org.apache.maven.model.Model;
24  
25  /**
26   * Describes a tag used by the model builder to access a {@link ModelCache}. This interface basically aggregates a name
27   * and a class to provide some type safety when working with the otherwise untyped cache.
28   *
29   * @author Benjamin Bentmann
30   * @param <T> The type of data associated with the tag.
31   */
32  interface ModelCacheTag<T>
33  {
34  
35      /**
36       * Gets the name of the tag.
37       *
38       * @return The name of the tag, must not be {@code null}.
39       */
40      String getName();
41  
42      /**
43       * Gets the type of data associated with this tag.
44       *
45       * @return The type of data, must not be {@code null}.
46       */
47      Class<T> getType();
48  
49      /**
50       * Creates a copy of the data suitable for storage in the cache. The original data to store can be mutated after the
51       * cache is populated but the state of the cache must not change so we need to make a copy.
52       *
53       * @param data The data to store in the cache, must not be {@code null}.
54       * @return The data being stored in the cache, never {@code null}.
55       */
56      T intoCache( T data );
57  
58      /**
59       * Creates a copy of the data suitable for retrieval from the cache. The retrieved data can be mutated after the
60       * cache is queried but the state of the cache must not change so we need to make a copy.
61       *
62       * @param data The data to retrieve from the cache, must not be {@code null}.
63       * @return The data being retrieved from the cache, never {@code null}.
64       */
65      T fromCache( T data );
66  
67      /**
68       * The tag used to denote raw model data.
69       */
70      ModelCacheTag<ModelData> RAW = new ModelCacheTag<ModelData>()
71      {
72  
73          @Override
74          public String getName()
75          {
76              return "raw";
77          }
78  
79          @Override
80          public Class<ModelData> getType()
81          {
82              return ModelData.class;
83          }
84  
85          @Override
86          public ModelData intoCache( ModelData data )
87          {
88              Model model = ( data.getModel() != null ) ? data.getModel().clone() : null;
89              return new ModelData( data.getSource(), model, data.getGroupId(), data.getArtifactId(), data.getVersion() );
90          }
91  
92          @Override
93          public ModelData fromCache( ModelData data )
94          {
95              return intoCache( data );
96          }
97  
98      };
99  
100     /**
101      * The tag used to denote an effective dependency management section from an imported model.
102      */
103     ModelCacheTag<DependencyManagement> IMPORT = new ModelCacheTag<DependencyManagement>()
104     {
105 
106         @Override
107         public String getName()
108         {
109             return "import";
110         }
111 
112         @Override
113         public Class<DependencyManagement> getType()
114         {
115             return DependencyManagement.class;
116         }
117 
118         @Override
119         public DependencyManagement intoCache( DependencyManagement data )
120         {
121             return ( data != null ) ? data.clone() : null;
122         }
123 
124         @Override
125         public DependencyManagement fromCache( DependencyManagement data )
126         {
127             return intoCache( data );
128         }
129 
130     };
131 
132 }