Changeset 7302

Show
Ignore:
Timestamp:
02/13/07 16:56:41 (22 months ago)
Author:
jburke
Message:

References #2366. Got a working comment stripping.

Location:
branches/0.4/buildscripts
Files:
2 modified

Legend:

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

    r7103 r7302  
    279279        <!-- end gen-strip-docs task --> 
    280280 
     281        <!-- strip-resource-comments --> 
     282                <target name="strip-resource-comments"> 
     283                <java jar="./lib/custom_rhino.jar" failonerror="true" fork="true"  
     284                                logerror="true"> 
     285                        <arg value="stripComments.js" /> 
     286                        <arg value="${release_dir}"/> 
     287                </java> 
     288        </target> 
     289        <!-- end strip-resource-comments --> 
     290 
    281291        <!-- src task --> 
    282292        <target name="src" 
  • branches/0.4/buildscripts/buildUtil.js

    r7284 r7302  
    860860                        //Don't process dojo.js since it has already been processed. 
    861861                        //Don't process dojo.js.uncompressed.js because it is huge. 
    862                         if(!fileList[i].match(/dojo\.js$/) && !fileList[i].match(/dojo\.js\.uncompressed\.js$/)){ 
     862                        //Don't process anything that might be in a buildscripts folder (only a concern for webbuild.sh) 
     863                        if(!fileList[i].match(/dojo\.js$/) 
     864                                && !fileList[i].match(/dojo\.js\.uncompressed\.js$/) 
     865                                && !fileList[i].match(/buildscripts/)){ 
    863866                                print("Stripping comments from file: " + fileList[i]); 
    864867                                 
     
    870873                                 
    871874                                //Get rid of cr, lf, since it messes up matching. 
    872                                 fileContents = fileContents.replace(/\r/g, "__DOJOCARRIAGERETURN__").replace(/\n/g, "__DOJONEWLINE__"); 
    873                                 var multiLineMatches = fileContents.match(/\/\*.*?copyright.*?\*\//gi); 
     875                                copyrightFileContents = fileContents.replace(/\r/g, "__DOJOCARRIAGERETURN__").replace(/\n/g, "__DOJONEWLINE__"); 
     876                                var multiLineMatches = copyrightFileContents.match(/\/\*.*?copyright.*?\*\//gi); 
    874877 
    875878                                //Finalize copyright notice. 
     
    887890 
    888891                                //Remove whitespace. 
    889                                 var commandResults = buildUtil.runCommand("java -jar lib/custom_rhinoPrettyPrint.jar -strict -opt -1 -p " + fileList[i]); 
     892                                var context = Packages.org.mozilla.javascript.Context.enter(); 
     893                                try{ 
     894                                        // Use the interpreter for interactive input (copied this from Main rhino class). 
     895                                        context.setOptimizationLevel(-1); 
     896                                         
     897                                        var script = context.compileString(fileContents, fileList[i], 1, null); 
     898                                        fileContents = new String(context.decompileScript(script, 0)); 
     899                                }catch(e){ 
     900                                        print("Could not strip comments for file: " + fileList[i]); 
     901                                }finally{ 
     902                                        Packages.org.mozilla.javascript.Context.exit(); 
     903                                } 
    890904                                 
    891                                 if(commandResults.error){ 
    892                                         print("ERROR. Skipping file. Error is: " + commandResults.error); 
    893                                 }else{ 
    894                                         fileContents = commandResults.result; 
    895          
    896                                         //Replace the spaces with tabs. 
    897                                         //Ideally do this in the pretty printer rhino code. 
    898                                         fileContents = fileContents.replace(/    /g, "\t"); 
    899                                          
    900                                         //Write out the file with appropriate copyright. 
    901                                         buildUtil.saveUtf8File(fileList[i], copyrightText + buildUtil.getLineSeparator() + fileContents); 
    902                                 } 
    903                         } 
    904                 } 
    905         } 
    906 } 
    907  
    908 buildUtil.runCommand = function(/*String*/commandLineCommand){ 
    909         //summary: runs a command on the command line. 
    910         var process = java.lang.Runtime.getRuntime().exec(commandLineCommand); 
    911         var resultReader = new java.io.BufferedReader(new java.io.InputStreamReader(process.getInputStream())); 
    912         var resultLine = null; 
    913         var result = ""; 
    914         var lineSeparator = buildUtil.getLineSeparator(); 
    915  
    916         var error = ""; 
    917         var errorReader = new java.io.BufferedReader(new java.io.InputStreamReader(process.getErrorStream())); 
    918         //Only read one line of error, since waiting for all of it seems to hang. 
    919         //TODO: Fix that. There should be a way to get the complete error message. 
    920         if((resultLine = errorReader.readLine()) != null){ 
    921                 error += new String(resultLine) + lineSeparator; 
    922         } 
    923  
    924         if(error){ 
    925                 error = error.replace(/^\s*/, "").replace(/\s*$/, ""); 
    926         }else{ 
    927                 while((resultLine = resultReader.readLine()) != null){ 
    928                         result += new String(resultLine) + lineSeparator; 
    929                 } 
    930         } 
    931  
    932         return {result: result, error: error}; //String 
    933 } 
     905                                //Replace the spaces with tabs. 
     906                                //Ideally do this in the pretty printer rhino code. 
     907                                fileContents = fileContents.replace(/    /g, "\t"); 
     908                                 
     909                                //Write out the file with appropriate copyright. 
     910                                buildUtil.saveUtf8File(fileList[i], copyrightText + buildUtil.getLineSeparator() + fileContents); 
     911                        } 
     912                } 
     913        } 
     914} 
     915