Donnerstag, 19. Januar 2012

webOS: Using ANT


I like ANT. I like the ANT integration in Eclipse. I like having all the targets of my project visible in a neat tree and just having to click on one to execute them.

Developing webOS applications is done using a few batch scripts that are provided by the SDK. You can find the scripts in the bin folder of your SDK installation directory. Newer versions of the SDK add this directory to your path (at least on Windows, haven't tried it on other platforms for some time), so you can just open a console and type the command to build your application.

So I came up with the idea of an ANT build script for the webOS batch files. Nothing fancy just a few targets, so I don't have to leave Eclipse in order to build my application.

<?xml version="1.0" encoding="UTF-8"?>
<project name="TestProject" default="all">
  <description>
    ANT project for HP Touchpad development
  </description>
  <property name="appinfo.id" value="codebrocken.test" />
  <property name="appinfo.version" value="1.0.0" />
  <property name="appinfo.title" value="TestProject" />
  <property name="appinfo.vendor" value="CodeBrocken" />

  <!-- ================================= 

    target: all              

    ================================= -->

  <target name="all" depends="depends" description="Build the project.">
  </target>

  <!-- - - - - - - - - - - - - - - - - - 

    target: depends                      

    - - - - - - - - - - - - - - - - - -->

  <target name="depends">
  </target>

  <!-- ================================= 

    target: package              

    ================================= -->

  <target name="package" depends="depends" description="Package the application.">
    <copy file="appinfo.json.in" tofile="src/appinfo.json">
      <filterchain>
        <replacetokens>
          <token key="id" value="${appinfo.id}" />
          <token key="version" value="${appinfo.version}" />
          <token key="title" value="${appinfo.title}" />
          <token key="vendor" value="${appinfo.vendor}" />
        </replacetokens>
      </filterchain>
    </copy>

    <exec executable="cmd">
      <arg value="/c" />
      <arg value="palm-package" />
      <arg value="src" />
      <arg value="-o" />
      <arg value="bin" />
    </exec>
  </target>

  <!-- ================================= 

    target: deploy              

    ================================= -->

  <target name="deploy" depends="package" description="Deploy to device.">
    <exec executable="cmd">
      <arg value="/c" />
      <arg value="palm-install" />
      <arg value="bin/${appinfo.id}_${appinfo.version}_all.ipk" />
    </exec>
  </target>

  <!-- ================================= 

    target: launch              

    ================================= -->

  <target name="launch" depends="deploy" description="Launch the application on the device.">
    <exec executable="cmd">
      <arg value="/c" />
      <arg value="palm-launch" />
      <arg value="${appinfo.id}" />
    </exec>
  </target>

  <!-- ================================= 
 
    target: log              

    ================================= -->

  <target name="log" depends="depends" description="Start logging for the application on the device.">
    <exec executable="cmd">
      <arg value="/c" />
      <arg value="palm-log" />
      <arg value="-f" />
      <arg value="${appinfo.id}" />
    </exec>
  </target>

  <!-- ================================= 

    target: emulator              

    ================================= -->

  <target name="emulator" depends="depends" description="Start the emulator">
    <exec executable="cmd">
      <arg value="/c" />
      <arg value="palm-emulator" />
    </exec>
  </target>
</project>

The interesting targets of the build file are:
  • emulator - start the emulator
  • log - start live logging for your application on the device
  • launch - package, install and launch your application on the device
The targets package and deploy are used by launch to create and install the application on the device.

The package target uses string token replacement to modify the template for my appinfo.json file. This way I do not have to touch the file and can reuse it in my next application. See my post about the string token replacement.

1 Kommentar: