【问题标题】:How can I replicate the functionality of the Flash Builder's release tool in ant?如何在 ant 中复制 Flash Builder 发布工具的功能?
【发布时间】:2010-11-29 05:02:24
【问题描述】:

我想构建一个 ant 脚本,它在 Flash Builder 4 (Gumbo) 项目上执行与 Project->Export Release Build... 菜单项完全相同的编译操作。我的 ant-fu 相当强大,这不是问题,而是我不确定该条目到底在做什么。

一些细节:

  • 我将使用 3.x SDK(为了具体起见,使用 3.2)来构建它。
  • 我将在 Mac 上进行构建,如果您愿意,我可以愉快地使用 ant、make 或一些奇怪的 shell 脚本。
  • 欢迎您提出任何有用的优化建议。
  • 该项目包含一些资产、MXML 和 actionscript 源代码,以及一些内置于项目中的 .swcs(不是 RSL)

谁能提供一个 ant build.xml 或 makefle 用于从类似的 Flex 项目构建发布 .swf 文件?

【问题讨论】:

    标签: apache-flex ant flex3 makefile flexbuilder


    【解决方案1】:

    了解编译器选项的一种快速方法是将此标记添加到您的编译器选项中:

    -dump-config your/drive/to/store/the/xmlfile.xml

    这将输出整个 ant 编译器选项,您可以复制您想要保留的部分。

    【讨论】:

      【解决方案2】:

      HellFire 编译器守护程序 (http://bytecode-workshop.com/) 可以直接从 Flex/Flash Builder 进行的编译器调用生成 build.xml。这意味着您的 ant 脚本会根据您在 Flex/Flash Builder 中设置的完全相同的编译器设置集生成 SWC 和 SWF。

      另外,看看这个博客:

      http://stopcoding.wordpress.com/2010/01/15/ant-tasks-for-hfcd-now-available-2/

      【讨论】:

        【解决方案3】:

        不久前,我在 Adob​​e Flex Ant 任务中遇到了一些问题,因此我最终使用了对 mxmlc 编译器的 exec 调用,其中包含大量选项,我们只是从那里开始构建它。有一些挥之不去的疑问,我对 build.xml 所做的与 FB3(我们所拥有的)所做的并不完全相同,但这可能足以帮助您入门……您说您的 ant-fu 是合理的强大,所以我会跳过我的大部分构建文件,让你拼凑起来。

        <!--flex stuff-->
        <property name="dir.flex.sdk"                 value="${system.build.flex.sdk}"/>
        <property name="dir.flex.home"                value="${dir.abc}/flex/sdks/${dir.flex.sdk}"/>
        <property name="dir.flex.projects"            value="${dir.abcd_plat}/webapp/flexprojects/"/>
        <property name="dir.modules"                  value="${dir.war}/modules/"/>
        <property name="FLEX_HOME"                    value="${dir.flex.home}"/>
        <property name="APP_ROOT"                     value="${dir.war}"/>
        <property name="flexc.exe"                    value="This should be set in the build-${os.family}.xml file"/>
        <property name="asdoc.exe"                    value="This should be set in the build-${os.family}.xml file"/>
        <property name="optimizer.exe"                value="This should be set in the build-${os.family}.xml file"/>
        <property name="flex.mxmlc"                   value="${dir.flex.home}/bin/${flexc.exe}"/>
        <property name="flex.compc"                   value="${dir.flex.home}/bin/${compc.exe}"/>
        <property name="flex.asdoc"                   value="${dir.flex.home}/bin/${asdoc.exe}"/>
        <property name="flex.optimizer"               value="${dir.flex.home}/bin/${optimizer.exe}"/>
        <property name="flex.options.warnings"        value="false"/>
        <!--options that are used in common for compiling all .swc and .swf files-->
        <property name="flex.meta.1"                  value="-creator 'MyCorp.' -publisher 'MyCorp.'"/>
        <property name="flex.meta.2"                  value="-title MegaProduct -description http://ourURL.com"/>
        <property name="flex.meta.props"              value="${flex.meta.1} ${flex.meta.2}"/>
        <property name="debug.options"                value="-optimize=true -debug=false"/>
        <property name="common.flex"                  value="-as3 -target-player=9.0.124 -warnings=${flex.options.warnings}"/>
        <property name="license.flex3"                value="(put your own here)"/>
        <property name="common.fixed"                 value="-license=flexbuilder3,${license.flex3} -sp ${dir.war} -library-path+=${dir.webinf}/lib"/>
        <property name="flex.common.args"             value="${flex.meta.props} ${debug.options} ${common.flex} ${common.fixed}"/>
        <!--this is currently unused, but if we make a debug version, this can be set to make a separate output file-->
        <property name="swf.suffix"                   value=""/>
        
        <!--=================================================================================
            MACRODEFs
        -->
        <!--this is used to extract .swf files from 3rd party .swc libraries, in order to do dynamic linking-->
        <macrodef name="extract-flex-lib" description="For modularizing flex compilation">
            <attribute name="swc-lib" default="NOT SET"/>
        
            <sequential>
                <!--use a copy task - it can get the file out of the zip, and rename it at the same time-->
                <copy todir="${dir.war}" preservelastmodified="true">
                    <zipfileset src="${dir.webinf}/lib/@{swc-lib}.swc">
                        <patternset>
                            <include name="library.swf"/>
                        </patternset>
                    </zipfileset>
                    <mapper type="glob" from="library.swf" to="@{swc-lib}-debug.swf"/>
                </copy>
                <!--run the flex optimizer on the extracted .swf - note the as3 metadata that's kept, it's required-->
                <exec executable="${flex.optimizer}" failonerror="true">
                    <arg line="-keep-as3-metadata='Bindable,Managed,ChangeEvent,NonCommittingChangeEvent,Transient'"/>
                    <arg line="-input @{swc-lib}-debug.swf -output @{swc-lib}.swf"/>
                </exec>
                <!--delete the unoptimzed swf, don't need it anymore-->
                <delete file="@{swc-lib}-debug.swf"/>
            </sequential>
        </macrodef>
        
        <!--this is used to compile our internal flex modules-->
        <macrodef name="flexc-mxml" description="For building the flex modules during flex compilation">
            <attribute name="name"        default=""/>
            <attribute name="mxml.args"   default="${flex.common.args} ${module.args}"/>
            <attribute name="sourcePath"  default=""/>
            <attribute name="destPath"    default=""/>
        
            <sequential>
                <echo message="  Compiling with mxmlc: @{name}"/>
                <exec executable="${flex.mxmlc}" failonerror="true">
                    <arg line="@{mxml.args} @{sourcePath} -output @{destPath}"/>
                </exec>
            </sequential>
        </macrodef>
        
        <!--this is used to compile our subprojects under abcd_plat/webapp/flexprojects-->
        <macrodef name="flexc-subproject" description="For compiling the flex subprojects into .swc files">
            <attribute name="name"        default=""/>
            <attribute name="xtra.args"   default=""/>
        
            <sequential>
                <echo/>
                <echo message=" Compiling subproject: @{name}"/>
                <xslt in="${dir.flex.projects}/@{name}/.flexLibProperties" out="${dir.flex.projects}/@{name}/src/manifest.xml" style="${dir.war}/build-manifest-style.xsl"/>
                <exec executable="${flex.compc}" failonerror="true">
                    <arg line="-load-config+=${dir.flex.projects}/@{name}/include-files.xml"/>
                    <arg line="-namespace http://@{name}.ourURL.com ${dir.flex.projects}/@{name}/src/manifest.xml"/>
                    <arg line="-include-namespaces http://@{name}.ourURL.com @{xtra.args}"/>
                    <arg line="-library-path+=${dir.webinf}/lib -sp ${dir.flex.projects}/@{name}/src -output ${dir.webinf}/lib/@{name}.swc"/>
                </exec>
            </sequential>
        </macrodef>
        
        
        <!--=================================================================================
            This is where all the compilation is done.  The actual work is split among
            several different tasks in order to organize them better.
        
            This target uses the html-wrapper task defined in flexTasks.jar - see taskdef above.
        -->
        <target name="flexcompile" depends="flexc-modularize" description="Builds the Flex sources" unless="flexc.notRequired.main">
            <echo message="Compiling MegaProduct Flex application on OS family: ${os.family}"/>
            <echo message="   mxmlc is: ${flex.mxmlc}"/>
            <echo message="   compc is: ${flex.compc}"/>
        
            <!--compile flex sub-projects first (main application depends on these extra libraries)-->
            <antcall target="flexc-projects"/>
        
            <!--compile the main MegaProduct application-->
            <antcall target="flexc-main"/>
        
            <!--compile the foobar stuff, which link against the main app.  these foorbars are modules
             inside a subproject, so they are handled differently from other flex projects and modules-->
            <antcall target="flexc-foorbars"/>
        
            <!--generate the html wrapper for the .swf-->
            <html-wrapper title="MyCorp MegaProduct" application="app_name" swf="app_name" history="false" template="express-installation"/>
        </target>
        
        <target name="flexc-projects">
            <!--the name must match the name of the folder exactly, also they are not in parallel as some depend on others-->
            <flexc-subproject name="Dockable"/>
            <flexc-subproject name="EXRibbon" xtra.args="-source-path+=${dir.flex.projects}/EXRibbon/locale/en_US/"/>
            <!--note: MPLib does some extra stuff with the image dir in order to link against images correctly-->
            <copy todir="${dir.flex.projects}/MPLib/src/image"><fileset dir="${dir.war}/image"/></copy>
            <flexc-subproject name="MPLib"/>
            <delete dir="${dir.flex.projects}/MPLib/src/image"/>
        </target>
        
        <target name="flexc-main">
            <!--the link report is used to create the symbols in the main swf, and modules link against it-->
            <property name="link.report"   value="${dir.war}/abc_link_report.xml"/>
        
            <!--modular.args is set in flexc-modularize.  If not set, this sets it to an empty property-->
            <property name="modular.args"  value=""/>
        
            <!--set up options specific for the main part and for the modules-->
            <property name="main.args"     value="-link-report=${link.report} ${modular.args}"/>
            <property name="module.args"   value="-load-externs=${link.report}"/>
        
            <!--compile abc_flex.mxml here-->
            <echo message="Compiling abc_flex application, sub-applications and modules..."/>
            <echo/>
            <flexc-mxml name="abc_flex" mxml.args="${flex.common.args} ${main.args}"
                    sourcePath="${dir.war}/abc_flex.mxml" destPath="${dir.war}/abc_flex${swf.suffix}.swf"/>
        
            <!--compile MPMainSubApplication.mxml sub-application here-->
            <flexc-mxml name="MPMainSubApplication" mxml.args="${flex.common.args} ${main.args}"
                    sourcePath="${dir.war}/MPMainSubApplication.mxml" destPath="${dir.war}/MPMainSubApplication.swf"/>
        
            <!--compile internal modules next - just add new modules to the list here -->
            <parallel>   <!--do in parallel - it goes faster and they don't depend on each other-->
                <property name="dir.module.src" value="${dir.war}/module/"/>
                <flexc-mxml name="module1"      sourcePath="${dir.module.src}/editor/Editor.mxml"          destPath="${dir.module.src}/editor/Editor.swf"          />
                <flexc-mxml name="RunModule"   sourcePath="${dir.module.src}/run/RunModule.mxml"          destPath="${dir.module.src}/run/RunModule.swf"          />
                <!--<flexc-mxml name="JobManager"  sourcePath="${dir.module.src}/jobmanager/JobManager.mxml"  destPath="${dir.module.src}/jobmanager/JobManager.swf"  />-->
                <flexc-mxml name="Editor2"        sourcePath="${dir.module.src}/edit/Editor.mxml"                destPath="${dir.module.src}/edit/Editor.swf"                />
            </parallel>
        </target>
        

        注意事项:

        我不确定这是否是个好主意,但我们只是将 .swc 文件与我们的 Java 中间层库一起包含在 WEB-INF/lib 中,所以每当我们将新的 flex 库添加到源代码控制时我们只是把它放在那里。编译在宏中完成,大部分参数在顶部定义为属性。目标拆分工作,因为我们的应用程序很大;您可能不需要这些,但它是在子项目加上链接报告中执行模块的示例,并遵循从主应用程序引用子项目的方式(我认为)。我们的构建机器是 linux,所以这就是 flexc.exe 属性(和其他属性)以这种方式定义的原因 - 它在运行时设置。此答案的名称是手工修改的,所以如果您剪切粘贴任何内容,请仔细检查是否有错别字。

        另外,增量编译并没有实际使用;它似乎是错误的。模块化的东西也一样,所以我没有包括那个目标。

        所有这些都是我自己建造的,所以我对此感到相当自豪,但如果有任何看起来有问题或闻起来很糟糕的东西,请随时告诉我。谢谢!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-15
          • 2012-11-24
          • 2017-01-11
          • 1970-01-01
          • 2011-05-15
          相关资源
          最近更新 更多