Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i888 Use correct java compiler for JUnit tests #895

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

johnbrvc
Copy link
Collaborator

Description of what the PR does

Since Eclipse 4.17 (2020-09), Java 11 (or newer) is the default JDK that ships with Eclipse. Previously, it was Java 8 (1.8). This PR attempts to track down the correct JDK to use for compiling the JUnit test programs. The JDK must match the currently running JVM in order to qualify. A search of the JAVA_HOME/bin and folders on the PATH environment variable are checked for the presence of the corresponding JDK (javac[.exe]). The code only checks for the presence of the Java version string in the folder name. It could be expanded to actually attempt to run "javac -version" in each folder, but that shouldn't be necessary, and is highly inefficient.

The reason for this PR is that the JUnits requiring compiles were using Eclipse's JDK (Version >11), but attempting to execute the produced class files using JRE 1.8. This lead to the errors described in #888.

Issue which the PR addresses

Fixed #888

Environment in which the PR was developed (OS,IDE, Java version, etc.)

Windows 11
Eclipse 2021-12, with JVM org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.1.v20211116-1657
JDK 1.8.0_351

Precise steps for testing the PR (i.e., how to demonstrate that it works correctly)

Run all JUnits. They should pass now. Previously, the ones in #888 (ExecuteTest, among others) did not pass.

@troy2914
Copy link
Contributor

troy2914 commented Dec 10, 2023

Tested with jdk17 as first in my PATH (and only java in my PATH), generated a version 61.0 PracticeA.class
added my Amazon Corretto 8 to the end my PATH /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/bin,
still generated a version 61.0 class.

@troy2914
Copy link
Contributor

btw, standard location on MacOS is for the jdk to be under
/Library/Java/JavaVirtualMachines
where I have

/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk
/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk
/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk
/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk
/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk
/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk
/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk
/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk

along with the amazon-corretto one

@johnbrvc

This comment was marked as resolved.

@johnbrvc
Copy link
Collaborator Author

Tested with jdk17 as first in my PATH (and only java in my PATH), generated a version 61.0 PracticeA.class added my Amazon Corretto 8 to the end my PATH /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/bin, still generated a version 61.0 class.

Changed so it actually runs "javac -version" on every javac or javac.exe on the JAVA_HOME/bin and PATH until it finds one that matches instead of just looking for the version in the folder string.

@johnbrvc

This comment was marked as resolved.

@johnbrvc johnbrvc requested review from lane55 and troy2914 and removed request for lane55 December 13, 2023 03:29
@johnbrvc johnbrvc self-assigned this Dec 13, 2023
@johnbrvc johnbrvc added this to the 9.10.0 milestone Dec 13, 2023
Since Eclipse 4.17 (2020-09), Java 11 is the default JDK that ships with Eclipse.  Previously, it was Java 8 (1.8).
This PR attempts to track down the correct JDK to use for compiling the JUnit test programs.  The JDK must match the currently running JVM in order to qualify.  A search of  the JAVA_HOME/bin and folders on the PATH environment variable are checked for the presence of the corresponding JDK (javac[.exe]).
The code only checks for the presence of the java version string in the folder name.  It could be expanded to actually attempt to run "javac -version" in each folder, but that shouldn't be necessary.
In order to track down the correct JDK to use for building java applications as part of a JUnit, we try each folder of: JAVA_HOME/bin, and PATH components until we find one that matches the JRE.
@johnbrvc johnbrvc force-pushed the i_888_test_units_fail_windows_mac branch from 50fbeff to c02d82e Compare December 17, 2023 22:14
@troy2914 troy2914 modified the milestones: 9.10.0, 9.11.0 Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test units fail when run as part of a package build on Windows/MacOS
2 participants