Ant uptodate task does not consider deleted files - apache-flex

I'm trying to speed up my builds by using the ANT <updtodate/> task to check for changes and compile only if necessary. This is for a Flex project. Here is the relevant part of my build.xml:
<target name="framework-clean"
description="Clean the Framework library">
<echo>Clean: Deleting dist directory in framework</echo>
<delete dir="${flex.framework.dir}/dist"/>
</target>
<target name="check-framework-changes">
<uptodate property="framework-no-changes" targetfile="${flex.framework.dir}/dist/imanager-framework.swc">
<srcfiles dir="${flex.framework.dir}/src" />
<srcfiles dir="${flex.framework.dir}/libs" />
</uptodate>
</target>
<target name="framework-compile"
depends="check-framework-changes"
unless="framework-no-changes"
description="Compile the Framework library">
<mkdir dir="${flex.framework.dir}/dist"/>
<echo>Compile: Compiling iManager Framework</echo>
<compc output="${flex.framework.dir}/dist/imanager-framework.swc"
debug="${debug}"
incremental="${incremental}">
<keep-as3-metadata name="Master"/>
<keep-as3-metadata name="Component"/>
<keep-as3-metadata name="Key"/>
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${flex.framework.dir}/src" />
<library-path dir="${flex.framework.dir}/libs" includes="*.swc" append="true"/>
<include-sources dir="${flex.framework.dir}/src" includes="*" />
</compc>
</target>
The problem:
Suppose I add a file called Foo.as in my project, the script will detect the change and recompile the swc. But if I delete this Foo.as without changing any other files, the script does not compile the project. The change is ignored even though the last modified timestamp of Foo's parent folder is updated.
Is there any way to fix this?
My ANT version is 1.8.4 and I'm using Flex SDK 4.6

I modified the check-framework-changes target to include directories along with files.
<target name="check-framework-changes">
<uptodate property="framework-no-changes" targetfile="${flex.framework.dir}/dist/imanager-framework.swc">
<srcresources>
<fileset dir="${flex.framework.dir}/src" />
<fileset dir="${flex.framework.dir}/libs" />
<dirset dir="${flex.framework.dir}/src" />
<dirset dir="${flex.framework.dir}/libs" />
</srcresources>
</uptodate>
</target>
This has solved the problem

Related

Flex Ant: Compile multiple module

I am trying to compile my project by using Ant.
I did. But I have some problem. I don't know how to resolve.
<!-- Compile Modules (S) -->
<target name="compileModules" depends="compileBLP">
<record name="${LOG_DIR}/LOG_${CURR_TIME_SUBFIX}${LOG_FILE_TYPE}" append="false" action="start" />
<cpmdl file="com/dou/pi/views/dm/Module1" />
<cpmdl file="com/dou/pi/views/pim/Module2" />
<record name="${LOG_DIR}/LOG_${CURR_TIME_SUBFIX}${LOG_FILE_TYPE}" action="stop" />
</target>
<!-- Compile Modules (E) -->
<macrodef name="cpmdl">
<attribute name="file" />
<sequential>
<echo>#{file}</echo>
<mxmlc file="${SRC_DIR}/#{file}.mxml" output='${DEPLOY_DIR}/#{file}.swf' optimize="true" debug="false" incremental="false" fork="true">
<compiler.source-path path-element="${SRC_DIR}" />
<source-path path-element="${FLEX_HOME}/frameworks" />
<compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
<include name="libs" />
</compiler.library-path>
<compiler.library-path dir="${basedir}" append="true">
<include name="libs" />
<include name="src/assets/swc" />
</compiler.library-path>
<source-path path-element="${SRC_DIR}" />
</mxmlc>
</sequential>
</macrodef>
You can see. If I compile 2 modules, I have to load file config 2 times.
[mxmlc] Loading configuration file C:\Program Files\Adobe\Adobe Flash Builder 4 Plug-in\sdks\4.1.0\frameworks\flex-config.xml
[mxmlc] D:\Projects\BLP\BUILD\DEPLOY\com\dou\pi\views\dm\Module1.swf (1233413 bytes)
[mxmlc] Loading configuration file C:\Program Files\Adobe\Adobe Flash Builder 4 Plug-in\sdks\4.1.0\frameworks\flex-config.xml
[mxmlc] D:\Projects\BLP\BUILD\DEPLOY\com\dou\pi\views\pim\Module2.swf (963045 bytes)
Maybe, that is not good.
I though, can we load it just 1 time?
Hope you can give me any suggestion.
Thanks.
There's really nothing to be done here. The loading of the config file is done internally by mxmlc, not ant. Remember, each time you call mxmlc in your ant script, it's launching a new instance of it, so each instance has to load the configuration for itself.
It's similar to how, if you launch your web browser, close it, and reopen it, you'll end up loading your homepage twice. There's nothing in the environment that can save the page to memory to pass it in to the second invocation of the program.

