Skip to content

Commit 34d6873

Browse files
tresfBerenzVzor-
authored
jlink branch, rebased (#4)
* 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]>
1 parent 802d1f8 commit 34d6873

22 files changed

+765
-198
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ matrix:
1919
language: java
2020
dist: trusty
2121
before_script:
22-
- sw_vers -productVersion && brew update && brew install ant; ant -version
22+
- 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
2323
- test -e /etc/lsb-release && sudo apt-get update -qq && sudo apt-get install -y makeself nsis; echo;
2424
script: ant $TARGET

ant/apple/apple-entitlements.plist

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.cs.allow-jit</key>
6+
<true/>
7+
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
8+
<true/>
9+
<key>com.apple.security.cs.disable-executable-page-protection</key>
10+
<true/>
11+
<key>com.apple.security.cs.disable-library-validation</key>
12+
<true/>
13+
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
14+
<true/>
15+
</dict>
16+
</plist>

ant/apple/installer.xml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<target name="pkgbuild-preflight">
1212
<property name="target.platform.mac" value="true"/>
1313
</target>
14-
<target name="build-pkg" depends="get-version">
14+
<target name="build-pkg" depends="codesign-jre,get-version">
1515
<echo level="info">Creating installer using pkgbuild</echo>
1616

1717
<property file="ant/apple/apple.properties"/>
@@ -62,6 +62,9 @@
6262
<include name="**/${project.name}"/>
6363
<include name="**/uninstall"/>
6464
</fileset>
65+
<fileset dir="${build.dir}/scripts/payload/PlugIns/Java.runtime/Contents/Home/bin">
66+
<include name="**"/>
67+
</fileset>
6568
</chmod>
6669

6770
<!-- Disable signing and append "-community" if id is missing -->
@@ -102,8 +105,32 @@
102105
</exec>
103106

104107
<!-- Cleanup lingering files (for other OS installers) -->
105-
<delete dir="${dist.dir}/Contents/Resources"/>
106-
<delete dir="${dist.dir}/Contents/MacOS"/>
108+
<!-- FIXME BRING BACK BEFORE MERGE <delete dir="${dist.dir}/Contents/Resources"/> -->
109+
<!-- FIXME BRING BACK BEFORE MERGE <delete dir="${dist.dir}/Contents/MacOS"/> -->
110+
<!-- FIXME BUILD AN APP HERE LOCALLY -->
111+
<delete dir="${dist.dir}/../QZ Tray.app"/>
112+
<move todir="${dist.dir}/../QZ Tray.app">
113+
<fileset dir="${dist.dir}"/>
114+
</move>
115+
<chmod perm="a+x">
116+
<fileset dir="${dist.dir}/../QZ Tray.app/Contents/MacOS"/>
117+
</chmod>
118+
</target>
119+
120+
<target name="codesign-jre" if="codesign.mac">
121+
<property file="ant/apple/apple.properties"/>
122+
<exec executable="codesign" failonerror="true">
123+
<arg value="--force"/>
124+
<arg value="-s"/>
125+
<arg value="${apple.packager.signid}"/>
126+
<arg value="--timestamp"/>
127+
<arg value="--options"/>
128+
<arg value="runtime"/>
129+
<arg value="--entitlements"/>
130+
<arg value="${basedir}/ant/apple/apple-entitlements.plist"/>
131+
<arg value="--deep"/>
132+
<arg value="${dist.dir}/PlugIns/Java.runtime"/>
133+
</exec>
107134
</target>
108135

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

146173
</target>

ant/unix/unix-launcher.sh.in

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ if [ -n "$JAVA_HOME" ]; then
3232
PATH="$JAVA_HOME/bin:$PATH"
3333
fi
3434

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

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

