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 package net.israfil.mojo.flex2;
35
36 import java.io.File;
37 import java.io.IOException;
38 import java.util.Arrays;
39 import java.util.HashSet;
40 import java.util.Iterator;
41 import java.util.List;
42 import java.util.Set;
43
44 import org.apache.maven.artifact.Artifact;
45 import org.apache.maven.plugin.MojoExecutionException;
46 import org.apache.maven.plugin.MojoFailureException;
47
48
49 /***
50 * Base class for flex2/actionscript3 plugin
51 *
52 * @author <a href="cgruber@israfil.net">Christian Edward Gruber</a>
53 * @author <a href="tspurway@gmail.com">Tim Spurway</a>
54 * @version $Id: AbstractFlexMojo.java 570 2007-11-22 13:07:05Z christianedwardgruber $
55 */
56 public abstract class AbstractFlexCompilerMojo extends AbstractFlexMojo {
57
58 private static final String SWF_SUFFIX = ".swf";
59 private static final String[] FLEX_FRAMEWORKS = { "automation","framework","playerglobal","flex","utilities","rpc" };
60 private static final String[] FLEX_OPTIONAL_FRAMEWORKS = { "charts", "automation_charts", "fds" };
61
62 /***
63 * Resolve extra libraries (such as charts or fds) from
64 * ${flex.home}/frameworks/libs. Default is false, in which case
65 * these (and other) swcs should be deployed as flex artifacts (swcs).
66 *
67 * @parameter alias="resolve-extra-framework-libs" default="false"
68 */
69 protected boolean resolveExtraSwcsFromFlexFrameworksLibs = false;
70
71 /***
72 * The current locale.
73 *
74 * @parameter expression="${flex.locale}" default="en_US"
75 */
76 protected String locale = "en_US";
77
78 /***
79 * @parameter expression="${flex.compiler.optimize}" default="false"
80 */
81 protected boolean optimize;
82
83 /***
84 * @parameter expression="${flex.compiler.profile}" default="false"
85 */
86 protected boolean profile;
87
88 /***
89 * @parameter expression="${flex.compiler.strict}" default="false"
90 */
91 protected boolean strict;
92
93 /***
94 * @parameter expression="${flex.compiler.use-network}" default="false"
95 */
96 protected boolean useNetwork;
97
98 /***
99 * @parameter expression="${flex.compiler.show-warnings}" default="false"
100 */
101 protected boolean warnings;
102
103 /***
104 * @parameter expression="${flex.compiler.incremental}" default="false"
105 */
106 protected boolean incremental;
107
108 /***
109 * @parameter expression="${flex.compiler.show-actionscript-warnings}" default="false"
110 */
111 protected boolean showActionscriptWarnings;
112
113 /***
114 * @parameter expression="${flex.compiler.show-binding-warnings}" default="false"
115 */
116 protected boolean showBindingWarnings;
117
118 /***
119 * @parameter expression="${flex.compiler.show-deprecation-warnings}" default="false"
120 */
121 protected boolean showDeprecationWarnings;
122
123
124 /***
125 * @parameter expression="${flex.licenses}"
126 */
127 protected License[] licenses;
128
129
130 /***
131 * @parameter expression="${flex.dataservices.config}"
132 */
133 protected File dataServicesConfig;
134
135 public AbstractFlexCompilerMojo() {
136 super();
137 }
138
139 /***
140 * Overload this to produce a test-jar, for example.
141 */
142 protected String getClassifier() {
143 return null;
144 }
145
146 protected File getOutputFile() {
147 return getFile(outputDirectory, finalName, classifier);
148 }
149
150
151
152
153 protected List prepareParameters() throws MojoFailureException, MojoExecutionException {
154 List parameters = super.prepareParameters();
155
156
157 File outFile = getOutputFile();
158 parameters.add("-output");
159 try {
160 parameters.add(outFile.getCanonicalFile().getAbsolutePath());
161 } catch (IOException e) {
162 throw new MojoExecutionException("Exception attempting to set output file: " + outFile, e);
163 }
164
165
166 parameters.add("-compiler.locale");
167 parameters.add(locale);
168
169
170
171 getLog().info("Attaching licenses.");
172 for (int i = 0; licenses != null && i < licenses.length; i++) {
173 getLog().debug("Adding license: " + licenses[i].getProduct() + "=" + licenses[i].getSerialNumber());
174 parameters.add("-licenses.license");
175 parameters.add(licenses[i].getProduct());
176 parameters.add(licenses[i].getSerialNumber());
177 }
178
179
180
181 if (optimize) parameters.add("-compiler.optimize");
182 if (profile) parameters.add("-compiler.profile");
183 if (strict) parameters.add("-compiler.strict");
184 if (useNetwork) parameters.add("-use-network");
185 if (warnings) parameters.add("-warnings");
186 if (incremental) parameters.add("-compiler.incremental");
187 if (showActionscriptWarnings) parameters.add("-show-actionscript-warnings");
188 if (showBindingWarnings) parameters.add("-show-binding-warnings");
189 if (showDeprecationWarnings) parameters.add("-show-deprecation-warnings");
190
191
192
193 if (dataServicesConfig != null) {
194 parameters.add("-compiler.services");
195 try {
196 parameters.add(dataServicesConfig.getCanonicalFile().getAbsolutePath());
197 } catch (IOException e) {
198 throw new MojoExecutionException("Unable to set data services config file.", e);
199 }
200 }
201
202
203
204 Set linkedLibraryPaths = new HashSet();
205 Set artifacts = project.getArtifacts();
206 getLog().debug("Dependency artifacts: " + artifacts);
207 Iterator depsIterator = artifacts.iterator();
208 while (depsIterator.hasNext()) {
209 Artifact dep = (Artifact)depsIterator.next();
210
211 if ( Artifact.SCOPE_COMPILE.equals( dep.getScope() ) ||
212 Artifact.SCOPE_PROVIDED.equals( dep.getScope() ) ||
213 Artifact.SCOPE_SYSTEM.equals( dep.getScope() ) ) {
214 if ("swc".equals(dep.getType())) {
215 getLog().debug("Linking dependency: " + dep);
216 try {
217 String absPath = dep.getFile().getCanonicalFile().getAbsolutePath();
218 linkedLibraryPaths.add(absPath);
219
220 } catch (IOException e) {
221 throw new MojoExecutionException("Dependency file not present or readable: " + dep.getFile().getAbsolutePath(),e);
222 }
223 } else if ("swf".equals(dep.getType())) {
224 throw new MojoExecutionException("Cannot link swf project '" +
225 dep + "' into other swf. Compile dependencies must be .swcs.");
226 }
227 } else {
228 getLog().debug("Skipping non-compile artifact: " + dep);
229 }
230
231 }
232
233
234
235
236
237
238
239
240
241 Iterator linkedLibsIter = linkedLibraryPaths.iterator();
242 while (linkedLibsIter.hasNext())
243 parameters.add("-library-path+=" + linkedLibsIter.next());
244
245
246 return parameters;
247 }
248
249
250 }