Skip to content

Commit 1638e94

Browse files
committed
Consider projects even if pmd is not enabled
1 parent a46d89e commit 1638e94

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/ui/properties/ExternalRuleSetFileTest.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
public class ExternalRuleSetFileTest {
3131
private static final Logger LOG = LoggerFactory.getLogger(ExternalRuleSetFileTest.class);
3232

33+
private static final String PMD_PROPERTIES_FILENAME = ".pmd";
34+
3335
private static final String PROJECT_RULESET_FILENAME = ".pmd-ruleset.xml";
3436

3537
private IProject testProject;
@@ -106,6 +108,48 @@ public void changedExternalRulesetShouldBeReloaded() throws Exception {
106108
Assert.assertSame(model, model2);
107109
}
108110

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+
109153
@Test
110154
public void externallyChangedProjectPropertiesShouldBeReloaded() throws Exception {
111155
setUpProject("ProjectPropertiesChanged");
@@ -146,7 +190,7 @@ public void externallyChangedProjectPropertiesShouldBeReloaded() throws Exceptio
146190
ResourceUtil.copyResource(this, "ruleset1.xml", ruleSetFileReal);
147191

148192
// 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);
150194
if (!projectPropertiesFile.exists()) {
151195
Assert.fail("File .pmd does not exist!");
152196
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/properties/impl/ProjectPropertiesImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,7 @@ public void setProjectWorkingSet(final IWorkingSet projectWorkingSet) {
263263
*/
264264
@Override
265265
public boolean isNeedRebuild() {
266-
LOG.debug("Query if project {} need rebuild : {}", project.getName(), pmdEnabled && needRebuild);
267-
LOG.debug(" PMD Enabled = {}", pmdEnabled);
268-
LOG.debug(" Project need rebuild = {}", needRebuild);
266+
LOG.debug("Query if project {} need rebuild : {}", project.getName(), needRebuild);
269267
if (ruleSetStoredInProject) {
270268
boolean rulesetFilesChanged = false;
271269
for (File f : getResolvedRuleSetFiles()) {
@@ -275,7 +273,7 @@ public boolean isNeedRebuild() {
275273
LOG.debug(" ruleset files have changed = {}", rulesetFilesChanged);
276274
this.setNeedRebuild(needRebuild | rulesetFilesChanged);
277275
}
278-
return pmdEnabled && needRebuild;
276+
return needRebuild;
279277
}
280278

281279
/**

0 commit comments

Comments
 (0)