Repository: flex-falcon Updated Branches: refs/heads/develop afe290ea6 -> 9262e10e4
add option to pass args to Google Closure Compiler Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/3fbaa899 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/3fbaa899 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/3fbaa899 Branch: refs/heads/develop Commit: 3fbaa8995268915ba63e9ab60fea4aa579794a66 Parents: afe290e Author: Alex Harui <[email protected]> Authored: Wed Oct 21 12:16:07 2015 -0700 Committer: Alex Harui <[email protected]> Committed: Wed Oct 21 12:16:07 2015 -0700 ---------------------------------------------------------------------- .../mxml/flexjs/MXMLFlexJSPublisher.java | 2 +- .../driver/js/goog/JSGoogConfiguration.java | 20 ++++++++ .../utils/JSClosureCompilerWrapper.java | 52 +++++++++++++++++--- 3 files changed, 67 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3fbaa899/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java index 6341c3d..0f7e54d 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java @@ -287,7 +287,7 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher FileUtils.copyDirectory(new File(closureGoogSrcLibDirPath), new File(closureGoogTgtLibDirPath)); // } - JSClosureCompilerWrapper compilerWrapper = new JSClosureCompilerWrapper(); + JSClosureCompilerWrapper compilerWrapper = new JSClosureCompilerWrapper(((JSGoogConfiguration) configuration).getJSCompilerOptions()); List<ISWC> swcs = project.getLibraries(); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3fbaa899/compiler.jx/src/org/apache/flex/compiler/internal/driver/js/goog/JSGoogConfiguration.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/driver/js/goog/JSGoogConfiguration.java b/compiler.jx/src/org/apache/flex/compiler/internal/driver/js/goog/JSGoogConfiguration.java index 1b7efe1..55f449e 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/driver/js/goog/JSGoogConfiguration.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/driver/js/goog/JSGoogConfiguration.java @@ -248,4 +248,24 @@ public class JSGoogConfiguration extends JSConfiguration .getCanonicalPath(); } + // + // 'js-compiler-option' + // + + protected List<String> jsCompilerOptions = new ArrayList<String>(); + + public List<String> getJSCompilerOptions() + { + return jsCompilerOptions; + } + + @Config(allowMultiple = true) + @Mapping("js-compiler-option") + @InfiniteArguments + public void setJSCompilerOptions(ConfigurationValue cv, List<String> value) + throws ConfigurationException + { + jsCompilerOptions.addAll(value); + } + } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3fbaa899/compiler.jx/src/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java b/compiler.jx/src/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java index f804fa0..03ca077 100644 --- a/compiler.jx/src/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java +++ b/compiler.jx/src/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java @@ -44,14 +44,28 @@ import com.google.javascript.rhino.Token; public class JSClosureCompilerWrapper { - public JSClosureCompilerWrapper() + public JSClosureCompilerWrapper(List<String> args) { Compiler.setLoggingLevel(Level.INFO); compiler_ = new Compiler(); - options_ = new CompilerOptions(); - initOptions(); + ArrayList<String> splitArgs = new ArrayList<String>(); + for (String s : args) + { + if (s.contains(" ")) + { + String[] parts = s.split(" "); + for (String part : parts) + splitArgs.add(part); + } + else + splitArgs.add(s); + } + String[] stringArgs = new String[splitArgs.size()]; + splitArgs.toArray(stringArgs); + options_ = new CompilerOptionsParser(stringArgs).getOptions(); + initOptions(args); jsExternsFiles_ = new ArrayList<SourceFile>(); initExterns(); @@ -129,12 +143,26 @@ public class JSClosureCompilerWrapper } } - private void initOptions() + private void initOptions(List<String> args) { - CompilationLevel.WHITESPACE_ONLY.setOptionsForCompilationLevel( + boolean hasCompilationLevel = false; + boolean hasWarningLevel = false; + for (String s : args) + { + if (s.startsWith("--compilation_level ") || + s.startsWith("-O ")) + hasCompilationLevel = true; + + if (s.startsWith("--warning_level ") || + s.startsWith("-W ")) + hasWarningLevel = true; + } + if (!hasCompilationLevel) + CompilationLevel.WHITESPACE_ONLY.setOptionsForCompilationLevel( options_); - WarningLevel.VERBOSE.setOptionsForWarningLevel(options_); + if (!hasWarningLevel) + WarningLevel.VERBOSE.setOptionsForWarningLevel(options_); String[] asdocTags = new String[] {"productversion", "playerversion", "langversion", "copy", @@ -258,4 +286,16 @@ public class JSClosureCompilerWrapper options_.sourceMapOutputPath = sourceMapPath + ".map"; } + private static class CompilerOptionsParser extends CommandLineRunner + { + public CompilerOptionsParser(String[] args) + { + super(args); + } + + public CompilerOptions getOptions() + { + return createOptions(); + } + } }
