How to use custom tokens with flex ant tasks - apache-flex

I am trying to use the flex ant task to build my Flex project.
Before using ant, I ran the mxmlc command like this:
mxmlc -load-config mxmlc_conf.xml src\project.mxml -output bin-debug +libs=<absolute_path_to>3rdparty\libs +<other_token>=<absoulte_path_to_value>
The thing is now I am supposed to use flex ant tasks and it looks like they disabled (or forgot about) the custom tokens like += as I haven't found a way to pass those to the mxmlc task.
I have tried using:
< mxmlc ...>< arg token value="..." />< /mxmlc>
but that doesn't work.
What I am trying to accomplish is to get rid of hard-coded paths in the mxmlc config-file (mxmlc_conf.xml) and at first I used the custom tokens in mxmlc but now I don't know how to pass paths as variables to the config file.
I can accept suggestions.
Thanks a lot in advance.

I'm trying to do the exact same thing (replace hard-coded paths in the config file) and I'm looking for the same solution.
It seems we might have to abandon the mxmlc task and simply use mxmlc from the command line:
<exec searchpath="true" executable="amxmlc"
dir="${project.build.outputDirectory}">
<env key="PATH"
path="${env.PATH}:/Applications/Adobe\ Flash\ Builder\ 4.5/sdks/4.5.1/bin" />
<arg value="-load-config" />
<arg value="../src/main/resources/dumpConfig.xml" />
<arg value="+libs=/absolute/path/to/3rd/party/libs" />
<arg value="-output" />
<arg
value="${project.build.outputDirectory}/${application.name}.swf" />
<arg value="../src/main/flex/${application.name}.mxml" />
</exec>
Something like this should work. I'm just hoping there's a better way (that is, a way we can actually use the mxml ant target!)
I hope that helps someone...

Try this
<target>
<replace file="mxmlc_conf.xml" token="$${libs}" value="absolute/path/to/3rdparty/libs"/>
<mxmlc ...>
<load-config filename="mxmlc_conf.xml" />
</mxmlc>
<replace file="mxmlc_conf.xml" token="absolute/path/to/3rdparty/libs" value="$${libs}"/>
</target>

Related

specify ouput file name flash builder 4

This should be easy, but I can't find it. I want my .html and .swf files to be named something differently than the project name. Project name is foo, I want the outputs to be bar.html and bar.swf. Thanks.
Flextras was on the right track. You can't change the output filename (even using the "-output" compiler param) if you're compiling in Flash Builder. Not sure why.
The solution that has worked for me has been to use a bit of indirection:
use mxmlc to compile to ApplicationClass.swf
command line copy ApplicationClass.swf to YourCustomSwf.swf
command line run YourCustomSwf.swf
You can do this with either a simple (platform-dependent) build script, or with Flex Ant Tasks. I highly recommend the latter; it's easy to setup, integrates well with Flash Builder, and (as a mostly platform-independent solution) will work in a multi-team multi-OS environment. Here are the above steps as ant tasks that will perform the magic for you:
<project name="sample-build" default="run-your-swf">
<property file="${basedir}/your.properties.file"/>
<target name="compile-your-app">
<mxmlc file="${SOURCE_DIR}/ApplicationFile.mxml" compiler.debug="${IS_DEBUG}" incremental="true" failonerror="true">
<load-config filename="${DEFAULT_FLEX_CONFIG}"/>
<define name="CONFIG::DEBUG" value="${IS_DEBUG}"/>
<define name="CONFIG::FLASH_AUTHORING" value="${IS_FLASH_AUTHORING}"/>
<define name="CONFIG::IS_RELEASE" value="${IS_RELEASE}"/>
</mxmlc>
</target>
<target name="rename-your-swf" depends="compile-your-app">
<copy file="${OUTPUT_DIR}/feed/FeedComponent.swf" tofile="${OUTPUT_DIR}/YourNewSexyFilename.swf"/>
</target>
<target name="run-your-swf" depends="rename-your-swf">
<exec executable="${STANDALONE_FLASH_DEBUG_PLAYER}">
<arg line="${OUTPUT_DIR}/YourNewSexyFilename.swf"/>
</exec>
</target>
</project>
you need only define all ${VARIABLES} I've listed in "your.properties.file", like so:
FLASH_PLAYER_DEBUG=/Applications/Adobe Flash CS5/Players/Debug/Flash Player Debugger.app/Contents/MacOS/Flash Player Debugger
IS_DEBUG=true
(et cetera)
And anyway - what's in a name? A program by any other name, would be as awesome... B-)

ASP.NET Web Application (MVC) Deployment Automation and Subversion

