| 37 | |
| 38 | |
| 39 | public void execute() throws BuildException { |
| 40 | // Do a bunch of checks... |
| 41 | if (baseDir == null) { |
| 42 | throw new BuildException("dir parameter must be set!"); |
| 43 | } |
| 44 | |
| 45 | //System.out.println("using basedir " + baseDir); |
| 46 | File graphicsFile = new File(baseDir, "PGraphics.java"); |
| 47 | File appletFile = new File(baseDir, "PApplet.java"); |
| 48 | File imageFile = new File(baseDir, "PImage.java"); |
| 49 | |
| 50 | if (!graphicsFile.exists() || !graphicsFile.canRead()) { |
| 51 | throw new BuildException("PGraphics file not readable: " + |
| 52 | graphicsFile.getAbsolutePath()); |
| 53 | } |
| 54 | |
| 55 | if (!appletFile.exists() || |
| 56 | !appletFile.canRead() || |
| 57 | !appletFile.canWrite()) { |
| 58 | throw new BuildException("PApplet file not read/writeable: " + |
| 59 | appletFile.getAbsolutePath()); |
| 60 | } |
| 61 | |
| 62 | if (!imageFile.exists() || !imageFile.canRead()) { |
| 63 | throw new BuildException("PImage file not readable: " + |
| 64 | imageFile.getAbsolutePath()); |
| 65 | } |
| 66 | |
| 67 | // Looking good, let's do this! |
| 68 | //ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); |
| 69 | //PrintStream out = new PrintStream(outBytes, "UTF-8"); |
| 70 | StringBuilder out = new StringBuilder(); |
| 71 | StringBuilder content = new StringBuilder(); |
| 72 | |
| 73 | try{ |
| 74 | BufferedReader applet = createReader(appletFile); |
| 75 | String line; |
| 76 | while ((line = applet.readLine()) != null) { |
| 77 | out.append(line); |
| 78 | out.append('\n'); // to avoid Windows CRs |
| 79 | content.append(line); |
| 80 | content.append('\n'); // for efficiency |
| 81 | |
| 82 | if (line.indexOf("public functions for processing.core") >= 0) { |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // read the rest of the file and append it to the |
| 88 | while ((line = applet.readLine()) != null) { |
| 89 | content.append(line); |
| 90 | content.append('\n'); |
| 91 | } |
| 92 | |
| 93 | applet.close(); |
| 94 | process(out, graphicsFile); |
| 95 | process(out, imageFile); |
| 96 | |