Search in sources :

Example 1 with IPreferences

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));
}
Also used : IPreferencesManager(net.sourceforge.pmd.eclipse.runtime.preferences.IPreferencesManager) IPreferences(net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences) Test(org.junit.Test)

Example 2 with IPreferences

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;
}
Also used : RuleSet(net.sourceforge.pmd.RuleSet) IPreferences(net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences) ArrayList(java.util.ArrayList) MultiRule(org.eclipse.core.runtime.jobs.MultiRule) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) Rule(net.sourceforge.pmd.Rule)

Example 3 with IPreferences

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");
}
Also used : IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IPreferences(net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) IProject(org.eclipse.core.resources.IProject)

Example 4 with IPreferences

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;
}
Also used : IPreferences(net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences) Renderer(net.sourceforge.pmd.renderers.Renderer) ArrayList(java.util.ArrayList)

Example 5 with IPreferences

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);
}
Also used : IPreferencesManager(net.sourceforge.pmd.eclipse.runtime.preferences.IPreferencesManager) IPreferences(net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences) RulePriority(net.sourceforge.pmd.RulePriority) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

IPreferences (net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences)6 ArrayList (java.util.ArrayList)2 RulePriority (net.sourceforge.pmd.RulePriority)2 IPreferencesManager (net.sourceforge.pmd.eclipse.runtime.preferences.IPreferencesManager)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Rule (net.sourceforge.pmd.Rule)1 RuleSet (net.sourceforge.pmd.RuleSet)1 Renderer (net.sourceforge.pmd.renderers.Renderer)1 IProject (org.eclipse.core.resources.IProject)1 IResourceChangeEvent (org.eclipse.core.resources.IResourceChangeEvent)1 IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)1 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)1 MultiRule (org.eclipse.core.runtime.jobs.MultiRule)1 Test (org.junit.Test)1