📄 update.java
字号:
int addedBugs = 0; int addedInNewCode = 0; int deadBugInDeadCode = 0; HashSet<String> analyzedSourceFiles = sourceFilesInCollection(newCollection); // Copy unmatched bugs if (copyDeadBugs || incrementalAnalysis) for (BugInstance bug : origCollection.getCollection()) if (!matchedOldBugs.contains(bug) && bug.getLastVersion() == -1) { newlyDeadBugs++; BugInstance newBug = (BugInstance) bug.clone(); ClassAnnotation classBugFoundIn = bug.getPrimaryClass(); String className = classBugFoundIn.getClassName(); String sourceFile = classBugFoundIn.getSourceFileName(); boolean removed = sourceFile != null && analyzedSourceFiles.contains(sourceFile) || newCollection.getProjectStats().getClassStats(className) != null; if (removed) { if (!copyDeadBugs) continue; newBug.setRemovedByChangeOfPersistingClass(true); newBug.setLastVersion(lastSequence); } else { deadBugInDeadCode++; if (!incrementalAnalysis) newBug.setLastVersion(lastSequence); } if (newBug.getLastVersion() != -1 && newBug.getFirstVersion() > newBug.getLastVersion()) throw new IllegalStateException("Illegal Version range: " + newBug.getFirstVersion() + ".." + newBug.getLastVersion()); resultCollection.add(newBug, false); } // Copy matched bugs for (BugInstance bug : newCollection.getCollection()) { BugInstance newBug = (BugInstance) bug.clone(); if (mapFromNewToOldBug.containsKey(bug)) { BugInstance origWarning = mapFromNewToOldBug.get(bug); assert origWarning.getLastVersion() == -1; copyBugHistory(origWarning, newBug); // handle getAnnotationText()/setAnnotationText() and // designation key BugDesignation designation = newBug.getUserDesignation(); if (designation != null) designation.merge(origWarning.getUserDesignation()); else newBug.setUserDesignation(origWarning.getUserDesignation()); // clone?? persistantBugs++; } else { newBug.setFirstVersion(lastSequence + 1); addedBugs++; ClassAnnotation classBugFoundIn = bug.getPrimaryClass(); String className = classBugFoundIn.getClassName(); if (origCollection.getProjectStats().getClassStats(className) != null) { newBug.setIntroducedByChangeOfExistingClass(true); // System.out.println("added bug to existing code " + // newBug.getUniqueId() + " : " + newBug.getAbbrev() + " in // " + classBugFoundIn); } else addedInNewCode++; } assert newBug.getLastVersion() == -1; if (newBug.getLastVersion() != -1) throw new IllegalStateException("Illegal Version range: " + newBug.getFirstVersion() + ".." + newBug.getLastVersion()); int oldSize = resultCollection.getCollection().size(); resultCollection.add(newBug, false); int newSize = resultCollection.getCollection().size(); if (newSize != oldSize + 1) { System.out.println("Failed to add bug #" + newBug.getUniqueId() + " : " + newBug.getMessage()); } } if (false && verbose) { System.out.println(origCollection.getCollection().size() + " orig bugs, " + newCollection.getCollection().size() + " new bugs"); System.out.println("Bugs: " + oldBugs + " old, " + deadBugInDeadCode + " in removed code, " + (newlyDeadBugs - deadBugInDeadCode) + " died, " + persistantBugs + " persist, " + addedInNewCode + " in new code, " + (addedBugs - addedInNewCode) + " added"); System.out.println(resultCollection.getCollection().size() + " resulting bugs"); } return resultCollection; } boolean verbose = true; public static String[] getFilePathParts(String filePath) { String regex = (File.separatorChar=='\\' ? "\\\\" : File.separator); return filePath.split(regex); } public static void main(String[] args) throws IOException, DocumentException { new Update().doit(args); } public void doit(String[] args) throws IOException, DocumentException { DetectorFactoryCollection.instance(); UpdateCommandLine commandLine = new UpdateCommandLine(); int argCount = commandLine.parse(args, 2, Integer.MAX_VALUE, USAGE); if (commandLine.outputFilename == null) verbose = false; String[] firstPathParts = getFilePathParts(args[argCount]); int commonPrefix = firstPathParts.length; for (int i = argCount + 1; i <= (args.length - 1); i++) { commonPrefix = Math.min(commonPrefix, lengthCommonPrefix( firstPathParts, getFilePathParts(args[i]))); } String origFilename = args[argCount++]; Project project = new Project(); BugCollection origCollection; origCollection = new SortedBugCollection(); if (verbose) System.out.println("Starting with " + origFilename); origCollection.readXML(origFilename, project); if (commandLine.overrideRevisionNames || origCollection.getReleaseName() == null || origCollection.getReleaseName().length() == 0) origCollection.setReleaseName(firstPathParts[commonPrefix]); for (BugInstance bug : origCollection.getCollection()) if (bug.getLastVersion() >= 0 && bug.getFirstVersion() > bug.getLastVersion()) throw new IllegalStateException("Illegal Version range: " + bug.getFirstVersion() + ".." + bug.getLastVersion()); while (argCount <= (args.length - 1)) { BugCollection newCollection = new SortedBugCollection(); String newFilename = args[argCount++]; if (verbose) System.out.println("Merging " + newFilename); project = new Project(); try { File f = new File(newFilename); if (f.length() == 0) { if (verbose) System.out.println("Empty input file: " + f); continue; } newCollection.readXML(newFilename, project); if (commandLine.overrideRevisionNames || newCollection.getReleaseName() == null || newCollection.getReleaseName().length() == 0) newCollection .setReleaseName(getFilePathParts(newFilename)[commonPrefix]); origCollection = mergeCollections(origCollection, newCollection, true, false); } catch (IOException e) { if (verbose) System.out.println(e); else throw e; } } origCollection.setWithMessages(commandLine.withMessages); if (commandLine.outputFilename != null) origCollection.writeXML(commandLine.outputFilename, project); else origCollection.writeXML(System.out, project); } private static int lengthCommonPrefix(String[] string, String[] string2) { int maxLength = Math.min(string.length, string2.length); for (int result = 0; result < maxLength; result++) if (!string[result].equals(string2[result])) return result; return maxLength; } private static void copyBugHistory(BugInstance src, BugInstance dest) { dest.setFirstVersion(src.getFirstVersion()); dest.setLastVersion(src.getLastVersion()); dest.setIntroducedByChangeOfExistingClass(src .isIntroducedByChangeOfExistingClass()); dest.setRemovedByChangeOfPersistingClass(src .isRemovedByChangeOfPersistingClass()); } private void matchBugs(Comparator<BugInstance> bugInstanceComparator, BugCollection origCollection, BugCollection newCollection) { TreeMap<BugInstance, LinkedList<BugInstance>> set = new TreeMap<BugInstance, LinkedList<BugInstance>>( bugInstanceComparator); int oldBugs = 0; int newBugs = 0; int matchedBugs = 0; for (BugInstance bug : origCollection.getCollection()) if (bug.getLastVersion() == -1 && !matchedOldBugs.contains(bug)) { oldBugs++; LinkedList<BugInstance> q = set.get(bug); if (q == null) { q = new LinkedList<BugInstance>(); set.put(bug, q); } q.add(bug); } for (BugInstance bug : newCollection.getCollection()) if (!mapFromNewToOldBug.containsKey(bug)) { newBugs++; LinkedList<BugInstance> q = set.get(bug); if (q != null && !q.isEmpty()) { matchedBugs++; BugInstance matchedBug = q.removeFirst(); mapFromNewToOldBug.put(bug, matchedBug); matchedOldBugs.add(matchedBug); } } if (false && verbose) System.out.println("matched " + matchedBugs + " of " + oldBugs + "o/" + newBugs + "n bugs using " + bugInstanceComparator.getClass().getName()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -