| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ public void execute() throws BuildException { | |||
| 36 | 36 | throw new BuildException("dir parameter must be set!"); | |
| 37 | 37 | } | |
| 38 | 38 | ||
| 39 | - System.out.println("using basedir " + baseDir); | ||
| 39 | + //System.out.println("using basedir " + baseDir); | ||
| 40 | 40 | File graphicsFile = new File(baseDir, "PGraphics.java"); | |
| 41 | 41 | File appletFile = new File(baseDir, "PApplet.java"); | |
| 42 | 42 | File imageFile = new File(baseDir, "PImage.java"); | |
@@ -59,17 +59,19 @@ public void execute() throws BuildException { | |||
| 59 | 59 | } | |
| 60 | 60 | ||
| 61 | 61 | // Looking good, let's do this! | |
| 62 | - ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); | ||
| 63 | - PrintStream out = new PrintStream(outBytes); | ||
| 62 | + //ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); | ||
| 63 | + //PrintStream out = new PrintStream(outBytes, "UTF-8"); | ||
| 64 | + StringBuffer out = new StringBuffer(); | ||
| 64 | 65 | StringBuffer content = new StringBuffer(); | |
| 65 | 66 | ||
| 66 | 67 | try{ | |
| 67 | 68 | BufferedReader applet = createReader(appletFile); | |
| 68 | 69 | String line; | |
| 69 | 70 | while ((line = applet.readLine()) != null) { | |
| 70 | - out.println(line); | ||
| 71 | + out.append(line); | ||
| 72 | + out.append('\n'); // to avoid Windows CRs | ||
| 71 | 73 | content.append(line); | |
| 72 | - content.append('\n'); | ||
| 74 | + content.append('\n'); // for efficiency | ||
| 73 | 75 | ||
| 74 | 76 | if (line.indexOf("public functions for processing.core") >= 0) { | |
| 75 | 77 | break; | |
@@ -86,34 +88,38 @@ public void execute() throws BuildException { | |||
| 86 | 88 | process(out, graphicsFile); | |
| 87 | 89 | process(out, imageFile); | |
| 88 | 90 | ||
| 89 | - out.println("}"); | ||
| 91 | + out.append('}'); | ||
| 92 | + out.append('\n'); | ||
| 90 | 93 | ||
| 91 | - } catch (IOException e) { | ||
| 92 | - e.printStackTrace(); | ||
| 94 | + //} catch (IOException e) { | ||
| 95 | + //e.printStackTrace(); | ||
| 93 | 96 | ||
| 94 | - } catch(Exception ex) { | ||
| 95 | - ex.printStackTrace(); | ||
| 97 | + } catch (Exception e) { | ||
| 98 | + //ex.printStackTrace(); | ||
| 99 | + throw new BuildException(e); | ||
| 96 | 100 | } | |
| 97 | - out.flush(); | ||
| 101 | + //out.flush(); | ||
| 98 | 102 | ||
| 99 | - if (content.toString().equals(outBytes.toString())) { | ||
| 103 | + String outString = out.toString(); | ||
| 104 | + if (content.toString().equals(outString)) { | ||
| 100 | 105 | System.out.println("No changes to PApplet API."); | |
| 101 | 106 | } else { | |
| 102 | 107 | System.out.println("Updating PApplet with API changes " + | |
| 103 | 108 | "from PImage or PGraphics."); | |
| 104 | 109 | try { | |
| 105 | - PrintStream temp = new PrintStream(appletFile); | ||
| 106 | - temp.print(outBytes.toString()); | ||
| 110 | + PrintStream temp = new PrintStream(appletFile, "UTF-8"); | ||
| 111 | + temp.print(outString); | ||
| 107 | 112 | temp.flush(); | |
| 108 | 113 | temp.close(); | |
| 109 | - } catch (FileNotFoundException e) { | ||
| 110 | - e.printStackTrace(); | ||
| 114 | + } catch (IOException e) { | ||
| 115 | + //e.printStackTrace(); | ||
| 116 | + throw new BuildException(e); | ||
| 111 | 117 | } | |
| 112 | 118 | } | |
| 113 | 119 | } | |
| 114 | 120 | ||
| 115 | 121 | ||
| 116 | - private void process(PrintStream out, File input) throws IOException { | ||
| 122 | + private void process(StringBuffer out, File input) throws IOException { | ||
| 117 | 123 | BufferedReader in = createReader(input); | |
| 118 | 124 | int comments = 0; | |
| 119 | 125 | String line = null; | |
@@ -184,20 +190,22 @@ private void process(PrintStream out, File input) throws IOException { | |||
| 184 | 190 | line = line.replaceAll(Pattern.quote(";"), " {\n"); | |
| 185 | 191 | ||
| 186 | 192 | //out.println("\n\n" + line); | |
| 187 | - out.println(); | ||
| 188 | - out.println(); | ||
| 193 | + out.append('\n'); | ||
| 194 | + out.append('\n'); | ||
| 189 | 195 | // end has its own newline | |
| 190 | 196 | //out.print(commentBuffer.toString()); // TODO disabled for now XXXX | |
| 191 | - out.print(commentBuffer.toString()); // duplicates all comments | ||
| 197 | + out.append(commentBuffer.toString()); // duplicates all comments | ||
| 192 | 198 | commentBuffer.setLength(0); | |
| 193 | - out.println(line); | ||
| 199 | + out.append(line); | ||
| 200 | + out.append('\n'); | ||
| 194 | 201 | ||
| 195 | 202 | decl += line; | |
| 196 | 203 | while(line.indexOf(')') == -1) { | |
| 197 | 204 | line = in.readLine(); | |
| 198 | 205 | decl += line; | |
| 199 | 206 | line = line.replaceAll("\\;\\s*$", " {\n"); | |
| 200 | - out.println(line); | ||
| 207 | + out.append(line); | ||
| 208 | + out.append('\n'); | ||
| 201 | 209 | } | |
| 202 | 210 | ||
| 203 | 211 | result = Pattern.compile(".*?\\s(\\S+)\\(.*?").matcher(decl); | |
@@ -240,10 +248,13 @@ private void process(PrintStream out, File input) throws IOException { | |||
| 240 | 248 | rline += ");"; | |
| 241 | 249 | ||
| 242 | 250 | if (!gotStatic && returns.equals("")) { | |
| 243 | - out.println(rline); | ||
| 251 | + out.append(rline); | ||
| 252 | + out.append('\n'); | ||
| 244 | 253 | } | |
| 245 | - out.println(gline); | ||
| 246 | - out.println(" }"); | ||
| 254 | + out.append(gline); | ||
| 255 | + out.append('\n'); | ||
| 256 | + out.append(" }"); | ||
| 257 | + out.append('\n'); | ||
| 247 | 258 | ||
| 248 | 259 | } else { | |
| 249 | 260 | commentBuffer.setLength(0); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments