use of edu.umd.cs.findbugs.Project in project spotbugs by spotbugs.
the class FindBugsWorker method work.
/**
* Run FindBugs on the given collection of resources from same project
* (note: This is currently not thread-safe)
*
* @param resources
* files or directories which should be on the project classpath.
* All resources must belong to the same project, and no one of
* the elements can contain another one. Ergo, if the list
* contains a project itself, then it must have only one element.
* @throws CoreException
*/
public void work(List<WorkItem> resources) throws CoreException {
if (resources == null || resources.isEmpty()) {
if (DEBUG) {
FindbugsPlugin.getDefault().logInfo("No resources to analyse for project " + project);
}
return;
}
if (DEBUG) {
System.out.println(resources);
}
st = new StopTimer();
st.newPoint("initPlugins");
// make sure it's initialized
FindbugsPlugin.applyCustomDetectors(false);
st.newPoint("clearMarkers");
// clear markers
clearMarkers(resources);
st.newPoint("configureOutputFiles");
final Project findBugsProject = new Project();
findBugsProject.setProjectName(javaProject.getElementName());
final Reporter bugReporter = new Reporter(javaProject, findBugsProject, monitor);
if (FindBugsConsole.getConsole() != null) {
bugReporter.setReportingStream(FindBugsConsole.getConsole().newOutputStream());
}
bugReporter.setPriorityThreshold(userPrefs.getUserDetectorThreshold());
FindBugs.setHome(FindbugsPlugin.getFindBugsEnginePluginLocation());
Map<IPath, IPath> outLocations = createOutputLocations();
// collect all related class/jar/war etc files for analysis
collectClassFiles(resources, outLocations, findBugsProject);
// attach source directories (can be used by some detectors, see
// SwitchFallthrough)
configureSourceDirectories(findBugsProject, outLocations);
if (findBugsProject.getFileCount() == 0) {
if (DEBUG) {
FindbugsPlugin.getDefault().logInfo("No resources to analyse for project " + project);
}
return;
}
st.newPoint("createAuxClasspath");
String[] classPathEntries = createAuxClasspath();
// add to findbugs classpath
for (String entry : classPathEntries) {
findBugsProject.addAuxClasspathEntry(entry);
}
st.newPoint("configureProps");
IPreferenceStore store = FindbugsPlugin.getPluginPreferences(project);
boolean cacheClassData = store.getBoolean(FindBugsConstants.KEY_CACHE_CLASS_DATA);
final FindBugs2 findBugs = new FindBugs2Eclipse(project, cacheClassData, bugReporter);
findBugs.setNoClassOk(true);
findBugs.setProject(findBugsProject);
findBugs.setBugReporter(bugReporter);
findBugs.setProgressCallback(bugReporter);
findBugs.setDetectorFactoryCollection(DetectorFactoryCollection.instance());
// configure detectors.
userPrefs.setIncludeFilterFiles(relativeToAbsolute(userPrefs.getIncludeFilterFiles()));
userPrefs.setExcludeFilterFiles(relativeToAbsolute(userPrefs.getExcludeFilterFiles()));
userPrefs.setExcludeBugsFiles(relativeToAbsolute(userPrefs.getExcludeBugsFiles()));
findBugs.setUserPreferences(userPrefs);
// configure extended preferences
findBugs.setAnalysisFeatureSettings(userPrefs.getAnalysisFeatureSettings());
findBugs.setMergeSimilarWarnings(false);
if (cacheClassData) {
FindBugs2Eclipse.checkClassPathChanges(findBugs.getProject().getAuxClasspathEntryList(), project);
}
st.newPoint("runFindBugs");
if (DEBUG) {
FindbugsPlugin.log("Running SpotBugs");
}
runFindBugs(findBugs);
if (DEBUG) {
FindbugsPlugin.log("Done running SpotBugs");
}
// Merge new results into existing results
// if the argument is project, then it's not incremental
boolean incremental = !(resources.get(0) instanceof IProject);
updateBugCollection(findBugsProject, bugReporter, incremental);
st.newPoint("done");
st = null;
monitor.done();
}
use of edu.umd.cs.findbugs.Project in project spotbugs by spotbugs.
the class MainFrameTree method bugListPanel.
public JPanel bugListPanel() {
tableheader = new JTableHeader();
getTableheader().setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
// Listener put here for when user double clicks on sorting
// column header SorterDialog appears.
getTableheader().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
Debug.println("tableheader.getReorderingAllowed() = " + getTableheader().getReorderingAllowed());
if (!getTableheader().getReorderingAllowed()) {
return;
}
if (e.getClickCount() == 2) {
SorterDialog.getInstance().setVisible(true);
}
}
@Override
public void mouseReleased(MouseEvent arg0) {
if (!getTableheader().getReorderingAllowed()) {
return;
}
BugTreeModel bt = (BugTreeModel) (getTree().getModel());
bt.checkSorter();
}
});
sorter = GUISaveState.getInstance().getStarterTable();
getTableheader().setColumnModel(getSorter());
getTableheader().setToolTipText(edu.umd.cs.findbugs.L10N.getLocalString("tooltip.reorder_message", "Drag to reorder tree folder and sort order"));
tree = new JTree();
getTree().setLargeModel(true);
getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
getTree().setCellRenderer(new BugRenderer());
getTree().setRowHeight((int) (Driver.getFontSize() + 7));
getTree().setModel(new BugTreeModel(mainFrame, getTree(), getSorter(), new BugSet(new ArrayList<BugLeafNode>())));
setupTreeListeners();
mainFrame.setProject(new Project());
treeScrollPane = new JScrollPane(getTree());
treePanel = new JPanel(new BorderLayout());
treePanel.add(treeScrollPane, BorderLayout.CENTER);
JTable t = new JTable(new DefaultTableModel(0, sortables().length));
t.setTableHeader(getTableheader());
textFieldForPackagesToDisplay = new JTextField();
ActionListener filterAction = e -> {
try {
String text = textFieldForPackagesToDisplay.getText();
if (text.indexOf('/') >= 0) {
text = text.replace('/', '.');
textFieldForPackagesToDisplay.setText(text);
}
mainFrame.getViewFilter().setPackagesToDisplay(text);
mainFrame.resetViewCache();
} catch (IllegalArgumentException err) {
JOptionPane.showMessageDialog(mainFrame, err.getMessage(), "Bad class search string", JOptionPane.ERROR_MESSAGE);
}
};
textFieldForPackagesToDisplay.addActionListener(filterAction);
JButton filterButton = new JButton("Filter");
filterButton.addActionListener(filterAction);
JPanel filterPanel = new JPanel();
filterPanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1;
gbc.fill = GridBagConstraints.BOTH;
gbc.gridy = 1;
filterPanel.add(textFieldForPackagesToDisplay, gbc);
gbc.weightx = 0;
gbc.fill = GridBagConstraints.NONE;
filterPanel.add(filterButton, gbc);
filterPanel.setToolTipText("Only show classes containing the word(s) you specify");
JPanel sortablePanel = new JPanel(new GridBagLayout());
JLabel sortableLabel = new JLabel("Group bugs by:");
sortableLabel.setLabelFor(getTableheader());
gbc = new GridBagConstraints();
gbc.weightx = 0;
gbc.gridy = 1;
gbc.insets = new Insets(3, 3, 3, 3);
gbc.fill = GridBagConstraints.BOTH;
sortablePanel.add(sortableLabel, gbc);
gbc.weightx = 1;
sortablePanel.add(getTableheader(), gbc);
getTableheader().setBorder(new LineBorder(Color.BLACK));
JPanel topPanel = makeNavigationPanel("Class name filter:", filterPanel, sortablePanel, treePanel);
cardPanel = new JPanel(new CardLayout());
JPanel waitPanel = new JPanel();
waitPanel.setLayout(new BoxLayout(waitPanel, BoxLayout.Y_AXIS));
waitPanel.add(new JLabel("Please wait..."));
waitStatusLabel = new JLabel();
waitPanel.add(waitStatusLabel);
cardPanel.add(topPanel, MainFrame.BugCard.TREECARD.name());
cardPanel.add(waitPanel, MainFrame.BugCard.WAITCARD.name());
return cardPanel;
}
use of edu.umd.cs.findbugs.Project in project spotbugs by spotbugs.
the class NewProjectWizard method createFilePanel.
private JPanel createFilePanel(final String label, final JList<String> list, final DefaultListModel<String> listModel, final int fileSelectionMode, final FileFilter filter, final String dialogTitle, boolean wizard, final String helpUrl) {
JPanel myPanel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridheight = 1;
gbc.gridwidth = 1;
gbc.weightx = 1;
gbc.weighty = 0;
gbc.anchor = GridBagConstraints.WEST;
myPanel.add(new JLabel(label), gbc);
gbc.gridx = 1;
gbc.gridy = 0;
gbc.gridheight = 1;
gbc.gridwidth = 1;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.anchor = GridBagConstraints.WEST;
JButton button = new JButton("<HTML><U>Help");
button.setFont(button.getFont().deriveFont(Font.PLAIN));
button.setForeground(Color.BLUE);
button.setBorderPainted(false);
button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
button.setContentAreaFilled(false);
button.addActionListener(e -> {
try {
LaunchBrowser.showDocument(new URL(helpUrl));
} catch (MalformedURLException e1) {
throw new IllegalStateException(e1);
}
});
myPanel.add(button, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridheight = 3;
gbc.gridwidth = 1;
gbc.weightx = 1;
gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH;
myPanel.add(new JScrollPane(list), gbc);
list.setModel(listModel);
gbc.gridx = 1;
gbc.gridy = 1;
gbc.gridheight = 1;
gbc.gridwidth = 1;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
final JButton addButton = new JButton(edu.umd.cs.findbugs.L10N.getLocalString("dlg.add_btn", "Add"));
myPanel.add(addButton, gbc);
gbc.gridx = 1;
gbc.gridy = 2;
gbc.insets = new Insets(5, 0, 0, 0);
final JButton removeButton = new JButton(edu.umd.cs.findbugs.L10N.getLocalString("dlg.remove_btn", "Remove"));
myPanel.add(removeButton, gbc);
gbc.gridx = 1;
gbc.gridy = 3;
final JButton wizardButton = new JButton("Wizard");
if (wizard) {
final NewProjectWizard thisGUI = this;
myPanel.add(wizardButton, gbc);
wizardButton.addActionListener(evt -> {
final Project tempProject = new Project();
for (int i1 = 0; i1 < analyzeModel.getSize(); i1++) {
tempProject.addFile(analyzeModel.get(i1));
}
for (int i2 = 0; i2 < auxModel.getSize(); i2++) {
tempProject.addAuxClasspathEntry(auxModel.get(i2));
}
java.awt.EventQueue.invokeLater(() -> {
final SourceDirectoryWizard dialog = new SourceDirectoryWizard(new javax.swing.JFrame(), true, tempProject, thisGUI);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
if (dialog.discover != null && dialog.discover.isAlive()) {
dialog.discover.interrupt();
}
}
});
dialog.setVisible(true);
});
});
}
gbc.insets = new Insets(0, 0, 0, 0);
myPanel.add(Box.createGlue(), gbc);
myPanel.setBorder(border);
addButton.addActionListener(evt -> {
chooser.setFileSelectionMode(fileSelectionMode);
chooser.setMultiSelectionEnabled(true);
chooser.setApproveButtonText("Choose");
chooser.setDialogTitle(dialogTitle);
// Removes all the file filters currently in the chooser.
for (FileFilter ff : chooser.getChoosableFileFilters()) {
chooser.removeChoosableFileFilter(ff);
}
chooser.setFileFilter(filter);
if (chooser.showOpenDialog(NewProjectWizard.this) == JFileChooser.APPROVE_OPTION) {
File[] selectedFiles = chooser.getSelectedFiles();
for (File selectedFile : selectedFiles) {
listModel.addElement(selectedFile.getAbsolutePath());
}
projectChanged = true;
// it to enable the finish button of the main dialog
if (label.equals(edu.umd.cs.findbugs.L10N.getLocalString("dlg.class_jars_dirs_lbl", "Class archives and directories to analyze:"))) {
finishButton.setEnabled(true);
}
}
});
removeButton.addActionListener(evt -> {
if (list.getSelectedValues().length > 0) {
projectChanged = true;
}
for (Object i : list.getSelectedValues()) {
listModel.removeElement(i);
// If this is the primary class directories remove button, set
// it to disable finish when there are no class files being
// analyzed
// if (listModel.size()==0 &&
// label.equals(edu.umd.cs.findbugs.L10N.getLocalString("dlg.class_jars_dirs_lbl",
// "Class archives and directories to analyze:")))
// finishButton.setEnabled(false);
}
});
return myPanel;
}
use of edu.umd.cs.findbugs.Project in project spotbugs by spotbugs.
the class PreferencesFrame method handleWindowClose.
private void handleWindowClose() {
TreeModel bt = (MainFrame.getInstance().getTree().getModel());
if (bt instanceof BugTreeModel) {
((BugTreeModel) bt).checkSorter();
}
Project project = getCurrentProject();
boolean changed = pluginsAdded;
pluginsAdded = false;
List<String> enabledPlugins = new ArrayList<>();
List<String> disabledPlugins = new ArrayList<>();
for (Map.Entry<Plugin, EnabledSettings> entry : pluginEnabledStatus.entrySet()) {
Plugin plugin = entry.getKey();
EnabledSettings enabled = entry.getValue();
if (project != null) {
Boolean newSetting = enabled.project;
Boolean existingSetting = project.getPluginStatus(plugin);
boolean sameSettings = Objects.equals(existingSetting, newSetting);
if (!sameSettings) {
project.setPluginStatusTrinary(plugin.getPluginId(), newSetting);
changed = true;
}
}
if (enabled.global) {
enabledPlugins.add(plugin.getPluginId());
} else {
disabledPlugins.add(plugin.getPluginId());
}
if (plugin.isGloballyEnabled() != enabled.global) {
plugin.setGloballyEnabled(enabled.global);
changed = true;
}
}
if (changed && project != null) {
MainFrame.getInstance().updateBugTree();
MainFrame.getInstance().setProjectChanged(true);
}
if (project == null) {
GUISaveState.getInstance().setPluginsEnabled(enabledPlugins, disabledPlugins);
GUISaveState.getInstance().save();
}
}
use of edu.umd.cs.findbugs.Project in project spotbugs by spotbugs.
the class SourceDirectoryWizard method main.
// GEN-LAST:event_finshButtonActionPerformed
/**
* @param args
* the command line arguments
*/
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(() -> {
final SourceDirectoryWizard dialog = new SourceDirectoryWizard(new JFrame(), true, new Project(), null);
dialog.setVisible(true);
});
}
Aggregations