瀏覽代碼

将路径分隔符由 "/" 修改为 File.separator, 便于跨平台

reghao 4 年之前
父節點
當前提交
6d470ade9a

+ 2 - 2
common/src/main/java/cn/reghao/autodop/common/util/FileOps.java

@@ -36,7 +36,7 @@ public class FileOps {
         for (File file : Objects.requireNonNull(srcDir.listFiles())) {
             if (file.isDirectory()) {
                 String dirname = file.getName();
-                File dstdir = new File(dst + "/" + dirname);
+                File dstdir = new File(dst + File.separator + dirname);
                 FileUtils.copyDirectory(file, dstdir);
             } else {
                 FileUtils.copyFileToDirectory(file, dstDir);
@@ -59,7 +59,7 @@ public class FileOps {
         }
 
         String dirname = srcDir.getName();
-        File dstDir = new File(dst + "/" + dirname);
+        File dstDir = new File(dst + File.separator + dirname);
         FileUtils.copyDirectory(srcDir, dstDir);
     }
 

+ 7 - 7
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppBuilder.java

@@ -75,9 +75,9 @@ public class AppBuilder {
     }
 
     private void initLocalDir() {
-        appLocalRepo = LocalBuildDir.localRepo + "/" + app.getAppId();
-        appCompileDir = LocalBuildDir.compileDir + "/" + app.getAppId();
-        appPackDir = LocalBuildDir.packDir + "/" + app.getAppId();
+        appLocalRepo = LocalBuildDir.localRepo + File.separator + app.getAppId();
+        appCompileDir = LocalBuildDir.compileDir + File.separator + app.getAppId();
+        appPackDir = LocalBuildDir.packDir + File.separator + app.getAppId();
     }
 
     /**
@@ -175,9 +175,9 @@ public class AppBuilder {
     }
 
     public String pack() throws Exception {
-        String appDirPath = compileDir() + File.separator + app.getAppRootPath();
-
-        return codePacker.pack(app.getAppId(), latestCommitInfo.getCommitId(), compileDir());
+        String appRootPath = compileDir() + File.separator + app.getAppRootPath();
+        return codePacker.pack(app.getAppId(), latestCommitInfo.getCommitId(), appRootPath);
+        //return codePacker.pack(app.getAppId(), latestCommitInfo.getCommitId(), compileDir());
     }
 
     public String push(String localPath) throws DockerException {
@@ -185,7 +185,7 @@ public class AppBuilder {
     }
 
     private String compileDir() {
-        return appCompileDir + "/" + app.getProjDirname();
+        return appCompileDir + File.separator + app.getProjDirname();
     }
 
     @Data

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/util/BuilderUtil.java

@@ -21,7 +21,7 @@ public class BuilderUtil {
      * @date 2019-12-03 上午9:55
      */
     public static void copyToCompileDir(String appLocalRepo, AppConfig app) throws IOException {
-        String appCompileDir = LocalBuildDir.compileDir + "/" + app.getAppId();
+        String appCompileDir = LocalBuildDir.compileDir + File.separator + app.getAppId();
         File compileDir = new File(appCompileDir);
         if (!compileDir.exists() && !FileOps.mkdirs(compileDir)) {
             throw new IOException(compileDir + "不存在");

+ 3 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/util/buildtool/packer/DockerPack.java

@@ -6,6 +6,8 @@ import cn.reghao.autodop.common.docker.DockerException;
 import cn.reghao.autodop.dmaster.app.model.po.config.build.PackerConfig;
 import lombok.extern.slf4j.Slf4j;
 
+import java.io.File;
+
 /**
  * 打包为 docker 应用
  *
@@ -26,7 +28,7 @@ public class DockerPack implements CodePacker {
 
     @Override
     public String pack(String appId, String commitId, String appCompileHome) throws Exception {
-        String repo = targetPath + "/" + appId;
+        String repo = targetPath + File.separator + appId;
         String image = repo + ":" + commitId;
         docker.build(image, appCompileHome, dockerfile);
         return image;

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/util/buildtool/packer/ZipPack.java

@@ -24,7 +24,7 @@ public class ZipPack implements CodePacker {
     @Override
     public String pack(String appId, String commitId, String appCompileHome) throws Exception {
         String filename = String.format("%s_%s.zip", appId, commitId);
-        String dst = targetPath + "/" + filename;
+        String dst = targetPath + File.separator + filename;
         if (new File(dst).exists()) {
             throw new Exception(dst + " 已存在");
         }

+ 2 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/sys/controller/SysController.java

@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.BufferedInputStream;
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 
@@ -32,7 +33,7 @@ public class SysController {
     @GetMapping("/package/{filename}")
     public void downloadPackage(@PathVariable("filename") String filename, HttpServletResponse response)
             throws IOException {
-        String filePath = LocalBuildDir.packDir + "/" + filename;
+        String filePath = LocalBuildDir.packDir + File.separator + filename;
         FileInputStream fileInputStream = new FileInputStream(filePath);
         BufferedInputStream bis = new BufferedInputStream(fileInputStream);
         uploadDownload.download(filename, bis, response);