Skip to content
Open
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
6 changes: 6 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## 2.9.2

### Maven Execution JRE used for Tests

Similar to what is done for the Maven Launch Actions the JRE for tests (TestNG, JUnit) is now also derived from
the Maven execution JRE. Previously this was by default set to the project's JRE (derived from the `maven-compiler-plugin`s target/release configuration).
The Maven execution JRE is determined from the `maven-enforcer-plugin`s `requireJavaVersion` rule by selecting the best matching installed JRE for the [configured Java version range](https://maven.apache.org/enforcer/enforcer-rules/requireJavaVersion.html).

### Multi-Release-Jar support

JDT added support for native [https://openjdk.org/jeps/238](Multi-Release) compilation support recently.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

import java.io.File;
import java.util.List;

import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
Expand All @@ -47,68 +45,30 @@ public class MavenLaunchDelegateTest extends AbstractMavenProjectTestCase {
private static final String DEFAULT_VM = "defaultVM";
private static final List<String> AVAILABLE_VM_VERSIONS = List.of("17.0.4", "11.0.7", "13.0.5", "11.0.1", "1.8.0");

@Test
public void testGetBestMatchingVM_majorOnly() throws InvalidVersionSpecificationException {
try (var mock = mockJavaRuntime()) {
assertEquals("11.0.7", MavenLaunchDelegate.getBestMatchingVM("11").getId());
}
}

@Test
public void testGetBestMatchingVM_rangeWithOnlyMajorLowerBound() throws InvalidVersionSpecificationException {
try (var mock = mockJavaRuntime()) {
assertEquals("11.0.7", MavenLaunchDelegate.getBestMatchingVM("[11,)").getId());
}
}

@Test
public void testGetBestMatchingVM_9versionRange() throws InvalidVersionSpecificationException {
try (var mock = mockJavaRuntime()) {
assertEquals("17.0.4", MavenLaunchDelegate.getBestMatchingVM("[11,18)").getId());
}
}

@Test
public void testGetBestMatchingVM_1XversionRange() throws InvalidVersionSpecificationException {
try (var mock = mockJavaRuntime()) {
assertEquals("1.8.0", MavenLaunchDelegate.getBestMatchingVM("[1.8,9)").getId());
}
}

@Test
public void testGetBestMatchingVM_versionRangeWithNoMajorVersionMatch() {
try (var mock = mockJavaRuntime()) {
assertEquals("13.0.5", MavenLaunchDelegate.getBestMatchingVM("[12,)").getId());
}
}

@Test
public void testRequiredJavaVersionFromEnforcerRule_Version() throws Exception {
IProject project = importProject("resources/projects/enforcerSettingsWithVersion/pom.xml");
assertRequiredJavaBuildVersion(project, "13.0.3", "13.0.5");
assertRequiredJavaBuildVersion(project, "13.0.5");
}

@Test
public void testRequiredJavaVersionFromEnforcerRule_VersionRange() throws Exception {
IProject project = importProject("resources/projects/enforcerSettingsWithVersionRange/pom.xml");
assertRequiredJavaBuildVersion(project, "[11.0.6,13)", "11.0.7");
assertRequiredJavaBuildVersion(project, "11.0.7");
}

@Test
public void testRequiredJavaVersionFromEnforcerRule_NoVersionRange() throws Exception {
IProject project = importProject("resources/projects/enforcerSettingsWithoutRequiredJavaVersion/pom.xml");
assertRequiredJavaBuildVersion(project, null, DEFAULT_VM);
assertRequiredJavaBuildVersion(project, DEFAULT_VM);
}

private void assertRequiredJavaBuildVersion(IProject project, String expectedVersionRange, String expectedVMVersion)
private void assertRequiredJavaBuildVersion(IProject project, String expectedVMVersion)
throws Exception {

waitForJobsToComplete();

File pomFile = project.getLocation().toFile();

assertEquals(expectedVersionRange, MavenLaunchDelegate.readEnforcedJavaVersion(pomFile, monitor));

String pomDir = "${workspace_loc:/" + project.getName() + "}";

try (var mock = mockJavaRuntime()) {
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.m2e.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.eclipse.m2e.feature"
label="%featureName"
version="2.9.200.qualifier"
version="2.10.0.qualifier"
provider-name="%providerName"
plugin="org.eclipse.m2e.core"
license-feature="org.eclipse.license"
Expand Down
3 changes: 3 additions & 0 deletions org.eclipse.m2e.jdt.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui.tests.harness,
org.eclipse.ui,
org.eclipse.debug.ui;bundle-version="3.18.600"
Import-Package:
org.mockito,
org.mockito.stubbing
Bundle-RequiredExecutionEnvironment: JavaSE-21
Bundle-Vendor: Eclipse.org - m2e
Automatic-Module-Name: org.eclipse.m2e.jdt.tests
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*******************************************************************************
* Copyright (c) 2022, 2023 Hannes Wellmann 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:
* Hannes Wellmann - initial API and implementation
* Konrad Windszus - Add tests for required java runtime version implied by enforcer rule
*******************************************************************************/

package org.eclipse.m2e.jdt.tests;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

import java.util.List;

import org.eclipse.jdt.internal.launching.StandardVMType;
import org.eclipse.jdt.launching.AbstractVMInstall;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.IVMInstallType;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.m2e.jdt.MavenExecutionJre;
import org.eclipse.m2e.tests.common.AbstractMavenProjectTestCase;
import org.junit.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

@SuppressWarnings("restriction")
public class MavenExecutionJreTest extends AbstractMavenProjectTestCase {

private static final String DEFAULT_VM = "defaultVM";
private static final List<String> AVAILABLE_VM_VERSIONS = List.of("17.0.4", "11.0.7", "13.0.5", "11.0.1", "1.8.0");

@Test
public void testGetBestMatchingVM_majorOnly() {
try (var mock = mockJavaRuntime()) {
assertEquals("11.0.7", MavenExecutionJre.getBestMatchingVM("11").get().getId());
}
}

@Test
public void testGetBestMatchingVM_rangeWithOnlyMajorLowerBound() {
try (var mock = mockJavaRuntime()) {
assertEquals("11.0.7", MavenExecutionJre.getBestMatchingVM("[11,)").get().getId());
}
}

@Test
public void testGetBestMatchingVM_9versionRange() {
try (var mock = mockJavaRuntime()) {
assertEquals("17.0.4", MavenExecutionJre.getBestMatchingVM("[11,18)").get().getId());
}
}

@Test
public void testGetBestMatchingVM_1XversionRange() {
try (var mock = mockJavaRuntime()) {
assertEquals("1.8.0", MavenExecutionJre.getBestMatchingVM("[1.8,9)").get().getId());
}
}

@Test
public void testGetBestMatchingVM_versionRangeWithNoMajorVersionMatch() {
try (var mock = mockJavaRuntime()) {
assertEquals("13.0.5", MavenExecutionJre.getBestMatchingVM("[12,)").get().getId());
}
}

private static MockedStatic<JavaRuntime> mockJavaRuntime() {
IVMInstall defaultVM = Mockito.mock(IVMInstall.class);
Mockito.when(defaultVM.getId()).thenReturn(DEFAULT_VM);

IVMInstallType standardVMType = Mockito.mock(StandardVMType.class, Mockito.CALLS_REAL_METHODS);
IVMInstall[] installs = AVAILABLE_VM_VERSIONS.stream().map(version -> {
AbstractVMInstall vm = Mockito.mock(AbstractVMInstall.class, Mockito.CALLS_REAL_METHODS);
when(vm.getId()).thenReturn(version);
when(vm.getJavaVersion()).thenReturn(version);
when(vm.getVMInstallType()).thenReturn(standardVMType);
when(vm.getName()).thenReturn("JDK " + version);
return vm;
}).toArray(IVMInstall[]::new);
Mockito.doReturn(installs).when(standardVMType).getVMInstalls();

MockedStatic<JavaRuntime> javaRuntimeMock = Mockito.mockStatic(JavaRuntime.class, Mockito.CALLS_REAL_METHODS);
javaRuntimeMock.when(JavaRuntime::getVMInstallTypes).thenReturn(new IVMInstallType[] { standardVMType });
javaRuntimeMock.when(() -> JavaRuntime.computeVMInstall(Mockito.any())).thenReturn(defaultVM);
return javaRuntimeMock;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void test_configuration_must_be_updated_with_surefire_config()
ILaunchConfiguration config = updatedConfigurations[0];

// check argLine
String argLine = config.getAttribute(UnitTestSupport.LAUNCH_CONFIG_VM_ARGUMENTS, "");
String argLine = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "");
assertTrue(argLine.contains("--argLineItem=surefireArgLineValue"));

// check environmentVariables
Expand Down Expand Up @@ -208,7 +208,7 @@ public void test_configuration_must_be_updated_with_failsafe_config()
ILaunchConfiguration config = updatedConfigurations[0];

// check argLine
String argLine = config.getAttribute(UnitTestSupport.LAUNCH_CONFIG_VM_ARGUMENTS, "");
String argLine = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "");
assertTrue(argLine.contains("--argLineItem=failsafeArgLineValue"));

// check environmentVariables
Expand Down Expand Up @@ -260,7 +260,7 @@ public void test_configuration_must_be_updated_with_surefire_config_when_created
ILaunchConfiguration config = updatedConfigurations[0];

// check argLine
String argLine = config.getAttribute(UnitTestSupport.LAUNCH_CONFIG_VM_ARGUMENTS, "");
String argLine = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "");
assertTrue(argLine.contains("--argLineItem=surefireArgLineValue"));

// check environmentVariables
Expand Down Expand Up @@ -309,7 +309,7 @@ public void test_configuration_must_be_updated_with_failSafe_config_when_created
ILaunchConfiguration config = updatedConfigurations[0];

// check argLine
String argLine = config.getAttribute(UnitTestSupport.LAUNCH_CONFIG_VM_ARGUMENTS, "");
String argLine = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "");
assertTrue(argLine.contains("--argLineItem=failsafeArgLineValue"));

// check environmentVariables
Expand Down Expand Up @@ -353,7 +353,7 @@ public void test_deferred_variable_are_resolved() throws CoreException, IOExcept
assertTrue(updatedConfigurations.length == 1);

ILaunchConfiguration config = updatedConfigurations[0];
String argLine = config.getAttribute(UnitTestSupport.LAUNCH_CONFIG_VM_ARGUMENTS, "");
String argLine = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "");
assertTrue(argLine.contains("-javaagent")); // resolved jacoco agent
assertTrue(argLine.contains("@{titi.tata}")); // unresolved property is unchanged as in CLI
}
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.m2e.jdt/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.m2e.jdt;singleton:=true
Bundle-Version: 2.4.200.qualifier
Bundle-Version: 2.5.0.qualifier
Bundle-Localization: plugin
Export-Package: org.eclipse.m2e.jdt,
org.eclipse.m2e.jdt.internal;x-friends:="org.eclipse.m2e.jdt.ui",
Expand Down
Loading
Loading