Applying Web.Config transformations outside of Web Deployment

Is there a way to apply VS 2010 Web.Config transformations outside of web deployment, say during debugging? It would give me a great boost to be able to freely switch between different environments.
Yes, you can perform a Web.config transformation explicitly by invoking the TransformXml MSBuild task during the AfterBuild step in your project file.
Here's an example:
<UsingTask
TaskName="TransformXml"
AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterBuild" Condition="exists('Web.$(Configuration).config')">
<!-- Generates the transformed Web.config in the intermediate directory -->
<TransformXml
Source="Web.config"
Destination="$(IntermediateOutputPath)Web.config"
Transform="Web.$(Configuration).config" />
<!-- Overwrites the original Web.config with the transformed configuration file -->
<Copy
SourceFiles="$(IntermediateOutputPath)Web.config"
DestinationFolder="$(ProjectDir)" />
</Target>
Related resources:
Web.config transformations for App.config files
Can I specify that a package should be created every time I build a solution?
The solution above made a great starting point for me, but I ended up with the following which doesn't need a copy task and doesn't have any issues with file in use errors.
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterBuild">
<TransformXml Condition="exists('$(TempBuildDir)\Web.$(Configuration).config')" Source="$(TempBuildDir)\Web.config" Destination="$(OutputPath)Web.config" Transform="$(TempBuildDir)\Web.$(Configuration).config" />
<ItemGroup>
<DeleteAfterBuild Include="$(OutputPath)Web.*.config" />
</ItemGroup>
<Delete Files="#(DeleteAfterBuild)">
<Output TaskParameter="DeletedFiles" PropertyName="deleted" />
</Delete>
<Message Text="DELETED FILES: $(deleted)" Importance="high" />
</Target>

Run AsUnit runner from Ant

How can you run AsUnit test runner from Ant?
I'm on the Mac OS so I use:
open -a "flash player" tests.swf
How can I make this cross platform?
Here's a target that will compile the tests into a swf and run them. The tests are run using the exec task. This version uses the open command from the Mac OS.
For Windows I can only think of using a property set to the complete path to the Flash player exe and using that to run the tests.
<target name="tests">
<taskdef resource="flexTasks.tasks" classpath="${flextask.jar}" />
<mxmlc file="${test.main}" output="${tests.output}" incremental="true" debug="false" static-link-runtime-shared-libraries="true">
<source-path path-element="${tests.dir}"/>
<load-config filename="${flex.config}" />
<library-path dir="${flex.lib}" append="true">
<include name="flex.swc" />
</library-path>
<library-path dir="${libs.test.dir}" append="true">
<include name="*.swc" />
</library-path>
</mxmlc>
<exec executable="open" os="Mac OS X">
<arg line='-a "flash player" ${tests.output}' />
</exec>
</target>
Here's the properties:
# Build locations
src.dir=${basedir}/src/main/actionscript
package.dir=your/apps/package
libs.dir=${basedir}/libs
output.dir=${basedir}/bin
output.swc=${output.dir}/${project.name.versioned}.swc
# testing
tests.dir=${basedir}/src/test/actionscript
tests.output=${output.dir}/${ant.project.name}-tests.swf
libs.test.dir=${basedir}/src/test/libs
test.main=test.main=${tests.dir}/${package.dir}/AllTestsRunner.as
docs.dir=${basedir}/docs
# flex resources
flex.config=${FLEX_HOME}/frameworks/flex-config.xml
flex.lib=${FLEX_HOME}/frameworks/libs
flextask.jar=${FLEX_HOME}/ant/lib/flexTasks.jar
mxmlc.jar=${FLEX_HOME}/lib/mxmlc.jar
compc.jar=${FLEX_HOME}/lib/compc.jar

Could not load definitions from resource flexTasks.tasks. It could not be found

