This is an automated email from the ASF dual-hosted git repository.

mawiesne pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opennlp-sandbox.git


The following commit(s) were added to refs/heads/main by this push:
     new 4f2cd24  fixes an 'Illegal char <:> at index 2' problem for CS 
connector tests, raised on Win* environments
4f2cd24 is described below

commit 4f2cd24bcfd69e487c7b9aab731bd0e56427d866
Author: Martin Wiesner <[email protected]>
AuthorDate: Sun Apr 27 18:35:45 2025 +0200

    fixes an 'Illegal char <:> at index 2' problem for CS connector tests, 
raised on Win* environments
---
 .../corpus_server/connector/AbstractCSTest.java    | 25 ++++++++++++++++------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git 
a/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/AbstractCSTest.java
 
b/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/AbstractCSTest.java
index c596950..00390b8 100644
--- 
a/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/AbstractCSTest.java
+++ 
b/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/AbstractCSTest.java
@@ -21,8 +21,12 @@ import 
org.apache.opennlp.corpus_server.impl.DerbyCorporaStore;
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Comparator;
 
 public abstract class AbstractCSTest {
@@ -35,16 +39,23 @@ public abstract class AbstractCSTest {
     org.slf4j.bridge.SLF4JBridgeHandler.install();
   }
 
-  protected static final String BASE_PATH = 
CSCollectionReaderTest.class.getProtectionDomain().getCodeSource().getLocation().toExternalForm();
+  protected static final URL BASE_LOCATION = 
AbstractCSTest.class.getProtectionDomain().getCodeSource().getLocation();
+  protected static final String BASE_PATH = BASE_LOCATION.toExternalForm();
 
   protected static void cleanTestDB() throws IOException {
-    String baseDir = BASE_PATH.replace("file:", "").replace("/test-classes", 
"");
-    String dbDir = baseDir + DerbyCorporaStore.DB_NAME;
-    Path p = Path.of(dbDir);
-    if (p.toFile().exists()) {
-      try (var dirStream = Files.walk(p)) {
-        
dirStream.map(Path::toFile).sorted(Comparator.reverseOrder()).forEach(File::delete);
+    try {
+      URI baseURI = BASE_LOCATION.toURI();
+      String mainPath = Paths.get(baseURI).toString().
+              replace("file:", "").replace("/test-classes", "");
+      String dbDir = mainPath + File.separator + DerbyCorporaStore.DB_NAME;
+      Path p = Path.of(dbDir);
+      if (p.toFile().exists()) {
+        try (var dirStream = Files.walk(p)) {
+          
dirStream.map(Path::toFile).sorted(Comparator.reverseOrder()).forEach(File::delete);
+        }
       }
+    } catch (URISyntaxException e) {
+      throw new IOException("Can't clean Test DB!", e);
     }
   }
 }

Reply via email to