Skip to content

Commit 813fbfb

Browse files
committed
Add maven 4 testcase
1 parent 17366ad commit 813fbfb

File tree

7 files changed

+357
-0
lines changed

7 files changed

+357
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Hello Maven 4 Test Project
2+
3+
## Overview
4+
This is a demonstration project showcasing Maven 4 features for testing m2e compatibility.
5+
6+
## Project Structure
7+
```
8+
HelloMaven4/
9+
├── pom.xml (parent)
10+
├── hello-core/ (library subproject)
11+
│ └── src/main/java/org/eclipse/m2e/tests/demo/core/
12+
│ └── GreetingService.java
13+
└── hello-app/ (application subproject)
14+
└── src/main/java/org/eclipse/m2e/tests/demo/app/
15+
└── HelloWorldApp.java
16+
```
17+
18+
## Maven 4 Features Used
19+
20+
This project demonstrates the following Maven 4 features from [What's New in Maven 4](https://maven.apache.org/whatsnewinmaven4.html):
21+
22+
### 1. ✅ New Model Version 4.1.0
23+
- **Feature**: Maven 4 introduces a new POM model version `4.1.0`
24+
- **Usage**: All POMs use `<modelVersion>4.1.0</modelVersion>` and `xmlns="http://maven.apache.org/POM/4.1.0"` namespace
25+
- **Location**: All `pom.xml` files
26+
- **Status**: Demonstrated
27+
28+
### 2. ✅ Subprojects Instead of Modules
29+
- **Feature**: Maven 4 uses `<subprojects>` instead of `<modules>` for better semantics
30+
- **Usage**: Parent POM uses `<subprojects>` to declare child projects
31+
- **Location**: `pom.xml` (parent)
32+
- **Status**: Demonstrated
33+
34+
### 3. ✅ Inheritance of GroupId and Version
35+
- **Feature**: Child projects can omit `<groupId>` and `<version>` when inheriting from parent
36+
- **Usage**: Child POMs (`hello-core` and `hello-app`) omit these elements
37+
- **Location**: `hello-core/pom.xml` and `hello-app/pom.xml`
38+
- **Status**: Demonstrated
39+
40+
### 4. ⏳ Build/Consumer POM Split
41+
- **Feature**: Maven 4 separates build-time and consumption-time concerns
42+
- **Usage**: Not explicitly demonstrated in this simple project
43+
- **Status**: Not applicable for this simple test case
44+
45+
### 5. ⏳ Better Java Version Handling
46+
- **Feature**: Improved handling of Java versions with `maven.compiler.release`
47+
- **Usage**: Uses `maven.compiler.release` property set to 11
48+
- **Location**: Parent POM properties
49+
- **Status**: Partially demonstrated
50+
51+
## Testing with Maven 4
52+
53+
This project is designed to be built with **Maven 4.0.0-rc-2** or later (Preview release).
54+
55+
To verify Maven 4 compatibility:
56+
```bash
57+
# Requires Maven 4.0.0-rc-2 or later
58+
mvn clean install
59+
```
60+
61+
## Purpose
62+
63+
This test project serves two main goals:
64+
65+
1. **Demonstrate Incompatibility**: Show that current m2e does NOT support Maven 4 features
66+
2. **Validation Target**: Provide a test case to verify Maven 4 support as it's implemented
67+
68+
## References
69+
70+
- [Apache Maven 4 Downloads](https://maven.apache.org/download.cgi)
71+
- [What's New in Maven 4](https://maven.apache.org/whatsnewinmaven4.html)
72+
- [Maven 4 Announcement](https://lists.apache.org/thread/jnb3snhdm4b564gz8hbctp9rfk8fc67n)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Maven 4 Subproject - demonstrates dependency on sibling subproject
4+
5+
This module also inherits groupId and version from parent
6+
-->
7+
<project xmlns="http://maven.apache.org/POM/4.1.0"
8+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:schemaLocation="http://maven.apache.org/POM/4.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd">
10+
11+
<modelVersion>4.1.0</modelVersion>
12+
13+
<parent>
14+
<groupId>org.eclipse.m2e.tests.demo</groupId>
15+
<artifactId>hello-maven4-parent</artifactId>
16+
<version>1.0.0-SNAPSHOT</version>
17+
</parent>
18+
19+
<artifactId>hello-app</artifactId>
20+
21+
<name>Hello Maven 4 App</name>
22+
<description>Application module demonstrating Maven 4 features</description>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>org.eclipse.m2e.tests.demo</groupId>
27+
<artifactId>hello-core</artifactId>
28+
<version>1.0.0-SNAPSHOT</version>
29+
</dependency>
30+
</dependencies>
31+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.eclipse.m2e.tests.demo.app;
2+
3+
import org.eclipse.m2e.tests.demo.core.GreetingService;
4+
5+
/**
6+
* Simple HelloWorld application demonstrating Maven 4 multi-subproject structure.
7+
*/
8+
public class HelloWorldApp {
9+
10+
public static void main(String[] args) {
11+
GreetingService service = new GreetingService();
12+
13+
String name = args.length > 0 ? args[0] : "Maven 4 World";
14+
String greeting = service.greet(name);
15+
16+
System.out.println(greeting);
17+
System.out.println("Built with Maven 4!");
18+
}
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Maven 4 Subproject - demonstrates inheritance of groupId and version
4+
5+
Note: In Maven 4, child projects can omit groupId and version
6+
when they inherit from parent, making the POM cleaner
7+
-->
8+
<project xmlns="http://maven.apache.org/POM/4.1.0"
9+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:schemaLocation="http://maven.apache.org/POM/4.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd">
11+
12+
<modelVersion>4.1.0</modelVersion>
13+
14+
<parent>
15+
<groupId>org.eclipse.m2e.tests.demo</groupId>
16+
<artifactId>hello-maven4-parent</artifactId>
17+
<version>1.0.0-SNAPSHOT</version>
18+
</parent>
19+
20+
<artifactId>hello-core</artifactId>
21+
22+
<name>Hello Maven 4 Core</name>
23+
<description>Core library module demonstrating Maven 4 features</description>
24+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.eclipse.m2e.tests.demo.core;
2+
3+
/**
4+
* A simple greeting service to demonstrate Maven 4 project structure.
5+
*/
6+
public class GreetingService {
7+
8+
private final String prefix;
9+
10+
public GreetingService(String prefix) {
11+
this.prefix = prefix;
12+
}
13+
14+
public GreetingService() {
15+
this("Hello");
16+
}
17+
18+
public String greet(String name) {
19+
return prefix + ", " + name + "!";
20+
}
21+
22+
public String getPrefix() {
23+
return prefix;
24+
}
25+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Maven 4 Test Project for m2e
4+
5+
This project demonstrates Maven 4 features including:
6+
- Model version 4.1.0
7+
- Subprojects instead of modules
8+
- Inheritance of groupId and version from parent
9+
-->
10+
<project xmlns="http://maven.apache.org/POM/4.1.0"
11+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
12+
xsi:schemaLocation="http://maven.apache.org/POM/4.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd">
13+
14+
<modelVersion>4.1.0</modelVersion>
15+
16+
<groupId>org.eclipse.m2e.tests.demo</groupId>
17+
<artifactId>hello-maven4-parent</artifactId>
18+
<version>1.0.0-SNAPSHOT</version>
19+
<packaging>pom</packaging>
20+
21+
<name>Hello Maven 4 Parent</name>
22+
<description>A simple Maven 4 demo project for testing m2e support</description>
23+
24+
<properties>
25+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
26+
<maven.compiler.release>11</maven.compiler.release>
27+
</properties>
28+
29+
<subprojects>
30+
<subproject>hello-core</subproject>
31+
<subproject>hello-app</subproject>
32+
</subprojects>
33+
34+
<build>
35+
<pluginManagement>
36+
<plugins>
37+
<plugin>
38+
<groupId>org.apache.maven.plugins</groupId>
39+
<artifactId>maven-compiler-plugin</artifactId>
40+
<version>3.11.0</version>
41+
</plugin>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-jar-plugin</artifactId>
45+
<version>3.3.0</version>
46+
</plugin>
47+
</plugins>
48+
</pluginManagement>
49+
</build>
50+
</project>
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Red Hat Inc. and others
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Red Hat Inc. - initial API and implementation
12+
*******************************************************************************/
13+
14+
package org.eclipse.m2e.core;
15+
16+
import static org.junit.Assert.assertNotNull;
17+
import static org.junit.Assert.assertTrue;
18+
import static org.junit.Assert.fail;
19+
20+
import java.io.File;
21+
22+
import org.eclipse.core.resources.IProject;
23+
import org.eclipse.core.resources.ResourcesPlugin;
24+
import org.eclipse.core.runtime.FileLocator;
25+
import org.eclipse.m2e.tests.common.AbstractMavenProjectTestCase;
26+
import org.junit.After;
27+
import org.junit.Test;
28+
29+
/**
30+
* Test case for Maven 4 support in m2e.
31+
*
32+
* This test demonstrates that m2e currently does NOT support Maven 4 features.
33+
* As Maven 4 support is implemented, this test can be enhanced to verify:
34+
* - Model version 4.1.0 parsing
35+
* - Subprojects support (instead of modules)
36+
* - Inheritance of groupId and version
37+
* - Build/Consumer POM split
38+
*
39+
* Based on real-world usage from https://github.com/jline/jline3
40+
*
41+
* @see https://maven.apache.org/whatsnewinmaven4.html
42+
*/
43+
public class Maven4Test extends AbstractMavenProjectTestCase {
44+
45+
@After
46+
public void clearWorkspace() throws Exception {
47+
for(IProject p : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
48+
p.delete(true, null);
49+
}
50+
}
51+
52+
/**
53+
* Test Maven 4 project with model version 4.1.0 and subprojects.
54+
*
55+
* This test attempts to import a Maven 4 project that uses:
56+
* - Model version 4.1.0
57+
* - Subprojects instead of modules
58+
* - Inheritance of groupId and version from parent
59+
*
60+
* Expected behavior:
61+
* - With current m2e (Maven 3 only): This test is expected to fail or show errors
62+
* - With Maven 4 support: This test should pass and projects should be imported correctly
63+
*/
64+
@Test
65+
public void testMaven4BasicProject() throws Exception {
66+
// Get the Maven 4 test project
67+
File sourceDirectory = new File(
68+
FileLocator.toFileURL(getClass().getResource("/resources/projects/HelloMaven4")).toURI());
69+
70+
assertNotNull("HelloMaven4 project directory should exist", sourceDirectory);
71+
assertTrue("HelloMaven4 project directory should be a directory", sourceDirectory.isDirectory());
72+
73+
File parentPom = new File(sourceDirectory, "pom.xml");
74+
assertTrue("Parent pom.xml should exist", parentPom.exists());
75+
76+
// Attempt to import the Maven 4 project
77+
// Note: This will likely fail with current m2e since it doesn't support Maven 4
78+
try {
79+
IProject project = importProject("resources/projects/HelloMaven4/pom.xml");
80+
81+
// If we get here, the project was imported (unexpected with current m2e)
82+
assertNotNull("Parent project should be imported", project);
83+
84+
// Check if subprojects are recognized
85+
// Note: With Maven 4 support, these should be imported as child projects
86+
IProject helloCore = ResourcesPlugin.getWorkspace().getRoot().getProject("hello-core");
87+
IProject helloApp = ResourcesPlugin.getWorkspace().getRoot().getProject("hello-app");
88+
89+
// These assertions will help verify Maven 4 support when implemented
90+
// For now, they document what should work with Maven 4
91+
assertNotNull("hello-core subproject should be recognized", helloCore);
92+
assertNotNull("hello-app subproject should be recognized", helloApp);
93+
94+
} catch (Exception e) {
95+
// Expected with current m2e - Maven 4 is not yet supported
96+
// This documents that m2e needs Maven 4 support
97+
System.err.println("Expected failure with Maven 3 based m2e: " + e.getMessage());
98+
99+
// For now, we'll let this exception indicate Maven 4 is not supported
100+
// When Maven 4 support is added, this test should pass without exceptions
101+
fail("Maven 4 project import failed (expected with current m2e): " + e.getMessage());
102+
}
103+
}
104+
105+
/**
106+
* Test that Maven 4 model version 4.1.0 is recognized.
107+
*
108+
* This is a more basic test that just checks if the model version is parsed correctly.
109+
* When Maven 4 support is added, this should pass.
110+
*/
111+
@Test
112+
public void testMaven4ModelVersion() throws Exception {
113+
File sourceDirectory = new File(
114+
FileLocator.toFileURL(getClass().getResource("/resources/projects/HelloMaven4")).toURI());
115+
File parentPom = new File(sourceDirectory, "pom.xml");
116+
117+
assertTrue("Parent pom.xml should exist", parentPom.exists());
118+
119+
// Try to read the POM
120+
// With Maven 4 support, this should recognize the 4.1.0 model version
121+
try {
122+
// This will likely fail with current Maven 3 based implementation
123+
// as it doesn't recognize model version 4.1.0
124+
@SuppressWarnings("unused")
125+
IProject project = importProject("resources/projects/HelloMaven4/pom.xml");
126+
127+
// If we get here, Maven 4 model version was recognized
128+
// This indicates Maven 4 support is working
129+
130+
} catch (Exception e) {
131+
// Expected with current m2e
132+
System.err.println("Maven 4 model version not supported yet: " + e.getMessage());
133+
fail("Maven 4 model version 4.1.0 is not supported (expected with current m2e): " + e.getMessage());
134+
}
135+
}
136+
}

0 commit comments

Comments
 (0)