1 57 58 package org.apache.commons.jrcs.tools; 59 60 import java.io.BufferedReader ; 61 import java.io.FileReader ; 62 import java.io.IOException ; 63 import java.util.ArrayList ; 64 import java.util.Date ; 65 import java.util.List ; 66 67 import org.apache.commons.jrcs.diff.Diff; 68 import org.apache.commons.jrcs.diff.Revision; 69 70 71 79 public class JDiff 80 { 81 82 static final String [] loadFile(String name) throws IOException 83 { 84 BufferedReader data = new BufferedReader (new FileReader (name)); 85 List lines = new ArrayList (); 86 String s; 87 while ((s = data.readLine()) != null) 88 { 89 lines.add(s); 90 } 91 return (String [])lines.toArray(new String [lines.size()]); 92 } 93 94 static final void usage(String name) 95 { 96 System.err.println("Usage: " + name + " file1 file2"); 97 } 98 99 public static void main(String [] argv) throws Exception 100 { 101 if (argv.length < 2) 102 { 103 usage("JDiff"); 104 } 105 else 106 { 107 Object [] orig = loadFile(argv[0]); 108 Object [] rev = loadFile(argv[1]); 109 110 Diff df = new Diff(orig); 111 Revision r = df.diff(rev); 112 113 System.err.println("------"); 114 System.out.print(r.toString()); 115 System.err.println("------" + new Date ()); 116 117 try 118 { 119 Object [] reco = r.patch(orig); 120 if (!Diff.compare(rev, reco)) 122 { 123 System.err.println("INTERNAL ERROR:" 124 + "files differ after patching!"); 125 } 126 } 127 catch (Throwable o) 128 { 129 System.out.println("Patch failed"); 130 } 131 } 132 } 133 } 134 135 | Popular Tags |