View Javadoc

1   /*
2    * Copyright (c) 2006-2007 Israfil Consulting Services Corporation
3    * Copyright (c) 2006-2007 Christian Edward Gruber
4    * All Rights Reserved
5    * 
6    * This software is licensed under the Berkeley Standard Distribution license,
7    * (BSD license), as defined below:
8    * 
9    * Redistribution and use in source and binary forms, with or without 
10   * modification, are permitted provided that the following conditions are met:
11   *
12   * 1. Redistributions of source code must retain the above copyright notice, this 
13   *    list of conditions and the following disclaimer.
14   * 2. Redistributions in binary form must reproduce the above copyright notice, 
15   *    this list of conditions and the following disclaimer in the documentation 
16   *    and/or other materials provided with the distribution.
17   * 3. Neither the name of Israfil Consulting Services nor the names of its contributors 
18   *    may be used to endorse or promote products derived from this software without 
19   *    specific prior written permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
23   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
24   * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
25   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
26   * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
27   * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
28   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
30   * OF SUCH DAMAGE.
31   * 
32   * $Id: AbstractFlexMojo.java 570 2007-11-22 13:07:05Z christianedwardgruber $
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 		// define output file.
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 		// add in locale
166 		parameters.add("-compiler.locale");
167 		parameters.add(locale);
168 		
169 		// add in license
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 		// add in binary options.
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 		//verbose-stacktraces
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 		// Add in dependency .swfs.
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 	        // TODO: let the scope handler deal with this
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 						//includedLibraryPaths.add(absPath);
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 		//	FIXME: What do we do with include-libraries???
234 		//	add included library paths.
235 		//	Set includedLibraryPaths = new HashSet();
236 		//	Iterator inclLibsIter = includedLibraryPaths.iterator();
237 		//	while (inclLibsIter.hasNext()) 
238 		//		parameters.add("-include-libraries+=" + inclLibsIter.next());
239 
240 		// add linked library paths.
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 }