I'm attempting to compile a Flex application from an ANT script, inside of Eclipse (CFBuilder, based on Eclipse), and I've run into this error:
Could not load definitions from resource flexTasks.tasks. It could not be found.
I haven't been able to find anything that gives directions on where this file (flexTasks.tasks) should be copied to, if it's needed at all. Some places indicate that it should be part of the flexTasks.jar file. I've tried two different things:
Copy the jar file into the ant/plugins/lib folder (and restart my CF Builder instance)
Specify the path to the jar in the classpath attribute, as suggested by the comment on this page
Neither helps me get past this error.
Here's my build script, for reference:
<project name="Tagging" default="compile-tagging" basedir=".">
<!-- setup flex compilation capability -->
<taskdef resource="flexTasks.tasks" />
<property name="flex.src" value="./src" />
<property name="flex.bin" value="./bin"/>
<target name="compile-tagging">
<mxmlc
file="${flex.src}/main.mxml"
output="${flex.bin}/main.swf"
keep-generated-actionscript="true">
<source-path path-element="${FLEX_HOME}/frameworks" />
</mxmlc>
</target>
</project>
Adam, I believe you need to tell taskdef where to look for the file. try keeping flextasks.jar in the same directory as your ant file (for now... you can move it later after you get it working).
then, you can do something like this:
<taskdef name="mxmlc" classname="WhateverTheTaskIsNamed" classpath="flexTAsks.jar" />
While not ideal, this code is working for me at the moment:
<project name="IOLTagging" default="go" basedir=".">
<!-- setup flex compilation capability -->
<property name="FLEX_HOME" value="C:/program files (x86)/Adobe/Adobe Flash Builder Beta 2/sdks/3.4.1/" />
<taskdef name="mxmlc" classname="flex.ant.MxmlcTask" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
<taskdef name="html-wrapper" classname="flex.ant.HtmlWrapperTask" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
<property name="flex.src" value="./src" />
<property name="flex.bin" value="./bin"/>
<property name="swf.name" value="main" />
<target name="go" depends="compile-flex" />
<target name="compile-flex">
<mxmlc
file="${flex.src}/main.mxml"
output="${flex.bin}/${swf.name}.swf"
debug="false"
keep-generated-actionscript="false">
<source-path path-element="${FLEX_HOME}/frameworks" />
<compiler.library-path dir="${basedir}/libs" append="true">
<include name="*.swc" />
</compiler.library-path>
</mxmlc>
</target>
</project>
I had the same problem, and the reason was in lack of permissions to acces $FLEX_HOME/ant.
You can also put the flexTasks.jar in ~/.ant/lib directory
If you run ant -diagnostics you should see the jar in USER_HOME/.ant/lib jar listing
I think you should have solved this problem. just trying flexmonkey today and also got the same problem.
"Could not load definitions from resource flexTasks.tasks. It could not be found."
solution is to make sure the flexTasks.jar is included in the dir lib of your project workplace.
when I copied flexTasks.jar from flashbuild folder \ant\lib and built it again. the problem is fixed.

