Permalink
Browse files

JSON bug fix + Add support for compressing via Google Closure

  • Loading branch information...
1 parent 6522c1e commit adbc32839b4048e5f7fffd3efde23a18a909357c @rbackhouse rbackhouse committed Nov 23, 2012
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry exported="true" kind="lib" path="" sourcepath="source-bundle"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="javaBin"/>
+</classpath>
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.dojotoolkit.compressor.closure</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Closure
+Bundle-SymbolicName: org.dojotoolkit.compressor.closure
+Bundle-Version: 0.4.9
+Import-Package: com.google.javascript.jscomp,
+ org.dojotoolkit.compressor,
+ org.dojotoolkit.server.util.osgi,
+ org.dojotoolkit.server.util.resource,
+ org.osgi.framework;version="1.3.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-Activator: org.dojotoolkit.server.util.osgi.DojoServiceActivator
+Export-DojoService: org.dojotoolkit.compressor.JSCompressorFactory;impl=org.dojotoolkit.compressor.closure.ClosureJSCompressorFactory;id=ClosureJSCompressor
+Export-Package: org.dojotoolkit.compressor.closure
@@ -0,0 +1,63 @@
+/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+package org.dojotoolkit.compressor.closure;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.dojotoolkit.compressor.JSCompressor;
+import org.dojotoolkit.server.util.resource.ResourceLoader;
+
+import com.google.javascript.jscomp.CompilationLevel;
+import com.google.javascript.jscomp.Compiler;
+import com.google.javascript.jscomp.CompilerOptions;
+import com.google.javascript.jscomp.JSError;
+import com.google.javascript.jscomp.Result;
+import com.google.javascript.jscomp.SourceFile;
+
+public class ClosureJSCompressor implements JSCompressor {
+ private static Logger logger = Logger.getLogger("org.dojotoolkit.compressor");
+ private Map<String, String> sourceMapMap = null;
+
+ public ClosureJSCompressor(ResourceLoader resourceLoader) {
+ sourceMapMap = new HashMap<String, String>();
+ }
+
+ public String compress(String path, String src) throws IOException {
+ Compiler compiler = new Compiler();
+ CompilerOptions options = new CompilerOptions();
+ CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
+ //CompilationLevel.WHITESPACE_ONLY.setOptionsForCompilationLevel(options);
+ options.sourceMapOutputPath = "";
+ options.setLineLengthThreshold(1024 * 64);
+ SourceFile extern = SourceFile.fromCode("externs.js", "");
+ SourceFile input = SourceFile.fromCode(path, src);
+ long start = System.currentTimeMillis();
+ Result result = compiler.compile(extern, input, options);
+ if (!result.success) {
+ StringBuffer sb = new StringBuffer();
+ for (JSError error : result.errors) {
+ sb.append(error.toString());
+ sb.append("\n");
+ }
+ throw new IOException(sb.toString());
+ }
+ String compressedSrc = compiler.toSource();
+ long end = System.currentTimeMillis();
+ StringBuffer sb = new StringBuffer();
+ result.sourceMap.appendTo(sb, path);
+ sourceMapMap.put(path+".map", sb.toString());
+ logger.logp(Level.FINE, getClass().getName(), "compress", "time : "+(end-start)+" ms");
+ return compressedSrc;
+ }
+
+ public String getSourceMap(String path) {
+ return sourceMapMap.get(path);
+ }
+}
@@ -0,0 +1,21 @@
+/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+package org.dojotoolkit.compressor.closure;
+
+import org.dojotoolkit.compressor.JSCompressor;
+import org.dojotoolkit.compressor.JSCompressorFactory;
+import org.dojotoolkit.compressor.JSCompressorFactoryImpl;
+import org.dojotoolkit.server.util.resource.ResourceLoader;
+
+public class ClosureJSCompressorFactory implements JSCompressorFactory {
+ public JSCompressor createJSCompressor(ResourceLoader resourceLoader) {
+ return new ClosureJSCompressor(resourceLoader);
+ }
+
+ public String[] getIgnoreList() {
+ return JSCompressorFactoryImpl.defaultIgnoreList;
+ }
+}
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Compressor
Bundle-SymbolicName: org.dojotoolkit.compressor
-Bundle-Version: 0.4.4
+Bundle-Version: 0.4.9
Import-Package: org.dojotoolkit.server.util.resource,
org.osgi.framework;version="1.3.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
@@ -1,3 +1,3 @@
-jsCompressorClassName=org.dojotoolkit.compressor.shrinksafe.ShrinksafeJSCompressor
+jsCompressorClassName=org.dojotoolkit.compressor.closure.ClosureJSCompressor
ignoreList=/dojo/dojo.js,\
.*/nls/.*
@@ -20,7 +20,7 @@
public class JSCompressorFactoryImpl implements JSCompressorFactory {
private static Logger logger = Logger.getLogger("org.dojotoolkit.compressor");
- private static final String DEFAULT_JS_COMPRESSOR_CLASS = "org.dojotoolkit.compressor.shrinksafe.ShrinksafeJSCompressor";
+ private static final String DEFAULT_JS_COMPRESSOR_CLASS = "org.dojotoolkit.compressor.closure.ClosureJSCompressor";
public static String[] defaultIgnoreList = new String[] {
"/dojo/dojo.js",
@@ -2,5 +2,5 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Json Plug-in
Bundle-SymbolicName: org.dojotoolkit.json
-Bundle-Version: 0.3.1
+Bundle-Version: 0.3.6
Export-Package: org.dojotoolkit.json
Binary file not shown.
@@ -153,7 +153,6 @@ JSONSerializer writeString(String value) throws IOException {
char c = chars[i];
switch (c) {
case '"': writer.write("\\\""); break;
- case '\'': writer.write("\\'"); break;
case '\\': writer.write("\\\\"); break;
case 0: writer.write("\\0"); break;
case '\b': writer.write("\\b"); break;

0 comments on commit adbc328

Please sign in to comment.