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.purgeDesignations) {
for (BugInstance b : origCollection) {
b.setUserDesignation(null);
}
}
if (commandLine.exclusionFilterFile != null) {
project.setSuppressionFilter(Filter.parseFilter(commandLine.exclusionFilterFile));
}
if (commandLine.resetProject) {
project.getSourceDirList().clear();
project.getFileList().clear();
project.getAuxClasspathEntryList().clear();
}
boolean reinitializeCloud = false;
if (commandLine.cloudId != null) {
project.setCloudId(commandLine.cloudId);
reinitializeCloud = true;
}
for (Map.Entry<String, String> e : commandLine.cloudProperties.entrySet()) {
project.getCloudProperties().setProperty(e.getKey(), e.getValue());
reinitializeCloud = true;
}
if (commandLine.resetSource) {
project.getSourceDirList().clear();
}
for (String source : commandLine.sourcePaths) {
project.addSourceDir(source);
}
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<String, Set<String>>();
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.get(src.getSourceFile());
if (paths == null) {
paths = new HashSet<String>();
missingFiles.put(src.getSourceFile(), paths);
}
String fullPath = fullPath(src);
// System.out.println("Missing " + fullPath);
paths.add(fullPath);
}
}
Set<String> foundPaths = new HashSet<String>();
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<String>();
for (String p1 : foundPaths) {
for (String p2 : foundPaths) {
if (!p1.equals(p2) && p1.startsWith(p2)) {
toRemove.add(p1);
break;
}
}
}
foundPaths.removeAll(toRemove);
for (String dir : foundPaths) {
project.addSourceDir(dir);
if (argCount < args.length) {
System.out.println("Found " + dir);
}
}
}
if (reinitializeCloud)
{
origCollection.clearCloud();
// OK, now we know all the missing source files
// we also know all the .java files in the directories we were pointed
// to
}
if (argCount < args.length) {
origCollection.writeXML(args[argCount++]);
} else {
origCollection.writeXML(System.out);
}
}