Просмотр исходного кода

fix: 缺少port字段导致解析错误

370774330@qq.com 5 лет назад
Родитель
Сommit
99b3774fdf

+ 34 - 36
core/src/main/java/seecoder/devcloud/core/pipeline/handler/JavaImageBuildHandler.java

@@ -8,8 +8,6 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.apache.http.HttpStatus;
 import org.eclipse.jgit.api.Git;
-import org.w3c.dom.Document;
-import org.w3c.dom.NodeList;
 import seecoder.devcloud.api.docker.DockerApi;
 import seecoder.devcloud.api.git.GitApi;
 import seecoder.devcloud.common.util.SpringUtil;
@@ -17,9 +15,6 @@ import seecoder.devcloud.core.pipeline.Context;
 import seecoder.devcloud.core.pipeline.PipelineException;
 import seecoder.devcloud.core.pipeline.template.PipelineTemplateTable;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import java.io.File;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -50,6 +45,8 @@ public class JavaImageBuildHandler extends AbstractHandler {
 
     private String branchName;
 
+    private String jarName;
+
     @Override
     public void process(Context context) throws PipelineException {
         //0. 变量准备
@@ -78,37 +75,38 @@ public class JavaImageBuildHandler extends AbstractHandler {
             throw new PipelineException(HttpStatus.SC_SERVICE_UNAVAILABLE,PipelineException.DOCKERFILE_CREATE_ERROR,e);
         }
 
-        //3. 读取项目 groupId artifactId version, 替换dockerfile的project name
-        //todo 因为不知道学生构建的jar名,且dockerapi没有提供可以输入ARG参数的接口,逼不得已只能读取pom来获取jar包名。
-        // 这种默认的实现形式,必须保证需要运行的项目pom在根目录(单模块)
-        // pom的结构顺序没有经过人为调整,不奇葩(也就是groupId artifactId version按默认就在pom最前面)
-        // 使用xml 解析强行读取
-        // 待使用更好的实现
-        String artifactId = null;
-        String version = null;
-        File pom = Paths.get(directory.toString(),"pom.xml").toFile();
-        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
-        DocumentBuilder dBuilder;
-        Document doc = null;
-        String jarName = context.getConfigs().getOrDefault("jarName",null);
-        if (jarName == null){
-            try {
-                dBuilder = dbFactory.newDocumentBuilder();
-                doc = dBuilder.parse(pom);
-                NodeList nodes = doc.getChildNodes().item(0).getChildNodes();
-                //按默认顺序 前二十个xml节点肯定有那三个量了
-                for (int i = 0; i < 20; i++){
-                    if ("artifactId".equals(nodes.item(i).getNodeName())) {
-                        artifactId = nodes.item(i).getTextContent();
-                    } else if ("version".equals(nodes.item(i).getNodeName())){
-                        version = nodes.item(i).getTextContent();
-                    }
-                }
-            } catch (Exception e) {
-                throw new PipelineException(HttpStatus.SC_SERVICE_UNAVAILABLE,PipelineException.POM_READ_ERROR,e);
-            }
-            jarName = artifactId+"-"+version;
-        }
+//        //3. 读取项目 groupId artifactId version, 替换dockerfile的project name
+//        //todo 因为不知道学生构建的jar名,且dockerapi没有提供可以输入ARG参数的接口,逼不得已只能读取pom来获取jar包名。
+//        // 这种默认的实现形式,必须保证需要运行的项目pom在根目录(单模块)
+//        // pom的结构顺序没有经过人为调整,不奇葩(也就是groupId artifactId version按默认就在pom最前面)
+//        // 使用xml 解析强行读取
+//        // 待使用更好的实现
+//        String artifactId = null;
+//        String version = null;
+//        File pom = Paths.get(directory.toString(),"pom.xml").toFile();
+//        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+//        DocumentBuilder dBuilder;
+//        Document doc = null;
+//        String jarName = context.getConfigs().getOrDefault("jarName",null);
+//        if (jarName == null){
+//            try {
+//                dBuilder = dbFactory.newDocumentBuilder();
+//                doc = dBuilder.parse(pom);
+//                NodeList nodes = doc.getChildNodes().item(0).getChildNodes();
+//                //按默认顺序 前二十个xml节点肯定有那三个量了
+//                for (int i = 0; i < 20; i++){
+//                    if ("artifactId".equals(nodes.item(i).getNodeName())) {
+//                        artifactId = nodes.item(i).getTextContent();
+//                    } else if ("version".equals(nodes.item(i).getNodeName())){
+//                        version = nodes.item(i).getTextContent();
+//                    }
+//                }
+//            } catch (Exception e) {
+//                throw new PipelineException(HttpStatus.SC_SERVICE_UNAVAILABLE,PipelineException.POM_READ_ERROR,e);
+//            }
+//            jarName = artifactId+"-"+version;
+//        }
+
         //4. 修改dockerfile内部需要替换的内容
         List<String> dockerfileLines = null;
         try {