use of edu.umd.cs.findbugs.SortedBugCollection in project spotbugs by spotbugs.
the class BugLoader method loadBugs.
@CheckForNull
public static SortedBugCollection loadBugs(MainFrame mainFrame, Project project, URL url) {
SortedBugCollection col = new SortedBugCollection(project);
try {
if (MainFrame.GUI2_DEBUG) {
System.out.println("loading from: " + url);
JOptionPane.showMessageDialog(mainFrame, "loading from: " + url);
}
col.readXML(url);
if (MainFrame.GUI2_DEBUG) {
System.out.println("finished reading: " + url);
JOptionPane.showMessageDialog(mainFrame, "loaded: " + url);
}
addDeadBugMatcher(col);
} catch (Throwable e) {
String msg = SystemProperties.getOSDependentProperty("findbugs.unableToLoadViaURL");
if (msg == null) {
msg = e.getMessage();
} else {
try {
msg = String.format(msg, url);
} catch (Exception e2) {
msg = e.getMessage();
}
}
JOptionPane.showMessageDialog(mainFrame, "Could not read " + url + "\n" + msg);
if (SystemProperties.getBoolean("findbugs.failIfUnableToLoadViaURL")) {
System.exit(1);
}
}
MainFrame.getInstance().setProjectAndBugCollectionInSwingThread(project, col);
return col;
}
use of edu.umd.cs.findbugs.SortedBugCollection in project spotbugs by spotbugs.
the class BugLoader method loadBugs.
@CheckForNull
public static SortedBugCollection loadBugs(MainFrame mainFrame, Project project, File source) {
if (!source.isFile() || !source.canRead()) {
JOptionPane.showMessageDialog(mainFrame, "Unable to read " + source);
return null;
}
SortedBugCollection col = new SortedBugCollection(project);
try {
col.readXML(source);
if (col.hasDeadBugs()) {
addDeadBugMatcher(col);
}
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(mainFrame, "Could not read " + source + "; " + e.getMessage());
}
MainFrame.getInstance().setProjectAndBugCollectionInSwingThread(project, col);
return col;
}
use of edu.umd.cs.findbugs.SortedBugCollection in project spotbugs by spotbugs.
the class ObfuscateBugs method main.
public static void main(String[] args) throws Exception {
FindBugs.setNoAnalysis();
CommandLine commandLine = new CommandLine();
int argCount = commandLine.parse(args, 0, 2, "Usage: " + ObfuscateBugs.class.getName() + " [options] [<xml results>] ");
SortedBugCollection bugCollection = new SortedBugCollection();
if (argCount < args.length) {
bugCollection.readXML(args[argCount++]);
} else {
bugCollection.readXML(System.in);
}
SortedBugCollection results = bugCollection.createEmptyCollectionWithMetadata();
Project project = results.getProject();
project.getSourceDirList().clear();
project.getFileList().clear();
project.getAuxClasspathEntryList().clear();
results.getProjectStats().getPackageStats().clear();
results.clearMissingClasses();
results.clearErrors();
for (BugInstance bug : bugCollection) {
results.add(Obfuscate.obfuscate(bug), false);
}
if (argCount == args.length) {
results.writeXML(System.out);
} else {
results.writeXML(args[argCount++]);
}
}
use of edu.umd.cs.findbugs.SortedBugCollection in project spotbugs by spotbugs.
the class SetBugDatabaseInfo method main.
public static void main(String[] args) throws IOException, DocumentException {
FindBugs.setNoAnalysis();
DetectorFactoryCollection.instance();
SetInfoCommandLine commandLine = new SetInfoCommandLine();
int argCount = commandLine.parse(args, 0, 2, USAGE);
SortedBugCollection origCollection = new SortedBugCollection();
if (argCount < args.length) {
origCollection.readXML(args[argCount++]);
} else {
origCollection.readXML(System.in);
}
Project project = origCollection.getProject();
if (commandLine.revisionName != null) {
origCollection.setReleaseName(commandLine.revisionName);
}
if (commandLine.projectName != null) {
origCollection.getProject().setProjectName(commandLine.projectName);
}
if (commandLine.revisionTimestamp != 0) {
origCollection.setTimestamp(commandLine.revisionTimestamp);
}
origCollection.setWithMessages(commandLine.withMessages);
if (commandLine.exclusionFilterFile != null) {
project.setSuppressionFilter(Filter.parseFilter(commandLine.exclusionFilterFile));
}
if (commandLine.resetProject) {
project.getSourceDirList().clear();
project.getFileList().clear();
project.getAuxClasspathEntryList().clear();
}
if (commandLine.resetSource) {
project.getSourceDirList().clear();
}
project.addSourceDirs(commandLine.sourcePaths);
if (commandLine.purgeStats) {
origCollection.getProjectStats().getPackageStats().clear();
}
if (commandLine.purgeClassStats) {
for (PackageStats ps : origCollection.getProjectStats().getPackageStats()) {
ps.getClassStats().clear();
}
}
if (commandLine.purgeMissingClasses) {
origCollection.clearMissingClasses();
}
if (commandLine.lastVersion != null) {
long last = edu.umd.cs.findbugs.workflow.Filter.FilterCommandLine.getVersionNum(origCollection, commandLine.lastVersion, true);
if (last < origCollection.getSequenceNumber()) {
String name = origCollection.getAppVersionFromSequenceNumber(last).getReleaseName();
long timestamp = origCollection.getAppVersionFromSequenceNumber(last).getTimestamp();
origCollection.setReleaseName(name);
origCollection.setTimestamp(timestamp);
origCollection.trimAppVersions(last);
}
}
Map<String, Set<String>> missingFiles = new HashMap<>();
if (!commandLine.searchSourcePaths.isEmpty()) {
sourceSearcher = new SourceSearcher(project);
for (BugInstance bug : origCollection.getCollection()) {
SourceLineAnnotation src = bug.getPrimarySourceLineAnnotation();
if (!sourceSearcher.sourceNotFound.contains(src.getClassName()) && !sourceSearcher.findSource(src)) {
Set<String> paths = missingFiles.computeIfAbsent(src.getSourceFile(), k -> new HashSet<>());
String fullPath = fullPath(src);
// System.out.println("Missing " + fullPath);
paths.add(fullPath);
}
}
Set<String> foundPaths = new HashSet<>();
for (String f : commandLine.searchSourcePaths) {
for (File javaFile : RecursiveSearchForJavaFiles.search(new File(f))) {
Set<String> matchingMissingClasses = missingFiles.get(javaFile.getName());
if (matchingMissingClasses == null) {
// System.out.println("Nothing for " + javaFile);
} else {
for (String sourcePath : matchingMissingClasses) {
String path = javaFile.getAbsolutePath();
if (path.endsWith(sourcePath)) {
String dir = path.substring(0, path.length() - sourcePath.length());
foundPaths.add(dir);
}
}
}
}
}
Set<String> toRemove = new HashSet<>();
for (String p1 : foundPaths) {
for (String p2 : foundPaths) {
if (!p1.equals(p2) && p1.startsWith(p2)) {
toRemove.add(p1);
break;
}
}
}
foundPaths.removeAll(toRemove);
project.addSourceDirs(foundPaths);
for (String dir : foundPaths) {
if (argCount < args.length) {
System.out.println("Found " + dir);
}
}
}
if (argCount < args.length) {
origCollection.writeXML(args[argCount++]);
} else {
origCollection.writeXML(System.out);
}
}
use of edu.umd.cs.findbugs.SortedBugCollection in project spotbugs by spotbugs.
the class DefectDensity method main.
public static void main(String[] args) throws Exception {
if (args.length > 1 || (args.length > 0 && "-help".equals(args[0]))) {
System.err.println("Usage: " + DefectDensity.class.getName() + " [<infile>]");
System.exit(1);
}
FindBugs.setNoAnalysis();
BugCollection origCollection = new SortedBugCollection();
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()) {
if (p.getTotalBugs() > 4) {
double packageDensity = density(p.getTotalBugs(), p.size());
if (Double.isNaN(packageDensity) || packageDensity < projectDensity) {
continue;
}
printRow("package", p.getPackageName(), packageDensity, p.getTotalBugs(), p.size());
for (ClassStats c : p.getSortedClassStats()) {
if (c.getTotalBugs() > 4) {
double density = density(c.getTotalBugs(), c.size());
if (Double.isNaN(density) || density < packageDensity) {
continue;
}
printRow("class", c.getName(), density, c.getTotalBugs(), c.size());
}
}
}
}
}
Aggregations