Skip to content

Commit

Permalink
Support Apple Silicon
Browse files Browse the repository at this point in the history
  • Loading branch information
bertfrees committed May 1, 2024
1 parent 005e203 commit 07c61bd
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 18 deletions.
24 changes: 19 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.liblouis</groupId>
<artifactId>liblouis-java</artifactId>
<version>5.0.3-SNAPSHOT</version>
<version>5.1.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>liblouis-java</name>
<description>JNA based Java bindings to liblouis, an open-source braille translator and back-translator.</description>
Expand Down Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>org.liblouis</groupId>
<artifactId>louis</artifactId>
<version>3.27.0-p1</version>
<version>3.27.0-p2</version>
<type>nar</type>
</dependency>
</dependencies>
Expand All @@ -47,7 +47,7 @@
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.2.0</version>
<version>5.14.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down Expand Up @@ -118,6 +118,12 @@
<classifier>x86_64-MacOSX-gpp-shared</classifier>
<type>nar</type>
</artifactItem>
<artifactItem>
<groupId>org.liblouis</groupId>
<artifactId>louis</artifactId>
<classifier>aarch64-MacOSX-gpp-shared</classifier>
<type>nar</type>
</artifactItem>
<artifactItem>
<groupId>org.liblouis</groupId>
<artifactId>louis</artifactId>
Expand Down Expand Up @@ -157,7 +163,14 @@
<includes>
<include>liblouis.dylib</include>
</includes>
<targetPath>darwin</targetPath>
<targetPath>darwin-x86-64</targetPath>
</resource>
<resource>
<directory>target/dependency/lib/aarch64-MacOSX-gpp/shared</directory>
<includes>
<include>liblouis.dylib</include>
</includes>
<targetPath>darwin-aarch64</targetPath>
</resource>
<resource>
<directory>target/dependency/lib/i386-Linux-gpp/shared</directory>
Expand Down Expand Up @@ -232,7 +245,8 @@
<Export-Package />
<Include-Resource>
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,
Expand Down
1 change: 1 addition & 0 deletions src/it/test- standalone-jar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<forkMode>pertest</forkMode>
<systemPropertyVariables>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/liblouis/EmbeddedTableResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class EmbeddedTableResolver implements TableResolver {
EmbeddedTableResolver(org.slf4j.Logger logger) {
tables = new HashMap<String,URL>();
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()))
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/liblouis/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer,Level> levels;
static Level from(int value) {
if (levels == null) {
Expand Down
17 changes: 6 additions & 11 deletions src/main/java/org/liblouis/Louis.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}

/**
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/liblouis/TranslatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class TranslatorTest {
@Test
public void testVersion() {
assertEquals(
"3.27.0-p1",
"3.27.0-p2",
Louis.getVersion());
}

Expand Down

0 comments on commit 07c61bd

Please sign in to comment.