This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch namespace
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/namespace by this push:
new 523d67cca0 tests
523d67cca0 is described below
commit 523d67cca0dcf7e6a44756c0561acd906258b060
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Sat Jul 19 07:55:37 2025 -0400
tests
---
.../invoker/mvnup/goals/ModelVersionUtils.java | 14 +----
.../invoker/mvnup/goals/InferenceStrategyTest.java | 3 ++
.../mvnup/goals/ModelUpgradeStrategyTest.java | 60 +---------------------
.../invoker/mvnup/goals/ModelVersionUtilsTest.java | 18 -------
4 files changed, 7 insertions(+), 88 deletions(-)
diff --git
a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/ModelVersionUtils.java
b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/ModelVersionUtils.java
index 8d37407789..b8e7c9e4eb 100644
---
a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/ModelVersionUtils.java
+++
b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/ModelVersionUtils.java
@@ -24,8 +24,6 @@
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.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.SchemaLocations.MAVEN_4_1_0_SCHEMA_LOCATION;
import static
org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.XmlElements.MODEL_VERSION;
@@ -40,7 +38,7 @@ private ModelVersionUtils() {
/**
* Detects the model version from a POM document.
- * Uses both the modelVersion element and namespace URI for detection.
+ * Uses the modelVersion element for detection.
*
* @param pomDocument the POM document
* @return the detected model version
@@ -49,7 +47,7 @@ public static String detectModelVersion(Document pomDocument)
{
Element root = pomDocument.getRootElement();
Namespace namespace = root.getNamespace();
- // First try to get from modelVersion element
+ // Try to get from modelVersion element
Element modelVersionElement = root.getChild(MODEL_VERSION, namespace);
if (modelVersionElement != null) {
String modelVersion = modelVersionElement.getTextTrim();
@@ -58,14 +56,6 @@ public static String detectModelVersion(Document
pomDocument) {
}
}
- // Fallback to namespace URI detection
- String namespaceUri = namespace.getURI();
- 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;
- }
-
// Default fallback
return MODEL_VERSION_4_0_0;
}
diff --git
a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/InferenceStrategyTest.java
b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/InferenceStrategyTest.java
index 85be99aee2..a87225f5c2 100644
---
a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/InferenceStrategyTest.java
+++
b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/InferenceStrategyTest.java
@@ -150,6 +150,7 @@ void shouldRemoveDependencyVersionForProjectArtifact()
throws Exception {
"""
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
+ <modelVersion>4.1.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>parent-project</artifactId>
@@ -284,6 +285,7 @@ void shouldHandlePluginDependencies() throws Exception {
"""
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
+ <modelVersion>4.1.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>module-a</artifactId>
<version>1.0.0</version>
@@ -294,6 +296,7 @@ void shouldHandlePluginDependencies() throws Exception {
"""
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
+ <modelVersion>4.1.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>module-b</artifactId>
<version>1.0.0</version>
diff --git
a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/ModelUpgradeStrategyTest.java
b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/ModelUpgradeStrategyTest.java
index 10f1e404c3..8e800affa8 100644
---
a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/ModelUpgradeStrategyTest.java
+++
b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/ModelUpgradeStrategyTest.java
@@ -132,7 +132,6 @@ void shouldHandleVariousModelVersionUpgradeScenarios(
String initialNamespace,
String initialModelVersion,
String targetModelVersion,
- String expectedNamespace,
String expectedModelVersion,
int expectedModifiedCount,
String description)
@@ -158,7 +157,6 @@ void shouldHandleVariousModelVersionUpgradeScenarios(
// Verify the model version and namespace
Element root = document.getRootElement();
- assertEquals(expectedNamespace, root.getNamespaceURI(), "Namespace
should be updated: " + description);
Element modelVersionElement = root.getChild("modelVersion",
root.getNamespace());
if (expectedModelVersion != null) {
@@ -176,7 +174,6 @@ private static Stream<Arguments> provideUpgradeScenarios() {
"http://maven.apache.org/POM/4.0.0",
"4.0.0",
"4.1.0",
- "http://maven.apache.org/POM/4.0.0",
"4.1.0",
1,
"Should upgrade from 4.0.0 to 4.1.0"),
@@ -184,7 +181,6 @@ private static Stream<Arguments> provideUpgradeScenarios() {
"http://maven.apache.org/POM/4.0.0",
"4.1.0",
"4.1.0",
- "http://maven.apache.org/POM/4.0.0",
"4.1.0",
0,
"Should not modify when already at target
version"),
@@ -192,7 +188,6 @@ private static Stream<Arguments> provideUpgradeScenarios() {
"http://maven.apache.org/POM/4.0.0",
null,
"4.1.0",
- "http://maven.apache.org/POM/4.0.0",
"4.1.0",
1,
"Should add model version when missing"));
@@ -200,59 +195,8 @@ private static Stream<Arguments> provideUpgradeScenarios()
{
}
@Nested
- @DisplayName("Namespace Updates")
- class NamespaceUpdateTests {
-
- @Test
- @DisplayName("should update namespace recursively")
- void shouldUpdateNamespaceRecursively() throws Exception {
- String pomXml =
- """
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0">
- <modelVersion>4.0.0</modelVersion>
- <dependencies>
- <dependency>
- <groupId>test</groupId>
- <artifactId>test</artifactId>
- <version>1.0.0</version>
- </dependency>
- </dependencies>
- </project>
- """;
-
- Document document = saxBuilder.build(new StringReader(pomXml));
- Map<Path, Document> pomMap = Map.of(Paths.get("pom.xml"),
document);
-
- // Create context with --model-version=4.1.0 option to trigger
namespace update
- UpgradeOptions options = mock(UpgradeOptions.class);
- when(options.modelVersion()).thenReturn(Optional.of("4.1.0"));
- when(options.all()).thenReturn(Optional.empty());
- UpgradeContext context = createMockContext(options);
-
- UpgradeResult result = strategy.apply(context, pomMap);
-
- assertTrue(result.success(), "Model upgrade should succeed");
- assertTrue(result.modifiedCount() > 0, "Should have upgraded
namespace");
-
- // Verify namespace was updated recursively
- Element root = document.getRootElement();
- Namespace newNamespace =
Namespace.getNamespace("http://maven.apache.org/POM/4.0.0");
- assertEquals(newNamespace, root.getNamespace());
-
- // Verify child elements namespace updated recursively
- Element dependencies = root.getChild("dependencies", newNamespace);
- assertNotNull(dependencies);
- assertEquals(newNamespace, dependencies.getNamespace());
-
- Element dependency = dependencies.getChild("dependency",
newNamespace);
- assertNotNull(dependency);
- assertEquals(newNamespace, dependency.getNamespace());
-
- Element groupId = dependency.getChild("groupId", newNamespace);
- assertNotNull(groupId);
- assertEquals(newNamespace, groupId.getNamespace());
- }
+ @DisplayName("Model Version Updates")
+ class ModelVersionUpdateTests {
@Test
@DisplayName("should convert modules to subprojects in 4.1.0")
diff --git
a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/ModelVersionUtilsTest.java
b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/ModelVersionUtilsTest.java
index d2226f017b..13562ae25a 100644
---
a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/ModelVersionUtilsTest.java
+++
b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/ModelVersionUtilsTest.java
@@ -104,24 +104,6 @@ void shouldReturnDefaultVersionWhenModelVersionMissing()
throws Exception {
String result = ModelVersionUtils.detectModelVersion(document);
assertEquals("4.0.0", result); // Default version
}
-
- @Test
- @DisplayName("should detect version from namespace when model version
is missing")
- void shouldDetectVersionFromNamespaceWhenModelVersionMissing() throws
Exception {
- String pomXml =
- """
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0">
- <groupId>test</groupId>
- <artifactId>test</artifactId>
- <version>1.0.0</version>
- </project>
- """;
-
- Document document = saxBuilder.build(new StringReader(pomXml));
- String result = ModelVersionUtils.detectModelVersion(document);
- assertEquals("4.1.0", result);
- }
}
@Nested