Last active
October 1, 2015 08:07
-
-
Save jasonhofer/1951532 to your computer and use it in GitHub Desktop.
Apache Ant "which" scriptdef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<property environment="env" /> | |
<property name="env.PATH" value="${env.Path}" /><!-- because windows --> | |
<scriptdef name="which" language="javascript"> | |
<attribute name="command" /> | |
<attribute name="property" /> | |
<![CDATA[ | |
var cmd = attributes.get("command") || ""; | |
var prop = attributes.get("property") || ""; | |
if ("" == cmd ) throw new Error("The attribute 'command' is required for the Which task."); | |
if ("" == prop) throw new Error("The attribute 'property' is required for the Which task."); | |
var path = project.getProperty("env.PATH") || ""; | |
var exts = project.getProperty("env.PATHEXT") || ""; // only windows will have this | |
var uri = null; | |
var res = cmd + ".uri"; | |
var which = project.createTask("whichresource"); | |
which.setProperty(res); | |
which.createClasspath().createPath().setPath(path); | |
for each (var ext in exts.split(";")) { | |
which.setResource(cmd + ext); | |
which.execute(); | |
uri = project.getProperty(res); | |
if (null !== uri) { | |
importClass(Packages.org.apache.tools.ant.util.FileUtils); | |
project.setNewProperty(prop, FileUtils.getFileUtils().fromURI(uri)); | |
break; | |
} | |
} | |
]]> | |
</scriptdef> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment