Search in sources :

Example 1 with IPreferencesManager

use of net.sourceforge.pmd.eclipse.runtime.preferences.IPreferencesManager 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 IPreferencesManager

use of net.sourceforge.pmd.eclipse.runtime.preferences.IPreferencesManager in project pmd-eclipse-plugin by pmd.

the class ProjectPropertiesModelTest method testProjectRuleSet.

/**
 * A brand new project should be affected the Plugin ruleset in the global ruleset.
 */
@Test
public void testProjectRuleSet() throws PropertiesException {
    final IProjectPropertiesManager mgr = PMDPlugin.getDefault().getPropertiesManager();
    final IProjectProperties model = mgr.loadProjectProperties(this.testProject);
    final IPreferencesManager pmgr = PMDPlugin.getDefault().getPreferencesManager();
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(byteStream);
    Assert.assertTrue("A new project is not created with the default plugin ruleset", EclipseUtils.assertRuleSetEquals(model.getProjectRuleSet().getRules(), pmgr.getRuleSet().getRules(), out));
}
Also used : IPreferencesManager(net.sourceforge.pmd.eclipse.runtime.preferences.IPreferencesManager) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 3 with IPreferencesManager

use of net.sourceforge.pmd.eclipse.runtime.preferences.IPreferencesManager in project pmd-eclipse-plugin by pmd.

the class ProjectPropertiesModelTest method testProjectRuleSet2.

/**
 * When rules are removed from the plugin preferences, these rules should also be removed from the project euh...
 * ben en fait non. annulé.
 */
@Test
@Ignore("implementation is not finished - maybe the behavior would even be wrong")
public void testProjectRuleSet2() throws PropertiesException, RuleSetNotFoundException, CoreException {
    // First ensure that the plugin initial ruleset is equal to the project
    // // ruleset IProjectPropertiesManager
    final IProjectPropertiesManager mgr = PMDPlugin.getDefault().getPropertiesManager();
    final IProjectProperties model = mgr.loadProjectProperties(this.testProject);
    RuleSet projectRuleSet = model.getProjectRuleSet();
    Assert.assertEquals("The project ruleset is not equal to the plugin ruleset", this.initialPluginRuleSet.getRules(), projectRuleSet.getRules());
    final RuleSetFactory factory = new RuleSetFactory();
    // use the best practices ruleset because it should be included in the
    // plugin ruleset.
    final RuleSet bestPracticesRuleSet = factory.createRuleSet("category/java/bestpractices.xml");
    IPreferencesManager pmgr = PMDPlugin.getDefault().getPreferencesManager();
    pmgr.setRuleSet(bestPracticesRuleSet);
    projectRuleSet = model.getProjectRuleSet();
    dumpRuleSet(bestPracticesRuleSet);
    dumpRuleSet(projectRuleSet);
    Assert.assertEquals("The project ruleset is not equal to the plugin ruleset", bestPracticesRuleSet.getRules(), projectRuleSet.getRules());
}
Also used : RuleSetFactory(net.sourceforge.pmd.RuleSetFactory) IPreferencesManager(net.sourceforge.pmd.eclipse.runtime.preferences.IPreferencesManager) RuleSet(net.sourceforge.pmd.RuleSet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with IPreferencesManager

use of net.sourceforge.pmd.eclipse.runtime.preferences.IPreferencesManager in project pmd-eclipse-plugin by pmd.

the class FilterPreferencesPage method performOk.

/**
 * @return boolean
 * @see org.eclipse.jface.preference.IPreferencePage#performOk()
 */
@Override
public boolean performOk() {
    IPreferencesManager ipMgr = plugin.getPreferencesManager();
    RuleSet ruleSet = ipMgr.getRuleSet();
    ruleSet = RuleSetUtil.setExcludePatterns(ruleSet, tableFilters(false));
    ruleSet = RuleSetUtil.setIncludePatterns(ruleSet, tableFilters(true));
    ipMgr.setRuleSet(ruleSet);
    Set<FilterHolder> filters = currentCheckedFilters();
    preferences.activeExclusionPatterns(patternsIn(filters, false));
    preferences.activeInclusionPatterns(patternsIn(filters, true));
    preferences.sync();
    if (isModified()) {
        rebuildProjects();
    }
    return super.performOk();
}
Also used : IPreferencesManager(net.sourceforge.pmd.eclipse.runtime.preferences.IPreferencesManager) RuleSet(net.sourceforge.pmd.RuleSet)

Example 5 with IPreferencesManager

use of net.sourceforge.pmd.eclipse.runtime.preferences.IPreferencesManager 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

IPreferencesManager (net.sourceforge.pmd.eclipse.runtime.preferences.IPreferencesManager)5 Test (org.junit.Test)3 RuleSet (net.sourceforge.pmd.RuleSet)2 IPreferences (net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 RulePriority (net.sourceforge.pmd.RulePriority)1 RuleSetFactory (net.sourceforge.pmd.RuleSetFactory)1 Ignore (org.junit.Ignore)1