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 public String getName() 74 { 75 return "raw"; 76 } 77 78 public Class<ModelData> getType() 79 { 80 return ModelData.class; 81 } 82 83 public ModelData intoCache( ModelData data ) 84 { 85 Model model = ( data.getModel() != null ) ? data.getModel().clone() : null; 86 return new ModelData( model, data.getGroupId(), data.getArtifactId(), data.getVersion() ); 87 } 88 89 public ModelData fromCache( ModelData data ) 90 { 91 return intoCache( data ); 92 } 93 94 }; 95 96 /** 97 * The tag used to denote an effective dependency management section from an imported model. 98 */ 99 ModelCacheTag<DependencyManagement> IMPORT = new ModelCacheTag<DependencyManagement>() 100 { 101 102 public String getName() 103 { 104 return "import"; 105 } 106 107 public Class<DependencyManagement> getType() 108 { 109 return DependencyManagement.class; 110 } 111 112 public DependencyManagement intoCache( DependencyManagement data ) 113 { 114 return ( data != null ) ? data.clone() : null; 115 }; 116 117 public DependencyManagement fromCache( DependencyManagement data ) 118 { 119 return intoCache( data ); 120 }; 121 122 }; 123 124 }