Skip to content

Commit 1bb46cd

Browse files
committed
Move Features to the api
1 parent c5b4ace commit 1bb46cd

File tree

5 files changed

+75
-86
lines changed

5 files changed

+75
-86
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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.feature;
20+
21+
import java.util.Map;
22+
import java.util.Properties;
23+
24+
import org.apache.maven.api.Session;
25+
import org.apache.maven.api.annotations.Nullable;
26+
27+
/**
28+
* Centralized class for feature information
29+
*
30+
* @since 4.0.0
31+
*/
32+
public final class Features {
33+
34+
public static final String BUILDCONSUMER = "maven.experimental.buildconsumer";
35+
36+
private Features() {}
37+
38+
public static boolean buildConsumer(@Nullable Properties userProperties) {
39+
return doGet(userProperties, BUILDCONSUMER, true);
40+
}
41+
42+
public static boolean buildConsumer(@Nullable Map<String, String> userProperties) {
43+
return doGet(userProperties, BUILDCONSUMER, true);
44+
}
45+
46+
public static boolean buildConsumer(@Nullable Session session) {
47+
return buildConsumer(session != null ? session.getUserProperties() : null);
48+
}
49+
50+
private static boolean doGet(Properties userProperties, String key, boolean def) {
51+
return doGet(userProperties != null ? userProperties.get(key) : null, def);
52+
}
53+
54+
private static boolean doGet(Map<String, ?> userProperties, String key, boolean def) {
55+
return doGet(userProperties != null ? userProperties.get(key) : null, def);
56+
}
57+
58+
private static boolean doGet(Object val, boolean def) {
59+
if (val instanceof Boolean) {
60+
return (Boolean) val;
61+
} else if (val != null) {
62+
return Boolean.parseBoolean(val.toString());
63+
} else {
64+
return def;
65+
}
66+
}
67+
}

maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
import java.util.stream.Collectors;
3939

4040
import org.apache.maven.api.Repository;
41+
import org.apache.maven.api.feature.Features;
4142
import org.apache.maven.api.model.DistributionManagement;
4243
import org.apache.maven.api.model.Model;
4344
import org.apache.maven.api.model.ModelBase;
4445
import org.apache.maven.api.model.Profile;
45-
import org.apache.maven.feature.Features;
4646
import org.apache.maven.model.building.FileModelSource;
4747
import org.apache.maven.model.building.ModelBuilder;
4848
import org.apache.maven.model.building.ModelBuildingRequest;
@@ -95,7 +95,7 @@ public void injectTransformedArtifacts(MavenProject project, RepositorySystemSes
9595
// If there is no build POM there is no reason to inject artifacts for the consumer POM.
9696
return;
9797
}
98-
if (isActive(session)) {
98+
if (Features.buildConsumer(session.getUserProperties())) {
9999
Path buildDir =
100100
project.getBuild() != null ? Paths.get(project.getBuild().getDirectory()) : null;
101101
if (buildDir != null) {
@@ -134,23 +134,19 @@ private void doDeleteFiles() {
134134
}
135135

136136
public InstallRequest remapInstallArtifacts(RepositorySystemSession session, InstallRequest request) {
137-
if (isActive(session) && consumerPomPresent(request.getArtifacts())) {
137+
if (Features.buildConsumer(session.getUserProperties()) && consumerPomPresent(request.getArtifacts())) {
138138
request.setArtifacts(replacePom(request.getArtifacts()));
139139
}
140140
return request;
141141
}
142142

143143
public DeployRequest remapDeployArtifacts(RepositorySystemSession session, DeployRequest request) {
144-
if (isActive(session) && consumerPomPresent(request.getArtifacts())) {
144+
if (Features.buildConsumer(session.getUserProperties()) && consumerPomPresent(request.getArtifacts())) {
145145
request.setArtifacts(replacePom(request.getArtifacts()));
146146
}
147147
return request;
148148
}
149149

150-
private boolean isActive(RepositorySystemSession session) {
151-
return Features.buildConsumer(session.getUserProperties()).isActive();
152-
}
153-
154150
private boolean consumerPomPresent(Collection<Artifact> artifacts) {
155151
return artifacts.stream()
156152
.anyMatch(a -> "pom".equals(a.getExtension()) && CONSUMER_POM_CLASSIFIER.equals(a.getClassifier()));

maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
import java.util.stream.Collectors;
3939

4040
import org.apache.maven.RepositoryUtils;
41+
import org.apache.maven.api.feature.Features;
4142
import org.apache.maven.artifact.Artifact;
4243
import org.apache.maven.artifact.InvalidArtifactRTException;
4344
import org.apache.maven.artifact.InvalidRepositoryException;
4445
import org.apache.maven.artifact.repository.ArtifactRepository;
4546
import org.apache.maven.bridge.MavenRepositorySystem;
46-
import org.apache.maven.feature.Features;
4747
import org.apache.maven.model.Build;
4848
import org.apache.maven.model.Dependency;
4949
import org.apache.maven.model.DependencyManagement;
@@ -390,7 +390,7 @@ public List<ProjectBuildingResult> build(List<File> pomFiles, boolean recursive,
390390
Thread.currentThread().setContextClassLoader(oldContextClassLoader);
391391
}
392392

393-
if (Features.buildConsumer(request.getUserProperties()).isActive()) {
393+
if (Features.buildConsumer(request.getUserProperties())) {
394394
request.getRepositorySession()
395395
.getData()
396396
.set(TransformerContext.KEY, config.transformerContextBuilder.build());

maven-model-builder/src/main/java/org/apache/maven/feature/Features.java

Lines changed: 0 additions & 74 deletions
This file was deleted.

maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
import java.util.concurrent.ConcurrentHashMap;
4242
import java.util.stream.Collectors;
4343

44+
import org.apache.maven.api.feature.Features;
4445
import org.apache.maven.api.model.Exclusion;
4546
import org.apache.maven.api.model.InputSource;
4647
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
4748
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
4849
import org.apache.maven.artifact.versioning.VersionRange;
4950
import org.apache.maven.building.Source;
50-
import org.apache.maven.feature.Features;
5151
import org.apache.maven.model.Activation;
5252
import org.apache.maven.model.ActivationFile;
5353
import org.apache.maven.model.Build;
@@ -1125,7 +1125,7 @@ private Model readRawModel(ModelBuildingRequest request, DefaultModelProblemColl
11251125
}
11261126

11271127
Model rawModel;
1128-
if (Features.buildConsumer(request.getUserProperties()).isActive() && modelSource instanceof FileModelSource) {
1128+
if (Features.buildConsumer(request.getUserProperties()) && modelSource instanceof FileModelSource) {
11291129
rawModel = readFileModel(request, problems);
11301130
File pomFile = ((FileModelSource) modelSource).getFile();
11311131

0 commit comments

Comments
 (0)