flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erikdebr...@apache.org
Subject [2/3] git commit: Added FlexJS support to FalconJx.MXMLJSC
Date Mon, 25 Mar 2013 15:36:43 GMT
Added FlexJS support to FalconJx.MXMLJSC

You can now create FlexJS compatible output using the Falcon MXMLJSC class.

Use these command line arguments:
+env.PLAYERGLOBAL_HOME=/Users/erik/Documents/ApacheFlex/dependencies/PlayerGlobal/player +playerglobal.version=11.1
-load-config="/Applications/Adobe Flash Builder 4.7/sdks/4.9.1/frameworks/flex-config.xml"
-library-path+=/Users/erik/Documents/ApacheFlex/git/flex-asjs/frameworks/as/libs/FlexJSUI.swc
-js-output-type=FLEXJS
-output=/Users/erik/Desktop/FlexJS/fromEclipse/FlexJSTest.js
/Users/erik/Documents/ApacheFlex/git/flex-asjs/examples/FlexJSTest_again/src/FlexJSTest.mxml

Signed-off-by: Erik de Bruin <erik@ixsoftware.nl>


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

Branch: refs/heads/develop
Commit: 5085979e45e5bf65b0931c7acfa97a13d9421326
Parents: 42ad50c
Author: Erik de Bruin <erik@ixsoftware.nl>
Authored: Mon Mar 25 16:30:48 2013 +0100
Committer: Erik de Bruin <erik@ixsoftware.nl>
Committed: Mon Mar 25 16:30:48 2013 +0100

----------------------------------------------------------------------
 .../org/apache/flex/compiler/clients/MXMLJSC.java  |   31 ++++--
 .../internal/codegen/mxml/MXMLBlockWalker.java     |   19 ++++
 .../compiler/internal/codegen/mxml/MXMLWriter.java |   79 +++++++++++++++
 .../driver/mxml/MXMLSourceFileHandler.java         |    4 +-
 .../driver/mxml/flexjs/MXMLFlexJSBackend.java      |   19 ++++
 .../internal/visitor/mxml/MXMLNodeSwitch.java      |    7 +-
 .../compiler/visitor/mxml/IMXMLBlockVisitor.java   |    6 +
 7 files changed, 150 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/5085979e/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 8fc95d7..d9bb8c5 100644
--- a/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
+++ b/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
@@ -52,9 +52,9 @@ import org.apache.flex.compiler.internal.codegen.js.JSPublisher;
 import org.apache.flex.compiler.internal.codegen.js.JSSharedData;
 import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogPublisher;
 import org.apache.flex.compiler.internal.driver.as.ASBackend;
-import org.apache.flex.compiler.internal.driver.js.JSBackend;
 import org.apache.flex.compiler.internal.driver.js.amd.AMDBackend;
 import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+import org.apache.flex.compiler.internal.driver.mxml.flexjs.MXMLFlexJSBackend;
 import org.apache.flex.compiler.internal.projects.CompilerProject;
 import org.apache.flex.compiler.internal.projects.FlexProject;
 import org.apache.flex.compiler.internal.projects.ISourceFileHandler;
@@ -155,7 +155,7 @@ public class MXMLJSC
                     backend = new AMDBackend();
                     break;
                 case FLEXJS:
-                    backend = new JSBackend();
+                    backend = new MXMLFlexJSBackend();
                     break;
                 case GOOG:
                     backend = new GoogBackend();
@@ -330,7 +330,10 @@ public class MXMLJSC
                         return false;
                 }
 
-                File outputFolder = null;
+                File outputFolder = new File(getOutputFilePath());
+                if (!outputFolder.isDirectory())
+                    outputFolder = outputFolder.getParentFile();
+                
                 // output type specific pre-compile actions
                 switch (jsOutputType)
                 {
@@ -341,7 +344,7 @@ public class MXMLJSC
                 }
 
                 case FLEXJS: {
-                    //
+                    // jsPublisher = new MXMLFlexJSPublisher(config);
 
                     break;
                 }
@@ -359,18 +362,19 @@ public class MXMLJSC
                 }
                 default: {
                     jsPublisher = new JSPublisher(config);
-
-                    outputFolder = new File(getOutputFilePath())
-                            .getParentFile();
                 }
                 }
 