48-
if [[ "$OSTYPE" == "darwin"* ]]; then
49-
DEFAULTS_READ=$(defaults read ${apple.bundleid} ${launch.overrides} 2>/dev/null) || true
50-
if [ -n "$DEFAULTS_READ" ]; then
51-
echo -e "$MESSAGE Picked up additional launch options: $DEFAULTS_READ"
52-
LAUNCH_OPTS="$LAUNCH_OPTS $DEFAULTS_READ"
53-
fi
54-
ICON_PATH="$DIR/Contents/Resources/apple-icon.icns"
55-
MAC_PRIMARY="/usr/libexec/java_home"
56-
MAC_FALLBACK="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin"
57-
echo "Trying $MAC_PRIMARY..."
58-
if "$MAC_PRIMARY" -v $JAVA_MIN+ &>/dev/null; then
59-
echo -e "$SUCCESS Using \"$MAC_PRIMARY -v $JAVA_MIN+ --exec\" to launch $ABOUT_TITLE"
60-
java() {
61-
"$MAC_PRIMARY" -v $JAVA_MIN+ --exec java "$@"
62-
}
63-
elif [ -d "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin" ]; then
64-
echo -e "$WARNING No luck using $MAC_PRIMARY"
65-
echo "Trying $MAC_FALLBACK..."
66-
java() {
67-
"$MAC_FALLBACK/java" "$@"
68-
}
69-
fi
48+
# Fallback on some known locations
49+
if ! command -v java > /dev/null ; then
50+
if [[ "$OSTYPE" == "darwin"* ]]; then
51+
# Apple: Fallback on system-wide install
52+
DEFAULTS_READ=$(defaults read ${apple.bundleid} ${launch.overrides} 2>/dev/null) || true
53+
if [ -n "$DEFAULTS_READ" ]; then
54+
echo -e "$MESSAGE Picked up additional launch options: $DEFAULTS_READ"
55+
LAUNCH_OPTS="$LAUNCH_OPTS $DEFAULTS_READ"
56+
fi
57+
MAC_PRIMARY="/usr/libexec/java_home"
58+
MAC_FALLBACK="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin"
59+
echo "Trying $MAC_PRIMARY..."
60+
if "$MAC_PRIMARY" -v $JAVA_MIN+ &>/dev/null; then
61+
echo -e "$SUCCESS Using \"$MAC_PRIMARY -v $JAVA_MIN+ --exec\" to launch $ABOUT_TITLE"
62+
java() {
63+
"$MAC_PRIMARY" -v $JAVA_MIN+ --exec java "$@"
64+
}
65+
elif [ -d "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin" ]; then
66+
echo -e "$WARNING No luck using $MAC_PRIMARY"
67+
echo "Trying $MAC_FALLBACK..."
68+
java() {
69+
"$MAC_FALLBACK/java" "$@"
70+
}
71+
fi
72+
else
73+
# Linux/Unix: Fallback on known install location(s)
74+
PATH="$PATH:/usr/java/latest/bin/"
75+
fi
76+
fi
77+
78+
if command -v java > /dev/null ; then
79+
echo -e "$SUCCESS Java was found: $(command -v java)"
7080
else
71-
export PATH="$PATH:/usr/java/latest/bin/"
81+
echo -e "$FAILURE Please install Java $JAVA_MIN or higher to continue"
82+
exit 1
7283
fi
7384

7485
# Make sure Java version is sufficient
@@ -96,7 +107,7 @@ if command -v java &>/dev/null; then
96107
else
97108
prefix="../../" # back two directories, e.g. postinstall
98109
fi
99-
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 "$@"
110+
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 "$@"
100111
else
101112
java $LAUNCH_OPTS -jar "$PROPS_FILE.jar" "$@"
102113
fi

ant/windows/nsis/Include/FindJava.nsh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ Var /GLOBAL javaw
3838
IfFileExists "$0" Found
3939
!macroend
4040

41+
!macro _ReadPayload root path
42+
ClearErrors
43+
StrCpy $0 "${root}\${path}\bin\${EXE}"
44+
IfFileExists $0 Found
45+
!macroend
46+
4147
!macro _ReadWorking path
4248
ClearErrors
4349
StrCpy $0 "$EXEDIR\${path}\bin\${EXE}"
@@ -54,10 +60,17 @@ Var /GLOBAL javaw
5460
; Create the shared function.
5561
!macro _FindJava un
5662
Function ${un}FindJava
63+
; Snag payload directory
64+
exch $R0
65+
5766
${If} ${RunningX64}
5867
SetRegView 64
5968
${EndIf}
6069

70+
; Check payload directories
71+
!insertmacro _ReadPayload "$R0" "jre"
72+
!insertmacro _ReadPayload "$R0" "jdk"
73+
6174
; Check relative directories
6275
!insertmacro _ReadWorking "jre"
6376
!insertmacro _ReadWorking "jdk"
@@ -80,6 +93,9 @@ Var /GLOBAL javaw
8093
StrCpy $java $0
8194
${StrRep} '$java' '$java' 'javaw.exe' '${EXE}' ; AdoptOpenJDK returns "javaw.exe"
8295
${StrRep} '$javaw' '$java' '${EXE}' 'javaw.exe'
96+
97+
; Discard payload directory
98+
pop $R0
8399
FunctionEnd
84100
!macroend
85101

ant/windows/windows-installer.nsi.in

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,22 @@ Section
7272
System::Call 'Kernel32::SetEnvironmentVariable(t, t)i ("${vendor.name}_silent", "1").r0'
7373
${EndIf}
7474

75+
; Echo final destination to logs
76+
SetOutPath $INSTDIR
77+
78+
; Copy files to a temporary location
79+
SetOutPath "$PLUGINSDIR\payload"
80+
DetailPrint "Extracting..."
81+
SetDetailsPrint none ; Temporarily suppress details
82+
File /r "${dist.dir}\*"
83+
7584
; Set the $java variable
7685
TryAgain:
86+
Push "$OUTDIR"
7787
Call FindJava
7888
!insertmacro VerifyJava "TryAgain"
7989

