FDT Ant Tasks

From FDT Documentation

Jump to: navigation, search

Along with support for ANT's built in tasks, FDT provides some Ant tasks of its own. To assure that these tasks work, the task has to run in the same JRE (Java Runtime Environment) as Eclipse.

Contents

JRE - A Common Pitfall

Before getting into Ant, an important concept to understand is how Ant tools, by default, run in their own JRE. If you get the error:

BUILD FAILED Could not create task or type ...

It's most likely because your Ant file is not executing in the same JRE as FDT.

Learn more about setting up the JRE with the FDT and Ant Tutorial.

FDT Launchers

FDT ships with a number of launchers for you to use when viewing your applications.

<fdt.launch.application projectname="AirDebugTest" 
debug="true" startswf="true" swflauncher="AIR Debug Launcher" 
mainclass="src/Main.mxml" target="Main.swf" />


The below values are applicable when using the swflauncher argument:

  • External SWF Viewer
  • Adobe Flash Player
  • Browser
  • Internal SWF Viewer
  • AIR Debug Launcher

FDT Tasks

Here are a list of FDT tasks that ship with FDT.

Some tasks have arguments such as false, no, off, on, true, yes. These all get converted to Boolean arguments, so false, no and off are the same as are on, true and yes.

fdt.exportAirApplication (FDT 5.6)

This task executes the same behaviour as pressing the 'Export Application' button within 'Mobile properties > Deploy'

<project default="myProject">
     <target name="export">
           <fdt.exportAirApplication project="Desktop" platform="AirDesktop" />
     </target>
</project>

fdt.invoke.launchConfiguration (FDT 5.5)

This task executes an existing launch configuration.

<fdt.invoke.launchConfiguration file=".settings/launch/AntTask.launch" mode="debug" />

Arguments:

  1. file : The location of the launch configuration.
  2. mode : How FDT launches the run configuration. Values can be debug, run or profile.

Example: Runs a launch configuration named AntTask in debug mode.

<project name="Features" default="echo.project.properties">
  <target name="fdt.invoke.launchConfiguration">
	 <fdt.invoke.launchConfiguration file=".settings/launch/AntTask.launch" mode="debug" />
   </target>
</project>



fdt.loadProjectProperties (FDT 4.1)

With this task users can access the properties associated with any open project within the workspace.

<fdt.loadProjectProperties/>


Arguments:

  1. projectpath : The location of the project within the workspace to access properties from. When referencing other projects, the project root should be referenced relative to the location of the Ant file.


Example: Echo properties of the project which the ant file is currently in and then echo the properties of a different project.

<project name="Features" default="echo.project.properties">
  <target name="echo.project.properties">
	  <fdt.loadProjectProperties/>
	  <echo message="${FDTProject}" />
	  <echo message="${FDTProjectPath}" />
	  <echo message="${FDTProjectSdkPath}" />
	  <echo message="${FDTProjectSdkName}" />
	  <echo message="${FDTProjectSdkVersion}" />
	  <echo message="${FDTProjectPlayerVersion}" />
	  <echo message="${FDTProjectKind}" />
          <echo message="${FDTHostIP}" />
 
	  <fdt.loadProjectProperties projectpath="./../my_other_project"/>
	  <echo message="${FDTProject}" />
	  <echo message="${FDTProjectPath}" />
	  <echo message="${FDTProjectSdkPath}" />
	  <echo message="${FDTProjectSdkName}" />
	  <echo message="${FDTProjectSdkVersion}" />
	  <echo message="${FDTProjectPlayerVersion}" />
	  <echo message="${FDTProjectKind}" />
          <echo message="${FDTHostIP}" />
   </target>
</project>



fdt.browse

Opens a document in the Browser.

<fdt.browse location="url" />


Arguments:

  1. location : the location of the file to open.
  2. url : the location of the file to open.

*note: location and url are interpreted as by FDT as the same. The two naming conventions are provided for your connivence.

Example: Open index.php located on a local server in the default browser.

<project default="default">
  <target name="default">
    <fdt.browse location="http://localhost/index.php" /> 
  </target>
</project>



fdt.extSWFViewer.focusWindow

Focuses a running process. The window containing the process will pop up to the foreground.

<fdt.extSWFViewer.focusWindow process="executable" />


Arguments:

  1. process : the name of the process to focus.
  2. delay : amount in milliseconds before focus takes effect.

