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.model.DependencyManagement;
22 import org.apache.maven.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 * @deprecated use {@code org.apache.maven.api.services.ModelBuilder} instead
30 */
31 @Deprecated(since = "4.0.0")
32 interface ModelCacheTag<T> {
33
34 /**
35 * Gets the name of the tag.
36 *
37 * @return The name of the tag, must not be {@code null}.
38 */
39 String getName();
40
41 /**
42 * Gets the type of data associated with this tag.
43 *
44 * @return The type of data, must not be {@code null}.
45 */
46 Class<T> getType();
47
48 /**
49 * Creates a copy of the data suitable for storage in the cache. The original data to store can be mutated after the
50 * cache is populated but the state of the cache must not change so we need to make a copy.
51 *
52 * @param data The data to store in the cache, must not be {@code null}.
53 * @return The data being stored in the cache, never {@code null}.
54 */
55 T intoCache(T data);
56
57 /**
58 * Creates a copy of the data suitable for retrieval from the cache. The retrieved data can be mutated after the
59 * cache is queried but the state of the cache must not change so we need to make a copy.
60 *
61 * @param data The data to retrieve from the cache, must not be {@code null}.
62 * @return The data being retrieved from the cache, never {@code null}.
63 */
64 T fromCache(T data);
65
66 /**
67 * The tag used to denote raw model data.
68 */
69 ModelCacheTag<ModelData> RAW = new ModelCacheTag<ModelData>() {
70
71 @Override
72 public String getName() {
73 return "raw";
74 }
75
76 @Override
77 public Class<ModelData> getType() {
78 return ModelData.class;
79 }
80
81 @Override
82 public ModelData intoCache(ModelData data) {
83 Model model = (data.getModel() != null) ? data.getModel().clone() : null;
84 return new ModelData(data.getSource(), model, data.getGroupId(), data.getArtifactId(), data.getVersion());
85 }
86
87 @Override
88 public ModelData fromCache(ModelData data) {
89 return intoCache(data);
90 }
91 };
92
93 /**
94 * The tag used to denote an effective dependency management section from an imported model.
95 */
96 ModelCacheTag<DependencyManagement> IMPORT = new ModelCacheTag<DependencyManagement>() {
97
98 @Override
99 public String getName() {
100 return "import";
101 }
102
103 @Override
104 public Class<DependencyManagement> getType() {
105 return DependencyManagement.class;
106 }
107
108 @Override
109 public DependencyManagement intoCache(DependencyManagement data) {
110 return (data != null) ? data.clone() : null;
111 }
112
113 @Override
114 public DependencyManagement fromCache(DependencyManagement data) {
115 return intoCache(data);
116 }
117 };
118 }