You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ft...@apache.org on 2015/06/02 14:42:41 UTC
[34/35] git commit: [flex-falcon] [refs/heads/IDEA-FLEX_JS_COMPILER]
- Chain the compilation in case -js-output-type=FLEXJS_DUAL on the command
line. Note: At the moment, -output needs to be passed to the command line too.
Chain the compilation in case -js-output-type=FLEXJS_DUAL on the command line.
Note: At the moment, -output needs to be passed to the command line too.
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/55443ff9
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/55443ff9
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/55443ff9
Branch: refs/heads/IDEA-FLEX_JS_COMPILER
Commit: 55443ff9b6488f8f7a5e0293f49b97e753389ac4
Parents: 6675bd0
Author: Frédéric THOMAS <we...@gmail.com>
Authored: Tue Jun 2 13:32:33 2015 +0100
Committer: Frédéric THOMAS <we...@gmail.com>
Committed: Tue Jun 2 13:41:45 2015 +0100
----------------------------------------------------------------------
.../apache/flex/compiler/clients/MXMLJSC.java | 4 +-
.../apache/flex/compiler/clients/COMPJSC.java | 1 +
.../apache/flex/compiler/clients/MXMLJSC.java | 7 +-
.../src/org/apache/flex/utils/ArgumentUtil.java | 122 ++++++++++++++
.../apache/flex/utils/ConfigurationUtil.java | 42 -----
flex-compiler-oem/src/flex2/tools/Compc.java | 3 -
flex-compiler-oem/src/flex2/tools/MxmlJSC.java | 1 +
flex-compiler-oem/src/flex2/tools/Tool.java | 168 +++++++++++--------
8 files changed, 226 insertions(+), 122 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/55443ff9/compiler.js/src/org/apache/flex/compiler/clients/MXMLJSC.java
----------------------------------------------------------------------
diff --git a/compiler.js/src/org/apache/flex/compiler/clients/MXMLJSC.java b/compiler.js/src/org/apache/flex/compiler/clients/MXMLJSC.java
index b4f5718..1f8f070 100644
--- a/compiler.js/src/org/apache/flex/compiler/clients/MXMLJSC.java
+++ b/compiler.js/src/org/apache/flex/compiler/clients/MXMLJSC.java
@@ -75,7 +75,7 @@ import org.apache.flex.swc.ISWC;
import org.apache.flex.swf.ISWF;
import org.apache.flex.swf.io.ISWFWriter;
import org.apache.flex.swf.types.Rect;
-import org.apache.flex.utils.ConfigurationUtil;
+import org.apache.flex.utils.ArgumentUtil;
import org.apache.flex.utils.FilenameNormalization;
import java.io.*;
@@ -145,7 +145,7 @@ public class MXMLJSC
int exitCode = -1;
try
{
- exitCode = _mainNoExit(ConfigurationUtil.fixArgs(args), problems);
+ exitCode = _mainNoExit(ArgumentUtil.fixArgs(args), problems);
}
catch (Exception e)
{
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/55443ff9/compiler.jx/src/org/apache/flex/compiler/clients/COMPJSC.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/clients/COMPJSC.java b/compiler.jx/src/org/apache/flex/compiler/clients/COMPJSC.java
index 7c205a8..c288f33 100644
--- a/compiler.jx/src/org/apache/flex/compiler/clients/COMPJSC.java
+++ b/compiler.jx/src/org/apache/flex/compiler/clients/COMPJSC.java
@@ -115,6 +115,7 @@ public class COMPJSC extends MXMLJSC
break;
case FLEXJS:
+ case FLEXJS_DUAL:
backend = new MXMLFlexJSSWCBackend();
break;
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/55443ff9/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java b/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
index 759da96..ae9e76a 100644
--- a/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
+++ b/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
@@ -66,7 +66,7 @@ import org.apache.flex.compiler.targets.ITarget.TargetType;
import org.apache.flex.compiler.targets.ITargetSettings;
import org.apache.flex.compiler.units.ICompilationUnit;
import org.apache.flex.tools.FlexTool;
-import org.apache.flex.utils.ConfigurationUtil;
+import org.apache.flex.utils.ArgumentUtil;
import org.apache.flex.utils.FilenameNormalization;
import java.io.*;
@@ -87,7 +87,7 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider, Flex
*/
public enum JSOutputType
{
- AMD("amd"), FLEXJS("flexjs"), GOOG("goog"), VF2JS("vf2js");
+ AMD("amd"), FLEXJS("flexjs"), GOOG("goog"), VF2JS("vf2js"), FLEXJS_DUAL("flexjs_dual");
private String text;
@@ -191,6 +191,7 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider, Flex
backend = new AMDBackend();
break;
case FLEXJS:
+ case FLEXJS_DUAL:
backend = new MXMLFlexJSBackend();
break;
case GOOG:
@@ -243,7 +244,7 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider, Flex
int exitCode = -1;
try
{
- exitCode = _mainNoExit(ConfigurationUtil.fixArgs(args), problems);
+ exitCode = _mainNoExit(ArgumentUtil.fixArgs(args), problems);
}
catch (Exception e)
{
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/55443ff9/compiler/src/org/apache/flex/utils/ArgumentUtil.java
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/utils/ArgumentUtil.java b/compiler/src/org/apache/flex/utils/ArgumentUtil.java
new file mode 100644
index 0000000..8b5fe7a
--- /dev/null
+++ b/compiler/src/org/apache/flex/utils/ArgumentUtil.java
@@ -0,0 +1,122 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.utils;
+
+import java.io.File;
+import java.lang.reflect.Array;
+
+public class ArgumentUtil {
+
+ // workaround for Falcon bug.
+ // Input files with relative paths confuse the algorithm that extracts the root class name.
+ public static String[] fixArgs(final String[] args) {
+ String[] newArgs = args;
+ if (args.length > 1) {
+ String targetPath = args[args.length - 1];
+ if (targetPath.startsWith(".")) {
+ targetPath = FileUtils.getTheRealPathBecauseCanonicalizeDoesNotFixCase(new File(targetPath));
+ newArgs = new String[args.length];
+ System.arraycopy(args, 0, newArgs, 0, args.length - 1);
+ newArgs[args.length - 1] = targetPath;
+ }
+ }
+ return newArgs;
+ }
+
+ public static String[] removeElement(String[] args, String element) {
+
+ int length = Array.getLength(args);
+ int index = -1;
+
+ for (int i = 0; i < length; i++) {
+ final String[] kvp = args[i].split("=");
+ if (element.equals(kvp[0])) {
+ index = i;
+ break;
+ }
+ }
+
+ if (index < 0 || index >= length) {
+ throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
+ }
+
+ String[] newArgs = new String[args.length - 1];
+ System.arraycopy(args, 0, newArgs, 0, index);
+ if (index < length - 1) {
+ System.arraycopy(args, index + 1, newArgs, index, length - index - 1);
+ }
+
+ return newArgs;
+ }
+
+ public static String getValue(String[] args, String element) {
+
+ boolean found = false;
+ String[] kvp = new String[0];
+
+ for (String s : args) {
+ kvp = s.split("=");
+
+ if (kvp[0].equals(element)) {
+ found = true;
+ break;
+ }
+ }
+
+ return found ? kvp[1] : null;
+ }
+
+ public static void setValue(String[] args, String element, String value) {
+ String[] kvp;
+
+ for (int i = 0, argsLength = args.length; i < argsLength; i++) {
+ kvp = args[i].split("=");
+
+ if (kvp[0].equals(element)) {
+ args[i] = kvp[0] + "=" + value;
+ break;
+ }
+ }
+ }
+
+ public static String[] addValueAt(String[] args, String elemrnt, String value, int index) {
+
+ int length = Array.getLength(args);
+
+ if (index < 0 || index >= length) {
+ throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
+ }
+
+ String[] newArgs = new String[args.length + 1];
+
+ for (int i = 0; i < newArgs.length; i++) {
+ if (i < index) {
+ newArgs[i] = args[i];
+ } else if (i == index) {
+ newArgs[i] = elemrnt + "=" + value;
+ } else {
+ newArgs[i] = args[i - 1];
+ }
+
+ }
+
+ return newArgs;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/55443ff9/compiler/src/org/apache/flex/utils/ConfigurationUtil.java
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/utils/ConfigurationUtil.java b/compiler/src/org/apache/flex/utils/ConfigurationUtil.java
deleted file mode 100644
index ea1bc10..0000000
--- a/compiler/src/org/apache/flex/utils/ConfigurationUtil.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.flex.utils;
-
-import java.io.File;
-
-public class ConfigurationUtil {
-
- // workaround for Falcon bug.
- // Input files with relative paths confuse the algorithm that extracts the root class name.
- public static String[] fixArgs(final String[] args) {
- String[] newArgs = args;
- if (args.length > 1) {
- String targetPath = args[args.length - 1];
- if (targetPath.startsWith(".")) {
- targetPath = FileUtils.getTheRealPathBecauseCanonicalizeDoesNotFixCase(new File(targetPath));
- newArgs = new String[args.length];
- for (int i = 0; i < args.length - 1; ++i)
- newArgs[i] = args[i];
- newArgs[args.length - 1] = targetPath;
- }
- }
- return newArgs;
- }
-}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/55443ff9/flex-compiler-oem/src/flex2/tools/Compc.java
----------------------------------------------------------------------
diff --git a/flex-compiler-oem/src/flex2/tools/Compc.java b/flex-compiler-oem/src/flex2/tools/Compc.java
index 38848fa..6580e9a 100644
--- a/flex-compiler-oem/src/flex2/tools/Compc.java
+++ b/flex-compiler-oem/src/flex2/tools/Compc.java
@@ -27,9 +27,6 @@ import java.lang.reflect.InvocationTargetException;
* Entry-point for compc, the command-line tool for compiling components.
*/
public class Compc extends Tool {
-
- public static final String FILE_SPECS = "include-classes";
-
/**
* The entry-point for Mxmlc.
* Note that if you change anything in this method, make sure to check Compc, Shell, and
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/55443ff9/flex-compiler-oem/src/flex2/tools/MxmlJSC.java
----------------------------------------------------------------------
diff --git a/flex-compiler-oem/src/flex2/tools/MxmlJSC.java b/flex-compiler-oem/src/flex2/tools/MxmlJSC.java
index f71633a..9ff8381 100644
--- a/flex-compiler-oem/src/flex2/tools/MxmlJSC.java
+++ b/flex-compiler-oem/src/flex2/tools/MxmlJSC.java
@@ -70,6 +70,7 @@ public class MxmlJSC implements ProblemQueryProvider {
backend = new AMDBackend();
break;
case FLEXJS:
+ case FLEXJS_DUAL:
backend = new MXMLFlexJSBackend();
break;
case GOOG:
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/55443ff9/flex-compiler-oem/src/flex2/tools/Tool.java
----------------------------------------------------------------------
diff --git a/flex-compiler-oem/src/flex2/tools/Tool.java b/flex-compiler-oem/src/flex2/tools/Tool.java
index b61fa43..a41c1f4 100644
--- a/flex-compiler-oem/src/flex2/tools/Tool.java
+++ b/flex-compiler-oem/src/flex2/tools/Tool.java
@@ -26,13 +26,17 @@ import flex2.compiler.util.CompilerMessage;
import flex2.compiler.util.CompilerMessage.CompilerError;
import flex2.compiler.util.ThreadLocalToolkit;
import flex2.tools.oem.Message;
-import org.apache.flex.compiler.clients.problems.ProblemQueryProvider;
+import org.apache.flex.compiler.clients.COMPC;
import org.apache.flex.compiler.clients.MXMLC;
+import org.apache.flex.compiler.clients.MXMLJSC.JSOutputType;
import org.apache.flex.compiler.clients.problems.ProblemQuery;
+import org.apache.flex.compiler.clients.problems.ProblemQueryProvider;
import org.apache.flex.compiler.problems.CompilerProblemSeverity;
import org.apache.flex.compiler.problems.ICompilerProblem;
import org.apache.flex.compiler.problems.annotations.DefaultSeverity;
+import org.apache.flex.utils.ArgumentUtil;
+import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.annotation.Annotation;
@@ -42,83 +46,117 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import static org.apache.flex.compiler.clients.MXMLJSC.JSOutputType.FLEXJS_DUAL;
+
/**
* Common base class for most flex tools.
*/
-public class Tool
-{
+public class Tool {
protected static Class<? extends MXMLC> COMPILER;
protected static Class<? extends MxmlJSC> JS_COMPILER;
protected static int compile(String[] args) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
int exitCode;
- if (hasJsOutputType(args)) {
+ final JSOutputType jsOutputType = JSOutputType.fromString(ArgumentUtil.getValue(args, "-js-output-type"));
+
+ if (jsOutputType != null) {
+ ArgumentBag bag = preparePhase1(new ArgumentBag(args));
+
MxmlJSC mxmlJSC = JS_COMPILER.newInstance();
- exitCode = mxmlJSC.execute(args);
- processProblemReport(mxmlJSC);
+ exitCode = mxmlJSC.execute(bag.args);
+
+ if (!mxmlJSC.getProblemQuery().hasErrors()) {
+ if (jsOutputType.equals(FLEXJS_DUAL)) {
+ preparePhase2(bag);
+ exitCode = flexCompile(bag.args);
+ }
+ } else {
+ processProblemReport(mxmlJSC);
+ }
} else {
- MXMLC mxmlc = COMPILER.newInstance();
- exitCode = mxmlc.execute(args);
- processProblemReport(new CompilerRequestableProblems(mxmlc));
+ exitCode = flexCompile(args);
}
return exitCode;
}
- protected static boolean hasJsOutputType(String[] args) {
- boolean found = false;
+ protected static class ArgumentBag {
+ public String[] args;
- for (String s : args) {
- String[] kvp = s.split("=");
+ public String oldOutputPath;
+ public String newOutputPath;
- if (s.contains("-js-output-type")) {
- found = true;
- break;
+ public ArgumentBag(String[] args) {
+ this.args = args;
+ }
+ }
+
+ protected static ArgumentBag preparePhase1(ArgumentBag bag) {
+ bag.oldOutputPath = ArgumentUtil.getValue(bag.args, "-output");
+
+ if (bag.oldOutputPath != null) {
+ final int lastIndexOf = Math.max(bag.oldOutputPath.lastIndexOf("/"), bag.oldOutputPath.lastIndexOf("\\"));
+
+ if (lastIndexOf > -1) {
+ bag.newOutputPath = bag.oldOutputPath.substring(0, lastIndexOf) + File.separator + "js" + File.separator + "out";
+ ArgumentUtil.setValue(bag.args, "-output", bag.newOutputPath);
}
}
- return found;
+ return bag;
}
- public static Map<String, String> getLicenseMapFromFile(String fileName) throws ConfigurationException
- {
+ protected static ArgumentBag preparePhase2(ArgumentBag bag) {
+ bag.args = ArgumentUtil.removeElement(bag.args, "-js-output-type");
+
+ if (bag.oldOutputPath != null) {
+ ArgumentUtil.setValue(bag.args, "-output", bag.oldOutputPath);
+ }
+
+ if (COMPILER.getName().equals(COMPC.class.getName())) {
+ bag.args = ArgumentUtil.addValueAt(bag.args, "-include-file", "js" + File.separator + "out" + File.separator + "*," + bag.newOutputPath, bag.args.length - 1);
+ }
+
+ return bag;
+ }
+
+ protected static int flexCompile(String[] args) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
+ int exitCode;
+
+ MXMLC mxmlc = COMPILER.newInstance();
+ exitCode = mxmlc.execute(args);
+ processProblemReport(new CompilerRequestableProblems(mxmlc));
+
+ return exitCode;
+ }
+
+ public static Map<String, String> getLicenseMapFromFile(String fileName) throws ConfigurationException {
Map<String, String> result = null;
FileInputStream in = null;
- try
- {
+ try {
in = new FileInputStream(fileName);
Properties properties = new Properties();
properties.load(in);
Enumeration enumeration = properties.propertyNames();
- if ( enumeration.hasMoreElements() )
- {
+ if (enumeration.hasMoreElements()) {
result = new HashMap<String, String>();
- while ( enumeration.hasMoreElements() )
- {
+ while (enumeration.hasMoreElements()) {
String propertyName = (String) enumeration.nextElement();
result.put(propertyName, properties.getProperty(propertyName));
}
}
- }
- catch (IOException ioException)
- {
- LocalizationManager l10n = ThreadLocalToolkit.getLocalizationManager();
+ } catch (IOException ioException) {
+ LocalizationManager l10n = ThreadLocalToolkit.getLocalizationManager();
throw new ConfigurationException(l10n.getLocalizedTextString(new FailedToLoadLicenseFile(fileName)));
- }
- finally
- {
- if (in != null)
- {
- try
- {
+ } finally {
+ if (in != null) {
+ try {
in.close();
- }
- catch (IOException ioe)
- {
+ } catch (IOException ioe) {
}
}
}
@@ -126,28 +164,24 @@ public class Tool
return result;
}
- public static class FailedToLoadLicenseFile extends CompilerError
- {
- private static final long serialVersionUID = -2980033917773108328L;
-
+ public static class FailedToLoadLicenseFile extends CompilerError {
+ private static final long serialVersionUID = -2980033917773108328L;
+
public String fileName;
- public FailedToLoadLicenseFile(String fileName)
- {
- super();
- this.fileName = fileName;
- }
- }
-
- public static void processProblemReport(ProblemQueryProvider requestableProblems)
- {
- for (ICompilerProblem problem : requestableProblems.getProblemQuery().getProblems())
- {
+ public FailedToLoadLicenseFile(String fileName) {
+ super();
+ this.fileName = fileName;
+ }
+ }
+
+ public static void processProblemReport(ProblemQueryProvider requestableProblems) {
+ for (ICompilerProblem problem : requestableProblems.getProblemQuery().getProblems()) {
Class aClass = problem.getClass();
Annotation[] annotations = aClass.getAnnotations();
- for(Annotation annotation : annotations){
- if(annotation instanceof DefaultSeverity){
+ for (Annotation annotation : annotations) {
+ if (annotation instanceof DefaultSeverity) {
DefaultSeverity myAnnotation = (DefaultSeverity) annotation;
CompilerProblemSeverity cps = myAnnotation.value();
String level;
@@ -161,11 +195,9 @@ public class Tool
problem.getSourcePath(),
problem.getLine() + 1,
problem.getColumn());
- try
- {
+ try {
String errText = (String) aClass.getField("DESCRIPTION").get(aClass);
- while (errText.contains("${"))
- {
+ while (errText.contains("${")) {
int start = errText.indexOf("${");
int end = errText.indexOf("}", start);
String token = errText.substring(start + 2, end);
@@ -176,24 +208,16 @@ public class Tool
msg.setMessage(errText);
logMessage(msg);
- }
- catch (IllegalArgumentException e)
- {
+ } catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- }
- catch (SecurityException e)
- {
+ } catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- }
- catch (IllegalAccessException e)
- {
+ } catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- }
- catch (NoSuchFieldException e)
- {
+ } catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}