Example: Set focus to Eclipse.

<project default="default">
  <target name="default">
    <fdt.extSWFViewer.focusWindow process="javaw.exe" />
  </target>
</project>



fdt.extSWFViewer.startSWF

An existing SWF file is started in the external SWF Viewer.

<fdt.extSWFViewer.focusWindow process="executable" />


Arguments:

  1. file : the name of the file to run.
  2. width : the width of the window.
  3. height : the height of the window.
  4. flashvars : the variables passing to Flash (optional).
  5. focusprocess : the name of the process to focus (optional).

Example: Start SWF in external swf viewer with given size and flashvars and set focus to Flash IDE.

<project default="default">
  <target name="default">
    <fdt.extSWFViewer.startSWF file="${basedir}/start.swf" width="640" height="480" 
         flashvars="a=1&amp;b=2" focusprocess="flash.exe"/>
  </target> 
</project>



fdt.flashCompile

This task compiles a single FLA or a set of FLA's with the Flash IDE. The Flash IDE must be set in the Flash Preferences see (Managing External Dependencies). The Flash Output is captured and shown in the console. If any error occurs the build will be aborted. You can define a timeout for how long the build waits for the output. If the timeout is not specified, the task will take a 60 second timeout.

<fdt.flashCompile file="fla" timeout="t in ms " />


Arguments:

  1. file : the FLA to compile
  2. timeout : the timeout(ms) for how long the tasks wait until it fails
  3. failonerror : whether the ant should fail if flash outputs something. Default is "true"


Example: Compile for a single FLA with a timout of 5 seconds.

<project default="default"> <target name="default">
  <fdt.flashCompile file="${basedir}/start.fla" timeout="5000"> </target>
</project>


Example: Compile for a set of FLA's and two additional FLA's.

<project default="default">
  <target name="default">
    <fdt.flashCompile> 
      <fileset dir="${basedir}">
         <include name="*.fla"/>
      </fileset>
    </fdt.flashCompile>
    <fdt.flashCompile file="${basedir}/data/start.fla" failonerror="false"/> 
    <fdt.flashCompile file="${basedir}/data/main.fla"/>
   </target> 
</project>



fdt.launch.application

update: This will not work for AIR projects. Instead use fdt.invoke.launchConfiguration (FDT 5.5) and fdt.exportAirApplication (FDT 5.6) Compile your applications to a .SWF using this task. This task is essentially an Ant version of the built in launcher. Just like the built in launcher, you can launch your .SWF with a particular viewer, debug and profile. FDT will automatically incorporate it's incremental compilation as it does with the launcher.

<fdt.launch.application projectname="HelloWorld" mainclass="src/test/Main.as" debug="true"  
    target="${basedir}/Main.swf" startswf="true" swflauncher="Adobe Flash Player"/>


*note:Currently this task requires that no spaces exist in your project's name. E.g using projectname="Hello World" will fail but projectname="HelloWorld" will work fine.

Arguments:

  1. projectname : name of the project that contains the source.
  2. mainclass : path to the 'Main' or 'Document' class for your .SWF.
  3. debug : flag whether to compile the SWF for debugging.
  4. profile : flag whether to compile the SWF and launch the profiler.
  5. target : the path to the SWF to create, relative to the used project
  6. compilerarguments : any arguments that should be used for compiling. If no arguments are provided FDT's default arguments are used.
  7. startswf : should the created SWF launched immediatly?
  8. swflauncher : The viewer to be should be used to launch the SWF: "External SWF Viewer", "Adobe Flash Player", "Internal SWF Viewer" or AIR Debug Launcher.
  9. autoaddclasspath : optional setting for FDT to auto detect source folders and include them in the build. By default this is set to true.
  10. autoaddswcs : optional setting for FDT to auto detect designated .SWC files and include them in the build. By default this is set to true.
  11. autoaddrsls : optional setting to use Flex's Using Runtime Shared Libraries. By default it is set to false.


Example: Compile to a SWF.

<project default="default">
  <target name="default">
    <fdt.launch.application projectname="HelloWorld" mainclass="src/test/Main.as"
         debug="true" target="${basedir}/Main.swf" startswf="false"/>
  </target>
</project>



fdt.launch.library

You can use this task to create SWC files. All options from the "AS3 FDT Library" launcher are available.

