Skip to content

Instantly share code, notes, and snippets.

@tresf
Last active February 22, 2019 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tresf/3b91b221ce95217e5a967ebc9e46f21f to your computer and use it in GitHub Desktop.
Save tresf/3b91b221ce95217e5a967ebc9e46f21f to your computer and use it in GitHub Desktop.
JavaFX download ant
<project name="test" default="download-javafx" basedir=".">
<target name="download-javafx" depends="download-javafx-windows,download-javafx-mac,download-javafx-linux,copy-native-current,copy-native-target">
<echo>Windows:</echo>
<echo> current.platform.windows=${current.platform.windows}</echo>
<echo> target.platform.windows=${target.platform.windows}</echo>
<echo> javafx.windows.needed=${javafx.windows.needed}</echo>
<echo> javafx.windows.found=${javafx.windows.found}</echo>
<echo/>
<echo>Mac:</echo>
<echo> current.platform.mac=${current.platform.mac}</echo>
<echo> target.platform.mac=${target.platform.mac}</echo>
<echo> javafx.mac.needed=${javafx.mac.needed}</echo>
<echo> javafx.mac.found=${javafx.mac.found}</echo>
<echo/>
<echo>Linux:</echo>
<echo> current.platform.linux=${current.platform.linux}</echo>
<echo> target.platform.linux=${target.platform.linux}</echo>
<echo> javafx.linux.needed=${javafx.linux.needed}</echo>
<echo> javafx.linux.found=${javafx.linux.found}</echo>
<echo/>
</target>
<!-- Gets the javafx version and version url -->
<target name="get-javafx-version">
<!-- <property file="ant/project.properties"/> -->
<property name="javafx.version" value="11.0.2"/>
<property name="javafx.mirror" value="https://gluonhq.com/download"/>
<property name="lib.dir" value="lib"/>
<property name="dist.dir" value="out/dist"/>
<!-- end properties -->
<loadresource property="javafx.version-url">
<propertyresource name="javafx.version"/>
<filterchain>
<tokenfilter>
<filetokenizer/>
<replacestring from="." to="-"/>
</tokenfilter>
</filterchain>
</loadresource>
</target>
<!-- Flags if javafx is needed for a particular platform-->
<target name="check-javafx-needed" depends="get-javafx-version">
<condition property="javafx.windows.needed" value="true">
<or>
<isset property="current.platform.windows"/>
<isset property="target.platform.windows"/>
</or>
</condition>
<condition property="javafx.mac.needed" value="true">
<or>
<isset property="current.platform.mac"/>
<isset property="target.platform.mac"/>
</or>
</condition>
<condition property="javafx.linux.needed" value="true">
<or>
<isset property="current.platform.linux"/>
<isset property="target.platform.linux"/>
</or>
</condition>
</target>
<!-- Downloads and extracts javafx for Windows -->
<target name="download-javafx-windows" if="javafx.windows.needed" unless="javafx.windows.found" depends="check-javafx-needed,check-javafx-found">
<antcall target="download-javafx-platform">
<param name="javafx.platform" value="windows"/>
</antcall>
</target>
<!-- Downloads and extracts javafx for macOS -->
<target name="download-javafx-mac" if="javafx.mac.needed" unless="javafx.mac.found" depends="check-javafx-needed,check-javafx-found">
<antcall target="download-javafx-platform">
<param name="javafx.platform" value="mac"/>
</antcall>
</target>
<!-- Downloads and extracts javafx for linux -->
<target name="download-javafx-linux" if="javafx.linux.needed" unless="javafx.linux.found" depends="check-javafx-needed,check-javafx-found">
<antcall target="download-javafx-platform">
<param name="javafx.platform" value="linux"/>
</antcall>
</target>
<!-- Downloads and extracts javafx for the specified platform -->
<target name="download-javafx-platform">
<get src="${javafx.mirror}/javafx-${javafx.version-url}-sdk-${javafx.platform}/" verbose="true" dest="javafx-${javafx.platform}.zip"/>
<unzip src="javafx-${javafx.platform}.zip" dest="${lib.dir}" overwrite="true"/>
<delete file="javafx-${javafx.platform}.zip"/>
</target>
<!-- Removes old javafx versions -->
<target name="cleanup-javafx" depends="get-javafx-version">
<delete>
<fileset dir="${lib.dir}">
<include name="**/javafx*/**"/>
<exclude name="**/javafx*${javafx.version}*/**"/>
</fileset>
</delete>
</target>
<!-- Copies native libraries for current platform -->
<target name="copy-native-current" depends="check-javafx-needed">
<condition property="javafx.current.extension" value="dll">
<isset property="current.platform.windows"/>
</condition>
<condition property="javafx.current.extension" value="dylib">
<isset property="current.platform.mac"/>
</condition>
<condition property="javafx.current.extension" value="so">
<isset property="current.platform.linux"/>
</condition>
<echo>javafx.current.extension=${javafx.current.extension}</echo>
<antcall target="copy-native-platform">
<param name="dest.dir" value="${dist.dir}"/>
<param name="prefix.pattern" value="javafx*/"/>
<param name="native.extension" value="${javafx.current.extension}"/>
</antcall>
</target>
<!-- Copies native libraries for target platform -->
<target name="copy-native-target">
<condition property="javafx.target.extension" value="dll">
<isset property="target.platform.windows"/>
</condition>
<condition property="javafx.target.extension" value="dylib">
<isset property="target.platform.mac"/>
</condition>
<condition property="javafx.target.extension" value="so">
<isset property="target.platform.linux"/>
</condition>
<echo>javafx.target.extension=${javafx.target.extension}</echo>
<antcall target="copy-native-platform">
<param name="dest.dir" value="${dist.dir}"/>
<param name="prefix.pattern" value="javafx*/"/>
<param name="native.extension" value="${javafx.target.extension}"/>
</antcall>
</target>
<!-- Copies native libraries for specified platform -->
<target name="copy-native-platform">
<copy todir="${dest.dir}/libs" flatten="true">
<fileset dir="${lib.dir}">
<include name="${prefix.pattern}**/*.${native.extension}"/>
</fileset>
</copy>
</target>
<!-- Flags if javafx is already downloaded for a particular platform -->
<target name="check-javafx-found" depends="cleanup-javafx">
<first id="windows-found">
<fileset dir="${lib.dir}">
<include name="**/glass.dll"/>
</fileset>
</first>
<condition property="javafx.windows.found" value="${toString:windows-found}">
<not><equals arg1="${toString:windows-found}" arg2=""/></not>
</condition>
<property name="javafx.windows.files" value="${toString:windows-found}"/>
<first id="mac-found">
<fileset dir="${lib.dir}">
<include name="**/libglass.dylib"/>
</fileset>
</first>
<condition property="javafx.mac.found" value="${toString:mac-found}">
<not><equals arg1="${toString:mac-found}" arg2=""/></not>
</condition>
<property name="javafx.mac.files" value="${toString:mac-found}"/>
<first id="linux-found">
<fileset dir="${lib.dir}">
<include name="**/libglass.so"/>
</fileset>
</first>
<condition property="javafx.linux.found" value="${toString:linux-found}">
<not><equals arg1="${toString:linux-found}" arg2=""/></not>
</condition>
<property name="javafx.linux.files" value="${toString:linux-found}"/>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment