Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Fix detection of Javac version #1037

Merged
merged 2 commits into from
Jan 3, 2018
Merged

Fix detection of Javac version #1037

merged 2 commits into from
Jan 3, 2018

Conversation

rosen-vladimirov
Copy link
Collaborator

The command javac -version prints result to stderr when JAVA 8 is used and to stdout when JAVA 9 is used. Current check in CLI uses the stderr output, so when JAVA 9 is installed it fails to detect the correct version.
In order to support both JAVA 8 and JAVA 9, capture both stdout and stderr and get the version from there.
Also remove unneeded check for Java version - we care about JAVA Compiler, which is included in JDK.

The command `javac -version` prints result to stderr when JAVA 8 is used and to stdout when JAVA 9 is used. Current check in CLI uses the stderr output, so when JAVA 9 is installed it fails to detect the correct version.
In order to support both JAVA 8 and JAVA 9, capture both stdout and stderr and get the version from there.
Also remove unneeded check for Java version - we care about JAVA Compiler, which is included in JDK.
});

it("returns correct javac version when it is printed on stdout (Java 9)", () => {
return verifyJavaCompilerVersion("9.0.1", "stdout");
Copy link
Contributor

Choose a reason for hiding this comment

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

@rosen-vladimirov some distributions of java return 9 when java -version is called, in which case I think the regex might break. I haven't tested it but I encountered such an issue in the past.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for pointing this. In case 9 is returned, the current code will work fine, but this one will fail. I'll handle the case there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@rosen-vladimirov I tested it, and CLI provides a message to install java 1.8.0.

Improve `appendZeroesToVersion` method to return the passed value in case it is null, undefined or empty string and add tests for the method.
Copy link
Contributor

@Mitko-Kerezov Mitko-Kerezov left a comment

Choose a reason for hiding this comment

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

Looks all right to me

@rosen-vladimirov rosen-vladimirov merged commit d3fa315 into master Jan 3, 2018
@rosen-vladimirov rosen-vladimirov deleted the vladimirov/java-9 branch January 3, 2018 07:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants