clean compile of oem.  May not run

Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/f094bae3
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/f094bae3
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/f094bae3

Branch: refs/heads/dual
Commit: f094bae3c0f08849aa8f6a3ea2b08a6e4907511c
Parents: 283e87e
Author: Alex Harui <aha...@apache.org>
Authored: Sun Jan 29 10:02:10 2017 -0800
Committer: Alex Harui <aha...@apache.org>
Committed: Sun Jan 29 10:02:10 2017 -0800

----------------------------------------------------------------------
 .../flex/compiler/clients/JSConfiguration.java  | 128 ++++++++++
 .../apache/flex/compiler/clients/MXMLJSC.java   |   2 +
 .../flex/compiler/config/Configuration.java     |  11 +-
 .../src/main/java/flex2/tools/Compc.java        |   2 -
 .../src/main/java/flex2/tools/Mxmlc.java        |   2 -
 .../src/main/java/flex2/tools/Tool.java         | 248 +------------------
 6 files changed, 144 insertions(+), 249 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f094bae3/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
----------------------------------------------------------------------
diff --git 
a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
 
b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
index 35d3a4b..b6b2906 100644
--- 
a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
+++ 
b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
@@ -21,7 +21,9 @@ package org.apache.flex.compiler.clients;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.flex.compiler.clients.MXMLJSC.JSOutputType;
 import org.apache.flex.compiler.clients.MXMLJSC.JSTargetType;
@@ -167,5 +169,131 @@ public class JSConfiguration extends Configuration
         jslibraryPath.addAll(resolvedPaths);
     }
 
+    /**
+     * Syntax:<br/>
+     * <code>-define=&lt;name&gt;,&lt;value&gt;</code> where name is 
<code>NAMESPACE::name</code> and value is a legal
+     * definition value (e.g. <code>true</code> or <code>1</code> or 
<code>!CONFIG::debugging</code>)
+     *
+     * Example: <code>-define=CONFIG::debugging,true</code>
+     *
+     * In <code>flex-config.xml</code>:<br/>
+     * 
+     * <pre>
+     * <flex-config>
+     *    <compiler>
+     *       <define>
+     *          <name>CONFIG::debugging</name>
+     *          <value>true</value>
+     *       </define>
+     *       ...
+     *    </compile>
+     * </flex-config>
+     * </pre>
+     *
+     * Values:<br/>
+     * Values are ActionScript expressions that must coerce and evaluate to 
constants at compile-time. Effectively, they
+     * are replaced in AS code, verbatim, so 
<code>-define=TEST::oneGreaterTwo,"1>2"</code> will getCompiler coerced and
+     * evaluated, at compile-time, to <code>false</code>.
+     *
+     * It is good practice to wrap values with double-quotes, so that MXMLC 
correctly parses them as a single argument:
+     * <br/>
+     * <code>-define=TEST::oneShiftRightTwo,"1 >> 2"</code>
+     *
+     * Values may contain compile-time constants and other configuration 
values:<br/>
+     * <code>-define=CONFIG::bool2,false -define=CONFIG::and1,"CONFIG::bool2 
&& false" TestApp.mxml</code>
+     *
+     * String values on the command-line <i>must</i> be surrounded by 
double-quotes, and either escape-quoted (
+     * <code>"\"foo\""</code> or <code>"\'foo\'"</code>) or single-quoted 
(<code>"'foo'"</code>).
+     *
+     * String values in configuration files need only be single- or double- 
quoted:<br/>
+     * 
+     * <pre>
+     * <flex-config>
+     *    <compiler>
+     *       <define>
+     *          <name>NAMES::Organization</name>
+     *          <value>'Apache Software Foundation'</value>
+     *       </define>
+     *       <define>
+     *          <name>NAMES::Application</name>
+     *          <value>"Flex 4.8.0"</value>
+     *       </define>
+     *       ...
+     *    </compile>
+     * </flex-config>
+     * </pre>
+     *
+     * Empty strings <i>must</i> be passed as <code>"''"</code> on the 
command-line, and <code>''</code> or
+     * <code>""</code> in configuration files.
+     * 
+     * Finally, if you have existing definitions in a configuration file, and 
you would like to add to them with the
+     * command-line (let's say most of your build setCompilertings are in the 
configuration, and that you are adding one
+     * temporarily using the command-line), you use the following syntax: 
<code>-define+=TEST::temporary,false</code>
+     * (noting the plus sign)
+     * 
+     * Note that definitions can be overridden/redefined if you use the append 
("+=") syntax (on the commandline or in a
+     * user config file, for instance) with the same namespace and name, and a 
new value.
+     * 
+     * Definitions cannot be removed/undefined. You can undefine ALL existing 
definitions from (e.g. from
+     * flex-config.xml) if you do not use append syntax ("=" or 
append="false").
+     * 
+     * IMPORTANT FOR FLEXBUILDER If you are using "Additional commandline 
arguments" to "-define", don't use the
+     * following syntax though I suggest it above: 
-define+=CONFIG::foo,"'value'" The trouble is that FB parses the
+     * double quotes incorrectly as <"'value'> -- the trailing double-quote is 
dropped. The solution is to avoid inner
+     * double-quotes and put them around the whole expression: 
-define+="CONFIG::foo,'value'"
+     */
+    private Map<String, String> jsconfigVars;
+
+    /**
+     * @return A list of ConfigVars
+     */
+    @Override
+    public Map<String, String> getCompilerDefine()
+    {
+       if (jsconfigVars.size() > 0)
+               return jsconfigVars;
+       return super.getCompilerDefine();
+    }
+
+    @Config(advanced = true, allowMultiple = true)
+    @Arguments({ "name", "value" })
+    public void setJsCompilerDefine(ConfigurationValue cv, String name, String 
value) throws ConfigurationException
+    {
+        if (jsconfigVars == null)
+               jsconfigVars = new LinkedHashMap<String, String>();
+
+        jsconfigVars.put(name, value);
+    }
+
+    //
+    // 'output' option
+    //
+
+    private String jsoutput;
+
+    @Override
+    public String getOutput()
+    {
+       if (jsoutput != null)
+               return jsoutput;
+       return super.getOutput();
+    }
+
+    @Config
+    @Arguments("filename")
+    public void setJsOutput(ConfigurationValue val, String output) throws 
ConfigurationException
+    {
+        this.jsoutput = getOutputPath(val, output);
+    }
+
+    @Override
+    protected String overrideDefinedValue(String name, String value)
+    {
+       if (name.equals("COMPILE::SWF") && value.equals("AUTO"))
+               return "false";
+       if (name.equals("COMPILE::JS") && value.equals("AUTO"))
+               return "true";
+       return value;
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f094bae3/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
----------------------------------------------------------------------
diff --git 
a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java 
b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
index 12ac04f..7eb863e 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
@@ -397,6 +397,8 @@ public class MXMLJSC implements JSCompilerEntryPoint, 
ProblemQueryProvider,
                          arg.startsWith("-remove-circulars") ||
                          arg.startsWith("-compiler.js-external-library-path") 
||
                          arg.startsWith("-compiler.js-library-path") ||
+                         arg.startsWith("-compiler.js-define") ||
+                         arg.startsWith("-js-output") ||
                          arg.startsWith("-source-map")))
                        list.add(arg);                                          
        }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f094bae3/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java
----------------------------------------------------------------------
diff --git 
a/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java 
b/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java
index 7d9f3d7..f206e47 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java
@@ -1870,9 +1870,18 @@ public class Configuration
         if (configVars == null)
             configVars = new LinkedHashMap<String, String>();
 
-        configVars.put(name, value);
+        configVars.put(name, overrideDefinedValue(name, value));
     }
 
