flex ant file sample

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
 
<project basedir="." name="Flex Ant Builder SSO Project"> 
 
        <!– 定义ant存放位置  –>
        <property name="ant.lib.dir" value="E:\FlexSDK\3.2.0/ant/lib"></property>
        <!– 定义Flex SDK存放位置  –>
        <property name="FLEX_HOME" value="E:\FlexSDK\3.2.0"></property>
 
        <!– 初始化时间格式,以便使用 –>
        <tstamp>
                <format pattern="yy.mm.dd" property="TODAY" />
        </tstamp>
 
        <!– 导入ant支持包 –>
        <path id="ant.classpath">
                <fileset dir="${ant.lib.dir}">
                        <include name="*.jar" />
                </fileset>
        </path>
 
        <!– 定义目标编译结果路径 –>
        <property name="dist.home" value="./dist"></property>
        <property name="dist.home.src" value="./dist/src"></property>
        <property name="dist.home.libs" value="./dist/libs"></property>
        <property name="dist.home.bin" value="./dist/bin"></property>
 
        <!– 定义源码路径  –>
        <property name="project.home" value="./"></property>
        <property name="project.home.src" value="./src"></property>
        <property name="project.home.libs" value="./libs"></property>
 
<!–=========================================== –>
<!– 初始化                                                                         –>
<!–     清除dist目录; 将源码复制过去.                                                                          –>
<!– ============================================ –>
        <target name="init">
                <taskdef classpathref="ant.classpath" resource="flexTasks.tasks" />
                <taskdef classpathref="ant.classpath" resource="confusion.tasks" />
                <taskdef classpathref="ant.classpath" resource="net/sf/antcontrib/antlib.xml" />
 
                <echo message="Flex SDK Home: ${FLEX_HOME}" />
                <delete dir="${dist.home}" />
                <mkdir dir="${dist.home}" />
                <copy todir="${dist.home.src}">
                        <fileset dir="${project.home.src}" />
                </copy>
 
                <copy todir="${dist.home.libs}">
                        <fileset dir="${project.home.libs}" />
                </copy>
        </target>
 
<!– ================================= –>
<!– 混淆代码                                                                     –>
<!– ======================================== –>
        <target name="confusion" depends="init">
                <echo message="star confusion code…" />
                <for param="file">
                        <path>
                                <fileset dir="${dist.home.src}">
                                        <include name="**/*.as" />
                                </fileset>
                        </path>
                        <sequential>
                                <confusion filename="@{file}" />
                                <echo message="@{file} is confusioned!!" />
                        </sequential>
                </for>
        </target>
 
<!– ========================================== –>
<!– 编译Flex Library Project项目                                                                                  –>
<!– ===================================== –>
        <target name="compileFLP" depends="confusion">
                <property name="project.name" value="Comman"></property>
                <echo message="star complie Flex Library Project…" />
                <echo message="build ${dist.home.bin}/${project.name}.swc" />
 
                <compc incremental="true" debug="false" output="${dist.home.bin}/${project.name}.swc">
                        <!– 指定Comman项目的源码目录 –>
                        <source-path path-element="${dist.home.src}" />
                        <!– 指定编译的文件列表 –>
                        <include-sources dir="${dist.home.src}">
                                <include name="**/*.as" />
                        </include-sources>
                        <!– 将Flex SDK 作为外部库进行引用 –>
                        <compiler.external-library-path dir="${FLEX_HOME}/frameworks">
                                <include name="**/*.swc" />
                        </compiler.external-library-path>
                        <!– 添加项目中的SWC包,请注意这里是外部 –>
                        <compiler.external-library-path dir="${dist.home.libs}">
                                <include name="**/*.swc" />
                        </compiler.external-library-path>
                </compc>
                <!– 删除缓存文件 –>
                <delete>
                        <fileset dir="${dist.home.bin}" includes="*.cache" />
                </delete>
                <echo message="complier Flex Library Project finished!" />
        </target>
 