<fdt.launch.library projectname="HelloWorld" debug="false" target="${basedir}/Main.swc"/>

Arguments:

  1. autoaddrsls : optional setting to use Flex's Using Runtime Shared Libraries. By default it is set to false.
  2. autoaddswcs : optional setting for FDT to auto detect designated .SWC files and include them in the build. By default this is set to true.
  3. compilerarguments : any arguments that should be used for compiling. If no arguments are provided FDT's default arguments are used.
  4. debug : flag whether to compile the SWC with debugging code.
  5. projectname : the name of the project that contains the source.
  6. target : path to the SWC to create.

Example: Compile code to a SWC.

 
<project default="default">
  <target name="default">
    <fdt.launch.library projectname="HelloWorld" debug="true"
         target="${basedir}/Main.swc" />
  </target>
</project>



fdt.launch.resetFlexCompiler

FDT uses an incremental compilation process that reduces compile time significantly. It does this by keeping certain variables in memory; however, there may be a time when you need to reset FDT's compilation process because your class path or some other configuration has changed. When this task is run all incremental information is discarded and next time FDT builds it will be a full build.

This task has no arguments and simply calling it will reset FDT's compiler.

<fdt.launch.resetFlexCompiler/>



fdt.startDebugger

If you have FDT Max installed, you can use the debugger feature. Make sure your .SWF has been compiled and is currently running.

<fdt.startDebugger projectname="My Project" switchperspectiveonbreakpoint="false"/>

Arguments:

  1. projectname: Name of the project whose source code is associated with the running .SWF.
  2. targetswf: The .SWF to target.
  3. switchperspectiveonbreakpoint: Automatically switch to the debug perspective when hitting a breakpoint. The default value is true.
  4. asclient: Puts the debugger into client mode so it will ask for a connection to your application instead of listen for it (server mode). This is required for debugging via usb on mobile devices. The default value is false.
  5. port: Allows you to define a custom port FDT should use for debugging. The default value is 7935.

* The switchperspectiveonbreakpoint argument is part of the FDT4.1 Release * The asclient and port argument is part of the FDT 5 Release


fdt.startProfiler

Another feature with FDT Max is the Profiler. Use this to connect to a running .SWF

<fdt.startProfiler />

Arguments:

  1. collectstackdata: If you want to see back references, stack data has to be collected during Memory Profiling, otherwise you will only have the information displayed in the Live Objects View. Collecting stackdata needs far more performance and slows down the application even more.
  2. excludedpackages: A comma delimitated list of packages to ignore while profiling. E.g. excludedpackages="com.powerflahser.*,com.demo.*,com.fdt.test.*"
  3. filterinternalactions: A filter to hide actions thrown by the AVM during performance profiling.
  4. filterinternalpackages: A filter to hide FDT's native Objects.
  5. includedpackages: A comma delimitated list of packages to include while profiling.
  6. memoryprofilingenabled: Enable Memory Profiling
  7. performanceprofilingenabled: Enable Performance Profiling
  8. projectname: Name of project to profile with.
  9. targetswf: Target .SWF to profile.

Example: Start the profiler.

<fdt.startProfiler collectstackdata="true" filterinternalpackages="true" 
   memoryprofilingenabled="true" performanceprofilingenabled="false" 
   projectname="HelloWorld" targetswf="${basedir}/bin/Main.swf"/>



Other Important Ant Tasks

Ant provides a large number of pre-defined tasks. A good introduction into Ant together with the explanation of the pre-defined tasks can be found in Ant's User's Manual. Some of the for us important ones are briefly described in the following.

exec

Runs an executable file.

Example: Call up of the command line in windows and execution of a ".bat" file.

<target name="run bat"> 
  <exec executable="cmd">
    <arg value="/c"/> 
    <arg value="ant.bat"/> 
    <arg value="-p"/>
  </exec> 
</target>



copy

Copies one or several files/directories.

Example: Make a copy of a single file.

<copy file="myfile.txt" tofile="mycopy.txt"/>


Example: Make a copy of one directory into another one.

<copy todir="../new/dir"> 
  <fileset dir="src_dir"/>
</copy>



zip

Creates a ".zip" file.

Example: Zip a directory and an additional file.

<zip destfile="${dist}/manual.zip"> 
  <fileset dir="htdocs/manual"/> 
  <fileset dir="." includes="ChangeLog.txt"/>
</zip>
Get FDT5