Skip to content

Commit a790522

Browse files
committed
Update PMD to 6.30.0
1 parent 7d17f91 commit a790522

File tree

3 files changed

+31
-27
lines changed

3 files changed

+31
-27
lines changed

ReleaseNotes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ This is a minor release.
1313

1414
### New and noteworthy
1515

16+
* Updated to PMD 6.30.0
17+
1618
### Fixed Issues
1719

1820
### API Changes

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd/ReviewCmdTest.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -117,45 +117,52 @@ public void testReviewCmdBasic() throws CoreException {
117117
}
118118
}
119119

120+
private IFile createMissingOverrideTestCase(IProject project) throws Exception {
121+
EclipseUtils.createTestSourceFile(project, "/src/MyInterface.java", "public interface MyInterface { void run(); }");
122+
IFile sourceFile = EclipseUtils.createTestSourceFile(project, "/src/Foo.java",
123+
"class Foo implements MyInterface {\n"
124+
+ " void run() {\n" // line 2
125+
+ " }\n"
126+
+ "}");
127+
project.build(IncrementalProjectBuilder.FULL_BUILD, null);
128+
project.refreshLocal(IResource.DEPTH_INFINITE, null);
129+
return sourceFile;
130+
}
131+
120132
/**
121133
* https://sourceforge.net/p/pmd/bugs/1145/
122134
*/
123135
@Test
124136
public void testProjectBuildPath() throws Exception {
125137
IProjectProperties properties = PMDPlugin.getDefault().getPropertiesManager()
126138
.loadProjectProperties(testProject);
127-
Rule compareObjectsWithEquals = properties.getProjectRuleSet().getRuleByName("CompareObjectsWithEquals");
128-
RuleSet projectRuleSet = RuleSetUtil.newSingle(compareObjectsWithEquals);
139+
Rule missingOverrideRule = properties.getProjectRuleSet().getRuleByName("MissingOverride");
140+
RuleSet projectRuleSet = RuleSetUtil.newSingle(missingOverrideRule);
129141
properties.setProjectRuleSet(projectRuleSet);
130142
boolean oldSetting = PMDPlugin.getDefault().getPreferencesManager().loadPreferences()
131143
.isProjectBuildPathEnabled();
132144

133145
try {
134146
PMDPlugin.getDefault().getPreferencesManager().loadPreferences().setProjectBuildPathEnabled(true);
135-
EclipseUtils.createTestSourceFile(testProject, "/src/MyEnum.java", "public enum MyEnum { A, B }");
136-
IFile sourceFile = EclipseUtils.createTestSourceFile(testProject, "/src/Foo.java",
137-
"class Foo {\n" + " boolean bar(MyEnum a, MyEnum b) {\n" + " return a == b;\n" + // line 3
138-
" }\n" + "}");
139-
testProject.build(IncrementalProjectBuilder.FULL_BUILD, null);
140-
testProject.refreshLocal(IResource.DEPTH_INFINITE, null);
147+
IFile sourceFile = createMissingOverrideTestCase(testProject);
141148

142149
ReviewCodeCmd cmd = new ReviewCodeCmd();
143150
cmd.addResource(testProject);
144151
cmd.performExecute();
145152
cmd.join();
146153
Map<IFile, Set<MarkerInfo2>> markers = cmd.getMarkers();
147-
// with type resolution, this comparison is ok, as MyEnum is a enum
148-
Assert.assertTrue("Type Resolution didn't work", markers.get(sourceFile).isEmpty());
154+
// with type resolution, we detect missing override annotation
155+
Assert.assertFalse("Type Resolution didn't work", markers.get(sourceFile).isEmpty());
149156

150-
// without type resolution, there is a violation
157+
// without type resolution, there is no violation
151158
PMDPlugin.getDefault().getPreferencesManager().loadPreferences().setProjectBuildPathEnabled(false);
152159
cmd = new ReviewCodeCmd();
153160
cmd.addResource(testProject);
154161
cmd.performExecute();
155162
cmd.join();
156163
markers = cmd.getMarkers();
157-
// there is a violation expected without type resolution
158-
Assert.assertFalse(markers.get(sourceFile).isEmpty());
164+
// there is no violation expected without type resolution
165+
Assert.assertTrue(markers.get(sourceFile).isEmpty());
159166

160167
} finally {
161168
PMDPlugin.getDefault().getPreferencesManager().loadPreferences().setProjectBuildPathEnabled(oldSetting);
@@ -189,35 +196,30 @@ public void testProjectBuildPathOutsideWorkspace() throws Exception {
189196
IProjectProperties properties = PMDPlugin.getDefault().getPropertiesManager()
190197
.loadProjectProperties(newProject);
191198
properties.setPmdEnabled(true);
192-
Rule compareObjectsWithEquals = properties.getProjectRuleSet().getRuleByName("CompareObjectsWithEquals");
193-
RuleSet projectRuleSet = RuleSetUtil.newSingle(compareObjectsWithEquals);
199+
Rule missingOVerrideRule = properties.getProjectRuleSet().getRuleByName("MissingOverride");
200+
RuleSet projectRuleSet = RuleSetUtil.newSingle(missingOVerrideRule);
194201
properties.setProjectRuleSet(projectRuleSet);
195202

196203
PMDPlugin.getDefault().getPreferencesManager().loadPreferences().setProjectBuildPathEnabled(true);
197-
EclipseUtils.createTestSourceFile(newProject, "/src/MyEnum.java", "public enum MyEnum { A, B }");
198-
IFile sourceFile = EclipseUtils.createTestSourceFile(newProject, "/src/Foo.java",
199-
"class Foo {\n" + " boolean bar(MyEnum a, MyEnum b) {\n" + " return a == b;\n" + // line 3
200-
" }\n" + "}");
201-
newProject.build(IncrementalProjectBuilder.FULL_BUILD, null);
202-
newProject.refreshLocal(IResource.DEPTH_INFINITE, null);
204+
IFile sourceFile = createMissingOverrideTestCase(newProject);
203205

204206
ReviewCodeCmd cmd = new ReviewCodeCmd();
205207
cmd.addResource(newProject);
206208
cmd.performExecute();
207209
cmd.join();
208210
Map<IFile, Set<MarkerInfo2>> markers = cmd.getMarkers();
209-
// with type resolution, this comparison is ok, as MyEnum is a enum
210-
Assert.assertTrue("Type Resolution didn't work", markers.get(sourceFile).isEmpty());
211+
// with type resolution, we detect missing override annotation
212+
Assert.assertFalse("Type Resolution didn't work", markers.get(sourceFile).isEmpty());
211213

212-
// without type resolution, there is a violation
214+
// without type resolution, there is no violation
213215
PMDPlugin.getDefault().getPreferencesManager().loadPreferences().setProjectBuildPathEnabled(false);
214216
cmd = new ReviewCodeCmd();
215217
cmd.addResource(newProject);
216218
cmd.performExecute();
217219
cmd.join();
218220
markers = cmd.getMarkers();
219-
// there is a violation expected without type resolution
220-
Assert.assertFalse(markers.get(sourceFile).isEmpty());
221+
// there is no violation expected without type resolution
222+
Assert.assertTrue(markers.get(sourceFile).isEmpty());
221223

222224
} finally {
223225
PMDPlugin.getDefault().getPreferencesManager().loadPreferences().setProjectBuildPathEnabled(oldSetting);

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<tycho.version>1.7.0</tycho.version>
2323
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24-
<pmd.version>6.29.0</pmd.version>
24+
<pmd.version>6.30.0-SNAPSHOT</pmd.version>
2525
<maven-antrun-plugin.version>1.8</maven-antrun-plugin.version>
2626
<pmd.build-tools.version>6</pmd.build-tools.version>
2727
<checkstyle.version>8.30</checkstyle.version>

0 commit comments

Comments
 (0)