Compare commits
159
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96fffcaadd | ||
|
|
93aec5d064 | ||
|
|
37156724aa | ||
|
|
ed07ff259c | ||
|
|
e78f80416a | ||
|
|
5019eb11e4 | ||
|
|
194167e3c0 | ||
|
|
aa19957cee | ||
|
|
253d35a926 | ||
|
|
6007840346 | ||
|
|
dcb4ecc674 | ||
|
|
14cdf0b550 | ||
|
|
40ed778e43 | ||
|
|
92153696d8 | ||
|
|
33e1850d6b | ||
|
|
3a46e9bab2 | ||
|
|
d7b8bae1c9 | ||
|
|
4ab1d0cbee | ||
|
|
52a8758262 | ||
|
|
7bfc1b9545 | ||
|
|
8444b2fea6 | ||
|
|
a9d0de9450 | ||
|
|
2c7f2ec0df | ||
|
|
cec3e1a2ad | ||
|
|
176eda21fe | ||
|
|
276cff02f8 | ||
|
|
08b7959557 | ||
|
|
495dcb5ea9 | ||
|
|
6810b9c54a | ||
|
|
9f9124b8fb | ||
|
|
6dcf301e4d | ||
|
|
8c89ce0d9d | ||
|
|
15ff7ca944 | ||
|
|
ba50b3183e | ||
|
|
e611dc8412 | ||
|
|
4ac34af067 | ||
|
|
0c75e5123c | ||
|
|
cc94ed4c33 | ||
|
|
9be65ef2eb | ||
|
|
67ddaafe44 | ||
|
|
db26052236 | ||
|
|
5827acb93e | ||
|
|
7339227e9c | ||
|
|
2cc91732ec | ||
|
|
4310b36344 | ||
|
|
575a5b6547 | ||
|
|
1f046cd7e9 | ||
|
|
5937e89d4f | ||
|
|
7791a87c23 | ||
|
|
2158a792ff | ||
|
|
2f498d1130 | ||
|
|
0ba362c4c0 | ||
|
|
2f5a7058cb | ||
|
|
b2a66fef01 | ||
|
|
fa9485b41e | ||
|
|
c6680e2f66 | ||
|
|
5db46d6ad1 | ||
|
|
4cf22bed16 | ||
|
|
15b36498f3 | ||
|
|
10e4cc7290 | ||
|
|
949470013a | ||
|
|
bdde3533dc | ||
|
|
bdb408507b | ||
|
|
6fb962c326 | ||
|
|
2d1337b300 | ||
|
|
315ea28d4c | ||
|
|
45dfd29a46 | ||
|
|
f8f0afb5b4 | ||
|
|
f8d1162886 | ||
|
|
020170bd76 | ||
|
|
cb304c9ae7 | ||
|
|
646a4b0650 | ||
|
|
b0fb0cadc1 | ||
|
|
5c80473108 | ||
|
|
9de0727e43 | ||
|
|
127a2be871 | ||
|
|
238f6b721b | ||
|
|
f4f2402661 | ||
|
|
75c9cce071 | ||
|
|
04257e657d | ||
|
|
b2c59bcbdb | ||
|
|
c95051e97d | ||
|
|
7d5be34cd2 | ||
|
|
1e5c1c05ca | ||
|
|
5d11e77208 | ||
|
|
42d5a402c7 | ||
|
|
e7a68f4492 | ||
|
|
f88e86cdb1 | ||
|
|
578d854632 | ||
|
|
1bc409119c | ||
|
|
283dc00a43 | ||
|
|
e9f14e4496 | ||
|
|
9b7372eec0 | ||
|
|
8c82dae34c | ||
|
|
565a9aa0d8 | ||
|
|
d350bcb49e | ||
|
|
567be45b8c | ||
|
|
478ed3463c | ||
|
|
09ac963709 | ||
|
|
d8344b0672 | ||
|
|
382699b766 | ||
|
|
be83d154d0 | ||
|
|
42277d7b8d | ||
|
|
a046b8f93d | ||
|
|
df9893099f | ||
|
|
61b55bd7e5 | ||
|
|
8f62f6cae9 | ||
|
|
ca2ccb4a80 | ||
|
|
3774a22878 | ||
|
|
a10f98e0c4 | ||
|
|
a50c781d0a | ||
|
|
fccd26b2d0 | ||
|
|
b773da1441 | ||
|
|
1b52e0192a | ||
|
|
461365f543 | ||
|
|
8667aea076 | ||
|
|
aec40ec20c | ||
|
|
82cc8b1d50 | ||
|
|
f9deb34809 | ||
|
|
354b9a9cbc | ||
|
|
b07c2f4409 | ||
|
|
db44bc4745 | ||
|
|
b67ac6ff2b | ||
|
|
ccc09c5d4f | ||
|
|
108e302bb1 | ||
|
|
f01cc473d2 | ||
|
|
2fc01fedb5 | ||
|
|
522d0ea311 | ||
|
|
093a813c0f | ||
|
|
a99c506342 | ||
|
|
1693692f80 | ||
|
|
2245a644f4 | ||
|
|
579853385d | ||
|
|
c8a9f43ee0 | ||
|
|
cd9a8186db | ||
|
|
3bb9d90de8 | ||
|
|
d294a91ad8 | ||
|
|
7421f28414 | ||
|
|
cf4938a65b | ||
|
|
6aee2dd232 | ||
|
|
a74105faa4 | ||
|
|
869ee8569e | ||
|
|
8a6ac1f156 | ||
|
|
a6acf7ca81 | ||
|
|
4bb02531c7 | ||
|
|
0a2ebc2186 | ||
|
|
3e43fd8eb1 | ||
|
|
5207d48bb2 | ||
|
|
6746b7522c | ||
|
|
5b6580448e | ||
|
|
7578875cbd | ||
|
|
42a5c6a537 | ||
|
|
229fc57073 | ||
|
|
9240f98cce | ||
|
|
4adbeb04f1 | ||
|
|
e25bd5e9c1 | ||
|
|
c041f756c2 | ||
|
|
c92820eaae | ||
|
|
6efabd6909 |
No files matched your search
+3
-3
@@ -115,8 +115,8 @@ fi
|
||||
|
||||
(
|
||||
cd pmd-dist/target
|
||||
unzip pmd-bin-*.zip
|
||||
cd pmd-bin-*
|
||||
unzip pmd-bin-${RELEASE_VERSION}-SNAPSHOT.zip
|
||||
cd pmd-bin-${RELEASE_VERSION}-SNAPSHOT
|
||||
./bin/run.sh pmd -d ../../../pmd-java/src/main/java -language java -f xml -R rulesets/java/unusedcode.xml
|
||||
)
|
||||
|
||||
@@ -252,7 +252,7 @@ cat <<EOF
|
||||
|
||||
**New Supported Languages:**
|
||||
|
||||
**Feature Request and Improvements:**
|
||||
**Feature Requests and Improvements:**
|
||||
|
||||
**New/Modified/Deprecated Rules:**
|
||||
|
||||
|
||||
+10
-3
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF8"?>
|
||||
<toolchains>
|
||||
<!-- place this file in ${user.home}/.m2/toolchains.xml -->
|
||||
<!-- adjust the paths to jdkhome -->
|
||||
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
@@ -8,7 +9,9 @@
|
||||
<version>1.6</version>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>/path/to/jdk/1.6</jdkHome>
|
||||
<jdkHome>/path/to/jdk/1.6</jdkHome> <!-- Linux -->
|
||||
<jdkHome>/Library/Java/JavaVirtualMachines/jdk1.6.0_45.jdk/Contents/Home</jdkHome> <!-- MacOSX -->
|
||||
<jdkHome>C:\\java\\edition\\jdk1.6.0_45</jdkHome> <!-- Windows -->
|
||||
</configuration>
|
||||
</toolchain>
|
||||
<toolchain>
|
||||
@@ -17,7 +20,9 @@
|
||||
<version>1.7</version>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>/path/to/jdk/1.7</jdkHome>
|
||||
<jdkHome>/path/to/jdk/1.7</jdkHome> <!-- Linux -->
|
||||
<jdkHome>/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home</jdkHome> <!-- MacOSX -->
|
||||
<jdkHome>C:\\java\\edition\\jdk1.7.0_80</jdkHome> <!-- Windows -->
|
||||
</configuration>
|
||||
</toolchain>
|
||||
<toolchain>
|
||||
@@ -26,7 +31,9 @@
|
||||
<version>1.8</version>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>/path/to/jdk/1.8</jdkHome>
|
||||
<jdkHome>/path/to/jdk/1.8</jdkHome> <!-- Linux -->
|
||||
<jdkHome>/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home</jdkHome> <!-- MacOSX -->
|
||||
<jdkHome>C:\\java\\edition\\jdk1.8.0_92</jdkHome> <!-- Windows -->
|
||||
</configuration>
|
||||
</toolchain>
|
||||
</toolchains>
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd</artifactId>
|
||||
<version>5.5.1</version>
|
||||
<version>5.5.2</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -14,4 +14,17 @@ public class ASTMethodCallExpression extends AbstractApexNode<MethodCallExpressi
|
||||
public Object jjtAccept(ApexParserVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
public String getMethodName() {
|
||||
return getNode().getMethodName();
|
||||
}
|
||||
|
||||
public String getFullMethodName() {
|
||||
final String methodName = getMethodName();
|
||||
String typeName = "";
|
||||
if (!getNode().getReferenceExpression().getJadtIdentifiers().isEmpty()) {
|
||||
typeName = getNode().getReferenceExpression().getJadtIdentifiers().get(0).value + ".";
|
||||
}
|
||||
return typeName + methodName;
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -1,9 +1,13 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.apex.rule.apexunit;
|
||||
|
||||
import net.sourceforge.pmd.lang.apex.ast.*;
|
||||
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
|
||||
|
||||
import apex.jorje.services.Version;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTModifierNode;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexNode;
|
||||
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
|
||||
|
||||
/**
|
||||
* Do special checks for apex unit test classes and methods
|
||||
|
||||
+29
-22
@@ -1,10 +1,18 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.apex.rule.apexunit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import net.sourceforge.pmd.lang.apex.ast.*;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTBlockStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexNode;
|
||||
|
||||
/**
|
||||
* Apex unit tests should have System.assert methods in them
|
||||
@@ -13,11 +21,13 @@ import net.sourceforge.pmd.lang.apex.ast.*;
|
||||
*/
|
||||
public class ApexUnitTestClassShouldHaveAsserts extends AbstractApexUnitTestRule {
|
||||
|
||||
private static final String SYSTEM = "System";
|
||||
private static final String ASSERT = "assert";
|
||||
private static final String ASSERT_EQUALS = "assertEquals";
|
||||
private static final String ASSERT_NOT_EQUALS = "assertNotEquals";
|
||||
|
||||
private static final Set<String> ASSERT_METHODS = new HashSet<>();
|
||||
static {
|
||||
ASSERT_METHODS.add("System.assert");
|
||||
ASSERT_METHODS.add("System.assertEquals");
|
||||
ASSERT_METHODS.add("System.assertNotEquals");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTMethod node, Object data) {
|
||||
if (!isTestMethodOrClass(node)) {
|
||||
@@ -29,21 +39,18 @@ public class ApexUnitTestClassShouldHaveAsserts extends AbstractApexUnitTestRule
|
||||
|
||||
private Object checkForAssertStatements(ApexNode<?> node, Object data) {
|
||||
final List<ASTBlockStatement> blockStatements = node.findDescendantsOfType(ASTBlockStatement.class);
|
||||
final List<ASTStatement> statements = Iterables.getOnlyElement(blockStatements).findDescendantsOfType(ASTStatement.class);
|
||||
final List<ASTStatement> statements = new ArrayList<>();
|
||||
final List<ASTMethodCallExpression> methodCalls = new ArrayList<>();
|
||||
for (ASTBlockStatement blockStatement : blockStatements) {
|
||||
statements.addAll(blockStatement.findDescendantsOfType(ASTStatement.class));
|
||||
methodCalls.addAll(blockStatement.findDescendantsOfType(ASTMethodCallExpression.class));
|
||||
}
|
||||
boolean isAssertFound = false;
|
||||
|
||||
for (final ASTStatement statement : statements) {
|
||||
final List<ASTMethodCallExpression> methodCalls = statement.findDescendantsOfType(ASTMethodCallExpression.class);
|
||||
|
||||
for (final ASTMethodCallExpression methodCallExpression : methodCalls) {
|
||||
final String methodName = methodCallExpression.getNode().getMethod().getName();
|
||||
|
||||
if (methodCallExpression.getNode().getDefiningType().getApexName().equalsIgnoreCase(SYSTEM)
|
||||
&& (methodName.equalsIgnoreCase(ASSERT)
|
||||
|| methodName.equalsIgnoreCase(ASSERT_EQUALS)
|
||||
|| methodName.equalsIgnoreCase(ASSERT_NOT_EQUALS))) {
|
||||
isAssertFound = true;
|
||||
}
|
||||
|
||||
for (final ASTMethodCallExpression methodCallExpression : methodCalls) {
|
||||
if (ASSERT_METHODS.contains(methodCallExpression.getFullMethodName())) {
|
||||
isAssertFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-3
@@ -1,11 +1,18 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.apex.rule.apexunit;
|
||||
|
||||
import net.sourceforge.pmd.lang.apex.ast.*;
|
||||
|
||||
import apex.jorje.semantic.ast.modifier.*;
|
||||
import apex.jorje.semantic.ast.modifier.Annotation;
|
||||
import apex.jorje.semantic.ast.modifier.AnnotationParameter;
|
||||
import apex.jorje.semantic.ast.modifier.ModifierOrAnnotation;
|
||||
import apex.jorje.semantic.symbol.type.AnnotationTypeInfos;
|
||||
import apex.jorje.semantic.symbol.type.TypeInfoEquivalence;
|
||||
import apex.jorje.services.Version;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTModifierNode;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexNode;
|
||||
|
||||
/**
|
||||
* <p>It's a very bad practice to use @isTest(seeAllData=true) in Apex unit tests,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</description>
|
||||
|
||||
<rule name="ApexUnitTestClassShouldHaveAsserts"
|
||||
since="2.0"
|
||||
since="5.5.1"
|
||||
message="Apex unit tests should System.assert() or assertEquals() or assertNotEquals()"
|
||||
class="net.sourceforge.pmd.lang.apex.rule.apexunit.ApexUnitTestClassShouldHaveAsserts"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/apexunit.html#ApexUnitTestClassShouldHaveAsserts">
|
||||
@@ -33,7 +33,7 @@ public class Foo {
|
||||
</example>
|
||||
</rule>
|
||||
<rule name="ApexUnitTestShouldNotUseSeeAllDataTrue"
|
||||
since="2.0"
|
||||
since="5.5.1"
|
||||
message="Apex unit tests should not use @isTest(seeAllData = true)"
|
||||
class="net.sourceforge.pmd.lang.apex.rule.apexunit.ApexUnitTestShouldNotUseSeeAllDataTrue"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/apexunit.html#ApexUnitTestShouldNotUseSeeAllDataTrue">
|
||||
|
||||
+3
@@ -1,3 +1,6 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.apex.rule.apexunit;
|
||||
|
||||
import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
|
||||
+40
@@ -16,4 +16,44 @@ public class Foo {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#1521 [apex] ApexUnitTestClassShouldHaveAsserts: Parsing error on APEX class: expected one element but was: <BlockStatement, BlockStatement></description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
@isTest
|
||||
private class C2_Assignment_Report_Job_Test {
|
||||
|
||||
public static testMethod void testCreateAssignmentsForDifferentRoles() {
|
||||
User u = C2_Test_Utils.getWFUser('testWfc', true);
|
||||
System.runAs(u) {
|
||||
C2_Assignment_Report_Data_Aggregate_Job job = new C2_Assignment_Report_Data_Aggregate_Job();
|
||||
String query = job.start(null).getQuery();
|
||||
C2_Receiver_Unit__c ru = new C2_Receiver_Unit__c(Name='RU1');
|
||||
insert ru;
|
||||
List<C2_Case__c> cases = new List<C2_Case__c>();
|
||||
cases.add(new C2_Case__c(Name='TT0000000', Queue__c = 'PA-CSA', Status__c=C2_Case_Util.STATUS_NEW, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
|
||||
cases.add(new C2_Case__c(Name='TT0000001', Queue__c = 'PA-CSA', Status__c=C2_Case_Util.STATUS_NEW, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
|
||||
cases.add(new C2_Case__c(Name='TT0000002', Queue__c = 'PA-CSA', Status__c=C2_Case_Util.STATUS_NEW, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
|
||||
cases.add(new C2_Case__c(Name='TT0000011', Queue__c = 'DSA', Status__c=C2_Case_Util.STATUS_PACSA_COMPLETE, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
|
||||
cases.add(new C2_Case__c(Name='TT0000012', Queue__c = 'DSA', Status__c=C2_Case_Util.STATUS_PACSA_COMPLETE, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
|
||||
cases.add(new C2_Case__c(Name='TT0000021', Queue__c = 'QR-CSA', Status__c=C2_Case_Util.STATUS_DSA_COMPLETE, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
|
||||
insert cases;
|
||||
List<C2_Case__c> scope = Database.query(query);
|
||||
Test.startTest();
|
||||
job.execute(null, scope);
|
||||
Test.stopTest();
|
||||
List<C2_Case_Assign_Report_Data__c> caseEventEntries =
|
||||
[select Num_Cases_Assign__c, Num_Cases_Not_Completed__c, Num_Cases_Reassigned__c, Num_Cases_Completed__c, User__c, Role__c
|
||||
from C2_Case_Assign_Report_Data__c];
|
||||
System.assertEquals(3, caseEventEntries.size());
|
||||
Map<String, Integer> userIdWithRole2ReportData = getCaseEventEntriesMap(caseEventEntries);
|
||||
System.assertEquals(3, userIdWithRole2ReportData.get(createUserRoleKey(u.Id, 'PA-CSA')));
|
||||
System.assertEquals(2, userIdWithRole2ReportData.get(createUserRoleKey(u.Id, 'DSA')));
|
||||
System.assertEquals(1, userIdWithRole2ReportData.get(createUserRoleKey(u.Id, 'QR-CSA')));
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd</artifactId>
|
||||
<version>5.5.1</version>
|
||||
<version>5.5.2</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -32,9 +32,7 @@ public abstract class AbstractPropertySource implements PropertySource {
|
||||
* @return a copy of the property descriptors.
|
||||
*/
|
||||
protected List<PropertyDescriptor<?>> copyPropertyDescriptors() {
|
||||
List<PropertyDescriptor<?>> copy = new ArrayList<>(propertyDescriptors.size());
|
||||
copy.addAll(propertyDescriptors);
|
||||
return copy;
|
||||
return new ArrayList<>(propertyDescriptors);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,10 +41,7 @@ public abstract class AbstractPropertySource implements PropertySource {
|
||||
* @return a copy of the values
|
||||
*/
|
||||
protected Map<PropertyDescriptor<?>, Object> copyPropertyValues() {
|
||||
Map<PropertyDescriptor<?>, Object> copy = new HashMap<>(
|
||||
propertyValuesByDescriptor.size());
|
||||
copy.putAll(propertyValuesByDescriptor);
|
||||
return copy;
|
||||
return new HashMap<>(propertyValuesByDescriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,6 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
@@ -22,7 +21,9 @@ import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.sourceforge.pmd.benchmark.Benchmark;
|
||||
import net.sourceforge.pmd.benchmark.Benchmarker;
|
||||
@@ -43,7 +44,6 @@ import net.sourceforge.pmd.stat.Metric;
|
||||
import net.sourceforge.pmd.util.ClasspathClassLoader;
|
||||
import net.sourceforge.pmd.util.FileUtil;
|
||||
import net.sourceforge.pmd.util.IOUtil;
|
||||
import net.sourceforge.pmd.util.SystemUtils;
|
||||
import net.sourceforge.pmd.util.database.DBMSMetadata;
|
||||
import net.sourceforge.pmd.util.database.DBURI;
|
||||
import net.sourceforge.pmd.util.database.SourceObject;
|
||||
@@ -52,9 +52,6 @@ import net.sourceforge.pmd.util.datasource.ReaderDataSource;
|
||||
import net.sourceforge.pmd.util.log.ConsoleLogHandler;
|
||||
import net.sourceforge.pmd.util.log.ScopedLogHandlersManager;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* This is the main class for interacting with PMD. The primary flow of all Rule
|
||||
* process is controlled via interactions with this class. A command line
|
||||
@@ -245,8 +242,7 @@ public class PMD {
|
||||
long reportStart = System.nanoTime();
|
||||
try {
|
||||
Renderer renderer = configuration.createRenderer();
|
||||
List<Renderer> renderers = new LinkedList<>();
|
||||
renderers.add(renderer);
|
||||
List<Renderer> renderers = Collections.singletonList(renderer);
|
||||
|
||||
renderer.setWriter(IOUtil.createWriter(configuration.getReportFile()));
|
||||
renderer.start();
|
||||
@@ -365,7 +361,7 @@ public class PMD {
|
||||
* be disabled if threadCount is not positive, e.g. using the
|
||||
* "-threads 0" command line option.
|
||||
*/
|
||||
if (SystemUtils.MT_SUPPORTED && configuration.getThreads() > 0) {
|
||||
if (configuration.getThreads() > 0) {
|
||||
new MultiThreadProcessor(configuration).processFiles(ruleSetFactory, files, ctx, renderers);
|
||||
} else {
|
||||
new MonoThreadProcessor(configuration).processFiles(ruleSetFactory, files, ctx, renderers);
|
||||
|
||||
@@ -7,18 +7,22 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import net.sourceforge.pmd.benchmark.Benchmark;
|
||||
import net.sourceforge.pmd.benchmark.Benchmarker;
|
||||
import net.sourceforge.pmd.lang.*;
|
||||
import net.sourceforge.pmd.lang.Language;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.Parser;
|
||||
import net.sourceforge.pmd.lang.VisitorStarter;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.ast.ParseException;
|
||||
import net.sourceforge.pmd.lang.xpath.Initializer;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
public class SourceCodeProcessor {
|
||||
|
||||
private final PMDConfiguration configuration;
|
||||
@@ -141,13 +145,10 @@ public class SourceCodeProcessor {
|
||||
usesDFA(languageVersion, rootNode, ruleSets, language);
|
||||
usesTypeResolution(languageVersion, rootNode, ruleSets,language);
|
||||
|
||||
List<Node> acus = new ArrayList<>();
|
||||
acus.add(rootNode);
|
||||
List<Node> acus = Collections.singletonList(rootNode);
|
||||
ruleSets.apply(acus, ctx, language);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void determineLanguage(RuleContext ctx) {
|
||||
// If LanguageVersion of the source file is not known, make a determination
|
||||
if (ctx.getLanguageVersion() == null) {
|
||||
|
||||
@@ -179,7 +179,7 @@ public class PMDTaskImpl {
|
||||
return null;
|
||||
} // not relevant
|
||||
};
|
||||
List<Renderer> renderers = new LinkedList<>();
|
||||
List<Renderer> renderers = new ArrayList<>(formatters.size() + 1);
|
||||
renderers.add(logRenderer);
|
||||
for (Formatter formatter : formatters) {
|
||||
renderers.add(formatter.getRenderer());
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# AST
|
||||
|
||||
Abstract Syntax Tree
|
||||
|
||||
@@ -68,15 +68,11 @@ public abstract class AbstractRule extends AbstractPropertySource implements Rul
|
||||
}
|
||||
|
||||
private List<String> copyExamples() {
|
||||
List<String> copy = new ArrayList<>(examples.size());
|
||||
copy.addAll(examples);
|
||||
return copy;
|
||||
return new ArrayList<>(examples);
|
||||
}
|
||||
|
||||
private List<String> copyRuleChainVisits() {
|
||||
List<String> copy = new ArrayList<>(ruleChainVisits.size());
|
||||
copy.addAll(ruleChainVisits);
|
||||
return copy;
|
||||
return new ArrayList<>(ruleChainVisits);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,20 +3,17 @@
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.rule.xpath;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Stack;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.sourceforge.pmd.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
|
||||
import org.jaxen.BaseXPath;
|
||||
import org.jaxen.JaxenException;
|
||||
import org.jaxen.Navigator;
|
||||
@@ -33,6 +30,10 @@ import org.jaxen.expr.UnionExpr;
|
||||
import org.jaxen.expr.XPathFactory;
|
||||
import org.jaxen.saxpath.Axis;
|
||||
|
||||
import net.sourceforge.pmd.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
|
||||
/**
|
||||
* This is a Jaxen based XPathRule query.
|
||||
*/
|
||||
@@ -121,7 +122,7 @@ public class JaxenXPathRuleQuery extends AbstractXPathRuleQuery {
|
||||
indexXPath(originalXPath, AST_ROOT);
|
||||
|
||||
boolean useRuleChain = true;
|
||||
Stack<Expr> pending = new Stack<>();
|
||||
Deque<Expr> pending = new ArrayDeque<>();
|
||||
pending.push(originalXPath.getRootExpr());
|
||||
while (!pending.isEmpty()) {
|
||||
Expr node = pending.pop();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
package net.sourceforge.pmd.processor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@@ -41,7 +42,7 @@ public class MultiThreadProcessor extends AbstractPMDProcessor {
|
||||
PmdThreadFactory factory = new PmdThreadFactory(ruleSetFactory, ctx);
|
||||
ExecutorService executor = Executors.newFixedThreadPool(
|
||||
configuration.getThreads(), factory);
|
||||
List<Future<Report>> tasks = new LinkedList<>();
|
||||
List<Future<Report>> tasks = new ArrayList<>(files.size());
|
||||
|
||||
for (DataSource dataSource : files) {
|
||||
String niceFileName = filenameFrom(dataSource);
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.util;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public final class SystemUtils {
|
||||
|
||||
/**
|
||||
* Do we have proper permissions to use multithreading?
|
||||
*/
|
||||
public static final boolean MT_SUPPORTED;
|
||||
|
||||
private SystemUtils() {
|
||||
// this is a utility class and cannot be instantiated
|
||||
}
|
||||
|
||||
static {
|
||||
boolean error = false;
|
||||
try {
|
||||
/*
|
||||
* ant task ran from Eclipse with jdk 1.5.0 raises an AccessControlException
|
||||
* when shutdown is called. Standalone pmd or ant from command line are fine.
|
||||
*
|
||||
* With jdk 1.6.0, ant task from Eclipse also works.
|
||||
*
|
||||
* Bugs related to this hack:
|
||||
* http://sourceforge.net/p/pmd/bugs/1025/
|
||||
* http://sourceforge.net/p/pmd/bugs/670/
|
||||
*/
|
||||
ExecutorService executor = Executors.newFixedThreadPool(1);
|
||||
executor.shutdown();
|
||||
} catch (RuntimeException e) {
|
||||
error = true;
|
||||
System.err.println("Disabling multithreading - consider to upgrade to java 1.6");
|
||||
System.err.println("See also: http://sourceforge.net/p/pmd/bugs/670/");
|
||||
}
|
||||
MT_SUPPORTED = !error;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="551"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
|
||||
<description>
|
||||
This ruleset contains links to rules that are new in PMD v5.5.1
|
||||
</description>
|
||||
|
||||
<rule ref="rulesets/apex/apexunit.xml/ApexUnitTestClassShouldHaveAsserts" />
|
||||
<rule ref="rulesets/apex/apexunit.xml/ApexUnitTestShouldNotUseSeeAllDataTrue" />
|
||||
|
||||
</ruleset>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="552"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
|
||||
<description>
|
||||
This ruleset contains links to rules that are new in PMD v5.5.2
|
||||
</description>
|
||||
|
||||
<rule ref="rulesets/plsql/strictsyntax.xml/MisplacedPragma"/>
|
||||
|
||||
</ruleset>
|
||||
|
||||
@@ -627,6 +627,63 @@ public class RuleSetFactoryTest {
|
||||
ruleSetFactory.createRuleSet(ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* This unit test manifests the current behavior - which might change in the future. See #1537.
|
||||
*
|
||||
* Currently, if a ruleset is imported twice, the excludes of the first import are ignored.
|
||||
* Duplicated rules are silently ignored.
|
||||
*
|
||||
* @throws Exception any error
|
||||
* @see <a href="https://sourceforge.net/p/pmd/bugs/1537/">#1537 Implement strict ruleset parsing</a>
|
||||
* @see <a href="http://stackoverflow.com/questions/40299075/custom-pmd-ruleset-not-working">stackoverflow - custom ruleset not working</a>
|
||||
*/
|
||||
@Test
|
||||
public void testExcludeAndImportTwice() throws Exception {
|
||||
RuleSetReferenceId ref1 = createRuleSetReferenceId("<?xml version=\"1.0\"?>\n" +
|
||||
"<ruleset name=\"Custom ruleset for tests\"\n" +
|
||||
" xmlns=\"http://pmd.sourceforge.net/ruleset/2.0.0\"\n" +
|
||||
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
|
||||
" xsi:schemaLocation=\"http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd\">\n" +
|
||||
" <description>Custom ruleset for tests</description>\n" +
|
||||
" <rule ref=\"rulesets/dummy/basic.xml\">\n" +
|
||||
" <exclude name=\"DummyBasicMockRule\"/>\n" +
|
||||
" </rule>\n" +
|
||||
"</ruleset>\n");
|
||||
RuleSetFactory ruleSetFactory = new RuleSetFactory();
|
||||
RuleSet ruleset = ruleSetFactory.createRuleSet(ref1);
|
||||
Assert.assertNull(ruleset.getRuleByName("DummyBasicMockRule"));
|
||||
|
||||
RuleSetReferenceId ref2 = createRuleSetReferenceId("<?xml version=\"1.0\"?>\n" +
|
||||
"<ruleset name=\"Custom ruleset for tests\"\n" +
|
||||
" xmlns=\"http://pmd.sourceforge.net/ruleset/2.0.0\"\n" +
|
||||
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
|
||||
" xsi:schemaLocation=\"http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd\">\n" +
|
||||
" <description>Custom ruleset for tests</description>\n" +
|
||||
" <rule ref=\"rulesets/dummy/basic.xml\">\n" +
|
||||
" <exclude name=\"DummyBasicMockRule\"/>\n" +
|
||||
" </rule>\n" +
|
||||
" <rule ref=\"rulesets/dummy/basic.xml\"/>\n" +
|
||||
"</ruleset>\n");
|
||||
RuleSetFactory ruleSetFactory2 = new RuleSetFactory();
|
||||
RuleSet ruleset2 = ruleSetFactory2.createRuleSet(ref2);
|
||||
Assert.assertNotNull(ruleset2.getRuleByName("DummyBasicMockRule"));
|
||||
|
||||
RuleSetReferenceId ref3 = createRuleSetReferenceId("<?xml version=\"1.0\"?>\n" +
|
||||
"<ruleset name=\"Custom ruleset for tests\"\n" +
|
||||
" xmlns=\"http://pmd.sourceforge.net/ruleset/2.0.0\"\n" +
|
||||
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
|
||||
" xsi:schemaLocation=\"http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd\">\n" +
|
||||
" <description>Custom ruleset for tests</description>\n" +
|
||||
" <rule ref=\"rulesets/dummy/basic.xml\"/>\n" +
|
||||
" <rule ref=\"rulesets/dummy/basic.xml\">\n" +
|
||||
" <exclude name=\"DummyBasicMockRule\"/>\n" +
|
||||
" </rule>\n" +
|
||||
"</ruleset>\n");
|
||||
RuleSetFactory ruleSetFactory3 = new RuleSetFactory();
|
||||
RuleSet ruleset3 = ruleSetFactory3.createRuleSet(ref3);
|
||||
Assert.assertNotNull(ruleset3.getRuleByName("DummyBasicMockRule"));
|
||||
}
|
||||
|
||||
private static final String REF_OVERRIDE_ORIGINAL_NAME = "<?xml version=\"1.0\"?>"
|
||||
+ PMD.EOL
|
||||
+ "<ruleset name=\"test\">"
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd</artifactId>
|
||||
<version>5.5.1</version>
|
||||
<version>5.5.2</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd</artifactId>
|
||||
<version>5.5.1</version>
|
||||
<version>5.5.2</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
||||
+6
-1
@@ -8,7 +8,7 @@
|
||||
<parent>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd</artifactId>
|
||||
<version>5.5.1</version>
|
||||
<version>5.5.2</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
@@ -83,6 +83,11 @@
|
||||
<artifactId>pmd-go</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-groovy</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-java</artifactId>
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd</artifactId>
|
||||
<version>5.5.1</version>
|
||||
<version>5.5.2</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd</artifactId>
|
||||
<version>5.5.1</version>
|
||||
<version>5.5.2</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pmd-groovy</artifactId>
|
||||
<name>PMD Grooovy</name>
|
||||
|
||||
<parent>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd</artifactId>
|
||||
<version>5.5.2</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<config.basedir>${basedir}/../pmd-core</config.basedir>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<configuration>
|
||||
<useDefaultDelimiters>false</useDefaultDelimiters>
|
||||
<delimiters>
|
||||
<delimiter>${*}</delimiter>
|
||||
</delimiters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.cpd;
|
||||
|
||||
/**
|
||||
* Language implementation for Groovy
|
||||
*/
|
||||
public class GroovyLanguage extends AbstractLanguage {
|
||||
|
||||
/**
|
||||
* Creates a new Groovy Language instance.
|
||||
*/
|
||||
public GroovyLanguage() {
|
||||
super("Groovy", "groovy", new GroovyTokenizer(), ".groovy");
|
||||
}
|
||||
}
|
||||
Loaded 30 of 129 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user