Compare commits

..

4 Commits

@ -14,7 +14,7 @@ public class ThreadPoolConfig {
@Primary
public ExecutorService sonarScannerPool() {
ThreadFactory sonarScannerPool = new CustomizableThreadFactory("sonarScanner-pool-");
return new ThreadPoolExecutor(50, 50, 0,
return new ThreadPoolExecutor(10, 10, 0,
TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000), sonarScannerPool,
new ThreadPoolExecutor.AbortPolicy());
}
@ -23,7 +23,7 @@ public class ThreadPoolConfig {
@Bean("sonarQueryResultPool")
public ExecutorService queryResultPool() {
ThreadFactory sonarQueryResultPool = new CustomizableThreadFactory("sonarQueryResult-pool-");
return new ThreadPoolExecutor(50, 50, 0,
return new ThreadPoolExecutor(5, 5, 0,
TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000),
sonarQueryResultPool,
new ThreadPoolExecutor.AbortPolicy());

@ -16,10 +16,9 @@ public class Constant {
public static final String CXX = "cpp";
public static final String CPP = "c++";
public static final String PYTHON = "python";
public static final String H = "h";
public static final String OTHER = "other";
public static final List<String> language = Arrays.asList(JAVA, C, CXX, PYTHON, OTHER, H);
public static final List<String> language = Arrays.asList(JAVA, C, CXX, PYTHON, OTHER);
public static final String SUCCESS = "SUCCESS";

@ -129,7 +129,7 @@ public class QualityInspectController {
*/
@GetMapping("/problemAnalysis")
@ResponseBody
public ResponseResult<ProblemAnalysisDTO> problemAnalysis(@RequestParam Integer ruleId) {
public ResponseResult<ProblemAnalysisDTO> problemAnalysis(@RequestParam String ruleId) {
ProblemAnalysisDTO problemAnalysis = qualityInspectService.getProblemAnalysis(ruleId);
return ResponseResult.success(problemAnalysis);
}

@ -9,11 +9,7 @@ import org.apache.ibatis.annotations.Select;
* @Description:
*/
public interface GameCodesDao {
@Select("select new_code code,path from game_codes where id=#{id}")
GameCodes queryOriginalCodeById(Long id);
@Select("select code,path from student_work_shixun_codes where id=#{id}")
GameCodes queryShiXunOriginalCodeById(Long id);
}

@ -2,6 +2,7 @@ package net.educoder.ecsonar.dao;
import net.educoder.ecsonar.model.Issues;
import net.educoder.ecsonar.model.dto.DegreeDTO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -38,9 +39,10 @@ public interface IssuesDao {
*
* @param projectUuid
* @param issueType
* @param metricName
* @return
*/
DegreeDTO queryDegree(String projectUuid, Integer issueType, Integer metricId);
DegreeDTO queryDegree(String projectUuid, Integer issueType, String metricName);
/**
@ -48,5 +50,5 @@ public interface IssuesDao {
* @param issueId
* @return
*/
Issues queryById(Long issueId);
Issues queryById(@Param("issueId") String issueId);
}

@ -13,42 +13,66 @@ import org.springframework.stereotype.Repository;
@Mapper
public interface ProjectDao {
@Select("select * from projects where name = #{name}")
@Select("select uuid,kee,qualifier,name from projects where name = #{name}")
Project findByName(@Param("name")String name);
@Select("select COALESCE(value,0) from project_measures where component_uuid = #{uuid} and metric_id = 19 order by id desc limit 1")
/**
*
* @param uuid
* @return
*/
@Select("select COALESCE(value,0) from project_measures where component_uuid = #{uuid} and metric_uuid = select uuid from metrics m where name='file_complexity' limit 1")
Float getComplexity(@Param("uuid") String uuid);
@Select("select COALESCE(value,0) from project_measures where component_uuid = #{uuid} and metric_id = 1 order by id desc limit 1")
/**
*
* @param uuid
* @return
*/
@Select("select COALESCE(value,0) from project_measures where component_uuid = #{uuid} and metric_uuid=(select uuid from metrics m where name='lines') limit 1")
Integer getLines(@Param("uuid") String uuid);
@Select("select text_value from project_measures where component_uuid = #{uuid} and metric_id = #{metric_id} order by id desc limit 1")
String getLevel(@Param("uuid") String uuid, @Param("metric_id") int metric_id);
/**
*
* @param uuid
* @param metricName
* @return
*/
@Select("select text_value from project_measures where component_uuid = #{uuid} and metric_uuid=(select uuid from metrics m where name=#{metricName}}) limit 1")
String getLevel(@Param("uuid") String uuid, @Param("metricName") String metricName);
@Select("SELECT count(*) FROM issues where project_uuid=#{uuid} and " +
"status='OPEN' and issue_type=#{issue_type} and severity=#{severity}")
int getIndicator(@Param("uuid") String uuid, @Param("issue_type") int issue_type, @Param("severity") String severity);
/**
* 93 == AYeNSwayTEppvP7II93_
* 89 == AYeNSwayTEppvP7II94B
* 80 == AYeNSwaxTEppvP7II93y
* 19 == AYeNSwarTEppvP7II92z
* @param projectUuid
* @return
*/
@Select("select " +
"(select COALESCE(value,0) complexity from project_measures where component_uuid = #{projectUuid} and metric_id = 19 order by id desc limit 1)," +
"(select COALESCE(value,0) lines from project_measures where component_uuid = #{projectUuid} and metric_id = 1 order by id desc limit 1)," +
"(select COALESCE(value,0) complexity from project_measures where component_uuid = #{projectUuid} and metric_uuid = (select uuid from metrics m where name='file_complexity') limit 1)," +
"(select COALESCE(value,0) lines from project_measures where component_uuid = #{projectUuid} and metric_uuid = (select uuid from metrics m where name='lines') limit 1)," +
"(SELECT COALESCE(count(*),0) block_code_smells FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=1 and severity='BLOCKER'), " +
"(SELECT COALESCE(count(*),0) critical_code_smells FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=1 and severity='CRITICAL')," +
"(SELECT COALESCE(count(*),0) major_code_smells FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=1 and severity='MAJOR')," +
"(SELECT COALESCE(count(*),0) minor_code_smells FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=1 and severity='MINOR')," +
"(select text_value code_smells from project_measures where component_uuid = #{projectUuid} and metric_id = 80 order by id desc limit 1)," +
"(select text_value code_smells from project_measures where component_uuid = #{projectUuid} and metric_uuid = (select uuid from metrics m where name='sqale_rating') limit 1)," +
"(SELECT COALESCE(count(*),0) block_bugs FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=2 and severity='BLOCKER'), " +
"(SELECT COALESCE(count(*),0) critical_bugs FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=2 and severity='CRITICAL')," +
"(SELECT COALESCE(count(*),0) major_bugs FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=2 and severity='MAJOR')," +
"(SELECT COALESCE(count(*),0) minor_bugs FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=2 and severity='MINOR')," +
"(select text_value bugs from project_measures where component_uuid = #{projectUuid} and metric_id = 89 order by id desc limit 1)," +
"(select text_value bugs from project_measures where component_uuid = #{projectUuid} and metric_uuid = (select uuid from metrics m where name='security_review_rating') limit 1)," +
"(SELECT COALESCE(count(*),0) block_violations FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=3 and severity='BLOCKER'), " +
"(SELECT COALESCE(count(*),0) critical_violations FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=3 and severity='CRITICAL')," +
"(SELECT COALESCE(count(*),0) major_violations FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=3 and severity='MAJOR')," +
"(SELECT COALESCE(count(*),0) minor_violations FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=3 and severity='MINOR')," +
"(select text_value violations from project_measures where component_uuid = #{projectUuid} and metric_id = 93 order by id desc limit 1)")
"(select text_value violations from project_measures where component_uuid = #{projectUuid} and metric_uuid = (select uuid from metrics m where name='security_rating') limit 1)")
Metrics selectMetricsByProjectUuid(String projectUuid);
@ -57,13 +81,16 @@ public interface ProjectDao {
@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=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_uuid=(select uuid from metrics m where name='ncloc')) codeLines")
IssuesMetrics selectIssuesMetrics(String projectUuid);
/**
* rule
* @param id
* @param uuid
* @return
*/
Rule findRuleById(@Param("id") Integer id);
Rule findRuleById(@Param("uuid") String uuid);
// @Select("select uuid from metrics m where name=#{name}}")
// String findMetricUUIDByName(@Param("name") String name);
}

@ -20,8 +20,7 @@ public interface TaskInfoDetailDao {
*
* @param taskInfoDetail
*/
@Insert("insert into task_info_detail(id,task_id,project_name,student_id,user_id,name,code_ids, shixun_code_ids) " +
"values(#{id},#{taskId},#{projectName},#{studentId},#{userId} ,#{name},#{codeIds}, #{shiXunCodeIds})")
@Insert("insert into task_info_detail(id,task_id,project_name,student_id,user_id,name,code_ids) values(#{id},#{taskId},#{projectName},#{studentId},#{userId} ,#{name},#{codeIds})")
void insertTaskInfoDetail(TaskInfoDetail taskInfoDetail);
/**
@ -48,9 +47,7 @@ public interface TaskInfoDetailDao {
* @param id
* @return
*/
@Select("select id,task_id taskId,project_name projectName,student_id studentId,user_id userId,name," +
"code_ids codeIds,shixun_code_ids shiXunCodeIds, status,create_time createTime,update_time updateTime " +
"from task_info_detail where id=#{id}")
@Select("select id,task_id taskId,project_name projectName,student_id studentId,user_id userId,name,code_ids codeIds,status,create_time createTime,update_time updateTime from task_info_detail where id=#{id}")
TaskInfoDetail selectById(String id);
/**
@ -72,9 +69,6 @@ public interface TaskInfoDetailDao {
* @param position
* @return
*/
@Select("select id,task_id taskId,project_name projectName,student_id studentId,user_id userId,name," +
"code_ids codeIds,shixun_code_ids shiXunCodeIds, status,create_time createTime,update_time updateTime " +
"from task_info_detail where task_id=#{taskId} limit #{pageSize} offset #{position}")
List<TaskInfoDetail> selectTaskInfoDetailPageList(@Param("taskId") String taskId,
@Param("pageSize") Integer pageSize, @Param("position") Integer position);
@Select("select id,task_id taskId,project_name projectName,student_id studentId,user_id userId,name,code_ids codeIds,status,create_time createTime,update_time updateTime from task_info_detail where task_id=#{taskId} limit #{pageSize} offset #{position}")
List<TaskInfoDetail> selectTaskInfoDetailPageList(@Param("taskId") String taskId, @Param("pageSize") Integer pageSize, @Param("position") Integer position);
}

@ -8,17 +8,20 @@ package net.educoder.ecsonar.enums;
*/
public enum AnalyseTypeEnum {
CodeSmell(1,80),
BUG(2, 89),
Vulnerability(3,93);
CodeSmell(1,80, "sqale_rating"),
BUG(2, 89, "security_review_rating"),
Vulnerability(3,93, "security_rating");
private Integer type;
private Integer metricId;
private String metricName;
AnalyseTypeEnum(Integer type, Integer metricId) {
AnalyseTypeEnum(Integer type, Integer metricId, String metricName) {
this.type = type;
this.metricId = metricId;
this.metricName = metricName;
}
@ -30,6 +33,10 @@ public enum AnalyseTypeEnum {
return metricId;
}
public String getMetricName() {
return metricName;
}
public static AnalyseTypeEnum getAnalyseTypeEnum(Integer type) {
for (AnalyseTypeEnum analyseType : values()) {
if (analyseType.type.equals(type)) {

@ -22,7 +22,7 @@ public class FileSource {
private static final String SIZE_LIMIT_EXCEEDED_EXCEPTION_MESSAGE = "Protocol message was too large. May be malicious. " +
"Use CodedInputStream.setSizeLimit() to increase the size limit.";
private Long id;
private String uuid;
private String projectUuid;
private String fileUuid;
private String lineHashes;
@ -36,7 +36,7 @@ public class FileSource {
return decodeRegularSourceData(binaryData);
} catch (IOException e) {
throw new IllegalStateException(
format("Fail to decompress and deserialize source data [id=%s,fileUuid=%s,projectUuid=%s]", id, fileUuid, projectUuid),
format("Fail to decompress and deserialize source data [id=%s,fileUuid=%s,projectUuid=%s]", uuid, fileUuid, projectUuid),
e);
}
}

@ -11,9 +11,8 @@ import lombok.Data;
@Data
public class Issues {
private Long id;
private String kee;
private Integer ruleId;
private String id;
private String ruleId;
private String severity;
private String message;
private String status;
@ -26,10 +25,6 @@ public class Issues {
* bug
*/
private String name;
/**
* bug
*/
private String description;
/**
*
*/

@ -2,35 +2,36 @@ package net.educoder.ecsonar.model;
public class Project {
private int id;
private String uuid;
private boolean enabled;
private String kee;
private String qualifier;
private String project_uuid;
private String name;
public boolean isEnabled() {
return enabled;
public String getUuid() {
return uuid;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
public void setUuid(String uuid) {
this.uuid = uuid;
}
public int getId() {
return id;
public String getKee() {
return kee;
}
public void setId(int id) {
this.id = id;
public void setKee(String kee) {
this.kee = kee;
}
public String getProject_uuid() {
return project_uuid;
public String getQualifier() {
return qualifier;
}
public void setProject_uuid(String project_uuid) {
this.project_uuid = project_uuid;
public void setQualifier(String qualifier) {
this.qualifier = qualifier;
}
public String getName() {

@ -16,7 +16,6 @@ public class TaskInfoDetail {
private Long userId;
private String name;
private String codeIds;
private String shiXunCodeIds;
/**
* 0 1 -1
*/
@ -104,12 +103,4 @@ public class TaskInfoDetail {
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getShiXunCodeIds() {
return shiXunCodeIds;
}
public void setShiXunCodeIds(String shiXunCodeIds) {
this.shiXunCodeIds = shiXunCodeIds;
}
}

@ -43,8 +43,8 @@ public class AnalyseDetailListDTO {
*/
private String uuid;
private Integer ruleId;
private String ruleId;
private Long issueId;
private String issueId;
}

@ -30,9 +30,7 @@ public class AnalyseDetailListVO extends PageVO {
@NotBlank(message = "作业id不能为空")
private String homeworkId;
@NotBlank(message = "学号不能为空")
private String studentNo;
@NotBlank(message = "userId不能为空")
private String userId;
}

@ -15,9 +15,7 @@ public class AnalyseDetailVO {
@NotBlank(message = "作业id不能为空")
private String homeworkId;
@NotBlank(message = "学号不能为空")
private String studentNo;
@NotBlank(message = "userId不能为空")
private String userId;
}

@ -12,6 +12,6 @@ public class CodeDetailVO {
private String uuid;
private Integer ruleId;
private Long issueId;
private String ruleId;
private String issueId;
}

@ -30,8 +30,6 @@ public class QualityInspectUserDataVO implements Serializable {
*/
private List<Long> codeIds;
private List<Long> studentWorkShixunCodeIds;
public String getStudentId() {
return studentId;
}
@ -63,12 +61,4 @@ public class QualityInspectUserDataVO implements Serializable {
public void setUserId(Long userId) {
this.userId = userId;
}
public List<Long> getStudentWorkShixunCodeIds() {
return studentWorkShixunCodeIds;
}
public void setStudentWorkShixunCodeIds(List<Long> studentWorkShixunCodeIds) {
this.studentWorkShixunCodeIds = studentWorkShixunCodeIds;
}
}

@ -151,7 +151,7 @@ public class CloudBrainService {
return resultVO;
}
IssuesMetrics issuesMetrics = projectDao.selectIssuesMetrics(project.getProject_uuid());
IssuesMetrics issuesMetrics = projectDao.selectIssuesMetrics(project.getUuid());
resultVO.setTaskName(projectName);
resultVO.setBugs(issuesMetrics.getBugs());
resultVO.setVulnerability(issuesMetrics.getVulnerability());

@ -45,13 +45,6 @@ public class DbOperateService {
return gameCode;
}
public GameCodes queryShiXunCodesById(Long id) {
DynamicDataSourceContextHolder.setContextKey(DynamicDataSourceConfig.READONLY);
GameCodes gameCode = gameCodesDao.queryShiXunOriginalCodeById(id);
DynamicDataSourceContextHolder.removeContextKey();
return gameCode;
}
/**
*
*
@ -63,7 +56,7 @@ public class DbOperateService {
if (project == null) {
return null;
}
return ceActivityDao.queryActivityStatus(project.getProject_uuid());
return ceActivityDao.queryActivityStatus(project.getUuid());
}

@ -103,12 +103,11 @@ public class QualityInspectService {
TaskInfoDetail taskInfoDetail = new TaskInfoDetail();
taskInfoDetail.setId(IdUtils.nextStrId());
taskInfoDetail.setTaskId(taskInfo.getId());
taskInfoDetail.setProjectName(String.format("%s-%s", qualityInspectVO.getHomeworkId(), userData.getUserId()));
taskInfoDetail.setProjectName(String.format("%s-%s", qualityInspectVO.getHomeworkId(), userData.getStudentId()));
taskInfoDetail.setName(userData.getName());
taskInfoDetail.setStudentId(userData.getStudentId());
taskInfoDetail.setUserId(userData.getUserId());
taskInfoDetail.setCodeIds(userData.getCodeIds().toString());
taskInfoDetail.setShiXunCodeIds(userData.getStudentWorkShixunCodeIds().toString());
taskInfoDetailDao.insertTaskInfoDetail(taskInfoDetail);
@ -234,16 +233,16 @@ public class QualityInspectService {
*/
public AnalyseDetailDTO getAnalyseDetail(AnalyseDetailVO analyseDetailVO) {
// 作业id+学号
String projectName = String.format("%s-%s", analyseDetailVO.getHomeworkId(), analyseDetailVO.getUserId());
String projectName = String.format("%s-%s", analyseDetailVO.getHomeworkId(), analyseDetailVO.getStudentNo());
Project project = projectDao.findByName(projectName);
if (project == null) {
throw new BusinessException(-1, String.format("找不到分析记录homeworkId:%s,studentNo:%s", analyseDetailVO.getHomeworkId(), analyseDetailVO.getStudentNo()));
}
DegreeDTO codeSmall = issuesDao.queryDegree(project.getProject_uuid(), AnalyseTypeEnum.CodeSmell.getType(), AnalyseTypeEnum.CodeSmell.getMetricId());
DegreeDTO bug = issuesDao.queryDegree(project.getProject_uuid(), AnalyseTypeEnum.BUG.getType(), AnalyseTypeEnum.BUG.getMetricId());
DegreeDTO vulnerability = issuesDao.queryDegree(project.getProject_uuid(), AnalyseTypeEnum.Vulnerability.getType(), AnalyseTypeEnum.Vulnerability.getMetricId());
DegreeDTO codeSmall = issuesDao.queryDegree(project.getUuid(), AnalyseTypeEnum.CodeSmell.getType(), AnalyseTypeEnum.CodeSmell.getMetricName());
DegreeDTO bug = issuesDao.queryDegree(project.getUuid(), AnalyseTypeEnum.BUG.getType(), AnalyseTypeEnum.BUG.getMetricName());
DegreeDTO vulnerability = issuesDao.queryDegree(project.getUuid(), AnalyseTypeEnum.Vulnerability.getType(), AnalyseTypeEnum.Vulnerability.getMetricName());
AnalyseDetailDTO analyseDetail = new AnalyseDetailDTO();
analyseDetail.setBug(bug == null ? new DegreeDTO() : bug);
@ -275,7 +274,7 @@ public class QualityInspectService {
rollPage.setPageSize(analyseDetailListVO.getPageSize());
// 作业id+学号
String projectName = String.format("%s-%s", analyseDetailListVO.getHomeworkId(), analyseDetailListVO.getUserId());
String projectName = String.format("%s-%s", analyseDetailListVO.getHomeworkId(), analyseDetailListVO.getStudentNo());
Project project = projectDao.findByName(projectName);
if (project == null) {
@ -292,11 +291,11 @@ public class QualityInspectService {
severity = degreeEnum.getValue();
}
Integer pageIssuesCount = issuesDao.getPageIssuesCount(project.getProject_uuid(), analyseTypeEnum.getType(), severity);
Integer pageIssuesCount = issuesDao.getPageIssuesCount(project.getUuid(), analyseTypeEnum.getType(), severity);
rollPage.setRecordSum(pageIssuesCount);
if (pageIssuesCount > 0) {
int start = (analyseDetailListVO.getCurrentPage() - 1) * analyseDetailListVO.getPageSize();
List<Issues> pageIssues = issuesDao.getPageIssues(project.getProject_uuid(), analyseTypeEnum.getType(), severity, start, analyseDetailListVO.getPageSize());
List<Issues> pageIssues = issuesDao.getPageIssues(project.getUuid(), analyseTypeEnum.getType(), severity, start, analyseDetailListVO.getPageSize());
processPageIssues(pageIssues, rollPage);
} else {
rollPage.setRecordList(new ArrayList(0));
@ -305,7 +304,7 @@ public class QualityInspectService {
return rollPage;
}
public ProblemAnalysisDTO getProblemAnalysis(Integer ruleId) {
public ProblemAnalysisDTO getProblemAnalysis(String ruleId) {
Rule rule = projectDao.findRuleById(ruleId);
ProblemAnalysisDTO problemAnalysisDTO = new ProblemAnalysisDTO();
if (rule != null) {

@ -1,6 +1,7 @@
package net.educoder.ecsonar.services;
import net.educoder.ecsonar.dao.ProjectDao;
import net.educoder.ecsonar.enums.AnalyseTypeEnum;
import net.educoder.ecsonar.model.Metrics;
import net.educoder.ecsonar.model.Project;
import net.educoder.ecsonar.utils.ExcelUtil;
@ -32,7 +33,7 @@ public class ReportService {
if (project==null){
return getDefault();
}
String uuid = project.getProject_uuid();
String uuid = project.getUuid();
Metrics metrics = projectDao.selectMetricsByProjectUuid(uuid);
@ -162,7 +163,7 @@ public class ReportService {
*/
private String getViolations(String uuid) {
//93
return projectDao.getLevel(uuid, 93);
return projectDao.getLevel(uuid, AnalyseTypeEnum.Vulnerability.getMetricName());
}
@ -209,7 +210,7 @@ public class ReportService {
*/
private String getBugs(String uuid) {
//89
return projectDao.getLevel(uuid, 89);
return projectDao.getLevel(uuid, AnalyseTypeEnum.BUG.getMetricName());
}
@ -256,7 +257,7 @@ public class ReportService {
*/
private String getCodeSmells(String uuid) {
//80
return projectDao.getLevel(uuid, 80);
return projectDao.getLevel(uuid, AnalyseTypeEnum.CodeSmell.getMetricName());
}

@ -58,10 +58,10 @@ public class SonarService {
concurrentHashMap.put(Constant.JAVA, param -> {
String command = "sonar-scanner " +
"-Dsonar.host.url=" + sonarUrl + " " +
"-Dsonar.token=" + sonarToken + " " +
"-Dsonar.sourceEncoding=utf-8 " +
"-Dsonar.projectKey=" + param.getProjectKey() + " " +
"-Dsonar.java.binaries=./ " +
"-Dsonar.login=" + sonarToken + " " +
"-Dsonar.projectBaseDir=" + param.getProjectPath();
SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command);
@ -71,9 +71,9 @@ public class SonarService {
concurrentHashMap.put(Constant.PYTHON, param -> {
String command = "sonar-scanner " +
"-Dsonar.host.url=" + sonarUrl + " " +
"-Dsonar.token=" + sonarToken + " " +
"-Dsonar.sourceEncoding=utf-8 " +
"-Dsonar.projectKey=" + param.getProjectKey() + " " +
"-Dsonar.login=" + sonarToken + " " +
"-Dsonar.projectBaseDir=" + param.getProjectPath();
SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command);
@ -83,8 +83,8 @@ public class SonarService {
String command = "cppcheck --xml --xml-version=2 --enable=all " + param.getProjectPath() + " 2> " + param.getCppCheckReportPath() +
"&& sonar-scanner " +
"-Dsonar.host.url=" + sonarUrl + " " +
"-Dsonar.token=" + sonarToken + " " +
"-Dsonar.sourceEncoding=utf-8 " +
"-Dsonar.login=" + sonarToken + " " +
"-Dsonar.projectKey=" + param.getProjectKey() + " " +
"-Dsonar.cxx.cppcheck.reportPath=" + param.getCppCheckReportPath() + " " +
"-Dsonar.projectBaseDir=" + param.getProjectPath();
@ -95,8 +95,8 @@ public class SonarService {
String command = "cppcheck --xml --xml-version=2 --enable=all " + param.getProjectPath() + " 2> " + param.getCppCheckReportPath() +
"&& sonar-scanner " +
"-Dsonar.host.url=" + sonarUrl + " " +
"-Dsonar.token=" + sonarToken + " " +
"-Dsonar.sourceEncoding=utf-8 " +
"-Dsonar.login=" + sonarToken + " " +
"-Dsonar.projectKey=" + param.getProjectKey() + " " +
"-Dsonar.cxx.cppcheck.reportPath=" + param.getCppCheckReportPath() + " " +
"-Dsonar.projectBaseDir=" + param.getProjectPath();
@ -194,7 +194,6 @@ public class SonarService {
"-Dsonar.sourceEncoding=utf-8 " +
"-Dsonar.projectKey=" + key + " " +
"-Dsonar.java.binaries=./ " +
"-Dsonar.login=" + sonarToken + " " +
"-Dsonar.projectBaseDir=" + projectPath;
log.info("projectPath:{},key:{}, command: {}", projectPath, key, command);
SystemUtil.executeAndGetExitStatus(command);

@ -8,7 +8,6 @@ import net.educoder.ecsonar.model.TaskInfoDetail;
import net.educoder.ecsonar.model.vo.QualityInspectUserDataVO;
import net.educoder.ecsonar.services.DbOperateService;
import net.educoder.ecsonar.services.SonarService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.tomcat.util.http.fileupload.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -16,11 +15,8 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.function.Function;
/**
@ -45,9 +41,9 @@ public class QualityInspectRunnable implements Runnable {
private SonarService sonarService;
public QualityInspectRunnable(String taskId, String language, String homeworkId,
TaskInfoDetail taskInfoDetail,
QualityInspectUserDataVO userData,
ExecutorService queryResultPool) {
TaskInfoDetail taskInfoDetail,
QualityInspectUserDataVO userData,
ExecutorService queryResultPool) {
this.taskId = taskId;
this.language = language;
this.homeworkId = homeworkId;
@ -59,22 +55,47 @@ public class QualityInspectRunnable implements Runnable {
@Override
public void run() {
String projectName = String.format("%s-%s", homeworkId, userData.getUserId());
String projectName = String.format("%s-%s", homeworkId, userData.getStudentId());
String path = String.format("/tmp/%s/%s/", homeworkId, projectName);
List<Long> codeIds = userData.getCodeIds();
List<Long> shiXunCodeIds = userData.getStudentWorkShixunCodeIds();
boolean constantCFlag = true,constantCPPFlag = true,constantJavaFlag = true, constantPyFlag = true;
for (Long codeId : codeIds) {
File file = new File(path);
try {
FileUtils.forceMkdir(file);
} catch (IOException e) {
}
if(CollectionUtils.isNotEmpty(shiXunCodeIds)){
for (Long codeId : shiXunCodeIds) {
processCodeId(codeId, path, projectName, dbOperateService::queryShiXunCodesById);
GameCodes gameCodes = dbOperateService.queryGameCodesById(codeId);
if(gameCodes == null){
LOGGER.error("projectName:{}, game_codes_id:{}找不到对应的学员代码",projectName, codeId);
continue;
}
}else{
for (Long codeId : codeIds) {
processCodeId(codeId, path, projectName, dbOperateService::queryGameCodesById);
FileUtil.writeString(gameCodes.getCode(), path + gameCodes.getPath(), Charset.forName("UTF-8"));
if (constantCFlag && gameCodes.getPath().toLowerCase().contains(".c")) {
constantCFlag = false;
} else if (constantCPPFlag && gameCodes.getPath().toLowerCase().contains(".cpp")) {
constantCPPFlag = false;
} else if (constantJavaFlag && gameCodes.getPath().toLowerCase().contains(".java")) {
constantJavaFlag = false;
} else if (constantPyFlag && gameCodes.getPath().toLowerCase().contains(".py")) {
constantPyFlag = false;
}
}
// 需要自己判别语言,Java优先
if(!constantJavaFlag){
language = Constant.JAVA;
}else if(!constantPyFlag){
language = Constant.PYTHON;
} else if(!constantCFlag){
language = Constant.C;
}else if(!constantCPPFlag){
language = Constant.CXX;
}
// 写完所有文件开始用sonar进行质量分析
SonarScannerParam param = new SonarScannerParam(projectName, path);
if (Constant.C.equalsIgnoreCase(language) || Constant.CXX.equalsIgnoreCase(language)) {
@ -112,45 +133,4 @@ public class QualityInspectRunnable implements Runnable {
public void setSonarService(SonarService sonarService) {
this.sonarService = sonarService;
}
private void processCodeId(Long codeId, String path, String projectName, Function<Long, GameCodes> queryMethod) {
boolean constantCFlag = true, constantCPPFlag = true, constantJavaFlag = true, constantPyFlag = true;
File file = new File(path);
try {
FileUtils.forceMkdir(file);
} catch (IOException e) {
LOGGER.error("创建目录失败: {}", path, e);
}
GameCodes gameCodes = queryMethod.apply(codeId);
if (gameCodes == null) {
LOGGER.error("projectName:{}, game_codes_id:{} 找不到对应的学员代码", projectName, codeId);
return;
}
Path filePath = Paths.get(path, gameCodes.getPath());
FileUtil.writeString(gameCodes.getCode(), filePath.toString(), Charset.forName("UTF-8"));
String filePathLower = gameCodes.getPath().toLowerCase();
if (constantCFlag && filePathLower.matches(".*\\.c$")) {
constantCFlag = false;
} else if (constantCPPFlag && filePathLower.matches(".*\\.cpp$")) {
constantCPPFlag = false;
} else if (constantJavaFlag && filePathLower.matches(".*\\.java$")) {
constantJavaFlag = false;
} else if (constantPyFlag && filePathLower.matches(".*\\.py$")) {
constantPyFlag = false;
}
// 需要自己判别语言,Java优先
if (!constantJavaFlag) {
language = Constant.JAVA;
} else if (!constantPyFlag) {
language = Constant.PYTHON;
} else if (!constantCFlag) {
language = Constant.C;
} else if (!constantCPPFlag) {
language = Constant.CXX;
}
}
}

@ -6,15 +6,15 @@
spring.datasource.initSize=20
#spring.datasource.master.url=jdbc:postgresql://127.0.0.1:5432/sonar7.7
spring.datasource.master.url=jdbc:postgresql://106.75.25.158:5432/sonar
spring.datasource.master.username=sonar
spring.datasource.master.password=sonar
spring.datasource.master.url=jdbc:postgresql://106.75.223.53:5432/sonarqube10
spring.datasource.master.username=postgres
spring.datasource.master.password=sonarqube
spring.datasource.master.driverClassName=org.postgresql.Driver
#### test ######
spring.datasource.readonly.driverClassName=com.mysql.jdbc.Driver
spring.datasource.readonly.url=jdbc:mysql://testeducoder-public.mysql.polardb.rds.aliyuncs.com:3306/newtesteducoderweb?useSSL=false&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
spring.datasource.readonly.url=jdbc:mysql://rm-bp13v5020p7828r5rso.mysql.rds.aliyuncs.com:3306/preeducoderweb?userSSL=false&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
spring.datasource.readonly.username=testeducoder
spring.datasource.readonly.password=TEST@123
@ -43,11 +43,12 @@ zip.save.path=/tmp/
#excel.template.path=/Users/guange/work/java/ecsonar/src/main/resources/template.xlsx
excel.template.path=template.xlsx
sonar.url=http://127.0.0.1:9000
sonar.url=http://106.75.223.53:9005
#sonar.url=http://117.50.14.123:9000
# token令牌 02c142773360aebeedb4af1b178e20115ef46758
# token令牌
#sonar.token=0253a518e824a976ea2f11aec17938cb0f8c0495
sonar.token=02c142773360aebeedb4af1b178e20115ef46758
# ??token
sonar.token=sqa_6615790f07532bfb2cc180f63808548534f75544
extract.path=/usr/local/bin/unar
#extract.path=/usr/bin/unar
@ -60,4 +61,4 @@ skip.checked=true
server.port=8081
mybatis.mapper-locations=classpath:mapper/*
sonar.host=http://localhost:9000
sonar.host=http://106.75.223.53:9005

@ -5,7 +5,7 @@
<select id="findFileSourceFileUuid" parameterType="java.lang.String" resultType="net.educoder.ecsonar.model.FileSource">
select
id,
uuid,
project_uuid as projectUuid,
file_uuid as fileUuid,
binary_data as binaryData,

@ -8,11 +8,11 @@
select
count(1)
from issues i
inner join rules r on i.rule_id =r.id
inner join projects p on p.uuid =i.component_uuid
inner join rules r on i.rule_uuid =r.uuid
inner join projects p on p.uuid =i.project_uuid
where i.project_uuid = #{projectUuid,jdbcType=VARCHAR}
and i.status='OPEN'
and p.root_uuid =#{projectUuid,jdbcType=VARCHAR} and p.uuid !=#{projectUuid,jdbcType=VARCHAR} and p."scope" ='FIL'
and p.uuid =#{projectUuid,jdbcType=VARCHAR}
<if test="issueType != null">
and i.issue_type=#{issueType,jdbcType=INTEGER}
</if>
@ -24,13 +24,16 @@
<select id="getPageIssues" resultType="net.educoder.ecsonar.model.Issues">
select
i.id,i.kee,i.rule_id ruleId,i.severity,i.status,i.project_uuid projectUuid,i.issue_type issueType,i.locations,i.line lines,r.name,r.description,r.language,p.path,p.uuid,i.message
i.kee id,i.rule_uuid ruleId,i.severity,i.status,i.project_uuid projectUuid,i.issue_type issueType,i.locations,i.line lines,
r.name,c.path,c.uuid,r.language,i.message
from issues i
inner join rules r on i.rule_id =r.id
inner join projects p on p.uuid =i.component_uuid
inner join rules r on i.rule_uuid =r.uuid
inner join projects p on p.uuid =i.project_uuid
inner join components c on c.uuid =i.component_uuid
where i.project_uuid = #{projectUuid,jdbcType=VARCHAR}
and i.status='OPEN'
and p.root_uuid =#{projectUuid,jdbcType=VARCHAR} and p.uuid !=#{projectUuid,jdbcType=VARCHAR} and p."scope" ='FIL'
and p.uuid =#{projectUuid,jdbcType=VARCHAR}
and c.uuid !=#{projectUuid,jdbcType=VARCHAR} and c.branch_uuid =#{projectUuid,jdbcType=VARCHAR} and c."scope" ='FIL'
<if test="issueType != null">
and i.issue_type=#{issueType,jdbcType=INTEGER}
</if>
@ -47,12 +50,13 @@
(select count(1) from issues i where project_uuid =#{projectUuid} and issue_type=#{issueType} and severity = 'MINOR' and status='OPEN') minor,
(select count(1) from issues i where project_uuid =#{projectUuid} and issue_type=#{issueType} and severity = 'BLOCKER' and status='OPEN') blocker,
(select count(1) from issues i where project_uuid =#{projectUuid} and issue_type=#{issueType} and severity = 'CRITICAL' and status='OPEN') critical,
(select text_value from project_measures i where component_uuid =#{projectUuid} and metric_id = #{metricId} order by id desc limit 1) levelStr
(select text_value from project_measures i where component_uuid =#{projectUuid} and metric_uuid = (select uuid from metrics where name=#{metricName}) limit 1) levelStr
</select>
<select id="queryById" parameterType="java.lang.Long" resultType="net.educoder.ecsonar.model.Issues">
select i.id,i.kee,i.rule_id ruleId,i.severity,i.status,i.project_uuid projectUuid,i.issue_type issueType,i.locations,i.line lines,i.message from issues i where id=#{issueId}
<select id="queryById" parameterType="java.lang.String" resultType="net.educoder.ecsonar.model.Issues">
select i.kee id,i.rule_uuid ruleId,i.severity,i.status,i.project_uuid projectUuid,i.issue_type issueType,i.locations,i.line lines,i.message
from issues i where kee=#{issueId}
</select>

@ -3,16 +3,18 @@
<mapper namespace="net.educoder.ecsonar.dao.ProjectDao">
<select id="findRuleById" parameterType="java.lang.Integer" resultType="net.educoder.ecsonar.model.Rule">
<select id="findRuleById" parameterType="java.lang.String" resultType="net.educoder.ecsonar.model.Rule">
select
id,
name,
description,
language,
def_remediation_base_effort defRemediationBaseEffort,
system_tags tags,
created_at createTime
from rules where id=#{id,jdbcType=INTEGER}
r.uuid,
r.name,
r.language,
r.def_remediation_base_effort defRemediationBaseEffort,
r.system_tags tags,
r.created_at createTime,
rds.content description
from rules r
inner join rule_desc_sections rds on r.uuid=rds.rule_uuid
where r.uuid=#{uuid,jdbcType=VARCHAR}
</select>

@ -36,7 +36,7 @@ public class EcsonarApplicationTests {
@Test
public void contextLoads() {
Project demo_maven_webapp = projectDao.findByName("demo Maven Webapp");
System.out.println(demo_maven_webapp.getProject_uuid());
System.out.println(demo_maven_webapp.getUuid());
}
@Test

Loading…
Cancel
Save