Skip to content

Commit 23f2f74

Browse files
authored
Create a new modelVersion 4.2.0 (#2475)
1 parent 41e72d3 commit 23f2f74

File tree

14 files changed

+215
-25
lines changed

14 files changed

+215
-25
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public interface ModelBuilder extends Service {
2929

3030
String MODEL_VERSION_4_1_0 = "4.1.0";
3131

32-
List<String> KNOWN_MODEL_VERSIONS = List.of(MODEL_VERSION_4_0_0, MODEL_VERSION_4_1_0);
32+
String MODEL_VERSION_4_2_0 = "4.2.0";
33+
34+
List<String> KNOWN_MODEL_VERSIONS = List.of(MODEL_VERSION_4_0_0, MODEL_VERSION_4_1_0, MODEL_VERSION_4_2_0);
3335

3436
ModelBuilderSession newSession();
3537

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ enum Version {
6666
/**
6767
* Validation for Maven 4.1 POM format.
6868
*/
69-
V41
69+
V41,
70+
71+
/**
72+
* Validation for Maven 4.2 POM format.
73+
*/
74+
V42
7075
}
7176

7277
/**

api/maven-api-model/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ under the License.
4848
<groupId>org.codehaus.modello</groupId>
4949
<artifactId>modello-maven-plugin</artifactId>
5050
<configuration>
51-
<version>4.1.0</version>
51+
<version>4.2.0</version>
5252
<velocityBasedir>${project.basedir}/../../src/mdo</velocityBasedir>
5353
<models>
5454
<model>src/main/mdo/maven.mdo</model>

api/maven-api-model/src/main/mdo/maven.mdo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@
526526
<fields>
527527
<field xdoc.separator="blank">
528528
<name>modules</name>
529-
<version>4.0.0/4.1.0</version>
529+
<version>4.0.0/4.2.0</version>
530530
<description>
531531
@deprecated Use {@link #subprojects} instead.
532532
</description>
@@ -540,7 +540,7 @@
540540
</field>
541541
<field xdoc.separator="blank">
542542
<name>subprojects</name>
543-
<version>4.1.0</version>
543+
<version>4.1.0+</version>
544544
<description>The subprojects (formerly called modules) to build as a part of this
545545
project. Each subproject listed is a relative path to the directory containing the subproject.
546546
To be consistent with the way default URLs are calculated from parent, it is recommended

compat/maven-model-builder/src/main/resources/org/apache/maven/model/pom-4.1.0.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ under the License.
2020
-->
2121

2222
<!-- START SNIPPET: superpom -->
23-
<project>
24-
<modelVersion>4.0.0</modelVersion>
23+
<project xmlns="http://maven.apache.org/POM/4.1.0"
24+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
25+
xsi:schemaLocation="http://maven.apache.org/POM/4.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd">
26+
<modelVersion>4.1.0</modelVersion>
2527

2628
<properties>
2729
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
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+
<!-- START SNIPPET: superpom -->
23+
<project xmlns="http://maven.apache.org/POM/4.2.0"
24+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
25+
xsi:schemaLocation="http://maven.apache.org/POM/4.2.0 https://maven.apache.org/xsd/maven-4.2.0.xsd">
26+
<modelVersion>4.2.0</modelVersion>
27+
28+
<properties>
29+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
30+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
31+
<!-- Fixed date for reproducible build -->
32+
<project.build.outputTimestamp>1980-02-01T00:00:00Z</project.build.outputTimestamp>
33+
</properties>
34+
35+
<build>
36+
<directory>${project.basedir}/target</directory>
37+
<outputDirectory>${project.build.directory}/classes</outputDirectory>
38+
<finalName>${project.artifactId}-${project.version}</finalName>
39+
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
40+
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
41+
<scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory>
42+
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
43+
<resources>
44+
<resource>
45+
<directory>${project.basedir}/src/main/resources</directory>
46+
</resource>
47+
<resource>
48+
<directory>${project.basedir}/src/main/resources-filtered</directory>
49+
<filtering>true</filtering>
50+
</resource>
51+
</resources>
52+
<testResources>
53+
<testResource>
54+
<directory>${project.basedir}/src/test/resources</directory>
55+
</testResource>
56+
<testResource>
57+
<directory>${project.basedir}/src/test/resources-filtered</directory>
58+
<filtering>true</filtering>
59+
</testResource>
60+
</testResources>
61+
</build>
62+
63+
<reporting>
64+
<outputDirectory>${project.build.directory}/site</outputDirectory>
65+
</reporting>
66+
67+
</project>
68+
<!-- END SNIPPET: superpom -->

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/ModelUpgradeStrategy.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@
3737
import static org.apache.maven.cling.invoker.mvnup.goals.ModelVersionUtils.getSchemaLocationForModelVersion;
3838
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.ModelVersions.MODEL_VERSION_4_0_0;
3939
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.ModelVersions.MODEL_VERSION_4_1_0;
40+
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.ModelVersions.MODEL_VERSION_4_2_0;
4041
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.Namespaces.MAVEN_4_0_0_NAMESPACE;
4142
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.Namespaces.MAVEN_4_1_0_NAMESPACE;
43+
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.Namespaces.MAVEN_4_2_0_NAMESPACE;
4244
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.XmlAttributes.SCHEMA_LOCATION;
4345
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.XmlAttributes.XSI_NAMESPACE_PREFIX;
4446
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.XmlAttributes.XSI_NAMESPACE_URI;
@@ -246,7 +248,9 @@ private String determineTargetModelVersion(UpgradeContext context) {
246248
* Gets the namespace URI for a model version.
247249
*/
248250
private String getNamespaceForModelVersion(String modelVersion) {
249-
if (MODEL_VERSION_4_1_0.equals(modelVersion)) {
251+
if (MODEL_VERSION_4_2_0.equals(modelVersion)) {
252+
return MAVEN_4_2_0_NAMESPACE;
253+
} else if (MODEL_VERSION_4_1_0.equals(modelVersion)) {
250254
return MAVEN_4_1_0_NAMESPACE;
251255
} else {
252256
return MAVEN_4_0_0_NAMESPACE;

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/ModelVersionUtils.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424

2525
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.ModelVersions.MODEL_VERSION_4_0_0;
2626
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.ModelVersions.MODEL_VERSION_4_1_0;
27+
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.ModelVersions.MODEL_VERSION_4_2_0;
2728
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.Namespaces.MAVEN_4_0_0_NAMESPACE;
2829
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.Namespaces.MAVEN_4_1_0_NAMESPACE;
30+
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.Namespaces.MAVEN_4_2_0_NAMESPACE;
2931
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.SchemaLocations.MAVEN_4_1_0_SCHEMA_LOCATION;
32+
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.SchemaLocations.MAVEN_4_2_0_SCHEMA_LOCATION;
3033
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.XmlElements.MODEL_VERSION;
3134

3235
/**
@@ -60,7 +63,9 @@ public static String detectModelVersion(Document pomDocument) {
6063

6164
// Fallback to namespace URI detection
6265
String namespaceUri = namespace.getURI();
63-
if (MAVEN_4_1_0_NAMESPACE.equals(namespaceUri)) {
66+
if (MAVEN_4_2_0_NAMESPACE.equals(namespaceUri)) {
67+
return MODEL_VERSION_4_2_0;
68+
} else if (MAVEN_4_1_0_NAMESPACE.equals(namespaceUri)) {
6469
return MODEL_VERSION_4_1_0;
6570
} else if (MAVEN_4_0_0_NAMESPACE.equals(namespaceUri)) {
6671
return MODEL_VERSION_4_0_0;
@@ -72,13 +77,15 @@ public static String detectModelVersion(Document pomDocument) {
7277

7378
/**
7479
* Checks if a model version is valid for upgrade operations.
75-
* Currently only supports 4.0.0 and 4.1.0.
80+
* Currently supports 4.0.0, 4.1.0, and 4.2.0.
7681
*
7782
* @param modelVersion the model version to validate
7883
* @return true if the model version is valid
7984
*/
8085
public static boolean isValidModelVersion(String modelVersion) {
81-
return MODEL_VERSION_4_0_0.equals(modelVersion) || MODEL_VERSION_4_1_0.equals(modelVersion);
86+
return MODEL_VERSION_4_0_0.equals(modelVersion)
87+
|| MODEL_VERSION_4_1_0.equals(modelVersion)
88+
|| MODEL_VERSION_4_2_0.equals(modelVersion);
8289
}
8390

8491
/**
@@ -93,8 +100,15 @@ public static boolean canUpgrade(String fromVersion, String toVersion) {
93100
return false;
94101
}
95102

96-
// Currently only support 4.0.0 → 4.1.0 upgrade
97-
return MODEL_VERSION_4_0_0.equals(fromVersion) && MODEL_VERSION_4_1_0.equals(toVersion);
103+
// Support upgrades: 4.0.0 → 4.1.0, 4.0.0 → 4.2.0, 4.1.0 → 4.2.0
104+
if (MODEL_VERSION_4_0_0.equals(fromVersion)) {
105+
return MODEL_VERSION_4_1_0.equals(toVersion) || MODEL_VERSION_4_2_0.equals(toVersion);
106+
}
107+
if (MODEL_VERSION_4_1_0.equals(fromVersion)) {
108+
return MODEL_VERSION_4_2_0.equals(toVersion);
109+
}
110+
111+
return false;
98112
}
99113

100114
/**
@@ -105,7 +119,9 @@ public static boolean canUpgrade(String fromVersion, String toVersion) {
105119
* @return true if eligible for inference
106120
*/
107121
public static boolean isEligibleForInference(String modelVersion) {
108-
return MODEL_VERSION_4_0_0.equals(modelVersion) || MODEL_VERSION_4_1_0.equals(modelVersion);
122+
return MODEL_VERSION_4_0_0.equals(modelVersion)
123+
|| MODEL_VERSION_4_1_0.equals(modelVersion)
124+
|| MODEL_VERSION_4_2_0.equals(modelVersion);
109125
}
110126

111127
/**
@@ -220,8 +236,13 @@ public static boolean removeModelVersion(Document pomDocument) {
220236
* @return the schema location
221237
*/
222238
public static String getSchemaLocationForModelVersion(String modelVersion) {
223-
if (MODEL_VERSION_4_1_0.equals(modelVersion) || isNewerThan410(modelVersion)) {
239+
if (MODEL_VERSION_4_2_0.equals(modelVersion)) {
240+
return MAVEN_4_2_0_SCHEMA_LOCATION;
241+
} else if (MODEL_VERSION_4_1_0.equals(modelVersion)) {
224242
return MAVEN_4_1_0_SCHEMA_LOCATION;
243+
} else if (isNewerThan410(modelVersion)) {
244+
// For versions newer than 4.1.0 but not specifically 4.2.0, use 4.2.0 schema
245+
return MAVEN_4_2_0_SCHEMA_LOCATION;
225246
}
226247
return UpgradeConstants.SchemaLocations.MAVEN_4_0_0_SCHEMA_LOCATION;
227248
}

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/UpgradeConstants.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public static final class ModelVersions {
3838
/** Maven 4.1.0 model version */
3939
public static final String MODEL_VERSION_4_1_0 = "4.1.0";
4040

41+
/** Maven 4.2.0 model version */
42+
public static final String MODEL_VERSION_4_2_0 = "4.2.0";
43+
4144
private ModelVersions() {
4245
// Utility class
4346
}
@@ -183,6 +186,9 @@ public static final class Namespaces {
183186
/** Maven 4.1.0 namespace URI */
184187
public static final String MAVEN_4_1_0_NAMESPACE = "http://maven.apache.org/POM/4.1.0";
185188

189+
/** Maven 4.2.0 namespace URI */
190+
public static final String MAVEN_4_2_0_NAMESPACE = "http://maven.apache.org/POM/4.2.0";
191+
186192
private Namespaces() {
187193
// Utility class
188194
}
@@ -200,6 +206,10 @@ public static final class SchemaLocations {
200206
public static final String MAVEN_4_1_0_SCHEMA_LOCATION =
201207
Namespaces.MAVEN_4_1_0_NAMESPACE + " https://maven.apache.org/xsd/maven-4.1.0.xsd";
202208

209+
/** Schema location for 4.2.0 models */
210+
public static final String MAVEN_4_2_0_SCHEMA_LOCATION =
211+
Namespaces.MAVEN_4_2_0_NAMESPACE + " https://maven.apache.org/xsd/maven-4.2.0.xsd";
212+
203213
private SchemaLocations() {
204214
// Utility class
205215
}

impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/ModelVersionUtilsTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ void shouldDetectVersionFromNamespaceWhenModelVersionMissing() throws Exception
129129
class ModelVersionValidationTests {
130130

131131
@ParameterizedTest
132-
@ValueSource(strings = {"4.0.0", "4.1.0"})
132+
@ValueSource(strings = {"4.0.0", "4.1.0", "4.2.0"})
133133
@DisplayName("should validate supported model versions")
134134
void shouldValidateSupportedModelVersions(String version) {
135135
assertTrue(ModelVersionUtils.isValidModelVersion(version));
136136
}
137137

138138
@ParameterizedTest
139-
@ValueSource(strings = {"3.0.0", "5.0.0", "4.2.0", "2.0.0", "6.0.0"})
139+
@ValueSource(strings = {"3.0.0", "5.0.0", "2.0.0", "6.0.0"})
140140
@DisplayName("should reject unsupported model versions")
141141
void shouldRejectUnsupportedModelVersions(String version) {
142142
assertFalse(ModelVersionUtils.isValidModelVersion(version));
@@ -381,11 +381,11 @@ void shouldGetSchemaLocationFor400() {
381381
@DisplayName("should handle unknown model version in schema location")
382382
void shouldHandleUnknownModelVersionInSchemaLocation() {
383383
String schemaLocation = ModelVersionUtils.getSchemaLocationForModelVersion("5.0.0");
384-
assertNotNull(schemaLocation); // Should return 4.1.0 schema for newer versions
385-
// The method returns the 4.1.0 schema location for versions newer than 4.1.0
384+
assertNotNull(schemaLocation); // Should return 4.2.0 schema for newer versions
385+
// The method returns the 4.2.0 schema location for versions newer than 4.1.0
386386
assertTrue(
387-
schemaLocation.contains("4.1.0"),
388-
"Expected schema location to contain '4.1.0', but was: " + schemaLocation);
387+
schemaLocation.contains("4.2.0"),
388+
"Expected schema location to contain '4.2.0', but was: " + schemaLocation);
389389
}
390390
}
391391

0 commit comments

Comments
 (0)