Changeset 7907

Show
Ignore:
Timestamp:
04/02/07 15:33:56 (22 months ago)
Author:
jburke
Message:

Fixes #2407 and Refs #2386. dojo compressing now works over multiple files in the same process. Layer files are now compressed, and it is possible to compress all files in the src directory via the strip-resource-comments ant task. Specify that task and a -Dstrip_and_compress=true to ant.

Location:
branches/0.4/buildscripts
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • branches/0.4/buildscripts/build.xml

    r7574 r7907  
    3939        <property name="release_website_dir" value="/srv/www/htdocs"/> 
    4040        <property name="profile" value=""/> 
     41        <property name="strip_and_compress" value="false"/> 
    4142        <property name="locales" value="en-gb,en-us,de-de,es-es,fr-fr,it-it,pt-br,ko-kr,zh-tw,zh-cn,ja-jp"/> 
    4243        <!-- FIXME: where should this list come from? --> 
     
    284285                                logerror="true"> 
    285286                        <arg value="stripComments.js" /> 
    286                         <arg value="${release_dir}"/> 
     287                        <arg value="${release_dir}/src"/> 
     288                        <arg value="false"/> 
     289                        <arg value="${strip_and_compress}"/> 
    287290                </java> 
    288291        </target> 
  • branches/0.4/buildscripts/buildUtil.js

    r7803 r7907  
    10041004} 
    10051005 
    1006 buildUtil.stripComments = function(/*String*/startDir, /*boolean*/suppressDojoCopyright){ 
     1006buildUtil.stripComments = function(/*String*/startDir, /*boolean*/suppressDojoCopyright, /*boolean*/doCompress){ 
    10071007        //summary: strips the JS comments from all the files in "startDir", and all subdirectories. 
    10081008        var copyright = suppressDojoCopyright ? "" : (new String(buildUtil.readFile("copyright.txt")) + buildUtil.getLineSeparator()); 
     
    10241024                                //Do comment removal. 
    10251025                                try{ 
    1026                                         fileContents = buildUtil.optimizeJs(fileList[i], fileContents, copyright, false); 
     1026                                        fileContents = buildUtil.optimizeJs(fileList[i], fileContents, copyright, doCompress); 
    10271027                                }catch(e){ 
    10281028                                        print("Could not strip comments for file: " + fileList[i] + ", error: " + e); 
  • branches/0.4/buildscripts/lib/custom_rhino.diff

    r5877 r7907  
     1### Eclipse Workspace Patch 1.0 
     2#P rhino 
    13Index: src/org/mozilla/javascript/BaseFunction.java 
    24=================================================================== 
     
    57diff -u -r1.57 BaseFunction.java 
    68--- src/org/mozilla/javascript/BaseFunction.java        30 Aug 2005 10:05:42 -0000      1.57 
    7 +++ src/org/mozilla/javascript/BaseFunction.java        2 Jun 2006 09:19:22 -0000 
     9+++ src/org/mozilla/javascript/BaseFunction.java        2 Apr 2007 22:06:50 -0000 
    810@@ -373,6 +373,28 @@ 
    911         return sb.toString(); 
     
    3537  
    3638     public int getLength() { return 0; } 
     39Index: src/org/mozilla/javascript/NativeFunction.java 
     40=================================================================== 
     41RCS file: /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/NativeFunction.java,v 
     42retrieving revision 1.62 
     43diff -u -r1.62 NativeFunction.java 
     44--- src/org/mozilla/javascript/NativeFunction.java      17 Jan 2005 13:06:33 -0000      1.62 
     45+++ src/org/mozilla/javascript/NativeFunction.java      2 Apr 2007 22:06:50 -0000 
     46@@ -70,6 +70,26 @@ 
     47         } 
     48     } 
     49  
     50+    /** 
     51+     * Compress the script. 
     52+     * <p> 
     53+     *  
     54+     * @param parseTree Mapping for each function node and corresponding parameters & variables names 
     55+     * @param indent How much to indent the decompiled result 
     56+     * @param flags Flags specifying format of decompilation output 
     57+     * @return compressed script 
     58+     */ 
     59+    final String compress(ScriptOrFnNode parseTree, int indent, int flags) 
     60+    { 
     61+        String encodedSource = getEncodedSource(); 
     62+        if (encodedSource == null) { 
     63+            return super.compress(indent, flags); 
     64+        } else { 
     65+            UintMap properties = new UintMap(1); 
     66+            properties.put(Decompiler.INITIAL_INDENT_PROP, indent); 
     67+            return Decompiler.compress(encodedSource, flags, properties, parseTree); 
     68+        } 
     69+    } 
     70     public int getLength() 
     71     { 
     72         int paramCount = getParamCount(); 
     73Index: src/org/mozilla/javascript/TokenStream.java 
     74=================================================================== 
     75RCS file: /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/TokenStream.java,v 
     76retrieving revision 1.63 
     77diff -u -r1.63 TokenStream.java 
     78--- src/org/mozilla/javascript/TokenStream.java 31 Jul 2005 13:48:46 -0000      1.63 
     79+++ src/org/mozilla/javascript/TokenStream.java 2 Apr 2007 22:06:50 -0000 
     80@@ -64,9 +64,12 @@ 
     81     private final static int 
     82         EOF_CHAR = -1; 
     83  
     84+    public StringBuffer lastComment; 
     85+     
     86     TokenStream(Parser parser, Reader sourceReader, String sourceString, 
     87                 int lineno) 
     88     { 
     89+       this.lastComment = new StringBuffer(); 
     90         this.parser = parser; 
     91         this.lineno = lineno; 
     92         if (sourceReader != null) { 
     93@@ -736,6 +739,8 @@ 
     94  
     95             case '/': 
     96                 // is it a // comment? 
     97+               // FIXME: RAR: comment, need to set config to optionally keep 
     98+               // instead of skipping! 
     99                 if (matchChar('/')) { 
     100                     skipLine(); 
     101                     continue retry; 
    37102Index: src/org/mozilla/javascript/Context.java 
    38103=================================================================== 
     
    41106diff -u -r1.244 Context.java 
    42107--- src/org/mozilla/javascript/Context.java     4 Nov 2005 13:37:45 -0000       1.244 
    43 +++ src/org/mozilla/javascript/Context.java     2 Jun 2006 09:19:26 -0000 
     108+++ src/org/mozilla/javascript/Context.java     2 Apr 2007 22:06:50 -0000 
    44109@@ -1178,6 +1178,33 @@ 
    45110         } 
     
    76141      * Check whether a string is ready to be compiled. 
    77142      * <p> 
    78 @@ -1361,6 +1388,27 @@ 
     143@@ -1361,6 +1388,33 @@ 
    79144     } 
    80145  
     
    90155+    public final String compressScript(Script script, int indent, String source,int lineno) 
    91156+    { 
     157+        //Make sure to clear out the TokenMapper state before running. 
     158+        //This allows for more than one script to be compressed. 
     159+        //However, this is not a very clean way to do the reset. 
     160+        TokenMapper.reset(); 
     161+        Decompiler.tm = new TokenMapper(); 
     162+ 
    92163+        NativeFunction scriptImpl = (NativeFunction) script; 
    93164+         
     
    104175      * <p> 
    105176      * Decompiles a previously compiled JavaScript function object to 
    106 @@ -2240,7 +2288,6 @@ 
     177@@ -2240,7 +2294,6 @@ 
    107178                 sourceReader = null; 
    108179             } 
     
    112183         if (returnFunction) { 
    113184             p.calledByCompileFunction = true; 
    114 @@ -2251,6 +2298,7 @@ 
     185@@ -2251,6 +2304,7 @@ 
    115186         } else { 
    116187             tree = p.parse(sourceReader, sourceName, lineno); 
     
    126197diff -u -r1.19 Decompiler.java 
    127198--- src/org/mozilla/javascript/Decompiler.java  28 Aug 2005 23:25:22 -0000      1.19 
    128 +++ src/org/mozilla/javascript/Decompiler.java  2 Jun 2006 09:19:28 -0000 
     199+++ src/org/mozilla/javascript/Decompiler.java  2 Apr 2007 22:06:50 -0000 
    129200@@ -37,6 +37,11 @@ 
    130201  
     
    139210  * The following class save decompilation information about the source. 
    140211  * Source information is returned from the parser as a String 
    141 @@ -70,6 +75,264 @@ 
     212@@ -70,6 +75,272 @@ 
    142213  * the final constant pool entry from information available at parse 
    143214  * time. 
     
    169240+ 
    170241+       private int lastTokenCount = 0; 
     242+ 
     243+       /** 
     244+        * Reset the static members for the TokenMapper. 
     245+        */ 
     246+       public static void reset() { 
     247+               funcObjects = new ObjArray(); 
     248+               functionVarMappings = new ArrayList(); 
     249+       } 
    171250+ 
    172251+       /** 
     
    404483 { 
    405484     /** 
    406 @@ -266,6 +529,512 @@ 
     485@@ -266,6 +537,515 @@ 
    407486         return new String(sourceBuffer, offset, sourceTop - offset); 
    408487     } 
    409488  
    410 +    private static TokenMapper tm = new TokenMapper(); 
     489+    //Used to be private, but making it public so we 
     490+    //can reset the token state between compression runs. 
     491+    //Not very pretty. 
     492+    public static TokenMapper tm = new TokenMapper(); 
    411493+     
    412494+    /** 
     
    917999      * Decompile the source information associated with this js 
    9181000      * function/script back into a string.  For the most part, this 
    919 Index: src/org/mozilla/javascript/NativeFunction.java 
    920 =================================================================== 
    921 RCS file: /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/NativeFunction.java,v 
    922 retrieving revision 1.62 
    923 diff -u -r1.62 NativeFunction.java 
    924 --- src/org/mozilla/javascript/NativeFunction.java      17 Jan 2005 13:06:33 -0000      1.62 
    925 +++ src/org/mozilla/javascript/NativeFunction.java      2 Jun 2006 09:19:28 -0000 
    926 @@ -70,6 +70,26 @@ 
    927          } 
    928      } 
    929   
    930 +    /** 
    931 +     * Compress the script. 
    932 +     * <p> 
    933 +     *  
    934 +     * @param parseTree Mapping for each function node and corresponding parameters & variables names 
    935 +     * @param indent How much to indent the decompiled result 
    936 +     * @param flags Flags specifying format of decompilation output 
    937 +     * @return compressed script 
    938 +     */ 
    939 +    final String compress(ScriptOrFnNode parseTree, int indent, int flags) 
    940 +    { 
    941 +        String encodedSource = getEncodedSource(); 
    942 +        if (encodedSource == null) { 
    943 +            return super.compress(indent, flags); 
    944 +        } else { 
    945 +            UintMap properties = new UintMap(1); 
    946 +            properties.put(Decompiler.INITIAL_INDENT_PROP, indent); 
    947 +            return Decompiler.compress(encodedSource, flags, properties, parseTree); 
    948 +        } 
    949 +    } 
    950      public int getLength() 
    951      { 
    952          int paramCount = getParamCount(); 
    953 Index: src/org/mozilla/javascript/TokenStream.java 
    954 =================================================================== 
    955 RCS file: /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/TokenStream.java,v 
    956 retrieving revision 1.63 
    957 diff -u -r1.63 TokenStream.java 
    958 --- src/org/mozilla/javascript/TokenStream.java 31 Jul 2005 13:48:46 -0000      1.63 
    959 +++ src/org/mozilla/javascript/TokenStream.java 2 Jun 2006 09:19:29 -0000 
    960 @@ -64,9 +64,12 @@ 
    961      private final static int 
    962          EOF_CHAR = -1; 
    963   
    964 +    public StringBuffer lastComment; 
    965 +     
    966      TokenStream(Parser parser, Reader sourceReader, String sourceString, 
    967                  int lineno) 
    968      { 
    969 +       this.lastComment = new StringBuffer(); 
    970          this.parser = parser; 
    971          this.lineno = lineno; 
    972          if (sourceReader != null) { 
    973 @@ -736,6 +739,8 @@ 
    974   
    975              case '/': 
    976                  // is it a // comment? 
    977 +               // FIXME: RAR: comment, need to set config to optionally keep 
    978 +               // instead of skipping! 
    979                  if (matchChar('/')) { 
    980                      skipLine(); 
    981                      continue retry; 
    9821001Index: toolsrc/org/mozilla/javascript/tools/resources/Messages.properties 
    9831002=================================================================== 
     
    9861005diff -u -r1.22 Messages.properties 
    9871006--- toolsrc/org/mozilla/javascript/tools/resources/Messages.properties  2 Sep 2005 14:18:40 -0000       1.22 
    988 +++ toolsrc/org/mozilla/javascript/tools/resources/Messages.properties  2 Jun 2006 09:19:30 -0000 
     1007+++ toolsrc/org/mozilla/javascript/tools/resources/Messages.properties  2 Apr 2007 22:06:50 -0000 
    9891008@@ -55,7 +55,9 @@ 
    9901009     \    -version 100|110|120|130|140|150\n\ 
     
    10041023diff -u -r1.65 Main.java 
    10051024--- toolsrc/org/mozilla/javascript/tools/shell/Main.java        30 Sep 2005 08:28:51 -0000      1.65 
    1006 +++ toolsrc/org/mozilla/javascript/tools/shell/Main.java        2 Jun 2006 09:19:31 -0000 
     1025+++ toolsrc/org/mozilla/javascript/tools/shell/Main.java        2 Apr 2007 22:06:50 -0000 
    10071026@@ -66,6 +66,11 @@ 
    10081027     static private final int EXITCODE_RUNTIME_ERROR = 3; 
  • branches/0.4/buildscripts/makeDojoJs.js

    r7738 r7907  
    1616//Save the other layers, if there are any. 
    1717for(var i = 1; i < result.length; i++){ 
    18         buildUtil.saveFile(releaseDir + "/" + result[i].layerName, result[i].contents); 
     18        var layerName = releaseDir + "/" + result[i].layerName; 
     19        var uncompressedLayerName = layerName + ".uncompressed.js"; 
     20 
     21        buildUtil.saveFile(uncompressedLayerName, result[i].contents); 
     22         
     23        //Compress the layer files. It is clunky to do it here and have dojo.js 
     24        //compression done elsewhere. This will be fixed in 0.9 re-org. 
     25        print("Compressing file: " + layerName); 
     26 
     27        var copyright = new String(buildUtil.readFile("copyright.txt")); 
     28 
     29        //Load the file contents and optimize. 
     30        var fileContents = new String(buildUtil.readFile(uncompressedLayerName)); 
     31        fileContents = buildUtil.optimizeJs(uncompressedLayerName, fileContents, copyright, true); 
     32         
     33        //Save the optimized file. 
     34        buildUtil.saveFile(layerName, fileContents); 
    1935} 
    2036 
  • branches/0.4/buildscripts/stripComments.js

    r7308 r7907  
    11load("buildUtil.js"); 
    2 buildUtil.stripComments(arguments[0], arguments[1]); 
     2 
     3var startDir = arguments[0]; 
     4 
     5var suppressDojoCopyright =  arguments[1]; 
     6if(suppressDojoCopyright == "true"){ 
     7        suppressDojoCopyright = true; 
     8}else{ 
     9        suppressDojoCopyright = false; 
     10} 
     11 
     12var doCompress =  arguments[2]; 
     13if(doCompress == "true"){ 
     14        doCompress = true; 
     15}else{ 
     16        doCompress = false; 
     17} 
     18 
     19print(suppressDojoCopyright + ", " + doCompress); 
     20 
     21buildUtil.stripComments(startDir, suppressDojoCopyright, doCompress);