Skip to content

Instantly share code, notes, and snippets.

@davidtucker
Created December 15, 2010 20:32
Show Gist options
  • Save davidtucker/742562 to your computer and use it in GitHub Desktop.
Save davidtucker/742562 to your computer and use it in GitHub Desktop.
Generate a Flex Library manifest XML file via Ant by utilizing Flex metadata.
<!--
==========================================================================
Macro: generateManifestFile
Creates a manifest file for components using the [Manifest( "ComponentName" )]
metadata.
==========================================================================
-->
<macrodef name="generateManifestFile">
<attribute name="outputFile" default="${basedir}/manifest.xml" />
<attribute name="sourceDirectory" default="src" />
<sequential>
<var name="manifest.content" value="${manifest.template.contents}" />
<var name="components" value="" />
<var name="component.xml.declarations" value="" />
<property name="tab" value=" " />
<for param="file">
<path>
<fileset dir="${basedir}/@{sourceDirectory}" casesensitive="no">
<include name="**/*.as" />
<include name="**/*.mxml" />
<contains text="[Manifest" caseSensitive="true" />
</fileset>
</path>
<sequential>
<echo message="File: @{file}" />
<loadfile property="currentFileContents.@{file}" srcFile="@{file}"/>
<propertyregex property="manifest.name.@{file}"
input="${currentFileContents.@{file}}"
regexp='\[Manifest\( *\"(.*)\" *\)\]'
select="\1"
casesensitive="false" />
<echo message="Manifest Name: ${manifest.name.@{file}}" />
<pathconvert property="output.path.@{file}" dirsep="." >
<path>
<pathelement location="@{file}" />
</path>
<map from="${basedir}/@{sourceDirectory}/" to=""/>
</pathconvert>
<propertyregex property="as.path.@{file}"
input="${output.path.@{file}}"
regexp="(.*)(\.as|\.mxml)"
select="\1"
casesensitive="false" />
<var name="components" value="${components},${as.path.@{file}}|${manifest.name.@{file}}" />
</sequential>
</for>
<sortlist property="components.sorted"
value="${components}"
delimiter="," />
<echo message="Sorted List: ${components.sorted}" />
<for list="${components.sorted}" delimiter="," param="component.details">
<sequential>
<propertyregex property="component.line.@{component.details}"
input="@{component.details}"
regexp="(.*)\|(.*)"
replace='&lt;component id\=\"\2\" class\=\"\1\"\/&gt;'
casesensitive="false" />
<var name="component.xml.declarations" value="${component.xml.declarations}${tab}${component.line.@{component.details}}${line.separator}" />
</sequential>
</for>
<echo file="@{outputFile}" append="false" message='&lt;?xml version="1.0"?&gt;${line.separator}&lt;componentPackage&gt;${line.separator}${component.xml.declarations}&lt;/componentPackage&gt;' />
</sequential>
</macrodef>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment