BugCollection resultCollection = newCollection.createEmptyCollectionWithMetadata(); long lastSequence = origCollection.getSequenceNumber(); resultCollection.clearAppVersions(); for (Iterator<AppVersion> i = origCollection.appVersionIterator(); i.hasNext();) { AppVersion appVersion = i.next(); resultCollection.addAppVersion((AppVersion) appVersion.clone()); AppVersion origCollectionVersion = origCollection.getCurrentAppVersion(); AppVersion origCollectionVersionClone = new AppVersion(lastSequence); origCollectionVersionClone.setTimestamp(origCollectionVersion.getTimestamp()); origCollectionVersionClone.setReleaseName(origCollectionVersion.getReleaseName()); origCollectionVersionClone.setNumClasses(origCollection.getProjectStats().getNumClasses()); origCollectionVersionClone.setCodeSize(origCollection.getProjectStats().getCodeSize()); resultCollection.addAppVersion(origCollectionVersionClone); long currentSequence = origCollection.getSequenceNumber() + 1; resultCollection.setSequenceNumber(currentSequence); for (BugInstance bug : origCollection.getCollection()) { if (!matchedOldBugs.containsKey(bug)) { if (bug.isDead()) { resultCollection.add(newBug, false); } else { String sourceFile = classBugFoundIn.getSourceFileName();
origCollection.readXML(origFilename); break; } catch (Exception e) { if (commandLine.overrideRevisionNames || origCollection.getReleaseName() == null || origCollection.getReleaseName().length() == 0) { origCollection.setReleaseName(firstPathParts[commonPrefix]); if (useAnalysisTimes) { origCollection.setTimestamp(origCollection.getAnalysisTimestamp()); for (BugInstance bug : origCollection.getCollection()) { if (bug.getLastVersion() >= 0 && bug.getFirstVersion() > bug.getLastVersion()) { throw new IllegalStateException("Illegal Version range: " + bug.getFirstVersion() + ".." + bug.getLastVersion()); newCollection.readXML(newFilename); if (commandLine.overrideRevisionNames || newCollection.getReleaseName() == null || newCollection.getReleaseName().length() == 0) { newCollection.setReleaseName(getFilePathParts(newFilename)[commonPrefix]); newCollection.setTimestamp(newCollection.getAnalysisTimestamp()); origCollection.setWithMessages(commandLine.withMessages); if (commandLine.outputFilename != null) { if (verbose) { System.out.println("Writing " + commandLine.outputFilename); origCollection.writeXML(commandLine.outputFilename);
assert bugCollection != null; if ("BugInstance".equals(qName)) { bugCollection.add(bugInstance, false); if (BugCollection.ANALYSIS_ERROR_ELEMENT_NAME.equals(qName)) { analysisError.setMessage(getTextContents()); bugCollection.addError(analysisError); } else if (BugCollection.ERROR_ELEMENT_NAME.equals(qName)) { if (stackTrace.size() > 0) { analysisError.setStackTrace(stackTrace.toArray(new String[stackTrace.size()])); bugCollection.addError(analysisError); } else if (BugCollection.MISSING_CLASS_ELEMENT_NAME.equals(qName)) { bugCollection.addMissingClass(getTextContents()); assert bugCollection != null; bugCollection.setClassFeatureSet(classFeatureSet); classFeatureSet = null;
/** * @param baseline * @throws IOException * @throws DocumentException */ public static void addToExcludedInstanceHashes(Set<String> instanceHashesToExclude, String baseline) throws IOException, DocumentException { Project project = new Project(); BugCollection origCollection; origCollection = new SortedBugCollection(project); origCollection.readXML(baseline); for (BugInstance b : origCollection.getCollection()) { instanceHashesToExclude.add(b.getInstanceHash()); } }
@Override public void finish() { try { Project project = getProject(); if (project == null) { throw new NullPointerException("No project"); } getBugCollection().bugsPopulated(); getBugCollection().writeXML(outputStream); outputStream.close(); } catch (IOException e) { throw new FatalException("Error writing XML output: " + e.getMessage(), e); } }
public RegenerateClassFeatures execute() throws IOException { bugCollection.clearClassFeatures(); ArrayList<JavaClass> classList = new ArrayList<>(); try (ZipFile zipFile = new ZipFile(jarFile)){ // Add all classes to repository (for hierarchy queries) Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (!entry.getName().endsWith(".class")) { continue; } ClassParser parser = new ClassParser(zipFile.getInputStream(entry), entry.getName()); JavaClass javaClass = parser.parse(); Repository.addClass(javaClass); classList.add(javaClass); } } for (JavaClass javaClass : classList) { ClassFeatureSet classFeatureSet = new ClassFeatureSet().initialize(javaClass); bugCollection.setClassFeatureSet(classFeatureSet); } return this; }
bugCollection.setAnalysisVersion(version); bugCollection.setSequenceNumber(seqval); bugCollection.setTimestamp(tsval); bugCollection.setAnalysisTimestamp(parseLong(analysisTimestamp, -1L)); bugCollection.setAnalysisVersion(analysisVersion); bugCollection.setReleaseName((releaseName != null) ? releaseName : ""); } else if (isTopLevelFilter(qName)) { if (project != null) { String totalClasses = getOptionalAttribute(attributes, "total_classes"); if (totalClasses != null && totalClasses.length() > 0) { bugCollection.getProjectStats().setTotalClasses(Integer.parseInt(totalClasses)); bugCollection.getProjectStats().setTotalSize(Integer.parseInt(totalSize)); bugCollection.getProjectStats().setReferencedClasses(Integer.parseInt(referencedClasses)); bugCollection.getProjectStats().setVMVersion(vmVersion); try { bugCollection.getProjectStats().setTimestamp(timestamp); } catch (java.text.ParseException e) { throw new SAXException("Unparseable sequence number: '" + timestamp + "'", e); int numClasses = Integer.parseInt(getRequiredAttribute(attributes, "total_types", qName));
public static void trimToMaxRank(BugCollection origCollection, int maxRank) { for (Iterator<BugInstance> i = origCollection.getCollection().iterator(); i.hasNext();) { BugInstance b = i.next(); if (BugRanker.findRank(b) > maxRank) { i.remove(); } } } }
BugCollection origCollection = new SortedBugCollection(); if (args.length == 1) { origCollection.readXML(System.in); } else { origCollection.readXML(args[1]); for (BugInstance b : origCollection.getCollection()) { String prefix = ClassName.extractPackagePrefix(b.getPrimaryClass().getPackageName(), prefixLength); Integer v = map.get(prefix); for (PackageStats ps : origCollection.getProjectStats().getPackageStats()) { String prefix = ClassName.extractPackagePrefix(ps.getPackageName(), prefixLength);
FileBugHash(BugCollection bugs) { for (PackageStats pStat : bugs.getProjectStats().getPackageStats()) { for (ClassStats cStat : pStat.getSortedClassStats()) { String path = cStat.getName(); for (BugInstance bug : bugs.getCollection()) { SourceLineAnnotation source = bug.getPrimarySourceLineAnnotation();
int argCount = 0; if (argCount == args.length) { origCollection.readXML(System.in); } else { origCollection.readXML(args[argCount]); ProjectStats stats = origCollection.getProjectStats(); printRow("kind", "name", "density/KNCSS", "bugs", "NCSS"); double projectDensity = density(stats.getTotalBugs(), stats.getCodeSize()); printRow("project", origCollection.getCurrentAppVersion().getReleaseName(), projectDensity, stats.getTotalBugs(), stats.getCodeSize()); for (PackageStats p : stats.getPackageStats()) {
origCollection.readXML(args[0]); SourceFinder sourceFinder = new SourceFinder(origCollection.getProject()); Cloud cloud = origCollection.getCloud(); cloud.bugsPopulated(); if (cloud.getSigninState() != Cloud.SigninState.SIGNED_IN origCollection.writeXML(args[1]);
System.out.println("Setting bug collection to null"); } else { System.out.println("Setting bug collection; contains " + bugCollection.getCollection().size() + " bugs"); if (bugCollection != null && bugCollection.getProject() != project) { Project p2 = bugCollection.getProject(); throw new IllegalArgumentException(String.format("project %x and bug collection %x don't match", System.identityHashCode(project), System.identityHashCode(p2))); Cloud plugin = this.bugCollection.getCloud(); plugin.removeListener(userAnnotationListener); plugin.removeStatusListener(cloudStatusListener); displayer.clearCache(); if (bugCollection != null) { Cloud plugin = bugCollection.getCloud(); plugin.addListener(userAnnotationListener); plugin.addStatusListener(cloudStatusListener);
for (BugInstance bug : origCollection.getCollection()) { if (!matchedOldBugs.containsKey(bug)) { if (matchOld.match(bug)) { long newVersion = origCollection.getCurrentAppVersion().getSequenceNumber() + 1; for (BugInstance bug : newCollection.getCollection()) { if (!mapFromNewToOldBug.containsKey(bug)) {
public static void xslt(String stylesheet, boolean applySuppression, String[] args, int argCount) throws Exception { Project proj = new Project(); HTMLBugReporter reporter = new HTMLBugReporter(proj, stylesheet); BugCollection bugCollection = reporter.getBugCollection(); bugCollection.setApplySuppressions(applySuppression); if (argCount < args.length) { bugCollection.readXML(args[argCount++]); } else { bugCollection.readXML(System.in); } if (argCount < args.length) { reporter.setOutputStream(UTF8.printStream(new FileOutputStream(args[argCount++]), true)); } reporter.finish(); Exception e = reporter.getFatalException(); if (e != null) { throw e; } }
public static void main(String args[]) throws Exception { if (args.length > 1 || (args.length > 0 && "-help".equals(args[0]))) { System.err.println("Usage: " + FileBugHash.class.getName() + " [<infile>]"); System.exit(1); } BugCollection origCollection = new SortedBugCollection(); int argCount = 0; if (argCount == args.length) { origCollection.readXML(System.in); } else { origCollection.readXML(args[argCount]); } FileBugHash result = compute(origCollection); for (String sourceFile : result.getSourceFiles()) { System.out.println(result.getHash(sourceFile) + "\t" + sourceFile); } }
public static long getVersionNum(BugCollection collection, String val, boolean roundToLaterVersion) { if (val == null) { return -1; } Map<String, AppVersion> versions = new HashMap<>(); SortedMap<Long, AppVersion> timeStamps = new TreeMap<>(); for (Iterator<AppVersion> i = collection.appVersionIterator(); i.hasNext();) { AppVersion v = i.next(); versions.put(v.getReleaseName(), v); timeStamps.put(v.getTimestamp(), v); } // add current version to the maps AppVersion v = collection.getCurrentAppVersion(); versions.put(v.getReleaseName(), v); timeStamps.put(v.getTimestamp(), v); return getVersionNum(versions, timeStamps, val, roundToLaterVersion, v.getSequenceNumber()); }
public static void main(String[] args) throws IOException, DocumentException { FindBugs.setNoAnalysis(); DetectorFactoryCollection.instance(); if (args.length > 1) { System.out.println(USAGE); return; } BugCollection bugs = new SortedBugCollection(); if (args.length == 0) { bugs.readXML(System.in); } else { bugs.readXML(args[0]); } bugs.getCloud().waitUntilIssueDataDownloaded(); PrintWriter out = UTF8.printWriter(System.out); bugs.getCloud().printCloudSummary(out, bugs, new String[0]); out.close(); } }
bugCollection.setAnalysisVersion(version); bugCollection.setSequenceNumber(seqval); bugCollection.setTimestamp(tsval); bugCollection.setAnalysisTimestamp(parseLong(analysisTimestamp, -1L)); bugCollection.setAnalysisVersion(analysisVersion); bugCollection.setReleaseName((releaseName != null) ? releaseName : ""); } else if (isTopLevelFilter(qName)) { if (project != null) { String totalClasses = getOptionalAttribute(attributes, "total_classes"); if (totalClasses != null && totalClasses.length() > 0) { bugCollection.getProjectStats().setTotalClasses(Integer.parseInt(totalClasses)); bugCollection.getProjectStats().setTotalSize(Integer.parseInt(totalSize)); bugCollection.getProjectStats().setReferencedClasses(Integer.parseInt(referencedClasses)); bugCollection.getProjectStats().setVMVersion(vmVersion); try { bugCollection.getProjectStats().setTimestamp(timestamp); } catch (java.text.ParseException e) { throw new SAXException("Unparseable sequence number: '" + timestamp + "'", e); int numClasses = Integer.parseInt(getRequiredAttribute(attributes, "total_types", qName));
public void removeBaselineBugs(BugCollection baselineCollection, BugCollection bugCollection) { matchBugs(baselineCollection, bugCollection); matchBugs(SortedBugCollection.BugInstanceComparator.instance, baselineCollection, bugCollection); matchBugs(versionInsensitiveBugComparator, baselineCollection, bugCollection); for (Iterator<BugInstance> i = bugCollection.getCollection().iterator(); i.hasNext();) { BugInstance bug = i.next(); if (matchedOldBugs.containsKey(bug)) { i.remove(); } } }