Skip to content

Commit d2068f7

Browse files
committed
java: Add API for driver scan path
1 parent bc6b821 commit d2068f7

File tree

4 files changed

+46
-19
lines changed

4 files changed

+46
-19
lines changed

src/java/jni/modelbox_jni.cc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717

1818
#include "modelbox_jni.h"
1919

20+
#include "com_modelbox_ModelBox.h"
21+
#include "modelbox/base/driver.h"
22+
#include "modelbox/base/status.h"
2023
#include "scoped_jvm.h"
24+
#include "throw.h"
2125

2226
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
2327
JNIEnv *env;
@@ -33,3 +37,37 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
3337
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
3438
modelbox::ScopedJvm::SetJavaVM(nullptr);
3539
}
40+
41+
/*
42+
* Class: com_modelbox_ModelBox
43+
* Method: SetDefaultScanPath
44+
* Signature: (Ljava/lang/String;)V
45+
*/
46+
JNIEXPORT void JNICALL Java_com_modelbox_ModelBox_SetDefaultScanPath(
47+
JNIEnv *env, jclass j_class, jstring j_path) {
48+
const char *path = env->GetStringUTFChars(j_path, nullptr);
49+
if (path == nullptr) {
50+
modelbox::ModelBoxJNIThrow(env, modelbox::STATUS_INVALID, "invalid path");
51+
return;
52+
}
53+
54+
modelbox::Drivers::SetDefaultScanPath(path);
55+
env->ReleaseStringUTFChars(j_path, path);
56+
}
57+
58+
/*
59+
* Class: com_modelbox_ModelBox
60+
* Method: SetDefaultInfoPath
61+
* Signature: (Ljava/lang/String;)V
62+
*/
63+
JNIEXPORT void JNICALL Java_com_modelbox_ModelBox_SetDefaultInfoPath(
64+
JNIEnv *env, jclass j_class, jstring j_path) {
65+
const char *path = env->GetStringUTFChars(j_path, nullptr);
66+
if (path == nullptr) {
67+
modelbox::ModelBoxJNIThrow(env, modelbox::STATUS_INVALID, "invalid path");
68+
return;
69+
}
70+
71+
modelbox::Drivers::SetDefaultInfoPath(path);
72+
env->ReleaseStringUTFChars(j_path, path);
73+
}

src/java/src/main/java/com/modelbox/Log.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.Date;
2222

2323
public class Log extends NativeObject {
24-
enum LogLevel {
24+
public enum LogLevel {
2525
LOG_DEBUG, LOG_INFO, LOG_NOTICE, LOG_WARN, LOG_ERROR, LOG_FATAL, LOG_OFF
2626
}
2727

src/java/src/main/java/com/modelbox/ModelBoxJni.java renamed to src/java/src/main/java/com/modelbox/ModelBox.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
/**
2222
* modelbox defulat JNI
2323
*/
24-
public class ModelBoxJni {
24+
public class ModelBox {
2525
static {
2626
System.loadLibrary("modelbox-jni");
2727
}
2828

2929
// CHECKSTYLE:OFF
30+
public static native void SetDefaultScanPath(String path);
3031

32+
public static native void SetDefaultInfoPath(String path);
3133
// CHECKSTYLE:ON
3234
}

src/java/src/test/java/com/modelbox/ModelBoxFlowTest.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,22 @@
2020
import static org.junit.Assert.assertEquals;
2121
import static org.junit.Assert.assertFalse;
2222
import static org.junit.Assert.assertTrue;
23-
2423
import java.util.ArrayList;
2524
import java.util.HashMap;
2625
import java.util.Map;
27-
2826
import org.junit.BeforeClass;
2927
import org.junit.Test;
3028

3129
public class ModelBoxFlowTest {
3230
@BeforeClass
3331
public static void setUpTest() {
3432
Log.unRegLog();
33+
ModelBox.SetDefaultScanPath(TestConfig.TEST_DRIVER_DIR);
3534
}
3635

3736
@Test(expected = ModelBoxException.Badconf.class)
3837
public void testFlowNotExist() throws Exception {
39-
String driverDir = TestConfig.TEST_DRIVER_DIR;
40-
String txt = "[driver]\n";
41-
txt += "dir=[\"" + driverDir + "\"]\n";
42-
txt += "skip-default=true\n";
43-
txt += "[log]\n";
38+
String txt = "[log]\n";
4439
txt += "level=\"INFO\"\n";
4540
txt += "[graph]\n";
4641
txt += "graphconf = '''digraph demo {{ \n";
@@ -56,12 +51,8 @@ public void testFlowNotExist() throws Exception {
5651

5752
@Test
5853
public void testFlowProcessData() throws Exception {
59-
String driverDir = TestConfig.TEST_DRIVER_DIR;
6054
boolean get_result = false;
61-
String txt = "[driver]\n";
62-
txt += "dir=[\"" + driverDir + "\"]\n";
63-
txt += "skip-default=true\n";
64-
txt += "[log]\n";
55+
String txt = "[log]\n";
6556
txt += "level=\"INFO\"\n";
6657
txt += "[graph]\n";
6758
txt += "graphconf = '''digraph demo {{ \n";
@@ -139,12 +130,8 @@ public void testFlowProcessData() throws Exception {
139130

140131
@Test
141132
public void testFlowStreamIO() throws Exception {
142-
String driverDir = TestConfig.TEST_DRIVER_DIR;
143133
boolean get_result = false;
144-
String txt = "[driver]\n";
145-
txt += "dir=[\"" + driverDir + "\"]\n";
146-
txt += "skip-default=true\n";
147-
txt += "[log]\n";
134+
String txt = "[log]\n";
148135
txt += "level=\"INFO\"\n";
149136
txt += "[graph]\n";
150137
txt += "graphconf = '''digraph demo {{ \n";

0 commit comments

Comments
 (0)