+    protected String overrideDefinedValue(String name, String value)
+    {
+       if (name.equals("COMPILE::SWF") && value.equals("AUTO"))
+               return "true";
+       if (name.equals("COMPILE::JS") && value.equals("AUTO"))
+               return "false";
+       return value;
+    }
+    
     //
     // 'compiler.conservative' option (hidden)
     //

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f094bae3/flex-compiler-oem/src/main/java/flex2/tools/Compc.java
----------------------------------------------------------------------
diff --git a/flex-compiler-oem/src/main/java/flex2/tools/Compc.java 
b/flex-compiler-oem/src/main/java/flex2/tools/Compc.java
index 9186cbc..db8c1c2 100644
--- a/flex-compiler-oem/src/main/java/flex2/tools/Compc.java
+++ b/flex-compiler-oem/src/main/java/flex2/tools/Compc.java
@@ -42,7 +42,6 @@ public class Compc extends Tool {
 
     public static int compcNoExit(String[] args) throws 
InvocationTargetException, NoSuchMethodException, InstantiationException, 
IllegalAccessException {
 
-        COMPILER = COMPC.class;
         JS_COMPILER = CompJSC.class;
 
         return compile(args);
@@ -50,7 +49,6 @@ public class Compc extends Tool {
 
     public static void compc(String[] args) throws InvocationTargetException, 
NoSuchMethodException, InstantiationException, IllegalAccessException {
 
-        COMPILER = COMPC.class;
         JS_COMPILER = CompJSC.class;
 
         compile(args);

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f094bae3/flex-compiler-oem/src/main/java/flex2/tools/Mxmlc.java
----------------------------------------------------------------------
diff --git a/flex-compiler-oem/src/main/java/flex2/tools/Mxmlc.java 
b/flex-compiler-oem/src/main/java/flex2/tools/Mxmlc.java
index 93ed8e2..c78f90b 100644
--- a/flex-compiler-oem/src/main/java/flex2/tools/Mxmlc.java
+++ b/flex-compiler-oem/src/main/java/flex2/tools/Mxmlc.java
@@ -61,7 +61,6 @@ public final class Mxmlc extends Tool {
 
     public static int mxmlcNoExit(String[] args) throws 
InvocationTargetException, NoSuchMethodException, InstantiationException, 
IllegalAccessException {
 
-        COMPILER = MXMLC.class;
         JS_COMPILER = MxmlJSC.class;
 
         return compile(args);
@@ -69,7 +68,6 @@ public final class Mxmlc extends Tool {
 
     public static void mxmlc(String[] args) throws InvocationTargetException, 
NoSuchMethodException, InstantiationException, IllegalAccessException {
 
-        COMPILER = MXMLC.class;
         JS_COMPILER = MxmlJSC.class;
 
         compile(args);

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f094bae3/flex-compiler-oem/src/main/java/flex2/tools/Tool.java
----------------------------------------------------------------------
diff --git a/flex-compiler-oem/src/main/java/flex2/tools/Tool.java 
b/flex-compiler-oem/src/main/java/flex2/tools/Tool.java
index 7d1f138..dc59a00 100644
--- a/flex-compiler-oem/src/main/java/flex2/tools/Tool.java
+++ b/flex-compiler-oem/src/main/java/flex2/tools/Tool.java
@@ -57,7 +57,6 @@ import flex2.tools.oem.Message;
  */
 public class Tool
 {
-    protected static Class<? extends MXMLC> COMPILER;
     protected static Class<? extends MxmlJSC> JS_COMPILER;
 
     protected static int compile(String[] args)
@@ -65,223 +64,14 @@ public class Tool
     {
         int exitCode;
 
-        final String value = ArgumentUtil.getValue(args, "-js-output-type");
-        JSOutputType jsOutputType = null;
+        MxmlJSC mxmlJSC = JS_COMPILER.newInstance();
+        exitCode = mxmlJSC.execute(args);
 
-        if (value != null)
+        if (mxmlJSC.getProblemQuery().hasErrors())
         {
-            jsOutputType = JSOutputType.fromString(value);
+            processProblemReport(mxmlJSC);
         }
 
-        if (jsOutputType != null)
-        {
-            ArgumentBag bag = prepareJs(new ArgumentBag(args));
-
-            MxmlJSC mxmlJSC = JS_COMPILER.newInstance();
-            exitCode = mxmlJSC.execute(bag.args);
-
-            if (!mxmlJSC.getProblemQuery().hasErrors())
-            {
-                if (jsOutputType.equals(FLEXJS_DUAL))
-                {
-                    prepareAs3(bag);
-                    exitCode = flexCompile(bag.args);
-                }
-            }
-            else
-            {
-                processProblemReport(mxmlJSC);
-            }
-        }
-        else
-        {
-            exitCode = flexCompile(args);
-        }
-
-        return exitCode;
-    }
-
-    protected static ArgumentBag prepareJs(ArgumentBag bag)
-    {
-        SwitchDefineToCompileJs(bag);
-        prepareJsOutput(bag);
-
-        return bag;
-    }
-
-    protected static ArgumentBag prepareAs3(ArgumentBag bag)
-    {
-        SwitchDefineToCompileAs3(bag);
-        prepareAs3Output(bag);
-        removeNativeJSLibraries(bag);
-
-        return bag;
-    }
-
-    private static void removeNativeJSLibraries(ArgumentBag bag)
-    {
-        final List<String> argList = new 
ArrayList<String>(Arrays.asList(bag.args));
-        argList.add("--exclude-native-js-libraries=true");
-        bag.args = argList.toArray(new String[argList.size()]);
-    }
-
-    private static void prepareJsOutput(ArgumentBag bag)
-    {
-        bag.isCommandLineOutput = true;
-        bag.oldOutputPath = ArgumentUtil.getValue(bag.args, "-output");
-
-        if (bag.oldOutputPath == null)
-        {
-            bag.oldOutputPath = ArgumentUtil.getValue(bag.args, "-o");
-            if (bag.oldOutputPath != null)
-            {
-                bag.outputAlias = "-o";
-            }
-        }
-        else
-        {
-            bag.outputAlias = "-output";
-        }
-
-        if (bag.oldOutputPath == null)
-        {
-            bag.isCommandLineOutput = false;
-            List<ConfigurationBuffer> flexConfigs = null;
-
-            try
-            {
-                flexConfigs = loadConfig(bag.args);
-
-                for (ConfigurationBuffer flexConfig : flexConfigs)
-                {
-                    if (bag.oldOutputPath == null) {
-                        final List<ConfigurationValue> output = flexConfig != 
null ? flexConfig.getVar("output") : null;
-                        final ConfigurationValue configurationValue = output 
!= null ? output.get(0) : null;
-                        bag.oldOutputPath = configurationValue != null ? 
configurationValue.getArgs().get(0)
-                                : bag.oldOutputPath;
-                    }
-                }
-            }
-            catch (org.apache.flex.compiler.exceptions.ConfigurationException 
ignored)
-            {
-            }
-        }
-
-        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";
-
-                if (bag.isCommandLineOutput)
-                {
-                    ArgumentUtil.setValue(bag.args, bag.outputAlias, 
bag.newOutputPath);
-                }
-                else
-                {
-                    bag.args = ArgumentUtil.addValue(bag.args, "-output", 
bag.newOutputPath);
-                }
-            }
-        }
-    }
-
-    private static void SwitchDefineToCompileJs(ArgumentBag bag)
-    {
-        final Collection<String> defines = ArgumentUtil.getValues(bag.args, 
"-define");
-        if (defines.contains("COMPILE::AS3,AUTO") && 
defines.contains("COMPILE::JS,AUTO"))
-        {
-            bag.args = ArgumentUtil.removeElementWithValue(bag.args, 
"-define", "COMPILE::JS,AUTO");
-            bag.args = ArgumentUtil.removeElementWithValue(bag.args, 
"-define", "COMPILE::AS3,AUTO");
-
-            bag.args = ArgumentUtil.addValue(bag.args, "-define", 
"COMPILE::JS,true", true);
-            bag.args = ArgumentUtil.addValue(bag.args, "-define", 
"COMPILE::AS3,false", true);
-
-            bag.args = ArgumentUtil.addValue(bag.args, "-keep-asdoc", null);
-        }
-    }
-
-    private static void prepareAs3Output(ArgumentBag bag)
-    {
-        if (bag.oldOutputPath != null)
-        {
-            if (bag.isCommandLineOutput)
-            {
-                ArgumentUtil.setValue(bag.args, bag.outputAlias, 
bag.oldOutputPath);
-            }
-            else
-            {
-                bag.args = ArgumentUtil.removeElement(bag.args, "-output");
-            }
-        }
-
-        if (COMPILER.getName().equals(COMPC.class.getName()))
-        {
-            bag.args = ArgumentUtil.addValue(bag.args, "-include-file",
-                    "js" + File.separator + "out" + File.separator + "*," + 
bag.newOutputPath);
-        }
-    }
-
-    private static void SwitchDefineToCompileAs3(ArgumentBag bag)
-    {
-        final Collection<String> defines = ArgumentUtil.getValues(bag.args, 
"-define");
-        if (defines.contains("COMPILE::AS3,false") && 
defines.contains("COMPILE::JS,true"))
-        {
-            bag.args = ArgumentUtil.removeElement(bag.args, "-keep-asdoc");
-            bag.args = ArgumentUtil.removeElementWithValue(bag.args, 
"-define", "COMPILE::AS3,false");
-            bag.args = ArgumentUtil.removeElementWithValue(bag.args, 
"-define", "COMPILE::JS,true");
-
-            bag.args = ArgumentUtil.addValue(bag.args, "-define", 
"COMPILE::JS,false", true);
-            bag.args = ArgumentUtil.addValue(bag.args, "-define", 
"COMPILE::AS3,true", true);
-        }
-
-        bag.args = ArgumentUtil.removeElement(bag.args, "-js-output-type");
-    }
-
-    private static List<ConfigurationBuffer> loadConfig(String[] args)
-            throws org.apache.flex.compiler.exceptions.ConfigurationException
-    {
-        List<ConfigurationBuffer> configurationBuffers = null;
-
-        final Collection<String> configFilePaths = 
ArgumentUtil.getValues(args, "-load-config");
-        if (configFilePaths != null)
-        {
-            for (String configFilePath : configFilePaths)
-            {
-                final File configFile = new File(configFilePath);
-                final FileSpecification fileSpecification = new 
FileSpecification(configFile.getAbsolutePath());
-                final ConfigurationBuffer cfgbuf = 
createConfigurationBuffer(Configuration.class);
-
-                FileConfigurator.load(cfgbuf, fileSpecification, new 
File(configFile.getPath()).getParent(),
-                        "flex-config", false);
-
-                if (configurationBuffers == null)
-                {
-                    configurationBuffers = new 
ArrayList<ConfigurationBuffer>(0);
-                }
-                configurationBuffers.add(cfgbuf);
-            }
-        }
-
-        return configurationBuffers;
-    }
-
-    private static ConfigurationBuffer createConfigurationBuffer(Class<? 
extends Configuration> configurationClass)
-    {
-        return new ConfigurationBuffer(configurationClass, 
Configuration.getAliases());
-    }
-
-    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;
     }
 
@@ -444,34 +234,4 @@ public class Tool
         }
     }
 
-    static class CompilerRequestableProblems implements ProblemQueryProvider
-    {
-        private MXMLC mxmlc;
-
-        public CompilerRequestableProblems(MXMLC mxmlc)
-        {
-            this.mxmlc = mxmlc;
-        }
-
-        @Override
-        public ProblemQuery getProblemQuery()
-        {
-            return mxmlc.getProblems();
-        }
-    }
-
-    protected static class ArgumentBag
-    {
-        public String[] args;
-
-        public String outputAlias;
-        public String oldOutputPath;
-        public String newOutputPath;
-        public boolean isCommandLineOutput;
-
-        public ArgumentBag(String[] args)
-        {
-            this.args = args;
-        }
-    }
 }

Reply via email to