|
30 | 30 | public class ExternalRuleSetFileTest { |
31 | 31 | private static final Logger LOG = LoggerFactory.getLogger(ExternalRuleSetFileTest.class); |
32 | 32 |
|
| 33 | + private static final String PMD_PROPERTIES_FILENAME = ".pmd"; |
| 34 | + |
33 | 35 | private static final String PROJECT_RULESET_FILENAME = ".pmd-ruleset.xml"; |
34 | 36 |
|
35 | 37 | private IProject testProject; |
@@ -106,6 +108,48 @@ public void changedExternalRulesetShouldBeReloaded() throws Exception { |
106 | 108 | Assert.assertSame(model, model2); |
107 | 109 | } |
108 | 110 |
|
| 111 | + @Test |
| 112 | + public void changedExternalRulesetShouldBeReloadedForPmdDisabledProjects() throws Exception { |
| 113 | + setUpProject("ExternalRulesetTestPmdDisabled"); |
| 114 | + |
| 115 | + // load the project properties - pmd is not enabled, it uses the default ruleset (more than 1 active rule) |
| 116 | + final IProjectPropertiesManager mgr = PMDPlugin.getDefault().getPropertiesManager(); |
| 117 | + final IProjectProperties model = mgr.loadProjectProperties(this.testProject); |
| 118 | + RuleSet projectRuleSet = model.getProjectRuleSet(); |
| 119 | + Assert.assertNotEquals(1, projectRuleSet.getRules().size()); |
| 120 | + |
| 121 | + // now let's change the ruleSetFile without eclipse knowing about it ("externally") |
| 122 | + IFile ruleSetFile = this.testProject.getFile(PROJECT_RULESET_FILENAME); |
| 123 | + if (ruleSetFile.exists()) { |
| 124 | + Assert.fail("File " + PROJECT_RULESET_FILENAME + " already exists!"); |
| 125 | + } |
| 126 | + File ruleSetFileReal = ruleSetFile.getLocation().toFile(); |
| 127 | + ResourceUtil.copyResource(this, "ruleset1.xml", ruleSetFileReal); |
| 128 | + |
| 129 | + // now create the .pmd project properties without eclipse knowing about it ("externally") |
| 130 | + IFile projectPropertiesFile = this.testProject.getFile(PMD_PROPERTIES_FILENAME); |
| 131 | + if (projectPropertiesFile.exists()) { |
| 132 | + Assert.fail("File .pmd does already exist!"); |
| 133 | + } |
| 134 | + File projectPropertiesFileReal = projectPropertiesFile.getLocation().toFile(); |
| 135 | + ResourceUtil.copyResource(this, "pmd-properties", projectPropertiesFileReal); |
| 136 | + |
| 137 | + // the files have been created, but the .pmd file is not reloaded yet, so: |
| 138 | + Assert.assertFalse(model.isNeedRebuild()); |
| 139 | + // the model is not updated yet... |
| 140 | + Assert.assertNotEquals(1, model.getProjectRuleSet().getRules().size()); |
| 141 | + // but it will be when requesting the project properties again |
| 142 | + final IProjectProperties model2 = mgr.loadProjectProperties(testProject); |
| 143 | + // PMD is still not enabled |
| 144 | + Assert.assertFalse(model.isPmdEnabled()); |
| 145 | + // but rebuild is needed (because ruleset changed) |
| 146 | + Assert.assertTrue(model.isNeedRebuild()); |
| 147 | + // and the ruleset is loaded |
| 148 | + Assert.assertEquals(1, model2.getProjectRuleSet().getRules().size()); |
| 149 | + // the model is still cached, but the rules are updated |
| 150 | + Assert.assertSame(model, model2); |
| 151 | + } |
| 152 | + |
109 | 153 | @Test |
110 | 154 | public void externallyChangedProjectPropertiesShouldBeReloaded() throws Exception { |
111 | 155 | setUpProject("ProjectPropertiesChanged"); |
@@ -146,7 +190,7 @@ public void externallyChangedProjectPropertiesShouldBeReloaded() throws Exceptio |
146 | 190 | ResourceUtil.copyResource(this, "ruleset1.xml", ruleSetFileReal); |
147 | 191 |
|
148 | 192 | // now overwrite and change the .pmd project properties without eclipse knowing about it ("externally") |
149 | | - IFile projectPropertiesFile = this.testProject.getFile(".pmd"); |
| 193 | + IFile projectPropertiesFile = this.testProject.getFile(PMD_PROPERTIES_FILENAME); |
150 | 194 | if (!projectPropertiesFile.exists()) { |
151 | 195 | Assert.fail("File .pmd does not exist!"); |
152 | 196 | } |
|
0 commit comments