We are trying to automate the build process to our staging servers but have run into a snag, albeit fairly minor. We are using the Publish functionality built into VS2010, committing to Subversion, and then a 3rd party app (Beanstalk) automatically pulls the updated files and FTPs them to the Staging server.
The problem we've run into is that we only appear to have the following choices:
(Lesser of 2 evils) If we choose to use "Replace matching files with local copies", this works great, with one exception: this option does not delete any files that were deleted from the project. This will lead to junk and/or security issues for unkempt files from the days of old.
If we choose to use "Delete all existing files prior to publish", this deletes the entire folder structure, including the .SVN hidden folders that Subversion uses for Update tracking, etc. This seems like the best solution from an accuracy standpoint, but it really destroys the local SVN environment, which is the middle-man for this automation.
My question: Is there an easy work around for this, or a totally different deployment option we're overlooking (we do not want to publish directly to the server from VS, as we want to track who/what/when a deployment takes place)? The only thing I've come across is to delete the file contents manually prior to publishing, while leaving the folder structure intact, then deploying with "Replace matching files with local copies". Unfortunately, this brings on a whole new meaning of the word "automation".
Any ideas on how best to accomplish this?
You may want to consider using NAnt or something similar for tasks you wish to automate, like building and publishing to Subversion. This is most of my build file for a WebApplication Project. It might be different for MVC. If so, I'm sure you can use this as a starting point. I am by no means an NAnt expert so there may be some flaws, but this is definitely working for me.
I had to add a PublishToFileSystem target to each .csproj file I wanted to publish. The source for that can be found here.
Build file also available on Pastebin
<?xml version="1.0"?>
<project name="deploy" default="all">
<property name="nant.settings.currentframework" value="net-4.0" />
<!-- Any of these can be passed through the command line -->
<property name="sourceDirectory" value="${project::get-base-directory()}" />
<property name="publishDirectory" value="${sourceDirectory}\build" />
<property name="MSBuildPath" value="${framework::get-assembly-directory(framework::get-target-framework())}\msbuild.exe" />
<!-- The build configuration to use when publishing and transforming the web.config file. This is useful when you have multiple environments for which you create builds -->
<property name="buildConfiguration" value="Release" />
<!-- Set these as needed -->
<property name="svn.username" value="" />
<property name="svn.password" value="" />
<target name="SvnPrep">
<property name="svn.dir" value="${publishDirectory}\.svn" />
<property name="svn.update" value="true" readonly="false" />
<echo>env.svn.path = svn</echo>
<echo>svn.dir = ${svn.dir}</echo>
<mkdir dir="${publishDirectory}" unless="${directory::exists(publishDirectory)}" />
<!-- Check if there's a .svn dir already. If not: checkout, else: update. -->
<if test="${not directory::exists(svn.dir)}">
<exec program='svn.exe' workingdir="${publishDirectory}" verbose="true">
<arg line='co ${svn.builduri} --username ${svn.username} --password ${svn.password} --non-interactive ./' />
</exec>
<property name="svn.update" value="false" readonly="false" />
</if>
<if test="${svn.update}">
<exec program='svn.exe' workingdir="${publishDirectory}\" verbose="true">
<arg line='up --username ${svn.username} --password ${svn.password} --non-interactive --force ./' />
</exec>
</if>
<!-- Force any conflicts to be resolved with the most recent code -->
<exec program='svn.exe' workingdir="${publishDirectory}\" verbose="true">
<arg line='resolve --accept theirs-full -R ./' />
</exec>
</target>
<target name="DeleteFiles">
<!-- Delete only the files (retain directory structure) in the directory to which you are going to publish/build. NAnt excludes svn directories by default. -->
<delete includeemptydirs="false">
<fileset basedir="${publishDirectory}">
<include name="**/*.*" />
</fileset>
</delete>
</target>
<target name="Publish">
<!-- I know there's an MSBuild task, I don't know why I didn't use it, but this works. -->
<!-- Build and publish frontend -->
<exec program="${MSBuildPath}">
<arg line='"${sourceDirectory}\YourProject.csproj"' />
<arg value='"/p:Platform=AnyCPU;Configuration=${buildConfiguration};PublishDestination=${publishDirectory}"' />
<arg value="/target:PublishToFileSystem" />
</exec>
<!-- Transform the correct web.config and copy it to the build folder. PublishToFileSystem doesn't transform the web.config, unfortunately. -->
<exec program="${MSBuildPath}">
<arg line='"${sourceDirectory}\YourProject.csproj"' />
<arg value='"/p:Platform=AnyCPU;Configuration=${buildConfiguration};PublishDestination=${publishDirectory}"' />
<arg value="/target:TransformWebConfig" />
</exec>
<copy file="${sourceDirectory}\YourProject\obj\${buildConfiguration}\TransformWebConfig\transformed\Web.config" tofile="${publishDirectory}\YourProject\web.config" overwrite="true" />
</target>
<target name="SvnCommit">
<!-- add any new files -->
<exec program='svn.exe' workingdir="${publishDirectory}" verbose="true">
<arg line='add --force .' />
</exec>
<!-- delete any missing files, a modification of this http://stackoverflow.com/questions/1071857/how-do-i-svn-add-all-unversioned-files-to-svn -->
<!-- When there's nothing to delete it looks like this fails (to NAnt) but it is actually fine, that's why failonerror is false -->
<exec program='cmd.exe' workingdir="${publishDirectory}\" verbose="true" failonerror="false"
commandline='/C for /f "usebackq tokens=2*" %i in (`svn status ^| findstr /r "^\!"`) do svn del "%i %j"' >
</exec>
<exec program='svn.exe' workingdir="${publishDirectory}" verbose="true">
<arg line='commit -m "Automated commit from build runner"' />
</exec>
</target>
<target name="ShowProperties">
<script language="C#" prefix="util" >
<code>
<![CDATA[
public static void ScriptMain(Project project)
{
foreach (DictionaryEntry entry in project.Properties)
{
Console.WriteLine("{0}={1}", entry.Key, entry.Value);
}
}
]]>
</code>
</script>
</target>
<target name="all">
<call target="ShowProperties" />
<call target="SvnPrep" />
<call target="DeleteFiles" />
<call target="Publish" />
<call target="SvnCommit" />
</target>
</project>
We also deploy out of SVN and ran into the same problem. Our solution is to essentially branch the project for "significant" upgrades -- situations where we were adding and deleting files, not just fixing small bugs and making tweaks which you can usually handle by xcopy. Svn layout looks like:
--project
---production
----20100101
----20100213
[etc, etc]
Procedure-wise, it is pretty simple -- if there are big enough changes, check in build artifacts as appropriate.
Another thing you might want to try, especially if you cannot get your production bits to "switch" branches easily, would be to use something fancier such as powershell to execute the delete files command, that could filter out the *.svn folders.
I would say "fortunately" this brings a whole new meaning to the word automation :) What you're describing is knows as Application Release Automation, also sometimes called Deployment Automation. If you really want to know who did what and where, what was the outcome, etc. then you are looking for a product like Nolio ASAP (http://www.noliosoft.com). Please let me know if this helps, since from what you're describing, it seems like a perfect match.
+Daniel
Why are you publishing the site to a folder that is handled by Subversion?
The way I would do it is work directly with the files in the SVN handled folders. As soon as I commit anything, it gets pulled by beanstalk to the staging area. This way, files deleted are always deleted from the repo and you don't have to worry about that. Everything is always in sync.
If you feel that this is putting too many files to the staging area, you can still use scripts and Visual Studio commands to publish the site. But I'm not sure how well Beanstalk integrates with this scenario. I know CC.net and many other alternatives do.

