|
|
@ -17,6 +17,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.plugin.task.java; |
|
|
|
package org.apache.dolphinscheduler.plugin.task.java; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static com.google.common.truth.Truth.assertThat; |
|
|
|
import static org.apache.dolphinscheduler.plugin.task.api.enums.DataType.VARCHAR; |
|
|
|
import static org.apache.dolphinscheduler.plugin.task.api.enums.DataType.VARCHAR; |
|
|
|
import static org.apache.dolphinscheduler.plugin.task.api.enums.Direct.IN; |
|
|
|
import static org.apache.dolphinscheduler.plugin.task.api.enums.Direct.IN; |
|
|
|
import static org.apache.dolphinscheduler.plugin.task.java.JavaConstants.RUN_TYPE_JAR; |
|
|
|
import static org.apache.dolphinscheduler.plugin.task.java.JavaConstants.RUN_TYPE_JAR; |
|
|
@ -34,7 +35,6 @@ import org.apache.dolphinscheduler.plugin.task.java.exception.JavaSourceFileExis |
|
|
|
import org.apache.dolphinscheduler.plugin.task.java.exception.PublicClassNotFoundException; |
|
|
|
import org.apache.dolphinscheduler.plugin.task.java.exception.PublicClassNotFoundException; |
|
|
|
import org.apache.dolphinscheduler.plugin.task.java.exception.RunTypeNotFoundException; |
|
|
|
import org.apache.dolphinscheduler.plugin.task.java.exception.RunTypeNotFoundException; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Files; |
|
|
@ -82,10 +82,10 @@ public class JavaTaskTest { |
|
|
|
**/ |
|
|
|
**/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void buildJarCommand() { |
|
|
|
public void buildJarCommand() { |
|
|
|
String homeBinPath = JavaConstants.JAVA_HOME_VAR + File.separator + "bin" + File.separator; |
|
|
|
|
|
|
|
JavaTask javaTask = runJarType(); |
|
|
|
JavaTask javaTask = runJarType(); |
|
|
|
Assertions.assertEquals(javaTask.buildJarCommand(), homeBinPath |
|
|
|
assertThat(javaTask.buildJarCommand()) |
|
|
|
+ "java -classpath .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar -jar /tmp/dolphinscheduler/test/executepath/opt/share/jar/main.jar -host 127.0.0.1 -port 8080 -xms:50m"); |
|
|
|
.isEqualTo( |
|
|
|
|
|
|
|
"${JAVA_HOME}/bin/java -classpath .:/tmp/dolphinscheduler/test/executepath:opt/share/jar/resource2.jar -jar /tmp/dolphinscheduler/test/executepath/opt/share/jar/main.jar -host 127.0.0.1 -port 8080 -xms:50m"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -101,14 +101,13 @@ public class JavaTaskTest { |
|
|
|
Assertions.assertEquals("JavaTaskTest", publicClassName); |
|
|
|
Assertions.assertEquals("JavaTaskTest", publicClassName); |
|
|
|
String fileName = javaTask.buildJavaSourceCodeFileFullName(publicClassName); |
|
|
|
String fileName = javaTask.buildJavaSourceCodeFileFullName(publicClassName); |
|
|
|
try { |
|
|
|
try { |
|
|
|
String homeBinPath = JavaConstants.JAVA_HOME_VAR + File.separator + "bin" + File.separator; |
|
|
|
|
|
|
|
Path path = Paths.get(fileName); |
|
|
|
Path path = Paths.get(fileName); |
|
|
|
if (Files.exists(path)) { |
|
|
|
if (Files.exists(path)) { |
|
|
|
Files.delete(path); |
|
|
|
Files.delete(path); |
|
|
|
} |
|
|
|
} |
|
|
|
Assertions.assertEquals(homeBinPath |
|
|
|
assertThat(javaTask.buildJavaCompileCommand(sourceCode)) |
|
|
|
+ "javac -classpath .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar /tmp/dolphinscheduler/test/executepath/JavaTaskTest.java", |
|
|
|
.isEqualTo( |
|
|
|
javaTask.buildJavaCompileCommand(sourceCode)); |
|
|
|
"${JAVA_HOME}/bin/javac -classpath .:/tmp/dolphinscheduler/test/executepath:opt/share/jar/resource2.jar /tmp/dolphinscheduler/test/executepath/JavaTaskTest.java"); |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
Path path = Paths.get(fileName); |
|
|
|
Path path = Paths.get(fileName); |
|
|
|
if (Files.exists(path)) { |
|
|
|
if (Files.exists(path)) { |
|
|
@ -121,26 +120,29 @@ public class JavaTaskTest { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Construct java to run the command |
|
|
|
* Construct java to run the command |
|
|
|
* |
|
|
|
* |
|
|
|
* @return void |
|
|
|
* @return void |
|
|
|
**/ |
|
|
|
**/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void buildJavaCommand() throws Exception { |
|
|
|
public void buildJavaCommand() throws Exception { |
|
|
|
String wantJavaCommand = |
|
|
|
|
|
|
|
"${JAVA_HOME}/bin/javac -classpath .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar /tmp/dolphinscheduler/test/executepath/JavaTaskTest.java;${JAVA_HOME}/bin/java -classpath .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar JavaTaskTest -host 127.0.0.1 -port 8080 -xms:50m"; |
|
|
|
|
|
|
|
JavaTask javaTask = runJavaType(); |
|
|
|
JavaTask javaTask = runJavaType(); |
|
|
|
String sourceCode = javaTask.buildJavaSourceContent(); |
|
|
|
String sourceCode = javaTask.buildJavaSourceContent(); |
|
|
|
String publicClassName = javaTask.getPublicClassName(sourceCode); |
|
|
|
String publicClassName = javaTask.getPublicClassName(sourceCode); |
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertEquals("JavaTaskTest", publicClassName); |
|
|
|
Assertions.assertEquals("JavaTaskTest", publicClassName); |
|
|
|
|
|
|
|
|
|
|
|
String fileName = javaTask.buildJavaSourceCodeFileFullName(publicClassName); |
|
|
|
String fileName = javaTask.buildJavaSourceCodeFileFullName(publicClassName); |
|
|
|
Path path = Paths.get(fileName); |
|
|
|
Path path = Paths.get(fileName); |
|
|
|
if (Files.exists(path)) { |
|
|
|
if (Files.exists(path)) { |
|
|
|
Files.delete(path); |
|
|
|
Files.delete(path); |
|
|
|
} |
|
|
|
} |
|
|
|
Assertions.assertEquals(wantJavaCommand, javaTask.buildJavaCommand()); |
|
|
|
assertThat(javaTask.buildJavaCommand()) |
|
|
|
|
|
|
|
.isEqualTo( |
|
|
|
|
|
|
|
"${JAVA_HOME}/bin/javac -classpath .:/tmp/dolphinscheduler/test/executepath:opt/share/jar/resource2.jar /tmp/dolphinscheduler/test/executepath/JavaTaskTest.java;${JAVA_HOME}/bin/java -classpath .:/tmp/dolphinscheduler/test/executepath:opt/share/jar/resource2.jar JavaTaskTest -host 127.0.0.1 -port 8080 -xms:50m"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* There is no exception to overwriting the Java source file |
|
|
|
* There is no exception to overwriting the Java source file |
|
|
|
|
|
|
|
* |
|
|
|
* @return void |
|
|
|
* @return void |
|
|
|
* @throws IOException |
|
|
|
* @throws IOException |
|
|
|
**/ |
|
|
|
**/ |
|
|
@ -259,8 +261,8 @@ public class JavaTaskTest { |
|
|
|
resourceItem2.setResourceAbsolutePathInLocal("opt/share/jar/main.jar"); |
|
|
|
resourceItem2.setResourceAbsolutePathInLocal("opt/share/jar/main.jar"); |
|
|
|
|
|
|
|
|
|
|
|
ResourceContext.ResourceItem resourceItem3 = new ResourceContext.ResourceItem(); |
|
|
|
ResourceContext.ResourceItem resourceItem3 = new ResourceContext.ResourceItem(); |
|
|
|
resourceItem2.setResourceAbsolutePathInStorage("/JavaTaskTest.java"); |
|
|
|
resourceItem3.setResourceAbsolutePathInStorage("/JavaTaskTest.java"); |
|
|
|
resourceItem2.setResourceAbsolutePathInLocal("JavaTaskTest.java"); |
|
|
|
resourceItem3.setResourceAbsolutePathInLocal("JavaTaskTest.java"); |
|
|
|
|
|
|
|
|
|
|
|
ResourceContext resourceContext = new ResourceContext(); |
|
|
|
ResourceContext resourceContext = new ResourceContext(); |
|
|
|
resourceContext.addResourceItem(resourceItem1); |
|
|
|
resourceContext.addResourceItem(resourceItem1); |
|
|
@ -275,7 +277,7 @@ public class JavaTaskTest { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* The Java task to construct the jar run mode |
|
|
|
* The Java task to construct the jar run mode |
|
|
|
* |
|
|
|
* |
|
|
|
* @return JavaTask |
|
|
|
* @return JavaTask |
|
|
|
**/ |
|
|
|
**/ |
|
|
|
private JavaTask runJarType() { |
|
|
|
private JavaTask runJarType() { |
|
|
|
TaskExecutionContext taskExecutionContext = new TaskExecutionContext(); |
|
|
|
TaskExecutionContext taskExecutionContext = new TaskExecutionContext(); |
|
|
|