<!– =============================== –>
<!– 优化SWC文件                                                                     –>
<!– =========================== –>
        <target name="optimizeSWC" depends="compileFLP">
                <echo message="star optimize SWC…" />
 
                <!– 定义一个优化操作模块 –>
                <macrodef name="optimize-rsl">
                        <attribute name="rsl-dir" />
                        <attribute name="swc-path" />
                        <sequential>
                                <propertyregex property="swc-name" select="\1" regexp="bin\\(.*).swc" input="@{swc-path}" override="yes" />
                                <propertyregex property="swc-dir" select="\1" regexp="(.*)\\(.*).swc" input="@{swc-path}" override="yes" />
 
                                <!– 从SWC中解压出SWF文件 –>
                                <unzip dest="@{rsl-dir}" src="${swc-dir}/${swc-name}.swc">
                                        <patternset>
                                                <include name="library.swf" />
                                        </patternset>
                                </unzip>
                                <!– 优化SWF文件 –>
                                <java failonerror="true" fork="true" jar="${FLEX_HOME}\lib\optimizer.jar">
                                        <jvmarg line="-ea -DAS3 -DAVMPLUS -Dflexlib=${FLEX_HOME}\frameworks -Xms32m -Xmx384m -Dsun.io.useCanonCaches=false" />
                                        <arg line="’@{rsl-dir}/library.swf’ –output ‘@{rsl-dir}/${swc-name}.swf’&#13;&#10;                        –keep-as3-metadata=’Bindable,Managed,ChangeEvent,NonCommittingChangeEvent,Transient,RemoteClass’ " />
                                </java>
                                <!– 重建描述文件 –>
                                <java failonerror="true" fork="true" jar="${FLEX_HOME}/lib/digest.jar">
                                        <jvmarg line="-ea -DAS3 -DAVMPLUS -Xms32m -Xmx384m -Dsun.io.useCanonCaches=false" />
                                        <arg line="–digest.rsl-file  @{rsl-dir}/${swc-name}.swf –digest.swc-path  @{rsl-dir}/${swc-name}.swc" />
                                </java>
                                <!– 清除解压出来的文件 –>
                                <delete>
                                        <fileset dir="@{rsl-dir}" includes="*.swf" />
                                </delete>
                        </sequential>
                </macrodef>
 
                <!– 优化所有SWC文件 –>
                <for param="file">
                        <path>
                                <fileset dir="${dist.home.bin}">
                                        <include name="*.swc" />
                                </fileset>
                        </path>
                        <sequential>
                                <!– 优化SWC –>
                                <optimize-rsl swc-path="@{file}" rsl-dir="${dist.home.bin}" />
                                <echo message="optimize @{file} success~!" />
                        </sequential>
                </for>
        </target>
 
<!– =========================================== –>
<!– 编译  Flex Action Script Project 项目                                                                  –>
<!– ============================================= –>
        <target name="compileASP" depends="confusion">
                <property name="compile.name" value="AntASP"></property>
                <echo message="start compile ${dist.home.src}/${compile.name}.as" />
                <mxmlc incremental="true" output="${dist.home.bin}/${compile.name}.swf" keep-generated-actionscript="false" actionscript-file-encoding="UTF-8" file="${dist.home.src}/${compile.name}.as">
                        <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />
                        <source-path path-element="${FLEX_HOME}/frameworks" />
                        <source-path path-element="${dist.home.src}" />
                        <compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
                                <include name="libs" />
                                <include name="../bundles/{locale}" />
                        </compiler.library-path>
                </mxmlc>
                <echo message="clear cache file." />
                <delete>
                        <fileset dir="${dist.home.bin}" includes="*.cache" />
                </delete>
                <echo message="compile ${dist.home.src}/${compile.name}.as  ===&gt;&gt;  ${dist.home.bin}/${compile.name}.swf success!" />
        </target>
<!– ============================================ –>
<!– 编译Flex Project 项目                                                                                                  –>
<!– ========================================= –>
        <target name="compileFP" depends="confusion">
                <echo message="start compile Flex Project…" />
                <for param="file">
                        <path>
                                <fileset dir="${dist.home.src}">
                                        <include name="**/*.mxml" />
                                </fileset>
                        </path>
                        <sequential>
                                <!– 通过正则表达式取出modules中的模块文件,进行批量编译~! –>
                                <propertyregex property="compile.target.name" regexp="(.*)src(.*)(mxml)" input="@{file}" override="yes" replace="\1bin\2swf" />
                                <mxmlc incremental="true" debug="false" output="${compile.target.name}" file="@{file}">
                                        <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />
                                        <static-link-runtime-shared-libraries>false</static-link-runtime-shared-libraries>
                                        <source-path path-element="${dist.home.src}" />
 
                                        <runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/framework.swc">
                                                <url rsl-url="../framework_3.2.0.3958.swz" />
                                                <url rsl-url="../framework_3.2.0.3958.swf" />
                                        </runtime-shared-library-path>
 
<!– 指定外部依赖库文件,这些库文件将不会编译进目标SWF中 –>
                                        <compiler.external-library-path dir="${dist.home.libs}">
                                                <include name="**/*.swc" />
                                        </compiler.external-library-path>
 
                                </mxmlc>
                                <!– 清除缓存文件 –>
                                <delete file="${compile.target.name}.cache" />
                                <echo message="Compiled @{file} =====&gt;&gt;   ${compile.target.name}" />
                                <echo message=" " />
                        </sequential>
                </for>
 
        </target>
</project>
This entry was posted in java. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">