Skip to content

Commit

Permalink
[Bugfix] [Git Build] fix git build some bug (DataLinkDC#3747)
Browse files Browse the repository at this point in the history
Co-authored-by: zackyoungh <[email protected]>
  • Loading branch information
zackyoungh and zackyoungh authored Aug 27, 2024
1 parent 86e7bdf commit 1b2995d
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 162 deletions.
24 changes: 7 additions & 17 deletions dinky-admin/src/main/java/org/dinky/sse/StepSse.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.ArrayList;
import java.util.LinkedList;
Expand Down Expand Up @@ -108,24 +107,15 @@ public synchronized void sendMsg(Object msg) {
});
}

public synchronized void addFileMsg(Object msg) {
FileUtil.appendUtf8String(Convert.toStr(msg), getLogFile());
}

public synchronized void addFileMsgCusLog(String msg) {
String content = "\n============= " + Convert.toStr(msg) + " =============\n";
String content = "============= " + Convert.toStr(msg) + " =============";
addMsg(content);
FileUtil.appendUtf8String(content, getLogFile());
FileUtil.appendUtf8String(content + "\n", getLogFile());
}

public synchronized void addFileMsgLog(String msg) {
addMsg(msg);
FileUtil.appendUtf8String(msg, getLogFile());
}

public synchronized void addFileLog(List<?> data) {
sendMsg(getList(data));
FileUtil.appendString(StrUtil.join("\n", data), getLogFile(), StandardCharsets.UTF_8);
FileUtil.appendUtf8String(msg + "\n", getLogFile());
}

