Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# A hack to pass on this property for Maven 3 as well; Maven 4 supports this property out of the box
-DsessionRootDirectory=${session.rootDirectory}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public interface ModelBuilder extends Service {

String MODEL_VERSION_4_1_0 = "4.1.0";

List<String> KNOWN_MODEL_VERSIONS = List.of(MODEL_VERSION_4_0_0, MODEL_VERSION_4_1_0);
String MODEL_VERSION_4_2_0 = "4.2.0";

List<String> KNOWN_MODEL_VERSIONS = List.of(MODEL_VERSION_4_0_0, MODEL_VERSION_4_1_0, MODEL_VERSION_4_2_0);

ModelBuilderSession newSession();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ enum Version {
/**
* Validation for Maven 4.1 POM format.
*/
V41
V41,

/**
* Validation for Maven 4.2 POM format.
*/
V42
}

/**
Expand Down
2 changes: 1 addition & 1 deletion api/maven-api-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ under the License.
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<configuration>
<version>4.1.0</version>
<version>4.2.0</version>
<velocityBasedir>${project.basedir}/../../src/mdo</velocityBasedir>
<models>
<model>src/main/mdo/maven.mdo</model>
Expand Down
35 changes: 33 additions & 2 deletions api/maven-api-model/src/main/mdo/maven.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@
</association>
</field>

<!-- ====================================================================== -->
<!-- Mixins -->
<!-- ====================================================================== -->

<field xdoc.separator="blank">
<name>mixins</name>
<version>4.2.0+</version>
<description>Mixins...</description>
<association>
<type>Mixin</type>
<multiplicity>*</multiplicity>
</association>
</field>

<!-- ====================================================================== -->
<!-- groupId/artifactId/Version/Packaging -->
<!-- ====================================================================== -->
Expand Down Expand Up @@ -526,7 +540,7 @@
<fields>
<field xdoc.separator="blank">
<name>modules</name>
<version>4.0.0/4.1.0</version>
<version>4.0.0/4.2.0</version>
<description>
@deprecated Use {@link #subprojects} instead.
</description>
Expand All @@ -540,7 +554,7 @@
</field>
<field xdoc.separator="blank">
<name>subprojects</name>
<version>4.1.0</version>
<version>4.1.0+</version>
<description>The subprojects (formerly called modules) to build as a part of this
project. Each subproject listed is a relative path to the directory containing the subproject.
To be consistent with the way default URLs are calculated from parent, it is recommended
Expand Down Expand Up @@ -1836,6 +1850,23 @@
</codeSegments>

</class>
<class>
<name>Mixin</name>
<version>4.1.0+</version>
<superClass>Parent</superClass>
<fields>
<field>
<name>classifier</name>
<version>4.1.0+</version>
<type>String</type>
</field>
<field>
<name>extension</name>
<version>4.1.0+</version>
<type>String</type>
</field>
</fields>
</class>
<class>
<name>Scm</name>
<version>4.0.0+</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ protected void mergeModel_Profiles(
.collect(Collectors.toList()));
}

@Override
protected void mergeModel_Mixins(
Model.Builder builder, Model target, Model source, boolean sourceDominant, Map<Object, Object> context) {
// don't merge
}

@Override
protected void mergeModelBase_Dependencies(
ModelBase.Builder builder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ under the License.
-->

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

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<!-- START SNIPPET: superpom -->
<project xmlns="http://maven.apache.org/POM/4.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.2.0 https://maven.apache.org/xsd/maven-4.2.0.xsd">
<modelVersion>4.2.0</modelVersion>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Fixed date for reproducible build -->
<project.build.outputTimestamp>1980-02-01T00:00:00Z</project.build.outputTimestamp>
</properties>

<build>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources-filtered</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
<testResource>
<directory>${project.basedir}/src/test/resources-filtered</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>

<reporting>
<outputDirectory>${project.build.directory}/site</outputDirectory>
</reporting>

</project>
<!-- END SNIPPET: superpom -->
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
import static org.apache.maven.cling.invoker.mvnup.goals.ModelVersionUtils.getSchemaLocationForModelVersion;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.ModelVersions.MODEL_VERSION_4_0_0;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.ModelVersions.MODEL_VERSION_4_1_0;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.ModelVersions.MODEL_VERSION_4_2_0;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.Namespaces.MAVEN_4_0_0_NAMESPACE;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.Namespaces.MAVEN_4_1_0_NAMESPACE;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.Namespaces.MAVEN_4_2_0_NAMESPACE;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.XmlAttributes.SCHEMA_LOCATION;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.XmlAttributes.XSI_NAMESPACE_PREFIX;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.XmlAttributes.XSI_NAMESPACE_URI;
Expand Down Expand Up @@ -246,7 +248,9 @@ private String determineTargetModelVersion(UpgradeContext context) {
* Gets the namespace URI for a model version.
*/
private String getNamespaceForModelVersion(String modelVersion) {
if (MODEL_VERSION_4_1_0.equals(modelVersion)) {
if (MODEL_VERSION_4_2_0.equals(modelVersion)) {
return MAVEN_4_2_0_NAMESPACE;
} else if (MODEL_VERSION_4_1_0.equals(modelVersion)) {
return MAVEN_4_1_0_NAMESPACE;
} else {
return MAVEN_4_0_0_NAMESPACE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@

import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.ModelVersions.MODEL_VERSION_4_0_0;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.ModelVersions.MODEL_VERSION_4_1_0;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.ModelVersions.MODEL_VERSION_4_2_0;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.Namespaces.MAVEN_4_0_0_NAMESPACE;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.Namespaces.MAVEN_4_1_0_NAMESPACE;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.Namespaces.MAVEN_4_2_0_NAMESPACE;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.SchemaLocations.MAVEN_4_1_0_SCHEMA_LOCATION;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.SchemaLocations.MAVEN_4_2_0_SCHEMA_LOCATION;
import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.XmlElements.MODEL_VERSION;

/**
Expand Down Expand Up @@ -60,7 +63,9 @@ public static String detectModelVersion(Document pomDocument) {

// Fallback to namespace URI detection
String namespaceUri = namespace.getURI();
if (MAVEN_4_1_0_NAMESPACE.equals(namespaceUri)) {
if (MAVEN_4_2_0_NAMESPACE.equals(namespaceUri)) {
return MODEL_VERSION_4_2_0;
} else if (MAVEN_4_1_0_NAMESPACE.equals(namespaceUri)) {
return MODEL_VERSION_4_1_0;
} else if (MAVEN_4_0_0_NAMESPACE.equals(namespaceUri)) {
return MODEL_VERSION_4_0_0;
Expand All @@ -72,13 +77,15 @@ public static String detectModelVersion(Document pomDocument) {

/**
* Checks if a model version is valid for upgrade operations.
* Currently only supports 4.0.0 and 4.1.0.
* Currently supports 4.0.0, 4.1.0, and 4.2.0.
*
* @param modelVersion the model version to validate
* @return true if the model version is valid
*/
public static boolean isValidModelVersion(String modelVersion) {
return MODEL_VERSION_4_0_0.equals(modelVersion) || MODEL_VERSION_4_1_0.equals(modelVersion);
return MODEL_VERSION_4_0_0.equals(modelVersion)
|| MODEL_VERSION_4_1_0.equals(modelVersion)
|| MODEL_VERSION_4_2_0.equals(modelVersion);
}

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

// Currently only support 4.0.0 → 4.1.0 upgrade
return MODEL_VERSION_4_0_0.equals(fromVersion) && MODEL_VERSION_4_1_0.equals(toVersion);
// Support upgrades: 4.0.0 → 4.1.0, 4.0.0 → 4.2.0, 4.1.0 → 4.2.0
if (MODEL_VERSION_4_0_0.equals(fromVersion)) {
return MODEL_VERSION_4_1_0.equals(toVersion) || MODEL_VERSION_4_2_0.equals(toVersion);
}
if (MODEL_VERSION_4_1_0.equals(fromVersion)) {
return MODEL_VERSION_4_2_0.equals(toVersion);
}

return false;
}

/**
Expand All @@ -105,7 +119,9 @@ public static boolean canUpgrade(String fromVersion, String toVersion) {
* @return true if eligible for inference
*/
public static boolean isEligibleForInference(String modelVersion) {
return MODEL_VERSION_4_0_0.equals(modelVersion) || MODEL_VERSION_4_1_0.equals(modelVersion);
return MODEL_VERSION_4_0_0.equals(modelVersion)
|| MODEL_VERSION_4_1_0.equals(modelVersion)
|| MODEL_VERSION_4_2_0.equals(modelVersion);
}

/**
Expand Down Expand Up @@ -220,8 +236,13 @@ public static boolean removeModelVersion(Document pomDocument) {
* @return the schema location
*/
public static String getSchemaLocationForModelVersion(String modelVersion) {
if (MODEL_VERSION_4_1_0.equals(modelVersion) || isNewerThan410(modelVersion)) {
if (MODEL_VERSION_4_2_0.equals(modelVersion)) {
return MAVEN_4_2_0_SCHEMA_LOCATION;
} else if (MODEL_VERSION_4_1_0.equals(modelVersion)) {
return MAVEN_4_1_0_SCHEMA_LOCATION;
} else if (isNewerThan410(modelVersion)) {
// For versions newer than 4.1.0 but not specifically 4.2.0, use 4.2.0 schema
return MAVEN_4_2_0_SCHEMA_LOCATION;
}
return UpgradeConstants.SchemaLocations.MAVEN_4_0_0_SCHEMA_LOCATION;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public static final class ModelVersions {
/** Maven 4.1.0 model version */
public static final String MODEL_VERSION_4_1_0 = "4.1.0";

/** Maven 4.2.0 model version */
public static final String MODEL_VERSION_4_2_0 = "4.2.0";

private ModelVersions() {
// Utility class
}
Expand Down Expand Up @@ -183,6 +186,9 @@ public static final class Namespaces {
/** Maven 4.1.0 namespace URI */
public static final String MAVEN_4_1_0_NAMESPACE = "http://maven.apache.org/POM/4.1.0";

/** Maven 4.2.0 namespace URI */
public static final String MAVEN_4_2_0_NAMESPACE = "http://maven.apache.org/POM/4.2.0";

private Namespaces() {
// Utility class
}
Expand All @@ -200,6 +206,10 @@ public static final class SchemaLocations {
public static final String MAVEN_4_1_0_SCHEMA_LOCATION =
Namespaces.MAVEN_4_1_0_NAMESPACE + " https://maven.apache.org/xsd/maven-4.1.0.xsd";

/** Schema location for 4.2.0 models */
public static final String MAVEN_4_2_0_SCHEMA_LOCATION =
Namespaces.MAVEN_4_2_0_NAMESPACE + " https://maven.apache.org/xsd/maven-4.2.0.xsd";

private SchemaLocations() {
// Utility class
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ void shouldDetectVersionFromNamespaceWhenModelVersionMissing() throws Exception
class ModelVersionValidationTests {

@ParameterizedTest
@ValueSource(strings = {"4.0.0", "4.1.0"})
@ValueSource(strings = {"4.0.0", "4.1.0", "4.2.0"})
@DisplayName("should validate supported model versions")
void shouldValidateSupportedModelVersions(String version) {
assertTrue(ModelVersionUtils.isValidModelVersion(version));
}

@ParameterizedTest
@ValueSource(strings = {"3.0.0", "5.0.0", "4.2.0", "2.0.0", "6.0.0"})
@ValueSource(strings = {"3.0.0", "5.0.0", "2.0.0", "6.0.0"})
@DisplayName("should reject unsupported model versions")
void shouldRejectUnsupportedModelVersions(String version) {
assertFalse(ModelVersionUtils.isValidModelVersion(version));
Expand Down Expand Up @@ -381,11 +381,11 @@ void shouldGetSchemaLocationFor400() {
@DisplayName("should handle unknown model version in schema location")
void shouldHandleUnknownModelVersionInSchemaLocation() {
String schemaLocation = ModelVersionUtils.getSchemaLocationForModelVersion("5.0.0");
assertNotNull(schemaLocation); // Should return 4.1.0 schema for newer versions
// The method returns the 4.1.0 schema location for versions newer than 4.1.0
assertNotNull(schemaLocation); // Should return 4.2.0 schema for newer versions
// The method returns the 4.2.0 schema location for versions newer than 4.1.0
assertTrue(
schemaLocation.contains("4.1.0"),
"Expected schema location to contain '4.1.0', but was: " + schemaLocation);
schemaLocation.contains("4.2.0"),
"Expected schema location to contain '4.2.0', but was: " + schemaLocation);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ static Model transformNonPom(Model model, MavenProject project) {
.preserveModelVersion(false)
.root(false)
.parent(null)
.mixins(null)
.build(null),
model)
.mailingLists(null)
Expand Down
Loading
Loading