From 79955994bee125c098b300b05d23bb8c9aa639a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pereda?= Date: Fri, 25 Oct 2024 23:14:14 +0200 Subject: [PATCH] Add installers (#12) --- .github/scripts/jpackage.bat | 34 ++++ .github/scripts/jpackage.sh | 27 +++ .github/workflows/build.yml | 159 ++++++++++++++++++ pom.xml | 44 +++-- .../embedded/DependenciesScanner.java | 2 +- .../embedded/demo/DemoApplication.java | 3 +- src/main/java/module-info.java | 1 + 7 files changed, 254 insertions(+), 16 deletions(-) create mode 100644 .github/scripts/jpackage.bat create mode 100755 .github/scripts/jpackage.sh create mode 100644 .github/workflows/build.yml diff --git a/.github/scripts/jpackage.bat b/.github/scripts/jpackage.bat new file mode 100644 index 0000000..efb3e0e --- /dev/null +++ b/.github/scripts/jpackage.bat @@ -0,0 +1,34 @@ +set MODULE_NAME=EmbeddedSceneBuilderDemo +set MAIN_CLASS=com.gluonhq.scenebuilder.embedded.demo.DemoApplication + +cp target\demo-%APP_VERSION%.jar target\lib\ + +for /F %%i in ('%JAVA_HOME%\bin\jdeps --module-path target\lib --print-module-deps --ignore-missing-deps -m %MODULE_NAME%') do SET JDEPS_MODULES=%%i + +set JAVA_MODULES=javafx.fxml,javafx.media,javafx.swing,javafx.web,java.logging + +%JAVA_HOME%\bin\jlink ^ +--module-path target\lib ^ +--add-modules %JDEPS_MODULES%,%JAVA_MODULES% ^ +--output target\runtime ^ +--strip-debug --compress zip-6 --no-header-files --no-man-pages + +%JPACKAGE_HOME%\bin\jpackage ^ +--module-path target/lib ^ +--runtime-image target/runtime ^ +--dest target/installer ^ +--module %MODULE_NAME%/%MAIN_CLASS% ^ +--name %MODULE_NAME% ^ +--description "Embedded Scene Builder Demo" ^ +--vendor "Gluon" ^ +--copyright "Copyright © 2024 Gluon" ^ +--license-file LICENSE.txt ^ +--app-version %APP_VERSION% ^ +--java-options '"--add-opens=javafx.fxml/javafx.fxml=com.gluonhq.scenebuilder.kit"' ^ +--type msi ^ +--win-dir-chooser ^ +--win-menu ^ +--win-menu-group "Scene Builder" ^ +--win-per-user-install ^ +--win-shortcut + diff --git a/.github/scripts/jpackage.sh b/.github/scripts/jpackage.sh new file mode 100755 index 0000000..6bbfd5d --- /dev/null +++ b/.github/scripts/jpackage.sh @@ -0,0 +1,27 @@ +MODULE_NAME=EmbeddedSceneBuilderDemo +MAIN_CLASS=com.gluonhq.scenebuilder.embedded.demo.DemoApplication + +cp target/demo-$APP_VERSION.jar target/lib/ + +jdeps_modules=$($JAVA_HOME/bin/jdeps --module-path target/lib --print-module-deps --ignore-missing-deps -m $MODULE_NAME) +JAVA_MODULES=javafx.fxml,javafx.media,javafx.swing,javafx.web,java.logging + +$JAVA_HOME/bin/jlink \ +--module-path target/lib \ +--add-modules $jdeps_modules,$JAVA_MODULES \ +--output target/runtime \ +--strip-debug --compress zip-6 --no-header-files --no-man-pages + +$JPACKAGE_HOME/bin/jpackage \ +--module-path target/lib \ +--runtime-image target/runtime \ +--dest target/installer \ +--module $MODULE_NAME/$MAIN_CLASS \ +--name $MODULE_NAME \ +--description "Embedded Scene Builder Demo" \ +--vendor "Gluon" \ +--copyright "Copyright © 2024 Gluon" \ +--license-file LICENSE.txt \ +--app-version $APP_VERSION \ +--java-options '"--add-opens=javafx.fxml/javafx.fxml=com.gluonhq.scenebuilder.kit"' \ +"$@" \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a27dd5c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,159 @@ +name: Build + +on: + push: + branches: + - 'main' + pull_request: + branches: + - 'main' + +env: + JAVA_RELEASE: '23' + JAVA_VERSION: '23.0.1' + JAVAFX_VERSION: '23.0.1' + APP_VERSION: '1.0.0' + +jobs: + build: + strategy: + matrix: + os: [ macos-13, macos-14, ubuntu-latest, windows-latest ] + include: + - os: macos-13 + ARCH: "-amd64" + PLAT: "macos" + FX: "osx-x64" + - os: macos-14 + ARCH: "-aarch64" + PLAT: "macos" + FX: "osx-aarch64" + - os: ubuntu-latest + ARCH: "" + PLAT: "linux" + FX: "linux-x64" + - os: windows-latest + ARCH: "" + PLAT: "win" + FX: "windows-x64" + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + + - name: Setup Java + uses: oracle-actions/setup-java@v1.4.0 + with: + website: jdk.java.net + release: ${{ env.JAVA_RELEASE }} + version: ${{ env.JAVA_VERSION }} + + - uses: Apple-Actions/import-codesign-certs@v3 + if: github.event_name != 'pull_request' && (matrix.os == 'macos-13' || matrix.os == 'macos-14') + with: + p12-file-base64: ${{ secrets.CERTIFICATES_FILE_BASE64 }} + p12-password: ${{ secrets.CERTIFICATES_PASSWORD }} + + - name: Cache Maven packages + uses: actions/cache@v4 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + + - name: Build and package Jar (non-windows) + if: matrix.os != 'windows-latest' + run: mvn -B -ntp -q clean package -Dmaven.test.skip=true + + - name: Build and package Jar (windows) + if: matrix.os == 'windows-latest' + shell: cmd + run: call mvn -B -ntp package -Dmaven.test.skip=true + + - name: Create Bundle using jpackage for macos + if: matrix.os == 'macos-13' || matrix.os == 'macos-14' + id: outputfile_mac + run: | + if [[ ${{ github.event_name }} != 'pull_request' ]]; then + .github/scripts/jpackage.sh \ + --type dmg \ + --mac-package-identifier com.gluonhq.scenebuilder.embedded.Demo \ + --mac-package-name 'Embedded SB Demo' \ + --mac-package-signing-prefix "${{ env.MACSIGN_PREFIX }}" \ + --mac-signing-key-user-name "${{ env.MACSIGN_USER }}" \ + --mac-sign + else + .github/scripts/build_app_mac.sh \ + --type dmg \ + --mac-package-identifier com.gluonhq.scenebuilder.embedded.Demo \ + --mac-package-name 'Embedded SB Demo' + fi + mv target/installer/EmbeddedSceneBuilderDemo-${{ env.APP_VERSION }}.dmg target/installer/EmbeddedSceneBuilderDemo-${{ env.APP_VERSION }}${{ matrix.ARCH }}.dmg + echo path=target/installer/EmbeddedSceneBuilderDemo-${{ env.APP_VERSION }}${{ matrix.ARCH }}.dmg >> $GITHUB_OUTPUT + env: + JPACKAGE_HOME: ${{ env.JAVA_HOME }} + MACSIGN_PREFIX: ${{ secrets.GLUON_MACSIGN_PREFIX }} + MACSIGN_USER: ${{ secrets.GLUON_MACSIGN_USER }} + APP_VERSION: ${{ env.APP_VERSION }} + + - name: Create Bundle using jpackage for linux + if: matrix.os == 'ubuntu-latest' + id: outputfile_linux + run: | + .github/scripts/jpackage.sh \ + --type deb + echo path_deb=target/installer/embeddedscenebuilderdemo_${{ env.APP_VERSION }}_amd64.deb >> $GITHUB_OUTPUT + .github/scripts/jpackage.sh \ + --type rpm + ls -l target/installer/ + echo path_rpm=target/installer/embeddedscenebuilderdemo-${{ env.APP_VERSION }}-1.x86_64.rpm >> $GITHUB_OUTPUT + env: + JPACKAGE_HOME: ${{ env.JAVA_HOME }} + APP_VERSION: ${{ env.APP_VERSION }} + + - name: Create Bundle using jpackage for windows + if: matrix.os == 'windows-latest' + id: outputfile_win + shell: cmd + run: | + call .github\scripts\jpackage.bat + echo path=target\installer\EmbeddedSceneBuilderDemo-${{ env.APP_VERSION }}.msi >> %GITHUB_OUTPUT% + env: + JPACKAGE_HOME: ${{ env.JAVA_HOME }} + APP_VERSION: ${{ env.APP_VERSION }} + + - name: Notarize Release Build + if: github.event_name != 'pull_request' && (matrix.os == 'macos-13' || matrix.os == 'macos-14') + uses: erwin1/xcode-notarizer@v1 + with: + product-path: ${{ steps.outputfile_mac.outputs.path }} + apple-id: ${{ secrets.NOTARIZATION_USERNAME }} + app-password: ${{ secrets.NOTARIZATION_PASSWORD }} + team-id: ${{ secrets.GLUON_MACSIGN_PREFIX }} + + - name: Archive jpackage for macos + if: matrix.os == 'macos-13' || matrix.os == 'macos-14' + uses: actions/upload-artifact@v4 + with: + name: EmbeddedSceneBuilderDemo-${{ matrix.PLAT }}${{ matrix.ARCH }} + path: ${{ steps.outputfile_mac.outputs.path }} + + - name: Archive jpackage for linux deb + if: matrix.os == 'ubuntu-latest' + uses: actions/upload-artifact@v4 + with: + name: EmbeddedSceneBuilderDemo-${{ matrix.PLAT }}${{ matrix.ARCH }}-deb + path: ${{ steps.outputfile_linux.outputs.path_deb }} + + - name: Archive jpackage for linux rpm + if: matrix.os == 'ubuntu-latest' + uses: actions/upload-artifact@v4 + with: + name: EmbeddedSceneBuilderDemo-${{ matrix.PLAT }}${{ matrix.ARCH }}-rpm + path: ${{ steps.outputfile_linux.outputs.path_rpm }} + + - name: Archive jpackage for windows + if: matrix.os == 'windows-latest' + uses: actions/upload-artifact@v4 + with: + name: EmbeddedSceneBuilderDemo-${{ matrix.PLAT }}${{ matrix.ARCH }} + path: ${{ steps.outputfile_win.outputs.path }} \ No newline at end of file diff --git a/pom.xml b/pom.xml index ac31ad0..9a2c771 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.gluonhq.scenebuilder.embedded demo - 1.0.0-SNAPSHOT + 1.0.0 EmbeddedSceneBuilderDemo @@ -17,29 +17,24 @@ ${java.version} ${java.version} 23.0.1 - org.openjfx - javafx-web - ${javafx.version} - - - org.openjfx - javafx-fxml - ${javafx.version} - - - org.openjfx - javafx-swing + javafx-controls ${javafx.version} com.gluonhq.scenebuilder kit 24.0.0-SNAPSHOT + + + org.apache.maven.resolver + * + + org.controlsfx @@ -83,11 +78,32 @@ EmbeddedSceneBuilderDemo/com.gluonhq.scenebuilder.embedded.demo.DemoApplication - + + org.apache.maven.plugins + maven-dependency-plugin + 3.8.0 + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/lib + false + false + true + compile + runtime + + + + \ No newline at end of file diff --git a/src/main/java/com/gluonhq/scenebuilder/embedded/DependenciesScanner.java b/src/main/java/com/gluonhq/scenebuilder/embedded/DependenciesScanner.java index cefc217..05e913b 100644 --- a/src/main/java/com/gluonhq/scenebuilder/embedded/DependenciesScanner.java +++ b/src/main/java/com/gluonhq/scenebuilder/embedded/DependenciesScanner.java @@ -104,7 +104,7 @@ private static boolean isSystemModule(final ModuleReference moduleReference) { return false; } return name.startsWith("java.") || name.startsWith("jdk.") || name.startsWith("javafx.") || - name.startsWith("oracle.") || name.startsWith("com.gluonhq.scenebuilder.") || "EmbeddedSceneBuilderContainer".equals(name); + name.startsWith("oracle.") || name.startsWith("com.gluonhq.scenebuilder.") || "EmbeddedSceneBuilderDemo".equals(name); } public static List scan() { diff --git a/src/main/java/com/gluonhq/scenebuilder/embedded/demo/DemoApplication.java b/src/main/java/com/gluonhq/scenebuilder/embedded/demo/DemoApplication.java index c70cbc1..b56e876 100644 --- a/src/main/java/com/gluonhq/scenebuilder/embedded/demo/DemoApplication.java +++ b/src/main/java/com/gluonhq/scenebuilder/embedded/demo/DemoApplication.java @@ -40,6 +40,7 @@ import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.stage.Stage; +import org.controlsfx.control.ToggleSwitch; public class DemoApplication extends Application { @@ -56,7 +57,7 @@ public void start(Stage stage) { Button saveButton = new Button("Save FXML"); saveButton.setOnAction(sceneBuilderPane.saveFXMLHandler()); - HBox top = new HBox(50, newButton, fileButton, saveButton); + HBox top = new HBox(50, newButton, fileButton, saveButton, new ToggleSwitch()); top.setPadding(new Insets(5)); top.setAlignment(Pos.CENTER); diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 7bea09f..efa6d1a 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -34,6 +34,7 @@ requires javafx.fxml; requires com.gluonhq.scenebuilder.kit; requires org.controlsfx.controls; + requires java.logging; uses com.oracle.javafx.scenebuilder.kit.i18n.spi.I18NResourcesProvider; opens com.gluonhq.scenebuilder.embedded to javafx.fxml;