Skip to content

Commit ce0523d

Browse files
committed
Deprecate and remove usage of IntegerProperty
1 parent 21968bc commit ce0523d

File tree

8 files changed

+37
-139
lines changed

8 files changed

+37
-139
lines changed

ReleaseNotes.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ This is a minor release.
2121
* `setExcludePatterns(RuleSet ruleSet, Collection<String> excludePatterns)`
2222
* `setIncludePatterns(RuleSet ruleSet, Collection<String> includePatterns)`
2323
* These methods are not supposed to be public API and will be removed eventually.
24+
* The property `net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants.MAX_VIOLATIONS_DESCRIPTOR`
25+
is deprecated and will be removed.
26+
* The preference "net.sourceforge.pmd.eclipse.plugin.max_violations_pfpr" is deprecated and will be removed.
27+
It was never implemented. The following methods and fields are deprecated:
28+
* `net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences.getMaxViolationsPerFilePerRule()`
29+
* `net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences.setMaxViolationsPerFilePerRule(int)`
30+
* `net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences.MAX_VIOLATIONS_PFPR_DEFAULT`
31+
2432

2533
### External Contributions
2634

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/PMDRuntimeConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public class PMDRuntimeConstants {
3131
public static final String[] ALL_MARKER_TYPES = new String[] { PMD_MARKER, PMD_DFA_MARKER, PMD_TASKMARKER,
3232
PMD_MARKER_1, PMD_MARKER_2, PMD_MARKER_3, PMD_MARKER_4, PMD_MARKER_5 };
3333

34+
/**
35+
* @deprecated not useful, as the property cannot occur on rules anyway. The default was used always,
36+
* which was 1000 violations.
37+
*/
38+
@Deprecated
3439
public static final IntegerProperty MAX_VIOLATIONS_DESCRIPTOR = new IntegerProperty("maxviolations",
3540
"Max allowable violations", 1, Integer.MAX_VALUE - 1, 1000, 0f);
3641

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd/BaseVisitor.java

Lines changed: 14 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.io.Reader;
1212
import java.util.ArrayList;
1313
import java.util.Arrays;
14-
import java.util.HashMap;
1514
import java.util.HashSet;
1615
import java.util.List;
1716
import java.util.Locale;
@@ -452,26 +451,6 @@ private boolean isFileInWorkingSet(final IFile file) throws PropertiesException
452451
return fileInWorkingSet;
453452
}
454453

455-
/**
456-
* Update markers list for the specified file
457-
*
458-
* @param file
459-
* the file for which markers are to be updated
460-
* @param context
461-
* a PMD context
462-
* @param fTask
463-
* indicate if a task marker should be created
464-
* @param accumulator
465-
* a map that contains impacted file and marker informations
466-
*/
467-
468-
private int maxAllowableViolationsFor(Rule rule) {
469-
470-
return rule.hasDescriptor(PMDRuntimeConstants.MAX_VIOLATIONS_DESCRIPTOR)
471-
? rule.getProperty(PMDRuntimeConstants.MAX_VIOLATIONS_DESCRIPTOR)
472-
: PMDRuntimeConstants.MAX_VIOLATIONS_DESCRIPTOR.defaultValue();
473-
}
474-
475454
public static String markerTypeFor(RuleViolation violation) {
476455
switch (violation.getRule().getPriority()) {
477456
case HIGH:
@@ -505,9 +484,6 @@ private void updateMarkers(IFile file, List<RuleViolation> violations, boolean f
505484
Review review = new Review();
506485
// final IPreferences preferences =
507486
// PMDPlugin.getDefault().loadPreferences();
508-
// final int maxViolationsPerFilePerRule =
509-
// preferences.getMaxViolationsPerFilePerRule();
510-
Map<Rule, Integer> violationsByRule = new HashMap<Rule, Integer>();
511487

512488
Rule rule;
513489
for (RuleViolation violation : violations) {
@@ -521,34 +497,20 @@ private void updateMarkers(IFile file, List<RuleViolation> violations, boolean f
521497
continue;
522498
}
523499

524-
Integer count = violationsByRule.get(rule);
525-
if (count == null) {
526-
count = 0;
527-
violationsByRule.put(rule, count);
528-
}
529-
530-
int maxViolations = maxAllowableViolationsFor(rule);
531-
532-
if (count.intValue() < maxViolations) {
533-
// Ryan Gustafson 02/16/2008 - Always use PMD_MARKER, as people
534-
// get confused as to why PMD problems don't always show up on
535-
// Problems view like they do when you do build.
536-
// markerSet.add(getMarkerInfo(violation, fTask ?
537-
// PMDRuntimeConstants.PMD_TASKMARKER :
538-
// PMDRuntimeConstants.PMD_MARKER));
539-
markerSet.add(getMarkerInfo(violation, markerTypeFor(violation)));
540-
/*
541-
* if (isDfaEnabled && violation.getRule().usesDFA()) { markerSet.add(getMarkerInfo(violation,
542-
* PMDRuntimeConstants.PMD_DFA_MARKER)); } else { markerSet.add(getMarkerInfo(violation, fTask ?
543-
* PMDRuntimeConstants.PMD_TASKMARKER : PMDRuntimeConstants.PMD_MARKER)); }
544-
*/
545-
violationsByRule.put(rule, Integer.valueOf(count.intValue() + 1));
546-
547-
LOG.debug("Adding a violation for rule " + rule.getName() + " at line " + violation.getBeginLine());
548-
} else {
549-
LOG.debug("Ignoring violation of rule " + rule.getName() + " at line " + violation.getBeginLine()
550-
+ " because maximum violations has been reached for file " + file.getName());
551-
}
500+
// Ryan Gustafson 02/16/2008 - Always use PMD_MARKER, as people
501+
// get confused as to why PMD problems don't always show up on
502+
// Problems view like they do when you do build.
503+
// markerSet.add(getMarkerInfo(violation, fTask ?
504+
// PMDRuntimeConstants.PMD_TASKMARKER :
505+
// PMDRuntimeConstants.PMD_MARKER));
506+
markerSet.add(getMarkerInfo(violation, markerTypeFor(violation)));
507+
/*
508+
* if (isDfaEnabled && violation.getRule().usesDFA()) { markerSet.add(getMarkerInfo(violation,
509+
* PMDRuntimeConstants.PMD_DFA_MARKER)); } else { markerSet.add(getMarkerInfo(violation, fTask ?
510+
* PMDRuntimeConstants.PMD_TASKMARKER : PMDRuntimeConstants.PMD_MARKER)); }
511+
*/
512+
513+
LOG.debug("Adding a violation for rule " + rule.getName() + " at line " + violation.getBeginLine());
552514
}
553515

554516
if (accumulator != null) {

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/preferences/IPreferences.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public interface IPreferences {
2626
boolean PMD_VIOLATIONS_OUTLINE_ENABLED_DEFAULT = false;
2727
boolean PMD_CHECK_AFTER_SAVE_DEFAULT = false;
2828
boolean PMD_USE_CUSTOM_PRIORITY_NAMES_DEFAULT = true;
29+
@Deprecated
2930
int MAX_VIOLATIONS_PFPR_DEFAULT = 5;
3031
boolean DETERMINE_FILETYPES_AUTOMATICALLY_DEFAULT = true;
3132
String REVIEW_ADDITIONAL_COMMENT_DEFAULT = "by {0} on {1}";
@@ -131,15 +132,21 @@ public interface IPreferences {
131132
/**
132133
* Get the maximum number of violations per file per rule reported by the
133134
* plugin. This parameter is used to improve performances
135+
*
136+
* @deprecated
134137
*/
138+
@Deprecated
135139
int getMaxViolationsPerFilePerRule();
136140

137141
/**
138142
* Set the maximum number of violations per file per rule reported by the
139143
* plugin
140144
*
141145
* @param maxViolationPerFilePerRule
146+
*
147+
* @deprecated
142148
*/
149+
@Deprecated
143150
void setMaxViolationsPerFilePerRule(int maxViolationPerFilePerRule);
144151

145152
/**

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/preferences/impl/PreferencesManagerImpl.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ public void storePreferences(IPreferences thePreferences) {
261261
storePmdViolationsOutlineEnabled();
262262
storeCheckAfterSaveEnabled();
263263
storeUseCustomPriorityNames();
264-
storeMaxViolationsPerFilePerRule();
265264
storeDetermineFiletypesAutomatically();
266265
storeReviewAdditionalComment();
267266
storeReviewPmdStyleEnabled();
@@ -536,10 +535,6 @@ private void storePmdViolationsOverviewEnabled() {
536535
private void storePmdViolationsOutlineEnabled() {
537536
storePreferencesStore.setValue(PMD_VIOLATIONS_OUTLINE_ENABLED, preferences.isPmdViolationsOutlineEnabled());
538537
}
539-
540-
private void storeMaxViolationsPerFilePerRule() {
541-
storePreferencesStore.setValue(MAX_VIOLATIONS_PFPR, preferences.getMaxViolationsPerFilePerRule());
542-
}
543538

544539
private void storeDetermineFiletypesAutomatically() {
545540
storePreferencesStore.setValue(DETERMINE_FILETYPES_AUTOMATICALLY, preferences.isDetermineFiletypesAutomatically());

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/actions/internal/InternalRuleSetUtil.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import net.sourceforge.pmd.RulesetsFactoryUtils;
1515

1616
public class InternalRuleSetUtil {
17+
private InternalRuleSetUtil() {}
18+
1719
public static RuleSet setFileExclusions(RuleSet ruleSet, Collection<Pattern> excludePatterns) {
1820
RuleSetFactory factory = RulesetsFactoryUtils.defaultFactory();
1921
return factory.createNewRuleSet(ruleSet.getName(), ruleSet.getDescription(), ruleSet.getFileName(),

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/GeneralPreferencesPage.java

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.eclipse.swt.widgets.Label;
4444
import org.eclipse.swt.widgets.Link;
4545
import org.eclipse.swt.widgets.Scale;
46-
import org.eclipse.swt.widgets.Spinner;
4746
import org.eclipse.swt.widgets.Table;
4847
import org.eclipse.swt.widgets.Text;
4948
import org.eclipse.ui.IWorkbench;
@@ -92,7 +91,6 @@ public class GeneralPreferencesPage extends PreferencePage implements IWorkbench
9291
private Button useProjectBuildPath;
9392
private Button checkCodeOnSave;
9493
private Button useCustomPriorityNames;
95-
private Spinner maxViolationsPerFilePerRule;
9694
private Button reviewPmdStyleBox;
9795
private Text logFileNameText;
9896
private Scale logLevelScale;
@@ -169,7 +167,6 @@ private Group buildGeneralGroup(final Composite parent) {
169167
checkCodeOnSave = buildCheckCodeOnSaveButton(group);
170168
determineFiletypesAutomatically = buildDetermineFiletypesAutomatically(group);
171169
Label separator = new Label(group, SWT.SEPARATOR | SWT.SHADOW_IN | SWT.HORIZONTAL);
172-
maxViolationsPerFilePerRule = buildMaxViolationsPerFilePerRuleText(group);
173170

174171
GridData data = new GridData();
175172
data.horizontalAlignment = GridData.FILL;
@@ -196,11 +193,6 @@ private Group buildGeneralGroup(final Composite parent) {
196193
data.grabExcessHorizontalSpace = true;
197194
separator.setLayoutData(data);
198195

199-
data = new GridData();
200-
data.horizontalAlignment = GridData.FILL;
201-
data.grabExcessHorizontalSpace = true;
202-
maxViolationsPerFilePerRule.setLayoutData(data);
203-
204196
return group;
205197
}
206198

@@ -710,29 +702,6 @@ private Button buildUseProjectBuildPathButton(Composite viewGroup) {
710702
return button;
711703
}
712704

713-
/**
714-
* Build the text for maximum violations per file per rule
715-
*
716-
* @param parent
717-
* @return
718-
*/
719-
private Spinner buildMaxViolationsPerFilePerRuleText(Composite parent) {
720-
721-
Composite comp = new Composite(parent, 0);
722-
comp.setLayout(new GridLayout(2, false));
723-
724-
Label label = buildLabel(comp, StringKeys.PREF_GENERAL_LABEL_MAX_VIOLATIONS_PFPR);
725-
label.setLayoutData(
726-
new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.VERTICAL_ALIGN_CENTER, false, false, 1, 1));
727-
728-
final Spinner spinner = new Spinner(comp, SWT.BORDER);
729-
spinner.setLayoutData(
730-
new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.VERTICAL_ALIGN_CENTER, true, false, 1, 1));
731-
spinner.setMinimum(preferences.getMaxViolationsPerFilePerRule());
732-
spinner.setToolTipText(getMessage(StringKeys.PREF_GENERAL_TOOLTIP_MAX_VIOLATIONS_PFPR));
733-
return spinner;
734-
}
735-
736705
private Button buildDetermineFiletypesAutomatically(Composite viewGroup) {
737706
Button button = new Button(viewGroup, SWT.CHECK);
738707
button.setText(getMessage(StringKeys.PREF_GENERAL_LABEL_DETERMINE_FILETYPES_AUTOMATICALLY));
@@ -794,10 +763,6 @@ protected void performDefaults() {
794763
setSelection(reviewPmdStyleBox, IPreferences.REVIEW_PMD_STYLE_ENABLED_DEFAULT);
795764
setSelection(determineFiletypesAutomatically, IPreferences.DETERMINE_FILETYPES_AUTOMATICALLY_DEFAULT);
796765

797-
if (maxViolationsPerFilePerRule != null) {
798-
maxViolationsPerFilePerRule.setMinimum(IPreferences.MAX_VIOLATIONS_PFPR_DEFAULT);
799-
}
800-
801766
setText(logFileNameText, IPreferences.LOG_FILENAME_DEFAULT);
802767

803768
if (logLevelScale != null) {
@@ -916,11 +881,6 @@ public boolean performOk() {
916881
preferences.setProjectBuildPathEnabled(useProjectBuildPath.getSelection());
917882
}
918883

919-
if (maxViolationsPerFilePerRule != null) {
920-
preferences
921-
.setMaxViolationsPerFilePerRule(Integer.valueOf(maxViolationsPerFilePerRule.getText()).intValue());
922-
}
923-
924884
if (determineFiletypesAutomatically != null) {
925885
preferences.setDetermineFiletypesAutomatically(determineFiletypesAutomatically.getSelection());
926886
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/views/ViolationOverviewLabelProvider.java

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
import org.eclipse.jface.viewers.LabelProvider;
1313
import org.eclipse.swt.graphics.Image;
1414

15-
import net.sourceforge.pmd.Rule;
1615
import net.sourceforge.pmd.RulePriority;
1716
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
18-
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
1917
import net.sourceforge.pmd.eclipse.ui.PMDUiConstants;
2018
import net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord;
2119
import net.sourceforge.pmd.eclipse.ui.model.FileRecord;
@@ -123,46 +121,7 @@ public String getColumnText(Object element, int columnIndex) {
123121
*/
124122
private String getNumberOfViolations(AbstractPMDRecord element) {
125123
final int violations = this.violationView.getNumberOfFilteredViolations(element);
126-
String result = String.valueOf(violations);
127-
128-
if (element instanceof MarkerRecord && violationView.getShowType() != ViolationOverview.SHOW_MARKERS_FILES) {
129-
final String ruleName = ((MarkerRecord) element).getName();
130-
final int maxViolations = getMaxViolations(ruleName);
131-
132-
if (violations == maxViolations) {
133-
result = "(max) " + result;
134-
}
135-
} else if (element instanceof FileToMarkerRecord) {
136-
final String ruleName = ((FileToMarkerRecord) element).getParent().getName();
137-
final int maxViolations = getMaxViolations(ruleName);
138-
139-
if (violations == maxViolations) {
140-
result = "(max) " + result;
141-
}
142-
}
143-
144-
return result;
145-
}
146-
147-
/**
148-
* Gets the maximum number of violations to a rule.
149-
*
150-
* @param ruleName
151-
* name of the rule
152-
* @return maximum number
153-
*/
154-
private int getMaxViolations(String ruleName) {
155-
int maxViolations = PMDPlugin.getDefault().loadPreferences().getMaxViolationsPerFilePerRule();
156-
final Rule rule = PMDPlugin.getDefault().getPreferencesManager().getRuleSet().getRuleByName(ruleName);
157-
if (rule != null) {
158-
if (rule.hasDescriptor(PMDRuntimeConstants.MAX_VIOLATIONS_DESCRIPTOR)) {
159-
return rule.getProperty(PMDRuntimeConstants.MAX_VIOLATIONS_DESCRIPTOR);
160-
} else {
161-
return PMDRuntimeConstants.MAX_VIOLATIONS_DESCRIPTOR.defaultValue();
162-
}
163-
}
164-
165-
return maxViolations;
124+
return String.valueOf(violations);
166125
}
167126

168127
/**

0 commit comments

Comments
 (0)