# HG changeset patch # User Alexander Simon # Date 1429617772 -10800 # Tue Apr 21 15:02:52 2015 +0300 # Node ID 4469b55d4d67f18f73835926d41ebe58436d4050 # Parent 0d96c2056addad41bc0de31ae0979c26c2ebf792 patch for Bug #251965 Provide way to restrict bugs by priority diff --git a/findbugs/src/org/netbeans/modules/findbugs/RunFindBugs.java b/findbugs/src/org/netbeans/modules/findbugs/RunFindBugs.java --- a/findbugs/src/org/netbeans/modules/findbugs/RunFindBugs.java +++ b/findbugs/src/org/netbeans/modules/findbugs/RunFindBugs.java @@ -113,6 +113,8 @@ import org.netbeans.api.queries.FileEncodingQuery; import org.netbeans.modules.analysis.api.CodeAnalysis; import org.netbeans.modules.analysis.spi.Analyzer.WarningDescription; +import org.netbeans.modules.findbugs.options.FindBugsPanel; +import static org.netbeans.modules.findbugs.options.FindBugsPanel.MINIMAL_LEVEL_PROPERTY; import org.netbeans.spi.editor.hints.ChangeInfo; import org.netbeans.spi.editor.hints.EnhancedFix; import org.netbeans.spi.editor.hints.ErrorDescription; @@ -142,7 +144,7 @@ public static List runFindBugs(CompilationInfo info, Preferences customSettings, String singleBug, FileObject sourceRoot, Iterable classNames, final FindBugsProgress progress, final Cancel cancel, SigFilesValidator validator) { List result = new ArrayList(); - + String level = NbPreferences.forModule(FindBugsPanel.class).get(MINIMAL_LEVEL_PROPERTY, "Hihg"); try { Class.forName("org.netbeans.modules.findbugs.NbClassFactory", true, RunFindBugs.class.getClassLoader()); //NOI18N Project p = new Project(); @@ -216,8 +218,15 @@ return projectStats; } }; - - r.setPriorityThreshold(Priorities.LOW_PRIORITY); + if (FindBugsPanel.HIGH_LEVEL.equals(level)) { + r.setPriorityThreshold(Priorities.HIGH_PRIORITY); + } else if (FindBugsPanel.MEDIUM_LEVEL.equals(level)) { + r.setPriorityThreshold(Priorities.NORMAL_PRIORITY); + } else if (FindBugsPanel.LOW_LEVEL.equals(level)) { + r.setPriorityThreshold(Priorities.LOW_PRIORITY); + } else { + r.setPriorityThreshold(Priorities.LOW_PRIORITY); + } r.setRankThreshold(20); FindBugs2 engine = new FindBugs2(); @@ -353,7 +362,7 @@ int[] span = spanForEnclosingMethod(info, js, sourceLine.getStartLine()); if (span != null && span[0] != (-1)) { LazyFixList fixes = prepareFixes(b, inEditor, sourceFile, -1, span); - result.add(ErrorDescriptionFactory.createErrorDescription(PREFIX_FINDBUGS + b.getType(), Severity.VERIFIER, b.getMessageWithoutPrefix(), b.getBugPattern().getDetailHTML(), fixes, sourceFile, span[0], span[1])); + result.add(ErrorDescriptionFactory.createErrorDescription(PREFIX_FINDBUGS + b.getType(), getSeverity(b), b.getPriorityString()+":"+b.getMessageWithoutPrefix(), b.getBugPattern().getDetailHTML(), fixes, sourceFile, span[0], span[1])); continue; } } @@ -361,7 +370,7 @@ LazyFixList fixes = prepareFixes(b, inEditor, sourceFile, sourceLine.getStartLine(), null); if (doc != null) { - result.add(ErrorDescriptionFactory.createErrorDescription(PREFIX_FINDBUGS + b.getType(), Severity.VERIFIER, b.getMessageWithoutPrefix(), b.getBugPattern().getDetailHTML(), fixes, doc, sourceLine.getStartLine())); + result.add(ErrorDescriptionFactory.createErrorDescription(PREFIX_FINDBUGS + b.getType(), getSeverity(b), b.getPriorityString()+":"+b.getMessageWithoutPrefix(), b.getBugPattern().getDetailHTML(), fixes, doc, sourceLine.getStartLine())); } else { if (lineOffsets == null) { lineOffsets = computeLineMap(sourceFile, FileEncodingQuery.getEncoding(sourceFile)); @@ -369,7 +378,7 @@ int edLine = 2 * (Math.min(sourceLine.getStartLine(), lineOffsets.length / 2) - 1); - result.add(ErrorDescriptionFactory.createErrorDescription(PREFIX_FINDBUGS + b.getType(), Severity.VERIFIER, b.getMessageWithoutPrefix(), b.getBugPattern().getDetailHTML(), fixes, sourceFile, lineOffsets[edLine], lineOffsets[edLine + 1])); + result.add(ErrorDescriptionFactory.createErrorDescription(PREFIX_FINDBUGS + b.getType(), getSeverity(b), b.getPriorityString()+":"+b.getMessageWithoutPrefix(), b.getBugPattern().getDetailHTML(), fixes, sourceFile, lineOffsets[edLine], lineOffsets[edLine + 1])); } } else { if (js == null) { @@ -415,7 +424,20 @@ if (span != null && span[0] != (-1)) { LazyFixList fixes = prepareFixes(b, globalPreferences, sourceFile, -1, span); - result.add(ErrorDescriptionFactory.createErrorDescription(PREFIX_FINDBUGS + b.getType(), Severity.VERIFIER, b.getMessageWithoutPrefix(), b.getBugPattern().getDetailHTML(), fixes, sourceFile, span[0], span[1])); + result.add(ErrorDescriptionFactory.createErrorDescription(PREFIX_FINDBUGS + b.getType(), getSeverity(b), b.getPriorityString()+":"+b.getMessageWithoutPrefix(), b.getBugPattern().getDetailHTML(), fixes, sourceFile, span[0], span[1])); + } + } + + private static Severity getSeverity(BugInstance b) { + String p = b.getPriorityAbbreviation(); + if ("H".equals(p)) { + return Severity.ERROR; + } else if ("M".equals(p)) { + return Severity.WARNING; + } else if ("L".equals(p)) { + return Severity.HINT; + } else { + return Severity.VERIFIER; } } diff --git a/findbugs/src/org/netbeans/modules/findbugs/options/Bundle.properties b/findbugs/src/org/netbeans/modules/findbugs/options/Bundle.properties --- a/findbugs/src/org/netbeans/modules/findbugs/options/Bundle.properties +++ b/findbugs/src/org/netbeans/modules/findbugs/options/Bundle.properties @@ -5,3 +5,4 @@ CustomPluginsPanel.removePlugin.text=&Remove FindBugsPanel.customPlugins.text=Custom FindBugs &Plugins... TP_RunInEditor=Will automaticaly run FindBugs on the currently editted file after save. Warning: the results in the editor and in the Source/Inspect may differ. +FindBugsPanel.jLabel2.text=Minimal warning level: diff --git a/findbugs/src/org/netbeans/modules/findbugs/options/FindBugsPanel.form b/findbugs/src/org/netbeans/modules/findbugs/options/FindBugsPanel.form --- a/findbugs/src/org/netbeans/modules/findbugs/options/FindBugsPanel.form +++ b/findbugs/src/org/netbeans/modules/findbugs/options/FindBugsPanel.form @@ -18,9 +18,18 @@ - - - + + + + + + + + + + + + @@ -32,8 +41,13 @@ - - + + + + + + + @@ -87,7 +101,7 @@ - + @@ -150,5 +164,22 @@ + + + + + + + + + + + + + + + + + diff --git a/findbugs/src/org/netbeans/modules/findbugs/options/FindBugsPanel.java b/findbugs/src/org/netbeans/modules/findbugs/options/FindBugsPanel.java --- a/findbugs/src/org/netbeans/modules/findbugs/options/FindBugsPanel.java +++ b/findbugs/src/org/netbeans/modules/findbugs/options/FindBugsPanel.java @@ -114,6 +114,10 @@ private final FindBugsOptionsPanelController controller; private final OptionsFilter filter; private final CustomizerContext cc; + public static final String MINIMAL_LEVEL_PROPERTY = "minimalLevel"; //NOI18N + public static final String HIGH_LEVEL = "High"; + public static final String MEDIUM_LEVEL = "Medium"; + public static final String LOW_LEVEL = "Low"; @Messages("LBL_Loading=Loading...") public FindBugsPanel(@NullAllowed FindBugsOptionsPanelController controller, final @NullAllowed OptionsFilter filter, final @NullAllowed CustomizerContext cc) { @@ -122,6 +126,9 @@ this.filter = filter; this.cc = cc; initComponents(); + minimalLevel.addItem(HIGH_LEVEL); + minimalLevel.addItem(MEDIUM_LEVEL); + minimalLevel.addItem(LOW_LEVEL); // prevent from jumping setPreferredSize(getPreferredSize()); reinitialize(); @@ -165,6 +172,9 @@ } initComponents(); + minimalLevel.addItem(HIGH_LEVEL); + minimalLevel.addItem(MEDIUM_LEVEL); + minimalLevel.addItem(LOW_LEVEL); this.treeModel = new DefaultTreeModel(rootNode); if (filter != null) { @@ -327,6 +337,8 @@ jLabel1 = new javax.swing.JLabel(); runInEditor = new javax.swing.JCheckBox(); customPlugins = new javax.swing.JButton(); + minimalLevel = new javax.swing.JComboBox(); + jLabel2 = new javax.swing.JLabel(); jSplitPane1.setDividerLocation(250); @@ -361,7 +373,7 @@ jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addGap(0, 147, Short.MAX_VALUE) + .addGap(0, 137, Short.MAX_VALUE) .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)) @@ -379,15 +391,24 @@ } }); + jLabel2.setLabelFor(minimalLevel); + org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(FindBugsPanel.class, "FindBugsPanel.jLabel2.text")); // NOI18N + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 538, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() - .addComponent(runInEditor) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(customPlugins) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(runInEditor) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(customPlugins)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(minimalLevel, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) ); layout.setVerticalGroup( @@ -396,8 +417,12 @@ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(runInEditor) .addComponent(customPlugins)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jSplitPane1)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(minimalLevel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 374, Short.MAX_VALUE)) ); }// //GEN-END:initComponents @@ -428,6 +453,8 @@ return; } this.runInEditor.setSelected(NbPreferences.forModule(FindBugsPanel.class).getBoolean(RunInEditor.RUN_IN_EDITOR, RunInEditor.RUN_IN_EDITOR_DEFAULT)); + String level = NbPreferences.forModule(FindBugsPanel.class).get(MINIMAL_LEVEL_PROPERTY, LOW_LEVEL); + minimalLevel.setSelectedItem(level); } void store() { @@ -436,6 +463,7 @@ return; } ((ModifiedPreferences) this.settings).store(NbPreferences.forModule(FindBugsPanel.class).node("global-settings")); + NbPreferences.forModule(FindBugsPanel.class).put(MINIMAL_LEVEL_PROPERTY, minimalLevel.getSelectedItem().toString()); NbPreferences.forModule(RunInEditor.class).putBoolean(RunInEditor.RUN_IN_EDITOR, this.runInEditor.isSelected()); if (modifiedPluginsList != null) DetectorCollectionProvider.setCustomPlugins(modifiedPluginsList); } @@ -537,10 +565,12 @@ private javax.swing.JButton customPlugins; private javax.swing.JTextPane description; private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JSplitPane jSplitPane1; + private javax.swing.JComboBox minimalLevel; private javax.swing.JCheckBox runInEditor; // End of variables declaration//GEN-END:variables