- Refactored the way the closure resources are passed in to the compiler for maven builds - Made the flexjs-compiler use a white-list to dump only a hand full of files of the closure library instead of the entire content
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/43595eac Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/43595eac Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/43595eac Branch: refs/heads/feature-autobuild/example-maven-dirs Commit: 43595eacdfe152826e9274f684eca96e5e006666 Parents: 9694d69 Author: Christofer Dutz <christofer.d...@codecentric.de> Authored: Sat Oct 29 21:14:39 2016 +0200 Committer: Christofer Dutz <christofer.d...@codecentric.de> Committed: Sat Oct 29 21:14:39 2016 +0200 ---------------------------------------------------------------------- compiler-jx/pom.xml | 5 + .../codegen/js/goog/JSGoogPublisher.java | 55 ++++- .../internal/codegen/js/goog/JarSourceFile.java | 117 +++++++++ .../mxml/flexjs/MXMLFlexJSPublisher.java | 245 ++++++------------- .../compiler/internal/graph/GoogDepsWriter.java | 19 +- .../utils/JSClosureCompilerWrapper.java | 11 +- .../flexjs/closure-whitelist.properites | 44 ++++ 7 files changed, 301 insertions(+), 195 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/43595eac/compiler-jx/pom.xml ---------------------------------------------------------------------- diff --git a/compiler-jx/pom.xml b/compiler-jx/pom.xml index 85a0175..01a307b 100644 --- a/compiler-jx/pom.xml +++ b/compiler-jx/pom.xml @@ -82,6 +82,11 @@ <artifactId>compiler</artifactId> <version>0.8.0-SNAPSHOT</version> </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-compress</artifactId> + <version>1.11</version> + </dependency> <dependency> <groupId>args4j</groupId> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/43595eac/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogPublisher.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogPublisher.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogPublisher.java index ea39e45..85abdef 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogPublisher.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogPublisher.java @@ -23,14 +23,13 @@ import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Enumeration; -import java.util.List; +import java.util.*; import java.util.jar.JarEntry; import java.util.jar.JarFile; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.IOUtils; import org.apache.commons.io.filefilter.DirectoryFileFilter; import org.apache.commons.io.filefilter.RegexFileFilter; import org.apache.flex.compiler.clients.JSConfiguration; @@ -271,6 +270,54 @@ public class JSGoogPublisher extends JSPublisher implements IJSPublisher fw.close(); } + protected List<SourceFile> addClasspathResources(File jarFile) throws IOException { + return addClasspathResources(jarFile, null); + } + + protected List<SourceFile> addClasspathResources(File jarFile, Properties whiteList) throws IOException { + List<SourceFile> sourceFiles = new LinkedList<SourceFile>(); + + JarFile jar = null; + try { + jar = new JarFile(jarFile); + for (Enumeration<JarEntry> jarEntries = jar.entries(); jarEntries.hasMoreElements(); ) { + JarEntry jarEntry = jarEntries.nextElement(); + String fileName = jarEntry.getName(); + // Add only JS files and if a white-list is specified, only files on that white-list. + if (fileName.endsWith(".js") && ((whiteList == null) || (whiteList.containsKey(fileName)))) { + // Dump the file. + InputStream is = jar.getInputStream(jarEntry); + String code = IOUtils.toString(is, "UTF-8"); + SourceFile sourceFile = new JarSourceFile(jarEntry.getName(), code, false); + is.close(); + sourceFiles.add(sourceFile); + } + } + } finally { + if(jar != null) { + jar.close(); + } + } + + return sourceFiles; + } + + protected List<SourceFile> addDirectoryResources(File directory) throws IOException { + List<SourceFile> sourceFiles = new LinkedList<SourceFile>(); + + Collection<File> files = org.apache.commons.io.FileUtils.listFiles(directory, + new RegexFileFilter("^.*(\\.js)"), DirectoryFileFilter.DIRECTORY); + for (File file : files) + { + String relative = directory.toURI().relativize(file.toURI()).getPath(); + String code = FileUtils.readFileToString(file, "UTF-8"); + SourceFile sourceFile = new JarSourceFile(relative, code, false); + sourceFiles.add(sourceFile); + } + + return sourceFiles; + } + protected void dumpJar(File jarFile, File outputDir) throws IOException { // TODO (mschmalle) for some reason ide thinks this has not been closed http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/43595eac/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/goog/JarSourceFile.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/goog/JarSourceFile.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/goog/JarSourceFile.java new file mode 100644 index 0000000..8db5bc9 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/goog/JarSourceFile.java @@ -0,0 +1,117 @@ +/* + * + * 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.js.goog; + +import com.google.common.io.CharSource; +import com.google.javascript.jscomp.Region; +import com.google.javascript.jscomp.SourceFile; +import org.apache.commons.io.IOUtils; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; + +/** + * Created by christoferdutz on 28.10.16. + */ +public class JarSourceFile extends SourceFile { + + private String fileName; + private boolean isExtern; + private String code; + + public JarSourceFile(String fileName, String code, boolean isExtern) { + super(fileName); + this.fileName = fileName; + this.isExtern = isExtern; + this.code = code; + } + + @Override + public int getLineOffset(int lineno) { + return super.getLineOffset(lineno); + } + + @Override + public String getCode() throws IOException { + return code; + } + + @Override + public CharSource getCodeCharSource() { + return CharSource.wrap(code); + } + + @Override + public Reader getCodeReader() throws IOException { + return new StringReader(code); + } + + @Override + public String getOriginalPath() { + return fileName; + } + + @Override + public void setOriginalPath(String originalPath) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void clearCachedSource() { + // Ignore as we don't do caching. + } + + @Override + public String getName() { + return fileName; + } + + @Override + public boolean isExtern() { + return isExtern; + } + + @Override + public int getLineOfOffset(int offset) { + return super.getLineOfOffset(offset); + } + + @Override + public int getColumnOfOffset(int offset) { + throw new RuntimeException("Not implemented"); + } + + @Override + public String getLine(int lineNumber) { + throw new RuntimeException("Not implemented"); + } + + @Override + public Region getRegion(int lineNumber) { + throw new RuntimeException("Not implemented"); + } + + @Override + public String toString() { + return fileName; + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/43595eac/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java index adc7e8b..491bdb1 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java @@ -18,28 +18,14 @@ */ package org.apache.flex.compiler.internal.codegen.mxml.flexjs; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.URL; -import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; -import java.util.Map; - +import com.google.javascript.jscomp.SourceFile; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.IOUtils; 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; @@ -47,6 +33,7 @@ import org.apache.flex.compiler.css.ICSSPropertyValue; import org.apache.flex.compiler.internal.codegen.js.JSSharedData; import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens; import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogPublisher; +import org.apache.flex.compiler.internal.codegen.js.goog.JarSourceFile; import org.apache.flex.compiler.internal.css.CSSArrayPropertyValue; import org.apache.flex.compiler.internal.css.CSSFontFace; import org.apache.flex.compiler.internal.css.CSSFunctionCallPropertyValue; @@ -59,6 +46,11 @@ import org.apache.flex.compiler.utils.JSClosureCompilerWrapper; import org.apache.flex.swc.ISWC; import org.apache.flex.swc.ISWCFileEntry; +import java.io.*; +import java.net.URL; +import java.net.URLDecoder; +import java.util.*; + public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher { @@ -172,7 +164,9 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher } } } - + + JSClosureCompilerWrapper compilerWrapper = new JSClosureCompilerWrapper(((JSGoogConfiguration) configuration).getJSCompilerOptions()); + // 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 @@ -187,40 +181,34 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher 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()) + // 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(); + resourceJarPath = URLDecoder.decode(resourceJarPath, "UTF-8"); + if (resourceJarPath.contains(":")) { - 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(); - resourceJarPath = URLDecoder.decode(resourceJarPath, "UTF-8"); - if (resourceJarPath.contains(":")) - { - resourceJarPath = resourceJarPath.substring(resourceJarPath.lastIndexOf(":") + 1); - } - if (resourceJarPath.contains("!")) - { - resourceJarPath = resourceJarPath.substring(0, resourceJarPath.indexOf("!")); - } - File resourceJar = new File(resourceJarPath); + 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); + // We don't want to add all files to the classpath, so we only output the + // resources contained in 'closure-whitelist.properites' to the output. + Properties whiteList = new Properties(); + whiteList.load(Thread.currentThread().getContextClassLoader().getResourceAsStream( + "flexjs/closure-whitelist.properites")); + + // Add the closure files from classpath. + for(SourceFile sourceFile : addClasspathResources(resourceJar, whiteList)) { + compilerWrapper.addJSSourceFile(sourceFile); + // And dump a copy to the output directory (we will need them to execute the application) + FileUtils.write(new File(new File(intermediateDirPath, "library/closure"), + sourceFile.getName()), sourceFile.getCode()); } - // 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 @@ -229,12 +217,13 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher } } - // Dump FlexJS to the target directory. @SuppressWarnings("unused") String flexJsLibDirPath; // Check if the "FlexJS/src/createjs_externals.js" is available in the // classpath. URL resource = Thread.currentThread().getContextClassLoader().getResource("FlexJS/src/createjs_externals.js"); + + // If it exists, dump FlexJS to the target directory. if (resource != null) { File flexJsLibDir = new File(intermediateDir.getParent(), "flexjs"); @@ -266,17 +255,8 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher // Dump the closure lib from classpath. dumpJar(resourceJar, flexJsLibDir); } - // The compiler automatically adds a "closure" to the lib dir path, - // so we omit this here. - flexJsLibDirPath = intermediateDir.getParentFile().getPath(); } - final String closureGoogSrcLibDirPath = closureLibDirPath + "/closure/goog/"; - final String closureGoogTgtLibDirPath = intermediateDirPath + "/library/closure/goog"; - // final String depsSrcFilePath = intermediateDirPath - // + "/library/closure/goog/deps.js"; - @SuppressWarnings("unused") - final String depsTgtFilePath = intermediateDirPath + "/deps.js"; final String projectIntermediateJSFilePath = intermediateDirPath + File.separator + outputFileName; final String projectReleaseJSFilePath = releaseDirPath + File.separator + outputFileName; @@ -290,16 +270,13 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher // (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)); +// FileUtils.copyDirectory(new File(closureGoogSrcLibDirPath), new File(closureGoogTgtLibDirPath)); // } } - - JSClosureCompilerWrapper compilerWrapper = new JSClosureCompilerWrapper(((JSGoogConfiguration) configuration).getJSCompilerOptions()); + // Iterate over all swc dependencies and add all the externs they contain. + // (Externs are located in a "externs" directory in the root of the SWC) List<ISWC> swcs = project.getLibraries(); - - // (erikdebruin) We don't want to forget that we need to tell the GCC - // about them fancy externs we've been working so hard on for (ISWC swc : swcs) { Map<String, ISWCFileEntry> files = swc.getFiles(); @@ -310,100 +287,31 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher ISWCFileEntry fileEntry = swc.getFile(key); if (fileEntry != null) { - File destFile = new File(intermediateDirPath + File.separator + key); - InputStream inStream = fileEntry.createInputStream(); - OutputStream outStream = FileUtils.openOutputStream(destFile); - byte[] b = new byte[1024 * 1024]; - int bytes_read; - while ((bytes_read = inStream.read(b)) != -1) - { - outStream.write(b, 0, bytes_read); - } - outStream.flush(); - outStream.close(); - inStream.close(); - - String destPath = destFile.getAbsolutePath(); - - System.out.println("using extern: " + destPath); - - compilerWrapper.addJSExternsFile(destPath); + InputStream is = fileEntry.createInputStream(); + String code = IOUtils.toString(is, "UTF-8"); + is.close(); + JarSourceFile sexternFile = new JarSourceFile(key, code,true); + System.out.println("using extern: " + key); + compilerWrapper.addJSExternsFile(sexternFile); } } } } GoogDepsWriter gdw = new GoogDepsWriter(intermediateDir, projectName, (JSGoogConfiguration) configuration, swcs); - StringBuilder depsFileData = new StringBuilder(); - try - { - ArrayList<String> fileList = gdw.getListOfFiles(problems); - for (String file : fileList) - { - compilerWrapper.addJSSourceFile(file); - } - 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; + + // Add all the js-files generated by the compiler to to config. + ArrayList<String> fileList = gdw.getListOfFiles(problems); + for (String file : fileList) { + compilerWrapper.addJSSourceFile(file); } + + // Generate the content for the deps-file + String depsFileData = gdw.generateDeps(problems); + project.needCSS = gdw.needCSS; - + + // Copy static resources to the intermediate directory. IOFileFilter pngSuffixFilter = FileFilterUtils.and(FileFileFilter.FILE, FileFilterUtils.suffixFileFilter(".png")); IOFileFilter gifSuffixFilter = FileFilterUtils.and(FileFileFilter.FILE, @@ -415,12 +323,10 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher IOFileFilter assetFiles = FileFilterUtils.or(pngSuffixFilter, jpgSuffixFilter, gifSuffixFilter, jsonSuffixFilter); IOFileFilter subdirs = FileFilterUtils.or(DirectoryFileFilter.DIRECTORY, assetFiles); - FileUtils.copyDirectory(srcDir, intermediateDir, subdirs); - if (!configuration.debug()) - FileUtils.copyDirectory(srcDir, releaseDir, subdirs); - - // File srcDeps = new File(depsSrcFilePath); + if (!configuration.debug()) { + FileUtils.copyDirectory(srcDir, releaseDir, subdirs); + } File template = ((JSGoogConfiguration)configuration).getHtmlTemplate(); if (!((JSGoogConfiguration)configuration).getSkipTranspile()) @@ -448,26 +354,15 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher if (!configuration.debug()) { - /* - * 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()); } } - */ - Collection<File> files = org.apache.commons.io.FileUtils.listFiles(new File(closureGoogSrcLibDirPath), - 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()); } - */ - + +// sourceFiles.addAll(addDirectoryResources(new File(closureGoogSrcLibDirPath))); + + // Add all SourceFiles to the compiler. +/* for(SourceFile sourceFile : sourceFiles) { + compilerWrapper.addJSSourceFile(sourceFile); + } +*/ + compilerWrapper.setOptions(projectReleaseJSFilePath, useStrictPublishing, projectName); /* http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/43595eac/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/GoogDepsWriter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/GoogDepsWriter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/GoogDepsWriter.java index 7bf9e95..8b49a88 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/GoogDepsWriter.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/GoogDepsWriter.java @@ -74,7 +74,7 @@ public class GoogDepsWriter { public boolean needCSS = false; - public ArrayList<String> getListOfFiles(ProblemQuery problems) throws InterruptedException + public ArrayList<String> getListOfFiles(ProblemQuery problems) { problemsFound = false; this.problems = problems; @@ -92,7 +92,7 @@ public class GoogDepsWriter { return files; } - public boolean generateDeps(ProblemQuery problems, StringBuilder depsFileData) throws InterruptedException, FileNotFoundException + public String generateDeps(ProblemQuery problems) throws FileNotFoundException { problemsFound = false; this.problems = problems; @@ -101,25 +101,18 @@ public class GoogDepsWriter { buildDB(); dps = sort(mainName); } - String outString = "// generated by FalconJX" + "\n"; + StringBuilder sb = new StringBuilder("// generated by FalconJX\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; + sb.append("goog.addDependency('").append(relativePath(gd.filePath)).append("', ['") + .append(gd.className).append("'], [").append(getDependencies(gd.deps)).append("]);\n"); } } - depsFileData.append(outString); - return !problemsFound; + return sb.toString(); } private boolean isGoogClass(String className) http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/43595eac/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 f39382d..fa372fd 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 @@ -91,9 +91,14 @@ public class JSClosureCompilerWrapper public void addJSSourceFile(String fileName) { - jsSourceFiles_.add(SourceFile.fromFile(fileName)); + addJSSourceFile(SourceFile.fromFile(fileName)); } - + + public void addJSSourceFile(SourceFile file) + { + jsSourceFiles_.add(file); + } + public void compile() { compiler_.compile(jsExternsFiles_, jsSourceFiles_, options_); @@ -103,7 +108,7 @@ public class JSClosureCompilerWrapper FileWriter targetFile = new FileWriter(targetFilePath); targetFile.write(compiler_.toSource()); targetFile.close(); - + FileWriter sourceMapFile = new FileWriter(options_.sourceMapOutputPath); compiler_.getSourceMap().appendTo(sourceMapFile, ""); sourceMapFile.close(); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/43595eac/compiler-jx/src/main/resources/flexjs/closure-whitelist.properites ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/resources/flexjs/closure-whitelist.properites b/compiler-jx/src/main/resources/flexjs/closure-whitelist.properites new file mode 100644 index 0000000..5fd746b --- /dev/null +++ b/compiler-jx/src/main/resources/flexjs/closure-whitelist.properites @@ -0,0 +1,44 @@ + +# 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. + +goog/array/array.js +goog/asserts/asserts.js +goog/base.js +goog/deps.js +goog/debug/entrypointregistry.js +goog/debug/error.js +goog/disposable/disposable.js +goog/disposable/idisposable.js +goog/dom/nodetype.js +goog/events/browserevent.js +goog/events/browserfeature.js +goog/events/event.js +goog/events/eventid.js +goog/events/events.js +goog/events/eventtarget.js +goog/events/eventtype.js +goog/events/listenable.js +goog/events/listener.js +goog/events/listenermap.js +goog/labs/useragent/browser.js +goog/labs/useragent/engine.js +goog/labs/useragent/platform.js +goog/labs/useragent/util.js +goog/object/object.js +goog/reflect/reflect.js +goog/string/string.js +goog/useragent/useragent.js +goog/bootstrap/nodejs.js \ No newline at end of file