Skip to content

Commit 2ac2957

Browse files
committed
[MNG-8239] Missing ModelCacheFactory and introduce ModelBuilderSession
1 parent 8506d62 commit 2ac2957

File tree

18 files changed

+833
-661
lines changed

18 files changed

+833
-661
lines changed

api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderRequest.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ enum RepositoryMerging {
134134
@Nonnull
135135
RepositoryMerging getRepositoryMerging();
136136

137-
@Nullable
138-
ModelCache getModelCache();
139-
140137
@Nullable
141138
Object getListener();
142139

@@ -194,7 +191,6 @@ class ModelBuilderRequestBuilder {
194191
ModelResolver modelResolver;
195192
Object modelRepositoryHolder;
196193
RepositoryMerging repositoryMerging;
197-
ModelCache modelCache;
198194
Object listener;
199195
ModelBuilderResult interimResult;
200196
List<RemoteRepository> repositories;
@@ -215,7 +211,6 @@ class ModelBuilderRequestBuilder {
215211
this.modelResolver = request.getModelResolver();
216212
this.modelRepositoryHolder = request.getModelRepositoryHolder();
217213
this.repositoryMerging = request.getRepositoryMerging();
218-
this.modelCache = request.getModelCache();
219214
this.listener = request.getListener();
220215
this.interimResult = request.getInterimResult();
221216
this.repositories = request.getRepositories();
@@ -286,11 +281,6 @@ public ModelBuilderRequestBuilder repositoryMerging(RepositoryMerging repository
286281
return this;
287282
}
288283

289-
public ModelBuilderRequestBuilder modelCache(ModelCache modelCache) {
290-
this.modelCache = modelCache;
291-
return this;
292-
}
293-
294284
public ModelBuilderRequestBuilder listener(Object listener) {
295285
this.listener = listener;
296286
return this;
@@ -321,7 +311,6 @@ public ModelBuilderRequest build() {
321311
modelResolver,
322312
modelRepositoryHolder,
323313
repositoryMerging,
324-
modelCache,
325314
listener,
326315
interimResult,
327316
repositories);
@@ -340,7 +329,6 @@ private static class DefaultModelBuilderRequest extends BaseRequest implements M
340329
private final ModelResolver modelResolver;
341330
private final Object modelRepositoryHolder;
342331
private final RepositoryMerging repositoryMerging;
343-
private final ModelCache modelCache;
344332
private final Object listener;
345333
private final ModelBuilderResult interimResult;
346334
private final List<RemoteRepository> repositories;
@@ -360,7 +348,6 @@ private static class DefaultModelBuilderRequest extends BaseRequest implements M
360348
ModelResolver modelResolver,
361349
Object modelRepositoryHolder,
362350
RepositoryMerging repositoryMerging,
363-
ModelCache modelCache,
364351
Object listener,
365352
ModelBuilderResult interimResult,
366353
List<RemoteRepository> repositories) {
@@ -378,7 +365,6 @@ private static class DefaultModelBuilderRequest extends BaseRequest implements M
378365
this.modelResolver = modelResolver;
379366
this.modelRepositoryHolder = modelRepositoryHolder;
380367
this.repositoryMerging = repositoryMerging;
381-
this.modelCache = modelCache;
382368
this.listener = listener;
383369
this.interimResult = interimResult;
384370
this.repositories = repositories != null ? List.copyOf(repositories) : null;
@@ -445,11 +431,6 @@ public RepositoryMerging getRepositoryMerging() {
445431
return repositoryMerging;
446432
}
447433

448-
@Override
449-
public ModelCache getModelCache() {
450-
return modelCache;
451-
}
452-
453434
public Object getListener() {
454435
return listener;
455436
}

api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelCache.java renamed to maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelCache.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,33 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.apache.maven.api.services;
19+
package org.apache.maven.api.services.model;
2020

2121
import java.util.function.Supplier;
2222

23+
import org.apache.maven.api.annotations.Experimental;
24+
import org.apache.maven.api.annotations.ThreadSafe;
25+
import org.apache.maven.api.services.Source;
26+
2327
/**
2428
* Caches auxiliary data used during model building like already processed raw/effective models. The data in the cache
2529
* is meant for exclusive consumption by the model builder and is opaque to the cache implementation. The cache key is
26-
* formed by a combination of group id, artifact id, version and tag. The first three components generally refer to the
27-
* identity of a model. The tag allows for further classification of the associated data on the sole discretion of the
28-
* model builder.
30+
* formed by a combination of group id, artifact id, version and tag, or by the pom path on the filesystem and tag.
31+
* The tag allows for further classification of the associated data on the sole discretion of the model builder.
32+
* The cache is expected to be valid through the lifetime of the session, so the model builder is not allowed to
33+
* store data which may change during the session, especially effective models which may be different if the
34+
* user properties or activate profiles change between two invocations of the model builder.
35+
* The cache implementation is expected to be thread-safe.
2936
*
37+
* @since 4.0.0
3038
*/
39+
@Experimental
40+
@ThreadSafe
3141
public interface ModelCache {
3242

3343
<T> T computeIfAbsent(String groupId, String artifactId, String version, String tag, Supplier<T> data);
3444

3545
<T> T computeIfAbsent(Source path, String tag, Supplier<T> data);
46+
47+
void clear();
3648
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.api.services.model;
20+
21+
import org.apache.maven.api.annotations.Experimental;
22+
import org.apache.maven.api.annotations.Nonnull;
23+
24+
/**
25+
* Factory for creating model caches.
26+
* <p>
27+
* The model cache is meant for exclusive consumption by the model builder and is opaque to the cache implementation.
28+
* The cache is created once per session and is valid through the lifetime of the session.
29+
* <p>
30+
* The cache implementation could be annotated with {@code SessionScoped} to be created once per session, but
31+
* this would make tests more complicated to write as they would all need to enter the session scope.
32+
* This is similar to the {@code CIFriendlyVersionModelTransformer}.
33+
*
34+
* @since 4.0.0
35+
*/
36+
@Experimental
37+
public interface ModelCacheFactory {
38+
39+
@Nonnull
40+
ModelCache newInstance();
41+
}

0 commit comments

Comments
 (0)