Skip to content

Instantly share code, notes, and snippets.

@rzwitserloot
Last active June 5, 2020 00:09
Show Gist options
  • Save rzwitserloot/4db3fe11556cab3b58013c336baa628d to your computer and use it in GitHub Desktop.
Save rzwitserloot/4db3fe11556cab3b58013c336baa628d to your computer and use it in GitHub Desktop.
<project name="findjvmtest" default="findjvm.jdk8">
<target name="-findjvms.base">
<property file="jvms.properties" />
<available property="tools.exec.javahome" value="/usr/libexec/java_home" file="/usr/libexec/java_home" />
<condition property="tools.exec.reg" value="reg.exe">
<os family="windows" />
</condition>
</target>
<target name="-findjvm.jdk8.mac" unless="jvm.8.loc" if="tools.exec.javahome">
<exec outputproperty="jvm.8.loc.tmp" resultproperty="jvm.8.loc.res" failifexecutionfails="false" executable="${tools.exec.javahome}">
<arg value="-v" />
<arg value="1.8" />
</exec>
<condition property="jvm.8.loc" value="${jvm.8.loc.tmp}">
<equals arg1="${jvm.8.loc.res}" arg2="0" />
</condition>
</target>
<target name="-findjvm.jdk8.win" depends="-findjvms.base" unless="jvm.8.loc" if="tools.exec.reg">
<exec outputproperty="jvm.8.loc.tmp" resultproperty="jvm.8.loc.res" failifexecutionfails="false" executable="${tools.exec.reg}">
<arg value="query" />
<arg value="HKLM\\Software\\JavaSoft\\Java Runtime Environment\\1.8" />
<arg value="/v" />
<arg value="JavaHome" />
<arg value="/e" />
</exec>
<condition property="jvm.8.loc" value="${jvm.8.loc.tmp}">
<equals arg1="${jvm.8.loc.res}" arg2="0" />
</condition>
</target>
<target name="-findjvm.jdk8.manual" depends="-findjvms.base" unless="jvm.8.loc">
<input message="Cannot find the location to a JDK/JRE8 installation; enter the full path to the dir so that resolving 'bin/java' relative to it works, and runs java 1.8. Don't have one? Press enter." addproperty="jvm.8.loc" />
<echoproperties destfile="jvms.properties" regex="jvm\.\d+\.loc" />
</target>
<target name="findjvm.jdk8" depends="-findjvms.base, -findjvm.jdk8.mac, -findjvm.jdk8.win, -findjvm.jdk8.manual">
<echo>Using ${jvm.8.loc}/bin/java for running 1.8 tests</echo>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment