21
Feb
09

Ant task to generate SWC and ASDOC

Ant task to generate SWC and ASDOC for a library.

First create a property file to store location of your sdk and other information regarding your application: asdoc.properties - set properties file;


###################################################################
# Author: Elad Elrom - creates ASDOC and SWC
###################################################################
# Location of sdks directories
sdk.home 	 = /Users/user/Applications/Adobe\ Flex\ Builder\ 3\ Plug-in/sdks
# Location of sdk version
sdk.dir      = ${sdk.home}/3.2.0
# Location of asdoc.exe
asdoc.exe    = ${sdk.dir}/bin/asdoc
# ASDOC information
src.dir      = /Users/user/Documents/workspace/Library
doc.dir		 = /Users/user/Documents/workspace/Library
doc.src		 = ${doc.dir}/src/com/elad/API
output.dir   = ${doc.dir}/asdoc
# Libpath location to be included
libpath		 = ${doc.dir}/libs
# file name and folder
swc.dir		 = /Users/user/Documents/workspace/Library/swc
swcfilename	 = library.swc
FLEX_HOME	 = ${sdk.dir}
# ASDOC title for html pages
main.title   = ASDOC Title
window.title = ASDOC Title
</p>

Next, create the ant task to generate the asdoc and SWC file. Notice that I placed the flexTasks.jar in my local library, but feel free to point to it directly.


<project name="ASDoc build" default="main" >
	<!-- make sure that flexTasks.jar which is located in skd/ant/lib/flexTasks.jar otherwise you'll get an error message -->
	<taskdef resource="flexTasks.tasks" classpath="libs/flexTasks.jar" />
	<!-- defines all values for the ASDoc compiler -->
<property file="asdoc.properties" />
    <!-- main target: cleans and compiles ASDocs -->
    <target name="main" depends="clean-asdoc-directory, create-docs, clean-swc-directory, swc-generator" />
    <!-- deletes and recreates the asdoc directory -->
    <target name="clean-asdoc-directory" >
       <delete dir="${output.dir}" />
       <mkdir  dir="${output.dir}" />
    </target>
    <!-- deletes and recreates the swc directory -->
    <target name="clean-swc-directory" >
       <delete dir="${swc.dir}" />
       <mkdir  dir="${swc.dir}" />
    </target>
    <!-- runs the asdoc.exe compiler on the source -->
    <target name="create-docs" >
        <exec executable="${asdoc.exe}" failonerror="true" >
        	<arg line="-external-library-path='${libpath}/'" />
            <arg line="-doc-sources ${doc.src}" />
            <arg line="-output ${output.dir}" />
        </exec>
    	<echo>ASDOC created successfully</echo>
    </target>
	 <!-- generate the swc -->
	<target name="swc-generator" description="Compile the SWC file">
		<compc output="${swc.dir}/${swcfilename}">
			<include-libraries file="${libpath}/" />
			<!-- include our Class packages into the build (com folder) -->
			<include-sources dir="${doc.dir}/src/com" includes="*" />
		</compc>
		<echo>SWC created successfully</echo>
	</target>
</project>
</p>

4 Responses to “Ant task to generate SWC and ASDOC”


  1. 1 Tim Feb 21st, 2009 at 11:10 pm

    the swc task argument include-sources is pretty limited, it does not allow you to perform any tweaking on the source (in fact, it didn’t exist in Flex 2 at all, I don’t think). I use an ant fileset routine to move through the soruce directory and ignore files by name or regexp, and then create a list of classes for the include-classes task argument. This approach is messier, but ends up being the only option if you have a project that compc chokes on.

  2. 2 Elad Elrom Jul 31st, 2010 at 1:34 pm

    Use optimize and debug false to reduce swc size.

  1. 1 Ant task to generate SWC and ASDOC | Flash Rich Experience Blog — Some Random Dude Pingback on Apr 7th, 2009 at 2:20 pm
  2. 2 Robert Abramski | Before I Knew About Flex Libraries Pingback on May 18th, 2009 at 8:23 pm