1 19 20 package edu.umd.cs.findbugs; 21 22 import edu.umd.cs.findbugs.annotations.SuppressWarnings; 23 import java.io.IOException ; 24 import java.util.Iterator ; 25 26 import org.dom4j.DocumentException; 27 28 31 public class AddAnnotation { 32 private BugCollection bugCollection; 33 private Project project; 34 private String annotation; 35 36 public AddAnnotation(BugCollection bugCollection, Project project, String annotation) { 37 this.bugCollection = bugCollection; 38 this.project = project; 39 this.annotation = annotation; 40 } 41 42 public AddAnnotation(String resultsFile, String annotation) 43 throws IOException , DocumentException { 44 this(new SortedBugCollection(), new Project(), annotation); 45 bugCollection.readXML(resultsFile, project); 46 } 47 48 public BugCollection getBugCollection() { 49 return bugCollection; 50 } 51 52 public Project getProject() { 53 return project; 54 } 55 56 public void execute() { 57 for (Iterator <BugInstance> i = bugCollection.iterator(); i.hasNext();) { 58 BugInstance bugInstance = i.next(); 59 60 if (bugInstance.annotationTextContainsWord(this.annotation)) 62 continue; 63 64 String annotation = bugInstance.getAnnotationText(); 65 StringBuffer buf = new StringBuffer (); 66 if (!annotation.equals("")) { 67 buf.append(annotation); 68 buf.append('\n'); 69 } 70 buf.append(this.annotation); 71 bugInstance.setAnnotationText(buf.toString()); 72 } 73 } 74 75 @SuppressWarnings ("DM_EXIT") 76 public static void main(String [] argv) throws Exception { 77 if (argv.length != 2) { 78 System.err.println("Usage: " + AddAnnotation.class.getName() + " <results file> <annotation>"); 79 System.exit(1); 80 } 81 82 String filename = argv[0]; 83 String annotation = argv[1]; 84 85 AddAnnotation addAnnotation = new AddAnnotation(filename, annotation); 86 addAnnotation.execute(); 87 88 addAnnotation.getBugCollection().writeXML(filename, addAnnotation.getProject()); 89 } 90 } 91 92 | Popular Tags |