Skip to content

Commit 4bd0e6e

Browse files
committed
Update to PMD 6.6.0
Refs #48
1 parent 80af90e commit 4bd0e6e

File tree

4 files changed

+58
-20
lines changed

4 files changed

+58
-20
lines changed

ReleaseNotes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ Eclipse Update Site:
1111

1212
### New and noteworthy
1313

14-
* Updated PMD to 6.3.0
14+
* Updated PMD to 6.6.0
1515

1616
### Fixed Issues
1717

18-
* [#48](https://github.com/pmd/pmd-eclipse-plugin/issues/48): Upgrade to PMD 6.3.0
18+
* [#48](https://github.com/pmd/pmd-eclipse-plugin/issues/48): Upgrade to PMD 6.6.0
1919

2020
### External Contributions
2121

net.sourceforge.pmd.eclipse.plugin.test.fragment/src/main/resources/rulesets/extra1.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,10 @@ Avoid unnecessary return statements.
413413
[parent::Statement
414414
[parent::BlockStatement
415415
[parent::Block
416-
[parent::MethodDeclaration/ResultType[@Void='true']
417-
]
416+
[parent::MethodDeclaration/ResultType[@Void='true']]
418417
]
419-
] ]]>
418+
]
419+
] ]]>
420420
</value>
421421
</property>
422422
</properties>

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/EclipseUtils.java

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* Created on 14 mai 2005
3-
*
3+
*
44
* Copyright (c) 2005, PMD for Eclipse Development Team All rights reserved.
5-
*
5+
*
66
* Redistribution and use in source and binary forms, with or without
77
* modification, are permitted provided that the following conditions are
88
* met:
9-
*
9+
*
1010
* * Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer. * Redistributions
1212
* in binary form must reproduce the above copyright notice, this list of
@@ -18,7 +18,7 @@
1818
* Neither the name of "PMD for Eclipse Development Team" nor the names of
1919
* its contributors may be used to endorse or promote products derived from
2020
* this software without specific prior written permission.
21-
*
21+
*
2222
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
2323
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
2424
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -45,6 +45,7 @@
4545
import java.util.Map.Entry;
4646
import java.util.Set;
4747
import java.util.concurrent.CountDownLatch;
48+
import java.util.regex.Pattern;
4849

4950
import org.eclipse.core.resources.IFile;
5051
import org.eclipse.core.resources.IFolder;
@@ -68,7 +69,7 @@
6869

6970
/**
7071
* This is a utility class for Eclipse various operations
71-
*
72+
*
7273
* @author Philippe Herlin
7374
* @author Brian Remedios
7475
*/
@@ -96,7 +97,7 @@ private EclipseUtils() {
9697

9798
/**
9899
* Test if 2 sets of rules are equals
99-
*
100+
*
100101
* @param ruleSet1
101102
* @param ruleSet2
102103
* @return
@@ -126,7 +127,7 @@ public static boolean assertRuleSetEquals(final Collection<Rule> ruleSet1, final
126127

127128
/**
128129
* Create a new java project
129-
*
130+
*
130131
* @param projectName
131132
* a project name
132133
* @return newProject a new project resource handle
@@ -161,7 +162,7 @@ public static IProject createProject(final String projectName) throws CoreExcept
161162

162163
/**
163164
* Create a test source file
164-
*
165+
*
165166
* @param project
166167
* a project where to create that file; this project is expected to be empty
167168
*/
@@ -186,7 +187,7 @@ public static IFile createTestSourceFile(final IProject project)
186187

187188
/**
188189
* Get the content of a project resource.
189-
*
190+
*
190191
* @param project
191192
* a project reference
192193
* @param resourceName
@@ -202,7 +203,7 @@ public static InputStream getResourceStream(final IProject project, final String
202203

203204
/**
204205
* Remove the PMD Nature from a project
205-
*
206+
*
206207
* @param project
207208
* a project to remove the PMD Nature
208209
* @param monitor
@@ -238,7 +239,7 @@ public static boolean removePMDNature(final IProject project) throws CoreExcepti
238239

239240
/**
240241
* Add a Java Nature to a project when creating
241-
*
242+
*
242243
* @param project
243244
* @throws CoreException
244245
*/
@@ -272,7 +273,7 @@ private static void addJavaNature(final IProject project) throws CoreException {
272273

273274
/**
274275
* Print rule details
275-
*
276+
*
276277
* @param rule
277278
*/
278279
private static void dumpRule(final Rule rule, final PrintStream out) {
@@ -286,13 +287,50 @@ private static void dumpRule(final Rule rule, final PrintStream out) {
286287
}
287288

288289
private static boolean propertiesMatchFor(final Rule ruleA, final Rule ruleB) {
290+
Map<PropertyDescriptor<?>, Object> ruleAProperties = ruleA.getPropertiesByPropertyDescriptor();
289291

290-
return ruleA.getPropertiesByPropertyDescriptor().equals(ruleB.getPropertiesByPropertyDescriptor());
292+
Map<PropertyDescriptor<?>, Object> ruleBProperties = ruleB.getPropertiesByPropertyDescriptor();
293+
294+
// simple equals doesn't work for RegexProperties whose value type is java.util.regex.Pattern...
295+
//return ruleAProperties.equals(ruleBProperties);
296+
297+
if (ruleAProperties == ruleBProperties) {
298+
return true;
299+
}
300+
301+
if (ruleAProperties.size() != ruleBProperties.size()) {
302+
return false;
303+
}
304+
305+
for (Map.Entry<PropertyDescriptor<?>, Object> entry : ruleAProperties.entrySet()) {
306+
if (entry.getValue() == null) {
307+
Object valueB = ruleBProperties.get(entry.getKey());
308+
if (!(valueB == null && ruleBProperties.containsKey(entry.getKey()))) {
309+
return false;
310+
}
311+
} else {
312+
Object valueB = ruleBProperties.get(entry.getKey());
313+
if (entry.getValue() instanceof Pattern) {
314+
if (!(valueB instanceof Pattern)) {
315+
return false;
316+
}
317+
if (!entry.getValue().toString().equals(valueB.toString())) {
318+
return false;
319+
}
320+
} else {
321+
if (!entry.getValue().equals(valueB)) {
322+
return false;
323+
}
324+
}
325+
}
326+
}
327+
328+
return true;
291329
}
292330

293331
/**
294332
* Search a rule in a set of rules
295-
*
333+
*
296334
* @param rule
297335
* @param set
298336
* @return

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<properties>
1717
<tycho.version>1.1.0</tycho.version>
1818
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19-
<pmd.version>6.3.0</pmd.version>
19+
<pmd.version>6.6.0</pmd.version>
2020
<maven-antrun-plugin.version>1.8</maven-antrun-plugin.version>
2121
</properties>
2222

0 commit comments

Comments
 (0)