[OpenLayers-Commits] r11448 - in trunk/openlayers: build tools

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Thu Feb 24 18:19:53 EST 2011


Author: crschmidt
Date: 2011-02-24 15:19:53 -0800 (Thu, 24 Feb 2011)
New Revision: 11448

Added:
   trunk/openlayers/tools/closure.py
Modified:
   trunk/openlayers/build/README.txt
   trunk/openlayers/build/build.py
   trunk/openlayers/tools/closure_ws.py
Log:
Adding support for closure compiler and some documentation
in the README about how to use it.


Modified: trunk/openlayers/build/README.txt
===================================================================
--- trunk/openlayers/build/README.txt	2011-02-24 23:14:21 UTC (rev 11447)
+++ trunk/openlayers/build/README.txt	2011-02-24 23:19:53 UTC (rev 11448)
@@ -1,14 +1,43 @@
+The OpenLayers build tool supports several different
+forms of compressing your javascript code, and a method
+of describing build profiles to create customized 
+OpenLayers builds with only the components you need.
 
-## HowTo: Build & deploy "Shrunk" Single File Library version of OpenLayers ##
+When building a file, you can choose to build with several
+different compression options to the Python-based build.py
+script. The following is an example script:
 
- * Build:
+python build.py -c closure full OpenLayers-closure.js
 
-     cd build
-     ./build.py
-     cd ..
+This script selects the 'closure' compression mechanism,
+uses a config file called 'full.cfg', and writes the output
+to OpenLayers-closure.js.
 
- * Upload the result to the server: e.g.
+The options available for compression are:
 
-  scp build/OpenLayers.js openlayers at openlayers.org:openlayers.org/htdocs/code/
+ * closure
+   This requires you to have a closure-compiler.jar in your
+   tools directory. You can do this by fetching the compiler
+   from:
 
+     http://closure-compiler.googlecode.com/files/compiler-latest.zip
 
+   Then unzipping that file, and placing compiler.jar into tools
+   and renaming it closure-compiler.jar.
+
+ * closure_ws
+   This uses the closure compiler webservice. This will only work
+   for files source Javascript files which are under 1MB. (Note that
+   the default OpenLayers full build is not under 1MB.)
+
+ * jsmin
+   jsmin is the default compiler, and uses the Python-based
+   jsmin script to compress the Javascript. 
+
+ * minimize
+   This is a simple whitespace removing Python script, designed
+   to fill in when other tools are unavailable.
+
+ * none
+   None will leave the Javascript uncompressed.
+

Modified: trunk/openlayers/build/build.py
===================================================================
--- trunk/openlayers/build/build.py	2011-02-24 23:14:21 UTC (rev 11447)
+++ trunk/openlayers/build/build.py	2011-02-24 23:19:53 UTC (rev 11448)
@@ -13,6 +13,11 @@
     except ImportError:
         print "No jsmin"
     try:
+        import closure
+        have_compressor.append("closure")
+    except ImportError, E:
+        print "No closure (%s) % E"
+    try:
         import closure_ws
         have_compressor.append("closure_ws")
     except ImportError:
@@ -51,6 +56,8 @@
         minimized = minimize.minimize(merged)
     elif use_compressor == "closure_ws":
         minimized = closure_ws.minimize(merged)      
+    elif use_compressor == "closure":
+        minimized = closure.minimize(merged)      
     else: # fallback
         minimized = merged 
     print "Adding license file."

Added: trunk/openlayers/tools/closure.py
===================================================================
--- trunk/openlayers/tools/closure.py	                        (rev 0)
+++ trunk/openlayers/tools/closure.py	2011-02-24 23:19:53 UTC (rev 11448)
@@ -0,0 +1,21 @@
+import sys
+import os
+import tempfile
+
+path = os.path.join(os.path.dirname(__file__), "closure-compiler.jar")
+if not os.path.exists(path):
+    raise Exception("No closure-compiler.jar at %s; read README.txt!" % path)
+
+def minimize(code):
+    ntf = tempfile.NamedTemporaryFile()
+    ntf.write(code)
+    ntf.flush()
+
+    ntf2 = tempfile.NamedTemporaryFile()
+
+    os.system("java -jar %s --js %s --js_output_file %s" % (path, ntf.name, ntf2.name))
+    ntf2.seek(0)
+    data = ntf2.read()
+    ntf.close()
+    ntf2.close()
+    return data

Modified: trunk/openlayers/tools/closure_ws.py
===================================================================
--- trunk/openlayers/tools/closure_ws.py	2011-02-24 23:14:21 UTC (rev 11447)
+++ trunk/openlayers/tools/closure_ws.py	2011-02-24 23:19:53 UTC (rev 11448)
@@ -22,5 +22,7 @@
     response = conn.getresponse()
     data = response.read()
     conn.close()
-    print "%.3f seconds to compile", time.time() - t 
+    if data.startswith("Error"):
+        raise Exception(data)
+    print "%.3f seconds to compile" % (time.time() - t) 
     return data



More information about the Commits mailing list