Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature code path #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sql/coverage_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ CREATE TABLE `diff_deploy_info` (
KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COMMENT='服务部署地址';

ALTER TABLE `diff_coverage_report` ADD COLUMN `code_path` varchar(500) NOT NULL DEFAULT '';


Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public class CoverBaseRequest {
*/
private String subModule;

/**
* codePath为相对目录,表示从代码库根目录到pom.xml的相对路径,如果为空,则代表pom.xml在根目录下
*/
private String codePath;

/**
* 1、全量;2、增量
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ public class CoverageReportEntity {
private String reportFile;
private Integer from;
private String logFile = "";
private String nowLocalCodePath = "";
private String baseLocalCodePath = "";

}
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public void cloneAndCompileCode(CoverageReportEntity coverageReport) {
}
DeployInfoEntity deployInfo = new DeployInfoEntity();
deployInfo.setUuid(coverageReport.getUuid());
deployInfo.setCodePath(coverageReport.getNowLocalPath());
deployInfo.setCodePath(coverageReport.getNowLocalCodePath());
String pomPath = deployInfo.getCodePath() + "/pom.xml";
ArrayList<String> moduleList = MavenModuleUtil.getValidModules(pomPath);
StringBuilder moduleNames = new StringBuilder("");
Expand Down Expand Up @@ -341,7 +341,7 @@ public void calculateEnvCov(CoverageReportEntity coverageReport) {
}

try {
int exitCode = CmdExecutor.executeCmd(new String[]{"cd " + coverageReport.getNowLocalPath() + "&&java -jar " +
int exitCode = CmdExecutor.executeCmd(new String[]{"cd " + coverageReport.getNowLocalCodePath() + "&&java -jar " +
JACOCO_PATH + " dump --address " + deployInfoEntity.getAddress() + " --port " +
deployInfoEntity.getPort() + " --destfile ./jacoco.exec"}, CMD_TIMEOUT);

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/xiaoju/basetech/util/CodeCloneExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.util.StringUtil;

import java.io.File;

import static com.xiaoju.basetech.util.Constants.CODE_ROOT;

import org.springframework.util.StringUtils;

/**
* @description:
Expand All @@ -36,8 +37,13 @@ public void cloneCode(CoverageReportEntity coverageReport) {
coverageReport.setLogFile(logFile);
try {
String uuid = coverageReport.getUuid();
String nowLocalPath = CODE_ROOT + uuid + "/" + coverageReport.getNowVersion().replace("/", "_");
String nowLocalPath = CODE_ROOT + uuid + "/" +
coverageReport.getNowVersion().replace("/", "_");
coverageReport.setNowLocalPath(nowLocalPath);
String codePath=coverageReport.getCodePath();
coverageReport.setNowLocalCodePath( (StringUtils.isEmpty(coverageReport.getEnvType())
? nowLocalPath:nowLocalPath+"/"+codePath) );
// suppose pom.xml is not in project root path
if (new File(CODE_ROOT + uuid + "/").exists()) {
FileUtil.cleanDir(CODE_ROOT + uuid + "/");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class CodeCompilerExecutor {

public void compileCode(CoverageReportEntity coverageReport) {
String logFile = coverageReport.getLogFile().replace(LocalIpUtils.getTomcatBaseUrl()+"logs/", LOG_PATH);
String[] compileCmd = new String[]{"cd " + coverageReport.getNowLocalPath() + "&&mvn clean compile " +
String[] compileCmd = new String[]{"cd " + coverageReport.getNowLocalCodePath() + "&&mvn clean compile " +
(StringUtils.isEmpty(coverageReport.getEnvType()) ? "" : "-P=" + coverageReport.getEnvType()) + ">>" + logFile};
try {
int exitCode = CmdExecutor.executeCmd(compileCmd, 600000L);
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/xiaoju/basetech/util/MavenModuleUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ public class MavenModuleUtil {

public void addMavenModule(CoverageReportEntity coverageReport) {
try {
String pomPath = coverageReport.getNowLocalPath() + "/pom.xml";
String pomPath = coverageReport.getNowLocalCodePath() + "/pom.xml";
File pomFile = new File(pomPath);
if (!pomFile.exists()) {
coverageReport.setRequestStatus(Constants.JobStatus.FAILADDMODULE.val());
return;
}
// 添加lombok配置
File lombokConfig = new File(coverageReport.getNowLocalPath() + "/lombok.config");
File lombokConfig = new File(coverageReport.getNowLocalCodePath() + "/lombok.config");
FileWriter lombokWriter = new FileWriter(lombokConfig);
lombokWriter.write("lombok.addLombokGeneratedAnnotation = true");
lombokWriter.flush();
lombokWriter.close();
ArrayList<String> list = getChildPomsPath(pomPath);
if (list.size() <= 1) {
coverageReport.setReportFile(coverageReport.getNowLocalPath() + "/target/site/jacoco/index.html");
coverageReport.setReportFile(coverageReport.getNowLocalCodePath() + "/target/site/jacoco/index.html");
coverageReport.setRequestStatus(Constants.JobStatus.ADDMODULE_DONE.val());
return;
}
Expand All @@ -50,7 +50,7 @@ public void addMavenModule(CoverageReportEntity coverageReport) {
String str = dependencyStr(pomPath, moduleInfo, denpBuilder).toString();
if (StringUtils.isEmpty(str)) {
coverageReport.setRequestStatus(Constants.JobStatus.ADDMODULE_DONE.val());
coverageReport.setReportFile(coverageReport.getNowLocalPath() + "/target/site/jacoco/index.html");
coverageReport.setReportFile(coverageReport.getNowLocalCodePath() + "/target/site/jacoco/index.html");
return;
}
//在父pom中写入jacocomodule
Expand Down Expand Up @@ -102,17 +102,17 @@ public void addMavenModule(CoverageReportEntity coverageReport) {
" </plugins>\n" +
" </build>\n" +
"</project>");
File coverageModule = new File(coverageReport.getNowLocalPath() + "/jacocomodule");
File coverageModule = new File(coverageReport.getNowLocalCodePath() + "/jacocomodule");
if (!coverageModule.exists()) {
coverageModule.mkdir();
File coveragePomFile = new File(coverageReport.getNowLocalPath() + "/jacocomodule/pom.xml");
File coveragePomFile = new File(coverageReport.getNowLocalCodePath() + "/jacocomodule/pom.xml");
if (!coveragePomFile.exists()) {
coveragePomFile.createNewFile();
FileWriter cwriter = new FileWriter(coveragePomFile);
cwriter.write(builder.toString());
cwriter.flush();
cwriter.close();
coverageReport.setReportFile(coverageReport.getNowLocalPath() + "/jacocomodule/target/site/jacoco-aggregate/index.html");
coverageReport.setReportFile(coverageReport.getNowLocalCodePath() + "/jacocomodule/target/site/jacoco-aggregate/index.html");
coverageReport.setRequestStatus(Constants.JobStatus.ADDMODULE_DONE.val());
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/xiaoju/basetech/util/UnitTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class UnitTester {

public void executeUnitTest(CoverageReportEntity coverageReport) {
long startTime = System.currentTimeMillis();
String unittestCmd = "cd " + coverageReport.getNowLocalPath() + "&&mvn clean";
String unittestCmd = "cd " + coverageReport.getNowLocalCodePath() + "&&mvn clean";
if (coverageReport.getEnvType() != null && !coverageReport.getEnvType().equals("")) {
unittestCmd = unittestCmd + " -P=" + coverageReport.getEnvType();
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/mapper/CoverageReportDao.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<result column="update_time" property="updateTime"/>
<result column="from" property="from"/>
<result column="log_file" property="logFile"/>

<result column="code_path" property="codePath"/>
</resultMap>

<select id="queryCoverageReportByUuid" parameterType="java.lang.String" resultMap="coverageReportEntity">
Expand Down Expand Up @@ -55,6 +55,7 @@
`now_version`,
`now_local_path` ,
`base_local_path`,
`code_path`,
`from`
)VALUES (
#{coverageReportEntity.uuid},
Expand All @@ -67,6 +68,7 @@
#{coverageReportEntity.nowVersion},
#{coverageReportEntity.nowLocalPath},
#{coverageReportEntity.baseLocalPath},
#{coverageReportEntity.codePath},
#{coverageReportEntity.from}
)
</insert>
Expand Down