use of net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences in project pmd-eclipse-plugin by pmd.
the class PreferencesManagerImplTest method storeAndLoadInactiveRules.
/**
* See bug https://sourceforge.net/p/pmd/bugs/1184/
*
* Inactive rules were not stored / loaded
*/
@Test
public void storeAndLoadInactiveRules() {
String ruleName = "LocalVariableCouldBeFinal";
IPreferencesManager manager = PMDPlugin.getDefault().getPreferencesManager();
IPreferences preferences = manager.loadPreferences();
preferences.isActive(ruleName, false);
manager.storePreferences(preferences);
Assert.assertFalse(preferences.getActiveRuleNames().contains(ruleName));
preferences = manager.reloadPreferences();
Assert.assertFalse(preferences.getActiveRuleNames().contains(ruleName));
}
use of net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences in project pmd-eclipse-plugin by pmd.
the class ReviewCodeCmd method filteredRuleSet.
private RuleSet filteredRuleSet(IProjectProperties properties) throws CommandException, PropertiesException {
final RuleSet ruleSet = properties.getProjectRuleSet();
IPreferences preferences = PMDPlugin.getDefault().getPreferencesManager().loadPreferences();
Set<String> onlyActiveRuleNames = preferences.getActiveRuleNames();
int rulesBefore = ruleSet.size();
RuleSet filteredRuleSet = RuleSetUtil.newCopyOf(ruleSet);
if (preferences.getGlobalRuleManagement()) {
// TODO: active rules are not language aware... filter by rule
// name...
List<Rule> rulesToKeep = new ArrayList<Rule>();
for (Rule rule : filteredRuleSet.getRules()) {
if (onlyActiveRuleNames.contains(rule.getName())) {
rulesToKeep.add(rule);
}
}
filteredRuleSet = RuleSetUtil.retainOnly(filteredRuleSet, rulesToKeep);
int rulesAfter = filteredRuleSet.size();
if (rulesAfter < rulesBefore) {
PMDPlugin.getDefault().logWarn("Ruleset has been filtered as Global Rule Management is active. " + rulesAfter + " of " + rulesBefore + " rules are active and are used. " + (rulesBefore - rulesAfter) + " rules will be ignored.");
}
}
filteredRuleSet = RuleSetUtil.addExcludePatterns(filteredRuleSet, preferences.activeExclusionPatterns(), properties.getBuildPathExcludePatterns());
filteredRuleSet = RuleSetUtil.addIncludePatterns(filteredRuleSet, preferences.activeInclusionPatterns(), properties.getBuildPathIncludePatterns());
taskScope(filteredRuleSet.getRules().size(), ruleSet.getRules().size());
return filteredRuleSet;
}
use of net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences in project pmd-eclipse-plugin by pmd.
the class PMDPlugin method start.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework. BundleContext )
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
// this needs to be executed before the preferences are loaded, because
// the standard
// rulesets are needed for the default active rules.
registerStandardRuleSets();
IPreferences prefs = loadPreferences();
configureLogs(prefs);
registerAdditionalRuleSets();
fileChangeListenerEnabled(prefs.isCheckAfterSaveEnabled());
// if a project is deleted, remove the cached project properties
ResourcesPlugin.getWorkspace().addResourceChangeListener(new IResourceChangeListener() {
public void resourceChanged(IResourceChangeEvent arg0) {
if (arg0.getType() == IResourceChangeEvent.PRE_DELETE && arg0.getResource() instanceof IProject) {
getPropertiesManager().removeProjectProperties((IProject) arg0.getResource());
}
}
});
version = context.getBundle().getHeaders().get("Bundle-Version");
}
use of net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences in project pmd-eclipse-plugin by pmd.
the class ReportManager method activeRenderers.
public List<Renderer> activeRenderers() {
List<Renderer> actives = new ArrayList<Renderer>();
IPreferences prefs = PMDPlugin.getDefault().loadPreferences();
for (Renderer renderer : allRenderers) {
if (prefs.isActiveRenderer(renderer.getName())) {
actives.add(renderer);
}
}
return actives;
}
use of net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences in project pmd-eclipse-plugin by pmd.
the class PriorityDescriptorCache method storeInPreferences.
public void storeInPreferences() {
IPreferencesManager mgr = preferencesManager();
IPreferences prefs = mgr.loadPreferences();
for (Map.Entry<RulePriority, PriorityDescriptor> entry : uiDescriptorsByPriority.entrySet()) {
prefs.setPriorityDescriptor(entry.getKey(), entry.getValue());
}
mgr.storePreferences(prefs);
}
Aggregations