Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Commit 5bcdb3e

Browse files
authored
Merge pull request #29 from LabyMod/develop
Update 0.3.4
2 parents fe14b0b + 437fe36 commit 5bcdb3e

File tree

29 files changed

+954
-372
lines changed

29 files changed

+954
-372
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ jobs:
9292
run: "chmod +x gradlew"
9393
- name: Build base with gradle
9494
run: "./gradlew -PCI=true -PnativeBinaryExternalDir=native-binaries ultralight-java-base:build"
95-
- name: Build lwjgl3-opengl with gradle
96-
run: "./gradlew -PCI=true -PnativeBinaryExternalDir=native-binaries ultralight-java-lwjgl3-opengl:build"
95+
- name: Build lwjgl3-opengl example with gradle
96+
run: "./gradlew -PCI=true -PnativeBinaryExternalDir=native-binaries example:lwjgl3-opengl:build"
9797
- name: Check license
9898
run: "./gradlew licenseCheck"
9999
- name: Deploy to OSSHR

README.md

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,54 @@ based UI, while staying with the Java platform.
2626
Moreover, the databind API is capable of translating Java objects directly to JavaScript, allowing interop and Java
2727
calls directly from within your JavaScript code, making integration with the UI even easier.
2828

29+
# Using the library
30+
The library requires the Ultralight SDK, which can be downloaded
31+
[here](https://github.com/ultralight-ux/Ultralight/blob/master/README.md#getting-the-latest-sdk). The native binaries of
32+
the SDK need to be available at runtime and can be loaded using the provided Java methods.
33+
34+
### Maven
35+
Using the library with maven:
36+
```xml
37+
<dependency>
38+
<groupId>com.labymedia</groupId>
39+
<artifactId>ultralight-java-base</artifactId>
40+
<!-- Replace with latest version from https://search.maven.org/artifact/com.labymedia/ultralight-java-base !-->
41+
<version>0.3.4</version>
42+
</dependency>
43+
```
44+
45+
If you need Javascript interop:
46+
```xml
47+
<dependency>
48+
<groupId>com.labymedia</groupId>
49+
<artifactId>ultralight-java-databind</artifactId>
50+
<!-- Replace with latest version from https://search.maven.org/artifact/com.labymedia/ultralight-java-databind !-->
51+
<version>0.3.4</version>
52+
</dependency>
53+
```
54+
55+
### Gradle
56+
```kotlin
57+
dependencies {
58+
// Replace with latest version from https://search.maven.org/artifact/com.labymedia/ultralight-java-base
59+
implementation("com.labymedia", "ultralight-java-base", "0.3.4")
60+
61+
// // Replace with latest version from https://search.maven.org/artifact/com.labymedia/ultralight-java-databind
62+
// Remove the comments if you need Javascript interop
63+
// implementation("com.labymedia", "ultralight-java-databind", "0.3.4")
64+
}
65+
```
66+
67+
The latest version can usually also be found in the
68+
[VERSION file on the master branch](https://github.com/LabyMod/ultralight-java/blob/master/VERSION).
69+
70+
**You will also need to download the Ultralight SDK and extract the `bin` folder into a directory given to
71+
the Library in order to provide the natives!**
72+
73+
See [Examples](https://github.com/LabyMod/ultralight-java/tree/develop/example) for more info.
74+
2975
# Licensing
3076
For Ultralight Java [LGPLv3](https://www.gnu.org/licenses/lgpl-3.0.en.html) is being used, however, Ultralight itself is
3177
licensed under a custom proprietary license. See
3278
[Ultralight licensing](https://github.com/ultralight-ux/Ultralight/blob/master/README.md#licensing) for further
3379
information.
34-
35-
# Using the library
36-
The library requires the Ultralight SDK, which can be downloaded
37-
[here](https://github.com/ultralight-ux/Ultralight/blob/master/README.md#getting-the-latest-sdk). The native binaries of
38-
the SDK need to be available at runtime and can be loaded using the provided Java methods.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.3
1+
0.3.4

ci.gradle

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,77 @@
11
import org.apache.tools.ant.taskdefs.condition.Os
22

3+
// This is the directory the library headers will be generated in
34
ext.generatedHeadersDir = new File(buildDir, "generatedHeaders")
45
if(!ext.generatedHeadersDir.exists() && !ext.generatedHeadersDir.mkdirs()) {
56
throw new GradleException("Failed to create directory ${ext.generatedHeadersDir.absolutePath}")
67
}
78

9+
// This is the directory where the native binaries can be found after compilation
810
ext.nativeBinariesDir = new File(buildDir, "nativeBinaries")
911
if(!ext.nativeBinariesDir.exists() && !ext.nativeBinariesDir.mkdirs()) {
1012
throw new GradleException("Failed to create directory ${ext.nativeBinariesDir.absolutePath}")
1113
}
1214

15+
// Properties determining the build type
1316
def isExternalBuild = false
1417
def ciBuild = project.hasProperty("CI") && Boolean.parseBoolean(project.property("CI").toString())
1518

1619
if(!project.hasProperty("nativeBinaryExternalDir")) {
17-
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
20+
// The binaries will possibly be need to be built locally
21+
if(Os.isFamily(Os.FAMILY_WINDOWS)) {
1822
// WARNING, this assumes CMake uses visual studio
1923
// For GCC or Clang the output should be $nativeBinariesDir/libultralight-java.dll
2024
ext.nativeBinaries = Arrays.asList(new File(nativeBinariesDir, "Debug/ultralight-java.dll"))
21-
} else if (Os.isFamily(Os.FAMILY_MAC)) {
25+
} else if(Os.isFamily(Os.FAMILY_MAC)) {
2226
ext.nativeBinaries = Arrays.asList(new File(nativeBinariesDir, "libultralight-java.dylib"))
23-
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
27+
} else if(Os.isFamily(Os.FAMILY_UNIX)) {
2428
ext.nativeBinaries = Arrays.asList(new File(nativeBinariesDir, "libultralight-java.so"))
2529
} else {
26-
if (!project.hasProperty("nativeBinaryLibrary")) {
30+
if(!project.hasProperty("nativeBinaryLibrary")) {
31+
// Unknown OS and missing binary, bail out
2732
throw new GradleException("Unable to determine native output library, " +
2833
"pass -PnativeBinaryLibrary=/path/to/native/binary to gradle")
2934
} else {
35+
// Unknown OS but the user specified the output binary
3036
ext.nativeBinaries = [new File(project.property("nativeBinaryLibrary").toString())]
3137
}
3238
}
3339
} else {
40+
// The binaries have been built by an external process and can be used now
3441
def nativeBinaryExternalDir = file(project.property("nativeBinaryExternalDir").toString())
3542
if(!nativeBinaryExternalDir.exists()) {
43+
// The directory where the binaries are supposed to be is missing, bail out
3644
throw new GradleException("nativeBinaryExternalDir ${nativeBinaryExternalDir.absolutePath} does not exist")
3745
}
3846

3947
ext.nativeBinaries = new ArrayList<File>()
4048

49+
// Collect all native binaries built externally
4150
for(def file in nativeBinaryExternalDir.listFiles()) {
4251
println "Found native binary ${file.absolutePath}"
4352
ext.nativeBinaries.add(file)
4453
}
4554

55+
// Flag the build
4656
isExternalBuild = true
4757
}
4858

4959
project(":ultralight-java-base").afterEvaluate { javaProject ->
5060
project(":ultralight-java-native").afterEvaluate { nativeProject ->
5161
if(!isExternalBuild) {
62+
// If the binaries have not been built externally, building the java project requires
63+
// building OS dependent binary locally
5264
javaProject.tasks["processResources"].dependsOn(nativeProject.tasks["build"])
5365
}
5466
}
5567
}
5668

69+
/**
70+
* Helper function to retrieve the file extensions from a file.
71+
*
72+
* @param file The file to retrieve the extension from
73+
* @return The extension of the file, or an empty string, if the file does not have an extension
74+
*/
5775
static def getExtension(File file) {
5876
String fileName = file.getName()
5977

@@ -64,16 +82,30 @@ static def getExtension(File file) {
6482
}
6583
}
6684

85+
/**
86+
* Helper function to retrieve the absolute path of a file without its extension.
87+
*
88+
* @param file The file to retrieve the path from
89+
* @return The absolute path of the file without its extension, or the path itself,
90+
* if the file does not have an extension
91+
*/
6792
static def getPathWithoutExtension(File file) {
68-
String fileName = file.getAbsolutePath()
93+
String path = file.getAbsolutePath()
6994

70-
if(fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0) {
71-
return fileName.substring(0, fileName.lastIndexOf("."))
95+
if(path.lastIndexOf(".") != -1 && path.lastIndexOf(".") != 0) {
96+
return path.substring(0, path.lastIndexOf("."))
7297
} else {
73-
return ""
98+
return path
7499
}
75100
}
76101

102+
/**
103+
* Processes a binary file by calculating its new path and moving it if desired.
104+
*
105+
* @param binary The binary to process
106+
* @param doMove If {@code true}, the file will be moved to the new path
107+
* @return The new file of the binary
108+
*/
77109
def processBinary(File binary, boolean doMove) {
78110
String extension = getExtension(binary)
79111
String path = getPathWithoutExtension(binary)
@@ -89,12 +121,16 @@ def processBinary(File binary, boolean doMove) {
89121
}
90122

91123
if(ciBuild) {
124+
// We are running a CI build
92125
def ciDir = file("ci")
93126
if(!ciDir.exists() && !ciDir.mkdirs()) {
127+
// Failed to create a necessary directory, bail out
94128
throw new GradleException("Failed to create directory ${ciDir.absolutePath}")
95129
}
96130

97131
new File(ciDir, "binaries").withWriter {
132+
// Write a file with paths to the native binaries, required by our script
133+
// at .github/workflows/ci.yml to create an archive with natives
98134
for(File binary in ext.nativeBinaries) {
99135
it.write(processBinary(binary, false).absolutePath)
100136
}
@@ -104,13 +140,15 @@ if(ciBuild) {
104140

105141
task moveNativeBinaries {
106142
doLast {
107-
for (File binary in binaries) {
143+
for(File binary in binaries) {
144+
// Move the binaries to their new locations
108145
processBinary(binary, true)
109146
}
110147
}
111148
}
112149

113150
project(":ultralight-java-native").afterEvaluate { nativeProject ->
151+
// Make sure the binaries are moved after the build
114152
nativeProject.tasks["build"].finalizedBy(moveNativeBinaries)
115153
}
116154
}

0 commit comments

Comments
 (0)