| 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 | } |
| 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 | |