flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mschma...@apache.org
Subject git commit: [flex-falcon] [refs/heads/develop] - Added Full parse/emit as/generate JS.swc/compile Main.as test - This test shows the full flow of creating external .as API from .js externs files, compiling the global JS.swc, loading the FlexJS backend an
Date Wed, 10 Jun 2015 11:49:39 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop c5b0bdf88 -> 35579f104


Added Full parse/emit as/generate JS.swc/compile Main.as test
- This test shows the full flow of creating external .as API from
.js externs files, compiling the global JS.swc, loading the FlexJS
backend and cross compiling the Main.as to Main_output.js using the
JS.swc and no player global, the test also shows that we are using
DOM API of the browser without a problem.


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

Branch: refs/heads/develop
Commit: 35579f104665e192902482a3824e11f19f61123c
Parents: c5b0bdf
Author: Michael Schmalle <mschmalle@apache.org>
Authored: Wed Jun 10 07:48:42 2015 -0400
Committer: Michael Schmalle <mschmalle@apache.org>
Committed: Wed Jun 10 07:48:42 2015 -0400

----------------------------------------------------------------------
 .../codegen/externals/CompilerArguments.java    | 408 +++++++++++++++++++
 .../codegen/externals/ExternalsTestUtils.java   | 129 ++++++
 .../externals/TestExternalsJSCompile.java       | 271 ++++++++++++
 .../codegen/externals/TestReferenceModel.java   | 119 +-----
 .../test-files/externals/app1/as_src/Main.as    |  34 ++
 .../externals/reference/ReferenceModel.java     |  10 +-
 6 files changed, 861 insertions(+), 110 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/35579f10/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/CompilerArguments.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/CompilerArguments.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/CompilerArguments.java
