parent
3bb714f796
commit
3487d0739f
@ -0,0 +1,54 @@
|
||||
package net.educoder.ecsonar.config;
|
||||
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/18
|
||||
* @Description:
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfiguration implements WebMvcConfigurer {
|
||||
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
|
||||
|
||||
List<MediaType> supportedMediaTypes = new ArrayList<>(20);
|
||||
supportedMediaTypes.add(MediaType.APPLICATION_JSON);
|
||||
supportedMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
|
||||
supportedMediaTypes.add(MediaType.APPLICATION_ATOM_XML);
|
||||
supportedMediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
supportedMediaTypes.add(MediaType.APPLICATION_OCTET_STREAM);
|
||||
supportedMediaTypes.add(MediaType.APPLICATION_PDF);
|
||||
supportedMediaTypes.add(MediaType.APPLICATION_RSS_XML);
|
||||
supportedMediaTypes.add(MediaType.APPLICATION_XHTML_XML);
|
||||
supportedMediaTypes.add(MediaType.APPLICATION_XML);
|
||||
supportedMediaTypes.add(MediaType.IMAGE_GIF);
|
||||
supportedMediaTypes.add(MediaType.IMAGE_JPEG);
|
||||
supportedMediaTypes.add(MediaType.IMAGE_PNG);
|
||||
supportedMediaTypes.add(MediaType.TEXT_EVENT_STREAM);
|
||||
supportedMediaTypes.add(MediaType.TEXT_HTML);
|
||||
supportedMediaTypes.add(MediaType.TEXT_MARKDOWN);
|
||||
supportedMediaTypes.add(MediaType.TEXT_PLAIN);
|
||||
supportedMediaTypes.add(MediaType.TEXT_XML);
|
||||
fastJsonHttpMessageConverter.setSupportedMediaTypes(supportedMediaTypes);
|
||||
|
||||
// FastJsonConfig fastJsonConfig = new FastJsonConfig();
|
||||
// fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteMapNullValue);
|
||||
//
|
||||
// fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
|
||||
converters.add(0,fastJsonHttpMessageConverter);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package net.educoder.ecsonar.constant;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/18
|
||||
* @Description:
|
||||
*/
|
||||
public class Constant {
|
||||
|
||||
|
||||
public static final String JAVA = "JAVA";
|
||||
public static final String C = "C";
|
||||
public static final String CXX = "C++";
|
||||
public static final String PYTHON = "PYTHON";
|
||||
|
||||
public static final List<String> language = Arrays.asList(JAVA, C, CXX, PYTHON);
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package net.educoder.ecsonar.dao;
|
||||
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/18
|
||||
* @Description:
|
||||
*/
|
||||
public interface CeActivityDao {
|
||||
|
||||
|
||||
@Select("select status from ce_activity where component_uuid=#{projectId} and is_last=true")
|
||||
String queryActivityStatus(String projectId);
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package net.educoder.ecsonar.dao;
|
||||
|
||||
import net.educoder.ecsonar.model.GameCodes;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2021/12/31
|
||||
* @Description:
|
||||
*/
|
||||
public interface GameCodesDao {
|
||||
|
||||
@Select("select new_code code,path from game_codes where id=#{id}")
|
||||
GameCodes queryOriginalCodeById(Long id);
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package net.educoder.ecsonar.dao;
|
||||
|
||||
import net.educoder.ecsonar.model.TaskInfo;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/18
|
||||
* @Description:
|
||||
*/
|
||||
public interface TaskInfoDao {
|
||||
|
||||
@Insert("insert into task_info(id,language,homework_id,people_number) values(#{id},#{language},#{homeworkId},#{peopleNumber} )")
|
||||
void insertTaskInfo(TaskInfo taskInfo);
|
||||
|
||||
|
||||
@Update("update task_info set status=#{status},update_time=current_timestamp where id=#{id}")
|
||||
void updateTaskInfoStatus(@Param("id") String id, @Param("status") Integer status);
|
||||
|
||||
|
||||
@Select("select id,homework_id homeworkId,status,people_number peopleNumber,create_time createTime,update_time updateTime from task_info where id=#{id}")
|
||||
TaskInfo selectById(String id);
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package net.educoder.ecsonar.dao;
|
||||
|
||||
import net.educoder.ecsonar.model.TaskInfoDetail;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/18
|
||||
* @Description:
|
||||
*/
|
||||
public interface TaskInfoDetailDao {
|
||||
|
||||
/**
|
||||
* 插入数据
|
||||
*
|
||||
* @param taskInfoDetail
|
||||
*/
|
||||
@Insert("insert into task_info_detail(id,task_id,project_name,student_id,name,code_ids) values(#{id},#{taskId},#{projectName},#{studentId},#{name},#{codeIds})")
|
||||
void insertTaskInfoDetail(TaskInfoDetail taskInfoDetail);
|
||||
|
||||
/**
|
||||
* 更新状态
|
||||
*
|
||||
* @param id
|
||||
* @param status
|
||||
*/
|
||||
@Update("update task_info_detail set status=#{status},update_time=current_timestamp where id=#{id}")
|
||||
void updateTaskInfoDetailStatus(@Param("id") String id, @Param("status") Integer status);
|
||||
|
||||
/**
|
||||
* 查询taskId执行完的sonar任务数
|
||||
*
|
||||
* @param taskId
|
||||
* @return
|
||||
*/
|
||||
@Select("select count(1) from task_info_detail where task_id=#{taskId} and status != 0")
|
||||
Integer selectCountByTaskId(@Param("taskId") String taskId);
|
||||
|
||||
/**
|
||||
* 根据id查TaskInfoDetail
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Select("select id,task_id taskId,project_name projectName,student_id studentId,name,code_ids codeIds,status,create_time createTime,update_time updateTime from task_info_detail where id=#{id}")
|
||||
TaskInfoDetail selectById(String id);
|
||||
|
||||
/**
|
||||
* count
|
||||
*
|
||||
* @param taskId
|
||||
* @param pageSize
|
||||
* @param offset
|
||||
* @return
|
||||
*/
|
||||
@Select("select count(1) from task_info_detail where task_id=#{taskId} limit #{pageSize} offset #{offset}")
|
||||
Integer selectTaskInfoDetailPageCount(@Param("taskId") String taskId, @Param("pageSize") Integer pageSize, @Param("offset") Integer offset);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param taskId
|
||||
* @param pageSize
|
||||
* @param position
|
||||
* @return
|
||||
*/
|
||||
@Select("select id,task_id taskId,project_name projectName,student_id studentId,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);
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package net.educoder.ecsonar.exception;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/18
|
||||
* @Description:
|
||||
*/
|
||||
public class BusinessException extends RuntimeException{
|
||||
private Integer code;
|
||||
private String message;
|
||||
|
||||
public BusinessException(Integer code, String message){
|
||||
super(message);
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package net.educoder.ecsonar.model;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/18
|
||||
* @Description:
|
||||
*/
|
||||
public class GameCodes {
|
||||
|
||||
private String code;
|
||||
private String path;
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package net.educoder.ecsonar.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/18
|
||||
* @Description:
|
||||
*/
|
||||
public class RollPage<T> {
|
||||
|
||||
private static final Integer DEFAULT_PAGE_SIZE = 50;
|
||||
|
||||
private Integer pageSize;
|
||||
|
||||
private Integer currentPage = 1;
|
||||
|
||||
private Integer pageSum = 0;
|
||||
|
||||
private Integer recordSum = 0;
|
||||
|
||||
private List<T> recordList;
|
||||
|
||||
public RollPage() {
|
||||
pageSize = DEFAULT_PAGE_SIZE;
|
||||
}
|
||||
|
||||
public Integer getPageSum() {
|
||||
if (this.pageSum == 0) {
|
||||
this.pageSum = (int) Math.ceil(this.recordSum / this.pageSize) + ((this.recordSum % this.pageSize == 0) ? 0 : 1);
|
||||
}
|
||||
return pageSum;
|
||||
}
|
||||
|
||||
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public Integer getCurrentPage() {
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
public void setCurrentPage(Integer currentPage) {
|
||||
this.currentPage = currentPage;
|
||||
}
|
||||
|
||||
public void setPageSum(Integer pageSum) {
|
||||
this.pageSum = pageSum;
|
||||
}
|
||||
|
||||
public Integer getRecordSum() {
|
||||
return recordSum;
|
||||
}
|
||||
|
||||
public void setRecordSum(Integer recordSum) {
|
||||
this.recordSum = recordSum;
|
||||
}
|
||||
|
||||
public List<T> getRecordList() {
|
||||
return recordList;
|
||||
}
|
||||
|
||||
public void setRecordList(List<T> recordList) {
|
||||
this.recordList = recordList;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package net.educoder.ecsonar.model;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/18
|
||||
* @Description:
|
||||
*/
|
||||
public class SonarScannerParam {
|
||||
|
||||
/**
|
||||
* sonar项目名
|
||||
*/
|
||||
private String projectKey;
|
||||
|
||||
/**
|
||||
* 项目文件路径
|
||||
*/
|
||||
private String projectPath;
|
||||
|
||||
/**
|
||||
* c/++ 需要设置cppcheck文件路径
|
||||
*/
|
||||
private String cppCheckReportPath;
|
||||
|
||||
public SonarScannerParam(String projectKey, String projectPath) {
|
||||
this.projectKey = projectKey;
|
||||
this.projectPath = projectPath;
|
||||
}
|
||||
|
||||
public String getProjectKey() {
|
||||
return projectKey;
|
||||
}
|
||||
|
||||
public void setProjectKey(String projectKey) {
|
||||
this.projectKey = projectKey;
|
||||
}
|
||||
|
||||
public String getProjectPath() {
|
||||
return projectPath;
|
||||
}
|
||||
|
||||
public void setProjectPath(String projectPath) {
|
||||
this.projectPath = projectPath;
|
||||
}
|
||||
|
||||
public String getCppCheckReportPath() {
|
||||
return cppCheckReportPath;
|
||||
}
|
||||
|
||||
public void setCppCheckReportPath(String cppCheckReportPath) {
|
||||
this.cppCheckReportPath = cppCheckReportPath;
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package net.educoder.ecsonar.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/18
|
||||
* @Description:
|
||||
*/
|
||||
public class TaskInfoDetail {
|
||||
|
||||
private String id;
|
||||
private String taskId;
|
||||
private String projectName;
|
||||
private String studentId;
|
||||
private String name;
|
||||
private String codeIds;
|
||||
/**
|
||||
* 0处理中 1处理成功 -1 处理失败
|
||||
*/
|
||||
private Integer status;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTaskId() {
|
||||
return taskId;
|
||||
}
|
||||
|
||||
public void setTaskId(String taskId) {
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
public String getProjectName() {
|
||||
return projectName;
|
||||
}
|
||||
|
||||
public void setProjectName(String projectName) {
|
||||
this.projectName = projectName;
|
||||
}
|
||||
|
||||
public String getStudentId() {
|
||||
return studentId;
|
||||
}
|
||||
|
||||
public void setStudentId(String studentId) {
|
||||
this.studentId = studentId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getCodeIds() {
|
||||
return codeIds;
|
||||
}
|
||||
|
||||
public void setCodeIds(String codeIds) {
|
||||
this.codeIds = codeIds;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public Date getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package net.educoder.ecsonar.model.api;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/18
|
||||
* @Description:
|
||||
*/
|
||||
public class QualityInspect {
|
||||
|
||||
private String taskId;
|
||||
|
||||
public QualityInspect(String taskId){
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
public String getTaskId() {
|
||||
return taskId;
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package net.educoder.ecsonar.model.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/17
|
||||
* @Description: 检测结果
|
||||
*/
|
||||
public class QualityInspectResult {
|
||||
|
||||
/**
|
||||
* 任务id
|
||||
*/
|
||||
private String taskId;
|
||||
|
||||
|
||||
/**
|
||||
* 质量检测数据
|
||||
*/
|
||||
private List<QualityInspectResultData> dataList;
|
||||
|
||||
|
||||
|
||||
public String getTaskId() {
|
||||
return taskId;
|
||||
}
|
||||
|
||||
public void setTaskId(String taskId) {
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<QualityInspectResultData> getDataList() {
|
||||
return dataList;
|
||||
}
|
||||
|
||||
public void setDataList(List<QualityInspectResultData> dataList) {
|
||||
this.dataList = dataList;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package net.educoder.ecsonar.services;
|
||||
|
||||
import net.educoder.ecsonar.config.DynamicDataSourceConfig;
|
||||
import net.educoder.ecsonar.config.DynamicDataSourceContextHolder;
|
||||
import net.educoder.ecsonar.dao.CeActivityDao;
|
||||
import net.educoder.ecsonar.dao.GameCodesDao;
|
||||
import net.educoder.ecsonar.dao.ProjectDao;
|
||||
import net.educoder.ecsonar.dao.TaskInfoDetailDao;
|
||||
import net.educoder.ecsonar.model.GameCodes;
|
||||
import net.educoder.ecsonar.model.Project;
|
||||
import net.educoder.ecsonar.model.TaskInfoDetail;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2021/12/31
|
||||
* @Description:
|
||||
*/
|
||||
@Service
|
||||
public class DbOperateService {
|
||||
|
||||
@Autowired
|
||||
private GameCodesDao gameCodesDao;
|
||||
|
||||
|
||||
@Autowired
|
||||
private CeActivityDao ceActivityDao;
|
||||
|
||||
@Autowired
|
||||
private ProjectDao projectDao;
|
||||
|
||||
@Autowired
|
||||
private TaskInfoDetailDao taskInfoDetailDao;
|
||||
|
||||
/**
|
||||
* 根据id查询用户传的code
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public GameCodes queryGameCodesById(Long id){
|
||||
DynamicDataSourceContextHolder.setContextKey(DynamicDataSourceConfig.READONLY);
|
||||
GameCodes gameCode = gameCodesDao.queryOriginalCodeById(id);
|
||||
DynamicDataSourceContextHolder.removeContextKey();
|
||||
return gameCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询任务执行状态
|
||||
* @param projectName
|
||||
* @return
|
||||
*/
|
||||
public String queryCeActivityStatus(String projectName){
|
||||
Project project = projectDao.findByName(projectName);
|
||||
if(project == null ){
|
||||
return null;
|
||||
}
|
||||
return ceActivityDao.queryActivityStatus(project.getProject_uuid());
|
||||
}
|
||||
|
||||
|
||||
public void updateTaskInfoDetail(String id, Integer status){
|
||||
taskInfoDetailDao.updateTaskInfoDetailStatus(id, status);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package net.educoder.ecsonar.task;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import net.educoder.ecsonar.constant.Constant;
|
||||
import net.educoder.ecsonar.model.GameCodes;
|
||||
import net.educoder.ecsonar.model.SonarScannerParam;
|
||||
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.tomcat.util.http.fileupload.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/18
|
||||
* @Description: 质量检测任务
|
||||
*/
|
||||
public class QualityInspectRunnable implements Runnable {
|
||||
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(QualityInspectRunnable.class);
|
||||
|
||||
private String taskId;
|
||||
public String language;
|
||||
public String homeworkId;
|
||||
private QualityInspectUserDataVO userData;
|
||||
|
||||
private ExecutorService queryResultPool;
|
||||
|
||||
private TaskInfoDetail taskInfoDetail;
|
||||
private DbOperateService dbOperateService;
|
||||
private SonarService sonarService;
|
||||
|
||||
public QualityInspectRunnable(String taskId, String language, String homeworkId,
|
||||
TaskInfoDetail taskInfoDetail,
|
||||
QualityInspectUserDataVO userData,
|
||||
ExecutorService queryResultPool) {
|
||||
this.taskId = taskId;
|
||||
this.language = language;
|
||||
this.homeworkId = homeworkId;
|
||||
this.taskInfoDetail = taskInfoDetail;
|
||||
this.userData = userData;
|
||||
this.queryResultPool = queryResultPool;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String projectName = String.format("%s-%s", homeworkId, userData.getStudentId());
|
||||
String path = String.format("/tmp/%s/%s/", homeworkId, projectName);
|
||||
|
||||
List<Long> codeIds = userData.getCodeIds();
|
||||
for (Long codeId : codeIds) {
|
||||
File file = new File(path);
|
||||
try {
|
||||
FileUtils.forceMkdir(file);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
|
||||
GameCodes gameCodes = dbOperateService.queryGameCodesById(codeId);
|
||||
FileUtil.writeString(gameCodes.getCode(), path + gameCodes.getPath(), Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
// 写完所有文件开始用sonar进行质量分析
|
||||
SonarScannerParam param = new SonarScannerParam(projectName, path);
|
||||
if (Constant.C.equalsIgnoreCase(language) || Constant.CXX.equalsIgnoreCase(language)) {
|
||||
String resultPath = String.format("/tmp/%s", taskId);
|
||||
File f = new File(resultPath);
|
||||
if (!f.exists()) {
|
||||
f.mkdirs();
|
||||
}
|
||||
param.setCppCheckReportPath(resultPath + String.format("/%s-result.xml", projectName));
|
||||
|
||||
}
|
||||
// 调用sonar服务
|
||||
LOGGER.info("projectName:{}, detailId:{} 开始调用sonar分析,语言:{}", projectName,taskInfoDetail.getId(),language);
|
||||
sonarService.sonar(language, param);
|
||||
|
||||
// 提交一个查结果的任务
|
||||
SonarQueryResultRunnable queryResultRunnable = new SonarQueryResultRunnable(projectName, taskInfoDetail.getId(), dbOperateService);
|
||||
LOGGER.info("projectName:{}, detailId:{} 提交了查询结果的任务", projectName,taskInfoDetail.getId());
|
||||
queryResultPool.execute(queryResultRunnable);
|
||||
}
|
||||
|
||||
|
||||
public DbOperateService getDbOperateService() {
|
||||
return dbOperateService;
|
||||
}
|
||||
|
||||
public void setDbOperateService(DbOperateService dbOperateService) {
|
||||
this.dbOperateService = dbOperateService;
|
||||
}
|
||||
|
||||
public SonarService getSonarService() {
|
||||
return sonarService;
|
||||
}
|
||||
|
||||
public void setSonarService(SonarService sonarService) {
|
||||
this.sonarService = sonarService;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package net.educoder.ecsonar.task;
|
||||
|
||||
import net.educoder.ecsonar.services.DbOperateService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/18
|
||||
* @Description:
|
||||
*/
|
||||
public class SonarQueryResultRunnable implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SonarQueryResultRunnable.class);
|
||||
|
||||
private static final String SUCCESS = "SUCCESS";
|
||||
|
||||
private String projectName;
|
||||
private String detailId;
|
||||
private DbOperateService dbOperateService;
|
||||
|
||||
public SonarQueryResultRunnable(String projectName, String detailId, DbOperateService dbOperateService) {
|
||||
this.projectName = projectName;
|
||||
this.detailId = detailId;
|
||||
this.dbOperateService = dbOperateService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
|
||||
String status;
|
||||
while((status = dbOperateService.queryCeActivityStatus(projectName)) == null){
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {}
|
||||
LOGGER.info("detailId:[{}],sonar还未执行完", detailId);
|
||||
}
|
||||
// 查询
|
||||
LOGGER.info("detailId:[{}], 查询sonar执行状态[{}]", detailId, status);
|
||||
// 更新状态
|
||||
dbOperateService.updateTaskInfoDetail(detailId, SUCCESS.equals(status) ? 1 : -1);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in new issue