|
|
@@ -17,12 +17,12 @@ import java.util.List;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
public class MavenCompiler implements CodeCompiler {
|
|
|
- private String dirname;
|
|
|
+ private final String dirname;
|
|
|
// TODO 和 EnvType 关联
|
|
|
- private String env;
|
|
|
- private InvocationRequest request;
|
|
|
- private Invoker invoker;
|
|
|
- private List<String> compileLog;
|
|
|
+ private final String env;
|
|
|
+ private final InvocationRequest request;
|
|
|
+ private final Invoker invoker;
|
|
|
+ private final List<String> compileLog;
|
|
|
|
|
|
public MavenCompiler(String homePath, String env, String dirname) {
|
|
|
System.setProperty("maven.home", homePath);
|
|
|
@@ -34,28 +34,27 @@ public class MavenCompiler implements CodeCompiler {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void compile(String appName, String appCompileHome) throws Exception {
|
|
|
+ public void compile(String appId, String appCompileHome) throws Exception {
|
|
|
String pomPath = appCompileHome + "/pom.xml";
|
|
|
- setInvocationRequest(pomPath);
|
|
|
+ setInvocationRequest(appId, pomPath);
|
|
|
InvocationResult result = invoker.execute(request);
|
|
|
if (result.getExitCode() != 0) {
|
|
|
- throw new Exception(compileLog.toString());
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ compileLog.forEach(line -> sb.append(line).append(System.lineSeparator()));
|
|
|
+ throw new Exception(sb.toString());
|
|
|
} else {
|
|
|
log.info("构建成功");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * mvn clean package -am -Pdev -pl ${app} -Dmaven.test.skip=true
|
|
|
- * // TODO 注意线程安全,也可每个线程创建一个对象
|
|
|
+ * mvn clean package -Dmaven.test.skip=true -am -Pdev -pl dmaster
|
|
|
*
|
|
|
* @param
|
|
|
* @return
|
|
|
* @date 2020-05-12 上午10:36
|
|
|
*/
|
|
|
- private void setInvocationRequest(String pomPath) {
|
|
|
- // 清空前一次构建的日志
|
|
|
- compileLog.clear();
|
|
|
+ private void setInvocationRequest(String appId, String pomPath) {
|
|
|
request.setPomFile(new File(pomPath));
|
|
|
// mvn clean package -Dmaven.test.skip=true
|
|
|
request.setGoals(Arrays.asList("clean", "package", "-Dmaven.test.skip=true"));
|
|
|
@@ -64,7 +63,10 @@ public class MavenCompiler implements CodeCompiler {
|
|
|
// -Penv
|
|
|
request.setProfiles(Collections.singletonList(env));
|
|
|
// -pl app
|
|
|
- request.setProjects(Collections.singletonList(dirname));
|
|
|
- request.setOutputHandler(line -> compileLog.add(line));
|
|
|
+ request.setProjects(Collections.singletonList(appId));
|
|
|
+ // 清空前一次构建的日志
|
|
|
+ // TODO 多线程环境时编译日志会出现问题
|
|
|
+ compileLog.clear();
|
|
|
+ request.setOutputHandler(compileLog::add);
|
|
|
}
|
|
|
}
|