From 07c61bd18c8b52d7e92e0c3a1e30c87a29c8c353 Mon Sep 17 00:00:00 2001 From: Bert Frees Date: Tue, 30 Apr 2024 14:15:17 +0200 Subject: [PATCH] Support Apple Silicon --- pom.xml | 24 +++++++++++++++---- src/it/test- standalone-jar/pom.xml | 1 + .../org/liblouis/EmbeddedTableResolver.java | 2 +- src/main/java/org/liblouis/Logger.java | 8 +++++++ src/main/java/org/liblouis/Louis.java | 17 +++++-------- .../java/org/liblouis/TranslatorTest.java | 2 +- 6 files changed, 36 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 6cff5d9..ae02f72 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.liblouis liblouis-java - 5.0.3-SNAPSHOT + 5.1.0-SNAPSHOT bundle liblouis-java JNA based Java bindings to liblouis, an open-source braille translator and back-translator. @@ -38,7 +38,7 @@ org.liblouis louis - 3.27.0-p1 + 3.27.0-p2 nar @@ -47,7 +47,7 @@ net.java.dev.jna jna - 5.2.0 + 5.14.0 org.slf4j @@ -118,6 +118,12 @@ x86_64-MacOSX-gpp-shared nar + + org.liblouis + louis + aarch64-MacOSX-gpp-shared + nar + org.liblouis louis @@ -157,7 +163,14 @@ liblouis.dylib - darwin + darwin-x86-64 + + + target/dependency/lib/aarch64-MacOSX-gpp/shared + + liblouis.dylib + + darwin-aarch64 target/dependency/lib/i386-Linux-gpp/shared @@ -232,7 +245,8 @@ org/liblouis/resource-files/tables=target/dependency/share/liblouis/tables, - darwin/liblouis.dylib=target/dependency/lib/x86_64-MacOSX-gpp/shared/liblouis.dylib, + darwin-x86-64/liblouis.dylib=target/dependency/lib/x86_64-MacOSX-gpp/shared/liblouis.dylib, + darwin-aarch64/liblouis.dylib=target/dependency/lib/aarch64-MacOSX-gpp/shared/liblouis.dylib, linux-x86/liblouis.so=target/dependency/lib/i386-Linux-gpp/shared/liblouis.so, linux-x86-64/liblouis.so=target/dependency/lib/amd64-Linux-gpp/shared/liblouis.so, win32-x86/liblouis.dll=target/dependency/bin/i686-w64-mingw32-gpp/liblouis.dll, diff --git a/src/it/test- standalone-jar/pom.xml b/src/it/test- standalone-jar/pom.xml index ba37a16..77617f3 100644 --- a/src/it/test- standalone-jar/pom.xml +++ b/src/it/test- standalone-jar/pom.xml @@ -42,6 +42,7 @@ maven-surefire-plugin + 2.12.4 pertest diff --git a/src/main/java/org/liblouis/EmbeddedTableResolver.java b/src/main/java/org/liblouis/EmbeddedTableResolver.java index 59a5b18..196b55c 100644 --- a/src/main/java/org/liblouis/EmbeddedTableResolver.java +++ b/src/main/java/org/liblouis/EmbeddedTableResolver.java @@ -42,7 +42,7 @@ class EmbeddedTableResolver implements TableResolver { EmbeddedTableResolver(org.slf4j.Logger logger) { tables = new HashMap(); File resourcesJarFile; { - URL knownResource = Louis.class.getClassLoader().getResource("darwin/liblouis.dylib"); + URL knownResource = Louis.class.getClassLoader().getResource("darwin-aarch64/liblouis.dylib"); if (knownResource == null) throw new RuntimeException("resources artifact not on classpath"); else if ("file".equals(knownResource.getProtocol())) diff --git a/src/main/java/org/liblouis/Logger.java b/src/main/java/org/liblouis/Logger.java index ff74b29..51cb5ab 100644 --- a/src/main/java/org/liblouis/Logger.java +++ b/src/main/java/org/liblouis/Logger.java @@ -22,6 +22,14 @@ private Level(int value) { int value() { return value; } + boolean above(Level threshold) { + if (threshold == OFF) + return false; + else if (threshold == ALL) + return true; + else + return value >= threshold.value; + } private static Map levels; static Level from(int value) { if (levels == null) { diff --git a/src/main/java/org/liblouis/Louis.java b/src/main/java/org/liblouis/Louis.java index dbbe224..05e095f 100644 --- a/src/main/java/org/liblouis/Louis.java +++ b/src/main/java/org/liblouis/Louis.java @@ -131,6 +131,7 @@ private File[] _invoke(String table, File base) { tableResolverIsRegistered = false; } + private static Logger.Level logLevel = Logger.Level.INFO; private static Logger logCallback = null; private static Lou_LogCallback lou_logCallback = null; private static boolean loggerIsRegistered = false; @@ -145,22 +146,16 @@ public void invoke(int level, String message) { loggerIsRegistered = false; } - public static void setLogLevel(Logger.Level level) { + public static synchronized void setLogLevel(Logger.Level level) { + logLevel = level; getLibrary().lou_setLogLevel(level.value()); } static void log(Logger.Level level, String format, Object... args) { Slf4jLogger.INSTANCE.log(level, format, args); LouisLibrary lib = getLibrary(); - if (logCallback != null && !(logCallback instanceof Slf4jLogger)) - if (args.length > 0) { - String[] message = new String[1 + args.length]; - message[0] = format; - for (int i = 0; i < args.length; i++) - message[1 + i] = args[i].toString(); - lib._lou_logMessage(level.value(), message); - } else - lib._lou_logMessage(level.value(), format); + if (logCallback != null && !(logCallback instanceof Slf4jLogger) && level.above(logLevel)) + logCallback.log(level, String.format(format, args)); } /** @@ -298,7 +293,7 @@ public int lou_backTranslate(String tableList, WideCharString inbuf, IntByRefere public String[] lou_listTables(); - public void _lou_logMessage(int level, String... format); + //public void _lou_logMessage(int level, String... format); public String[] lou_getEmphClasses(String tableList); diff --git a/src/test/java/org/liblouis/TranslatorTest.java b/src/test/java/org/liblouis/TranslatorTest.java index dddaa7d..39b880b 100644 --- a/src/test/java/org/liblouis/TranslatorTest.java +++ b/src/test/java/org/liblouis/TranslatorTest.java @@ -16,7 +16,7 @@ public class TranslatorTest { @Test public void testVersion() { assertEquals( - "3.27.0-p1", + "3.27.0-p2", Louis.getVersion()); }