new file mode 100644
index 0000000..4631df8
--- /dev/null
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/CompilerArguments.java
@@ -0,0 +1,408 @@
+/***
+ * Copyright 2013 Teoti Graphix, LLC.
+ *
+ * Licensed 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.
+ *
+ *
+ * @author Michael Schmalle <mschmalle@teotigraphix.com>
+ */
+
+package org.apache.flex.compiler.internal.codegen.externals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Michael Schmalle
+ */
+public class CompilerArguments
+{
+    private List<String> bundles = new ArrayList<String>();
+
+    private List<String> libraries = new ArrayList<String>();
+
+    private List<String> sources = new ArrayList<String>();
+
+    private List<String> includes = new ArrayList<String>();
+
+    private String sdkPath = "";
+
+    private String appName = "";
+
+    private String output;
+
+    private String jsLibraryPath = "";
+
+    private String jsBasePath = "";
+
+    private Boolean jsOutputAsFiles = null;
+
+    //    private List<MergedFileSettings> jsMergedFiles = new ArrayList<MergedFileSettings>();
+
+    public void addBundlePath(String path)
+    {
+        if (bundles.contains(path))
+            return;
+        bundles.add(path);
+    }
+
+    public void addLibraryPath(String path)
+    {
+        if (libraries.contains(path))
+            return;
+        libraries.add(path);
+    }
+
+    public void addSourcepath(String path)
+    {
+        if (sources.contains(path))
+            return;
+        sources.add(path);
+    }
+
+    public void addIncludedSources(String path)
+    {
+        if (includes.contains(path))
+            return;
+        includes.add(path);
+    }
+
+    public List<String> getBundles()
+    {
+        return bundles;
+    }
+
+    public List<String> getLibraries()
+    {
+        return libraries;
+    }
+
+    public List<String> getSources()
+    {
+        return sources;
+    }
+
+    public List<String> getIncludes()
+    {
+        return includes;
+    }
+
+    public String getSDKPath()
+    {
+        return sdkPath;
+    }
+
+    public void setSDKPath(String value)
+    {
+        sdkPath = value;
+    }
+
+    public String getAppName()
+    {
+        return appName;
+    }
+
+    public void setAppName(String value)
+    {
+        appName = value;
+    }
+
+    public String getOutput()
+    {
+        return output;
+    }
+
+    public void setOutput(String path)
+    {
+        output = path;
+    }
+
+    public String getJsLibraryPath()
+    {
+        return jsLibraryPath;
+    }
+
+    public void setJsLibraryPath(String jsLibraryPath)
+    {
+        this.jsLibraryPath = jsLibraryPath;
+    }
+
+    public String getJsBasePath()
+    {
+        return jsBasePath;
+    }
+
+    public void setJsBasePath(String jsBasePath)
+    {
+        this.jsBasePath = jsBasePath;
+    }
+
+    public Boolean isJsOutputAsFiles()
+    {
+        return jsOutputAsFiles;
+    }
+
+    public void setJsOutputAsFiles(Boolean jsOutputAsFiles)
+    {
+        this.jsOutputAsFiles = jsOutputAsFiles;
+    }
+
+    //    public void addJsMergedFiles(MergedFileSettings setting)
+    //    {
+    //        jsMergedFiles.add(setting);
+    //    }
+
+    //--------------------------------------------------------------------------
+    // SWC
+    //--------------------------------------------------------------------------
+
+    private List<String> metadatas = new ArrayList<String>();
+
+    // -keep-as3-metadata
+    public List<String> getKeepMetadata()
+    {
+        return metadatas;
+    }
+
+    public void addKeepMetadata(String metadata)
+    {
+        if (metadatas.contains(metadata))
+            return;
+        metadatas.add(metadata);
+    }
+
+    //--------------------------------------------------------------------------
+    // Doc
+    //--------------------------------------------------------------------------
+
+    private List<String> docMembers = new ArrayList<String>();
+
+    private List<String> docNamespace = new ArrayList<String>();
+
+    private String mainTitle;
+
+    public String getMainTitle()
+    {
+        return mainTitle;
+    }
+
+    public void setMainTitle(String value)
+    {
+        mainTitle = value;
+    }
+
+    private String footer;
+
+    public String getFooter()
+    {
+        return footer;
+    }
+
+    public void setFooter(String value)
+    {
+        footer = value;
+    }
+
+    public void addDocMember(String member)
+    {
+        if (docMembers.contains(member))
+            return;
+        docMembers.add(member);
+    }
+
+    public void addDocNamespace(String namespace)
+    {
+        if (docNamespace.contains(namespace))
+            return;
+        docNamespace.add(namespace);
+    }
+
+    public void clear()
+    {
+        jsBasePath = "";
+        jsLibraryPath = "";
+        jsOutputAsFiles = false;
+        output = "";
+        clearLibraries();
+        clearSourcePaths();
+        includes.clear();
+        //        jsMergedFiles.clear();
+    }
+
+    public void clearSourcePaths()
+    {
+        sources = new ArrayList<String>();
+    }
+
+    public void clearBundles()
+    {
+        bundles = new ArrayList<String>();
+    }
+
+    public void clearLibraries()
+    {
+        libraries = new ArrayList<String>();
+    }
+
+    public List<String> toArguments()
+    {
+        List<String> result = new ArrayList<String>();
+
+        for (String arg : bundles)
+        {
+            result.add("-bundle-path=" + arg);
+        }
+
+        for (String arg : libraries)
+        {
+            result.add("-library-path=" + arg);
+        }
+
+        for (String arg : sources)
+        {
+            result.add("-source-path=" + arg);
+        }
+
+        if (includes.size() > 0)
+        {
+            result.add("-include-sources=" + join(includes, ","));
+        }
+        if (metadatas.size() > 0)
+        {
+            result.add("-keep-as3-metadata=" + join(metadatas, ","));
+        }
+
+        //        if (jsMergedFiles.size() > 0)
+        //        {
+        //            final StringBuilder sb = new StringBuilder();
+        //            for (MergedFileSettings setting : jsMergedFiles)
+        //            {
+        //                sb.append("-js-merged-file=");
+        //                sb.append(setting.getFileName());
+        //                sb.append(",");
+        //                sb.append(StringUtils.join(
+        //                        setting.getQualifiedNames().toArray(new String[] {}),
+        //                        ","));
+        //                result.add(sb.toString());
+        //                sb.setLength(0);
+        //            }
+        //        }
+
+        String sdk = getSDKPath();
+        if (sdk != null && !sdk.equals(""))
+            result.add("-sdk-path=" + sdk);
+
+        String name = getAppName();
+        if (name != null && !name.equals(""))
+            result.add("-app-name=" + name);
+
+        String base = getJsBasePath();
+        if (!base.equals(""))
+            result.add("-js-base-path=" + base);
+
+        String library = getJsLibraryPath();
+        if (!library.equals(""))
+            result.add("-js-library-path=" + library);
+
+        if (isJsOutputAsFiles() != null)
+        {
+            result.add("-js-classes-as-files="
+                    + (isJsOutputAsFiles() ? "true" : "false"));
+        }
+
+        result.add("-output=" + getOutput());
+
+        addArguments(result);
+
+        return result;
+    }
+
+    protected void addArguments(List<String> arguments)
+    {
+        String mainTitle = getMainTitle();
+        if (mainTitle != null && !mainTitle.equals(""))
+            arguments.add("-main-title=" + mainTitle);
+
+        if (footer != null && !footer.equals(""))
+            arguments.add("-footer=" + footer);
+
+        if (docMembers.size() > 0)
+        {
+            arguments.add("-doc-member=" + join(docMembers, ","));
+        }
+
+        if (docNamespace.size() > 0)
+        {
+            arguments.add("-doc-namespace=" + join(docNamespace, ","));
+        }
+    }
+
+    private String join(List<String> items, String separator)
+    {
+        StringBuilder sb = new StringBuilder();
+        int len = items.size();
+        int index = 0;
+        for (String item : items)
+        {
+            sb.append(item);
+            if (index < len)
+                sb.append(separator);
+            index++;
+        }
+        return sb.toString();
+    }
+
+    public static class CompilerArgument
+    {
+        private String name;
+
+        private String value;
+
+        CompilerArgument(String name, String value)
+        {
+            this.name = name;
+            this.value = value;
+        }
+
+        public String getValue()
+        {
+            return value;
+        }
+
+        public void setValue(String value)
+        {
+            this.value = value;
+        }
+
+        public String getName()
+        {
+            return name;
+        }
+
+        public void setName(String name)
+        {
+            this.name = name;
+        }
+
+        public static CompilerArgument create(String name, String value)
+        {
+            return new CompilerArgument(name, value);
+        }
+    }
+
+    @Override
+    public String toString()
+    {
+        return join(toArguments(), " ");
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/35579f10/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/ExternalsTestUtils.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/ExternalsTestUtils.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/ExternalsTestUtils.java
new file mode 100644
index 0000000..bd111b8
--- /dev/null
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/ExternalsTestUtils.java
@@ -0,0 +1,129 @@
+/*
+ *
+ *  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.externals;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.flex.compiler.internal.codegen.externals.reference.ReferenceModel;
+import org.apache.flex.utils.FilenameNormalization;
+
+public class ExternalsTestUtils
+{
+    public static File TEMP_DIR = new File(
+            FilenameNormalization.normalize("temp"));
+
+    // XXX missing.js is a temp location until we can figure out where it should placed in
the build
+    public static File MISSING_JS_FILE = FilenameNormalization.normalize(new File(
+            "test-files/externals/missing.js"));
+
+    public static File EXTERNAL_JS_DIR = FilenameNormalization.normalize(new File(
+            "../closure-compiler/externs"));
+
+    public static File AS_ROOT_DIR = new File(TEMP_DIR, "externals/as");
+
+    public static void addTestExcludesFull(ReferenceModel model)
+    {
+        model.addFieldExclude("Window", "focus");
+        model.addClassExclude("controlRange");
+
+        model.addExclude("Array", "toSource");
+        model.addExclude("Date", "valueOf");
+        model.addExclude("String", "valueOf");
+
+        model.addExclude("FontFaceSet", "delete");
+
+        model.addExclude("CSSStyleDeclaration", "cssText");
+        model.addExclude("CSSStyleRule", "style");
+        model.addExclude("CSSFontFaceRule", "style");
+        model.addExclude("CSSPageRule", "style");
+
+        model.addExclude("Generator", "throw");
+        model.addExclude("Generator", "return");
+        model.addExclude("HTMLMenuItemElement", "default");
+        model.addExclude("MessageEvent", "data"); // TODO returns T
+        model.addExclude("MessageEvent", "initMessageEventNS"); // TODO param T
+        model.addExclude("MessageEvent", "initMessageEvent"); // TODO param T
+        model.addExclude("MessageEvent", "default");
+        model.addExclude("Object", "is");
+        model.addExclude("Promise", "catch");
+
+        model.addExclude("IDBCursor", "continue");
+        model.addExclude("IDBCursor", "delete");
+        model.addExclude("IDBObjectStore", "delete");
+    }
+
+    public static void addTestExternalsFull(ReferenceModel model)
+            throws IOException
+    {
+        String coreRoot = ExternalsTestUtils.EXTERNAL_JS_DIR.getAbsolutePath();
+
+        model.addExternal(ExternalsTestUtils.MISSING_JS_FILE);
+        model.addExternal(coreRoot + "/es3.js");
+        model.addExternal(coreRoot + "/es5.js");
+        model.addExternal(coreRoot + "/es6.js");
+
+        model.addExternal(coreRoot + "/w3c_anim_timing.js");
+        model.addExternal(coreRoot + "/w3c_audio.js");
+        model.addExternal(coreRoot + "/w3c_batterystatus.js");
+        model.addExternal(coreRoot + "/w3c_css.js");
+        model.addExternal(coreRoot + "/w3c_css3d.js");
+        model.addExternal(coreRoot + "/w3c_device_sensor_event.js");
+        model.addExternal(coreRoot + "/w3c_dom1.js");
+        model.addExternal(coreRoot + "/w3c_dom2.js");
+        model.addExternal(coreRoot + "/w3c_dom3.js");
+        model.addExternal(coreRoot + "/w3c_elementtraversal.js");
+        model.addExternal(coreRoot + "/w3c_encoding.js");
+        model.addExternal(coreRoot + "/w3c_event.js");
+        model.addExternal(coreRoot + "/w3c_event3.js");
+        model.addExternal(coreRoot + "/w3c_geolocation.js");
+        model.addExternal(coreRoot + "/w3c_indexeddb.js");
+        model.addExternal(coreRoot + "/w3c_navigation_timing.js");
+        model.addExternal(coreRoot + "/w3c_range.js");
+        model.addExternal(coreRoot + "/w3c_rtc.js");
+        model.addExternal(coreRoot + "/w3c_selectors.js");
+        //model.addExternal(coreRoot + "/w3c_serviceworker.js");
+        //model.addExternal(coreRoot + "/w3c_webcrypto.js");
+        model.addExternal(coreRoot + "/w3c_xml.js");
+
+        //model.addExternal(coreRoot + "/fetchapi");
+
+        model.addExternal(coreRoot + "/window.js");
+
+        model.addExternal(coreRoot + "/ie_dom.js");
+        model.addExternal(coreRoot + "/gecko_dom.js");
+
+        model.addExternal(coreRoot + "/webkit_css.js");
+        model.addExternal(coreRoot + "/webkit_dom.js");
+        model.addExternal(coreRoot + "/webkit_event.js");
+        //model.addExternal(coreRoot + "/webkit_notifications.js");
+
+        model.addExternal(coreRoot + "/iphone.js");
+        model.addExternal(coreRoot + "/chrome.js");
+        model.addExternal(coreRoot + "/flash.js");
+
+        model.addExternal(coreRoot + "/page_visibility.js");
+        model.addExternal(coreRoot + "/fileapi.js");
+        model.addExternal(coreRoot + "/html5.js");
+
+        model.addExternal(coreRoot + "/webgl.js");
+        model.addExternal(coreRoot + "/webstorage.js");
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/35579f10/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternalsJSCompile.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternalsJSCompile.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternalsJSCompile.java
new file mode 100644
index 0000000..a868ab8
--- /dev/null
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternalsJSCompile.java
@@ -0,0 +1,271 @@
+/*
+ *
+ *  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.externals;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.flex.compiler.clients.COMPC;
+import org.apache.flex.compiler.codegen.as.IASEmitter;
+import org.apache.flex.compiler.config.Configurator;
+import org.apache.flex.compiler.internal.codegen.as.ASFilterWriter;
+import org.apache.flex.compiler.internal.codegen.externals.reference.ReferenceModel;
+import org.apache.flex.compiler.internal.driver.js.flexjs.FlexJSBackend;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.internal.projects.FlexProjectConfigurator;
+import org.apache.flex.compiler.internal.targets.JSTarget;
+import org.apache.flex.compiler.internal.workspaces.Workspace;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.units.ICompilationUnit;
+import org.apache.flex.compiler.visitor.as.IASBlockWalker;
+import org.apache.flex.utils.FilenameNormalization;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+
+public class TestExternalsJSCompile
+{
+    private static File tempDir = new File(
+            FilenameNormalization.normalize("temp"));
+
+    private static File app1ASSrcDir = new File(
+            FilenameNormalization.normalize("test-files/externals/app1/as_src"));
+
+    private static File app1AJSSrcDir = new File(
+            FilenameNormalization.normalize("temp/externals/app1/js_src"));
+
+    private static File jsSWCFile = new File(
+            FilenameNormalization.normalize("temp/externals/bin/JS.swc"));
+
+    private ReferenceModel model;
+
+    protected static Workspace workspace = new Workspace();
+    protected FlexJSProject project;
+    private ArrayList<ICompilerProblem> errors;
+
+    private FlexJSBackend backend;
+    //private IJSEmitter emitter;
+    //private IASBlockWalker walker;
+    //private JSFilterWriter writer;
+
+    private ArrayList<File> sourcePaths;
+    private ArrayList<File> libraries;
+
+    @Before
+    public void setUp()
+    {
+        backend = new FlexJSBackend();
+        model = new ReferenceModel();
+
+        if (project == null)
+            project = new FlexJSProject(workspace);
+        FlexProjectConfigurator.configure(project);
+
+        backend = new FlexJSBackend();
+        //writer = backend.createWriterBuffer(project);
+        //emitter = backend.createEmitter(writer);
+        //walker = backend.createWalker(project, errors, emitter);
+
+        sourcePaths = new ArrayList<File>();
+        libraries = new ArrayList<File>();
+
+        FileUtils.deleteQuietly(jsSWCFile);
+        FileUtils.deleteQuietly(app1AJSSrcDir);
+    }
+
+    @After
+    public void tearDown()
+    {
+        model = null;
+    }
+
+    @Test
+    public void test_full_compile() throws IOException
+    {
+        model.setASRoot(ExternalsTestUtils.AS_ROOT_DIR);
+
+        ExternalsTestUtils.addTestExcludesFull(model);
+        ExternalsTestUtils.addTestExternalsFull(model);
+
+        model.cleanOutput();
+        model.compile();
+        model.emit();
+
+        compileSWC();
+        assertTrue(jsSWCFile.exists());
+
+        compileProject("Main", app1ASSrcDir.getAbsolutePath());
+
+        assertTrue(new File(app1AJSSrcDir, "Main_output.js").exists());
+    }
+
+    private boolean compileSWC()
+    {
+        CompilerArguments arguments = new CompilerArguments();
+        configureCOMPCCompiler(arguments);
+
+        COMPC compc = new COMPC();
+
+        final String[] args = arguments.toArguments().toArray(new String[] {});
+        @SuppressWarnings("unused")
+        int code = compc.mainNoExit(args);
+
+        @SuppressWarnings("unused")
+        List<ICompilerProblem> problems = compc.getProblems().getProblems();
+        //getProblemQuery().addAll(problems);
+        if (compc.getProblems().hasErrors())
+            return false;
+
+        return true;
+    }
+
+    protected List<String> compileProject(String inputFileName,
+            String inputDirName)
+    {
+        List<String> compiledFileNames = new ArrayList<String>();
+
+        String mainFileName = inputDirName + File.separator + inputFileName
+                + ".as";
+
+        addDependencies();
+
+        ICompilationUnit mainCU = Iterables.getOnlyElement(workspace.getCompilationUnits(
+                FilenameNormalization.normalize(mainFileName), project));
+
+        if (project instanceof FlexJSProject)
+            project.mainCU = mainCU;
+
+        Configurator projectConfigurator = backend.createConfigurator();
+
+        JSTarget target = backend.createTarget(project,
+                projectConfigurator.getTargetSettings(null), null);
+
+        target.build(mainCU, new ArrayList<ICompilerProblem>());
+
+        List<ICompilationUnit> reachableCompilationUnits = project.getReachableCompilationUnitsInSWFOrder(ImmutableSet.of(mainCU));
+        for (final ICompilationUnit cu : reachableCompilationUnits)
+        {
+            try
+            {
+                ICompilationUnit.UnitType cuType = cu.getCompilationUnitType();
+
+                if (cuType == ICompilationUnit.UnitType.AS_UNIT
+                        || cuType == ICompilationUnit.UnitType.MXML_UNIT)
+                {
+                    File outputRootDir = new File(
+                            FilenameNormalization.normalize(tempDir
+                                    + File.separator + inputDirName));
+
+                    String qname = cu.getQualifiedNames().get(0);
+
+                    compiledFileNames.add(qname.replace(".", "/"));
+
+                    final File outputClassFile = getOutputClassFile(qname
+                            + "_output", outputRootDir);
+
+                    System.out.println(outputClassFile);
+
+                    ASFilterWriter writer = backend.createWriterBuffer(project);
+                    IASEmitter emitter = backend.createEmitter(writer);
+                    IASBlockWalker walker = backend.createWalker(project,
+                            errors, emitter);
+
+                    walker.visitCompilationUnit(cu);
+
+                    System.out.println(writer.toString());
+
+                    BufferedOutputStream out = new BufferedOutputStream(
+                            new FileOutputStream(outputClassFile));
+
+                    out.write(writer.toString().getBytes());
+                    out.flush();
+                    out.close();
+                }
+            }
+            catch (Exception e)
+            {
+                //System.out.println(e.getMessage());
+                e.printStackTrace();
+            }
+        }
+
+        return compiledFileNames;
+    }
+
+    private void configureCOMPCCompiler(CompilerArguments arguments)
+    {
+        arguments.setOutput(jsSWCFile.getAbsolutePath());
+
+        File root = ExternalsTestUtils.AS_ROOT_DIR.getParentFile();
+        File classes = new File(root, "as");
+        File constants = new File(root, "as_constants");
+        File functions = new File(root, "as_functions");
+
+        arguments.addSourcepath(classes.getAbsolutePath());
+        arguments.addSourcepath(constants.getAbsolutePath());
+        arguments.addSourcepath(functions.getAbsolutePath());
+
+        arguments.addIncludedSources(classes.getAbsolutePath());
+        arguments.addIncludedSources(constants.getAbsolutePath());
+        arguments.addIncludedSources(functions.getAbsolutePath());
+    }
+
+    protected File getOutputClassFile(String qname, File outputFolder)
+    {
+        File baseDir = app1AJSSrcDir;
+
+        String[] cname = qname.split("\\.");
+        String sdirPath = baseDir.getAbsolutePath() + File.separator;
+        if (cname.length > 0)
+        {
+            for (int i = 0, n = cname.length - 1; i < n; i++)
+            {
+                sdirPath += cname[i] + File.separator;
+            }
+
+            File sdir = new File(sdirPath);
+            if (!sdir.exists())
+                sdir.mkdirs();
+
+            qname = cname[cname.length - 1];
+        }
+
+        return new File(sdirPath + qname + "." + backend.getOutputExtension());
+    }
+
+    private void addDependencies()
+    {
+        libraries.add(jsSWCFile);
+        sourcePaths.add(app1ASSrcDir);
+
+        project.setSourcePath(sourcePaths);
+        project.setLibraries(libraries);
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/35579f10/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestReferenceModel.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestReferenceModel.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestReferenceModel.java
index 88dcaef..e83979e 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestReferenceModel.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestReferenceModel.java
@@ -19,43 +19,25 @@
 
 package org.apache.flex.compiler.internal.codegen.externals;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import java.io.File;
 import java.io.IOException;
 
 import org.apache.flex.compiler.internal.codegen.externals.reference.ReferenceModel;
-import org.apache.flex.utils.FilenameNormalization;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
 public class TestReferenceModel
 {
-    private static File tempDir = new File(
-            FilenameNormalization.normalize("temp"));
-
-    // XXX missing.js is a temp location until we can figure out where it should placed in
the build
-    private File missingJS;
-    // Checkout closure-compiler git repo and place it as a sibling directory next to flex-falcon
-    // Run the build.xml file in closure-compiler and copy that compiler.jar and replace
with
-    // the one existing in this project's lib directory.
-    private File externsJS;
-    
-    @SuppressWarnings("unused")
-    private String jsroot;
-    private File asroot = new File(tempDir, "externals/as");
-
     private ReferenceModel model;
 
     @Before
     public void setUp()
     {
         model = new ReferenceModel();
-        
-        missingJS = FilenameNormalization.normalize(new File("test-files/externals/missing.js"));
-        // C:\Users\Teoti\Documents\ApacheFlex\git\closure-compiler
-        // Where
-        // C:\Users\Teoti\Documents\ApacheFlex\git\flex-falcon\compiler.jx.tests
-        externsJS = FilenameNormalization.normalize(new File("../closure-compiler/externs"));
     }
 
     @After
@@ -67,92 +49,25 @@ public class TestReferenceModel
     @Test
     public void test_full_compile() throws IOException
     {
-        model.addFieldExclude("Window", "focus");
-        model.addClassExclude("controlRange");
-
-        model.addExclude("Array", "toSource");
-        model.addExclude("Date", "valueOf");
-        model.addExclude("String", "valueOf");
-
-        model.addExclude("FontFaceSet", "delete");
-
-        model.addExclude("CSSStyleDeclaration", "cssText");
-        model.addExclude("CSSStyleRule", "style");
-        model.addExclude("CSSFontFaceRule", "style");
-        model.addExclude("CSSPageRule", "style");
-
-        model.addExclude("Generator", "throw");
-        model.addExclude("Generator", "return");
-        model.addExclude("HTMLMenuItemElement", "default");
-        model.addExclude("MessageEvent", "data"); // TODO returns T
-        model.addExclude("MessageEvent", "initMessageEventNS"); // TODO param T
-        model.addExclude("MessageEvent", "initMessageEvent"); // TODO param T
-        model.addExclude("MessageEvent", "default");
-        model.addExclude("Object", "is");
-        model.addExclude("Promise", "catch");
-
-        model.addExclude("IDBCursor", "continue");
-        model.addExclude("IDBCursor", "delete");
-        model.addExclude("IDBObjectStore", "delete");
-
-        //model.setJSRoot(new File(jsroot));
-        model.setASRoot(asroot);
-
-        String coreRoot = externsJS.getAbsolutePath();
+        model.setASRoot(ExternalsTestUtils.AS_ROOT_DIR);
 
-        model.addExternal(missingJS);
-        model.addExternal(coreRoot + "/es3.js");
-        model.addExternal(coreRoot + "/es5.js");
-        model.addExternal(coreRoot + "/es6.js");
+        ExternalsTestUtils.addTestExcludesFull(model);
+        ExternalsTestUtils.addTestExternalsFull(model);
 
-        model.addExternal(coreRoot + "/w3c_anim_timing.js");
-        model.addExternal(coreRoot + "/w3c_audio.js");
-        model.addExternal(coreRoot + "/w3c_batterystatus.js");
-        model.addExternal(coreRoot + "/w3c_css.js");
-        model.addExternal(coreRoot + "/w3c_css3d.js");
-        model.addExternal(coreRoot + "/w3c_device_sensor_event.js");
-        model.addExternal(coreRoot + "/w3c_dom1.js");
-        model.addExternal(coreRoot + "/w3c_dom2.js");
-        model.addExternal(coreRoot + "/w3c_dom3.js");
-        model.addExternal(coreRoot + "/w3c_elementtraversal.js");
-        model.addExternal(coreRoot + "/w3c_encoding.js");
-        model.addExternal(coreRoot + "/w3c_event.js");
-        model.addExternal(coreRoot + "/w3c_event3.js");
-        model.addExternal(coreRoot + "/w3c_geolocation.js");
-        model.addExternal(coreRoot + "/w3c_indexeddb.js");
-        model.addExternal(coreRoot + "/w3c_navigation_timing.js");
-        model.addExternal(coreRoot + "/w3c_range.js");
-        model.addExternal(coreRoot + "/w3c_rtc.js");
-        model.addExternal(coreRoot + "/w3c_selectors.js");
-        //model.addExternal(coreRoot + "/w3c_serviceworker.js");
-        //model.addExternal(coreRoot + "/w3c_webcrypto.js");
-        model.addExternal(coreRoot + "/w3c_xml.js");
-
-        //model.addExternal(coreRoot + "/fetchapi");
-
-        model.addExternal(coreRoot + "/window.js");
-
-        model.addExternal(coreRoot + "/ie_dom.js");
-        model.addExternal(coreRoot + "/gecko_dom.js");
-
-        model.addExternal(coreRoot + "/webkit_css.js");
-        model.addExternal(coreRoot + "/webkit_dom.js");
-        model.addExternal(coreRoot + "/webkit_event.js");
-        //model.addExternal(coreRoot + "/webkit_notifications.js");
-
-        model.addExternal(coreRoot + "/iphone.js");
-        model.addExternal(coreRoot + "/chrome.js");
-        model.addExternal(coreRoot + "/flash.js");
-
-        model.addExternal(coreRoot + "/page_visibility.js");
-        model.addExternal(coreRoot + "/fileapi.js");
-        model.addExternal(coreRoot + "/html5.js");
+        model.cleanOutput();
 
-        model.addExternal(coreRoot + "/webgl.js");
-        model.addExternal(coreRoot + "/webstorage.js");
+        // TODO (mschmalle) this root needs to create 'classes' in the root and move 
+        // constants and functions up into it aside classes
+        assertFalse(ExternalsTestUtils.AS_ROOT_DIR.exists());
 
-        model.cleanOutput();
+        // TODO (mschmalle) get warnings and errors from the closure compiler
         model.compile();
+
         model.emit();
+
+        File root = ExternalsTestUtils.AS_ROOT_DIR.getParentFile();
+        assertTrue(new File(root, "as").exists());
+        assertTrue(new File(root, "as_constants").exists());
+        assertTrue(new File(root, "as_functions").exists());
     }
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/35579f10/compiler.jx.tests/test-files/externals/app1/as_src/Main.as
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/externals/app1/as_src/Main.as b/compiler.jx.tests/test-files/externals/app1/as_src/Main.as
new file mode 100644
index 0000000..b57d9d7
--- /dev/null
+++ b/compiler.jx.tests/test-files/externals/app1/as_src/Main.as
@@ -0,0 +1,34 @@
+/*
+ *
+ *  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
+{
+public class Main
+{
+	public function start():void
+	{
+		var element:Element = document.createElement("button");
+        element.onclick = function ():void {
+            alert("Hello browser from FalconJX!");
+        };
+        button.textContent = "Say Hello";
+        document.body.appendChild(button);
+	}
+}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/35579f10/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ReferenceModel.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ReferenceModel.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ReferenceModel.java
index e385b4b..ccceab0 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ReferenceModel.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ReferenceModel.java
@@ -46,7 +46,6 @@ public class ReferenceModel
     private static final List<SourceFile> EMPTY_EXTERNS = ImmutableList.of(SourceFile.fromCode(
             "externs", ""));
 
-    //private File jsRoot;
     private File asRoot;
     private File asFunctionRoot;
     private File asConstantRoot;
@@ -57,17 +56,11 @@ public class ReferenceModel
     private List<ExternalFile> externals = new ArrayList<ExternalFile>();
 
     private HashMap<String, ClassReference> classes = new HashMap<String, ClassReference>();
-    //private HashMap<String, ClassReference2> interfaces = new HashMap<String,
ClassReference2>();
     private HashMap<String, FunctionReference> functions = new HashMap<String, FunctionReference>();
     private HashMap<String, ConstantReference> constants = new HashMap<String, ConstantReference>();
 
     private com.google.javascript.jscomp.Compiler compiler;
 
-    //    public void setJSRoot(File file)
-    //    {
-    //        this.jsRoot = file;
-    //    }
-
     public void setASRoot(File file)
     {
         this.asRoot = file;
@@ -233,11 +226,12 @@ public class ReferenceModel
     public void cleanOutput() throws IOException
     {
         FileUtils.deleteDirectory(asRoot);
-        asRoot.mkdirs();
     }
 
     public void emit() throws IOException
     {
+        asRoot.mkdirs();
+
         for (Entry<String, ClassReference> set : classes.entrySet())
         {
             StringBuilder sb = new StringBuilder();


Mime
View raw message