Using ant, does anyone know how to build a SWF made up of SWCs (that you've built) that include resource bundles?

I'm trying to write an ant build script to build my group's flex app, and I've run into some roadblocks that I'm hoping someone on SO has seen before.
We have two projects that we build into SWCs and these components contain resource bundles. One SWC requires the other SWC. We have one project that we build into our application (the SWF) which uses both SWCs.
When I build the SWCs, I get no complaints about resource bundles not being found, and when I open the SWCs in winzip, I can see the bundles (in /locale/EN_US, for example)
When I build the SWF, however, I get complaints about not being able to find the resource bundles in the two swc's, but no complaints about not being able to find any other resource bundles (like the flex framework ones).
This is the kind of message I get from ant:
[mxmlc] Error: Unable to resolve resource bundle "whatever" for locale "en_US".
[mxmlc]
Surely, I am not the first person to hit this gotcha, so does anyone know what the problem is here?
Am I building the SWCs wrong, or the SWF?
For reference, here's one of my build tasks using compc (for some reason, I can't get the opening target tag to show up)
<path id="facet.sourcePath">
<pathelement location="${flex.facet.src}"/>
</path>
<property name="facet.sourcePath" refid="facet.sourcePath"/>
<echo message="sourcePath is ${facet.sourcePath}"/>
<fileset dir="${facet.sourcePath}" id="facet.sources">
<include name="**/*.as"/>
</fileset>
<pathconvert property="facet.classes" pathsep=" " refid="facet.sources">
<compositemapper>
<chainedmapper>
<globmapper from="*.as" to="*"/>
<globmapper from="${facet.sourcePath}\*" to="*" handledirsep="true" />
</chainedmapper>
<chainedmapper>
<globmapper from="*.mxml" to="*"/>
<globmapper from="${facet.sourcePath}\*" to="*" handledirsep="true" />
</chainedmapper>
</compositemapper>
</pathconvert>
<echo message="classes: ${facet.classes}"/>
<compc output="${flex.lib.output}/${facet.swc.name}" locale="EN_US"
include-classes="${facet.classes}" directory="false"
target-player="10.0.0"
>
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<include-resource-bundles bundle="foo"/>
<include-resource-bundles bundle="bar"/>
<include-resource-bundles bundle="whatever"/>
<sp path-element="${flex.facet.dir}/locale/{locale}"/>
<keep-as3-metadata name="Bindable"/>
<keep-as3-metadata name="Remotable"/>
<keep-as3-metadata name="Embed"/>
<keep-as3-metadata name="Event"/>
<keep-as3-metadata name="ResourceBundle"/>
<source-path path-element="${flex.facet.src}"/>
<compiler.library-path append="true" dir="${flex.framework.lib}">
<include name="*.swc"/>
<include name="../locale/${locale}"/>
</compiler.library-path>
<compiler.library-path append="true" dir="${flex.rsm.lib}">
<include name="*.swc"/>
</compiler.library-path>
</compc>
</target>
and here's my mxmlc task:
<target name="flex.webapp.compile" description="compiles your flex app">
<mxmlc file="${flex.webapp.src}\RSM.mxml"
output="${flex.webapp.deploy}\ant_test\RSM.swf"
use-network="true"
keep-generated-actionscript="true"
debug="true"
locale="en_US"
incremental="true"
actionscript-file-encoding="utf-8"
target-player="10.0.0"
>
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<include-resource-bundles bundle="RSM"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<source-path path-element="${flex.webapp.src}" />
<source-path path-element="${flex.webapp.dir}/locale/en_US" />
<source-path path-element="${flex.rsm.lib}" />
<sp path-element="${flex.core.dir}/locale/{locale}"/>
<sp path-element="${flex.facet.dir}/locale/{locale}" />
<compiler.library-path append="true" dir="${flex.framework.lib}">
<include name="*.swc"/>
<!--include name="../locale/${locale}"/-->
</compiler.library-path>
<compiler.library-path append="true" dir="${flex.rsm.lib}">
<include name="*.swc"/>
<include name="../locale/${locale}" />
<!--include name="rsm_rb.swc" /-->
</compiler.library-path>
</mxmlc>
</target>
Arrgh!
After many hours of staring at this problem, I realized that the issue was looking me in the face the whole time.
The compc task is using 'locale="EN_US"' and the mxmlc task is using 'locale="en_US"'.
If anyone ever posts a "what's the stupidest work problem you've ever had?", this would be my answer.
btw it doesnt have to be that complicated (even in linux console!), all you need is to include libs...
daemonna#NES-KOS-29:~/Desktop/FlexUnit4Turnkey_4.0_sdk_4.0.fxp_FILES/src$ mxmlc -library-path=../libs -locale=en_US App.mxml
Loading configuration file /home/daemonna/Frameworks/flex_sdk_4.1.0.16076/frameworks/flex-config.xml
Error: Unable to resolve resource bundle "components" for locale "en_US".
....bla bla bla...
Error: Unable to resolve resource bundle "controls" for locale "en_US".
daemonna#NES-KOS-29:~/Desktop/FlexUnit4Turnkey_4.0_sdk_4.0.fxp_FILES/src$ mxmlc -library-path=../libs -library-**path=/home/daemonna/Frameworks/flex_sdk_4.1.0.16076/frameworks/locale/en_US/** -locale=en_US App.mxml
Loading configuration file /home/daemonna/Frameworks/flex_sdk_4.1.0.16076/frameworks/flex-config.xml
/home/daemonna/Desktop/FlexUnit4Turnkey_4.0_sdk_4.0.fxp_FILES/src/App.swf (37964 bytes)

Resources