|
|
@@ -1,6 +1,7 @@
|
|
|
package cn.reghao.devops.web.mgr.builds.service.impl;
|
|
|
|
|
|
import cn.reghao.devops.web.mgr.app.db.query.AppBuildQuery;
|
|
|
+import cn.reghao.devops.web.mgr.build.model.constant.CompileType;
|
|
|
import cn.reghao.devops.web.mgr.builds.db.repository.CompilerConfigRepository;
|
|
|
import cn.reghao.devops.web.mgr.app.model.po.config.AppConfig;
|
|
|
import cn.reghao.devops.web.mgr.builds.model.po.CompilerConfig;
|
|
|
@@ -8,9 +9,13 @@ import cn.reghao.devops.web.mgr.build.chain.BuildTools;
|
|
|
import cn.reghao.devops.web.mgr.builds.service.CompilerConfigService;
|
|
|
import cn.reghao.jutil.jdk.result.Result;
|
|
|
import cn.reghao.jutil.jdk.result.ResultStatus;
|
|
|
+import cn.reghao.jutil.jdk.shell.ShellExecutor;
|
|
|
+import cn.reghao.jutil.jdk.shell.ShellResult;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -21,10 +26,13 @@ import java.util.stream.Collectors;
|
|
|
public class CompilerConfigServiceImpl implements CompilerConfigService {
|
|
|
private final CompilerConfigRepository compilerConfigRepository;
|
|
|
private final AppBuildQuery appBuildQuery;
|
|
|
+ private final ShellExecutor shellExecutor;
|
|
|
|
|
|
- public CompilerConfigServiceImpl(CompilerConfigRepository compilerConfigRepository, AppBuildQuery appBuildQuery) {
|
|
|
+ public CompilerConfigServiceImpl(CompilerConfigRepository compilerConfigRepository, AppBuildQuery appBuildQuery,
|
|
|
+ ShellExecutor shellExecutor) {
|
|
|
this.compilerConfigRepository = compilerConfigRepository;
|
|
|
this.appBuildQuery = appBuildQuery;
|
|
|
+ this.shellExecutor = shellExecutor;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -75,4 +83,68 @@ public class CompilerConfigServiceImpl implements CompilerConfigService {
|
|
|
BuildTools.removeCodeCompiler(compilerConfig.getName());
|
|
|
return Result.result(ResultStatus.SUCCESS);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getCompilerVersion(int id) {
|
|
|
+ CompilerConfig compilerConfig = compilerConfigRepository.findById(id).orElse(null);
|
|
|
+ if (compilerConfig == null) {
|
|
|
+ return "not exist";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!compilerConfig.getType().equals(CompileType.shell.getName())) {
|
|
|
+ return "not shell type";
|
|
|
+ }
|
|
|
+
|
|
|
+ String versionCmd = compilerConfig.getVersionCmd();
|
|
|
+ ShellResult shellResult = shellExecutor.exec(versionCmd.split("\\s+"));
|
|
|
+ String html = txtToHtml(shellResult.getResult());
|
|
|
+ return html;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String txtToHtml(String s) {
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ boolean previousWasASpace = false;
|
|
|
+ for (char c : s.toCharArray()) {
|
|
|
+ if (c == ' ') {
|
|
|
+ if (previousWasASpace) {
|
|
|
+ builder.append(" ");
|
|
|
+ previousWasASpace = false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ previousWasASpace = true;
|
|
|
+ } else {
|
|
|
+ previousWasASpace = false;
|
|
|
+ }
|
|
|
+ switch (c) {
|
|
|
+ case '<':
|
|
|
+ builder.append("<");
|
|
|
+ break;
|
|
|
+ case '>':
|
|
|
+ builder.append(">");
|
|
|
+ break;
|
|
|
+ case '&':
|
|
|
+ builder.append("&");
|
|
|
+ break;
|
|
|
+ case '"':
|
|
|
+ builder.append(""");
|
|
|
+ break;
|
|
|
+ case '\n':
|
|
|
+ builder.append("<br>");
|
|
|
+ break;
|
|
|
+ // We need Tab support here, because we print StackTraces as HTML
|
|
|
+ case '\t':
|
|
|
+ builder.append(" ");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ builder.append(c);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String converted = builder.toString();
|
|
|
+ String str = "(?i)\\b((?:https?://|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:\'\".,<>?«»“”‘’]))";
|
|
|
+ Pattern patt = Pattern.compile(str);
|
|
|
+ Matcher matcher = patt.matcher(converted);
|
|
|
+ converted = matcher.replaceAll("<a href=\"$1\">$1</a>");
|
|
|
+ return converted;
|
|
|
+ }
|
|
|
}
|