-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Checking Java version on startup #3418
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.jabref.logic.util; | ||
|
||
import java.util.Scanner; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Provides simple checks to ensure the correct version for JabRef is available. Currently, we need to make sure that we | ||
* have Java 1.8 but not Java 9. The functions here are not intended for direct use. Instead, they are called inside | ||
* {@link BuildInfo}, which has the required java version string (e.g. 1.8.0_144) available through the build system. | ||
* The version check should always happen through the <code>Globals#BUILD_INFO</code> instance which is available at a | ||
* very early stage in the JabRef startup. | ||
*/ | ||
public class JavaVersion { | ||
|
||
// See http://openjdk.java.net/jeps/223 | ||
private static final Pattern DELIMITER = Pattern.compile("[._\\-+]"); | ||
private final String JAVA_VERSION; | ||
|
||
public JavaVersion() { | ||
// Be adventurous and assume that we can always access this property! | ||
JAVA_VERSION = System.getProperty("java.version"); | ||
} | ||
|
||
public JavaVersion(final String version) { | ||
JAVA_VERSION = version; | ||
} | ||
|
||
/** | ||
* Tries to determine if we are running on Java 9. This test should return false, when we cannot extract the correct | ||
* Java version. Note that Java 9 has a different version scheme like "9-internal". | ||
* | ||
* @return true if Java 9 is used | ||
*/ | ||
public boolean isJava9() { | ||
if (JAVA_VERSION != null) { | ||
// Since isAtLeast is very optimistic, we first need to check if we have a "number" in the version string | ||
// at all. Otherwise we would get false-positives. | ||
final Scanner scanner = new Scanner(JAVA_VERSION); | ||
scanner.useDelimiter(DELIMITER); | ||
if (scanner.hasNextInt()) { | ||
return isAtLeast("1.9"); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* A very optimistic test for ensuring we at least have a minimal required Java version. It will not fail when we | ||
* cannot determine the result. In essence, this method splits a version string using {@link | ||
* JavaVersion#DELIMITER} and compares two version number by number. | ||
* | ||
* @param version Should be in the form X.X.X_XXX where X are integers. | ||
* @return true if the numbers in version available for comparison are all greater-equals the currently running Java | ||
* version. | ||
*/ | ||
public boolean isAtLeast(final String version) { | ||
if (JAVA_VERSION == null || version == null) { | ||
return true; | ||
} | ||
final Scanner scannerRunningVersion = new Scanner(JAVA_VERSION); | ||
final Scanner scannerRequiredVersion = new Scanner(version); | ||
scannerRunningVersion.useDelimiter(DELIMITER); | ||
scannerRequiredVersion.useDelimiter(DELIMITER); | ||
while (scannerRunningVersion.hasNextInt() && scannerRequiredVersion.hasNextInt()) { | ||
final int running = scannerRunningVersion.nextInt(); | ||
final int required = scannerRequiredVersion.nextInt(); | ||
if (running == required) continue; | ||
return running >= required; | ||
} | ||
return true; | ||
} | ||
|
||
public String getJavaVersion() { | ||
return JAVA_VERSION; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since we are trying to move to JavaFX, would it be possible to display the error message with a FX window instead of a
JFrame
?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.
Have a look at the FXDialogService.class. there are already some predefined dialogs for fx
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.
@Siedlerchr @lenhard That was on purpose. I was using
JFrame
because what good will it be if I check the Java version, try to display a message and crash with an exception because FX is not available? 😄Can we safely assume the FXDialog will always work?
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.
@lenhard I made JabRef quit only when Java 9 is used. Otherwise it displays the message but continues
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.
@halirutan if no openjfx is avaiable it will crash nonetheless because the JabRef main inherits from Application (javafx.application.Application). That is the thing which you can't check for directly.
The only thing would be we use a "Pre-Main-Class" that does nit depend on javafx. But I am unsure if this would work
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.
@Siedlerchr Ha.. overlooked this. My genius idea was to put the test at the very beginning before any of the fx stuff is instantiated. OK, I'm looking into fx dialog tonight.