|
|
@@ -18,26 +18,27 @@ import java.util.List;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
public class MavenCompiler implements CodeCompiler {
|
|
|
- private final String dirname;
|
|
|
+ private final String appDirPath;
|
|
|
// TODO 和 EnvType 关联
|
|
|
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) {
|
|
|
+ public MavenCompiler(String homePath, String env, String appDirPath) {
|
|
|
System.setProperty("maven.home", homePath);
|
|
|
this.env = env;
|
|
|
this.request = new DefaultInvocationRequest();
|
|
|
this.invoker = new DefaultInvoker();
|
|
|
this.compileLog = new ArrayList<>();
|
|
|
- this.dirname = dirname;
|
|
|
+ this.appDirPath = appDirPath;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void compile(String appId, String appCompileHome) throws Exception {
|
|
|
String pomPath = appCompileHome + "/pom.xml";
|
|
|
- setInvocationRequest(appId, pomPath);
|
|
|
+ String appDirname = appDirPath.substring(appDirPath.lastIndexOf(File.separator)+1);
|
|
|
+ setInvocationRequest(appDirname, pomPath);
|
|
|
InvocationResult result = invoker.execute(request);
|
|
|
if (result.getExitCode() != 0) {
|
|
|
CommandLineException exception = result.getExecutionException();
|
|
|
@@ -49,7 +50,7 @@ public class MavenCompiler implements CodeCompiler {
|
|
|
compileLog.forEach(line -> sb.append(line).append(System.lineSeparator()));
|
|
|
throw new Exception(sb.toString());
|
|
|
} else {
|
|
|
- log.info("构建成功");
|
|
|
+ log.info("maven 构建成功");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -60,7 +61,7 @@ public class MavenCompiler implements CodeCompiler {
|
|
|
* @return
|
|
|
* @date 2020-05-12 上午10:36
|
|
|
*/
|
|
|
- private void setInvocationRequest(String appId, String pomPath) {
|
|
|
+ private void setInvocationRequest(String appDirname, String pomPath) {
|
|
|
request.setPomFile(new File(pomPath));
|
|
|
// mvn clean package -Dmaven.test.skip=true
|
|
|
request.setGoals(Arrays.asList("clean", "package", "-Dmaven.test.skip=true"));
|
|
|
@@ -69,7 +70,7 @@ public class MavenCompiler implements CodeCompiler {
|
|
|
// -Penv
|
|
|
request.setProfiles(Collections.singletonList(env));
|
|
|
// -pl app
|
|
|
- request.setProjects(Collections.singletonList(appId));
|
|
|
+ request.setProjects(Collections.singletonList(appDirname));
|
|
|
// 清空前一次构建的日志
|
|
|
// TODO 多线程环境时编译日志会出现问题
|
|
|
compileLog.clear();
|