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.api.model.DependencyManagement; 23 import org.apache.maven.api.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 for the raw model without profile activation 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 return data; 89 } 90 91 @Override 92 public ModelData fromCache( ModelData data ) 93 { 94 return data; 95 } 96 97 }; 98 99 /** 100 * The tag used to denote an effective dependency management section from an imported model. 101 */ 102 ModelCacheTag<DependencyManagement> IMPORT = new ModelCacheTag<DependencyManagement>() 103 { 104 105 @Override 106 public String getName() 107 { 108 return "import"; 109 } 110 111 @Override 112 public Class<DependencyManagement> getType() 113 { 114 return DependencyManagement.class; 115 } 116 117 @Override 118 public DependencyManagement intoCache( DependencyManagement data ) 119 { 120 return data; 121 } 122 123 @Override 124 public DependencyManagement fromCache( DependencyManagement data ) 125 { 126 return data; 127 } 128 129 }; 130 131 /** 132 * The tag used for the file model without profile activation 133 * @since 4.0.0 134 */ 135 ModelCacheTag<Model> FILE = new ModelCacheTag<Model>() 136 { 137 @Override 138 public String getName() 139 { 140 return "file"; 141 } 142 143 @Override 144 public Class<Model> getType() 145 { 146 return Model.class; 147 } 148 149 @Override 150 public Model intoCache( Model data ) 151 { 152 return data; 153 } 154 155 @Override 156 public Model fromCache( Model data ) 157 { 158 return data; 159 } 160 }; 161 }