Using the ASP Compiler in NAnt to build an ASP .Net MVC application

I am succesfully building ASP .Net applications in NAnt using the ASP Compiler, without a problem., as part of my Continuous Integration process.
However, if I try exactly the same process on an ASP .NET MVC application, the build fails in NAnt, but will compile succesfully in Visual Studio. The error message I get in NAnt is:
[HttpParseException]: Could not load type 'MyNamespace.Views.Home.Index'
which appears that it has a problem with the dots in the filenames, but I might be wrong.
Any suggestions are most welcome.
You shouldn't install ASP.NET MVC onto the build box. You should be referencing the System.Web.MVC, System.Web.Routing and System.Web.Abstractions DLLs from wherever you store your third-party references. We normally have a /lib folder for all references where we have those 3 DLLs (and many more) stored and a /src folder where all of our code lives. If you are referencing these DLLs this way, you no longer have to rely on the environment for those DLLs. This blog post explains this idea in more detail.
Installing the MVC bits on the build box should sort this out--it is either lacking the .dlls to know your Home.Index view descends from System.Web.Mvc.ViewPage or it doesn't have the right project template for the compiler to use.
The MVC app needs to be built as a project before using aspnet_compile. If your MVC project uses other class library projects, they also need to be compiled.
After running aspnet_compile, we then want to delete various files that should not be part of the deployed site.
This build file is located in the parent directory to my project MvcApplication.
<project default="build">
<property name="build.dir" value="${project::get-base-directory()}"/>
<property name="build.config" value="Release" />
<target name="build">
<exec program="${framework::get-framework-directory('net-3.5')}/msbuild.exe">
<arg value="/property:Configuration=${build.config}" />
<arg value="${build.dir}/MvcApplication/MvcApplication.csproj" />
</exec>
<delete dir="${build.dir}/PrecompiledWeb" includeemptydirs="true" failonerror="false"/>
<exec program="${framework::get-framework-directory('net-2.0')}/aspnet_compiler.exe">
<arg value="-v" />
<arg value="/" />
<arg value="-p" />
<arg value="MvcApplication/" />
<arg value="-f" />
<arg value="PrecompiledWeb" />
</exec>
<delete verbose="true" includeemptydirs="true" failonerror="false">
<fileset basedir="${build.dir}/PrecompiledWeb">
<include name="Controllers" />
<include name="Properties" />
<include name="obj/**" />
<include name="obj" />
<include name="*.csproj" />
<include name="*.csproj.user" />
</fileset>
</delete>
</target>
</project>
Not exactly an answer to your question but more a different tack that might solve what you wish to achieve.
I find studio to be more friendly that the asp compiler from the command line.
Could you not build it with devenv.exe through a NAnt command line task.
Best of luck,
Dan
On a project I was working on recently we build the ASP.NET MVC web app using this target:
<target name="CompileSite" depends="blah blah">
<exec program="${framework::get-framework-directory('net-2.0')}\aspnet_compiler.exe" commandline="-p "${SrcDir}\Website" -v / -d "${CompiledSiteOutputDir}" -fixednames" workingdir="${BaseDir}" />
</target>
so it is definitely possible. Our views were named something like ProjectName.Views.News.List etc.
Could you provide more details? Does the compiler say where it encounters the error (file, linenumber etc.)?
My best guess is that the ASP.Net mvc dll's are not installed on the build server. ASP.Net MVC is a separate download.

