-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat: Add Java Module #314
feat: Add Java Module #314
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jakubclark, thanks for the PR!
This is looking pretty good already. You'll need to make a few minor changes due to a new PR that just got merged (sorry about the crummy timing) and there are a few questions I have, but the code is almost ready to merge (aside from those annoying version number issues you seem to be running into).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few minor styling + comment nitpicks and then we'll be good to go, I think!
docs/config/README.md
Outdated
| Variable | Default | Description | | ||
| ---------- | -------------- | -------------------------------------------------------- | | ||
| `symbol` | `"☕ "` | The symbol used before displaying the version of Java. | | ||
| `style` | `"bold RGB(166, 42, 42)"` | The style for the module. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The syntax for colors is #RRGGBB
, so the style would be bold #a62a2a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think built-in modules should probably all use the 16 ANSI colors to remain compatible with as many emulators and configurations as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can change it to be red instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't think about that. This is probably right. The color appears to be a darker version of the red color, perhaps dimmed red
would be a good color?
36c2ad4
to
f8f72eb
Compare
@chipbuster I've addressed your comments. Let me know if there is anything else to change! |
@jakubclark I'm really sorry about this, I should have done this a little sooner. I just pulled and tested the prompt from your fork, and the addition of the java module tanks performance. To give you an idea, we can get directory, git branch, git status, package, rust, and python info in 28ms, but adding a single java file raises that to 137.3ms. Do you have any ideas on how we could potentially mitigate this timing problem? I can tell you that it's definitely noticeable--the reason I reached for hyperfine was because I was surprised at how slow the prompt felt. Maybe it would be possible to parse the information out of With the current speeds I'm seeing, I don't think we can justify putting this module into the prompt :\ |
@chipbuster I'll try getting the version from I just chose I'll do some performance testing and post the results here. |
@jakubclark Thanks. I think the number we'd love to hit for java module render (via |
@chipbuster Unfortunately, using Looks like |
@jakubclark Damn 😞 Unfortunately, while we're building towards support for several things that could help to mitigate this, like disabled-by-default modules, timeouts, caching data, and (perhaps someday) asynchronous rendering, none of those are quite ready at the moment. I'm afraid we might have to put this PR on hold until one of those comes in. If you figure out some way to get the module time down without those, let us know and we'll be happy to merge this in! |
I had a similar issue when I tried to implement #182 - I'm considering implementing the version detection myself 😅 |
At least on OSX the openjdk jvm installed a release file, I was able to get the version number under 5ms.
If JAVA_HOME is not set this could be used
Not sure for other OSes but caching |
Just found out there is an option
On my Linux it is even below 5ms. I tried to add this functionallity, but more testing is needed. hdevalke@51428ed |
@hdevalke I think the Assuming the existence of any paths is a slightly dicey proposition, because we're making it a goal to (eventually) support all OSses, including things like BSDs, Windows, and Android (in Termux), so I'd prefer not to go for the @jakubclark Would you still be interested in working on this? |
@chipbuster @hdevalke I'll try using |
eae284c
to
bada063
Compare
Get java version from internalversion system property
74ac6cc
to
b095738
Compare
I get no noticeable difference on my Linux machine either. Looks like we got that timing issue nailed! Great work, and thanks to @hdevalke for the hint! Do you know if this works cross-platform with both OpenJDK/JRE and Oracle Java? I can try to test this out in a docker container later if you don't know. |
src/modules/java.rs
Outdated
} | ||
|
||
fn get_java_version() -> Option<String> { | ||
match Command::new("java").arg("-Xinternalversion").output() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we take into account the JAVA_HOME
variable?
If exists the version could be $JAVA_HOME/bin/java -Xinternalversion
.
When using maven it will take priority over the java binary in the PATH
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea. I'm not a fan of relying on JAVA_HOME being set (simply because half the envars that really ought to be set usually aren't), but I think checking for the existence of a JAVA_HOME variable should be more than fast enough.
Do you know if that variable gets set on Windows as well, or is that a UNIX-like-only thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answer to my own question: it seems like (as with many envars) it's supposed to be set on windows, but a lot of installers fail to do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's necessary to check $JAVA_HOME
. Running $JAVA_HOME/bin/java -Xinternalversion
should be identical to running java -Xinternalversion
. If java
isn't on the PATH
environment variable, then Java simply isn't set up properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's to say that if you set up a (maven?) environment, the PATH should automatically modify to put the newly-versioned Java binary first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.baeldung.com/maven-java-home-jdk-jre
First checks $JAVA_HOME
, otherwise defaults to java
on the $PATH
.
But I've never had to set up separate Java installations and setting up $JAVA_HOME
for different projects...
So maybe we should follow the same strategy as Maven:
Check for $JAVA_HOME
.
Otherwise just use the java
that is on the $PATH
.
@chipbuster I have Oracle Java installed and it works for me. Also, the result of running So I think it's safe to say that this works for both OpenJDK and Oracle versions. |
Alright, excellent. Looks like our CI is failing the standard test suite, though not the containerized tests...do we potentially have a test somewhere that should be |
For the test suites, I don't know what the issue is. Could be that the result of running |
66944cc
to
3487b8f
Compare
@chipbuster any suggestions on how to debug the Test Suites? I tried printing some data using |
@jakubclark Unfortunately, the CI is not my specialty. Looking at the logs, it looks like the Java version simply isn't being detected at all (the actual string for the Java version is just a Perhaps you could try something like // whatever you need to get the full version string here
let ver = std::command::process("java")...
assert_eq!(ver,"nope"); This will obviously fail, but it'll let you see what's going on when you try call the java binary to get the version. |
As this fails on Zulu maybe we could check the length of the version to be not zero: if end == start {
None
} else {
Some(format!("v{}", &java_stdout[start..end]))
} Support for openjdk could be the MVP, other JVM variants could be added later on. |
I tested some other jvm builds: for image in {azul/zulu-openjdk,adoptopenjdk,amazoncorretto}; do docker run --rm $image java -Xinternalversion; done
OpenJDK 64-Bit Server VM (25.222-b10) for linux-amd64 JRE (Zulu 8.40.0.25-CA-linux64) (1.8.0_222-b10), built on Jul 11 2019 11:36:39 by "zulu_re" with gcc 4.4.7 20120313 (Red Hat 4.4.7-3)
OpenJDK 64-Bit Server VM (12.0.2+10) for linux-amd64 JRE (12.0.2+10), built on Jul 18 2019 14:41:47 by "jenkins" with gcc 7.3.1 20180303 (Red Hat 7.3.1-5)
OpenJDK 64-Bit Server VM (25.222-b10) for linux-amd64 JRE (1.8.0_222-b10), built on Jul 11 2019 20:48:53 by "root" with gcc 7.3.1 20180303 (Red Hat 7.3.1-5) |
I think you're right @hdevalke. It's at least a start. |
Okay, I think this PR is (finally) in a state that it can be merged. It's able to extract the java version from the The Zulu distribution that comes with We could include a local copy of the jdkFile from a specific vendor, but I don't think it makes sense to keep an entire JDK in this repo. Thanks for all your comments and suggestions @chipbuster and @hdevalke ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor doc nitpick: do we need to update this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for sticking through the (somewhat prolonged) process!
Once this passes CI, we'll go ahead and merge it in.
At least now we know a number of ways to get the Java version 😄 |
That we do! It's why I love working on these projects--you're never quite sure what you're going to learn next. |
Woo! What a marathon of an issue. Thanks for all your work and for sticking it out! @all-contributors, please add @jakubclark for code, doc, and tests. |
I've put up a pull request to add @jakubclark! 🎉 |
@all-contributors please also add @hdevalke for their invaluable ideas on this PR. |
I've put up a pull request to add @hdevalke! 🎉 |
Thank you! |
I've updated the pull request to add @hdevalke! 🎉 |
Implemented a basic
Java
module, that shows theJava
version, when inside a Java/Maven Project.Description
java
that callsjavac --version
, to get the version of Javajavac
Dockerfile
to installJava
Motivation and Context
Just another language that can be supported.
Types of changes
Screenshots (if appropriate):
MacOS:
Linux (WSL):
How Has This Been Tested?
Checklist: