Compare commits

...

4 Commits

Author SHA1 Message Date
weishao 00c214a473 rm \ 2023-03-09 19:13:18 +08:00
youys 45a2f5be9b 添加注释 2023-03-09 18:10:53 +08:00
youys c657b31416 缺陷>代码详情接口v2版本 2023-03-09 17:35:00 +08:00
youys 7e387eb37a 缺陷>代码详情接口v2版本 2023-03-09 17:34:12 +08:00
7 changed files with 129 additions and 7 deletions

View File

@ -181,6 +181,8 @@ public class ProjectController {
return R.success(projectBugCenterDTOPageInfo);
}
/**
* 缺陷列表导出
*
@ -211,4 +213,18 @@ public class ProjectController {
return R.success(projectBugCenterCodeDetailDTO);
}
/**
* 缺陷中心> 代码详情
* V2版本
*
* @param projectId
* @return
*/
@GetMapping("/projects/v2/{projectId}/bug/center/codeDetail")
public R<ProjectBugCenterCodeDetailV2DTO> projectBugCenterCodeDetailV2(@PathVariable Long projectId, @RequestParam("ruleId") Integer id) {
ProjectBugCenterCodeDetailV2DTO codeDetailV2DTO = projectService.projectBugCenterCodeDetailV2(projectId, id);
return R.success(codeDetailV2DTO);
}
}

View File

@ -1,6 +1,8 @@
package net.educoder.quality.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author: youys
@ -8,6 +10,8 @@ import lombok.Data;
* @Description:
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class FileSourceDTO {
private Integer rowNumber;

View File

@ -0,0 +1,44 @@
package net.educoder.quality.dto;
import lombok.Data;
import java.util.List;
/**
* @Author: youys
* @Date: 2023/3/9
* @Description: 缺陷中心>查看详情 v2版本
*/
@Data
public class ProjectBugCenterCodeDetailV2DTO {
private String filePath;
/**
* 代码行号
*/
private Integer line;
/**
* 缺陷名称
*/
private String bugName;
/**
* 缺陷描述
*/
private String description;
/**
* 正确代码示例
*/
private String example;
/**
* 错误代码示例
*/
private String errorExample;
/**
* 代码所属错误分类
*/
private String parentBugCatalog;
/**
* 代码
*/
private List<FileSourceDTO> codes;
}

View File

@ -146,6 +146,15 @@ public interface ProjectService {
*/
ProjectBugCenterCodeDetailDTO projectBugCenterCodeDetail(Long projectId, ProjectBugCenterCodeDetailVO centerCodeDetailVO);
/**
* 获取缺陷中心代码详情 V2版本
* @param projectId
* @param id
* @return
*/
ProjectBugCenterCodeDetailV2DTO projectBugCenterCodeDetailV2(Long projectId, Integer id);
/**
* 许可证总计
*
@ -258,4 +267,5 @@ public interface ProjectService {
* @return
*/
List<ProjectVulnerabilityListDTO> projectVulnerabilityExport(Long projectId, CommonVO commonVO);
}

View File

@ -1,5 +1,12 @@
package net.educoder.quality.service;
import net.educoder.quality.entity.mysql.SastAnalysisDetail;
public interface SastService {
void analysis(Long projectId, String taskId);
SastAnalysisDetail findById(Long id);
}

View File

@ -27,6 +27,7 @@ import net.educoder.quality.service.postgres.PgProjectsService;
import net.educoder.quality.task.SonarDetectionRunnable;
import net.educoder.quality.vo.*;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -37,6 +38,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.*;
/**
@ -455,9 +458,9 @@ public class ProjectServiceImpl implements ProjectService {
BugResultDTO bug = pgProjectsService.getBug(projectName);
PgProjectMeasures projectMeasures = pgProjectsService.getProjectMeasureByMetricId(projectName, 1);
if(projectMeasures != null) {
if (projectMeasures != null) {
detectResult.setCodeNumber(projectMeasures.getValue().intValue());
}else{
} else {
detectResult.setCodeNumber(0);
}
@ -602,6 +605,40 @@ public class ProjectServiceImpl implements ProjectService {
return projectBugCenterCodeDetailDTO;
}
@Override
public ProjectBugCenterCodeDetailV2DTO projectBugCenterCodeDetailV2(Long projectId, Integer id){
SastAnalysisDetail sastAnalysisDetail = sastService.findById(Long.valueOf(id));
if(sastAnalysisDetail == null){
throw new BusinessException(ErrorCodeEnum.PARAM_ERROR);
}
ProjectBugCenterCodeDetailV2DTO codeDetailV2DTO = new ProjectBugCenterCodeDetailV2DTO();
BeanUtils.copyProperties(sastAnalysisDetail, codeDetailV2DTO);
String filePath = sastAnalysisDetail.getFilePath();
File file = new File(filePath);
if(file.exists()){
try {
List<String> codeStr = FileUtils.readLines(file, "UTF-8");
List<FileSourceDTO> codes = new ArrayList();
for (int i = 0; i < codeStr.size(); i++) {
codes.add(new FileSourceDTO(i+1, codeStr.get(i)));
}
codeDetailV2DTO.setCodes(codes);
} catch (IOException e) {
log.error("projectBugCenterCodeDetailV2 读文件异常", e);
codeDetailV2DTO.setCodes(new ArrayList<>());
}
}else{
codeDetailV2DTO.setCodes(new ArrayList<>());
}
return codeDetailV2DTO;
}
@Override
public LicenceOverviewDTO projectLicenceOverview(Long projectId) {
//TODO:暂用假数据
@ -862,7 +899,7 @@ public class ProjectServiceImpl implements ProjectService {
sonarScannerParam.setLanguage(contains ? QualityConstants.C : QualityConstants.OTHER);
boolean useNet = detectionTemplate.getLanguage().toLowerCase().contains(QualityConstants.NET);
if (useNet){
if (useNet) {
sonarScannerParam.setLanguage(QualityConstants.NET);
}
sonarScannerParam.setWorkspace(workspace);
@ -947,17 +984,17 @@ public class ProjectServiceImpl implements ProjectService {
/**
* 处理giturl
* @param gitUrl http://118.31.13.117:64300/wangwei/jwebssh/analysis Or http://118.31.13.117:64300/wangwei/jwebssh/analysis/
*
* @param gitUrl http://118.31.13.117:64300/wangwei/jwebssh/analysis Or http://118.31.13.117:64300/wangwei/jwebssh/analysis/
* @return
*/
private String processGitUrl(String gitUrl){
private String processGitUrl(String gitUrl) {
String router = gitUrl.substring(gitUrl.lastIndexOf("/"));
if ("/".equals(router) || StringUtils.isBlank(router)) {
String newGitUrl = gitUrl.substring(0, gitUrl.length() - 1);
router = newGitUrl.substring(newGitUrl.lastIndexOf("/"));
return newGitUrl.replaceAll(router,"") + ".git";
return newGitUrl.replaceAll(router, "") + ".git";
}
return gitUrl.replaceAll(router,"") + ".git";
return gitUrl.replaceAll(router, "") + ".git";
}
}

View File

@ -176,5 +176,9 @@ public class SastServiceImpl implements SastService {
return sastBugDTOS;
}
@Override
public SastAnalysisDetail findById(Long id) {
return sastAnalysisDetailMapper.selectByPrimaryKey(id);
}
}