feat: implement core code review extension
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import net.sourceforge.pmd.*;
|
||||
import net.sourceforge.pmd.renderers.*;
|
||||
|
||||
public class PmdRunner {
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length < 2) {
|
||||
System.err.println("Usage: PmdRunner <filePath|- for stdin> <rulesetPath>");
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
String filePath = args[0];
|
||||
String rulesetPath = args[1];
|
||||
|
||||
Path tempFile = null;
|
||||
if ("-".equals(filePath)) {
|
||||
String code = new String(System.in.readAllBytes());
|
||||
tempFile = Files.createTempFile("pmd-stdin-", ".java");
|
||||
Files.writeString(tempFile, code);
|
||||
filePath = tempFile.toString();
|
||||
}
|
||||
|
||||
try {
|
||||
PMDConfiguration config = new PMDConfiguration();
|
||||
config.setInputFilePath(Path.of(filePath));
|
||||
config.addRuleSet(Path.of(rulesetPath));
|
||||
config.setReportFormat("json");
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
config.setReportWriter(writer);
|
||||
|
||||
PmdAnalysis pmd = PmdAnalysis.create(config);
|
||||
pmd.performAnalysis();
|
||||
|
||||
System.out.print(writer.toString());
|
||||
} finally {
|
||||
if (tempFile != null) {
|
||||
Files.deleteIfExists(tempFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="Java Rules"
|
||||
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 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||
<description>Java Code Review Rules</description>
|
||||
<rule ref="category/java/bestpractices.xml"/>
|
||||
<rule ref="category/java/codestyle.xml"/>
|
||||
<rule ref="category/java/design.xml"/>
|
||||
<rule ref="category/java/errorprone.xml"/>
|
||||
<rule ref="category/java/performance.xml"/>
|
||||
<rule ref="category/java/security.xml"/>
|
||||
</ruleset>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="JSP Rules"
|
||||
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 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||
<description>JSP Code Review Rules</description>
|
||||
<rule ref="category/jsp/bestpractices.xml"/>
|
||||
<rule ref="category/jsp/codestyle.xml"/>
|
||||
<rule ref="category/jsp/design.xml"/>
|
||||
<rule ref="category/jsp/errorprone.xml"/>
|
||||
</ruleset>
|
||||
Reference in New Issue
Block a user