diff --git a/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/README.md b/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/README.md new file mode 100644 index 0000000000..9eaa5e63e0 --- /dev/null +++ b/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/README.md @@ -0,0 +1,74 @@ +# Hello Maven 4 Test Project + +## Overview +This is a demonstration project showcasing Maven 4 features for testing m2e compatibility. +The project is based on real-world usage patterns from [jline3](https://github.com/jline/jline3). + +## Project Structure +``` +HelloMaven4/ +├── pom.xml (parent) +├── hello-core/ (library subproject) +│ └── src/main/java/org/eclipse/m2e/tests/demo/core/ +│ └── GreetingService.java +└── hello-app/ (application subproject) + └── src/main/java/org/eclipse/m2e/tests/demo/app/ + └── HelloWorldApp.java +``` + +## Maven 4 Features Used + +This project demonstrates the following Maven 4 features from [What's New in Maven 4](https://maven.apache.org/whatsnewinmaven4.html): + +### 1. ✅ New Model Version 4.1.0 +- **Feature**: Maven 4 introduces a new POM model version `4.1.0` +- **Usage**: All POMs use `4.1.0` and `xmlns="http://maven.apache.org/POM/4.1.0"` namespace +- **Location**: All `pom.xml` files +- **Status**: Demonstrated + +### 2. ✅ Subprojects Instead of Modules +- **Feature**: Maven 4 uses `` instead of `` for better semantics +- **Usage**: Parent POM uses `` to declare child projects +- **Location**: `pom.xml` (parent) +- **Status**: Demonstrated + +### 3. ✅ Inheritance of GroupId and Version +- **Feature**: Child projects can omit `` and `` when inheriting from parent +- **Usage**: Child POMs (`hello-core` and `hello-app`) omit these elements +- **Location**: `hello-core/pom.xml` and `hello-app/pom.xml` +- **Status**: Demonstrated + +### 4. ⏳ Build/Consumer POM Split +- **Feature**: Maven 4 separates build-time and consumption-time concerns +- **Usage**: Not explicitly demonstrated in this simple project +- **Status**: Not applicable for this simple test case + +### 5. ⏳ Better Java Version Handling +- **Feature**: Improved handling of Java versions with `maven.compiler.release` +- **Usage**: Uses `maven.compiler.release` property set to 11 +- **Location**: Parent POM properties +- **Status**: Partially demonstrated + +## Testing with Maven 4 + +This project is designed to be built with **Maven 4.0.0-rc-2** or later (Preview release). + +To verify Maven 4 compatibility: +```bash +# Requires Maven 4.0.0-rc-2 or later +mvn clean install +``` + +## Purpose + +This test project serves two main goals: + +1. **Demonstrate Incompatibility**: Show that current m2e does NOT support Maven 4 features +2. **Validation Target**: Provide a test case to verify Maven 4 support as it's implemented + +## References + +- [Apache Maven 4 Downloads](https://maven.apache.org/download.cgi) +- [What's New in Maven 4](https://maven.apache.org/whatsnewinmaven4.html) +- [JLine3 Project](https://github.com/jline/jline3) - Real-world Maven 4 usage example +- [Maven 4 Announcement](https://lists.apache.org/thread/jnb3snhdm4b564gz8hbctp9rfk8fc67n) diff --git a/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/hello-app/pom.xml b/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/hello-app/pom.xml new file mode 100644 index 0000000000..d959aceaf7 --- /dev/null +++ b/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/hello-app/pom.xml @@ -0,0 +1,31 @@ + + + + + 4.1.0 + + + org.eclipse.m2e.tests.demo + hello-maven4-parent + 1.0.0-SNAPSHOT + + + hello-app + + Hello Maven 4 App + Application module demonstrating Maven 4 features + + + + org.eclipse.m2e.tests.demo + hello-core + 1.0.0-SNAPSHOT + + + diff --git a/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/hello-app/src/main/java/org/eclipse/m2e/tests/demo/app/HelloWorldApp.java b/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/hello-app/src/main/java/org/eclipse/m2e/tests/demo/app/HelloWorldApp.java new file mode 100644 index 0000000000..ffb0ffee32 --- /dev/null +++ b/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/hello-app/src/main/java/org/eclipse/m2e/tests/demo/app/HelloWorldApp.java @@ -0,0 +1,19 @@ +package org.eclipse.m2e.tests.demo.app; + +import org.eclipse.m2e.tests.demo.core.GreetingService; + +/** + * Simple HelloWorld application demonstrating Maven 4 multi-subproject structure. + */ +public class HelloWorldApp { + + public static void main(String[] args) { + GreetingService service = new GreetingService(); + + String name = args.length > 0 ? args[0] : "Maven 4 World"; + String greeting = service.greet(name); + + System.out.println(greeting); + System.out.println("Built with Maven 4!"); + } +} diff --git a/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/hello-core/pom.xml b/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/hello-core/pom.xml new file mode 100644 index 0000000000..ab4e017df8 --- /dev/null +++ b/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/hello-core/pom.xml @@ -0,0 +1,24 @@ + + + + + 4.1.0 + + + org.eclipse.m2e.tests.demo + hello-maven4-parent + 1.0.0-SNAPSHOT + + + hello-core + + Hello Maven 4 Core + Core library module demonstrating Maven 4 features + diff --git a/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/hello-core/src/main/java/org/eclipse/m2e/tests/demo/core/GreetingService.java b/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/hello-core/src/main/java/org/eclipse/m2e/tests/demo/core/GreetingService.java new file mode 100644 index 0000000000..4458173d37 --- /dev/null +++ b/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/hello-core/src/main/java/org/eclipse/m2e/tests/demo/core/GreetingService.java @@ -0,0 +1,25 @@ +package org.eclipse.m2e.tests.demo.core; + +/** + * A simple greeting service to demonstrate Maven 4 project structure. + */ +public class GreetingService { + + private final String prefix; + + public GreetingService(String prefix) { + this.prefix = prefix; + } + + public GreetingService() { + this("Hello"); + } + + public String greet(String name) { + return prefix + ", " + name + "!"; + } + + public String getPrefix() { + return prefix; + } +} diff --git a/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/pom.xml b/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/pom.xml new file mode 100644 index 0000000000..ab070dcac9 --- /dev/null +++ b/org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/pom.xml @@ -0,0 +1,50 @@ + + + + + 4.1.0 + + org.eclipse.m2e.tests.demo + hello-maven4-parent + 1.0.0-SNAPSHOT + pom + + Hello Maven 4 Parent + A simple Maven 4 demo project for testing m2e support + + + UTF-8 + 11 + + + + hello-core + hello-app + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + + org.apache.maven.plugins + maven-jar-plugin + 3.3.0 + + + + + diff --git a/org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/Maven4Test.java b/org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/Maven4Test.java new file mode 100644 index 0000000000..54779ee172 --- /dev/null +++ b/org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/Maven4Test.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2025 Red Hat Inc. and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.m2e.tests.common.AbstractMavenProjectTestCase; +import org.junit.After; +import org.junit.Test; + +/** + * Test case for Maven 4 support in m2e. + * + * This test demonstrates that m2e currently does NOT support Maven 4 features. + * As Maven 4 support is implemented, this test can be enhanced to verify: + * - Model version 4.1.0 parsing + * - Subprojects support (instead of modules) + * - Inheritance of groupId and version + * - Build/Consumer POM split + * + * Based on real-world usage from https://github.com/jline/jline3 + * + * @see https://maven.apache.org/whatsnewinmaven4.html + */ +public class Maven4Test extends AbstractMavenProjectTestCase { + + @After + public void clearWorkspace() throws Exception { + for(IProject p : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { + p.delete(true, null); + } + } + + /** + * Test Maven 4 project with model version 4.1.0 and subprojects. + * + * This test attempts to import a Maven 4 project that uses: + * - Model version 4.1.0 + * - Subprojects instead of modules + * - Inheritance of groupId and version from parent + * + * Expected behavior: + * - With current m2e (Maven 3 only): This test is expected to fail or show errors + * - With Maven 4 support: This test should pass and projects should be imported correctly + */ + @Test + public void testMaven4BasicProject() throws Exception { + // Get the Maven 4 test project + File sourceDirectory = new File( + FileLocator.toFileURL(getClass().getResource("/resources/projects/HelloMaven4")).toURI()); + + assertNotNull("HelloMaven4 project directory should exist", sourceDirectory); + assertTrue("HelloMaven4 project directory should be a directory", sourceDirectory.isDirectory()); + + File parentPom = new File(sourceDirectory, "pom.xml"); + assertTrue("Parent pom.xml should exist", parentPom.exists()); + + // Attempt to import the Maven 4 project + // Note: This will likely fail with current m2e since it doesn't support Maven 4 + try { + IProject project = importProject("resources/projects/HelloMaven4/pom.xml"); + + // If we get here, the project was imported (unexpected with current m2e) + assertNotNull("Parent project should be imported", project); + + // Check if subprojects are recognized + // Note: With Maven 4 support, these should be imported as child projects + IProject helloCore = ResourcesPlugin.getWorkspace().getRoot().getProject("hello-core"); + IProject helloApp = ResourcesPlugin.getWorkspace().getRoot().getProject("hello-app"); + + // These assertions will help verify Maven 4 support when implemented + // For now, they document what should work with Maven 4 + assertNotNull("hello-core subproject should be recognized", helloCore); + assertNotNull("hello-app subproject should be recognized", helloApp); + + } catch (Exception e) { + // Expected with current m2e - Maven 4 is not yet supported + // This documents that m2e needs Maven 4 support + System.err.println("Expected failure with Maven 3 based m2e: " + e.getMessage()); + + // For now, we'll let this exception indicate Maven 4 is not supported + // When Maven 4 support is added, this test should pass without exceptions + fail("Maven 4 project import failed (expected with current m2e): " + e.getMessage()); + } + } + + /** + * Test that Maven 4 model version 4.1.0 is recognized. + * + * This is a more basic test that just checks if the model version is parsed correctly. + * When Maven 4 support is added, this should pass. + */ + @Test + public void testMaven4ModelVersion() throws Exception { + File sourceDirectory = new File( + FileLocator.toFileURL(getClass().getResource("/resources/projects/HelloMaven4")).toURI()); + File parentPom = new File(sourceDirectory, "pom.xml"); + + assertTrue("Parent pom.xml should exist", parentPom.exists()); + + // Try to read the POM + // With Maven 4 support, this should recognize the 4.1.0 model version + try { + // This will likely fail with current Maven 3 based implementation + // as it doesn't recognize model version 4.1.0 + @SuppressWarnings("unused") + IProject project = importProject("resources/projects/HelloMaven4/pom.xml"); + + // If we get here, Maven 4 model version was recognized + // This indicates Maven 4 support is working + + } catch (Exception e) { + // Expected with current m2e + System.err.println("Maven 4 model version not supported yet: " + e.getMessage()); + fail("Maven 4 model version 4.1.0 is not supported (expected with current m2e): " + e.getMessage()); + } + } +}