|
@@ -3,6 +3,7 @@ package com.moekr.moocoder.logic.api;
|
|
|
import com.moekr.moocoder.logic.vo.MaintainMetricVO;
|
|
import com.moekr.moocoder.logic.vo.MaintainMetricVO;
|
|
|
import com.moekr.moocoder.logic.vo.PMDRelatedVO;
|
|
import com.moekr.moocoder.logic.vo.PMDRelatedVO;
|
|
|
import com.moekr.moocoder.logic.vo.ErrorProneMetricVO;
|
|
import com.moekr.moocoder.logic.vo.ErrorProneMetricVO;
|
|
|
|
|
+import lombok.extern.apachecommons.CommonsLog;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.w3c.dom.*;
|
|
import org.w3c.dom.*;
|
|
@@ -20,8 +21,11 @@ import java.util.Map;
|
|
|
* @since 2020/5/26
|
|
* @since 2020/5/26
|
|
|
*/
|
|
*/
|
|
|
@Component
|
|
@Component
|
|
|
|
|
+@CommonsLog
|
|
|
public class PMDController {
|
|
public class PMDController {
|
|
|
public static final String RULE_SET = "rulesets/internal/all-java.xml";
|
|
public static final String RULE_SET = "rulesets/internal/all-java.xml";
|
|
|
|
|
+ public static final String PMD_REPORT_SUFFIX = "-pmd-report";
|
|
|
|
|
+ public static final String CPD_REPORT_SUFFIX = "-cpd-report";
|
|
|
|
|
|
|
|
private PMDWrapper wrapper;
|
|
private PMDWrapper wrapper;
|
|
|
|
|
|
|
@@ -37,8 +41,8 @@ public class PMDController {
|
|
|
* @param project project id
|
|
* @param project project id
|
|
|
*/
|
|
*/
|
|
|
public void makeReport(String srcDir, String dstDir, String project) {
|
|
public void makeReport(String srcDir, String dstDir, String project) {
|
|
|
- String pmdPrefix = dstDir + File.separator + project + "-pmd-report";
|
|
|
|
|
- String cpdPrefix = dstDir + File.separator + project + "-cpd-report";
|
|
|
|
|
|
|
+ String pmdPrefix = dstDir + File.separator + project + PMD_REPORT_SUFFIX;
|
|
|
|
|
+ String cpdPrefix = dstDir + File.separator + project + CPD_REPORT_SUFFIX;
|
|
|
wrapper.runPMD(srcDir, "xml", RULE_SET, pmdPrefix+".xml", null);
|
|
wrapper.runPMD(srcDir, "xml", RULE_SET, pmdPrefix+".xml", null);
|
|
|
wrapper.runPMD(srcDir, "html", RULE_SET, pmdPrefix+".html", null);
|
|
wrapper.runPMD(srcDir, "html", RULE_SET, pmdPrefix+".html", null);
|
|
|
wrapper.runCPD(srcDir, "xml", cpdPrefix+".xml");
|
|
wrapper.runCPD(srcDir, "xml", cpdPrefix+".xml");
|
|
@@ -54,7 +58,7 @@ public class PMDController {
|
|
|
*/
|
|
*/
|
|
|
public PMDRelatedVO readXMLReport(String dstDir, String project) {
|
|
public PMDRelatedVO readXMLReport(String dstDir, String project) {
|
|
|
try {
|
|
try {
|
|
|
- String pmdReportPath = dstDir + File.separator + project + "-pmd-report.xml";
|
|
|
|
|
|
|
+ String pmdReportPath = dstDir + File.separator + project + PMD_REPORT_SUFFIX + ".xml";
|
|
|
File pmdFile = new File(pmdReportPath);
|
|
File pmdFile = new File(pmdReportPath);
|
|
|
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
|
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
|
|
DocumentBuilder db = dbf.newDocumentBuilder();
|
|
DocumentBuilder db = dbf.newDocumentBuilder();
|
|
@@ -64,13 +68,13 @@ public class PMDController {
|
|
|
PMDRelatedVO ret = new PMDRelatedVO();
|
|
PMDRelatedVO ret = new PMDRelatedVO();
|
|
|
readPMDXMLReport(ret, doc);
|
|
readPMDXMLReport(ret, doc);
|
|
|
|
|
|
|
|
- String cpdReportPath = dstDir + File.separator + project + "-cpd-report.xml";
|
|
|
|
|
|
|
+ String cpdReportPath = dstDir + File.separator + project + CPD_REPORT_SUFFIX + ".xml";
|
|
|
File cpdFile = new File(cpdReportPath);
|
|
File cpdFile = new File(cpdReportPath);
|
|
|
Document cpdDoc = db.parse(cpdFile);
|
|
Document cpdDoc = db.parse(cpdFile);
|
|
|
readCPDXMLReport(ret, cpdDoc);
|
|
readCPDXMLReport(ret, cpdDoc);
|
|
|
return ret;
|
|
return ret;
|
|
|
} catch (IOException|SAXException|ParserConfigurationException e){
|
|
} catch (IOException|SAXException|ParserConfigurationException e){
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ log.warn(e);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -82,7 +86,7 @@ public class PMDController {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String pmdReport = dstDir + File.separator + project + "-pmd-report.xml"; // one probe is enough
|
|
|
|
|
|
|
+ String pmdReport = dstDir + File.separator + project + PMD_REPORT_SUFFIX + ".xml"; // one probe is enough
|
|
|
File dst = new File(pmdReport);
|
|
File dst = new File(pmdReport);
|
|
|
if (!dst.exists()){
|
|
if (!dst.exists()){
|
|
|
return true;
|
|
return true;
|