diff --git a/pom.xml b/pom.xml index a4b577e..2ee73f3 100644 --- a/pom.xml +++ b/pom.xml @@ -243,7 +243,10 @@ ${project.build.directory}/it src/it/settings.xml - ${project.build.directory}/local-repo + + ${project.build.directory}/local- repo ${project.version} ${project.basedir} diff --git a/src/it/test-standalone-jar/pom.xml b/src/it/test- standalone-jar/pom.xml similarity index 100% rename from src/it/test-standalone-jar/pom.xml rename to src/it/test- standalone-jar/pom.xml diff --git a/src/main/java/org/liblouis/EmbeddedTableResolver.java b/src/main/java/org/liblouis/EmbeddedTableResolver.java index 5b886b3..506527d 100644 --- a/src/main/java/org/liblouis/EmbeddedTableResolver.java +++ b/src/main/java/org/liblouis/EmbeddedTableResolver.java @@ -62,7 +62,8 @@ public URL resolve(String table, URL base) { return aggregatorTables.get(table); StringBuilder b = new StringBuilder(); for (String s : table.split(",")) - b.append("include ").append(s.replaceAll("\\\\", "\\\\\\\\")).append('\n'); + // replace "\" (file separator on Windows) with "\\" and " " (space in file path) with "\s" + b.append("include ").append(s.replaceAll("\\\\", "\\\\\\\\").replaceAll(" ", "\\\\s")).append('\n'); InputStream in = new ByteArrayInputStream(b.toString().getBytes(StandardCharsets.UTF_8)); try { File f = File.createTempFile("liblouis-java-", ".tbl"); diff --git a/src/main/java/org/liblouis/Louis.java b/src/main/java/org/liblouis/Louis.java index d28cb30..7d7c498 100644 --- a/src/main/java/org/liblouis/Louis.java +++ b/src/main/java/org/liblouis/Louis.java @@ -7,7 +7,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.net.URLDecoder; import java.nio.file.Files; import java.util.Collections; import java.util.HashMap; @@ -352,7 +351,7 @@ static File asFile(URL url) throws IllegalArgumentException { try { if (!"file".equals(url.getProtocol())) throw new RuntimeException("expected file URL"); - return new File(new URI("file", url.getPath(), null)); + return new File(url.toURI()); } catch (URISyntaxException e) { throw new RuntimeException(e); // should not happen } @@ -362,7 +361,7 @@ static File asFile(URL url) throws IllegalArgumentException { static URL asURL(File file) { try { file = file.getCanonicalFile(); - return new URL(URLDecoder.decode(file.toURI().toString().replace("+", "%2B"))); + return file.toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException(e); // should not happen } catch (IOException e) { diff --git a/src/test/java/org/liblouis/FindTranslatorTest.java b/src/test/java/org/liblouis/FindTranslatorTest.java index 47d5cdf..a933456 100644 --- a/src/test/java/org/liblouis/FindTranslatorTest.java +++ b/src/test/java/org/liblouis/FindTranslatorTest.java @@ -42,7 +42,7 @@ public void testListAvailableLocales() { } public FindTranslatorTest() { - File testRootDir = new File(this.getClass().getResource("/").getPath()); + File testRootDir = asFile(this.getClass().getResource("/")); final Set tables = new HashSet(); for (File f : new File(testRootDir, "tables").listFiles()) tables.add(f.getAbsolutePath()); diff --git a/src/test/java/org/liblouis/TableFromFileSystemTest.java b/src/test/java/org/liblouis/TableFromFileSystemTest.java index 871e91a..4ae5675 100644 --- a/src/test/java/org/liblouis/TableFromFileSystemTest.java +++ b/src/test/java/org/liblouis/TableFromFileSystemTest.java @@ -5,6 +5,8 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.liblouis.Louis.asFile; + public class TableFromFileSystemTest { @Test @@ -18,7 +20,7 @@ public void testTableFromFileSystemAbsolutePath() throws Exception { private final File tablesDir; public TableFromFileSystemTest() { - File testRootDir = new File(this.getClass().getResource("/").getPath()); + File testRootDir = asFile(this.getClass().getResource("/")); tablesDir = new File(testRootDir, "tables"); } } diff --git a/src/test/java/org/liblouis/TableResolverTest.java b/src/test/java/org/liblouis/TableResolverTest.java index 6c52b73..a05e876 100644 --- a/src/test/java/org/liblouis/TableResolverTest.java +++ b/src/test/java/org/liblouis/TableResolverTest.java @@ -8,6 +8,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.liblouis.Louis.asFile; import static org.liblouis.Louis.asURL; public class TableResolverTest { @@ -29,7 +30,7 @@ public void testIncludeMagicTokenTable() throws Exception { } public TableResolverTest() { - final File testRootDir = new File(this.getClass().getResource("/").getPath()); + final File testRootDir = asFile(this.getClass().getResource("/")); Louis.setTableResolver(new TableResolver() { public URL resolve(String table, URL base) { if (table == null) diff --git a/src/test/java/org/liblouis/ThreadsTest.java b/src/test/java/org/liblouis/ThreadsTest.java index 0c06dce..c49caca 100644 --- a/src/test/java/org/liblouis/ThreadsTest.java +++ b/src/test/java/org/liblouis/ThreadsTest.java @@ -5,6 +5,8 @@ import org.junit.Test; +import static org.liblouis.Louis.asFile; + public class ThreadsTest { // If liblouis-java is thread-safe, the test should finish without causing crashes. @@ -51,7 +53,7 @@ private static String generateString(Random rng, String characters, int length) private final File tablesDir; public ThreadsTest() { - File testRootDir = new File(this.getClass().getResource("/").getPath()); + File testRootDir = asFile(this.getClass().getResource("/")); tablesDir = new File(testRootDir, "tables"); } } diff --git a/src/test/java/org/liblouis/TranslatorTest.java b/src/test/java/org/liblouis/TranslatorTest.java index 957f2fc..f80434c 100644 --- a/src/test/java/org/liblouis/TranslatorTest.java +++ b/src/test/java/org/liblouis/TranslatorTest.java @@ -7,6 +7,7 @@ import org.junit.Test; import org.liblouis.DisplayTable.StandardDisplayTables; +import static org.liblouis.Louis.asFile; import static org.liblouis.Utilities.Hyphenation.insertHyphens; public class TranslatorTest { @@ -132,7 +133,7 @@ private int[] byteToInt(byte [] array) { private final File tablesDir; public TranslatorTest() { - File testRootDir = new File(this.getClass().getResource("/").getPath()); + File testRootDir = asFile(this.getClass().getResource("/")); tablesDir = new File(testRootDir, "tables"); } }