<commit_before>/*
 * FindBugs - Find bugs in Java programs
 * Copyright (C) 2003-2005 <NAME>
 * 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.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.dom4j.DocumentException;

import edu.umd.cs.findbugs.BugCollection;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.DetectorFactoryCollection;
import edu.umd.cs.findbugs.Project;
import edu.umd.cs.findbugs.SortedBugCollection;
import edu.umd.cs.findbugs.SourceLineAnnotation;
import edu.umd.cs.findbugs.config.CommandLine;
import edu.umd.cs.findbugs.filter.Filter;

/**
 * Java main application to compute update a historical bug collection with
 * results from another build/analysis.
 * 
 * @author <NAME>
 */

public class SetBugDatabaseInfo {

	/**
	 * 
	 */
	private static final String USAGE = "Usage: <cmd> " + " [options] [<oldData> [<newData>]]";

	static class SetInfoCommandLine extends CommandLine {
		String revisionName;

		String exclusionFilterFile;

		boolean withMessages = false;

		long revisionTimestamp = 0L;

		public List<String> sourcePaths = new LinkedList<String>();

		public List<String> searchSourcePaths = new LinkedList<String>();

		SetInfoCommandLine() {
			addOption("-name", "name", "set name for (last) revision");
			addOption("-timestamp", "when", "set timestamp for (last) revision");
			addSwitch("-resetSource", "remove all source search paths");
			addOption("-source", "directory", "Add this directory to the source search path");
			addOption("-findSource", "directory", "Find and add all relevant source directions contained within this directory");
			addOption("-suppress", "filter file", "Suppress warnings matched by this file (replaces previous suppressions)");
			addSwitch("-withMessages", "Add bug descriptions");
		}

		@Override
		protected void handleOption(String option, String optionExtraPart) throws IOException {
			if (option.equals("-withMessages"))
				withMessages = true;
			else if (option.equals("-resetSource"))
				sourcePaths.clear();
			else
				throw new IllegalArgumentException("no option " + option);

		}

		@Override
		protected void handleOptionWithArgument(String option, String argument) throws IOException {
			if (option.equals("-name"))
				revisionName = argument;
			else if (option.equals("-suppress"))
				exclusionFilterFile = argument;
			else if (option.equals("-timestamp"))
				revisionTimestamp = Date.parse(argument);

			else if (option.equals("-source"))
				sourcePaths.add(argument);
			else if (option.equals("-findSource"))
				searchSourcePaths.add(argument);
			else
				throw new IllegalArgumentException("Can't handle option " + option);

		}

	}

