http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3724c2ff/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/vf2js/MXMLVF2JSPublisher.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/vf2js/MXMLVF2JSPublisher.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/vf2js/MXMLVF2JSPublisher.java deleted file mode 100644 index 164806c..0000000 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/vf2js/MXMLVF2JSPublisher.java +++ /dev/null @@ -1,600 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.apache.flex.compiler.internal.codegen.mxml.vf2js; - -import java.io.*; -import java.net.URL; -import java.util.*; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.io.filefilter.DirectoryFileFilter; -import org.apache.commons.io.filefilter.FileFileFilter; -import org.apache.commons.io.filefilter.FileFilterUtils; -import org.apache.commons.io.filefilter.IOFileFilter; -import org.apache.commons.io.filefilter.RegexFileFilter; -import org.apache.flex.compiler.clients.problems.ProblemQuery; -import org.apache.flex.compiler.codegen.js.IJSPublisher; -import org.apache.flex.compiler.config.Configuration; -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.js.flexjs.JSCSSCompilationSession; -import org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration; -import org.apache.flex.compiler.internal.graph.VF2JSDepsWriter; -import org.apache.flex.compiler.internal.projects.FlexJSProject; -import org.apache.flex.compiler.utils.VF2JSClosureCompilerWrapper; - -public class MXMLVF2JSPublisher extends JSGoogPublisher implements - IJSPublisher -{ - - public static final String FLEXJS_OUTPUT_DIR_NAME = "bin"; - public static final String FLEXJS_INTERMEDIATE_DIR_NAME = "js-debug"; - public static final String FLEXJS_RELEASE_DIR_NAME = "js-release"; - - class DependencyRecord - { - String path; - String deps; - String line; - int lineNumber; - } - - class DependencyLineComparator implements Comparator<DependencyRecord> { - @Override - public int compare(DependencyRecord o1, DependencyRecord o2) { - return new Integer(o1.lineNumber).compareTo(o2.lineNumber); - } - } - - public MXMLVF2JSPublisher(Configuration config, FlexJSProject project) - { - super(config); - - this.isMarmotinniRun = ((JSGoogConfiguration) configuration) - .getMarmotinni() != null; - this.outputPathParameter = configuration.getOutput(); - this.useStrictPublishing = ((JSGoogConfiguration) configuration) - .getStrictPublish(); - - this.project = project; - } - - private FlexJSProject project; - - private boolean isMarmotinniRun; - private String outputPathParameter; - private boolean useStrictPublishing; - - @Override - public File getOutputFolder() - { - // (erikdebruin) - If there is a -marmotinni switch, we want - // the output redirected to the directory it specifies. - // - If there is an -output switch, use that path as the - // output parent folder. - if (isMarmotinniRun) - { - outputParentFolder = new File( - ((JSGoogConfiguration) configuration).getMarmotinni()); - } - else if (outputPathParameter != null) - { - outputParentFolder = new File(outputPathParameter); - // FB usually specified -output <project-path>/bin-release/app.swf - if (outputPathParameter.contains(".swf")) - outputParentFolder = outputParentFolder.getParentFile().getParentFile(); - } - else - { - outputParentFolder = new File( - configuration.getTargetFileDirectory()).getParentFile(); - } - - outputParentFolder = new File(outputParentFolder, - FLEXJS_OUTPUT_DIR_NAME); - - outputFolder = new File(outputParentFolder, File.separator - + FLEXJS_INTERMEDIATE_DIR_NAME); - - // (erikdebruin) Marmotinni handles file management, so we - // bypass the setup. - if (!isMarmotinniRun) - setupOutputFolder(); - - return outputFolder; - } - - @Override - public boolean publish(ProblemQuery problems) throws IOException - { - boolean ok; - boolean subsetGoog = true; - - final String intermediateDirPath = outputFolder.getPath(); - final File intermediateDir = new File(intermediateDirPath); - File srcDir = new File(configuration.getTargetFile()); - srcDir = srcDir.getParentFile(); - - final String projectName = FilenameUtils.getBaseName(configuration - .getTargetFile()); - final String outputFileName = projectName - + "." + JSSharedData.OUTPUT_EXTENSION; - - File releaseDir = new File(outputParentFolder, FLEXJS_RELEASE_DIR_NAME); - final String releaseDirPath = releaseDir.getPath(); - - if (!isMarmotinniRun) - { - if (releaseDir.exists()) - org.apache.commons.io.FileUtils.deleteQuietly(releaseDir); - - releaseDir.mkdirs(); - } - - // If the closure-lib parameter is empty we'll try to find the resources - // in the classpath, dump its content to the output directory and use this - // as closure-lib parameter. - final String closureLibDirPath; - if(((JSGoogConfiguration) configuration).isClosureLibSet()) { - closureLibDirPath = ((JSGoogConfiguration) configuration).getClosureLib(); - } else { - // Check if the "goog/deps.js" is available in the classpath. - URL resource = Thread.currentThread().getContextClassLoader().getResource("goog/deps.js"); - if(resource != null) { - File closureLibDir = new File(intermediateDir.getParent(), "closure"); - - // Only create and dump the content, if the directory does not exists. - if(!closureLibDir.exists()) { - if(!closureLibDir.mkdirs()) { - throw new IOException( - "Unable to create directory for closure-lib at " + closureLibDir.getAbsolutePath()); - } - - // Strip the url of the parts we don't need. - // Unless we are not using some insanely complex setup - // the resource will always be on the same machine. - String resourceJarPath = resource.getFile(); - if(resourceJarPath.contains(":")) { - resourceJarPath = resourceJarPath.substring(resourceJarPath.lastIndexOf(":") + 1); - } - if(resourceJarPath.contains("!")) { - resourceJarPath = resourceJarPath.substring(0, resourceJarPath.indexOf("!")); - } - File resourceJar = new File(resourceJarPath); - - // Dump the closure lib from classpath. - dumpJar(resourceJar, closureLibDir); - } - // The compiler automatically adds a "closure" to the lib dir path, - // so we omit this here. - closureLibDirPath = intermediateDir.getParentFile().getPath(); - } - // Fallback to the default. - else { - closureLibDirPath = ((JSGoogConfiguration) configuration).getClosureLib(); - } - } - - final String closureGoogSrcLibDirPath = closureLibDirPath - + "/closure/goog/"; - final String closureGoogTgtLibDirPath = intermediateDirPath - + "/library/closure/goog"; - final String depsSrcFilePath = intermediateDirPath - + "/library/closure/goog/deps.js"; - final String depsTgtFilePath = intermediateDirPath + "/deps.js"; - final String projectIntermediateJSFilePath = intermediateDirPath - + File.separator + outputFileName; - final String projectReleaseJSFilePath = releaseDirPath - + File.separator + outputFileName; - - appendExportSymbol(projectIntermediateJSFilePath, projectName); - appendEncodedCSS(projectIntermediateJSFilePath, projectName); - - if (!subsetGoog) - { - // (erikdebruin) We need to leave the 'goog' files and dependencies well - // enough alone. We copy the entire library over so the - // 'goog' dependencies will resolve without our help. - FileUtils.copyDirectory(new File(closureGoogSrcLibDirPath), new File(closureGoogTgtLibDirPath)); - } - - VF2JSClosureCompilerWrapper compilerWrapper = new VF2JSClosureCompilerWrapper(); - - VF2JSDepsWriter gdw = new VF2JSDepsWriter(intermediateDir, projectName, (JSGoogConfiguration) configuration); - try - { - StringBuilder depsFileData = new StringBuilder(); - ok = gdw.generateDeps(problems, depsFileData); - if (!subsetGoog) - { - writeFile(depsTgtFilePath, depsFileData.toString(), false); - } - else - { - String s = depsFileData.toString(); - int c = s.indexOf("'goog."); - ArrayList<String> googreqs = new ArrayList<String>(); - while (c != -1) - { - int c2 = s.indexOf("'", c + 1); - String googreq = s.substring(c, c2 + 1); - googreqs.add(googreq); - c = s.indexOf("'goog.", c2); - } - HashMap<String, DependencyRecord> defmap = new HashMap<String, DependencyRecord>(); - // read in goog's deps.js - FileInputStream fis = new FileInputStream(closureGoogSrcLibDirPath + "/deps.js"); - Scanner scanner = new Scanner(fis, "UTF-8"); - String addDependency = "goog.addDependency('"; - int currentLine = 0; - while (scanner.hasNextLine()) - { - String googline = scanner.nextLine(); - if (googline.indexOf(addDependency) == 0) - { - int c1 = googline.indexOf("'", addDependency.length() + 1); - String googpath = googline.substring(addDependency.length(), c1); - String googdefs = googline.substring(googline.indexOf("[") + 1, googline.indexOf("]")); - String googdeps = googline.substring(googline.lastIndexOf("[") + 1, googline.lastIndexOf("]")); - String[] thedefs = googdefs.split(","); - DependencyRecord deprec = new DependencyRecord(); - deprec.path = googpath; - deprec.deps = googdeps; - deprec.line = googline; - deprec.lineNumber = currentLine; - for (String def : thedefs) - { - def = def.trim(); - defmap.put(def, deprec); - } - } - currentLine++; - } - // (erikdebruin) Prevent 'Resource leak' warning on line 212: - scanner.close(); - ArrayList<DependencyRecord> subsetdeps = new ArrayList<DependencyRecord>(); - HashMap<String, String> gotgoog = new HashMap<String, String>(); - for (String req : googreqs) - { - DependencyRecord deprec = defmap.get(req); - // if we've already processed this file, skip - if (!gotgoog.containsKey(deprec.path)) - { - gotgoog.put(deprec.path, null); - subsetdeps.add(deprec); - addDeps(subsetdeps, gotgoog, defmap, deprec.deps); - } - } - // now we should have the subset of files we need in the order needed - StringBuilder sb = new StringBuilder(); - sb.append("goog.addDependency('base.js', ['goog'], []);\n"); - File file = new File(closureGoogSrcLibDirPath + "/base.js"); - FileUtils.copyFileToDirectory(file, new File(closureGoogTgtLibDirPath)); - compilerWrapper.addJSSourceFile(file.getCanonicalPath()); - Collections.sort(subsetdeps, new DependencyLineComparator()); - for (DependencyRecord subsetdeprec : subsetdeps) - { - sb.append(subsetdeprec.line).append("\n"); - } - writeFile(depsTgtFilePath, sb.toString() + depsFileData.toString(), false); - // copy the required files - for (String googfn : gotgoog.keySet()) - { - file = new File(closureGoogSrcLibDirPath + File.separator + googfn); - String dir = closureGoogTgtLibDirPath; - if (googfn.contains("/")) - { - dir += File.separator + googfn.substring(0, googfn.lastIndexOf("/")); - } - FileUtils.copyFileToDirectory(file, new File(dir)); - compilerWrapper.addJSSourceFile(file.getCanonicalPath()); - } - } - } - catch (InterruptedException e) - { - e.printStackTrace(); - return false; - } - - IOFileFilter pngSuffixFilter = FileFilterUtils.and(FileFileFilter.FILE, - FileFilterUtils.suffixFileFilter(".png")); - IOFileFilter gifSuffixFilter = FileFilterUtils.and(FileFileFilter.FILE, - FileFilterUtils.suffixFileFilter(".gif")); - IOFileFilter jpgSuffixFilter = FileFilterUtils.and(FileFileFilter.FILE, - FileFilterUtils.suffixFileFilter(".jpg")); - IOFileFilter assetFiles = FileFilterUtils.or(pngSuffixFilter, - jpgSuffixFilter, gifSuffixFilter); - - FileUtils.copyDirectory(srcDir, intermediateDir, assetFiles); - FileUtils.copyDirectory(srcDir, releaseDir, assetFiles); - - File srcDeps = new File(depsSrcFilePath); - - // ToDo (erikdebruin): yeah, right, hard coded the path, nice! - File sdkDepsFile = new File("/Users/erik/Documents/ApacheFlex/git/flex-asjs/vf2js/frameworks/js/sdk-deps.js"); - if (sdkDepsFile.exists()) - FileUtils.copyFile(sdkDepsFile, new File(intermediateDirPath + File.separator + "sdk-deps.js")); - - writeHTML("intermediate", projectName, intermediateDirPath, gdw.additionalHTML); - writeHTML("release", projectName, releaseDirPath, gdw.additionalHTML); - writeCSS(projectName, intermediateDirPath); - writeCSS(projectName, releaseDirPath); - - if (!subsetGoog) - { - // (erikdebruin) add 'goog' files - Collection<File> files = org.apache.commons.io.FileUtils.listFiles(new File( - closureGoogTgtLibDirPath), new RegexFileFilter("^.*(\\.js)"), - DirectoryFileFilter.DIRECTORY); - for (File file : files) - { - compilerWrapper.addJSSourceFile(file.getCanonicalPath()); - } - } - - // (erikdebruin) add project files - for (String filePath : gdw.filePathsInOrder) - { - compilerWrapper.addJSSourceFile( - new File(filePath).getCanonicalPath()); - } - - compilerWrapper.setOptions( - projectReleaseJSFilePath, useStrictPublishing); - - // (erikdebruin) Include the 'goog' deps to allow the compiler to resolve - // dependencies. - compilerWrapper.addJSSourceFile( - closureGoogSrcLibDirPath + File.separator + "deps.js"); - - List<String> externs = ((JSGoogConfiguration)configuration).getExternalJSLib(); - for (String extern : externs) - { - compilerWrapper.addJSExternsFile(extern); - } - - compilerWrapper.targetFilePath = projectReleaseJSFilePath; - compilerWrapper.compile(); - - appendSourceMapLocation(projectReleaseJSFilePath, projectName); - - if (!isMarmotinniRun) - { - String allDeps = ""; - if (!subsetGoog) - allDeps += FileUtils.readFileToString(srcDeps); - allDeps += FileUtils.readFileToString(new File(depsTgtFilePath)); - - FileUtils.writeStringToFile(srcDeps, allDeps); - - org.apache.commons.io.FileUtils.deleteQuietly(new File(depsTgtFilePath)); - } - - if (ok) - System.out.println("The project '" - + projectName - + "' has been successfully compiled and optimized."); - - return true; - } - - private void addDeps(ArrayList<DependencyRecord> subsetdeps, HashMap<String, String> gotgoog, - HashMap<String, DependencyRecord> defmap, String deps) - { - if (deps.length() == 0) - return; - - String[] deplist = deps.split(","); - for (String dep : deplist) - { - dep = dep.trim(); - DependencyRecord deprec = defmap.get(dep); - if (!gotgoog.containsKey(deprec.path)) - { - gotgoog.put(deprec.path, null); - // put addDependencyLine in subset file - subsetdeps.add(deprec); - addDeps(subsetdeps, gotgoog, defmap, deprec.deps); - } - } - } - - private void appendExportSymbol(String path, String projectName) - throws IOException - { - StringBuilder appendString = new StringBuilder(); - appendString - .append("\n\n// Ensures the symbol will be visible after compiler renaming.\n"); - appendString.append("goog.exportSymbol('"); - appendString.append(projectName); - appendString.append("', "); - appendString.append(projectName); - appendString.append(");\n"); - writeFile(path, appendString.toString(), true); - } - - private void appendEncodedCSS(String path, String projectName) - throws IOException - { - StringBuilder appendString = new StringBuilder(); - appendString.append("\n\n"); - appendString.append(projectName); - appendString.append(".prototype.cssData = ["); - JSCSSCompilationSession cssSession = (JSCSSCompilationSession) project.getCSSCompilationSession(); - String s = cssSession.getEncodedCSS(); - int reqidx = s.indexOf("goog.require"); - if (reqidx != -1) - { - String reqs = s.substring(reqidx); - s = s.substring(0, reqidx - 1); - String fileData = readCode(new File(path)); - reqidx = fileData.indexOf("goog.require"); - String after = fileData.substring(reqidx); - String before = fileData.substring(0, reqidx - 1); - s = before + reqs + after + appendString.toString() + s; - writeFile(path, s, false); - } - else - { - appendString.append(s); - writeFile(path, appendString.toString(), true); - } - } - - protected String readCode(File file) - { - String code = ""; - try - { - BufferedReader in = new BufferedReader(new InputStreamReader( - new FileInputStream(file), "UTF8")); - - String line = in.readLine(); - - while (line != null) - { - code += line + "\n"; - line = in.readLine(); - } - code = code.substring(0, code.length() - 1); - - in.close(); - } - catch (Exception e) - { - // nothing to see, move along... - } - - return code; - } - - private void writeHTML(String type, String projectName, String dirPath, List<String> additionalHTML) - throws IOException - { - StringBuilder htmlFile = new StringBuilder(); - htmlFile.append("<!DOCTYPE html>\n"); - htmlFile.append("<html>\n"); - htmlFile.append("<head>\n"); - htmlFile.append("\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\n"); - htmlFile.append("\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"); - htmlFile.append("\t<link rel=\"stylesheet\" type=\"text/css\" href=\""); - htmlFile.append(projectName); - htmlFile.append(".css\">\n"); - - for (String s : additionalHTML) - htmlFile.append(s).append("\n"); - - if ("intermediate".equals(type)) - { - htmlFile.append("\t<script type=\"text/javascript\" src=\"./library/closure/goog/base.js\"></script>\n"); - htmlFile.append("\t<script type=\"text/javascript\" src=\"./sdk-deps.js\"></script>\n"); - htmlFile.append("\t<script type=\"text/javascript\">\n"); - //htmlFile.append("\t\tgoog.require('mx.styles.StyleProtoChain');\n"); - htmlFile.append("\t\tgoog.require('mx.managers.SystemManager');\n"); - htmlFile.append("\t\tgoog.require('mx.managers.systemClasses.ChildManager');\n"); - //htmlFile.append("\t\tgoog.require('" + projectName + "');\n"); - htmlFile.append("\t</script>\n"); - } - else - { - htmlFile.append("\t<script type=\"text/javascript\" src=\"./"); - htmlFile.append(projectName); - htmlFile.append(".js\"></script>\n"); - } - - htmlFile.append("</head>\n"); - htmlFile.append("<body onload=\"init();\">\n"); - htmlFile.append("\t<script type=\"text/javascript\">\n"); - htmlFile.append("\t\t'use strict';\n"); - htmlFile.append("\t\t\n"); - htmlFile.append("\t\tfunction init() {\n"); - htmlFile.append("\t\t\tvar /** @type {flash.display.LoaderInfo} */ loaderInfo,\n"); - htmlFile.append("\t\t\t /** @type {flash.display.Stage} */ stage,\n"); - htmlFile.append("\t\t\t /** @type {mx.managers.SystemManager} */ systemManager,\n"); - htmlFile.append("\t\t\t /** @type {mx.managers.systemClasses.ChildManager} */ childManager;\n"); - htmlFile.append("\t\t\t\n"); - htmlFile.append("\t\t\tstage = new flash.display.Stage();\n"); - htmlFile.append("\t\t\twindow['apache-flex_stage'] = stage;\n"); - htmlFile.append("\t\t\t\n"); - htmlFile.append("\t\t\twindow['apache-flex_loaderInfo'] = new flash.display.LoaderInfo();\n"); - htmlFile.append("\t\t\twindow['apache-flex_loaderInfo'].get_parameters = function () {\n"); - htmlFile.append("\t\t\t\tvar /** @type {Object} */ infoObject;\n"); - htmlFile.append("\t\t\t\n"); - htmlFile.append("\t\t\t infoObject = {};\n"); - htmlFile.append("\t\t\t infoObject[\"resourceModuleURLs\"] = '';\n"); - htmlFile.append("\t\t\t \n"); - htmlFile.append("\t\t\t return infoObject;\n"); - htmlFile.append("\t\t\t}\n"); - htmlFile.append("\t\t\t\n"); - htmlFile.append("\t\t\tsystemManager = new mx.managers.SystemManager();\n"); - htmlFile.append("\t\t\tsystemManager.info = function () {\n"); - htmlFile.append("\t\t\t\tvar /** @type {Object} */ infoObject;\n"); - htmlFile.append("\t\t\t\n"); - htmlFile.append("\t\t\t infoObject = {};\n"); - htmlFile.append("\t\t\t infoObject[\"applicationDPI\"] = '';\n"); - htmlFile.append("\t\t\t infoObject[\"backgroundAlpha\"] = '';\n"); - htmlFile.append("\t\t\t infoObject[\"backgroundColor\"] = '';\n"); - htmlFile.append("\t\t\t infoObject[\"backgroundImage\"] = '';\n"); - htmlFile.append("\t\t\t infoObject[\"backgroundSize\"] = '';\n"); - htmlFile.append("\t\t\t infoObject[\"cdRsls\"] = '';\n"); - htmlFile.append("\t\t\t infoObject[\"compiledLocales\"] = '';\n"); - htmlFile.append("\t\t\t infoObject[\"compiledResourceBundleNames\"] = '';\n"); - htmlFile.append("\t\t\t infoObject[\"currentDomain\"] = new flash.system.ApplicationDomain();\n"); - htmlFile.append("\t\t\t infoObject[\"fonts\"] = '';\n"); - htmlFile.append("\t\t\t infoObject[\"frames\"] = '';\n"); - htmlFile.append("\t\t\t infoObject[\"mainClassName\"] = '").append(projectName).append("';\n"); - htmlFile.append("\t\t\t infoObject[\"mixins\"] = '';\n"); - htmlFile.append("\t\t\t infoObject[\"preloader\"] = new mx.preloaders.DownloadProgressBar();\n"); - htmlFile.append("\t\t\t infoObject[\"rsls\"] = '';\n"); - htmlFile.append("\t\t\t infoObject[\"runtimeDPIProvider\"] = new mx.core.RuntimeDPIProvider();\n"); - htmlFile.append("\t\t\t infoObject[\"useNativeDragManager\"] = '';\n"); - htmlFile.append("\t\t\t infoObject[\"usePreloader\"] = false; // we're not showing a preloader in JS\n"); - htmlFile.append("\t\t\t \n"); - htmlFile.append("\t\t\t return infoObject;\n"); - htmlFile.append("\t\t\t}\n"); - htmlFile.append("\t\t\t\n"); - htmlFile.append("\t\t\tchildManager = new mx.managers.systemClasses.ChildManager(systemManager);\n"); - htmlFile.append("\t\t\t\n"); - htmlFile.append("\t\t\tmx.managers.DragManagerImpl.sm = window['apache-flex_system-manager'];\n"); - htmlFile.append("\t\t\t\n"); - htmlFile.append("\t\t\tmx.core.FlexGlobals.topLevelApplication = {};\n"); - htmlFile.append("\t\t\t\n"); - htmlFile.append("\t\t\twindow['apache-flex_loaderInfo'].dispatchEvent(new flash.events.Event(flash.events.Event.INIT));\n"); - htmlFile.append("\t\t}\n"); - htmlFile.append("\t</script>\n"); - htmlFile.append("</body>\n"); - htmlFile.append("</html>"); - - writeFile(dirPath + File.separator + "index.html", htmlFile.toString(), - false); - } - - private void writeCSS(String projectName, String dirPath) - throws IOException - { - StringBuilder cssFile = new StringBuilder(); - JSCSSCompilationSession cssSession = (JSCSSCompilationSession) project.getCSSCompilationSession(); - cssFile.append(cssSession.emitCSS()); - - writeFile(dirPath + File.separator + projectName + ".css", - cssFile.toString(), false); - } -}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3724c2ff/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/vf2js/JSVF2JSConfiguration.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/vf2js/JSVF2JSConfiguration.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/vf2js/JSVF2JSConfiguration.java deleted file mode 100644 index ae620f7..0000000 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/vf2js/JSVF2JSConfiguration.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.flex.compiler.internal.driver.js.vf2js; - -import java.util.List; - -import org.apache.flex.compiler.clients.MXMLJSC; -import org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration; - -/** - * The {@link JSVF2JSConfiguration} class holds all compiler arguments needed for - * compiling ActionScript to JavaScript the 'goog' way. - * <p> - * Specific flags are implemented here for the configuration to be loaded by the - * configure() method of {@link MXMLJSC}. - * <p> - * This class inherits all compiler arguments from the MXMLC compiler. - * - * @author Erik de Bruin - */ -public class JSVF2JSConfiguration extends JSGoogConfiguration -{ - public JSVF2JSConfiguration() - { - } - - // - // 'closure-lib' - // - - @Override - public String getClosureLib() - { - try - { - if (closureLib.equals("")) - { - closureLib = getAbsolutePathFromPathRelativeToMXMLC( - "../lib/google/closure-library"); - } - } - catch (Exception e) { /* better to try and fail... */ } - - return closureLib; - } - - // - // 'sdk-js-lib' - // - - @Override - public List<String> getSDKJSLib() - { - if (sdkJSLib.size() == 0) - { - try - { - String path = getAbsolutePathFromPathRelativeToMXMLC( - "../../../../frameworks/js/vf2js/src"); - - sdkJSLib.add(path); - } - catch (Exception e) { /* better to try and fail... */ } - } - - return sdkJSLib; - } - -} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3724c2ff/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/vf2js/VF2JSBackend.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/vf2js/VF2JSBackend.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/vf2js/VF2JSBackend.java deleted file mode 100644 index d0030fe..0000000 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/vf2js/VF2JSBackend.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.flex.compiler.internal.driver.js.vf2js; - -import java.io.FilterWriter; - -import org.apache.flex.compiler.codegen.js.IJSEmitter; -import org.apache.flex.compiler.internal.codegen.js.vf2js.JSVF2JSEmitter; -import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend; -import org.apache.flex.compiler.internal.targets.FlexJSTarget; -import org.apache.flex.compiler.internal.targets.JSTarget; -import org.apache.flex.compiler.projects.IASProject; -import org.apache.flex.compiler.targets.ITargetProgressMonitor; -import org.apache.flex.compiler.targets.ITargetSettings; - -/** - * @author Erik de Bruin - */ -public class VF2JSBackend extends GoogBackend -{ - - @Override - public IJSEmitter createEmitter(FilterWriter out) - { - IJSEmitter emitter = new JSVF2JSEmitter(out); - emitter.setDocEmitter(createDocEmitter(emitter)); - return emitter; - } - - @Override - public JSTarget createTarget(IASProject project, ITargetSettings settings, - ITargetProgressMonitor monitor) - { - return new FlexJSTarget(project, settings, monitor); - } - - -} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3724c2ff/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/mxml/vf2js/MXMLVF2JSBackend.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/mxml/vf2js/MXMLVF2JSBackend.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/mxml/vf2js/MXMLVF2JSBackend.java deleted file mode 100644 index f69d499..0000000 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/mxml/vf2js/MXMLVF2JSBackend.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.flex.compiler.internal.driver.mxml.vf2js; - -import java.io.FilterWriter; -import java.util.List; - -import org.apache.flex.compiler.codegen.IDocEmitter; -import org.apache.flex.compiler.codegen.as.IASEmitter; -import org.apache.flex.compiler.codegen.js.IJSEmitter; -import org.apache.flex.compiler.codegen.js.IJSWriter; -import org.apache.flex.compiler.codegen.mxml.IMXMLEmitter; -import org.apache.flex.compiler.config.Configuration; -import org.apache.flex.compiler.config.Configurator; -import org.apache.flex.compiler.driver.IBackend; -import org.apache.flex.compiler.driver.IPublisher; -import org.apache.flex.compiler.internal.codegen.js.vf2js.JSVF2JSDocEmitter; -import org.apache.flex.compiler.internal.codegen.js.vf2js.JSVF2JSEmitter; -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.vf2js.MXMLVF2JSEmitter; -import org.apache.flex.compiler.internal.codegen.mxml.vf2js.MXMLVF2JSPublisher; -import org.apache.flex.compiler.internal.driver.js.vf2js.JSVF2JSConfiguration; -import org.apache.flex.compiler.internal.driver.mxml.MXMLBackend; -import org.apache.flex.compiler.internal.projects.FlexJSProject; -import org.apache.flex.compiler.internal.targets.FlexJSTarget; -import org.apache.flex.compiler.internal.targets.JSTarget; -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.targets.ITargetProgressMonitor; -import org.apache.flex.compiler.targets.ITargetSettings; -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; - -/** - * A concrete implementation of the {@link IBackend} API where the - * {@link MXMLBlockWalker} is used to traverse the {@link IMXMLFileNode} AST. - * - * @author Erik de Bruin - */ -public class MXMLVF2JSBackend extends MXMLBackend -{ - - @Override - public Configurator createConfigurator() - { - return new Configurator(JSVF2JSConfiguration.class); - } - - @Override - public IMXMLEmitter createMXMLEmitter(FilterWriter out) - { - return new MXMLVF2JSEmitter(out); - } - - @Override - public IMXMLBlockWalker createMXMLWalker(IASProject project, - List<ICompilerProblem> errors, IMXMLEmitter mxmlEmitter, - IASEmitter asEmitter, IBlockWalker asBlockWalker) - { - MXMLBlockWalker walker = new MXMLFlexJSBlockWalker(errors, project, - mxmlEmitter, asEmitter, asBlockWalker); - - ASNodeSwitch asStrategy = new ASNodeSwitch( - (IBlockVisitor) asBlockWalker); - walker.setASStrategy(asStrategy); - - MXMLNodeSwitch mxmlStrategy = new MXMLNodeSwitch(walker); - walker.setMXMLStrategy(mxmlStrategy); - - return walker; - } - - @Override - public IDocEmitter createDocEmitter(IASEmitter emitter) - { - return new JSVF2JSDocEmitter((IJSEmitter) emitter); - } - - @Override - public IJSEmitter createEmitter(FilterWriter out) - { - IJSEmitter emitter = new JSVF2JSEmitter(out); - emitter.setDocEmitter(createDocEmitter(emitter)); - return emitter; - } - - @Override - public IJSWriter createMXMLWriter(IASProject project, - List<ICompilerProblem> problems, ICompilationUnit compilationUnit, - boolean enableDebug) - { - return new MXMLWriter(project, problems, compilationUnit, enableDebug); - } - - @Override - public JSTarget createTarget(IASProject project, ITargetSettings settings, - ITargetProgressMonitor monitor) - { - return new FlexJSTarget(project, settings, monitor); - } - - @Override - public IPublisher createPublisher(IASProject project, - List<ICompilerProblem> errors, Configuration config) - { - return new MXMLVF2JSPublisher(config, (FlexJSProject) project); - } -} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3724c2ff/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/mxml/vf2js/MXMLVF2JSSWCBackend.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/mxml/vf2js/MXMLVF2JSSWCBackend.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/mxml/vf2js/MXMLVF2JSSWCBackend.java deleted file mode 100644 index f9390fc..0000000 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/mxml/vf2js/MXMLVF2JSSWCBackend.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.flex.compiler.internal.driver.mxml.vf2js; - -import java.io.FilterWriter; -import java.util.List; - -import org.apache.flex.compiler.codegen.IDocEmitter; -import org.apache.flex.compiler.codegen.as.IASEmitter; -import org.apache.flex.compiler.codegen.js.IJSEmitter; -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.js.vf2js.JSVF2JSDocEmitter; -import org.apache.flex.compiler.internal.codegen.js.vf2js.JSVF2JSEmitter; -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.vf2js.MXMLVF2JSEmitter; -import org.apache.flex.compiler.internal.driver.js.vf2js.JSVF2JSConfiguration; -import org.apache.flex.compiler.internal.driver.mxml.MXMLBackend; -import org.apache.flex.compiler.internal.targets.FlexJSSWCTarget; -import org.apache.flex.compiler.internal.targets.JSTarget; -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.targets.ITargetProgressMonitor; -import org.apache.flex.compiler.targets.ITargetSettings; -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; - -/** - * A concrete implementation of the {@link IBackend} API where the - * {@link MXMLBlockWalker} is used to traverse the {@link IMXMLFileNode} AST. - * - * @author Erik de Bruin - */ -public class MXMLVF2JSSWCBackend extends MXMLBackend -{ - - @Override - public Configurator createConfigurator() - { - return new Configurator(JSVF2JSConfiguration.class); - } - - @Override - public IMXMLEmitter createMXMLEmitter(FilterWriter out) - { - return new MXMLVF2JSEmitter(out); - } - - @Override - public IMXMLBlockWalker createMXMLWalker(IASProject project, - List<ICompilerProblem> errors, IMXMLEmitter mxmlEmitter, - IASEmitter asEmitter, IBlockWalker asBlockWalker) - { - MXMLBlockWalker walker = new MXMLFlexJSBlockWalker(errors, project, - mxmlEmitter, asEmitter, asBlockWalker); - - ASNodeSwitch asStrategy = new ASNodeSwitch( - (IBlockVisitor) asBlockWalker); - walker.setASStrategy(asStrategy); - - MXMLNodeSwitch mxmlStrategy = new MXMLNodeSwitch(walker); - walker.setMXMLStrategy(mxmlStrategy); - - return walker; - } - - @Override - public IDocEmitter createDocEmitter(IASEmitter emitter) - { - return new JSVF2JSDocEmitter((IJSEmitter) emitter); - } - - @Override - public IJSEmitter createEmitter(FilterWriter out) - { - IJSEmitter emitter = new JSVF2JSEmitter(out); - emitter.setDocEmitter(createDocEmitter(emitter)); - return emitter; - } - - @Override - public IJSWriter createMXMLWriter(IASProject project, - List<ICompilerProblem> problems, ICompilationUnit compilationUnit, - boolean enableDebug) - { - return new MXMLWriter(project, problems, compilationUnit, enableDebug); - } - - @Override - public JSTarget createTarget(IASProject project, ITargetSettings settings, - ITargetProgressMonitor monitor) - { - return new FlexJSSWCTarget(project, settings, monitor); - } -} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3724c2ff/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/VF2JSDepsWriter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/VF2JSDepsWriter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/VF2JSDepsWriter.java deleted file mode 100644 index 4d625d4..0000000 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/VF2JSDepsWriter.java +++ /dev/null @@ -1,406 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.apache.flex.compiler.internal.graph; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Scanner; - -import org.apache.commons.io.FileUtils; -import org.apache.flex.compiler.clients.problems.ProblemQuery; -import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens; -import org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration; -import org.apache.flex.compiler.problems.FileNotFoundProblem; - -import com.google.common.io.Files; - -public class VF2JSDepsWriter { - - public VF2JSDepsWriter(File outputFolder, String mainClassName, JSGoogConfiguration config) - { - this.outputFolderPath = outputFolder.getAbsolutePath(); - this.mainName = mainClassName; - otherPaths = config.getSDKJSLib(); - } - - private ProblemQuery problems; - private String outputFolderPath; - private String mainName; - private List<String> otherPaths; - private boolean problemsFound = false; - - private HashMap<String,GoogDep> depMap = new HashMap<String,GoogDep>(); - - public ArrayList<String> getListOfFiles() throws InterruptedException - { - buildDB(); - ArrayList<GoogDep> dps = sort(mainName); - ArrayList<String> files = new ArrayList<String>(); - for (GoogDep gd : dps) - { - files.add(gd.filePath); - } - return files; - } - - public boolean generateDeps(ProblemQuery problems, StringBuilder depsFileData) - throws InterruptedException, FileNotFoundException - { - problemsFound = false; - this.problems = problems; - buildDB(); - ArrayList<GoogDep> dps = sort(mainName); - String outString = "// generated by FalconJS" + "\n"; - int n = dps.size(); - for (int i = n - 1; i >= 0; i--) - { - GoogDep gd = dps.get(i); - if (!isGoogClass(gd.className)) - { - String s = "goog.addDependency('"; - s += relativePath(gd.filePath); - s += "', ['"; - s += gd.className; - s += "'], ["; - s += getDependencies(gd.deps); - s += "]);\n"; - outString += s; - } - } - depsFileData.append(outString); - return !problemsFound; - } - - private boolean isGoogClass(String className) - { - return className.startsWith("goog."); - } - - private void buildDB() - { - addDeps(mainName); - } - - public ArrayList<String> filePathsInOrder = new ArrayList<String>(); - - public ArrayList<String> additionalHTML = new ArrayList<String>(); - - private HashMap<String, GoogDep> visited = new HashMap<String, GoogDep>(); - - private ArrayList<GoogDep> sort(String rootClassName) - { - ArrayList<GoogDep> arr = new ArrayList<GoogDep>(); - GoogDep current = depMap.get(rootClassName); - sortFunction(current, arr); - return arr; - } - - private void sortFunction(GoogDep current, ArrayList<GoogDep> arr) - { - visited.put(current.className, current); - - filePathsInOrder.add(current.filePath); - System.out.println("Dependencies calculated for '" + current.filePath + "'"); - - ArrayList<String> deps = current.deps; - for (String className : deps) - { - if (!visited.containsKey(className) && !isGoogClass(className)) - { - GoogDep gd = depMap.get(className); - sortFunction(gd, arr); - } - } - arr.add(current); - } - - private void addDeps(String className) - { - if (depMap.containsKey(className) || isGoogClass(className)) - return; - - // build goog dependency list - GoogDep gd = new GoogDep(); - gd.className = className; - gd.filePath = getFilePath(className); - depMap.put(gd.className, gd); - ArrayList<String> deps = getDirectDependencies(gd.filePath); - - gd.deps = new ArrayList<String>(); - ArrayList<String> circulars = new ArrayList<String>(); - for (String dep : deps) - { - if (depMap.containsKey(dep) && !isGoogClass(dep)) - { - circulars.add(dep); - continue; - } - gd.deps.add(dep); - } - for (String dep : deps) - { - addDeps(dep); - } - if (circulars.size() > 0) - { - // remove requires that would cause circularity - try - { - List<String> fileLines = Files.readLines(new File(gd.filePath), - Charset.defaultCharset()); - ArrayList<String> finalLines = new ArrayList<String>(); - - //String inherits = getBaseClass(fileLines, className); - - for (String line : fileLines) - { - int c = line.indexOf("goog.require"); - if (c > -1) - { - int c2 = line.indexOf(")"); - String s = line.substring(c + 14, c2 - 1); - if (circulars.contains(s) /* && !s.equals(inherits) */ ) - continue; - } - finalLines.add(line); - } - File file = new File(gd.filePath); - PrintWriter out = new PrintWriter(new FileWriter(file)); - for (String s : finalLines) - { - out.println(s); - } - out.close(); - - } - catch (IOException e) - { - e.printStackTrace(); - } - - } - } - - String getBaseClass(List<String> lines, String className) - { - int n = lines.size(); - for (int i = 0; i < n; i++) - { - String line = lines.get(i); - int c2; - int c = line.indexOf("goog.inherits"); - if (c > -1) - { - String inheritLine = ""; - while (true) - { - inheritLine += line; - c2 = line.indexOf(")"); - if (c2 > -1) - break; - else - { - i++; - line = lines.get(i); - } - } - c = inheritLine.indexOf(","); - c2 = inheritLine.indexOf(")"); - return inheritLine.substring(c + 1, c2).trim(); - } - } - return null; - } - - String getFilePath(String className) - { - String fn; - File destFile; - File f; - - String classPath = className.replace(".", File.separator); - - fn = outputFolderPath + File.separator + classPath + ".js"; - f = new File(fn); - if (f.exists()) - { - return fn; - } - - for (String otherPath : otherPaths) - { - fn = otherPath + File.separator + classPath + ".js"; - f = new File(fn); - if (f.exists()) - { - fn = outputFolderPath + File.separator + classPath + ".js"; - destFile = new File(fn); - // copy source to output - try { - FileUtils.copyFile(f, destFile); - - // (erikdebruin) copy class assets files - if (className.indexOf("org.apache.flex") > -1) - { - File assetsDir = new File(f.getParentFile(), "assets"); - if (assetsDir.exists()) - { - String nameOfClass = className.substring(className.lastIndexOf('.') + 1); - - File[] assetsList = assetsDir.listFiles(); - for (int i = 0; i < assetsList.length; i++) - { - File assetFile = assetsList[i]; - String assetFileName = assetFile.getName(); - - if (assetFile.isFile() && assetFileName.indexOf(nameOfClass) == 0) - { - String pathOfClass = ""; - pathOfClass = className.substring(0, className.lastIndexOf('.')); - pathOfClass = pathOfClass.replace(".", File.separator); - - destFile = new File(outputFolderPath + - File.separator + pathOfClass + - File.separator + "assets" + - File.separator + assetFileName); - FileUtils.copyFile(assetFile, destFile); - - destFile = new File(outputFolderPath.replace("js-debug", "js-release") + - File.separator + pathOfClass + - File.separator + "assets" + - File.separator + assetFileName); - FileUtils.copyFile(assetFile, destFile); - - System.out.println("Copied assets of the '" + nameOfClass + "' class"); - } - } - } - } - } catch (IOException e) { - System.out.println("Error copying file for class: " + className); - } - return fn; - } - } - - System.out.println("Could not find file for class: " + className); - problems.add(new FileNotFoundProblem(className)); - problemsFound = true; - return ""; - } - - private ArrayList<String> getDirectDependencies(String fn) - { - ArrayList<String> deps = new ArrayList<String>(); - - FileInputStream fis; - try { - fis = new FileInputStream(fn); - Scanner scanner = new Scanner(fis, "UTF-8"); - boolean inInjectHTML = false; - while (scanner.hasNextLine()) - { - String s = scanner.nextLine(); - if (s.indexOf("goog.inherits") > -1) - break; - if (inInjectHTML) - { - int c = s.indexOf("</inject_html>"); - if (c > -1) - { - inInjectHTML = false; - continue; - } - } - if (inInjectHTML) - { - additionalHTML.add(s); - continue; - } - int c = s.indexOf(JSGoogEmitterTokens.GOOG_REQUIRE.getToken()); - if (c > -1) - { - int c2 = s.indexOf(")"); - s = s.substring(c + 14, c2 - 1); - deps.add(s); - } - c = s.indexOf("<inject_html>"); - if (c > -1) - { - inInjectHTML = true; - } - } - scanner.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - return deps; - } - - private String getDependencies(ArrayList<String> deps) - { - String s = ""; - for (String dep : deps) - { - if (s.length() > 0) - { - s += ", "; - } - s += "'" + dep + "'"; - } - return s; - } - - String relativePath(String path) - { - if (path.indexOf(outputFolderPath) == 0) - { - path = path.replace(outputFolderPath, "../../.."); - } - else - { - for (String otherPath : otherPaths) - { - if (path.indexOf(otherPath) == 0) - { - path = path.replace(otherPath, "../../.."); - - } - } - } - // paths are actually URIs and always have forward slashes - path = path.replace('\\', '/'); - return path; - } - private class GoogDep - { - public String filePath; - public String className; - public ArrayList<String> deps; - - } -} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3724c2ff/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java index fa372fd..b462568 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java @@ -23,6 +23,7 @@ import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.logging.Level; @@ -54,8 +55,7 @@ public class JSClosureCompilerWrapper if (s.contains(" ")) { String[] parts = s.split(" "); - for (String part : parts) - splitArgs.add(part); + Collections.addAll(splitArgs, parts); } else splitArgs.add(s); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3724c2ff/compiler-jx/src/main/java/org/apache/flex/compiler/utils/VF2JSClosureCompilerWrapper.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/VF2JSClosureCompilerWrapper.java b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/VF2JSClosureCompilerWrapper.java deleted file mode 100644 index f1240e4..0000000 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/VF2JSClosureCompilerWrapper.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.flex.compiler.utils; - -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.logging.Level; - -import com.google.javascript.jscomp.CheckLevel; -import com.google.javascript.jscomp.CommandLineRunner; -import com.google.javascript.jscomp.CompilationLevel; -import com.google.javascript.jscomp.Compiler; -import com.google.javascript.jscomp.CompilerOptions; -import com.google.javascript.jscomp.DiagnosticGroups; -import com.google.javascript.jscomp.SourceFile; -import com.google.javascript.jscomp.SourceMap; -import com.google.javascript.jscomp.WarningLevel; -import com.google.javascript.rhino.Node; -import com.google.javascript.rhino.Token; - -public class VF2JSClosureCompilerWrapper -{ - - public VF2JSClosureCompilerWrapper() - { - Compiler.setLoggingLevel(Level.ALL); - - compiler_ = new Compiler(); - - options_ = new CompilerOptions(); - initOptions(); - - jsExternsFiles_ = new ArrayList<SourceFile>(); - initExterns(); - - jsSourceFiles_ = new ArrayList<SourceFile>(); - } - - private Compiler compiler_; - private CompilerOptions options_; - private List<SourceFile> jsExternsFiles_; - private List<SourceFile> jsSourceFiles_; - - public String targetFilePath; - - public void addJSExternsFile(String fileName) - { - addJSExternsFile(SourceFile.fromFile(fileName)); - } - - public void addJSExternsFile(SourceFile file) - { - jsExternsFiles_.add(file); - } - - public void addJSSourceFile(String fileName) - { - jsSourceFiles_.add(SourceFile.fromFile(fileName)); - } - - public void compile() - { - compiler_.compile(jsExternsFiles_, jsSourceFiles_, options_); - - try - { - FileWriter targetFile = new FileWriter(targetFilePath); - targetFile.write(compiler_.toSource()); - targetFile.close(); - - FileWriter sourceMapFile = new FileWriter(options_.sourceMapOutputPath); - compiler_.getSourceMap().appendTo(sourceMapFile, ""); - sourceMapFile.close(); - } - catch (IOException error) - { - System.out.println(error); - } - } - - @SuppressWarnings( "deprecation" ) - private void initExterns() - { - try - { - List<SourceFile> defaultExterns = CommandLineRunner.getDefaultExterns(); - for (SourceFile defaultExtern : defaultExterns) - { - this.addJSExternsFile(defaultExtern); - } - } - catch (IOException error) - { - System.out.println(error); - } - } - - private void initOptions() - { - CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel( - options_); - - WarningLevel.VERBOSE.setOptionsForWarningLevel(options_); - - String[] asdocTags = new String[] {"productversion", - "playerversion", "langversion", "copy"}; - options_.setExtraAnnotationNames(Arrays.asList(asdocTags)); - } - - public void setOptions(String sourceMapPath, boolean useStrictPublishing) - { - if (useStrictPublishing) - { - // (erikdebruin) set compiler flags to 'strictest' to allow maximum - // code optimization - - options_.getDefineReplacements().put( - "goog.DEBUG", new Node(Token.TRUE)); - - // ToDo (erikdebruin): re-evaluate this option on future GC release - //options_.setLanguageIn(LanguageMode.ECMASCRIPT6_STRICT); - - options_.setPreferSingleQuotes(true); - - options_.setFoldConstants(true); - options_.setDeadAssignmentElimination(true); - options_.setInlineConstantVars(true); - options_.setInlineFunctions(true); - options_.setInlineLocalFunctions(true); - options_.setCrossModuleCodeMotion(true); - options_.setCoalesceVariableNames(true); - options_.setCrossModuleMethodMotion(true); - options_.setInlineGetters(true); - options_.setInlineVariables(true); - options_.setSmartNameRemoval(true); - options_.setRemoveDeadCode(true); - options_.setCheckMissingReturn(CheckLevel.WARNING); - options_.setExtractPrototypeMemberDeclarations(true); - options_.setRemoveUnusedPrototypeProperties(true); - options_.setRemoveUnusedPrototypePropertiesInExterns(true); - options_.setRemoveUnusedClassProperties(true); - options_.setRemoveUnusedVars(true); - options_.setRemoveUnusedLocalVars(true); - options_.setCollapseVariableDeclarations(true); - options_.setCollapseAnonymousFunctions(true); - options_.setAliasAllStrings(true); - options_.setConvertToDottedProperties(true); - options_.setRewriteFunctionExpressions(true); - options_.setOptimizeParameters(true); - options_.setOptimizeReturns(true); - options_.setOptimizeCalls(true); - options_.setOptimizeArgumentsArray(true); - - // warnings already activated in previous incarnation - options_.setWarningLevel(DiagnosticGroups.ACCESS_CONTROLS, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.CONST, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.CONSTANT_PROPERTY, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.STRICT_MODULE_DEP_CHECK, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.VISIBILITY, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.DEPRECATED, CheckLevel.OFF); // OFF - - // the 'full' set of warnings - options_.setWarningLevel(DiagnosticGroups.AMBIGUOUS_FUNCTION_DECL, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.CHECK_EVENTFUL_OBJECT_DISPOSAL, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.MISSING_PROVIDE, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.CHECK_REGEXP, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.CHECK_TYPES, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.CHECK_USELESS_CODE, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.DEBUGGER_STATEMENT_PRESENT, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.DUPLICATE_MESSAGE, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.DUPLICATE_VARS, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.ES3, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.ES5_STRICT, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.EXTERNS_VALIDATION, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.GLOBAL_THIS, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.FILEOVERVIEW_JSDOC, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.INTERNET_EXPLORER_CHECKS, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.INVALID_CASTS, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.LINT_CHECKS, CheckLevel.OFF); // OFF - options_.setWarningLevel(DiagnosticGroups.MISPLACED_TYPE_ANNOTATION, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.MISSING_PROPERTIES, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.MISSING_PROVIDE, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.MISSING_REQUIRE, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.MISSING_RETURN, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.NEW_CHECK_TYPES, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.NON_STANDARD_JSDOC, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.REPORT_UNKNOWN_TYPES, CheckLevel.OFF); // OFF - options_.setWarningLevel(DiagnosticGroups.SUSPICIOUS_CODE, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.TWEAKS, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.TYPE_INVALIDATION, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.UNDEFINED_NAMES, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.UNDEFINED_VARIABLES, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.UNKNOWN_DEFINES, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.UNNECESSARY_CASTS, CheckLevel.OFF); // OFF - options_.setWarningLevel(DiagnosticGroups.USE_OF_GOOG_BASE, CheckLevel.WARNING); - options_.setWarningLevel(DiagnosticGroups.VIOLATED_MODULE_DEP, CheckLevel.WARNING); - } - - options_.sourceMapFormat = SourceMap.Format.V3; - options_.sourceMapOutputPath = sourceMapPath + ".map"; - } - -} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3724c2ff/compiler-jx/src/main/java/org/apache/flex/compiler/utils/VF2JSProjectUtils.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/VF2JSProjectUtils.java b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/VF2JSProjectUtils.java deleted file mode 100644 index 0542097..0000000 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/VF2JSProjectUtils.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.apache.flex.compiler.utils; - -import java.io.File; -import java.io.IOException; - -import org.apache.commons.io.FileUtils; - -import com.google.common.io.Files; - - -public class VF2JSProjectUtils -{ - - private static File tempDir; - - public static final String createTempProject(String projectFilePath, - boolean isFlashBuilderProject) - { - tempDir = Files.createTempDir(); - - String fileName = projectFilePath.substring(projectFilePath.lastIndexOf(File.separator) + 1, projectFilePath.length()); - - String path = projectFilePath.substring(0, projectFilePath.lastIndexOf(File.separator)); - - createTempProjectDir(new File(path).listFiles(), ""); - - return tempDir.getAbsolutePath() + File.separator + fileName; - } - - private static void createTempProjectDir(File[] files, String parentPath) - { - for (File file : files) - { - if (file.isDirectory()) - { - String path = parentPath + File.separator + file.getName(); - - new File(tempDir + File.separator + path).mkdirs(); - - createTempProjectDir(file.listFiles(), path); - } - else - { - String fileName = file.getName(); - - if (fileName.contains(".") && fileName.charAt(0) != '.') - { - String extension = fileName.substring(fileName.lastIndexOf("."), fileName.length()); - - if (extension.equals(".mxml") || extension.equals(".as")) - { - File intermediateFile = file; - String tempFileName = fileName.substring(0, fileName.indexOf(".")); - File targetDir = new File(tempDir + File.separator + parentPath); - - createTempFileWithVF2JSNamespace(intermediateFile, - tempFileName, false, targetDir, extension); - } - } - } - } - } - - private static File createTempFileWithVF2JSNamespace(File intermediateFile, - String tempFileName, boolean createTempFile, File targetDir, - String extension) - { - File tempFile = null; - - try - { - String content = FileUtils.readFileToString(intermediateFile, "UTF-8"); - - // mx (MXML) - content = content.replace( - "xmlns:mx=\"library://ns.adobe.com/flex/mx\"", - "xmlns:vf2js_mx=\"http://flex.apache.org/vf2js_mx/ns\""); - content = content.replace("<mx:", "<vf2js_mx:"); - content = content.replace("</mx:", "</vf2js_mx:"); - - // mx (AS) - content = content.replace("mx.", "vf2js_mx."); - - // s (MXML) - content = content.replace( - "xmlns:s=\"library://ns.adobe.com/flex/spark\"", - "xmlns:vf2js_s=\"http://flex.apache.org/vf2js_s/ns\""); - content = content.replace("<s:", "<vf2js_s:"); - content = content.replace("</s:", "</vf2js_s:"); - - // s (AS) - content = content.replace("spark.", "vf2js_s."); - - if (createTempFile) - { - tempFile = File.createTempFile(tempFileName, extension, - targetDir); - tempFile.deleteOnExit(); - } - else - { - tempFile = new File(targetDir.getAbsolutePath(), - tempFileName + extension); - } - FileUtils.writeStringToFile(tempFile, content, "UTF-8"); - } - catch (IOException e) - { - throw new RuntimeException("Generating file failed", e); - } - - return tempFile; - } -}