Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Jruby Rake's Ant integration, strategies for handling ant's xml namespace support

Tags:

rake

ant

jruby

I'm trying to use JavaFX's ant tasks from rake, and can't figure out how to handle the xml-namespacing: http://ant.apache.org/manual/Types/namespace.html

A build.xml file doing similar work would look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorldApp" default="default" basedir="."
         xmlns:fx="javafx:com.sun.javafx.tools.ant">
    <path id="fxant">
      <filelist>
        <file name="${java.home}\..\lib\ant-javafx.jar"/>
        <file name="${java.home}\lib\jfxrt.jar"/>
      </filelist>
    </path>
    <target name="default">
        <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
                uri="javafx:com.sun.javafx.tools.ant"
                classpath="${java.home}\..\lib\ant-javafx.jar"/>
    </target>
<target name="package-bundle">
      <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
                uri="javafx:com.sun.javafx.tools.ant"
                classpath="${java.home}\..\lib\ant-javafx.jar"/>
      <fx:deploy nativeBundles="all"
                   width="100" height="100"
                   outdir="build/" outfile="HelloWorldApp">
            <info title="Hello World App" vendor="Me"
                     description="Test built from Java executable jar"/>
            <fx:application mainClass="org.jruby.JarBootstrapMain"/>
            <fx:resources>
               <fx:fileset dir="dist">
                  <include name="HelloWorldApp.jar"/>
               </fx:fileset>
            </fx:resources>
      </fx:deploy>
</target>
</project>

The problem comes in with those tasks like "fx:deploy", when I start converting this into a Rakefile, I can't get far because I can't figure out how to tell ant about that "fx" namespace. I've searched for a couple days, but all I've turned up is a blog post from headius that says, "note to self: figure out if we have an equivalent for that" ( http://headius.blogspot.com/2010/04/using-ivy-with-jruby-15s-ant.html ). In his example, he seemed to be able to just ignore it, but that's not working in this instance.

The JavaFX packaging tasks provide some really cool stuff, especially beginning with Java 8, including the ability to create native installers for every platform from any executable jar. I think this could be really useful.

like image 832
Edub Kendo Avatar asked Nov 04 '22 06:11

Edub Kendo


1 Answers

Ok so we are missing some magic, but all is not lost I have a workaround. To call an XML namespaced task you need to do a send to the fully qualified xml uri. This is a bit ugly but not as ugly as it could have been since only the top parent needs to do this hack and child qualified elements are relative to their parent so they do not also need to do a send. I added an enhancement issue for this here:

require 'ant'

task :default do
  ant.echo message: "${java.home}"
  ant.taskdef(resource: "com/sun/javafx/tools/ant/antlib.xml",
              uri: "javafx:com.sun.javafx.tools.ant",
              classpath: "${java.home}/../lib/ant-javafx.jar")
end

task :package_bundle do
  ant do
    taskdef(resource: "com/sun/javafx/tools/ant/antlib.xml",
            uri: "javafx:com.sun.javafx.tools.ant",
            classpath: "${java.home}/../lib/ant-javafx.jar")
    __send__("javafx:com.sun.javafx.tools.ant:deploy", nativeBundles: "all", 
             width: "100", height: "100", outdir: "build/",
             outfile: "HelloWorldApp") do
      info(title: "Hello World App", vendor: "Me",
           description: "Test built from Java executable jar")
      application(mainClass: "org.jruby.JarBootstrapMain")
      resources do
        fileset(dir: "dist") do
          include name: "HelloWorldApp.jar"
        end
      end
    end
  end
end
like image 72
Thomas Enebo Avatar answered Nov 09 '22 10:11

Thomas Enebo