提交 3effef99 authored 作者: Thomas Mueller's avatar Thomas Mueller

Use a weak dependency to the JTS jar file (allow to use H2 without the JTS jar…

Use a weak dependency to the JTS jar file (allow to use H2 without the JTS jar file in the classpath)
上级 279516bb
...@@ -114,6 +114,10 @@ public class TestClearReferences extends TestBase { ...@@ -114,6 +114,10 @@ public class TestClearReferences extends TestBase {
Class<?> clazz = null; Class<?> clazz = null;
try { try {
clazz = Class.forName(className); clazz = Class.forName(className);
} catch (NoClassDefFoundError e) {
if (e.toString().indexOf("lucene") >= 0) {
// Lucene is not in the classpath, OK
}
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
fail("Could not load " + className + ": " + e.toString()); fail("Could not load " + className + ": " + e.toString());
} }
...@@ -129,7 +133,23 @@ public class TestClearReferences extends TestBase { ...@@ -129,7 +133,23 @@ public class TestClearReferences extends TestBase {
* @param clazz the class to clear * @param clazz the class to clear
*/ */
private void clearClass(Class<?> clazz) throws Exception { private void clearClass(Class<?> clazz) throws Exception {
for (Field field : clazz.getDeclaredFields()) { Field[] fields;
try {
fields = clazz.getDeclaredFields();
} catch (NoClassDefFoundError e) {
if (e.toString().indexOf("lucene") >= 0) {
// Lucene is not in the classpath, OK
return;
} else if (e.toString().indexOf("jts") >= 0) {
// JTS is not in the classpath, OK
return;
} else if (e.toString().indexOf("slf4j") >= 0) {
// slf4j is not in the classpath, OK
return;
}
throw e;
}
for (Field field : fields) {
if (field.getType().isPrimitive() || field.getName().indexOf("$") != -1) { if (field.getType().isPrimitive() || field.getName().indexOf("$") != -1) {
continue; continue;
} }
......
...@@ -24,6 +24,7 @@ import org.h2.tools.SimpleResultSet; ...@@ -24,6 +24,7 @@ import org.h2.tools.SimpleResultSet;
import org.h2.util.SmallLRUCache; import org.h2.util.SmallLRUCache;
import org.h2.util.TempFileDeleter; import org.h2.util.TempFileDeleter;
import org.h2.util.Utils; import org.h2.util.Utils;
import org.h2.value.DataType;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueArray;
import org.h2.value.ValueBoolean; import org.h2.value.ValueBoolean;
...@@ -81,7 +82,12 @@ public class TestValueMemory extends TestBase implements DataHandler { ...@@ -81,7 +82,12 @@ public class TestValueMemory extends TestBase implements DataHandler {
trace(s); trace(s);
} }
for (int i = 0; i < Value.TYPE_COUNT; i++) { for (int i = 0; i < Value.TYPE_COUNT; i++) {
assertEquals(i, create(i).getType()); Value v = create(i);
if (v == ValueNull.INSTANCE && i == Value.GEOMETRY) {
// jts not in the classpath, OK
continue;
}
assertEquals(i, v.getType());
testType(i); testType(i);
} }
} }
...@@ -188,6 +194,9 @@ public class TestValueMemory extends TestBase implements DataHandler { ...@@ -188,6 +194,9 @@ public class TestValueMemory extends TestBase implements DataHandler {
case Value.STRING_FIXED: case Value.STRING_FIXED:
return ValueStringFixed.get(randomString(random.nextInt(100))); return ValueStringFixed.get(randomString(random.nextInt(100)));
case Value.GEOMETRY: case Value.GEOMETRY:
if (DataType.GEOMETRY_CLASS == null) {
return ValueNull.INSTANCE;
}
return ValueGeometry.get("POINT (" + random.nextInt(100) + " "+random.nextInt(100)+")"); return ValueGeometry.get("POINT (" + random.nextInt(100) + " "+random.nextInt(100)+")");
default: default:
throw new AssertionError("type=" + type); throw new AssertionError("type=" + type);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论