use of cn.hutool.core.lang.Tuple in project Jpom by dromara.
the class SystemUpdateController method uploadJar.
@PostMapping(value = "uploadJar.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
public String uploadJar() throws IOException {
NodeModel nodeModel = tryGetNode();
if (nodeModel != null) {
return NodeForward.requestMultipart(getNode(), getMultiRequest(), NodeUrl.SystemUploadJar).toString();
}
//
Objects.requireNonNull(JpomManifest.getScriptFile());
MultipartFileBuilder multipartFileBuilder = createMultipart();
String absolutePath = ServerConfigBean.getInstance().getUserTempPath().getAbsolutePath();
multipartFileBuilder.setFileExt("jar", "zip").addFieldName("file").setUseOriginalFilename(true).setSavePath(absolutePath);
String path = multipartFileBuilder.save();
// 解析压缩包
File file = JpomManifest.zipFileFind(path, Type.Server, absolutePath);
path = FileUtil.getAbsolutePath(file);
// 基础检查
JsonMessage<Tuple> error = JpomManifest.checkJpomJar(path, Type.Server);
if (error.getCode() != HttpStatus.HTTP_OK) {
return error.toString();
}
Tuple data = error.getData();
String version = data.get(0);
JpomManifest.releaseJar(path, version);
//
backupInfoService.autoBackup();
//
JpomApplication.restart();
return JsonMessage.getString(200, Const.UPGRADE_MSG);
}
use of cn.hutool.core.lang.Tuple in project Jpom by dromara.
the class BuildInfoController method branchList.
/**
* 获取分支信息
*
* @param repositoryId 仓库id
* @return json
* @throws Exception 异常
*/
@RequestMapping(value = "/build/branch-list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String branchList(@ValidatorConfig(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "仓库ID不能为空")) String repositoryId) throws Exception {
// 根据 repositoryId 查询仓库信息
RepositoryModel repositoryModel = repositoryService.getByKey(repositoryId, false);
Assert.notNull(repositoryModel, "无效的仓库信息");
//
Assert.state(repositoryModel.getRepoType() == 0, "只有 GIT 仓库才有分支信息");
IPlugin plugin = PluginFactory.getPlugin("git-clone");
Map<String, Object> map = repositoryModel.toMap();
Tuple branchAndTagList = (Tuple) plugin.execute("branchAndTagList", map);
Assert.notNull(branchAndTagList, "没有任何分支");
Object[] members = branchAndTagList.getMembers();
return JsonMessage.getString(200, "ok", members);
}
use of cn.hutool.core.lang.Tuple in project Jpom by dromara.
the class AbstractProjectCommander method stop.
/**
* 停止
*
* @param nodeProjectInfoModel 项目
* @param javaCopyItem 副本信息
* @return 结果
* @throws Exception 异常
*/
public String stop(NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem javaCopyItem) throws Exception {
Tuple tuple = this.stopBefore(nodeProjectInfoModel, javaCopyItem);
String result = tuple.get(1);
String webHook = tuple.get(0);
int pid = ProjectCommanderUtil.parsePid(result);
if (pid > 0) {
RunMode runMode = nodeProjectInfoModel.getRunMode();
if (runMode == RunMode.Dsl) {
//
String startDsl = this.runDsl(nodeProjectInfoModel, "stop", process -> {
String log = nodeProjectInfoModel.getAbsoluteLog(null);
return DslScriptBuilder.run(process, nodeProjectInfoModel, log);
});
boolean checkRun = this.loopCheckRun(nodeProjectInfoModel, javaCopyItem, false);
result = StrUtil.emptyToDefault(startDsl, checkRun ? "stop done,but unsuccessful" : "stop done");
} else {
//
result = this.stopJava(nodeProjectInfoModel, javaCopyItem, pid);
}
}
return StrUtil.format("{} {}", result, webHook);
}
use of cn.hutool.core.lang.Tuple in project Jpom by dromara.
the class RemoteVersion method download.
/**
* 下载
*
* @param savePath 下载文件保存路径
* @param type 类型
* @param checkRepeat 是否验证重复
* @return 保存的全路径
* @throws IOException 异常
*/
public static Tuple download(String savePath, Type type, boolean checkRepeat) throws IOException {
RemoteVersion remoteVersion = loadRemoteInfo();
Assert.notNull(remoteVersion, "没有可用的新版本升级:-1");
// 检查是否存在下载地址
String remoteUrl = type.getRemoteUrl(remoteVersion);
Assert.hasText(remoteUrl, "存在新版本,下载地址不可用");
// 下载
File downloadFileFromUrl = HttpUtil.downloadFileFromUrl(remoteUrl, savePath);
// 解析压缩包
File file = JpomManifest.zipFileFind(FileUtil.getAbsolutePath(downloadFileFromUrl), type, savePath);
// 检查
JsonMessage<Tuple> error = JpomManifest.checkJpomJar(FileUtil.getAbsolutePath(file), type, checkRepeat);
Assert.state(error.getCode() == HttpStatus.HTTP_OK, error.getMsg());
return error.getData();
}
use of cn.hutool.core.lang.Tuple in project Jpom by dromara.
the class JpomManifest method getJarVersion.
/**
* 根据 jar 文件解析 jpom 版本信息
*
* @param jarFile 文件
* @return 版本, 打包时间, mainClass
*/
private static Tuple getJarVersion(File jarFile) {
Manifest manifest = ManifestUtil.getManifest(jarFile);
if (manifest != null) {
Attributes attributes = manifest.getMainAttributes();
String version = attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
if (version != null) {
// @see VersionUtils#getVersion()
String timeStamp = attributes.getValue("Jpom-Timestamp");
timeStamp = parseJpomTime(timeStamp);
String mainClass = attributes.getValue(Attributes.Name.MAIN_CLASS);
String jpomMinVersion = attributes.getValue("Jpom-Min-Version");
return new Tuple(version, timeStamp, mainClass, jarFile, jpomMinVersion);
}
}
return null;
}
Aggregations