Added basic full compile implementation test for external compiler - For now, colsure-compiler repo needs to be checked out in the directory that flex-falcon exists in so the tests correctly get the externs file. - Everything else uses reletive paths, so it should work after you build and copy the compiler.jar from closure-compiler repo.
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/f164b451 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/f164b451 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/f164b451 Branch: refs/heads/develop Commit: f164b451872863c22bbe116213a6af4e6a7bcac9 Parents: fd2fb5b Author: Michael Schmalle <[email protected]> Authored: Tue Jun 9 17:09:42 2015 -0400 Committer: Michael Schmalle <[email protected]> Committed: Tue Jun 9 17:09:42 2015 -0400 ---------------------------------------------------------------------- .../codegen/externals/TestReferenceModel.java | 158 +++++++++++++++++++ .../test-files/externals/missing.js | 92 +++++++++++ .../externals/reference/ReferenceModel.java | 27 +++- 3 files changed, 270 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f164b451/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 new file mode 100644 index 0000000..446d60e --- /dev/null +++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestReferenceModel.java @@ -0,0 +1,158 @@ +/* + * + * 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; +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 + public void tearDown() + { + model = null; + } + + @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.addExternal(missingJS); + 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"); + + model.cleanOutput(); + model.compile(); + model.emit(); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f164b451/compiler.jx.tests/test-files/externals/missing.js ---------------------------------------------------------------------- diff --git a/compiler.jx.tests/test-files/externals/missing.js b/compiler.jx.tests/test-files/externals/missing.js new file mode 100644 index 0000000..c22c5f5 --- /dev/null +++ b/compiler.jx.tests/test-files/externals/missing.js @@ -0,0 +1,92 @@ +/* + * + * 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. + * + */ + + +// webkit_notifications +/** + * @constructor + */ +function ExtendableEvent() {} + +// HACK @enum page_visibility +/** + * @constructor + */ +function VisibilityState(description) {} + + +// chrome.js +/** + * @constructor + */ +function HTMLEmbedElement() {}; + +/** + * @type {!Window} + * @const + */ +var window; + +/** + * @constructor + */ +function Promise() {} + +/** + * @constructor + */ +function FontFaceSetLoadStatus() {} + +/** + * @constructor + */ +function FontFaceLoadStatus() {} + +/** + * @constructor + */ +function Navigator() {} + + +/** + * @constructor + */ +function Screen() {} + +/** + * @constructor + */ +function uint() {} + +/** + * @constructor + */ +function int() {} + +// gecko + +/** + * @constructor + */ +function History() {} + +/** + * @constructor + */ +function Location() {} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f164b451/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 60f4bea..df5510b 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 @@ -30,6 +30,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.flex.compiler.internal.codegen.externals.pass.AddMemberPass; import org.apache.flex.compiler.internal.codegen.externals.pass.CollectTypesPass; +import org.apache.flex.utils.FilenameNormalization; import com.google.common.collect.ImmutableList; import com.google.javascript.jscomp.CustomPassExecutionTime; @@ -45,7 +46,7 @@ public class ReferenceModel private static final List<SourceFile> EMPTY_EXTERNS = ImmutableList.of(SourceFile.fromCode( "externs", "")); - private File jsRoot; + //private File jsRoot; private File asRoot; private File asFunctionRoot; private File asConstantRoot; @@ -62,10 +63,10 @@ public class ReferenceModel private com.google.javascript.jscomp.Compiler compiler; - public void setJSRoot(File file) - { - this.jsRoot = file; - } + // public void setJSRoot(File file) + // { + // this.jsRoot = file; + // } public void setASRoot(File file) { @@ -105,12 +106,24 @@ public class ReferenceModel excludesClass.add(new ExcludedMemeber(className, null, "")); } - public void addExternal(String name) + public void addExternal(File file) throws IOException { - File file = new File(jsRoot, name + ".js"); + if (!file.exists()) + throw new IOException(file.getAbsolutePath() + " does not exist."); externals.add(new ExternalFile(file)); } + public void addExternal(String externalFile) throws IOException + { + addExternal(new File(FilenameNormalization.normalize(externalFile))); + } + + // public void addExternal(String name) + // { + // File file = new File(jsRoot, name + ".js"); + // externals.add(new ExternalFile(file)); + // } + public ClassReference getClassReference(String qualifiedName) { return classes.get(qualifiedName);