80-
SetOutPath $INSTDIR
81-
8290
; Run preinstall tasks
83-
SetOutPath "$PluginsDir\tmp"
84-
DetailPrint "Extracting..."
85-
SetDetailsPrint none ; Temporarily suppress details
86-
File /r "${dist.dir}\*"
8791
SetDetailsPrint both
8892
!insertmacro QzInstaller "preinstall" "" ""
8993

ant/windows/windows-launcher.nsi.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Section
3939
${GetParameters} $params
4040

4141
; Sets the $java variable
42+
Push "$EXEDIR"
4243
Call FindJava
4344

4445
Var /GLOBAL opts

ant/windows/windows-uninstaller.nsi.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Section
6464
${EndIf}
6565

6666
; Set $javaw variable
67+
Push "$DELETE_DIR"
6768
Call FindJava
6869

6970
; Run uninstall step using jar

build.xml

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<import file="ant/linux/installer.xml"/>
99
<import file="ant/windows/installer.xml"/>
1010

11-
<target name="distribute" depends="init,clean,download-javafx,build-jar,override-authcert,include-assets,whitelist-certs">
11+
<target name="distribute" depends="init,download-javafx,build-jar,override-authcert,include-assets,whitelist-certs">
1212
<antcall target="tidy-javafx-dist"/>
1313
<echo level="info">Process complete</echo>
1414
</target>
@@ -37,7 +37,7 @@
3737
</target>
3838

3939
<target name="clean" depends="init">
40-
<delete dir="${out.dir}"/>
40+
<!-- <delete dir="${out.dir}"/> -->
4141
</target>
4242

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

87-
<echo level="info">Building Jar for Socket use</echo>
87+
<echo level="info">Building jar</echo>
8888
<mkdir dir="${sign.lib.dir}"/>
89-
<jar compress="${jar.compress}" index="${jar.index}" destfile="${dist.dir}/${project.filename}.jar" duplicate="preserve">
89+
<jar compress="false" index="${jar.index}" destfile="${out.dir}/${project.filename}.jar.tmp" duplicate="preserve">
9090
<fileset dir="${build.dir}/${project.filename}"/>
9191
<zipgroupfileset dir="${sign.lib.dir}" includes="**/*.jar" erroronmissingdir="false"/>
9292
<zipgroupfileset dir="lib">
9393
<include name="**/*.jar"/>
9494
<exclude name="**/jfxrt.jar"/>
9595
<exclude name="**/jssc-*.jar" if="codesign.mac"/>
9696
</zipgroupfileset>
97+
</jar>
98+
<!-- Strip jlink-incompat files -->
99+
<echo level="info">Stripping jlink-incompatible files</echo>
100+
<jar compress="${jar.compress}" index="${jar.index}" destfile="${dist.dir}/${project.filename}.jar" duplicate="preserve">
101+
<zipfileset src="${out.dir}/${project.filename}.jar.tmp" excludes="*.class,LICENSE,jetty-dir.css"/>
97102
<manifest>
98103
<attribute name="Application-Name" value="${project.name}"/>
99104
<attribute name="Main-Class" value="qz.ws.PrintSocketServer"/>
100105
<attribute name="Permissions" value="all-permissions"/>
101106
</manifest>
102107
</jar>
108+
<delete file="${out.dir}/${project.filename}.jar.tmp"/>
103109

104110
<antcall target="sign-jar">
105111
<param name="sign.jar.file" value="${dist.dir}/${project.filename}.jar"/>
@@ -139,7 +145,24 @@
139145
</copy>
140146
</target>
141147

142-
<target name="nsis" depends="nsis-preflight,distribute,build-exe"/>
143-
<target name="pkgbuild" depends="pkgbuild-preflight,distribute,build-pkg"/>
144-
<target name="makeself" depends="makeself-preflight,distribute,build-run"/>
148+
<target name="download-jre">
149+
<condition property="target.platform" value="windows">
150+
<isset property="target.platform.windows"/>
151+
</condition>
152+
<condition property="target.platform" value="mac">
153+
<isset property="target.platform.mac"/>
154+
</condition>
155+
<property description="target.platform default" name="target.platform" value="linux"/>
156+
157+
<echo level="info">Downloading and bundling the jre for ${target.platform}</echo>
158+
<java jar="${dist.dir}/${project.filename}.jar" fork="true">
159+
<arg value="jlink"/>
160+
<arg value="--platform"/>
161+
<arg value="${target.platform}"/>
162+
</java>
163+
</target>
164+
165+
<target name="nsis" depends="nsis-preflight,distribute,download-jre,build-exe"/>
166+
<target name="pkgbuild" depends="pkgbuild-preflight,distribute,download-jre,build-pkg"/>
167+
<target name="makeself" depends="makeself-preflight,distribute,download-jre,build-run"/>
145168
</project>

0 commit comments

Comments
 (0)