Skip to content

Commit

Permalink
jlink branch, rebased (#4)
Browse files Browse the repository at this point in the history
* Adds JLink helper class, CLI support
* Refactor main(); untangles TrayManager and PrintSocketServer
* Force openjdk@11 on Travis + macOS
* Mimic javapackager structure for macOS
* Temporarily disable clean between builds
* Temporarily allow running Mac version from out

Co-authored-by: Berenz <[email protected]>
Co-authored-by: Vzor- <[email protected]>
  • Loading branch information
3 people authored Apr 3, 2021
1 parent 802d1f8 commit 34d6873
Show file tree
Hide file tree
Showing 22 changed files with 765 additions and 198 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ matrix:
language: java
dist: trusty
before_script:
- sw_vers -productVersion && brew update && brew install ant; ant -version
- sw_vers -productVersion && brew update && brew install ant && brew uninstall --ignore-dependencies openjdk && brew install openjdk@11 && ln -s /usr/local/opt/openjdk@11 /usr/local/opt/openjdk; ant -version
- test -e /etc/lsb-release && sudo apt-get update -qq && sudo apt-get install -y makeself nsis; echo;
script: ant $TARGET
16 changes: 16 additions & 0 deletions ant/apple/apple-entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.disable-executable-page-protection</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
</dict>
</plist>
35 changes: 31 additions & 4 deletions ant/apple/installer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<target name="pkgbuild-preflight">
<property name="target.platform.mac" value="true"/>
</target>
<target name="build-pkg" depends="get-version">
<target name="build-pkg" depends="codesign-jre,get-version">
<echo level="info">Creating installer using pkgbuild</echo>

<property file="ant/apple/apple.properties"/>
Expand Down Expand Up @@ -62,6 +62,9 @@
<include name="**/${project.name}"/>
<include name="**/uninstall"/>
</fileset>
<fileset dir="${build.dir}/scripts/payload/PlugIns/Java.runtime/Contents/Home/bin">
<include name="**"/>
</fileset>
</chmod>

<!-- Disable signing and append "-community" if id is missing -->
Expand Down Expand Up @@ -102,8 +105,32 @@
</exec>

<!-- Cleanup lingering files (for other OS installers) -->
<delete dir="${dist.dir}/Contents/Resources"/>
<delete dir="${dist.dir}/Contents/MacOS"/>
<!-- FIXME BRING BACK BEFORE MERGE <delete dir="${dist.dir}/Contents/Resources"/> -->
<!-- FIXME BRING BACK BEFORE MERGE <delete dir="${dist.dir}/Contents/MacOS"/> -->
<!-- FIXME BUILD AN APP HERE LOCALLY -->
<delete dir="${dist.dir}/../QZ Tray.app"/>
<move todir="${dist.dir}/../QZ Tray.app">
<fileset dir="${dist.dir}"/>
</move>
<chmod perm="a+x">
<fileset dir="${dist.dir}/../QZ Tray.app/Contents/MacOS"/>
</chmod>
</target>

<target name="codesign-jre" if="codesign.mac">
<property file="ant/apple/apple.properties"/>
<exec executable="codesign" failonerror="true">
<arg value="--force"/>
<arg value="-s"/>
<arg value="${apple.packager.signid}"/>
<arg value="--timestamp"/>
<arg value="--options"/>
<arg value="runtime"/>
<arg value="--entitlements"/>
<arg value="${basedir}/ant/apple/apple-entitlements.plist"/>
<arg value="--deep"/>
<arg value="${dist.dir}/PlugIns/Java.runtime"/>
</exec>
</target>

<target name="codesign-jars" if="codesign.mac">
Expand Down Expand Up @@ -140,7 +167,7 @@
<echo level="info" message="Signing ${dist.dir}/libs/*.dylib using ${apple.packager.signid}"/>
<exec executable="bash" failonerror="true">
<arg value="-c"/>
<arg value="echo &quot;$(find ${dist.dir}/libs/*.dylib)&quot; |tr ':' '\n' |xargs codesign -s &quot;${apple.packager.signid}&quot; -v"/>
<arg value="echo &quot;$(find ${dist.dir}/libs/*.dylib)&quot; |tr ':' '\n' |xargs codesign --force -s &quot;${apple.packager.signid}&quot; -v"/>
</exec>

</target>
Expand Down
69 changes: 40 additions & 29 deletions ant/unix/unix-launcher.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ if [ -n "$JAVA_HOME" ]; then
PATH="$JAVA_HOME/bin:$PATH"
fi

# Check for bundled JRE
if [ -d ./jre ]; then
echo -e "$SUCCESS A bundled runtime was found. Using..."
PATH="$(pwd)/jre/bin:$PATH"
export PATH
# Always prefer relative jre/jdk
if [[ "$DIR" == *"/Contents/MacOS"* ]]; then
PATH="$DIR/../../PlugIns/Java.runtime/Contents/Home/bin:$PATH"
else
PATH="$DIR/jre/bin:$DIR/jdk/bin:$PATH"
fi

# Check for user overridable launch options
Expand All @@ -45,30 +45,41 @@ if [ -n "${dollar}${launch.overrides}" ]; then
LAUNCH_OPTS="$LAUNCH_OPTS ${dollar}${launch.overrides}"
fi

if [[ "$OSTYPE" == "darwin"* ]]; then
DEFAULTS_READ=$(defaults read ${apple.bundleid} ${launch.overrides} 2>/dev/null) || true
if [ -n "$DEFAULTS_READ" ]; then
echo -e "$MESSAGE Picked up additional launch options: $DEFAULTS_READ"
LAUNCH_OPTS="$LAUNCH_OPTS $DEFAULTS_READ"
fi
ICON_PATH="$DIR/Contents/Resources/apple-icon.icns"
MAC_PRIMARY="/usr/libexec/java_home"
MAC_FALLBACK="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin"
echo "Trying $MAC_PRIMARY..."
if "$MAC_PRIMARY" -v $JAVA_MIN+ &>/dev/null; then
echo -e "$SUCCESS Using \"$MAC_PRIMARY -v $JAVA_MIN+ --exec\" to launch $ABOUT_TITLE"
java() {
"$MAC_PRIMARY" -v $JAVA_MIN+ --exec java "$@"
}
elif [ -d "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin" ]; then
echo -e "$WARNING No luck using $MAC_PRIMARY"
echo "Trying $MAC_FALLBACK..."
java() {
"$MAC_FALLBACK/java" "$@"
}
fi
# Fallback on some known locations
if ! command -v java > /dev/null ; then
if [[ "$OSTYPE" == "darwin"* ]]; then
# Apple: Fallback on system-wide install
DEFAULTS_READ=$(defaults read ${apple.bundleid} ${launch.overrides} 2>/dev/null) || true
if [ -n "$DEFAULTS_READ" ]; then
echo -e "$MESSAGE Picked up additional launch options: $DEFAULTS_READ"
LAUNCH_OPTS="$LAUNCH_OPTS $DEFAULTS_READ"
fi
MAC_PRIMARY="/usr/libexec/java_home"
MAC_FALLBACK="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin"
echo "Trying $MAC_PRIMARY..."
if "$MAC_PRIMARY" -v $JAVA_MIN+ &>/dev/null; then
echo -e "$SUCCESS Using \"$MAC_PRIMARY -v $JAVA_MIN+ --exec\" to launch $ABOUT_TITLE"
java() {
"$MAC_PRIMARY" -v $JAVA_MIN+ --exec java "$@"
}
elif [ -d "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin" ]; then
echo -e "$WARNING No luck using $MAC_PRIMARY"
echo "Trying $MAC_FALLBACK..."
java() {
"$MAC_FALLBACK/java" "$@"
}
fi
else
# Linux/Unix: Fallback on known install location(s)
PATH="$PATH:/usr/java/latest/bin/"
fi
fi

if command -v java > /dev/null ; then
echo -e "$SUCCESS Java was found: $(command -v java)"
else
export PATH="$PATH:/usr/java/latest/bin/"
echo -e "$FAILURE Please install Java $JAVA_MIN or higher to continue"
exit 1
fi

# Make sure Java version is sufficient
Expand Down Expand Up @@ -96,7 +107,7 @@ if command -v java &>/dev/null; then
else
prefix="../../" # back two directories, e.g. postinstall
fi
java $LAUNCH_OPTS -Xdock:name="$ABOUT_TITLE" -Xdock:icon="$ICON_PATH" -jar -Dapple.awt.UIElement="true" -Dapple.awt.enableTemplateImages="true" "${prefix}$PROPS_FILE.jar" -NSRequiresAquaSystemAppearance False "$@"
java $LAUNCH_OPTS -Xdock:name="$ABOUT_TITLE" -Xdock:icon="$DIR/Contents/Resources/apple-icon.icns" -jar -Dapple.awt.UIElement="true" -Dapple.awt.enableTemplateImages="true" "${prefix}$PROPS_FILE.jar" -NSRequiresAquaSystemAppearance False "$@"
else
java $LAUNCH_OPTS -jar "$PROPS_FILE.jar" "$@"
fi
Expand Down
16 changes: 16 additions & 0 deletions ant/windows/nsis/Include/FindJava.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ Var /GLOBAL javaw
IfFileExists "$0" Found
!macroend

!macro _ReadPayload root path
ClearErrors
StrCpy $0 "${root}\${path}\bin\${EXE}"
IfFileExists $0 Found
!macroend

!macro _ReadWorking path
ClearErrors
StrCpy $0 "$EXEDIR\${path}\bin\${EXE}"
Expand All @@ -54,10 +60,17 @@ Var /GLOBAL javaw
; Create the shared function.
!macro _FindJava un
Function ${un}FindJava
; Snag payload directory
exch $R0

${If} ${RunningX64}
SetRegView 64
${EndIf}

; Check payload directories
!insertmacro _ReadPayload "$R0" "jre"
!insertmacro _ReadPayload "$R0" "jdk"

; Check relative directories
!insertmacro _ReadWorking "jre"
!insertmacro _ReadWorking "jdk"
Expand All @@ -80,6 +93,9 @@ Var /GLOBAL javaw
StrCpy $java $0
${StrRep} '$java' '$java' 'javaw.exe' '${EXE}' ; AdoptOpenJDK returns "javaw.exe"
${StrRep} '$javaw' '$java' '${EXE}' 'javaw.exe'

; Discard payload directory
pop $R0
FunctionEnd
!macroend

Expand Down
16 changes: 10 additions & 6 deletions ant/windows/windows-installer.nsi.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,22 @@ Section
System::Call 'Kernel32::SetEnvironmentVariable(t, t)i ("${vendor.name}_silent", "1").r0'
${EndIf}

; Echo final destination to logs
SetOutPath $INSTDIR

; Copy files to a temporary location
SetOutPath "$PLUGINSDIR\payload"
DetailPrint "Extracting..."
SetDetailsPrint none ; Temporarily suppress details
File /r "${dist.dir}\*"

; Set the $java variable
TryAgain:
Push "$OUTDIR"
Call FindJava
!insertmacro VerifyJava "TryAgain"

SetOutPath $INSTDIR

; Run preinstall tasks
SetOutPath "$PluginsDir\tmp"
DetailPrint "Extracting..."
SetDetailsPrint none ; Temporarily suppress details
File /r "${dist.dir}\*"
SetDetailsPrint both
!insertmacro QzInstaller "preinstall" "" ""

Expand Down
1 change: 1 addition & 0 deletions ant/windows/windows-launcher.nsi.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Section
${GetParameters} $params

; Sets the $java variable
Push "$EXEDIR"
Call FindJava

Var /GLOBAL opts
Expand Down
1 change: 1 addition & 0 deletions ant/windows/windows-uninstaller.nsi.in
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Section
${EndIf}

; Set $javaw variable
Push "$DELETE_DIR"
Call FindJava

; Run uninstall step using jar
Expand Down
37 changes: 30 additions & 7 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<import file="ant/linux/installer.xml"/>
<import file="ant/windows/installer.xml"/>

<target name="distribute" depends="init,clean,download-javafx,build-jar,override-authcert,include-assets,whitelist-certs">
<target name="distribute" depends="init,download-javafx,build-jar,override-authcert,include-assets,whitelist-certs">
<antcall target="tidy-javafx-dist"/>
<echo level="info">Process complete</echo>
</target>
Expand Down Expand Up @@ -37,7 +37,7 @@
</target>

<target name="clean" depends="init">
<delete dir="${out.dir}"/>
<!-- <delete dir="${out.dir}"/> -->
</target>

<target name="compile-socket" depends="init">
Expand Down Expand Up @@ -84,22 +84,28 @@
<!-- Apple: Extract, sign, repackage all nested native libs for notarization -->
<antcall target="apple-installer.codesign-jars"/>

<echo level="info">Building Jar for Socket use</echo>
<echo level="info">Building jar</echo>
<mkdir dir="${sign.lib.dir}"/>
<jar compress="${jar.compress}" index="${jar.index}" destfile="${dist.dir}/${project.filename}.jar" duplicate="preserve">
<jar compress="false" index="${jar.index}" destfile="${out.dir}/${project.filename}.jar.tmp" duplicate="preserve">
<fileset dir="${build.dir}/${project.filename}"/>
<zipgroupfileset dir="${sign.lib.dir}" includes="**/*.jar" erroronmissingdir="false"/>
<zipgroupfileset dir="lib">
<include name="**/*.jar"/>
<exclude name="**/jfxrt.jar"/>
<exclude name="**/jssc-*.jar" if="codesign.mac"/>
</zipgroupfileset>
</jar>
<!-- Strip jlink-incompat files -->
<echo level="info">Stripping jlink-incompatible files</echo>
<jar compress="${jar.compress}" index="${jar.index}" destfile="${dist.dir}/${project.filename}.jar" duplicate="preserve">
<zipfileset src="${out.dir}/${project.filename}.jar.tmp" excludes="*.class,LICENSE,jetty-dir.css"/>
<manifest>
<attribute name="Application-Name" value="${project.name}"/>
<attribute name="Main-Class" value="qz.ws.PrintSocketServer"/>
<attribute name="Permissions" value="all-permissions"/>
</manifest>
</jar>
<delete file="${out.dir}/${project.filename}.jar.tmp"/>

<antcall target="sign-jar">
<param name="sign.jar.file" value="${dist.dir}/${project.filename}.jar"/>
Expand Down Expand Up @@ -139,7 +145,24 @@
</copy>
</target>

<target name="nsis" depends="nsis-preflight,distribute,build-exe"/>
<target name="pkgbuild" depends="pkgbuild-preflight,distribute,build-pkg"/>
<target name="makeself" depends="makeself-preflight,distribute,build-run"/>
<target name="download-jre">
<condition property="target.platform" value="windows">
<isset property="target.platform.windows"/>
</condition>
<condition property="target.platform" value="mac">
<isset property="target.platform.mac"/>
</condition>
<property description="target.platform default" name="target.platform" value="linux"/>

<echo level="info">Downloading and bundling the jre for ${target.platform}</echo>
<java jar="${dist.dir}/${project.filename}.jar" fork="true">
<arg value="jlink"/>
<arg value="--platform"/>
<arg value="${target.platform}"/>
</java>
</target>

<target name="nsis" depends="nsis-preflight,distribute,download-jre,build-exe"/>
<target name="pkgbuild" depends="pkgbuild-preflight,distribute,download-jre,build-pkg"/>
<target name="makeself" depends="makeself-preflight,distribute,download-jre,build-run"/>
</project>
Loading

0 comments on commit 34d6873

Please sign in to comment.