Skip to content

Commit

Permalink
Fix OsgiCompilerTest for Java 21 JVM
Browse files Browse the repository at this point in the history
That test expects the byte code level to not be influenced by settings
in POM or manifest. Therefore it must match the JVM level.
  • Loading branch information
Bananeweizen authored and laeubi committed Jun 2, 2024
1 parent a20b8bb commit d896e75
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void testClasspath() throws Exception {
assertEquals(getClasspathElement(new File(getBasedir()), nestedJarPath, "[?**/*]"), cp.get(1));
assertEquals(getClasspathElement(project.getBasedir(), "target/classes", ""), cp.get(2));

// project with a (not yet) existing nested jar that would be copied later during build
// project with a (not yet) existing nested jar that would be copied later during build
// (wrapper scenario with copy-pom-dependencies)
// project = projects.get(4);
// mojo = getMojo(projects, project);
Expand Down Expand Up @@ -260,11 +260,13 @@ public void testSourceCompileLevel() throws Exception {
File basedir = getBasedir("projects/executionEnvironment");
List<MavenProject> projects = getSortedProjects(basedir);
MavenProject project;
// project with neither POM nor MANIFEST configuration => must fallback to
// source/target level == 17
// project with neither POM nor MANIFEST configuration => must fallback to
// source/target level of the JVM
project = projects.get(1);
getMojo(projects, project).execute();
assertBytecodeMajorLevel(61 /* Java 17 */, new File(project.getBasedir(), "target/classes/Generic.class"));
// Java 17 -> 61, Java 21 -> 65
assertBytecodeMajorLevel(Runtime.version().feature() + 44,
new File(project.getBasedir(), "target/classes/Generic.class"));

// project with multiple execution envs.
// Minimum source and target level must be taken
Expand All @@ -277,7 +279,7 @@ public void testSourceCompileLevel() throws Exception {
} catch (CompilationFailureException e) {
// expected
}
// project with both explicit compiler configuration in pom.xml and Bundle-RequiredExecutionEnvironment.
// project with both explicit compiler configuration in pom.xml and Bundle-RequiredExecutionEnvironment.
// explicit compiler configuration in the pom should win. see https://issues.sonatype.org/browse/TYCHO-476
project = projects.get(3);
mojo = getMojo(projects, project);
Expand All @@ -291,8 +293,8 @@ public void testSourceCompileLevel() throws Exception {
mojo = getMojo(projects, project);
mojo.execute();
assertEquals("1.3", mojo.getSourceLevel());
// project with both explicit compiler configuration in build.properties and Bundle-RequiredExecutionEnvironment.
// build.properties should win.
// project with both explicit compiler configuration in build.properties and Bundle-RequiredExecutionEnvironment.
// build.properties should win.
project = projects.get(5);
mojo = getMojo(projects, project);
mojo.execute();
Expand Down Expand Up @@ -451,7 +453,7 @@ public void warn(CharSequence content) {
}

public void testUseProjectSettingsSetToTrue() throws Exception {
// the code in the project does use boxing and the settings file
// the code in the project does use boxing and the settings file
// turns on warning for auto boxing so we expect here a warning
File basedir = getBasedir("projects/projectSettings/p001");
List<MavenProject> projects = getSortedProjects(basedir);
Expand Down Expand Up @@ -530,7 +532,7 @@ public void testBreeCompilerTargetCompatibilityIsChecked() throws Exception {
MavenProject project = projects.get(0);
MojoExecutionException e = assertThrows(MojoExecutionException.class,
() -> getMojo(projects, project).execute());
// assert that the compiler mojo checks the target levels of all BREEs (and not just the first or "minimal" one)
// assert that the compiler mojo checks the target levels of all BREEs (and not just the first or "minimal" one)
assertThat(e.getMessage(), containsString(
"The effective compiler target level 1.5 is incompatible with the following OSGi execution environments"));
assertThat(e.getMessage(), containsString("J2SE-1.2"));
Expand Down

0 comments on commit d896e75

Please sign in to comment.