protected Flags runDiff( SourceFile vmFile, SourceFile cpFile, String diffFileName, Map<String, String> packageDiffs) throws IOException, InterruptedException { final String[] cmd = { "diff", "-b", // Ignore white space change // "-E", // Ignore changes due to tab expansion // "-w", // Ignore all white space change // "-B", // Ignore changes whose lines are all blank // "-N", // Treat absent files as empty "-au", "-I", ".*$" + "Id:.*$.*", // Avoid cvs keyword // expansion in this string vmFile.getFileName(), cpFile.getFile().getAbsolutePath() }; final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ByteArrayOutputStream err = new ByteArrayOutputStream(); final PumpStreamHandler streamHandler = new PumpStreamHandler(out, err); final Execute exe = new Execute(streamHandler); exe.setCommandline(cmd); exe.setWorkingDirectory(vmFile.getBaseDir()); final int rc = exe.execute(); if ((rc != 0) && (out.size() > 0)) { File diffFile = new File(destDir, diffFileName); FileOutputStream os = new FileOutputStream(diffFile); try { final byte[] diff = out.toByteArray(); os.write(diff); os.flush(); final String diffStr = new String(diff); final String pkg = vmFile.getPackageName(); String pkgDiff; if (packageDiffs.containsKey(pkg)) { pkgDiff = packageDiffs.get(pkg); pkgDiff = pkgDiff + "diff\n" + diffStr; } else { pkgDiff = diffStr; } packageDiffs.put(pkg, pkgDiff); Flags flags = getFlags(diffStr); if (!vmFile.getTarget().equals(cpFile.getTarget())) { flags.set(FLAG_TARGET_DIFF); } flags.set(NEEDS_MERGE); return flags; } finally { os.close(); } } else { return new Flags(NO_CHANGE); } }
protected Flags getFlags(SourceFile file) throws IOException { final FileReader fr = new FileReader(file.getFile()); try { final BufferedReader in = new BufferedReader(fr); // final StringBuffer b = new StringBuffer(); String line; final Flags flags = new Flags(); while ((line = in.readLine()) != null) { getFlags(line.toString(), flags); // b.append(line); // b.append('\n'); } return flags; } finally { fr.close(); } }