1 32 33 package com.jeantessier.dependencyfinder.ant; 34 35 import java.io.*; 36 import java.util.*; 37 38 import org.apache.tools.ant.*; 39 import org.apache.tools.ant.types.*; 40 41 import com.jeantessier.classreader.*; 42 import com.jeantessier.dependency.*; 43 import com.jeantessier.diff.*; 44 45 public class JarJarDiff extends Task { 46 private String name = ""; 47 private Path oldPath; 48 private String oldLabel; 49 private File oldDocumentation = new File("old_documentation.txt"); 50 private Path newPath; 51 private String newLabel; 52 private File newDocumentation = new File("new_documentation.txt"); 53 private String encoding = Report.DEFAULT_ENCODING; 54 private String dtdPrefix = Report.DEFAULT_DTD_PREFIX; 55 private String indentText; 56 private File destfile; 57 58 public String getName() { 59 return name; 60 } 61 62 public void setName(String name) { 63 this.name = name; 64 } 65 66 public Path createOld() { 67 if (oldPath == null) { 68 oldPath = new Path(getProject()); 69 } 70 71 return oldPath; 72 } 73 74 public Path getOld() { 75 return oldPath; 76 } 77 78 public String getOldlabel() { 79 return oldLabel; 80 } 81 82 public void setOldlabel(String oldLabel) { 83 this.oldLabel = oldLabel; 84 } 85 86 public File getOlddocumentation() { 87 return oldDocumentation; 88 } 89 90 public void setOlddocumentation(File oldDocumentation) { 91 this.oldDocumentation = oldDocumentation; 92 } 93 94 public Path createNew() { 95 if (newPath == null) { 96 newPath = new Path(getProject()); 97 } 98 99 return newPath; 100 } 101 102 public Path getNew() { 103 return newPath; 104 } 105 106 public String getNewlabel() { 107 return newLabel; 108 } 109 110 public void setNewlabel(String newLabel) { 111 this.newLabel = newLabel; 112 } 113 114 public File getNewdocumentation() { 115 return newDocumentation; 116 } 117 118 public void setNewdocumentation(File newDocumentation) { 119 this.newDocumentation = newDocumentation; 120 } 121 122 public String getEncoding() { 123 return encoding; 124 } 125 126 public void setEncoding(String encoding) { 127 this.encoding = encoding; 128 } 129 130 public String getDtdprefix() { 131 return dtdPrefix; 132 } 133 134 public void setDtdprefix(String dtdPrefix) { 135 this.dtdPrefix = dtdPrefix; 136 } 137 138 public String getIndenttext() { 139 return indentText; 140 } 141 142 public void setIntenttext(String indentText) { 143 this.indentText = indentText; 144 } 145 146 public File getDestfile() { 147 return destfile; 148 } 149 150 public void setDestfile(File destfile) { 151 this.destfile = destfile; 152 } 153 154 public void execute() throws BuildException { 155 157 if (getOld() == null) { 158 throw new BuildException("old must be set!"); 159 } 160 161 if (getNew() == null) { 162 throw new BuildException("new must be set!"); 163 } 164 165 if (getDestfile() == null) { 166 throw new BuildException("destfile must be set!"); 167 } 168 169 VerboseListener verboseListener = new VerboseListener(this); 170 171 try { 172 175 log("Loading old classes from path " + getOld()); 176 Validator oldValidator = new ListBasedValidator(getOlddocumentation()); 177 ClassfileLoader oldJar = new AggregatingClassfileLoader(); 178 oldJar.addLoadListener(verboseListener); 179 oldJar.load(Arrays.asList(getOld().list())); 180 181 log("Loading new classes from path " + getNew()); 182 Validator newValidator = new ListBasedValidator(getNewdocumentation()); 183 ClassfileLoader newJar = new AggregatingClassfileLoader(); 184 newJar.addLoadListener(verboseListener); 185 newJar.load(Arrays.asList(getNew().list())); 186 187 191 log("Comparing old and new classes ..."); 192 193 String name = getName(); 194 String oldLabel = (getOldlabel() != null) ? getOldlabel() : getOld().toString(); 195 String newLabel = (getNewlabel() != null) ? getNewlabel() : getNew().toString(); 196 197 DifferencesFactory factory = new DifferencesFactory(oldValidator, newValidator); 198 Differences differences = factory.createJarDifferences(name, oldLabel, oldJar, newLabel, newJar); 199 200 log("Saving difference report to " + getDestfile().getAbsolutePath()); 201 202 com.jeantessier.diff.Printer printer = new Report(getEncoding(), getDtdprefix()); 203 if (getIndenttext() != null) { 204 printer.setIndentText(getIndenttext()); 205 } 206 207 differences.accept(printer); 208 209 PrintWriter out = new PrintWriter(new FileWriter(getDestfile())); 210 out.print(printer); 211 out.close(); 212 } catch (IOException ex) { 213 throw new BuildException(ex); 214 } 215 } 216 } 217 | Popular Tags |