How to include additional compiler arguments when using mxmlc ant task?

Flex Builder allows additional compiler arguments to be set in the compiler options, under properties. It sets the argument;
-services ".../services-config.xml"
Is there a way to set the same argument when using the ant task mxmlc?
Cheers,
Mike
You should be able to set it as an attribute on the mxmlc task:
<mxmlc services="../services-config.xml"/>
Not that I know of.
You could always use the task with subnodes if you still are unable to find it in the docs.
Example:
<exec executable="${mxmlc.exe}" dir="${basedir}">
<arg line="-source-path '${flex2sdk.locale.dir}'" />
<arg line="-locale en_US" />
</exec>
I was having the same issues with the services attribute not being available for use in the ant tasks so I added the option to fix the problem:
<mxmlc file="path" output="path to output" >
<compiler.services>${path-to-services}</compiler.services>
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<compiler.debug>false</compiler.debug>
<compiler.context-root>/PATWeb</compiler.context-root>
</mxmlc>
This is accomplished by the following:
<target name="compileApp">
<mxmlc file="src/app.mxml"
...other options
services="[path to your services-config.xml]"
context-root="[path to where your gateway file is]">
...
</target>
This is how we are currently building the mxml app... which means Christophe was correct.
Most of the compiler options are available as either attributes or tags for the mxmlc task, however some options are missing, or work in somewhat unexpected way. Worst thing is lack of proper documentation for the flex Ant tasks.
Sometimes I find it easier to do this:
<mxmlc file="Main.as" output="bin/app.swf">
<load-config filename="${FLEX_HOME}/flex-config.xml" />
<load-config filename="build/config.xml" />
</mxmlc>
And then specify all the options I want in build/config.xml, at least the syntax is documented better, and you can always use flex-config.xml or air-config.xml from your SDK as a (well-commented) sample.

Custom Flex Ant build task

A beginner's question.
I'm building a .swf with Flex Ant.
To my .swf I link a file, target.as, which I generate from file source.txt with command
./tool.sh source.txt > target.as
How can I add what is described in the above sentence to my ant build process?
The exec task executes any external program:
<exec executable="${basedir}/tool.sh" dir="${basedir}" output="target.as">
<arg path="source.txt"/>
</exec>
So if you use the mxmlc ant task to compile your swf, you can define your build task like this:
<target name="build">
<exec executable="${basedir}/tool.sh" dir="${basedir}" output="target.as">
<arg path="source.txt"/>
</exec>
<mxmlc ....>
...
</mxmlc>
</target>
To run that command in Ant use the exec task.
<exec executable="tool.sh" dir="toolshdir" output="target.as">
<arg value="source.txt" />
</exec>
http://livedocs.adobe.com/flex/3/html/anttasks_1.html
You may also want to use the Flex "mxmlc" task instead of calling it with exec. You can do a lot of configuration right within the XML if you'd prefer not to have to maintain the shell script.

Resources