Skip to content

Commit

Permalink
Merge pull request #3 from Pi4J/feature/download-openjfx
Browse files Browse the repository at this point in the history
Added downloading of openjfx on mvn package
  • Loading branch information
FDelporte authored Apr 17, 2024
2 parents 0f7615e + 8461633 commit bcf462d
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Make staging directory
run: mkdir staging
- name: Copy JAR to staging
run: cp target/distribution/* staging
run: cp -r target/distribution/* staging
- name: Upload
uses: actions/upload-artifact@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/.idea/
/target/
/*.iml
download/
55 changes: 34 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,47 @@ dependency comes pre-installed on recent Raspbian images. However, you can also
download and install it yourself using the instructions found
[here](http://abyz.me.uk/rpi/pigpio/download.html).

As this application has a JavaFX user interface, the project requires the OpenJFX runtime. When the package is build,
then the runtime is downloaded and added to the distribution directory.

## BUILD DEPENDENCIES & INSTRUCTIONS

This project can be built with [Apache Maven](https://maven.apache.org/) 3.6
(or later) and Java 11 OpenJDK (or later). These prerequisites must be installed
prior to building this project. The following command can be used to download
all project dependencies and compile the Java module. You can build this
project directly on a Raspberry Pi with Java 11+.
This project can be built with [Apache Maven](https://maven.apache.org/) 3.6 (or later) and Java 17 OpenJDK (or later).
These prerequisites must be installed prior to building this project. The following command can be used to download all
project dependencies and compile the Java module. You can build this project directly on a Raspberry Pi with Java 17+.

```
```bash
mvn clean package
```

### Compiled application to run on the Raspberry Pi

Once the build is complete and was successful, you can find the compiled
artifacts in the `target` folder. Specifically
all dependency modules (JARs) and a simple `run.sh` bash script will be located in the
`target/distribution`.
Once the build is complete and was successful, you can find the compiled artifacts in the `target` folder. Specifically
all dependency modules (JARs) and a simple `run.sh` bash script will be located in the `target/distribution` folder.
This folder contains all the required files needed to distribute (copy) to your Raspberry Pi to run this project.

For your convenience, this `distribution` folder is zipped up, and is also located in the `target/` folder. Copy this
file to your Raspberry Pi, for example with the following command:

```bash
rsync target/pi4j-example-fxgl-0.0.1.zip [email protected]:.
```

Then on the Raspberry Pi unzip the file with the following command:

```bash
unzip pi4j-example-fxgl-0.0.1.zip
```

These are all the required files needed to distribute (copy) to your
Raspberry Pi to run this project. If you are using the native bindings running
locally on the Raspberry Pi, then you make have to run the program using `sudo`
to gain the necessary access permissions to the hardware I/O.
Now the example can be started with the following command:

```bash
cd pi4j-example-fxgl-0.0.1/
./run.sh
```

*Note:* If you are using the native bindings running locally on the Raspberry Pi, then you may have to run the program
using `sudo` to gain the necessary access permissions to the hardware I/O.

This is the list of files created by the build process of this example application:

Expand All @@ -59,15 +77,10 @@ This is the list of files created by the build process of this example applicati
* pi4j-plugin-raspberrypi
* slf4j-api
* slf4j-simple
* javafx-*
* and additional dependencies required for JavaFX and FXGL
* run.sh --> this is the actual start file which will run pi4j-example-javafx

Make the run script executable and start it like this:

```
chmod +x run.sh
sudo ./run.sh
```

## LICENSE

Pi4J Version 2.0 and later is licensed under the Apache License,
Expand Down
5 changes: 3 additions & 2 deletions assets/run-kiosk.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/usr/bin/env bash
/sbin/init 3
export ENABLE_GLUON_COMMERCIAL_EXTENSIONS=true
declare SCRIPT_DIR="$(cd "${0%/*}" ; pwd)"
java \
-Degl.displayid=/dev/dri/card0 \
-Dmonocle.egl.lib=/opt/javafx-sdk-17/lib/libgluon_drm-1.1.3.so \
-Djava.library.path=/opt/javafx-sdk-17/lib \
-Djava.library.path="${SCRIPT_DIR}/openjfx/lib" \
-Dmonocle.platform.traceConfig=false \
-Dprism.verbose=false \
-Djavafx.verbose=false \
-Dmonocle.platform=EGL \
--module-path .:/opt/javafx-sdk-17/lib \
--module-path ".:${SCRIPT_DIR}/openjfx/lib" \
--add-modules javafx.controls \
--module com.pi4j.example/com.pi4j.example.JavaFxExample $@
/sbin/init 5
5 changes: 3 additions & 2 deletions assets/run.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env bash
declare SCRIPT_DIR="$(cd "${0%/*}" ; pwd)"
java \
-Dglass.platform=gtk \
-Djava.library.path=/opt/javafx-sdk-17/lib \
-Djava.library.path="${SCRIPT_DIR}/openjfx/lib" \
-Dmonocle.platform.traceConfig=false \
-Dprism.verbose=false \
-Djavafx.verbose=false \
--module-path .:/opt/javafx-sdk-17/lib \
--module-path ".:${SCRIPT_DIR}/openjfx/lib" \
--add-modules javafx.controls \
--module com.pi4j.example/com.pi4j.example.JavaFxExample $@
62 changes: 62 additions & 0 deletions download_openjfx.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
@echo off

REM Variables
set URL="https://download2.gluonhq.com/openjfx/22/openjfx-22_linux-aarch64_bin-sdk.zip"
set SHA_URL="https://download2.gluonhq.com/openjfx/22/openjfx-22_linux-aarch64_bin-sdk.zip.sha256"
set TARGET_DIR="target\openjfx"
set SUBDIR="extracted_files"
set TEMP_DIR="%TEMP%\openjfx_temp"

REM Function to calculate SHA256 sum
:calculate_sha256
certutil -hashfile "%1" SHA256 | findstr /R "[0-9a-fA-F]*"

REM Create target directory
rmdir /s /q "%TARGET_DIR%\%SUBDIR%"
mkdir "%TARGET_DIR%\%SUBDIR%" 2>nul

REM Download the file if not already downloaded
if not exist "%TARGET_DIR%\%~n0" (
echo Downloading %URL%...
bitsadmin.exe /transfer myDownloadJob /download /priority normal %URL% "%TARGET_DIR%\%~n0"
) else (
echo File already exists. Skipping download.
)

REM Download the SHA256 file if not already downloaded
if not exist "%TARGET_DIR%\%~n1" (
echo Downloading SHA256 checksum file...
bitsadmin.exe /transfer mySHA256Job /download /priority normal %SHA_URL% "%TARGET_DIR%\%~n1"
)

REM Verify the SHA256 sum
echo Verifying SHA256 sum...
for /f "tokens=*" %%a in ('type "%TARGET_DIR%\%~n1"') do set "sha256sum=%%a"
for /f "tokens=*" %%b in ('call :calculate_sha256 "%TARGET_DIR%\%~n0"') do (
if "%%b"=="%sha256sum%" (
echo SHA256 sum verified successfully.
) else (
echo SHA256 sum verification failed.
rmdir /s /q "%TEMP_DIR%"
exit /b 1
)
)

REM Extract the zip file
echo Extracting the zip file...
powershell -noprofile -command "& {Add-Type -A 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::ExtractToDirectory('%TARGET_DIR%\%~n0', '%TARGET_DIR%\%SUBDIR%')}"

rem Find the folder and rename it
for /f "delims=" %%D in ('dir /b /ad "%TARGET_DIR%\%SUBDIR%"') do (
set "folder=%%~fD"
goto :rename
)
:rename
if defined folder (
ren "%folder%" new_name
echo Folder renamed successfully.
) else (
echo Folder not found.
)

echo Extraction completed. Files are located in: %TARGET_DIR%\%SUBDIR%
53 changes: 53 additions & 0 deletions download_openjfx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

# Variables
URL="https://download2.gluonhq.com/openjfx/22/openjfx-22_linux-aarch64_bin-sdk.zip"
SHA_URL="https://download2.gluonhq.com/openjfx/22/openjfx-22_linux-aarch64_bin-sdk.zip.sha256"
TARGET_DIR="download/openjfx"
SUBDIR="extracted_files"
TEMP_DIR=$(mktemp -d)

# Function to calculate SHA256 sum
calculate_sha256() {
sha256sum "$1" | awk '{print $1}'
}

# Create target directory if it doesn't exist
rm -rf "${TARGET_DIR:?}/$SUBDIR"
mkdir -p "$TARGET_DIR/$SUBDIR"

# Download the file if not already downloaded
if [ ! -f "$TARGET_DIR/$(basename "$URL")" ]; then
echo "Downloading $URL..."
wget -q --show-progress -O "$TARGET_DIR/$(basename "$URL")" "$URL"
else
echo "File already exists. Skipping download."
fi

# Download the SHA256 file if not already downloaded
if [ ! -f "$TARGET_DIR/$(basename "$SHA_URL")" ]; then
echo "Downloading SHA256 checksum file..."
wget -q -O "$TARGET_DIR/$(basename "$SHA_URL")" "$SHA_URL"
fi

# Verify the SHA256 sum
echo "Verifying SHA256 sum..."
if [ "$(calculate_sha256 "$TARGET_DIR/$(basename "$URL")")" == "$(cut -d ' ' -f1 "$TARGET_DIR/$(basename "$SHA_URL")")" ]; then
echo "SHA256 sum verified successfully."
else
echo "SHA256 sum verification failed."
rm -rf "$TEMP_DIR"
exit 1
fi

# Extract the zip file
echo "Extracting the zip file..."
unzip -q "$TARGET_DIR/$(basename "$URL")" -d "$TARGET_DIR/$SUBDIR"

# Find the folder and rename it
folder=$(find "$TARGET_DIR/$SUBDIR" -maxdepth 1 -mindepth 1 -type d -exec echo {} \;)
if [ -n "$folder" ]; then
mv "$folder" "$TARGET_DIR/$SUBDIR/openjfx"
fi

echo "Extraction completed. Files are located in: $TARGET_DIR/$SUBDIR"
46 changes: 43 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,28 @@
<!-- COPY ANY RUNTIME SCRIPTS TO THE /target/distribution PATH -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<version>3.1.0</version>
<executions>

<execution>
<id>copy</id>
<phase>package</phase>
<configuration>
<target>
<echo message="Running OpenJFX download script..."/>
<exec executable="/bin/bash" osfamily="unix">
<arg line="${project.basedir}/download_openjfx.sh"/>
</exec>
<exec executable="cmd" osfamily="windows">
<arg line="/c ${project.basedir}\download_openjfx.bat"/>
</exec>

<echo message="Copying distribution files..."/>
<copy todir="${project.build.directory}/distribution" overwrite="true" flatten="true">
<fileset dir="assets" includes="*.sh" ></fileset>
<fileset dir="assets" includes="*.sh"/>
</copy>
<copy todir="${project.build.directory}/distribution/openjfx" overwrite="true">
<fileset dir="download/openjfx/extracted_files/openjfx"/>
</copy>
<chmod dir="${project.build.directory}/distribution" perm="ugo+rx" includes="**/*.sh"/>
</target>
Expand All @@ -138,6 +151,13 @@
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.10.11</version>
</dependency>
</dependencies>
</plugin>

<!-- DOWNLOAD RUNTIME DEPENDENCIES -->
Expand All @@ -162,11 +182,31 @@
On the Raspberry Pi we use specific JavaFX dependencies,
so we exclude them here and they are added in the run-script.
-->
<excludeGroupIds>org.openjfx</excludeGroupIds>
<!-- exclude platform specific dependencies, as we add the runtime in the assembly-->
<excludeClassifiers>linux,win,mac</excludeClassifiers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>
16 changes: 16 additions & 0 deletions src/assembly/assembly.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>bin</id>
<formats>
<format>zip</format>
</formats>

<fileSets>
<fileSet>
<directory>${project.build.directory}/distribution</directory>
<outputDirectory/>
<filtered>false</filtered>
</fileSet>
</fileSets>

</assembly>

0 comments on commit bcf462d

Please sign in to comment.