Skip to content

Commit f84ae8f

Browse files
committed
Fix deprecations
1 parent 832afc5 commit f84ae8f

File tree

8 files changed

+22
-12
lines changed

8 files changed

+22
-12
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
steps:
4444
- uses: actions/checkout@v3
4545

46-
- name: Run .ci/build
46+
- name: Run .ci/build.sh
4747
run: |
4848
cd custom-rules/plain-java
4949
.ci/build.sh
@@ -54,8 +54,7 @@ jobs:
5454
steps:
5555
- uses: actions/checkout@v3
5656

57-
- name: Run maven
57+
- name: Run .ci/build.sh
5858
run: |
5959
cd maven/simple-project
60-
mvn verify | tee build.log
61-
grep "You have 2 PMD violations" build.log || (echo "Missing expected rule violation"; exit 1)
60+
.ci/build.sh

custom-rules/maven-java/pmd-java-custom/src/main/java/net/sourceforge/pmd/examples/java/rules/MyRule.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
44
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
5-
import net.sourceforge.pmd.properties.StringProperty;
5+
import net.sourceforge.pmd.properties.PropertyDescriptor;
6+
import net.sourceforge.pmd.properties.PropertyFactory;
67

78
public class MyRule extends AbstractJavaRule {
89

9-
private static final StringProperty BAD_NAME = StringProperty.named("badName")
10+
private static final PropertyDescriptor<String> BAD_NAME = PropertyFactory.stringProperty("badName")
1011
.defaultValue("foo")
1112
.desc("The variable name that should not be used.")
12-
.uiOrder(1.0f)
1313
.build();
1414

1515
public MyRule() {
@@ -21,7 +21,7 @@ public MyRule() {
2121
public Object visit(ASTVariableDeclaratorId node, Object data) {
2222
String badName = getProperty(BAD_NAME);
2323
if (node.hasImageEqualTo(badName)) {
24-
addViolation(data, node, node.getImage());
24+
asCtx(data).addViolation(node, node.getName());
2525
}
2626
return data;
2727
}

custom-rules/maven-java/pmd-java-custom/src/main/resources/net/sourceforge/pmd/examples/java/rules/MyRule.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22

33
<ruleset name="My Rule"
44
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"

custom-rules/maven-java/pmd-java-custom/src/main/resources/net/sourceforge/pmd/examples/java/rules/VariableNaming.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22

33
<ruleset name="VariableNamingRule"
44
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"

custom-rules/maven-plsql/pmd-plsql-custom/src/main/java/net/sourceforge/pmd/examples/plsql/rules/ShortVariableRule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public Object visit(ASTVariableOrConstantDeclaratorId node, Object data) {
3131
ASTID id = node.getFirstChildOfType(ASTID.class);
3232
if (id != null) {
3333
if (node.getImage().length() < min) {
34-
addViolation(data, node, node.getImage());
34+
asCtx(data).addViolation(node, node.getImage());
3535
}
3636
}
3737
return data;

custom-rules/plain-java/src/MyRule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class MyRule extends AbstractJavaRule {
66
@Override
77
public Object visit(ASTVariableDeclaratorId node, Object data) {
88
if (node.hasImageEqualTo("foo")) {
9-
addViolationWithMessage(data, node, "Avoid the identifier 'foo'.");
9+
asCtx(data).addViolationWithMessage(node, "Avoid the identifier 'foo'.");
1010
}
1111
return super.visit(node, data);
1212
}

maven/simple-project/.ci/build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
# exit immediately if a command fails
4+
set -e
5+
java -version
6+
mvn --version
7+
8+
mvn verify | tee build.log
9+
grep "You have 2 PMD violations" build.log || (echo "Missing expected rule violation"; exit 1)

maven/simple-project/src/main/java/net/sourceforge/pmd/examples/maven/simpleproject/Main.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package net.sourceforge.pmd.examples.maven.simpleproject;
2+
13
public class Main {
24

35
// UnusedPrivateField

0 commit comments

Comments
 (0)