protected File getLogFile() {
Expand All @@ -144,7 +134,7 @@ public void send() {
cachedThreadPool.execute(this::sendSync);
}

public void main() {
public void run() {
this.status = 1;
getStep();
FileUtil.del(getLogFile());
Expand Down Expand Up @@ -192,7 +182,7 @@ public void setFinish(boolean status) {
gitProject.setBuildState(1);
gitProject.setBuildStep(nexStepSse.getStep());
gitProject.updateById();
nexStepSse.main();
nexStepSse.run();
}
}

Expand All @@ -201,7 +191,7 @@ private void close() {
try {
emitter.complete();
} catch (Exception e) {
e.printStackTrace();
log.error("", e);
}
});
// Manual GC is required here to release file IO(此处需要手动GC,释放文件IO)
Expand Down Expand Up @@ -233,7 +223,7 @@ protected Dict getLogObj(Object data) {
//
// }

Object dataResult = (data instanceof List) ? StrUtil.join("\n", data) : JSONUtil.toJsonStr(data);
Object dataResult = (data instanceof List) ? StrUtil.join("\n", data) + "\n" : JSONUtil.toJsonStr(data);
return Dict.create()
.set("type", 1)
.set("currentStep", getStep())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public GetJarsStepSse(
public void exec() {
List<File> jars = MavenUtil.getJars((File) params.get("pom"));
List<String> pathList = uploadResources(jars);
addFileMsg(pathList);
addMsg(String.join("\n", pathList));

params.put("jarPath", pathList);
}
Expand Down
4 changes: 2 additions & 2 deletions dinky-admin/src/main/java/org/dinky/sse/git/HeadStepSse.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ private void checkJava() {
String mavenHome = MavenUtil.getMavenHome();

if (StrUtil.isBlank(mavenHome)) {
addFileMsg(Status.GIT_MAVEN_HOME_NOT_SET.getMessage());
addFileMsgLog(Status.GIT_MAVEN_HOME_NOT_SET.getMessage());
setFinish(false);
}
String mavenVersionMsg = MavenUtil.getMavenVersion();
mavenVersionMsg += "\n Your Maven Home is: " + mavenHome;
mavenVersionMsg += "Your Maven Home is: " + mavenHome;
addFileMsgLog(mavenVersionMsg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void exec() {
null,
getLogFile().getAbsolutePath(),
CollUtil.newArrayList("clean", "package"),
StrUtil.split(gitProject.getBuildArgs(), " "),
gitProject.getBuildArgs(),
this::addFileMsgLog);
params.put("pom", pom);
Assert.isTrue(state, "maven build failed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void build(GitProject gitProject, Dict params) {
List<SseEmitter> emitterList = new ArrayList<>();

StepSse headStepSse = getHeadStepPlan(gitProject.getCodeType(), sleep, emitterList, params);
cachedThreadPool.execute(headStepSse::main);
cachedThreadPool.execute(headStepSse::run);
gitProject.setBuildStep(1);
gitProject.setBuildState(1);
gitProject.setLastBuild(DateUtil.date());
Expand Down
21 changes: 9 additions & 12 deletions dinky-admin/src/main/java/org/dinky/utils/MavenUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Assert;
Expand Down Expand Up @@ -68,18 +67,14 @@ public class MavenUtil {
private static final TemplateEngine ENGINE =
new FreemarkerEngine(new TemplateConfig("templates", TemplateConfig.ResourceMode.CLASSPATH));

public static boolean build(String setting, String pom, String logFile, List<String> args) {
return build(setting, pom, null, null, logFile, CollUtil.newArrayList("package"), args, null);
}

public static boolean build(
String setting,
String pom,
String mavenHome,
String repositoryDir,
String logFile,
List<String> goals,
List<String> args,
String args,
Consumer<String> consumer) {
Assert.notBlank(pom, "the project pom file cannot be empty");

Expand All @@ -97,15 +92,17 @@ public static boolean build(
}
String mavenCommandLine =
getMavenCommandLineByMvn(pom, mavenHome, localRepositoryDirectory, setting, goals, args);
Opt.ofNullable(consumer).ifPresent(c -> c.accept("Executing command: " + mavenCommandLine + "\n"));
Opt.ofNullable(consumer).ifPresent(c -> c.accept("Executing command: " + mavenCommandLine));

int waitValue = RuntimeUtils.run(
mavenCommandLine,
s -> {
s = DateUtil.date().toMsStr() + " - " + s + "\n";
consumer.accept(s);
s = DateUtil.date().toMsStr() + " - " + s;
if (consumer != null) {
consumer.accept(s);
}
},
consumer::accept);
consumer);
return waitValue == 0;
}

Expand Down Expand Up @@ -158,7 +155,7 @@ public static String getMavenCommandLineByMvn(
String repositoryDir,
String settingsPath,
List<String> goals,
List<String> args) {
String args) {
projectDir = StrUtil.wrap(projectDir, "\"");
settingsPath = StrUtil.wrap(settingsPath, "\"");
List<String> commandLine = new LinkedList<>();
Expand All @@ -171,7 +168,7 @@ public static String getMavenCommandLineByMvn(
commandLine.add("-Dclassworlds.conf=" + StrUtil.wrap(mavenHome + "/bin/m2.conf", "\""));
commandLine.add("-s " + settingsPath);
commandLine.add("-f " + projectDir);
commandLine.add(StrUtil.join(" ", args));
commandLine.add(StrUtil.wrap(StrUtil.replace(args, "\"", "\\*"), "\""));
commandLine.add(StrUtil.join(" ", goals));
return StrUtil.join(" ", commandLine);
}
Expand Down
93 changes: 0 additions & 93 deletions dinky-admin/src/test/java/org/dinky/utils/MavenUtilTests.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.dinky.trans.dml;

import static org.dinky.utils.RunTimeUtil.extractArgs;

import org.dinky.executor.CustomTableEnvironment;
import org.dinky.trans.AbstractOperation;
import org.dinky.trans.ExtendOperation;
Expand All @@ -38,10 +40,7 @@

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -131,30 +130,6 @@ public static Pipeline getStreamGraph(
}
}

public static List<String> extractArgs(String args) {
List<String> programArgs = new ArrayList<>();
if (StrUtil.isNotEmpty(args)) {
String[] array = args.split("\\s+");
Iterator<String> iter = Arrays.asList(array).iterator();
while (iter.hasNext()) {
String v = iter.next();
String p = v.substring(0, 1);
if (p.equals("'") || p.equals("\"")) {
String value = v;
if (!v.endsWith(p)) {
while (!value.endsWith(p) && iter.hasNext()) {
value += " " + iter.next();
}
}
programArgs.add(value.substring(1, value.length() - 1));
} else {
programArgs.add(v);
}
}
}
return programArgs;
}

@Override
public String asSummaryString() {
return statement;
Expand Down
32 changes: 32 additions & 0 deletions dinky-common/src/main/java/org/dinky/utils/RunTimeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package org.dinky.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;

Expand All @@ -35,6 +37,36 @@
*/
public class RunTimeUtil {

/**
* Extract parameters
*
* @param args parameters
* @return List of parameters
*/
public static List<String> extractArgs(String args) {
List<String> programArgs = new ArrayList<>();
if (StrUtil.isNotEmpty(args)) {
String[] array = args.split("\\s+");
Iterator<String> iter = Arrays.asList(array).iterator();
while (iter.hasNext()) {
String v = iter.next();
String p = v.substring(0, 1);
if (p.equals("'") || p.equals("\"")) {
String value = v;
if (!v.endsWith(p)) {
while (!value.endsWith(p) && iter.hasNext()) {
value += " " + iter.next();
}
}
programArgs.add(value.substring(1, value.length() - 1));
} else {
programArgs.add(v);
}
}
}
return programArgs;
}

public static void recovery(Object obj) {
obj = null;
System.gc();
Expand Down
Loading

0 comments on commit 1b2995d

Please sign in to comment.