forked from LWJGL/lwjgl3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core) impl version lookup on module path
- Package::getImplementationVersion is unspecified when loading a JAR file from the module path. The new multi-release code uses the module descriptor to retrieve the implementation version. - Restored code that retrieves the implementation version from the JAR manifest, as a fallback. Also added the suggested fix from LWJGL#644, when running on a GraalVM native image. - Changed the LWJGL version string to match the Java version format. Close LWJGL#770 Co-authored-by: Leon Linhart <themrmilchmann@gmail.com>
- Loading branch information
Showing
4 changed files
with
160 additions
and
4 deletions.
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
32 changes: 32 additions & 0 deletions
32
modules/lwjgl/core/src/main/java/org/lwjgl/VersionImpl.java
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,32 @@ | ||
/* | ||
* Copyright LWJGL. All rights reserved. | ||
* License terms: https://www.lwjgl.org/license | ||
*/ | ||
package org.lwjgl; | ||
|
||
/** | ||
* Finds the LWJGL implementation version (build type/number). | ||
* | ||
* <p>Base implementation for Java 8. When run in the module path, it cannot find the implementation version without reading the JAR manifest. See the | ||
* {@code lwjgl.core9} module for the module-aware implementation.</p> | ||
*/ | ||
final class VersionImpl { | ||
|
||
static String find() { | ||
Package org_lwjgl = Version.class.getPackage(); | ||
|
||
String specVersion = org_lwjgl.getSpecificationVersion(); | ||
String implVersion = org_lwjgl.getImplementationVersion(); | ||
if (specVersion != null && implVersion != null) { | ||
return Version.createImplementation(specVersion, implVersion); | ||
} | ||
|
||
String version = Version.findImplementationFromManifest(); | ||
if (version != null) { | ||
return version; | ||
} | ||
|
||
return "-snapshot"; | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
modules/lwjgl/core/src/main/java9/org/lwjgl/VersionImpl.java
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,51 @@ | ||
/* | ||
* Copyright LWJGL. All rights reserved. | ||
* License terms: https://www.lwjgl.org/license | ||
*/ | ||
package org.lwjgl; | ||
|
||
import java.lang.module.*; | ||
|
||
/** | ||
* Finds the LWJGL implementation version (build type/number). | ||
* | ||
* <p>Module-aware implementation for Java 9 or higher.</p> | ||
*/ | ||
final class VersionImpl { | ||
|
||
static String find() { | ||
Package org_lwjgl = Version.class.getPackage(); | ||
|
||
String specVersion = org_lwjgl.getSpecificationVersion(); | ||
String implVersion = org_lwjgl.getImplementationVersion(); | ||
if (specVersion != null && implVersion != null) { | ||
return Version.createImplementation(specVersion, implVersion); | ||
} | ||
|
||
Module module = Version.class.getModule(); | ||
if ("org.lwjgl".equals(module.getName())) { | ||
String moduleVersion = module.getDescriptor() | ||
.version() | ||
.map(ModuleDescriptor.Version::toString) | ||
.orElse(null); | ||
|
||
if (moduleVersion != null) { | ||
int plusIndex = moduleVersion.indexOf('+'); | ||
if (plusIndex != -1) { | ||
return Version.createImplementation( | ||
moduleVersion.substring(0, plusIndex), | ||
moduleVersion.substring(plusIndex + 1) | ||
); | ||
} | ||
} | ||
} | ||
|
||
String version = Version.findImplementationFromManifest(); | ||
if (version != null) { | ||
return version; | ||
} | ||
|
||
return "-snapshot"; | ||
} | ||
|
||
} |