	public static void main(String[] args) throws IOException,
			DocumentException {

		DetectorFactoryCollection.instance();
		SetInfoCommandLine commandLine = new SetInfoCommandLine();
		int argCount = commandLine.parse(args, 0, 2, USAGE);

		Project project = new Project();
		BugCollection origCollection;
		origCollection = new SortedBugCollection();

		if (argCount < args.length) 
			origCollection.readXML(args[argCount++], project);
		else
			origCollection.readXML(System.in, project);


		if (commandLine.revisionName != null)
			origCollection.setReleaseName(commandLine.revisionName);
		if (commandLine.revisionTimestamp != 0)
			origCollection.setTimestamp(commandLine.revisionTimestamp);
		origCollection.setWithMessages(commandLine.withMessages);

		if (commandLine.exclusionFilterFile != null) {
			project.setSuppressionFilter(Filter.parseFilter(commandLine.exclusionFilterFile));
		}
		for(String source : commandLine.sourcePaths)
			project.addSourceDir(source);

		Map<String,Set<String>> missingFiles = new HashMap<String,Set<String>>();
		if (!commandLine.searchSourcePaths.isEmpty()) {
			sourceSearcher = new SourceSearcher(project);
			for(BugInstance bug : origCollection.getCollection()) {<commit_msg>add option to purge stats<commit_after>/*
 * FindBugs - Find bugs in Java programs
 * Copyright (C) 2003-2005 <NAME>
 * 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.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.dom4j.DocumentException;

import edu.umd.cs.findbugs.BugCollection;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.DetectorFactoryCollection;
import edu.umd.cs.findbugs.Project;
import edu.umd.cs.findbugs.SortedBugCollection;
import edu.umd.cs.findbugs.SourceLineAnnotation;
import edu.umd.cs.findbugs.config.CommandLine;
import edu.umd.cs.findbugs.filter.Filter;

/**
 * Java main application to compute update a historical bug collection with
 * results from another build/analysis.
 * 
 * @author <NAME>
 */

public class SetBugDatabaseInfo {

	/**
	 * 
	 */
	private static final String USAGE = "Usage: <cmd> " + " [options] [<oldData> [<newData>]]";

	static class SetInfoCommandLine extends CommandLine {
		String revisionName;

		String exclusionFilterFile;

		boolean withMessages = false;
		boolean purgeStats = false;

		long revisionTimestamp = 0L;

		public List<String> sourcePaths = new LinkedList<String>();

		public List<String> searchSourcePaths = new LinkedList<String>();

		SetInfoCommandLine() {
			addOption("-name", "name", "set name for (last) revision");
			addOption("-timestamp", "when", "set timestamp for (last) revision");
			addSwitch("-resetSource", "remove all source search paths");
			addOption("-source", "directory", "Add this directory to the source search path");
			addSwitch("-purgeStats", "purge/delete information about sizes of analyzed class files");
			addOption("-findSource", "directory", "Find and add all relevant source directions contained within this directory");
			addOption("-suppress", "filter file", "Suppress warnings matched by this file (replaces previous suppressions)");
			addSwitch("-withMessages", "Add bug descriptions");
		}

		@Override
		protected void handleOption(String option, String optionExtraPart) throws IOException {
			if (option.equals("-withMessages"))
				withMessages = true;
			else if (option.equals("-resetSource"))
				sourcePaths.clear();
			else if (option.equals("-purgeStats"))
				purgeStats = true;
			else
				throw new IllegalArgumentException("no option " + option);

		}

		@Override
		protected void handleOptionWithArgument(String option, String argument) throws IOException {
			if (option.equals("-name"))
				revisionName = argument;
			else if (option.equals("-suppress"))
				exclusionFilterFile = argument;
			else if (option.equals("-timestamp"))
				revisionTimestamp = Date.parse(argument);

			else if (option.equals("-source"))
				sourcePaths.add(argument);
			else if (option.equals("-findSource"))
				searchSourcePaths.add(argument);
			else
				throw new IllegalArgumentException("Can't handle option " + option);

		}

	}

	public static void main(String[] args) throws IOException,
			DocumentException {

		DetectorFactoryCollection.instance();
		SetInfoCommandLine commandLine = new SetInfoCommandLine();
		int argCount = commandLine.parse(args, 0, 2, USAGE);

		Project project = new Project();
		BugCollection origCollection;
		origCollection = new SortedBugCollection();

		if (argCount < args.length) 
			origCollection.readXML(args[argCount++], project);
		else
			origCollection.readXML(System.in, project);


		if (commandLine.revisionName != null)
			origCollection.setReleaseName(commandLine.revisionName);
		if (commandLine.revisionTimestamp != 0)
			origCollection.setTimestamp(commandLine.revisionTimestamp);
		origCollection.setWithMessages(commandLine.withMessages);

		if (commandLine.exclusionFilterFile != null) {
			project.setSuppressionFilter(Filter.parseFilter(commandLine.exclusionFilterFile));
		}
		for(String source : commandLine.sourcePaths)
			project.addSourceDir(source);
		if (commandLine.purgeStats)
			origCollection.getProjectStats().getPackageStats().clear();

		Map<String,Set<String>> missingFiles = new HashMap<String,Set<String>>();
		if (!commandLine.searchSourcePaths.isEmpty()) {
			sourceSearcher = new SourceSearcher(project);
			for(BugInstance bug : origCollection.getCollection()) {
{'fraction_non_alphanumeric': 0.10731953558808682, 'fraction_numerical': 0.00585562847046946, 'mean_word_length': 4.7727272727272725, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4231379', 'n_tokens_mistral': 3071, 'n_tokens_neox': 2743, 'n_words': 836}