+                if (!outputFolder.exists())
+                    outputFolder.mkdirs();
+
                 List<ICompilationUnit> reachableCompilationUnits = project
                         .getReachableCompilationUnitsInSWFOrder(ImmutableSet
                                 .of(mainCU));
                 for (final ICompilationUnit cu : reachableCompilationUnits)
                 {
-                    if (cu.getCompilationUnitType() == ICompilationUnit.UnitType.AS_UNIT)
+                    if (cu.getCompilationUnitType() == ICompilationUnit.UnitType.AS_UNIT
+                            || cu.getCompilationUnitType() == ICompilationUnit.UnitType.MXML_UNIT)
                     {
                         final File outputClassFile = getOutputClassFile(cu
                                 .getQualifiedNames().get(0), outputFolder);
@@ -415,7 +419,8 @@ public class MXMLJSC
                 }
                 }
 
-                jsPublisher.publish();
+                if (jsPublisher != null)
+                    jsPublisher.publish();
 
                 compilationSuccess = true;
             }
@@ -607,6 +612,10 @@ public class MXMLJSC
         // if (getTargetSettings() == null)
         //     return false;
 
+        ITargetSettings settings = getTargetSettings();
+        if (settings != null)
+            project.setTargetSettings(settings);
+
         target = JSSharedData.backend.createTarget(project,
                 getTargetSettings(), null);
 
@@ -708,8 +717,8 @@ public class MXMLJSC
             // Print version if "-version" is present.
             if (configBuffer.getVar("version") != null) //$NON-NLS-1$
             {
-                println(VersionInfo.buildMessage() + " ("
-                        + JSSharedData.COMPILER_VERSION + ")");
+                println(VersionInfo.buildMessage()
+                        + " (" + JSSharedData.COMPILER_VERSION + ")");
                 return false;
             }
             //

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/5085979e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java
index b155b72..f3d439f 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java
@@ -26,6 +26,7 @@ import org.apache.flex.compiler.codegen.mxml.IMXMLEmitter;
 import org.apache.flex.compiler.problems.ICompilerProblem;
 import org.apache.flex.compiler.projects.IASProject;
 import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IFileNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLArrayNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLBooleanNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLClassDefinitionNode;
@@ -44,6 +45,7 @@ import org.apache.flex.compiler.tree.mxml.IMXMLScriptNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLStringNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLStyleSpecifierNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLUintNode;
+import org.apache.flex.compiler.units.ICompilationUnit;
 import org.apache.flex.compiler.visitor.IASNodeStrategy;
 import org.apache.flex.compiler.visitor.IBlockWalker;
 import org.apache.flex.compiler.visitor.mxml.IMXMLBlockVisitor;
@@ -139,6 +141,23 @@ public class MXMLBlockWalker implements IMXMLBlockVisitor, IMXMLBlockWalker
             asStrategy.handle(node);
     }
 
