|
|
@@ -1,11 +1,10 @@
|
|
|
package seecoder.devcloud.core.pipeline.template;
|
|
|
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.http.HttpStatus;
|
|
|
-import org.springframework.util.ResourceUtils;
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
import seecoder.devcloud.core.pipeline.PipelineException;
|
|
|
|
|
|
-import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
@@ -13,6 +12,8 @@ import java.util.ArrayList;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import static java.nio.charset.StandardCharsets.UTF_8;
|
|
|
+
|
|
|
/**
|
|
|
* @author PuHong Weng
|
|
|
* @date 2021/3/16
|
|
|
@@ -60,8 +61,8 @@ public class PipelineTemplateTable {
|
|
|
*/
|
|
|
public static void copyTemplateDockerfile(String templateName, Path dockerfile) throws IOException {
|
|
|
Files.createFile(dockerfile);
|
|
|
- File template = ResourceUtils.getFile("classpath:template/dockerfile/" + templateName);
|
|
|
- FileUtils.copyFile(template, dockerfile.toFile());
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource("template/dockerfile/"+templateName);
|
|
|
+ Files.write(dockerfile,IOUtils.toString(classPathResource.getInputStream(), UTF_8).getBytes());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -71,27 +72,21 @@ public class PipelineTemplateTable {
|
|
|
* @return
|
|
|
*/
|
|
|
public static void copyTemplateMavenSetting(Path mavenSetting) throws IOException {
|
|
|
- File template = ResourceUtils.getFile("classpath:template/settings.xml");
|
|
|
- FileUtils.copyFile(template, mavenSetting.toFile());
|
|
|
+ Files.createFile(mavenSetting);
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource("template/settings.xml");
|
|
|
+ Files.write(mavenSetting,IOUtils.toString(classPathResource.getInputStream(), UTF_8).getBytes());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取模板的json配置文件
|
|
|
*/
|
|
|
public static String getTemplateConfigJson(String templateName) throws PipelineException {
|
|
|
- File file = null;
|
|
|
- String template = null;
|
|
|
+
|
|
|
try {
|
|
|
- file = ResourceUtils.getFile("classpath:template/config/" + templateName + ".json");
|
|
|
- List<String> lines = Files.readAllLines(file.toPath());
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
- for (String line : lines) {
|
|
|
- sb.append(line);
|
|
|
- }
|
|
|
- template = sb.toString();
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource("template/config/"+ templateName + ".json");
|
|
|
+ return IOUtils.toString(classPathResource.getInputStream(), UTF_8);
|
|
|
} catch (IOException e) {
|
|
|
throw new PipelineException(HttpStatus.SC_SERVICE_UNAVAILABLE, PipelineException.CONFIG_JSON_ERROR, e);
|
|
|
}
|
|
|
- return template;
|
|
|
}
|
|
|
}
|