📄 update.java
字号:
/* * FindBugs - Find bugs in Java programs * Copyright (C) 2003-2005 William Pugh * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package edu.umd.cs.findbugs.workflow;import java.io.File;import java.io.IOException;import java.util.Comparator;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.LinkedList;import java.util.Set;import java.util.TreeMap;import org.dom4j.DocumentException;import edu.umd.cs.findbugs.AppVersion;import edu.umd.cs.findbugs.BugCollection;import edu.umd.cs.findbugs.BugDesignation;import edu.umd.cs.findbugs.BugInstance;import edu.umd.cs.findbugs.ClassAnnotation;import edu.umd.cs.findbugs.DetectorFactoryCollection;import edu.umd.cs.findbugs.PackageStats;import edu.umd.cs.findbugs.Project;import edu.umd.cs.findbugs.SortedBugCollection;import edu.umd.cs.findbugs.TigerSubstitutes;import edu.umd.cs.findbugs.VersionInsensitiveBugComparator;import edu.umd.cs.findbugs.PackageStats.ClassStats;import edu.umd.cs.findbugs.config.CommandLine;import edu.umd.cs.findbugs.model.MovedClassMap;/** * Java main application to compute update a historical bug collection with * results from another build/analysis. * * @author William Pugh */public class Update { /** * */ private static final String USAGE = "Usage: " + Update.class.getName() + " [options] data1File data2File data3File ... "; private HashMap<BugInstance, BugInstance> mapFromNewToOldBug = new HashMap<BugInstance, BugInstance>(); private HashSet<BugInstance> matchedOldBugs = new HashSet<BugInstance>(); boolean noPackageMoves = false; boolean preciseMatch = false; boolean precisePriorityMatch = false; class UpdateCommandLine extends CommandLine { boolean overrideRevisionNames = false; String outputFilename; boolean withMessages = false; UpdateCommandLine() { addSwitch("-overrideRevisionNames", "override revision names for each version with names computed filenames"); addSwitch( "-noPackageMoves", "if a class seems to have moved from one package to another, treat warnings in that class as two seperate warnings"); addSwitch("-preciseMatch", "require bug patterns to match precisely"); addSwitch("-precisePriorityMatch", "only consider two warnings to be the same if their priorities match exactly"); addOption("-output", "output file", "explicit filename for merged results (standard out used if not specified)"); addSwitch("-quiet", "don't generate any outout to standard out unless there is an error"); addSwitch("-withMessages", "Add bug description"); } @Override protected void handleOption(String option, String optionExtraPart) throws IOException { if (option.equals("-overrideRevisionNames")) { if (optionExtraPart.length() == 0) overrideRevisionNames = true; else overrideRevisionNames = TigerSubstitutes .parseBoolean(optionExtraPart); } else if (option.equals("-noPackageMoves")) { if (optionExtraPart.length() == 0) noPackageMoves = true; else noPackageMoves = TigerSubstitutes .parseBoolean(optionExtraPart); } else if (option.equals("-preciseMatch")) { preciseMatch = true; } else if (option.equals("-precisePriorityMatch")) { versionInsensitiveBugComparator.setComparePriorities(true); fuzzyBugPatternMatcher.setComparePriorities(true); precisePriorityMatch = true; } else if (option.equals("-quiet")) verbose = false; else if (option.equals("-withMessages")) withMessages = true; else throw new IllegalArgumentException("no option " + option); } @Override protected void handleOptionWithArgument(String option, String argument) throws IOException { if (option.equals("-output")) outputFilename = argument; else throw new IllegalArgumentException("Can't handle option " + option); } } VersionInsensitiveBugComparator versionInsensitiveBugComparator = new VersionInsensitiveBugComparator(); VersionInsensitiveBugComparator fuzzyBugPatternMatcher = new VersionInsensitiveBugComparator(); { fuzzyBugPatternMatcher.setExactBugPatternMatch(false); } HashSet<String> sourceFilesInCollection(BugCollection collection) { HashSet<String> result = new HashSet<String>(); for(PackageStats pStats : collection.getProjectStats().getPackageStats()) { for(ClassStats cStats : pStats.getClassStats()) { result.add(cStats.getSourceFile()); } } return result; } public BugCollection mergeCollections(BugCollection origCollection, BugCollection newCollection, boolean copyDeadBugs, boolean incrementalAnalysis) { if (false) { System.out.println("merging"); System.out.println("Bugs in old collection:"); System.out.println(origCollection.getProjectStats()); for(BugInstance bug : origCollection.getCollection()) System.out.println(bug.getMessage()); System.out.println("Bugs in new collection:"); System.out.println(newCollection.getProjectStats()); for(BugInstance bug : newCollection.getCollection()) System.out.println(bug.getMessage()); } mapFromNewToOldBug.clear(); matchedOldBugs.clear(); BugCollection resultCollection = newCollection .createEmptyCollectionWithMetadata(); // Previous sequence number long lastSequence = origCollection.getSequenceNumber(); // The AppVersion history is retained from the orig collection, // adding an entry for the sequence/timestamp of the current state // of the orig collection. resultCollection.clearAppVersions(); for (Iterator<AppVersion> i = origCollection.appVersionIterator(); i .hasNext();) { AppVersion appVersion = i.next(); resultCollection.addAppVersion((AppVersion) appVersion.clone()); } // why not do: AppVersion origCollectionVersion = // origCollection.getCurrentAppVersion(); AppVersion origCollectionVersion = new AppVersion(lastSequence); origCollectionVersion.setTimestamp(origCollection .getCurrentAppVersion().getTimestamp()); origCollectionVersion.setReleaseName(origCollection .getCurrentAppVersion().getReleaseName()); origCollectionVersion.setNumClasses(origCollection.getProjectStats() .getNumClasses()); origCollectionVersion.setCodeSize(origCollection.getProjectStats() .getCodeSize()); resultCollection.addAppVersion(origCollectionVersion); // We assign a sequence number to the new collection as one greater than // the original collection. long currentSequence = origCollection.getSequenceNumber() + 1; resultCollection.setSequenceNumber(currentSequence); int oldBugs = 0; // move all inactive bugs if (copyDeadBugs) for (BugInstance bug : origCollection.getCollection()) if (bug.getLastVersion() != -1) { oldBugs++; BugInstance newBug = (BugInstance) bug.clone(); resultCollection.add(newBug, false); } matchBugs(SortedBugCollection.BugInstanceComparator.instance, origCollection, newCollection); matchBugs(versionInsensitiveBugComparator, origCollection, newCollection); if (!preciseMatch) { matchBugs(fuzzyBugPatternMatcher, origCollection, newCollection); } if (!noPackageMoves) { VersionInsensitiveBugComparator movedBugComparator = new VersionInsensitiveBugComparator(); MovedClassMap movedClassMap = new MovedClassMap( origCollection, newCollection).execute(); if (!movedClassMap.isEmpty()) { movedBugComparator.setClassNameRewriter(movedClassMap); movedBugComparator.setComparePriorities(precisePriorityMatch); matchBugs(movedBugComparator, origCollection, newCollection); if (!preciseMatch) { movedBugComparator.setExactBugPatternMatch(false); matchBugs(movedBugComparator, origCollection, newCollection); } } } // matchBugs(new SloppyBugComparator(), origCollection, newCollection); int newlyDeadBugs = 0; int persistantBugs = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -