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