SbloodyS commented on code in PR #16542:
URL: 
https://github.com/apache/dolphinscheduler/pull/16542#discussion_r1845944085


##########
dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowJavaTaskE2ETest.java:
##########
@@ -70,16 +99,102 @@ public class WorkflowJavaTaskE2ETest {
 
     private static final String environmentWorkerGroup = "default";
 
-    private static final String javaContent = "public class Test {" +
-            "    public static void main(String[] args) {" +
-            "        System.out.println(\"hello world\");" +
-            "    }" +
-            "}";
+    private static final String filePath = Constants.HOST_TMP_PATH.toString();
 
     private static RemoteWebDriver browser;
 
+    public static void main(String[] args) {
+        createAndBuildJars();
+    }
+
+    private static void createJar(String className, String classFilePath, 
String entryName, String mainPackage,
+                                  String jarName) {
+
+        String jarFilePath = Constants.HOST_TMP_PATH + "/" + jarName;
+
+        Manifest manifest = new Manifest();
+        manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, 
"1.0");
+        manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, 
mainPackage);
+
+        try (
+                FileOutputStream fos = new FileOutputStream(jarFilePath);
+                JarOutputStream jos = new JarOutputStream(fos, manifest)) {
+            Path path = new File(classFilePath + className).toPath();
+            JarEntry entry = new JarEntry(entryName);
+            jos.putNextEntry(entry);
+            byte[] bytes = Files.readAllBytes(path);
+            jos.write(bytes, 0, bytes.length);
+            jos.closeEntry();
+        } catch (IOException e) {
+            throw new RuntimeException("Create jar failed:", e);
+        }
+
+    }
+    private static void createAndBuildJars() {

Review Comment:
   ```suggestion
       }
       
       private static void createAndBuildJars() {
   ```



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/main/java/org/apache/dolphinscheduler/plugin/task/java/MainClassExtractor.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.plugin.task.java;
+
+import java.io.File;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class MainClassExtractor {
+
+    private MainClassExtractor() {
+    }
+    public static String getMainClassName(String jarFilePath) {
+        String mainClassName = null;
+        try (JarFile jarFile = new JarFile(new File(jarFilePath))) {
+
+            Manifest manifest = jarFile.getManifest();
+            mainClassName = 
manifest.getMainAttributes().getValue("Main-Class");
+
+        } catch (Exception e) {
+            log.error("get mainJarName failed:", e);

Review Comment:
   ```suggestion
   ```



##########
dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowJavaTaskE2ETest.java:
##########
@@ -70,16 +99,102 @@ public class WorkflowJavaTaskE2ETest {
 
     private static final String environmentWorkerGroup = "default";
 
-    private static final String javaContent = "public class Test {" +
-            "    public static void main(String[] args) {" +
-            "        System.out.println(\"hello world\");" +
-            "    }" +
-            "}";
+    private static final String filePath = Constants.HOST_TMP_PATH.toString();
 
     private static RemoteWebDriver browser;
 
+    public static void main(String[] args) {
+        createAndBuildJars();
+    }

Review Comment:
   We don't need this since this have been execute in `setup`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to