增加搜索全部issue

dev
youys 2 years ago
parent 4c7113e67e
commit 7a861c0c65

@ -14,6 +14,7 @@ public class Constant {
public static final String JAVA = "java"; public static final String JAVA = "java";
public static final String C = "c"; public static final String C = "c";
public static final String CXX = "cpp"; public static final String CXX = "cpp";
public static final String CPP = "c++";
public static final String PYTHON = "python"; public static final String PYTHON = "python";
public static final List<String> language = Arrays.asList(JAVA, C, CXX, PYTHON); public static final List<String> language = Arrays.asList(JAVA, C, CXX, PYTHON);
@ -25,4 +26,5 @@ public class Constant {
public static final String VULNERABILITY = "VULNERABILITY"; public static final String VULNERABILITY = "VULNERABILITY";
public static final String CODE_SMELL = "CODE_SMELL"; public static final String CODE_SMELL = "CODE_SMELL";
public static final String SECURITY_HOTSPOT = "SECURITY_HOTSPOT"; public static final String SECURITY_HOTSPOT = "SECURITY_HOTSPOT";
public static final String ALL = "ALL";
} }

@ -53,9 +53,9 @@ public interface ProjectDao {
@Select("select (select count(1) from issues where project_uuid=#{projectUuid} and issue_type=1) vulnerability," + @Select("select (select count(1) from issues where project_uuid=#{projectUuid} and issue_type=1) codeSmell," +
"(select count(1) from issues where project_uuid=#{projectUuid} and issue_type=2) bugs," + "(select count(1) from issues where project_uuid=#{projectUuid} and issue_type=2) bugs," +
"(select count(1) from issues where project_uuid=#{projectUuid} and issue_type=3) codeSmell," + "(select count(1) from issues where project_uuid=#{projectUuid} and issue_type=3) vulnerability," +
"(select value from project_measures pm where component_uuid=#{projectUuid} and metric_id=3) codeLines") "(select value from project_measures pm where component_uuid=#{projectUuid} and metric_id=3) codeLines")
IssuesMetrics selectIssuesMetrics(String projectUuid); IssuesMetrics selectIssuesMetrics(String projectUuid);
} }

@ -8,6 +8,12 @@ package net.educoder.ecsonar.model.vo;
public class IssuesSearchVO { public class IssuesSearchVO {
private String taskName; private String taskName;
/**
* BUG,
* CODE_SMELL,
* VULNERABILITY
* ALL
*/
private String type; private String type;
public String getTaskName() { public String getTaskName() {

@ -3,6 +3,7 @@ package net.educoder.ecsonar.services;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import net.educoder.ecsonar.constant.Constant;
import net.educoder.ecsonar.dao.CloudTaskInfoDao; import net.educoder.ecsonar.dao.CloudTaskInfoDao;
import net.educoder.ecsonar.dao.CloudTaskInfoDetailDao; import net.educoder.ecsonar.dao.CloudTaskInfoDetailDao;
import net.educoder.ecsonar.dao.ProjectDao; import net.educoder.ecsonar.dao.ProjectDao;
@ -23,6 +24,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -183,15 +185,19 @@ public class CloudBrainService {
/** /**
* issues * issues
* *
* @param projectName * @param taskName
* @param types * @param type
* @return * @return
*/ */
private List<IssuesVO> doGetIssues(String projectName, String types) { private List<IssuesVO> doGetIssues(String taskName, String type) {
if (Constant.ALL.equals(type)) {
type = StringUtils.join(Constant.BUG, ",", Constant.VULNERABILITY, ",", Constant.CODE_SMELL);
}
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("/api/issues/search?componentKeys=").append(projectName) sb.append("/api/issues/search?componentKeys=").append(taskName)
.append("&s=FILE_LINE&resolved=false&types=").append(types) .append("&s=FILE_LINE&resolved=false&types=").append(type)
.append("&ps=500&organization=default-organization&facets=severities%2Ctypes&additionalFields=_all"); .append("&ps=500&organization=default-organization&facets=severities%2Ctypes&additionalFields=_all");
String url = sonarHost + sb.toString(); String url = sonarHost + sb.toString();
@ -217,6 +223,12 @@ public class CloudBrainService {
return issuesVOS; return issuesVOS;
} }
/**
*
*
* @param component
* @return
*/
private List<SourceCodeVO> doGetSourceCode(String component) { private List<SourceCodeVO> doGetSourceCode(String component) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

@ -176,7 +176,7 @@ public class SonarService {
public void sonar(String language, SonarScannerParam sonarScannerParam) { public void sonar(String language, SonarScannerParam sonarScannerParam) {
Consumer<SonarScannerParam> consumer = concurrentHashMap.get(language); Consumer<SonarScannerParam> consumer = concurrentHashMap.get(language.toLowerCase());
if (consumer != null) { 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); consumer.accept(sonarScannerParam);
@ -195,6 +195,15 @@ public class SonarService {
SystemUtil.executeAndGetExitStatus(command); SystemUtil.executeAndGetExitStatus(command);
} }
/**
*
* @param language
* @return
*/
public boolean supportLanguage(String language){
return concurrentHashMap.containsKey(language.toLowerCase());
}
/** /**
* zip * zip
* *

@ -1,6 +1,7 @@
package net.educoder.ecsonar.task; package net.educoder.ecsonar.task;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import net.educoder.ecsonar.constant.Constant;
import net.educoder.ecsonar.model.CloudTaskInfoDetail; import net.educoder.ecsonar.model.CloudTaskInfoDetail;
import net.educoder.ecsonar.model.SonarScannerParam; import net.educoder.ecsonar.model.SonarScannerParam;
import net.educoder.ecsonar.services.DbOperateService; import net.educoder.ecsonar.services.DbOperateService;
@ -10,6 +11,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
/** /**
@ -54,7 +56,24 @@ public class CloudBrainQualityInspectRunnable implements Runnable {
String projectKey = projectName; String projectKey = projectName;
String projectPath = path; String projectPath = path;
sonarService.sonar(cloudTaskInfoDetail.getLanguage(), new SonarScannerParam(projectKey, projectPath));
String language = cloudTaskInfoDetail.getLanguage();
// c和c++需要额外做一些处理
if (sonarService.supportLanguage(language)) {
SonarScannerParam scannerParam = new SonarScannerParam(projectKey, projectPath);
if (Constant.C.equalsIgnoreCase(language) || Constant.CPP.equalsIgnoreCase(language)) {
String resultPath = String.format("/tmp/%s", cloudTaskInfoDetail.getTaskId());
File f = new File(resultPath);
if (!f.exists()) {
f.mkdirs();
}
scannerParam.setCppCheckReportPath(resultPath + String.format("/%s-result.xml", projectName));
}
sonarService.sonar(cloudTaskInfoDetail.getLanguage(), scannerParam);
} else {
sonarService.sonar(projectPath, projectKey);
}
CloudBrainQueryResultRunnable queryResultRunnable = new CloudBrainQueryResultRunnable(projectName, cloudTaskInfoDetail.getId(), dbOperateService); CloudBrainQueryResultRunnable queryResultRunnable = new CloudBrainQueryResultRunnable(projectName, cloudTaskInfoDetail.getId(), dbOperateService);
queryResultPool.execute(queryResultRunnable); queryResultPool.execute(queryResultRunnable);

Loading…
Cancel
Save