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

fix: detect JAVA_HOME with Java 11 #1406

Merged
merged 1 commit into from
Mar 17, 2022
Merged

fix: detect JAVA_HOME with Java 11 #1406

merged 1 commit into from
Mar 17, 2022

Conversation

ltm
Copy link
Contributor

@ltm ltm commented Mar 11, 2022

Platforms affected

Linux and Windows

Motivation and Context

Starting with Java 9 the JRE and JDK no longer include tools.jar as described in JEP 220. As a result the check_java function is unable to detect a Java 11 installation unless the JAVA_HOME environment variable is set manually:

var maybeJavaHome = path.dirname(path.dirname(javacPath));
if (fs.existsSync(path.join(maybeJavaHome, 'lib', 'tools.jar'))) {

The check for tools.jar appears to have been added in commit 7133576.

Description

This change instead checks for the presence of ${maybeJavaHome}/bin/java or ${maybeJavaHome}/bin/java.exe. This is similar to the checks performed by gradlew and gradlew.bat.

Testing

On Debian 11:

$ readlink -f $(which javac)
/usr/lib/jvm/java-11-openjdk-amd64/bin/javac
$ ls /usr/lib/jvm/java-11-openjdk-amd64/lib/tools.jar
ls: cannot access '/usr/lib/jvm/java-11-openjdk-amd64/lib/tools.jar': No such file or directory
$ ls /usr/lib/jvm/java-11-openjdk-amd64/bin/java
/usr/lib/jvm/java-11-openjdk-amd64/bin/java

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

@codecov-commenter
Copy link

Codecov Report

Merging #1406 (c794ee5) into master (6d3ce21) will decrease coverage by 0.06%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1406      +/-   ##
==========================================
- Coverage   73.20%   73.14%   -0.07%     
==========================================
  Files          21       21              
  Lines        1646     1646              
==========================================
- Hits         1205     1204       -1     
- Misses        441      442       +1     
Impacted Files Coverage Δ
lib/env/java.js 98.00% <100.00%> (ø)
lib/check_reqs.js 69.62% <0.00%> (-0.75%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6d3ce21...c794ee5. Read the comment docs.

@breautek breautek requested a review from erisu March 16, 2022 14:04
Copy link
Member

@erisu erisu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@breautek
Copy link
Contributor

Looks good, thanks for the well documented PR and fix!

@breautek breautek merged commit 112f0a6 into apache:master Mar 17, 2022
@ltm ltm deleted the fix-detect-java11 branch March 21, 2022 14:48
wedgberto pushed a commit to wedgberto/cordova-android that referenced this pull request May 17, 2022
ebhsgit added a commit to ebhsgit/cordova-android that referenced this pull request May 25, 2022
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.

4 participants