Skip to content
Browse files

Initial check-in

  • Loading branch information...
1 parent 400a4d3 commit a067a171918b9a777c69352651c95218203817a7 @rbackhouse rbackhouse committed May 25, 2012
Showing with 8,240 additions and 0 deletions.
  1. +7 −0 org.dojotoolkit.compressor.shrinksafe/.classpath
  2. +17 −0 org.dojotoolkit.compressor.shrinksafe/.project
  3. +14 −0 org.dojotoolkit.compressor.shrinksafe/META-INF/MANIFEST.MF
  4. BIN ...otoolkit.compressor.shrinksafe/org/dojotoolkit/compressor/shrinksafe/ShrinksafeJSCompressor.class
  5. BIN ...t.compressor.shrinksafe/org/dojotoolkit/compressor/shrinksafe/ShrinksafeJSCompressorFactory.class
  6. +36 −0 ...olkit.compressor.shrinksafe/src/org/dojotoolkit/compressor/shrinksafe/ShrinksafeJSCompressor.java
  7. +22 −0 ...ompressor.shrinksafe/src/org/dojotoolkit/compressor/shrinksafe/ShrinksafeJSCompressorFactory.java
  8. +7 −0 org.dojotoolkit.compressor/.classpath
  9. +17 −0 org.dojotoolkit.compressor/.project
  10. +9 −0 org.dojotoolkit.compressor/META-INF/MANIFEST.MF
  11. BIN org.dojotoolkit.compressor/org/dojotoolkit/compressor/JSCompressor.class
  12. BIN org.dojotoolkit.compressor/org/dojotoolkit/compressor/JSCompressorContentFilter.class
  13. BIN org.dojotoolkit.compressor/org/dojotoolkit/compressor/JSCompressorFactory.class
  14. BIN org.dojotoolkit.compressor/org/dojotoolkit/compressor/JSCompressorFactoryImpl.class
  15. +3 −0 org.dojotoolkit.compressor/org_dojotoolkit_compressor.properties
  16. +21 −0 org.dojotoolkit.compressor/src/org/dojotoolkit/compressor/JSCompressor.java
  17. +66 −0 org.dojotoolkit.compressor/src/org/dojotoolkit/compressor/JSCompressorContentFilter.java
  18. +13 −0 org.dojotoolkit.compressor/src/org/dojotoolkit/compressor/JSCompressorFactory.java
  19. +102 −0 org.dojotoolkit.compressor/src/org/dojotoolkit/compressor/JSCompressorFactoryImpl.java
  20. +1 −0 org.dojotoolkit.compressor/uglifyjs_V8_org_dojotoolkit_compressor.properties
  21. +1 −0 org.dojotoolkit.compressor/uglifyjs_rhino_org_dojotoolkit_compressor.properties
  22. +7 −0 org.dojotoolkit.json/.classpath
  23. +17 −0 org.dojotoolkit.json/.project
  24. +6 −0 org.dojotoolkit.json/META-INF/MANIFEST.MF
  25. BIN org.dojotoolkit.json/org/dojotoolkit/json/JSONParseException.class
  26. BIN org.dojotoolkit.json/org/dojotoolkit/json/JSONParser.class
  27. BIN org.dojotoolkit.json/org/dojotoolkit/json/JSONSerializeException.class
  28. BIN org.dojotoolkit.json/org/dojotoolkit/json/JSONSerializer.class
  29. BIN org.dojotoolkit.json/org/dojotoolkit/json/JSONSerializerVerbose.class
  30. BIN org.dojotoolkit.json/org/dojotoolkit/json/internal/Token.class
  31. BIN org.dojotoolkit.json/org/dojotoolkit/json/internal/Tokenizer.class
  32. +30 −0 org.dojotoolkit.json/src/org/dojotoolkit/json/JSONParseException.java
  33. +170 −0 org.dojotoolkit.json/src/org/dojotoolkit/json/JSONParser.java
  34. +30 −0 org.dojotoolkit.json/src/org/dojotoolkit/json/JSONSerializeException.java
  35. +318 −0 org.dojotoolkit.json/src/org/dojotoolkit/json/JSONSerializer.java
  36. +77 −0 org.dojotoolkit.json/src/org/dojotoolkit/json/JSONSerializerVerbose.java
  37. +103 −0 org.dojotoolkit.json/src/org/dojotoolkit/json/internal/Token.java
  38. +317 −0 org.dojotoolkit.json/src/org/dojotoolkit/json/internal/Tokenizer.java
  39. +7 −0 org.dojotoolkit.optimizer.amd.rhinoast/.classpath
  40. +17 −0 org.dojotoolkit.optimizer.amd.rhinoast/.project
  41. +16 −0 org.dojotoolkit.optimizer.amd.rhinoast/META-INF/MANIFEST.MF
  42. BIN ...kit.optimizer.amd.rhinoast/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizer$AstVisitor.class
  43. BIN ...toolkit.optimizer.amd.rhinoast/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizer$Module.class
  44. BIN org.dojotoolkit.optimizer.amd.rhinoast/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizer.class
  45. BIN ...toolkit.optimizer.amd.rhinoast/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizerFactory.class
  46. +623 −0 ...dojotoolkit.optimizer.amd.rhinoast/src/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizer.java
  47. +20 −0 ...lkit.optimizer.amd.rhinoast/src/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizerFactory.java
  48. +7 −0 org.dojotoolkit.optimizer.amd/.classpath
  49. +17 −0 org.dojotoolkit.optimizer.amd/.project
  50. +5 −0 org.dojotoolkit.optimizer.amd/META-INF/MANIFEST.MF
  51. +652 −0 org.dojotoolkit.optimizer.amd/loader/amd/zazl.js
  52. +128 −0 org.dojotoolkit.optimizer.amd/optimizer/amd/AMDAnalyzer.js
  53. +532 −0 org.dojotoolkit.optimizer.amd/optimizer/amd/astwalker.js
  54. +39 −0 org.dojotoolkit.optimizer.amd/optimizer/amd/map.js
  55. +24 −0 org.dojotoolkit.optimizer.amd/optimizer/amd/module.js
  56. +47 −0 org.dojotoolkit.optimizer.amd/optimizer/amd/plugins/dojo/has.js
  57. +3 −0 org.dojotoolkit.optimizer.amd/optimizer/amd/plugins/dojo/selector/_loader.js
  58. +21 −0 org.dojotoolkit.optimizer.amd/optimizer/amd/plugins/dojo/text.js
  59. +3 −0 org.dojotoolkit.optimizer.amd/optimizer/amd/plugins/dojox/gfx/renderer.js
  60. +4 −0 org.dojotoolkit.optimizer.amd/optimizer/package.json
  61. +7 −0 org.dojotoolkit.optimizer.servlet/.classpath
  62. +17 −0 org.dojotoolkit.optimizer.servlet/.project
  63. +28 −0 org.dojotoolkit.optimizer.servlet/META-INF/MANIFEST.MF
  64. BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/AMDJSHandler.class
  65. BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/HTMLParser$HTMLWriter.class
  66. BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/HTMLParser.class
  67. BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/JSFilter$RequestWrapper.class
  68. BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/JSFilter$ResponseWrapper.class
  69. BIN ...kit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/JSFilter$ServletOutputStreamWrapper.class
  70. BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/JSFilter.class
  71. BIN ...dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/JSHandler$OptimizerRunnable.class
  72. BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/JSHandler.class
  73. BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/JSServlet.class
  74. BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/JSURLGenerator.class
  75. BIN ....optimizer.servlet/org/dojotoolkit/optimizer/servlet/MultiContextResourceLoader$ContextData.class
  76. BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/MultiContextResourceLoader.class
  77. BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/RhinoASTScriptAnalyzer.class
  78. BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/RhinoScriptAnalyzer.class
  79. BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/ScriptAnalyzer.class
  80. BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/ServletResourceLoader.class
  81. BIN ...toolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/SyncLoaderJSHandler$JSNamespace.class
  82. BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/SyncLoaderJSHandler.class
  83. BIN ...g/dojotoolkit/optimizer/servlet/osgi/ZazlServicesTracker$HttpContextExtensionServiceTracker.class
  84. BIN ...mizer.servlet/org/dojotoolkit/optimizer/servlet/osgi/ZazlServicesTracker$HttpServiceTracker.class
  85. BIN ...rg/dojotoolkit/optimizer/servlet/osgi/ZazlServicesTracker$JSCompressorFactoryServiceTracker.class
  86. BIN ...org/dojotoolkit/optimizer/servlet/osgi/ZazlServicesTracker$JSOptimizerFactoryServiceTracker.class
  87. BIN ...ptimizer.servlet/org/dojotoolkit/optimizer/servlet/osgi/ZazlServicesTracker$ResourceServlet.class
  88. BIN ...zer.servlet/org/dojotoolkit/optimizer/servlet/osgi/ZazlServicesTracker$ZazlServicesListener.class
  89. BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/osgi/ZazlServicesTracker.class
  90. +125 −0 org.dojotoolkit.optimizer.servlet/src/org/dojotoolkit/optimizer/servlet/AMDJSHandler.java
  91. +217 −0 org.dojotoolkit.optimizer.servlet/src/org/dojotoolkit/optimizer/servlet/HTMLParser.java
  92. +215 −0 org.dojotoolkit.optimizer.servlet/src/org/dojotoolkit/optimizer/servlet/JSFilter.java
  93. +252 −0 org.dojotoolkit.optimizer.servlet/src/org/dojotoolkit/optimizer/servlet/JSHandler.java
  94. +156 −0 org.dojotoolkit.optimizer.servlet/src/org/dojotoolkit/optimizer/servlet/JSServlet.java
  95. +77 −0 org.dojotoolkit.optimizer.servlet/src/org/dojotoolkit/optimizer/servlet/JSURLGenerator.java
  96. +61 −0 ...jotoolkit.optimizer.servlet/src/org/dojotoolkit/optimizer/servlet/MultiContextResourceLoader.java
  97. +158 −0 org.dojotoolkit.optimizer.servlet/src/org/dojotoolkit/optimizer/servlet/RhinoASTScriptAnalyzer.java
  98. +60 −0 org.dojotoolkit.optimizer.servlet/src/org/dojotoolkit/optimizer/servlet/RhinoScriptAnalyzer.java
  99. +47 −0 org.dojotoolkit.optimizer.servlet/src/org/dojotoolkit/optimizer/servlet/ScriptAnalyzer.java
  100. +55 −0 org.dojotoolkit.optimizer.servlet/src/org/dojotoolkit/optimizer/servlet/ServletResourceLoader.java
  101. +199 −0 org.dojotoolkit.optimizer.servlet/src/org/dojotoolkit/optimizer/servlet/SyncLoaderJSHandler.java
  102. +327 −0 ...dojotoolkit.optimizer.servlet/src/org/dojotoolkit/optimizer/servlet/osgi/ZazlServicesTracker.java
  103. +5 −0 org.dojotoolkit.optimizer.servlet/syncloader.json
  104. +111 −0 org.dojotoolkit.optimizer.servlet/taganalyzer/analyzer.js
  105. +31 −0 org.dojotoolkit.optimizer.servlet/zazl.json
  106. +31 −0 org.dojotoolkit.optimizer.servlet/zazlUsingESPrima.json
  107. +7 −0 org.dojotoolkit.optimizer/.classpath
  108. +17 −0 org.dojotoolkit.optimizer/.project
  109. +11 −0 org.dojotoolkit.optimizer/META-INF/MANIFEST.MF
  110. +1 −0 org.dojotoolkit.optimizer/V8_org_dojotoolkit_optimizer.properties
  111. +1 −0 org.dojotoolkit.optimizer/amd_V8_org_dojotoolkit_optimizer.properties
  112. +1 −0 org.dojotoolkit.optimizer/amd_rhino_org_dojotoolkit_optimizer.properties
  113. +1 −0 org.dojotoolkit.optimizer/amd_rhinoast_org_dojotoolkit_optimizer.properties
  114. +227 −0 org.dojotoolkit.optimizer/optimizer/syncloader/analyzer.js
  115. +18 −0 org.dojotoolkit.optimizer/optimizer/syncloader/bootstrap.js
  116. +34 −0 org.dojotoolkit.optimizer/optimizer/syncloader/hostenv_optimizer.js
  117. +39 −0 org.dojotoolkit.optimizer/optimizer/syncloader/localization.js
  118. +38 −0 org.dojotoolkit.optimizer/optimizer/syncloader/map.js
  119. +23 −0 org.dojotoolkit.optimizer/optimizer/syncloader/module.js
  120. BIN org.dojotoolkit.optimizer/org/dojotoolkit/optimizer/CachingJSOptimizer.class
  121. BIN org.dojotoolkit.optimizer/org/dojotoolkit/optimizer/ChecksumCreator.class
  122. BIN org.dojotoolkit.optimizer/org/dojotoolkit/optimizer/JSAnalysisData.class
  123. BIN org.dojotoolkit.optimizer/org/dojotoolkit/optimizer/JSAnalysisDataImpl.class
  124. BIN org.dojotoolkit.optimizer/org/dojotoolkit/optimizer/JSOptimizer.class
  125. BIN org.dojotoolkit.optimizer/org/dojotoolkit/optimizer/JSOptimizerFactory.class
  126. BIN org.dojotoolkit.optimizer/org/dojotoolkit/optimizer/JSOptimizerFactoryImpl.class
  127. BIN org.dojotoolkit.optimizer/org/dojotoolkit/optimizer/Localization.class
  128. BIN org.dojotoolkit.optimizer/org/dojotoolkit/optimizer/Util.class
  129. +1 −0 org.dojotoolkit.optimizer/org_dojotoolkit_optimizer.properties
  130. +1 −0 org.dojotoolkit.optimizer/rhino_org_dojotoolkit_optimizer.properties
  131. +101 −0 org.dojotoolkit.optimizer/src/org/dojotoolkit/optimizer/CachingJSOptimizer.java
  132. +44 −0 org.dojotoolkit.optimizer/src/org/dojotoolkit/optimizer/ChecksumCreator.java
  133. +52 −0 org.dojotoolkit.optimizer/src/org/dojotoolkit/optimizer/JSAnalysisData.java
  134. +315 −0 org.dojotoolkit.optimizer/src/org/dojotoolkit/optimizer/JSAnalysisDataImpl.java
  135. +55 −0 org.dojotoolkit.optimizer/src/org/dojotoolkit/optimizer/JSOptimizer.java
  136. +16 −0 org.dojotoolkit.optimizer/src/org/dojotoolkit/optimizer/JSOptimizerFactory.java
  137. +80 −0 org.dojotoolkit.optimizer/src/org/dojotoolkit/optimizer/JSOptimizerFactoryImpl.java
  138. +27 −0 org.dojotoolkit.optimizer/src/org/dojotoolkit/optimizer/Localization.java
  139. +149 −0 org.dojotoolkit.optimizer/src/org/dojotoolkit/optimizer/Util.java
  140. +7 −0 org.dojotoolkit.server.util.js/.classpath
  141. +17 −0 org.dojotoolkit.server.util.js/.project
  142. +5 −0 org.dojotoolkit.server.util.js/META-INF/MANIFEST.MF
  143. +29 −0 org.dojotoolkit.server.util.js/astcache.js
  144. +59 −0 org.dojotoolkit.server.util.js/jsutil/array/reduce.js
  145. +162 −0 org.dojotoolkit.server.util.js/jsutil/commonjs/loader.js
  146. +8 −0 org.dojotoolkit.server.util.js/resourceloader.js
  147. +7 −0 org.dojotoolkit.server.util.js/uglify-js.js
  148. +7 −0 org.dojotoolkit.server.util.js/zazlutil.js
  149. +7 −0 org.dojotoolkit.server.util/.classpath
  150. +17 −0 org.dojotoolkit.server.util/.project
  151. +12 −0 org.dojotoolkit.server.util/META-INF/MANIFEST.MF
  152. BIN org.dojotoolkit.server.util/org/dojotoolkit/server/util/osgi/DojoServiceActivator.class
  153. BIN org.dojotoolkit.server.util/org/dojotoolkit/server/util/osgi/DojoServicesInitializer.class
  154. BIN org.dojotoolkit.server.util/org/dojotoolkit/server/util/osgi/OSGiResourceLoader.class
  155. BIN ...ojotoolkit.server.util/org/dojotoolkit/server/util/resource/CachingContentFilter$CacheEntry.class
  156. BIN org.dojotoolkit.server.util/org/dojotoolkit/server/util/resource/CachingContentFilter.class
  157. BIN ...toolkit.server.util/org/dojotoolkit/server/util/resource/CachingResourceLoader$URLTimestamp.class
  158. BIN org.dojotoolkit.server.util/org/dojotoolkit/server/util/resource/CachingResourceLoader.class
  159. BIN org.dojotoolkit.server.util/org/dojotoolkit/server/util/resource/ContentFilter.class
  160. BIN org.dojotoolkit.server.util/org/dojotoolkit/server/util/resource/MultiRootResourceLoader.class
  161. BIN org.dojotoolkit.server.util/org/dojotoolkit/server/util/resource/ResourceLoader.class
  162. BIN org.dojotoolkit.server.util/org/dojotoolkit/server/util/rhino/ASTCache$ASTCacheEntry.class
  163. BIN org.dojotoolkit.server.util/org/dojotoolkit/server/util/rhino/ASTCache.class
  164. BIN org.dojotoolkit.server.util/org/dojotoolkit/server/util/rhino/RhinoClassLoader.class
  165. BIN org.dojotoolkit.server.util/org/dojotoolkit/server/util/rhino/RhinoJSMethods.class
  166. +25 −0 org.dojotoolkit.server.util/src/org/dojotoolkit/server/util/osgi/DojoServiceActivator.java
  167. +147 −0 org.dojotoolkit.server.util/src/org/dojotoolkit/server/util/osgi/DojoServicesInitializer.java
  168. +67 −0 org.dojotoolkit.server.util/src/org/dojotoolkit/server/util/osgi/OSGiResourceLoader.java
  169. +55 −0 org.dojotoolkit.server.util/src/org/dojotoolkit/server/util/resource/CachingContentFilter.java
  170. +156 −0 org.dojotoolkit.server.util/src/org/dojotoolkit/server/util/resource/CachingResourceLoader.java
  171. +10 −0 org.dojotoolkit.server.util/src/org/dojotoolkit/server/util/resource/ContentFilter.java
  172. +39 −0 org.dojotoolkit.server.util/src/org/dojotoolkit/server/util/resource/MultiRootResourceLoader.java
  173. +33 −0 org.dojotoolkit.server.util/src/org/dojotoolkit/server/util/resource/ResourceLoader.java
  174. +64 −0 org.dojotoolkit.server.util/src/org/dojotoolkit/server/util/rhino/ASTCache.java
  175. +102 −0 org.dojotoolkit.server.util/src/org/dojotoolkit/server/util/rhino/RhinoClassLoader.java
  176. +191 −0 org.dojotoolkit.server.util/src/org/dojotoolkit/server/util/rhino/RhinoJSMethods.java