+    @Override
+    public void visitCompilationUnit(ICompilationUnit unit)
+    {
+        debug("visitMXMLCompilationUnit()");
+        IFileNode node = null;
+        try
+        {
+            node = (IFileNode) unit.getSyntaxTreeRequest().get().getAST();
+        }
+        catch (InterruptedException e)
+        {
+            throw new RuntimeException(e);
+        }
+
+        walk(node);
+    }
+
     public MXMLBlockWalker(List<ICompilerProblem> errors, IASProject project,
             IMXMLEmitter mxmlEmitter, IASEmitter asEmitter,
             IBlockWalker asBlockWalker)

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/5085979e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLWriter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLWriter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLWriter.java
new file mode 100644
index 0000000..925d70d
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLWriter.java
@@ -0,0 +1,79 @@
+/*
+ *
+ *  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.compiler.internal.codegen.mxml;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.List;
+
+import org.apache.flex.compiler.codegen.as.IASEmitter;
+import org.apache.flex.compiler.codegen.mxml.IMXMLEmitter;
+import org.apache.flex.compiler.internal.codegen.js.JSFilterWriter;
+import org.apache.flex.compiler.internal.codegen.js.JSSharedData;
+import org.apache.flex.compiler.internal.codegen.js.JSWriter;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.projects.IASProject;
+import org.apache.flex.compiler.units.ICompilationUnit;
+import org.apache.flex.compiler.visitor.as.IASBlockWalker;
+import org.apache.flex.compiler.visitor.mxml.IMXMLBlockWalker;
+
+public class MXMLWriter extends JSWriter
+{
+    /**
+     * Create a JSApplication writer.
+     * 
+     * @param application the JSApplication model to be encoded
+     * @param useCompression use ZLIB compression if true
+     */
+    public MXMLWriter(IASProject project, List<ICompilerProblem> problems,
+            ICompilationUnit compilationUnit, boolean enableDebug)
+    {
+        super(project, problems, compilationUnit, enableDebug);
+    }
+
+    @Override
+    public void writeTo(OutputStream out)
+    {
+        JSFilterWriter writer = (JSFilterWriter) JSSharedData.backend
+                .createWriterBuffer(project);
+
+        IASEmitter asEmitter = JSSharedData.backend.createEmitter(writer);
+        IASBlockWalker asBlockWalker = JSSharedData.backend.createWalker(
+                project, problems, asEmitter);
+
+        IMXMLEmitter mxmlEmitter = JSSharedData.backend
+                .createMXMLEmitter(writer);
+        IMXMLBlockWalker mxmlBlockWalker = JSSharedData.backend.createMXMLWalker(
+                project, problems, mxmlEmitter, asEmitter, asBlockWalker);
+
+        mxmlBlockWalker.visitCompilationUnit(compilationUnit);
+
+        try
+        {
+            out.write(writer.toString().getBytes());
+        }
+        catch (IOException e)
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/5085979e/compiler.jx/src/org/apache/flex/compiler/internal/driver/mxml/MXMLSourceFileHandler.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/driver/mxml/MXMLSourceFileHandler.java
b/compiler.jx/src/org/apache/flex/compiler/internal/driver/mxml/MXMLSourceFileHandler.java
index 8e28e31..ef147b2 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/driver/mxml/MXMLSourceFileHandler.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/driver/mxml/MXMLSourceFileHandler.java
@@ -19,11 +19,11 @@
 
 package org.apache.flex.compiler.internal.driver.mxml;
 
-import org.apache.flex.compiler.internal.driver.js.JSCompilationUnit;
 import org.apache.flex.compiler.internal.projects.CompilerProject;
 import org.apache.flex.compiler.internal.projects.DefinitionPriority;
 import org.apache.flex.compiler.internal.projects.ISourceFileHandler;
 import org.apache.flex.compiler.internal.units.ASCompilationUnit;
+import org.apache.flex.compiler.internal.units.MXMLCompilationUnit;
 import org.apache.flex.compiler.units.ICompilationUnit;
 
 /**
@@ -61,7 +61,7 @@ public final class MXMLSourceFileHandler implements ISourceFileHandler
             String path, DefinitionPriority.BasePriority basePriority,
             int order, String qname, String locale)
     {
-        return new JSCompilationUnit(proj, path, basePriority, qname);
+        return new MXMLCompilationUnit(proj, path, basePriority, order, qname);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/5085979e/compiler.jx/src/org/apache/flex/compiler/internal/driver/mxml/flexjs/MXMLFlexJSBackend.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/driver/mxml/flexjs/MXMLFlexJSBackend.java
b/compiler.jx/src/org/apache/flex/compiler/internal/driver/mxml/flexjs/MXMLFlexJSBackend.java
index 375c80d..c8e396a 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/driver/mxml/flexjs/MXMLFlexJSBackend.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/driver/mxml/flexjs/MXMLFlexJSBackend.java
@@ -23,18 +23,23 @@ import java.io.FilterWriter;
 import java.util.List;
 
 import org.apache.flex.compiler.codegen.as.IASEmitter;
+import org.apache.flex.compiler.codegen.js.IJSWriter;
 import org.apache.flex.compiler.codegen.mxml.IMXMLEmitter;
+import org.apache.flex.compiler.config.Configurator;
 import org.apache.flex.compiler.driver.IBackend;
 import org.apache.flex.compiler.internal.codegen.as.ASEmitter;
 import org.apache.flex.compiler.internal.codegen.mxml.MXMLBlockWalker;
+import org.apache.flex.compiler.internal.codegen.mxml.MXMLWriter;
 import org.apache.flex.compiler.internal.codegen.mxml.flexjs.MXMLFlexJSBlockWalker;
 import org.apache.flex.compiler.internal.codegen.mxml.flexjs.MXMLFlexJSEmitter;
+import org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration;
 import org.apache.flex.compiler.internal.driver.mxml.MXMLBackend;
 import org.apache.flex.compiler.internal.visitor.as.ASNodeSwitch;
 import org.apache.flex.compiler.internal.visitor.mxml.MXMLNodeSwitch;
 import org.apache.flex.compiler.problems.ICompilerProblem;
 import org.apache.flex.compiler.projects.IASProject;
 import org.apache.flex.compiler.tree.mxml.IMXMLFileNode;
+import org.apache.flex.compiler.units.ICompilationUnit;
 import org.apache.flex.compiler.visitor.IBlockVisitor;
 import org.apache.flex.compiler.visitor.IBlockWalker;
 import org.apache.flex.compiler.visitor.mxml.IMXMLBlockWalker;
@@ -49,6 +54,12 @@ public class MXMLFlexJSBackend extends MXMLBackend
 {
 
     @Override
+    public Configurator createConfigurator()
+    {
+        return new Configurator(JSGoogConfiguration.class);
+    }
+
+    @Override
     public IMXMLEmitter createMXMLEmitter(FilterWriter out)
     {
         return new MXMLFlexJSEmitter(out);
@@ -78,4 +89,12 @@ public class MXMLFlexJSBackend extends MXMLBackend
         return new ASEmitter(out);
     }
 
+    @Override
+    public IJSWriter createWriter(IASProject project,
+            List<ICompilerProblem> problems, ICompilationUnit compilationUnit,
+            boolean enableDebug)
+    {
+        return new MXMLWriter(project, problems, compilationUnit, enableDebug);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/5085979e/compiler.jx/src/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java
b/compiler.jx/src/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java
index 8b68359..51a4e23 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java
@@ -26,6 +26,7 @@ import org.apache.flex.compiler.tree.mxml.IMXMLDeclarationsNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLDeferredInstanceNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLDocumentNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLEventSpecifierNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLFileNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLInstanceNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLIntNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLLiteralNode;
@@ -35,8 +36,8 @@ import org.apache.flex.compiler.tree.mxml.IMXMLScriptNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLStringNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLStyleSpecifierNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLUintNode;
-import org.apache.flex.compiler.visitor.IBlockVisitor;
 import org.apache.flex.compiler.visitor.IASNodeStrategy;
+import org.apache.flex.compiler.visitor.IBlockVisitor;
 import org.apache.flex.compiler.visitor.mxml.IMXMLBlockVisitor;
 
 /**
@@ -75,6 +76,9 @@ public class MXMLNodeSwitch implements IASNodeStrategy
         case MXMLEventSpecifierID:
             visitor.visitEventSpecifier((IMXMLEventSpecifierNode) node);
             break;
+        case MXMLFileID:
+            visitor.visitFile((IMXMLFileNode) node);
+            break;
         case MXMLIntID:
             visitor.visitInt((IMXMLIntNode) node);
             break;
@@ -118,7 +122,6 @@ public class MXMLNodeSwitch implements IASNodeStrategy
         case MXMLEmbedID:
         case MXMLEffectSpecifierID:
         case MXMLFactoryID:
-        case MXMLFileID:
         case MXMLFunctionID:
         case MXMLHTTPServiceID:
         case MXMLHTTPServiceRequestID:

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/5085979e/compiler.jx/src/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java
b/compiler.jx/src/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java
index 9a8ce9e..98c8958 100644
--- a/compiler.jx/src/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java
+++ b/compiler.jx/src/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java
@@ -36,6 +36,7 @@ import org.apache.flex.compiler.tree.mxml.IMXMLScriptNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLStringNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLStyleSpecifierNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLUintNode;
+import org.apache.flex.compiler.units.ICompilationUnit;
 import org.apache.flex.compiler.visitor.IBlockVisitor;
 
 /**
@@ -44,6 +45,11 @@ import org.apache.flex.compiler.visitor.IBlockVisitor;
  */
 public interface IMXMLBlockVisitor extends IBlockVisitor
 {
+
+    //--------------------------------------------------------------------------
+
+    void visitCompilationUnit(ICompilationUnit unit);
+
     void visitFile(IMXMLFileNode node);
 
     void visitDocument(IMXMLDocumentNode node);


Mime
View raw message