Search in sources :

Example 11 with Tuple

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);
}
Also used : NodeModel(io.jpom.model.data.NodeModel) MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) File(java.io.File) Tuple(cn.hutool.core.lang.Tuple) PostMapping(org.springframework.web.bind.annotation.PostMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 12 with Tuple

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);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) RepositoryModel(io.jpom.model.data.RepositoryModel) Tuple(cn.hutool.core.lang.Tuple) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 13 with Tuple

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);
}
Also used : RunMode(io.jpom.model.RunMode) Tuple(cn.hutool.core.lang.Tuple)

Example 14 with Tuple

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();
}
Also used : File(java.io.File) Tuple(cn.hutool.core.lang.Tuple)

Example 15 with Tuple

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;
}
Also used : Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest) Tuple(cn.hutool.core.lang.Tuple)

Aggregations

Tuple (cn.hutool.core.lang.Tuple)22 File (java.io.File)8 JSONObject (com.alibaba.fastjson.JSONObject)6 ClassFeature (io.jpom.permission.ClassFeature)6 Feature (io.jpom.permission.Feature)6 MethodFeature (io.jpom.permission.MethodFeature)6 ZipFile (java.util.zip.ZipFile)4 MultipartFileBuilder (cn.jiangzeyin.controller.multipart.MultipartFileBuilder)3 RepositoryModel (io.jpom.model.data.RepositoryModel)2 SystemPermission (io.jpom.permission.SystemPermission)2 JpomRuntimeException (io.jpom.system.JpomRuntimeException)2 ServerConfigBean (io.jpom.system.ServerConfigBean)2 IOException (java.io.IOException)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 JarFile (java.util.jar.JarFile)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JarClassLoader (cn.hutool.core.lang.JarClassLoader)1