Skip to content

Commit

Permalink
Merge pull request #232 from XenoAmess/xenoamess_maintain_fork_develop
Browse files Browse the repository at this point in the history
version to 2.1.1.3x
  • Loading branch information
XenoAmess authored Apr 9, 2022
2 parents 0563130 + 495fccd commit 9d2594c
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: adopt
Expand Down
20 changes: 18 additions & 2 deletions idea-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cd p3c-idea

## <font color="green">Use p3c-common as your plugin dependency</font>
```groovy
compile 'com.xenoamess.p3c.idea:p3c-common:2.1.1.2x'
compile 'com.xenoamess.p3c.idea:p3c-common:2.1.1.3x'
```
## [中文使用手册](README_cn.md)
## <font color="green">Install</font>
Expand Down Expand Up @@ -157,6 +157,9 @@ Firstly p3c_config.x8l be at "$your_project_path/p3c_config.x8l".
>
<class_blacklist [>
Console
>
<package_blacklist [>
com.xenoamess.cyan_potion.base.steam
>
<rule_class_pair_blacklist>
<JamepadGamepadKeyEnum [>EnumConstantsMustHaveCommentRule>
Expand Down Expand Up @@ -239,6 +242,16 @@ then means in this repo we will not detect anything for all classes whose name b
BE ATTENTION, according to PMD interface reason,
class names in class_blacklist must be SimpleName.

### package_blacklist

Node package_blacklist contains global settings for a repo,
means ban packages in this repo globally.

For example, if package_blacklist contains `com.xenoamess`,
then means in this repo we will not detect anything for all classes whose package under `com.xenoamess`.

BE ATTENTION, it will also ban packages under `com.xenoamess`, like `com.xenoamess.cyan_potion`

### rule_class_pair_blacklist

Node rule_class_pair_blacklist contains settings for class/rule pairs,
Expand Down Expand Up @@ -307,7 +320,10 @@ If you really hate x8l you can use json configuration files.
],
"class_blacklist": [
"Console"
],
],
"package_blacklist": [
"com.xenoamess.cyan_potion.base.steam"
],
"rule_class_pair_blacklist": {
"JamepadGamepadKeyEnum": [
"EnumConstantsMustHaveCommentRule"
Expand Down
16 changes: 15 additions & 1 deletion idea-plugin/README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ Alt+Enter键可呼出Intention菜单,不同的规则会提示不同信息的Qu
>
<class_blacklist [>
Console
>
<package_blacklist [>
com.xenoamess.cyan_potion.base.steam
>
<rule_class_pair_blacklist>
<JamepadGamepadKeyEnum [>EnumConstantsMustHaveCommentRule>
Expand Down Expand Up @@ -267,6 +270,14 @@ class_blacklist节点主要包括对该项目中的某一类禁用所有规则

注意,由于PMD技术原因,class_blacklist中的类必须为SimpleName

### package_blacklist

package_blacklist节点主要包括对该项目中的某一个父包禁用所有规则。

如,package_blacklist中含有`com.xenoamess`包,则该项目中所有`com.xenoamess`包下的类均不会进行任何检测。

注意,形如`com.xenoamess.cyan_potion`的,`com.xenoamess`包的子包也会被禁用所有规则。

### rule_class_pair_blacklist

rule_class_pair_blacklist节点主要包括对该项目中的某一类禁用某数个规则。
Expand Down Expand Up @@ -332,7 +343,10 @@ Rule类名既可以是SimpleName,也可以是CanonicalName。
],
"class_blacklist": [
"Console"
],
],
"package_blacklist": [
"com.xenoamess.cyan_potion.base.steam"
],
"rule_class_pair_blacklist": {
"JamepadGamepadKeyEnum": [
"EnumConstantsMustHaveCommentRule"
Expand Down
2 changes: 1 addition & 1 deletion idea-plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ idea_version=201.7223.91
#idea_version=145.258.11
plugin_name=Alibaba Java Coding Guidelines
systemProp.file.encoding=UTF-8
plugin_version=2.1.1.2x
plugin_version=2.1.1.3x
5 changes: 5 additions & 0 deletions idea-plugin/p3c-idea/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
]]></description>

<change-notes><![CDATA[
<ul>2.1.1.3x
<li>pmd upgrade to 6.44.0</li>
<li>fix bugs of SneakyThrowsWithoutExceptionTypeRule</li>
<li>add com.alibaba.p3c.pmd.config>package_blacklist config. see https://github.com/XenoAmess/p3c/issues/211</li>
</ul>
<ul>2.1.1.2x
<li>pmd upgrade to 6.41.0</li>
<li>now allow use json for configuration too (p3c_config.json). see https://github.com/XenoAmess/p3c/issues/144</li>
Expand Down
2 changes: 1 addition & 1 deletion p3c-pmd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<dependency>
<groupId>com.xenoamess.p3c</groupId>
<artifactId>p3c-pmd</artifactId>
<version>2.1.1.2x</version>
<version>2.1.1.3x</version>
</dependency>
```
### <font color="green">Gradle</font>
Expand Down
5 changes: 2 additions & 3 deletions p3c-pmd/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.xenoamess.p3c</groupId>
<artifactId>p3c-pmd</artifactId>
<version>2.1.1.2x</version>
<version>2.1.1.3x</version>
<packaging>jar</packaging>
<name>p3c-pmd</name>
<properties>
Expand All @@ -23,7 +23,6 @@
<!---->
<!--libraries versions-->
<pmd.version>6.44.0</pmd.version>
<maven.compiler.target>1.8</maven.compiler.target>
<annotation.version>1.3.2</annotation.version>
<kotlin.version>1.6.20</kotlin.version>
<x8l.version>2.3.9</x8l.version>
Expand All @@ -48,7 +47,7 @@
<maven-deploy-plugin.version>3.0.0-M2</maven-deploy-plugin.version>
<maven-surefire-plugin.version>3.0.0-M6</maven-surefire-plugin.version>
<animal-sniffer-maven-plugin.version>1.21</animal-sniffer-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.7</jacoco-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.8</jacoco-maven-plugin.version>
<log4j.version>2.17.2</log4j.version>
<slf4j.version>1.7.36</slf4j.version>
<!--enforce-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ HashMap<String, Set<String>> getRuleClassPairBlackListMap(@NotNull List<Object>
)
private Set<String> classBlackListSet;

@X8lDataBeanFieldMark(
paths = {
"com.alibaba.p3c.pmd.config>package_blacklist"
},
parser = P3cConfigDataBean.class,
functionName = "getContentNodeAsStringSet"
)
private Set<String> packageBlackListSet;

@X8lDataBeanFieldMark(
paths = {
"com.alibaba.p3c.pmd.config>rule_class_pair_blacklist"
Expand Down Expand Up @@ -145,4 +154,13 @@ public Map<String, Set<String>> getRuleClassPairBlackListMap() {
public void setRuleClassPairBlackListMap(Map<String, Set<String>> ruleClassPairBlackListMap) {
this.ruleClassPairBlackListMap = ruleClassPairBlackListMap;
}

public Set<String> getPackageBlackListSet() {
return packageBlackListSet;
}

public void setPackageBlackListSet(Set<String> packageBlackListSet) {
this.packageBlackListSet = packageBlackListSet;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public Object visit(ASTCompilationUnit rootNode, Object data) {
+ " not((.//MemberValuePair/@Image = 'value') or (./SingleMemberAnnotation))"
+ "]"
+ "]"
+ "//MethodDeclaration"
);
} catch (JaxenException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.xenoamess.p3c.pmd.lang.java.util.namelist.NameListConfig;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator;
Expand All @@ -25,6 +26,7 @@
import net.sourceforge.pmd.lang.rule.AbstractRule;
import net.sourceforge.pmd.lang.symboltable.Scope;
import net.sourceforge.pmd.lang.symboltable.ScopedNode;
import org.jetbrains.annotations.Nullable;

/**
* @author caikang
Expand Down Expand Up @@ -67,6 +69,14 @@ public static boolean shouldIgnoreViolation(Class ruleClass, Node node) {
return true;
}

ASTCompilationUnit nodeRoot = getNodeRoot(node);
if (nodeRoot != null) {
String packageName = nodeRoot.getPackageName();
if (NameListConfig.getNameListService().ifPackageNameInPackageBlackList(packageName)) {
return true;
}
}

if (node instanceof ScopedNode) {
ScopedNode scopedNode = (ScopedNode) node;
Scope scope = scopedNode.getScope();
Expand All @@ -85,4 +95,16 @@ public static boolean shouldIgnoreViolation(Class ruleClass, Node node) {

return false;
}

@Nullable
private static ASTCompilationUnit getNodeRoot(@Nullable Node node) {
while (node != null) {
if (node instanceof ASTCompilationUnit) {
return (ASTCompilationUnit) node;
}
node = node.getParent();
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.xenoamess.p3c.pmd.lang.java.util.namelist;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.List;
Expand Down Expand Up @@ -65,6 +66,13 @@ void loadPatchConfigFile(
*/
boolean ifClassNameInClassBlackList(String className);

/**
* check if package name is in package black list.
* @param packageName package name
* @return true if in package black list
*/
boolean ifPackageNameInPackageBlackList(@Nullable String packageName);

/**
* check if class name is in class name pair black list.
* @param ruleClass rule class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.xenoamess.x8l.dealers.X8lDealer;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -114,6 +115,22 @@ public boolean ifClassNameInClassBlackList(String className) {
return this.getP3cConfigDataBean().getClassBlackListSet().contains(className);
}

@Override
public boolean ifPackageNameInPackageBlackList(@Nullable String packageName) {
if (packageName == null) {
return false;
}
Set<String> packageBlackListSet = this.getP3cConfigDataBean().getPackageBlackListSet();
if (packageBlackListSet != null) {
for (String packageBlack : packageBlackListSet) {
if (packageName.startsWith(packageBlack)) {
return true;
}
}
}
return false;
}

@Override
public boolean ifRuleClassNameClassNamePairInPairIgnoreList(Class ruleClass, String className) {
if (getP3cConfigDataBean().getRuleClassPairBlackListMap().containsKey(className)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<test-code>
<description>testFail1</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>4</expected-linenumbers>
<code-ref id="testFail1"/>
</test-code>

Expand All @@ -36,6 +37,7 @@
<test-code>
<description>testFail2</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>4</expected-linenumbers>
<code-ref id="testFail2"/>
</test-code>

Expand All @@ -54,6 +56,7 @@
<test-code>
<description>testFail3</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>4</expected-linenumbers>
<code-ref id="testFail3"/>
</test-code>

Expand All @@ -70,6 +73,7 @@
<test-code>
<description>testFail4</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>2</expected-linenumbers>
<code-ref id="testFail4"/>
</test-code>

Expand Down

0 comments on commit 9d2594c

Please sign in to comment.