View
7 org.dojotoolkit.compressor.shrinksafe/.classpath
@@ -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>
View
17 org.dojotoolkit.compressor.shrinksafe/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.dojotoolkit.compressor.shrinksafe</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>
View
14 org.dojotoolkit.compressor.shrinksafe/META-INF/MANIFEST.MF
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Shrinksafe
+Bundle-SymbolicName: org.dojotoolkit.compressor.shrinksafe
+Bundle-Version: 0.3.2
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Import-Package: org.dojotoolkit.compressor,
+ org.dojotoolkit.server.util.resource,
+ org.dojotoolkit.shrinksafe,
+ org.mozilla.javascript,
+ org.dojotoolkit.server.util.osgi
+Export-Package: org.dojotoolkit.compressor.shrinksafe
+Bundle-Activator: org.dojotoolkit.server.util.osgi.DojoServiceActivator
+Export-DojoService: org.dojotoolkit.compressor.JSCompressorFactory;impl=org.dojotoolkit.compressor.shrinksafe.ShrinksafeJSCompressorFactory;id=ShrinksafeJSCompressor
View
BIN ....compressor.shrinksafe/org/dojotoolkit/compressor/shrinksafe/ShrinksafeJSCompressor.class
Binary file not shown.
View
BIN ...ssor.shrinksafe/org/dojotoolkit/compressor/shrinksafe/ShrinksafeJSCompressorFactory.class
Binary file not shown.
View
36 ...mpressor.shrinksafe/src/org/dojotoolkit/compressor/shrinksafe/ShrinksafeJSCompressor.java
@@ -0,0 +1,36 @@
+/*
+ Copyright (c) 2004-2010, 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.shrinksafe;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.dojotoolkit.compressor.JSCompressor;
+import org.dojotoolkit.server.util.resource.ResourceLoader;
+import org.dojotoolkit.shrinksafe.Compressor;
+import org.mozilla.javascript.Context;
+
+public class ShrinksafeJSCompressor implements JSCompressor {
+ private static Logger logger = Logger.getLogger("org.dojotoolkit.compressor");
+
+ public ShrinksafeJSCompressor(ResourceLoader resourceLoader) {}
+
+ public String compress(String src) throws IOException {
+ long start = System.currentTimeMillis();
+ Context ctx = null;
+ try {
+ ctx = Context.enter();
+ ctx.initStandardObjects();
+ String compressedSrc = Compressor.compressScript(src, 0, 1, null);
+ long end = System.currentTimeMillis();
+ logger.logp(Level.FINE, getClass().getName(), "compress", "time : "+(end-start)+" ms");
+ return compressedSrc;
+ } finally {
+ Context.exit();
+ }
+ }
+}
View
22 ...r.shrinksafe/src/org/dojotoolkit/compressor/shrinksafe/ShrinksafeJSCompressorFactory.java
@@ -0,0 +1,22 @@
+/*
+ Copyright (c) 2004-2010, 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.shrinksafe;
+
+import org.dojotoolkit.compressor.JSCompressor;
+import org.dojotoolkit.compressor.JSCompressorFactory;
+import org.dojotoolkit.compressor.JSCompressorFactoryImpl;
+import org.dojotoolkit.server.util.resource.ResourceLoader;
+
+public class ShrinksafeJSCompressorFactory implements JSCompressorFactory {
+
+ public JSCompressor createJSCompressor(ResourceLoader resourceLoader) {
+ return new ShrinksafeJSCompressor(resourceLoader);
+ }
+
+ public String[] getIgnoreList() {
+ return JSCompressorFactoryImpl.defaultIgnoreList;
+ }
+}
View
7 org.dojotoolkit.compressor/.classpath
@@ -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>
View
17 org.dojotoolkit.compressor/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.dojotoolkit.compressor</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>
View
9 org.dojotoolkit.compressor/META-INF/MANIFEST.MF
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Compressor
+Bundle-SymbolicName: org.dojotoolkit.compressor
+Bundle-Version: 0.3.2
+Import-Package: org.dojotoolkit.server.util.resource,
+ org.osgi.framework;version="1.3.0"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Export-Package: org.dojotoolkit.compressor
View
BIN org.dojotoolkit.compressor/org/dojotoolkit/compressor/JSCompressor.class
Binary file not shown.
View
BIN org.dojotoolkit.compressor/org/dojotoolkit/compressor/JSCompressorContentFilter.class
Binary file not shown.
View
BIN org.dojotoolkit.compressor/org/dojotoolkit/compressor/JSCompressorFactory.class
Binary file not shown.
View
BIN org.dojotoolkit.compressor/org/dojotoolkit/compressor/JSCompressorFactoryImpl.class
Binary file not shown.
View
3 org.dojotoolkit.compressor/org_dojotoolkit_compressor.properties
@@ -0,0 +1,3 @@
+jsCompressorClassName=org.dojotoolkit.compressor.shrinksafe.ShrinksafeJSCompressor
+ignoreList=/dojo/dojo.js,\
+.*/nls/.*
View
21 org.dojotoolkit.compressor/src/org/dojotoolkit/compressor/JSCompressor.java
@@ -0,0 +1,21 @@
+/*
+ Copyright (c) 2004-2010, 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;
+
+import java.io.IOException;
+
+/**
+ * Implementations with allow callers to compress provide javascript source
+ *
+ */
+public interface JSCompressor {
+ /**
+ * @param src String value containing the javascript source
+ * @return String containing compressed javascript source
+ * @throws IOException
+ */
+ String compress(String src) throws IOException;
+}
View
66 org.dojotoolkit.compressor/src/org/dojotoolkit/compressor/JSCompressorContentFilter.java
@@ -0,0 +1,66 @@
+/*
+ Copyright (c) 2004-2010, 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;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.dojotoolkit.server.util.resource.CachingContentFilter;
+import org.dojotoolkit.server.util.resource.ResourceLoader;
+
+public class JSCompressorContentFilter extends CachingContentFilter {
+ private static Logger logger = Logger.getLogger("org.dojotoolkit.compressor");
+ private JSCompressor jsCompressor = null;
+ private Pattern[] ignorePatterns = null;
+
+ public JSCompressorContentFilter(JSCompressorFactory jsCompressorFactory, ResourceLoader resourceLoader) {
+ super(resourceLoader);
+ if (jsCompressorFactory != null) {
+ jsCompressor = jsCompressorFactory.createJSCompressor(resourceLoader);
+ String[] ignoreList = jsCompressorFactory.getIgnoreList();
+ ignorePatterns = new Pattern[ignoreList.length];
+ int i = 0;
+ for (String ignorePath : ignoreList) {
+ ignorePatterns[i++] = Pattern.compile(ignorePath);
+ }
+ }
+ }
+
+ protected String _runFilter(String content, String path) {
+ if (doCompress(path)) {
+ try {
+ return jsCompressor.compress(content);
+ } catch (IOException e) {
+ logger.logp(Level.SEVERE, getClass().getName(), "_runFilter", "Unable to compress ["+path+"]", e);
+ return content;
+ }
+ } else {
+ return content;
+ }
+ }
+
+ private boolean doCompress(String path) {
+ boolean compress = false;
+ if (jsCompressor != null && path.endsWith(".js")) {
+ boolean ignore = false;
+ if (ignorePatterns != null) {
+ for (Pattern ignorePattern : ignorePatterns) {
+ Matcher matcher = ignorePattern.matcher(path);
+ if (matcher.lookingAt()) {
+ logger.logp(Level.FINE, getClass().getName(), "doCompress", "["+path+"] will not be compressed");
+ ignore = true;
+ break;
+ }
+ }
+ }
+ compress = !ignore;
+ }
+ return compress;
+ }
+}
View
13 org.dojotoolkit.compressor/src/org/dojotoolkit/compressor/JSCompressorFactory.java
@@ -0,0 +1,13 @@
+/*
+ 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;
+
+import org.dojotoolkit.server.util.resource.ResourceLoader;
+
+public interface JSCompressorFactory {
+ public JSCompressor createJSCompressor(ResourceLoader resourceLoader);
+ public String[] getIgnoreList();
+}
View
102 org.dojotoolkit.compressor/src/org/dojotoolkit/compressor/JSCompressorFactoryImpl.java
@@ -0,0 +1,102 @@
+/*
+ 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.dojotoolkit.server.util.resource.ResourceLoader;
+
+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";
+
+ public static String[] defaultIgnoreList = new String[] {
+ "/dojo/dojo.js",
+ ".*/nls/.*"
+ };
+
+ private Constructor<JSCompressor> jsCompressorConstructor = null;
+ private String[] ignoreList = defaultIgnoreList;
+
+ public JSCompressorFactoryImpl() {
+ try {
+ Class<JSCompressor> jsCompressorClass = null;
+ URL propsURL = getClass().getClassLoader().getResource("/org_dojotoolkit_compressor.properties");
+ if (propsURL != null) {
+ logger.logp(Level.FINE, getClass().getName(), "JSCompressorFactoryImpl", "org_dojotoolkit_compressor.properties is available");
+ InputStream is = null;
+ try {
+ is = propsURL.openStream();
+ Properties props = new Properties();
+ props.load(is);
+ String jsCompressorClassName = props.getProperty("jsCompressorClassName");
+ if (jsCompressorClassName != null) {
+ logger.logp(Level.FINE, getClass().getName(), "JSCompressorFactoryImpl", "jsCompressorClassName is to ["+jsCompressorClassName+"]");
+ jsCompressorClass = (Class<JSCompressor>) getClass().getClassLoader().loadClass(jsCompressorClassName);
+ }
+ String ignoreListValues = props.getProperty("ignoreList");
+ if (ignoreListValues != null) {
+ StringTokenizer st = new StringTokenizer(ignoreListValues, ",");
+ List<String> ignoreListList = new ArrayList<String>();
+ while (st.hasMoreTokens()) {
+ String ignoreListValue = st.nextToken();
+ logger.logp(Level.FINE, getClass().getName(), "JSCompressorFactoryImpl", "Adding ignore list value["+ignoreListValue+"]");
+ ignoreListList.add(ignoreListValue);
+ }
+ ignoreList = new String[ignoreListList.size()];
+ ignoreList = ignoreListList.toArray(ignoreList);
+ }
+ } catch (IOException e) {
+ logger.logp(Level.SEVERE, getClass().getName(), "JSOptimizerFactoryImpl", "Implementation of JSCompressor defined in org_dojotoolkit_compressor.properties is unavailable", e);
+ throw new IllegalStateException("Implementation of JSCompressor defined in org_dojotoolkit_compressor.properties is unavailable");
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ }
+ if (jsCompressorClass == null) {
+ logger.logp(Level.INFO, getClass().getName(), "JSCompressorFactoryImpl", "jsCompressorClassName is default of ["+DEFAULT_JS_COMPRESSOR_CLASS+"]");
+ jsCompressorClass = (Class<JSCompressor>) getClass().getClassLoader().loadClass(DEFAULT_JS_COMPRESSOR_CLASS);
+ }
+ jsCompressorConstructor = jsCompressorClass.getConstructor(new Class[] {ResourceLoader.class});
+ } catch (ClassNotFoundException e) {
+ logger.logp(Level.SEVERE, getClass().getName(), "JSOptimizerFactoryImpl", "Implementation of JSCompressor defined in org_dojotoolkit_compressor.properties is unavailable", e);
+ throw new IllegalStateException("Implementation of JSCompressor defined in org_dojotoolkit_compressor.properties is unavailable");
+ } catch (NoSuchMethodException e) {
+ logger.logp(Level.SEVERE, getClass().getName(), "JSOptimizerFactoryImpl", "JSCompressor implementation does not have a valid constructor", e);
+ throw new IllegalStateException("JSCompressor implementation does not have a valid constructor");
+ }
+ }
+
+ public JSCompressor createJSCompressor(ResourceLoader resourceLoader) {
+ JSCompressor jsCompressor = null;
+
+ try {
+ jsCompressor = jsCompressorConstructor.newInstance(new Object[] {resourceLoader});
+ } catch (Exception e) {
+ logger.logp(Level.SEVERE, getClass().getName(), "createJSCompressor", "Exception thrown while creating and instance of "+jsCompressorConstructor.toString(), e);
+ }
+
+ return jsCompressor;
+ }
+
+ public String[] getIgnoreList() {
+ return ignoreList;
+ }
+}
View
1 org.dojotoolkit.compressor/uglifyjs_V8_org_dojotoolkit_compressor.properties
@@ -0,0 +1 @@
+jsCompressorClassName=org.dojotoolkit.compressor.uglifyjs.v8.V8UglifyJSCompressor
View
1 org.dojotoolkit.compressor/uglifyjs_rhino_org_dojotoolkit_compressor.properties
@@ -0,0 +1 @@
+jsCompressorClassName=org.dojotoolkit.compressor.uglifyjs.rhino.RhinoUglifyJSCompressor
View
7 org.dojotoolkit.json/.classpath
@@ -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>
View
17 org.dojotoolkit.json/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.dojotoolkit.json</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>
View
6 org.dojotoolkit.json/META-INF/MANIFEST.MF
@@ -0,0 +1,6 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Json Plug-in
+Bundle-SymbolicName: org.dojotoolkit.json
+Bundle-Version: 0.3.1
+Export-Package: org.dojotoolkit.json
View
BIN org.dojotoolkit.json/org/dojotoolkit/json/JSONParseException.class
Binary file not shown.
View
BIN org.dojotoolkit.json/org/dojotoolkit/json/JSONParser.class
Binary file not shown.
View
BIN org.dojotoolkit.json/org/dojotoolkit/json/JSONSerializeException.class
Binary file not shown.
View
BIN org.dojotoolkit.json/org/dojotoolkit/json/JSONSerializer.class
Binary file not shown.
View
BIN org.dojotoolkit.json/org/dojotoolkit/json/JSONSerializerVerbose.class
Binary file not shown.
View
BIN org.dojotoolkit.json/org/dojotoolkit/json/internal/Token.class
Binary file not shown.
View
BIN org.dojotoolkit.json/org/dojotoolkit/json/internal/Tokenizer.class
Binary file not shown.
View
30 org.dojotoolkit.json/src/org/dojotoolkit/json/JSONParseException.java
@@ -0,0 +1,30 @@
+/*
+ Copyright (c) 2004-2010, 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
+
+ This code has been generously donated by Pat Mueller (http://muellerware.org/)
+*/
+package org.dojotoolkit.json;
+
+import java.io.IOException;
+
+/**
+ *
+ */
+public class JSONParseException extends IOException {
+
+ /**
+ *
+ */
+ public JSONParseException() {
+ super();
+ }
+
+ /**
+ *
+ */
+ public JSONParseException(String message) {
+ super(message);
+ }
+}
View
170 org.dojotoolkit.json/src/org/dojotoolkit/json/JSONParser.java
@@ -0,0 +1,170 @@
+/*
+ Copyright (c) 2004-2010, 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
+
+ This code has been generously donated by Pat Mueller (http://muellerware.org/)
+*/
+package org.dojotoolkit.json;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.dojotoolkit.json.internal.Token;
+import org.dojotoolkit.json.internal.Tokenizer;
+
+/**
+ * Converts encoded <a href="http://www.ietf.org/rfc/rfc4627.txt">JSON</a> into Java objects.
+ * Specifically,
+ * <ul>
+ * <li>JSON Objects are converted to Maps
+ * <li>JSON Arrays are converted to Lists
+ * <li>JSON Strings are converted to Strings
+ * <li>JSON Numbers are converted to either Long or Double, depending on
+ * whether they are integral or not.
+ * <li>JSON Booleans are converted to Booleans
+ * <li>nulls are converted to null
+ * </ul>
+ * <p>Note that this parser reads ahead one character, if it can, and
+ * that read-ahead character will be thrown away at the end of parsing if
+ * not part of the JSON representation.
+ */
+public class JSONParser {
+
+ private Tokenizer tokenizer;
+ private Token lastToken;
+
+ /**
+ *
+ */
+ static public Object parse(Reader reader) throws IOException {
+ JSONParser parser = new JSONParser(reader);
+ return parser.parseValue();
+ }
+
+ /**
+ *
+ */
+ private JSONParser(Reader reader) throws IOException {
+ super();
+
+ this.tokenizer = new Tokenizer(reader);
+ this.lastToken = tokenizer.next();
+ }
+
+ /**
+ *
+ */
+ private Object parseMap() throws IOException {
+ Map result = new HashMap();
+
+ if (lastToken != Token.TokenBraceL) throw new JSONParseException("Expecting '{' " + tokenizer.onLineCol());//NON-NLS
+ lastToken = tokenizer.next();
+
+ while (true) {
+ if (lastToken == Token.TokenEOF) throw new JSONParseException("Unterminated object " + tokenizer.onLineCol());//NON-NLS
+
+ if (lastToken == Token.TokenBraceR) {
+ lastToken = tokenizer.next();
+ break;
+ }
+
+ if (!lastToken.isString()) throw new JSONParseException("Expecting string key " + tokenizer.onLineCol());//NON-NLS
+ String key = lastToken.getString();
+
+ lastToken = tokenizer.next();
+ if (lastToken != Token.TokenColon) throw new JSONParseException("Expecting colon " + tokenizer.onLineCol());//NON-NLS
+
+ lastToken = tokenizer.next();
+ Object val = parseValue();
+
+ result.put(key, val);
+
+ if (lastToken == Token.TokenComma) {
+ lastToken = tokenizer.next();
+ }
+
+ else if (lastToken != Token.TokenBraceR) {
+ throw new JSONParseException("expecting either ',' or '}' " + tokenizer.onLineCol());//NON-NLS
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ *
+ */
+ private List parseArray() throws IOException {
+ List result = new ArrayList();
+
+ if (lastToken != Token.TokenBrackL) throw new JSONParseException("Expecting '[' " + tokenizer.onLineCol());//NON-NLS
+ lastToken = tokenizer.next();
+
+ while (true) {
+ if (lastToken == Token.TokenEOF) throw new JSONParseException("Unterminated array " + tokenizer.onLineCol());//NON-NLS
+
+ if (lastToken == Token.TokenBrackR) {
+ lastToken = tokenizer.next();
+ break;
+ }
+
+ Object val = parseValue();
+
+ result.add(val);
+
+ if (lastToken == Token.TokenComma) {
+ lastToken = tokenizer.next();
+ }
+ else if (lastToken != Token.TokenBrackR) {
+ throw new JSONParseException("expecting either ',' or ']' " + tokenizer.onLineCol());//NON-NLS
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ *
+ */
+ private Object parseValue() throws IOException {
+ if (lastToken == Token.TokenEOF) throw new JSONParseException("Expecting property value " + tokenizer.onLineCol());//NON-NLS
+
+ if (lastToken.isNumber()) {
+ Object result = lastToken.getNumber();
+ lastToken = tokenizer.next();
+ return result;
+ }
+
+ if (lastToken.isString()) {
+ Object result = lastToken.getString();
+ lastToken = tokenizer.next();
+ return result;
+ }
+
+ if (lastToken == Token.TokenFalse) {
+ lastToken = tokenizer.next();
+ return Boolean.FALSE;
+ }
+
+ if (lastToken == Token.TokenTrue) {
+ lastToken = tokenizer.next();
+ return Boolean.TRUE;
+ }
+
+ if (lastToken == Token.TokenNull) {
+ lastToken = tokenizer.next();
+ return null;
+ }
+
+ if (lastToken == Token.TokenBrackL) return parseArray();
+ if (lastToken == Token.TokenBraceL) return parseMap();
+
+ throw new JSONParseException("Invalid token " + tokenizer.onLineCol());//NON-NLS
+ }
+
+}
View
30 org.dojotoolkit.json/src/org/dojotoolkit/json/JSONSerializeException.java
@@ -0,0 +1,30 @@
+/*
+ Copyright (c) 2004-2010, 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
+
+ This code has been generously donated by Pat Mueller (http://muellerware.org/)
+*/
+package org.dojotoolkit.json;
+
+import java.io.IOException;
+
+/**
+ *
+ */
+public class JSONSerializeException extends IOException {
+
+ /**
+ *
+ */
+ public JSONSerializeException() {
+ super();
+ }
+
+ /**
+ *
+ */
+ public JSONSerializeException(String message) {
+ super(message);
+ }
+}
View
318 org.dojotoolkit.json/src/org/dojotoolkit/json/JSONSerializer.java
@@ -0,0 +1,318 @@
+/*
+ Copyright (c) 2004-2010, 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
+
+ This code has been generously donated by Pat Mueller (http://muellerware.org/)
+*/
+package org.dojotoolkit.json;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Converts Java objects into encoded <a href="http://www.ietf.org/rfc/rfc4627.txt">JSON</a>.
+ * See {@link JSONParser} for the mapping rules.
+ */
+public class JSONSerializer {
+
+ private Writer writer;
+
+ /**
+ * Serialize an object to a Writer as JSON.
+ */
+ static public void serialize(Writer writer, Object object, boolean verbose) throws IOException {
+ JSONSerializer JSONSerializer = verbose ? new JSONSerializerVerbose(writer) : new JSONSerializer(writer);
+ JSONSerializer.write(object);
+ writer.flush();
+ }
+
+ /**
+ * Serialize an object to a Writer as JSON, specifying whether to be verbose or not.
+ */
+ static public void serialize(Writer writer, Object object) throws IOException {
+ serialize(writer,object,false);
+ }
+
+ /**
+ * Create a JSONSerializer on the specified output stream.
+ * Note that you should create
+ */
+ JSONSerializer(Writer writer) {
+ super();
+
+ this.writer = writer;
+ }
+
+ /**
+ *
+ */
+ JSONSerializer write(Object object) throws IOException {
+ if (null == object) return writeNull();
+ if (object instanceof Number) return writeNumber((Number) object);
+ if (object instanceof Character) return writeCharacter((Character) object);
+ if (object instanceof String) return writeString((String) object);
+ if (object instanceof Boolean) return writeBoolean((Boolean) object);
+ if (object instanceof Map) return writeObject((Map) object);
+ if (object instanceof List) return writeArray((List) object);
+
+ throw new JSONSerializeException("attempting to serialize unserializable object: '" + object + "'");//NON-NLS
+ }
+
+ /**
+ *
+ */
+ JSONSerializer writeRawString(String s) throws IOException {
+ writer.write(s);
+
+ return this;
+ }
+
+ /**
+ *
+ */
+ JSONSerializer writeNull() throws IOException {
+ writeRawString("null");
+
+ return this;
+ }
+
+ /**
+ *
+ */
+ JSONSerializer writeNumber(Number value) throws IOException {
+ if (null == value) return writeNull();
+
+ if (value instanceof Float) {
+ if (Float.NaN == value.floatValue()) return writeNull();
+ if (Float.NEGATIVE_INFINITY == value.floatValue()) return writeNull();
+ if (Float.POSITIVE_INFINITY == value.floatValue()) return writeNull();
+ }
+
+ if (value instanceof Double) {
+ if (Double.NaN == value.doubleValue()) return writeNull();
+ if (Double.NEGATIVE_INFINITY == value.doubleValue()) return writeNull();
+ if (Double.POSITIVE_INFINITY == value.doubleValue()) return writeNull();
+ }
+
+ writeRawString(value.toString());
+
+ return this;
+ }
+
+ /**
+ *
+ */
+ JSONSerializer writeCharacter(Character value) throws IOException {
+ if (null == value) return writeNull();
+
+ return writeNumber(new Integer(value.charValue()));
+ }
+
+ /**
+ *
+ */
+ JSONSerializer writeBoolean(Boolean value) throws IOException {
+ if (null == value) return writeNull();
+
+ writeRawString(value.toString());
+
+ return this;
+ }
+
+ /**
+ *
+ */
+ String rightAlignedZero(String s, int len) {
+ if (len == s.length()) return s;
+
+ StringBuffer sb = new StringBuffer(s);
+
+ while (sb.length() < len) {
+ sb.insert(0, '0');
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ *
+ */
+ JSONSerializer writeString(String value) throws IOException {
+ if (null == value) return writeNull();
+
+ writer.write('"');
+
+ char[] chars = value.toCharArray();
+
+ for (int i=0; i<chars.length; i++) {
+ 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;
+ case '\t': writer.write("\\t"); break;
+ case '\n': writer.write("\\n"); break;
+ case 0x0B: writer.write("\\v"); break;
+ case '\f': writer.write("\\f"); break;
+ case '\r': writer.write("\\r"); break;
+ default:
+ if ((c >= 32) && (c <= 126)) {
+ writer.write(c);
+ }
+ else if (c < 255) {
+ writer.write("\\x");
+ writer.write(rightAlignedZero(Integer.toHexString(c),2));
+ }
+ else {
+ writer.write("\\u");
+ writer.write(rightAlignedZero(Integer.toHexString(c),4));
+ }
+ }
+ }
+
+ writer.write('"');
+
+ return this;
+ }
+
+ /**
+ *
+ */
+ JSONSerializer writeObject(Map object) throws IOException {
+ if (null == object) return writeNull();
+
+ // write header
+ writeRawString("{");
+ indentPush();
+
+ List propertyNames = getPropertyNames(object);
+ for (Iterator iter=propertyNames.iterator(); iter.hasNext(); ) {
+ Object key = iter.next();
+ if (!(key instanceof String)) throw new JSONSerializeException("attempting to serialize object with an invalid property name: '" + key + "'" );//NON-NLS
+
+ Object value = object.get(key);
+ if (!isValidObject(value)) throw new JSONSerializeException("attempting to serialize object with an invalid property value: '" + value + "'");//NON-NLS
+
+ newLine();
+ indent();
+// writeRawString("\"");
+ writeString((String)key);
+ writeRawString(":");
+ space();
+ write(value);
+
+ if (iter.hasNext()) writeRawString(",");
+ }
+
+ // write trailer
+ indentPop();
+ newLine();
+ indent();
+ writeRawString("}");
+
+ return this;
+ }
+
+ /**
+ *
+ */
+ JSONSerializer writeArray(List value) throws IOException {
+ if (null == value) return writeNull();
+
+ // write header
+ writeRawString("[");
+ indentPush();
+
+ for (Iterator iter=value.iterator(); iter.hasNext(); ) {
+ Object element = iter.next();
+ if (!isValidObject(element)) throw new JSONSerializeException("attempting to serialize array with an invalid element: '" + value + "'");//NON-NLS
+
+ newLine();
+ indent();
+ write(element);
+
+ if (iter.hasNext()) writeRawString(",");
+ }
+
+ // write trailer
+ indentPop();
+ newLine();
+ indent();
+ writeRawString("]");
+
+ return this;
+ }
+
+ /**
+ *
+ */
+ private boolean isValidObject(Object object) {
+ if (null == object) return true;
+ return isValidType(object.getClass());
+ }
+
+ /**
+ * Return whether the class is a valid type of value for a property.
+ */
+ private static boolean isValidType(Class clazz) {
+ if (null == clazz) throw new IllegalArgumentException();
+
+ if (String.class == clazz) return true;
+ if (Boolean.class == clazz) return true;
+ if (Map.class.isAssignableFrom(clazz)) return true;
+ if (List.class.isAssignableFrom(clazz)) return true;
+ if (Number.class.isAssignableFrom(clazz)) return true;
+ if (Character.class.isAssignableFrom(clazz)) return true;
+
+ return false;
+ }
+
+ //---------------------------------------------------------------
+ // pretty printing overridables
+ //---------------------------------------------------------------
+
+ /**
+ *
+ */
+ void space() throws IOException {
+ }
+
+ /**
+ *
+ */
+ void newLine() throws IOException {
+ }
+
+ /**
+ *
+ */
+ void indent() throws IOException {
+ }
+
+ /**
+ *
+ */
+ void indentPush() {
+ }
+
+ /**
+ *
+ */
+ void indentPop() {
+ }
+
+ /**
+ *
+ */
+ List getPropertyNames(Map map) {
+ return new ArrayList(map.keySet());
+ }
+
+}
View
77 org.dojotoolkit.json/src/org/dojotoolkit/json/JSONSerializerVerbose.java
@@ -0,0 +1,77 @@
+/*
+ Copyright (c) 2004-2010, 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
+
+ This code has been generously donated by Pat Mueller (http://muellerware.org/)
+*/
+package org.dojotoolkit.json;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/**
+ *
+ */
+class JSONSerializerVerbose extends JSONSerializer {
+
+ private int indent = 0;
+
+ /**
+ *
+ */
+ JSONSerializerVerbose(Writer writer) {
+ super(writer);
+ }
+
+ /**
+ *
+ */
+ void space() throws IOException {
+ writeRawString(" ");
+ }
+
+ /**
+ *
+ */
+ void newLine() throws IOException {
+ writeRawString("\n");
+ }
+
+ /**
+ *
+ */
+ void indent() throws IOException {
+ for (int i=0; i<indent; i++) writeRawString(" ");
+ }
+
+ /**
+ *
+ */
+ void indentPush() {
+ indent++;
+ }
+
+ /**
+ *
+ */
+ void indentPop() {
+ indent--;
+ if (indent < 0) throw new IllegalStateException();
+ }
+
+ /**
+ *
+ */
+ List getPropertyNames(Map map) {
+ List propertyNames = super.getPropertyNames(map);
+
+ Collections.sort(propertyNames);
+
+ return propertyNames;
+ }
+
+}
View
103 org.dojotoolkit.json/src/org/dojotoolkit/json/internal/Token.java
@@ -0,0 +1,103 @@
+/*
+ Copyright (c) 2004-2010, 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
+
+ This code has been generously donated by Pat Mueller (http://muellerware.org/)
+*/
+package org.dojotoolkit.json.internal;
+
+/**
+ *
+ */
+public class Token {
+
+ static final public Token TokenEOF = new Token();
+ static final public Token TokenBraceL = new Token();
+ static final public Token TokenBraceR = new Token();
+ static final public Token TokenBrackL = new Token();
+ static final public Token TokenBrackR = new Token();
+ static final public Token TokenColon = new Token();
+ static final public Token TokenComma = new Token();
+ static final public Token TokenTrue = new Token();
+ static final public Token TokenFalse = new Token();
+ static final public Token TokenNull = new Token();
+
+ private String valueString;
+ private Number valueNumber;
+
+
+ /**
+ *
+ */
+ public Token() {
+ super();
+ }
+
+ /**
+ *
+ */
+ public Token(String value) {
+ super();
+
+ valueString = value;
+ }
+
+ /**
+ *
+ */
+ public Token(Number value) {
+ super();
+
+ valueNumber = value;
+ }
+
+ /**
+ *
+ */
+ public String getString() {
+ return valueString;
+ }
+
+ /**
+ *
+ */
+ public Number getNumber() {
+ return valueNumber;
+ }
+
+ /**
+ *
+ */
+ public boolean isString() {
+ return null != valueString;
+ }
+
+ /**
+ *
+ */
+ public boolean isNumber() {
+ return null != valueNumber;
+ }
+
+ /**
+ *
+ */
+ public String toString() {
+ if (this == TokenEOF) return "Token: EOF";
+ if (this == TokenBraceL) return "Token: {";
+ if (this == TokenBraceR) return "Token: }";
+ if (this == TokenBrackL) return "Token: [";
+ if (this == TokenBrackR) return "Token: ]";
+ if (this == TokenColon) return "Token: :";
+ if (this == TokenComma) return "Token: ,";
+ if (this == TokenTrue) return "Token: true";
+ if (this == TokenFalse) return "Token: false";
+ if (this == TokenNull) return "Token: null";
+
+ if (this.isNumber()) return "Token: Number - " + getNumber();
+ if (this.isString()) return "Token: String - '" + getString() + "'";
+
+ return "Token: unknown!!";
+ }
+}
View
317 org.dojotoolkit.json/src/org/dojotoolkit/json/internal/Tokenizer.java
@@ -0,0 +1,317 @@
+/*
+ Copyright (c) 2004-2010, 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
+
+ This code has been generously donated by Pat Mueller (http://muellerware.org/)
+*/
+package org.dojotoolkit.json.internal;
+
+import java.io.IOException;
+import java.io.Reader;
+
+/**
+ * Tokenizes a stream into JSON tokens.
+ */
+public class Tokenizer {
+
+ private Reader reader;
+ private int lineNo;
+ private int colNo;
+ private int lastChar;
+
+ /**
+ * Create a new instance of this class.
+ */
+ public Tokenizer(Reader reader) throws IOException {
+ super();
+
+ this.reader = reader;
+ this.lineNo = 0;
+ this.colNo = 0;
+ this.lastChar = '\n';
+
+ readChar();
+ }
+
+ /**
+ * Return the next token in the stream, returning Token.TokenEOF when finished.
+ */
+ public Token next() throws IOException {
+
+ // skip whitespace
+ while (Character.isWhitespace((char)lastChar)) {
+ readChar();
+ }
+
+ // handle punctuation
+ switch (lastChar) {
+ case -1: readChar(); return Token.TokenEOF;
+ case '{': readChar(); return Token.TokenBraceL;
+ case '}': readChar(); return Token.TokenBraceR;
+ case '[': readChar(); return Token.TokenBrackL;
+ case ']': readChar(); return Token.TokenBrackR;
+ case ':': readChar(); return Token.TokenColon;
+ case ',': readChar(); return Token.TokenComma;
+
+ case '"':
+ case '\'':
+ String stringValue = readString();
+ return new Token(stringValue);
+
+ case '-':
+ case '.':
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ Number numberValue = readNumber();
+ return new Token(numberValue);
+
+ case 'n':
+ case 't':
+ case 'f':
+ String ident = readIdentifier();
+
+ if (ident.equals("null")) return Token.TokenNull;
+ if (ident.equals("true")) return Token.TokenTrue;
+ if (ident.equals("false")) return Token.TokenFalse;
+
+ throw new IOException("Unexpected identifier '" + ident + "' " + onLineCol());//NON-NLS
+
+ default:
+ throw new IOException("Unexpected character '" + lastChar + "' " + onLineCol());//NON-NLS
+
+ }
+
+ }
+
+ /**
+ *
+ */
+ private String readString() throws IOException {
+ StringBuffer sb = new StringBuffer();
+ int delim = lastChar;
+ int l = lineNo;
+ int c = colNo;
+
+ readChar();
+ while ((-1 != lastChar) && (delim != lastChar)) {
+ StringBuffer digitBuffer;
+
+ if (lastChar != '\\') {
+ sb.append((char)lastChar);
+ readChar();
+ continue;
+ }
+
+ readChar();
+
+ switch (lastChar) {
+ case 'b': readChar(); sb.append('\b'); continue;
+ case 'f': readChar(); sb.append('\f'); continue;
+ case 'n': readChar(); sb.append('\n'); continue;
+ case 'r': readChar(); sb.append('\r'); continue;
+ case 't': readChar(); sb.append('\t'); continue;
+ case '\'': readChar(); sb.append('\''); continue;
+ case '"': readChar(); sb.append('"'); continue;
+ case '\\': readChar(); sb.append('\\'); continue;
+ case '/': readChar(); sb.append('/'); continue;
+
+ // hex constant
+ // unicode constant
+ case 'x':
+ case 'u':
+ digitBuffer = new StringBuffer();
+
+ int toRead = 2;
+ if (lastChar == 'u') toRead = 4;
+
+ for (int i=0; i<toRead; i++) {
+ readChar();
+ if (!isHexDigit(lastChar)) throw new IOException("non-hex digit " + onLineCol());//NON-NLS
+ digitBuffer.append((char) lastChar);
+ }
+ readChar();
+
+ try {
+ int digitValue = Integer.parseInt(digitBuffer.toString(), 16);
+ sb.append((char) digitValue);
+ }
+ catch (NumberFormatException e) {
+ throw new IOException("non-hex digit " + onLineCol());//NON-NLS
+ }
+
+ break;
+
+ // octal constant
+ default:
+ if (!isOctalDigit(lastChar)) throw new IOException("non-hex digit " + onLineCol());//NON-NLS
+
+ digitBuffer = new StringBuffer();
+ digitBuffer.append((char) lastChar);
+
+ for (int i=0; i<2; i++) {
+ readChar();
+ if (!isOctalDigit(lastChar)) break;
+
+ digitBuffer.append((char) lastChar);
+ }
+
+ try {
+ int digitValue = Integer.parseInt(digitBuffer.toString(), 8);
+ sb.append((char) digitValue);
+ }
+ catch (NumberFormatException e) {
+ throw new IOException("non-hex digit " + onLineCol());//NON-NLS
+ }
+ }
+ }
+
+ if (-1 == lastChar) {
+ throw new IOException("String not terminated " + onLineCol(l,c));//NON-NLS
+ }
+
+ readChar();
+
+ return sb.toString();
+ }
+
+ /**
+ * Read a number.
+ *
+ * (-)(1-9)(0-9)* : decimal
+ * (-)0(0-7)* : octal
+ * (-)0(x|X)(0-9|a-f|A-F)* : hex
+ * [digits][.digits][(E|e)[(+|-)]digits]
+ * */
+ private Number readNumber() throws IOException {
+ StringBuffer sb = new StringBuffer();
+ int l = lineNo;
+ int c = colNo;
+
+ while (isDigitChar(lastChar)) {
+ sb.append((char)lastChar);
+ readChar();
+ }
+
+ // convert it!
+ String string = sb.toString();
+ try {
+ if (-1 != string.indexOf('.')) {
+ return Double.valueOf(string);
+ }
+
+ String sign = "";
+ if (string.startsWith("-")) {
+ sign = "-";
+ string = string.substring(1);
+ }
+
+ if (string.toUpperCase().startsWith("0X")) {
+ return Long.valueOf(sign + string.substring(2),16);
+ }
+
+ if (string.equals("0")) {
+ return Long.valueOf(0);
+ }
+
+ if (string.startsWith("0")) {
+ return Long.valueOf(sign + string.substring(1),8);
+ }
+
+ return Long.valueOf(sign + string,10);
+ }
+
+ catch (NumberFormatException e) {
+ throw new IOException("Invalid number literal " + onLineCol(l,c));//NON-NLS
+ }
+
+ }
+
+ /**
+ *
+ */
+ private boolean isHexDigit(int c) {
+ switch (c) {
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ *
+ */
+ private boolean isOctalDigit(int c) {
+ switch (c) {
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7':
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ *
+ */
+ private boolean isDigitChar(int c) {
+ switch (c) {
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ case '.':
+ case 'e': case 'E':
+ case 'x': case 'X':
+ case '+': case '-':
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * only really need to handle 'null', 'true', and 'false'
+ */
+ private String readIdentifier() throws IOException {
+ StringBuffer sb = new StringBuffer();
+
+ while ((-1 != lastChar) && Character.isLetter((char)lastChar)) {
+ sb.append((char)lastChar);
+ readChar();
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ *
+ */
+ private void readChar() throws IOException {
+ if ('\n' == lastChar) {
+ this.colNo = 0;
+ this.lineNo++;
+ }
+
+ lastChar = reader.read();
+ if (-1 == lastChar) return ;
+
+ colNo++;
+ }
+
+ /**
+ *
+ */
+ private String onLineCol(int line, int col) {
+ return "on line " + line + ", column " + col;
+ }
+
+ /**
+ *
+ */
+ public String onLineCol() {
+ return onLineCol(lineNo,colNo);
+ }
+}
View
7 org.dojotoolkit.optimizer.amd.rhinoast/.classpath
@@ -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>
View
17 org.dojotoolkit.optimizer.amd.rhinoast/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.dojotoolkit.optimizer.amd.rhinoast</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>
View
16 org.dojotoolkit.optimizer.amd.rhinoast/META-INF/MANIFEST.MF
@@ -0,0 +1,16 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Rhinoast
+Bundle-SymbolicName: org.dojotoolkit.optimizer.amd.rhinoast
+Bundle-Version: 0.3.2
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Require-Bundle: org.dojotoolkit.optimizer
+Import-Package: org.dojotoolkit.json,
+ org.dojotoolkit.server.util.osgi,
+ org.dojotoolkit.server.util.resource,
+ org.dojotoolkit.server.util.rhino,
+ org.mozilla.javascript,
+ org.mozilla.javascript.ast
+Bundle-Activator: org.dojotoolkit.server.util.osgi.DojoServiceActivator
+Export-DojoService: org.dojotoolkit.optimizer.JSOptimizerFactory;impl=org.dojotoolkit.optimizer.amd.rhinoast.AMDJSOptimizerFactory;id=AMDRhinoASTJSOptimizer
+Export-Package: org.dojotoolkit.optimizer.amd.rhinoast
View
BIN ...mizer.amd.rhinoast/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizer$AstVisitor.class
Binary file not shown.
View
BIN ...optimizer.amd.rhinoast/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizer$Module.class
Binary file not shown.
View
BIN ...oolkit.optimizer.amd.rhinoast/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizer.class
Binary file not shown.
View
BIN ...optimizer.amd.rhinoast/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizerFactory.class
Binary file not shown.
View
623 ...kit.optimizer.amd.rhinoast/src/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizer.java
@@ -0,0 +1,623 @@
+/*
+ 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.optimizer.amd.rhinoast;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.dojotoolkit.json.JSONParser;
+import org.dojotoolkit.json.JSONSerializer;
+import org.dojotoolkit.optimizer.CachingJSOptimizer;
+import org.dojotoolkit.optimizer.JSAnalysisData;
+import org.dojotoolkit.optimizer.JSAnalysisDataImpl;
+import org.dojotoolkit.server.util.resource.ResourceLoader;
+import org.dojotoolkit.server.util.rhino.ASTCache;
+import org.dojotoolkit.server.util.rhino.RhinoClassLoader;
+import org.dojotoolkit.server.util.rhino.RhinoJSMethods;
+import org.mozilla.javascript.CompilerEnvirons;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.EvaluatorException;
+import org.mozilla.javascript.Parser;
+import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.ast.ArrayLiteral;
+import org.mozilla.javascript.ast.AstNode;
+import org.mozilla.javascript.ast.AstRoot;
+import org.mozilla.javascript.ast.FunctionCall;
+import org.mozilla.javascript.ast.Name;
+import org.mozilla.javascript.ast.NodeVisitor;
+import org.mozilla.javascript.ast.StringLiteral;
+
+public class AMDJSOptimizer extends CachingJSOptimizer {
+ private static Logger logger = Logger.getLogger("org.dojotoolkit.optimizer.amd.rhinoast");
+
+ private Map<String, Object> config = null;
+ private ASTCache astCacheHandler = null;
+ private RhinoClassLoader rhinoClassLoader = null;
+
+ public AMDJSOptimizer(ResourceLoader resourceLoader, RhinoClassLoader rhinoClassLoader, Map<String, Object> config, File tempDir) {
+ super(tempDir, resourceLoader);
+ this.config = config;
+ this.rhinoClassLoader = rhinoClassLoader;
+
+ Boolean useAstCache = (Boolean)config.get("astCache");
+ if (useAstCache != null && useAstCache == Boolean.TRUE) {
+ astCacheHandler = new ASTCache();
+ }
+ }
+
+ public Map<String, Object> getConfig() {
+ return config;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected JSAnalysisDataImpl _getAnalysisData(String[] modules, JSAnalysisData[] exclude, Map<String, Object> pageConfig) throws IOException {
+ JSAnalysisDataImpl jsAnalysisData = null;
+
+ Map<String, Object> fullConfig = new HashMap<String, Object>();
+ Map<String, Object> baseConfig = (Map<String, Object>)config.get("amdconfig");
+ fullConfig.putAll(baseConfig);
+ if (pageConfig != null) {
+ fullConfig.putAll(pageConfig);
+ }
+
+ Map<String, Object> cfg = new HashMap<String, Object>();
+ Map<String, Object> pkgs = new HashMap<String, Object>();
+ cfg.put("pkgs", pkgs);
+ cfg.put("paths", new HashMap<String, Object>());
+ cfg.put("baseUrl", "");
+ for (String key : fullConfig.keySet()) {
+ if (key.equals("packages")) {
+ List<Map<String, Object>> packages = (List<Map<String, Object>>)fullConfig.get("packages");
+ for (Map<String, Object> p : packages) {
+ String name = (String)p.get("name");
+ String location = (String)p.get("location");
+ if (location == null) {
+ location = name;
+ }
+ String main = (String)p.get("main");
+ if (main == null) {
+ main = "main";
+ }
+ Map<String, Object> pkg = new HashMap<String, Object>();
+ pkg.put("name", name);
+ pkg.put("location", location);
+ pkg.put("main", main);
+ pkgs.put(name, pkg);
+ }
+ } else {
+ cfg.put(key, fullConfig.get(key));
+ }
+ }
+ StringWriter sw = new StringWriter();
+ String pageConfigString = "";
+ try {
+ JSONSerializer.serialize(sw, cfg);
+ pageConfigString = sw.toString();
+ } catch (IOException e) {
+ logger.logp(Level.SEVERE, getClass().getName(), "_getAnalysisData", "IOException while parsing page configuration data", e);
+ throw new IOException("IOException while parsing page configuration data", e);
+ }
+
+ List<String> excludeList = new ArrayList<String>();
+ for (JSAnalysisData analysisData : exclude) {
+ for (String excludeModule : analysisData.getDependencies()) {
+ excludeModule = excludeModule.substring(0, excludeModule.indexOf(".js"));
+ if (!excludeList.contains(excludeModule)) {
+ excludeList.add(excludeModule);
+ }
+ }
+ }
+ if (fullConfig.containsKey("excludes")) {
+ List<String> configExcludes = (List<String>)fullConfig.get("excludes");
+ for (String excludeModule : configExcludes) {
+ if (excludeModule.charAt(0) != '/') {
+ excludeModule = '/'+excludeModule;
+ }
+ if (!excludeList.contains(excludeModule)) {
+ excludeList.add(excludeModule);
+ }
+ }
+ }
+ Map<String, List<Map<String, String>>> pluginRefs = new HashMap<String, List<Map<String, String>>>();
+ List<Map<String, Object>> missingNamesList = new ArrayList<Map<String, Object>>();
+ Map<String, Module> moduleMap = new HashMap<String, Module>();
+
+ for (String moduleId : modules) {
+ logger.logp(Level.INFO, getClass().getName(), "_getAnalysisData", "AST parsing ["+moduleId+"] using the Rhino AST API");
+ AstVisitor visitor = new AstVisitor(moduleId, moduleMap, pluginRefs, missingNamesList, cfg, new Stack<String>(), excludeList, pageConfigString);
+ if (visitor.getError() != null) {
+ logger.logp(Level.INFO, getClass().getName(), "_getAnalysisData", "AST parsing error for ["+moduleId+"] error : "+visitor.getError());
+ throw new IOException("AST parsing error for ["+moduleId+"] error : "+visitor.getError());
+ }
+ }
+
+ List<String> dependencies = new ArrayList<String>();
+ Map<String, Boolean> seen = new HashMap<String, Boolean>();
+ seen.put("require", Boolean.TRUE);
+ seen.put("module", Boolean.TRUE);
+ seen.put("exports", Boolean.TRUE);
+ for (String moduleId : modules) {
+ if (moduleId.indexOf('!') != -1) {
+ moduleId = moduleId.substring(0, moduleId.indexOf('!'));
+ }
+ Module m = moduleMap.get(moduleId);
+ buildDependencyList(m, moduleMap, dependencies, seen);
+ scanForCircularDependencies(m, new Stack<String>(), moduleMap);
+ }
+
+ jsAnalysisData = new JSAnalysisDataImpl(modules, dependencies, null, null, missingNamesList, pluginRefs, resourceLoader, JSAnalysisDataImpl.getExludes(exclude), pageConfig);
+ return jsAnalysisData;
+ }
+
+ private static String join(List<String> l, char separator) {
+ StringBuffer result = new StringBuffer();
+ for (String s : l) {
+ result.append(s);
+ result.append(separator);
+ }
+ if (result.length() > 0)
+ result.deleteCharAt(result.length()-1);
+ return result.toString();
+ }
+
+ private static void splice(List<String> l, int index, int howMany, String toInsert) {
+ for (int i = index; i < howMany; i++) {
+ l.remove(i);
+ }
+ l.add(index, toInsert);
+ }
+
+ private static String normalize(String path) {
+ try {
+ URI uri = new URI(path);
+ String normalized = uri.normalize().toString();
+ if (normalized.charAt(normalized.length()-1) == '/') {
+ normalized = normalized.substring(0, normalized.length()-1);
+ }
+ return normalized;
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ private static String idToUrl(String path, Map<String, Object> config) {
+ List<String> segments = new ArrayList<String>(Arrays.asList(path.split("/")));
+ Map<String, Object> paths = (Map<String, Object>)config.get("paths");
+ Map<String, Object> packages = (Map<String, Object>)config.get("pkgs");
+ String baseUrl = (String)config.get("baseUrl");
+ for (int i = segments.size(); i >= 0; i--) {
+ Map<String, Object> pkg;
+ String parent = join(segments.subList(0, i), '/');
+ if (paths.get(parent) != null) {
+ splice(segments, 0, i, (String)paths.get(parent));
+ break;
+ }else if ((pkg = (Map<String, Object>)packages.get(parent)) != null) {
+ String pkgPath;
+ if (path.equals((String)pkg.get("name"))) {
+ pkgPath = (String)pkg.get("location") + '/' + (String)pkg.get("main");
+ } else {
+ pkgPath = (String)pkg.get("location");
+ }
+ splice(segments, 0, i, pkgPath);
+ break;
+ }
+ }
+ path = join(segments, '/');
+ if (path.charAt(0) != '/') {
+ path = baseUrl + path;
+ }
+ path = normalize(path);
+ return path;
+ }
+
+ private static String getParentId(List<String> pathStack) {
+ return pathStack.size() > 0 ? pathStack.get(pathStack.size()-1) : "";
+ }
+
+ private static String expand(String path, List<String> pathStack, Map<String, Object> config) {
+ Map<String, Object> packages = (Map<String, Object>)config.get("pkgs");
+ if (path.charAt(0) == '.') {
+ Map<String, Object> pkg;
+ if ((pkg = (Map<String, Object>)packages.get(getParentId(pathStack))) != null) {
+ path = (String)pkg.get("name") + "/" + path;
+ } else {
+ path = getParentId(pathStack) + "/../" + path;
+ }
+ path = normalize(path);
+ }
+ for (String pkgName : packages.keySet()) {
+ if (path.equals(pkgName)) {
+ return (String)((Map<String, Object>)packages.get(pkgName)).get("name") + '/' + (String)((Map<String, Object>)packages.get(pkgName)).get("main");
+ }
+ }
+ return path;
+ }
+
+ private void buildDependencyList(Module m, Map<String, Module> moduleMap, List<String> dependencyList, Map<String, Boolean> seen) {
+ if (!seen.containsKey(m.uri)) {
+ seen.put(m.uri, Boolean.TRUE);
+ for (String dep : m.dependencies) {
+ Module depModule = moduleMap.get(dep);
+ if (depModule != null) {
+ buildDependencyList(depModule, moduleMap, dependencyList, seen);
+ } else {
+ if (!seen.containsKey(dep)) {
+ dependencyList.add(dep+".js");
+ seen.put(dep, Boolean.TRUE);
+ }
+ }
+ }
+ dependencyList.add(m.uri+".js");
+ }
+ }
+
+ private void scanForCircularDependencies(Module module, Stack<String> check, Map<String, Module> moduleMap) {
+ check.push(module.id);
+ for (String dep : module.dependencies) {
+ Module moduleDependency = moduleMap.get(dep);
+ if (moduleDependency.scanned) {
+ continue;
+ }
+ boolean found = false;
+ String dup = null;
+ for (String s : check) {
+ if (s.equals(moduleDependency.id)) {
+ found = true;
+ dup = moduleDependency.id;
+ break;
+ }
+ }
+ if (found) {
+ StringBuffer msg = new StringBuffer("Circular dependency found : ");
+ for (String s : check) {
+ msg.append(s);
+ msg.append("->");
+ }
+ msg.append(dup);
+ logger.logp(Level.INFO, getClass().getName(), "scanForCircularDependencies", msg.toString());
+ } else {
+ scanForCircularDependencies(moduleDependency, check, moduleMap);
+ }
+ }
+ module.scanned = true;
+ check.pop();
+ }
+
+ private class AstVisitor implements NodeVisitor {
+ private List<Map<String, Object>> missingNamesList = null;
+ private String moduleId = null;
+ private String url = null;
+ private Map<String, Module> moduleMap = null;
+ private Map<String, List<Map<String, String>>> pluginRefList = null;
+ private Map<String, Object> config = null;
+ private Stack<String> pathStack = null;
+ private List<String> excludeList = null;
+ private Module module = null;
+ private String baseUrl = null;
+ private String pageConfigString = null;
+ private String error = null;
+
+ public AstVisitor(String moduleId,
+ Map<String, Module> moduleMap,
+ Map<String, List<Map<String, String>>> pluginRefList,