From b26b392c27ae0fdabe056a8d60e67da0aa4e0bc2 Mon Sep 17 00:00:00 2001 From: youys <1272586223@qq.com> Date: Mon, 7 Jul 2025 10:56:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(SonarService):=20h=E5=92=8Cother=E8=AF=AD?= =?UTF-8?q?=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ecsonar/services/SonarService.java | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/educoder/ecsonar/services/SonarService.java b/src/main/java/net/educoder/ecsonar/services/SonarService.java index 21e3511..99da808 100644 --- a/src/main/java/net/educoder/ecsonar/services/SonarService.java +++ b/src/main/java/net/educoder/ecsonar/services/SonarService.java @@ -65,7 +65,7 @@ public class SonarService { "-Dsonar.projectBaseDir=" + param.getProjectPath(); SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command); - log.info("java语言:command{},result:{}",command,executeResp.getOutput()); + log.info("java语言:command{},result:{}", command, executeResp.getOutput()); }); concurrentHashMap.put(Constant.PYTHON, param -> { @@ -77,7 +77,7 @@ public class SonarService { "-Dsonar.projectBaseDir=" + param.getProjectPath(); SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command); - log.info("python语言:command{},result:{}",command,executeResp.getOutput()); + log.info("python语言:command{},result:{}", command, executeResp.getOutput()); }); concurrentHashMap.put(Constant.C, param -> { String command = "cppcheck --xml --xml-version=2 --enable=all " + param.getProjectPath() + " 2> " + param.getCppCheckReportPath() + @@ -89,7 +89,7 @@ public class SonarService { "-Dsonar.cxx.cppcheck.reportPath=" + param.getCppCheckReportPath() + " " + "-Dsonar.projectBaseDir=" + param.getProjectPath(); SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command); - log.info("c语言:command{},result:{}",command,executeResp.getOutput()); + log.info("c语言:command{},result:{}", command, executeResp.getOutput()); }); concurrentHashMap.put(Constant.CXX, param -> { String command = "cppcheck --xml --xml-version=2 --enable=all " + param.getProjectPath() + " 2> " + param.getCppCheckReportPath() + @@ -103,6 +103,30 @@ public class SonarService { SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command); log.info("c++: command:{}, result:{}", command, executeResp.getOutput()); }); + + concurrentHashMap.put(Constant.H, param -> { + String command = "sonar-scanner " + + "-Dsonar.host.url=" + sonarUrl + " " + + "-Dsonar.sourceEncoding=utf-8 " + + "-Dsonar.login=" + sonarToken + " " + + "-Dsonar.projectKey=" + param.getProjectKey() + " " + + "-Dsonar.projectBaseDir=" + param.getProjectPath(); + SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command); + log.info("H语言 command: {},result:{}", command, executeResp.getOutput()); + }); + + + concurrentHashMap.put(Constant.OTHER, param -> { + String command = "sonar-scanner " + + "-Dsonar.host.url=" + sonarUrl + " " + + "-Dsonar.sourceEncoding=utf-8 " + + "-Dsonar.projectKey=" + param.getProjectKey() + " " + + "-Dsonar.login=" + sonarToken + " " + + "-Dsonar.projectBaseDir=" + param.getProjectPath(); + + SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command); + log.info("Other语言 command:{},result:{}", command, executeResp.getOutput()); + }); } /** @@ -182,7 +206,7 @@ public class SonarService { public void sonar(String language, SonarScannerParam sonarScannerParam) { Consumer consumer = concurrentHashMap.get(language.toLowerCase()); if (consumer != null) { - log.info("语言:{},projectName:{},path:{}找到了consumer", language, sonarScannerParam.getProjectKey(),sonarScannerParam.getProjectPath()); + log.info("语言:{},projectName:{},path:{}找到了consumer", language, sonarScannerParam.getProjectKey(), sonarScannerParam.getProjectPath()); consumer.accept(sonarScannerParam); } } @@ -202,10 +226,11 @@ public class SonarService { /** * 是否是支持的语言 + * * @param language * @return */ - public boolean supportLanguage(String language){ + public boolean supportLanguage(String language) { return concurrentHashMap.containsKey(language.toLowerCase()); }