refactor(nativelib): implement JVM-wide native library availability checks and management (#790)
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package org.booklore.test;
|
||||
|
||||
import org.booklore.nativelib.NativeLibraries;
|
||||
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
|
||||
import org.junit.jupiter.api.extension.ExecutionCondition;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
/**
|
||||
* Enables tests only when epub4j-native binaries are available on the current
|
||||
* platform.
|
||||
*
|
||||
* <p>Delegates to the JVM-wide native-library loader singleton.
|
||||
*/
|
||||
public class EpubNativeAvailableCondition implements ExecutionCondition {
|
||||
|
||||
private static final ConditionEvaluationResult ENABLED =
|
||||
ConditionEvaluationResult.enabled("epub4j-native library is available");
|
||||
|
||||
private static final ConditionEvaluationResult DISABLED =
|
||||
ConditionEvaluationResult.disabled("epub4j-native library not available on this platform");
|
||||
|
||||
@Override
|
||||
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
|
||||
return NativeLibraries.get().isEpubNativeAvailable() ? ENABLED : DISABLED;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,26 @@
|
||||
package org.booklore.test;
|
||||
|
||||
import org.grimmory.pdfium4j.PdfiumLibrary;
|
||||
import org.booklore.nativelib.NativeLibraries;
|
||||
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
|
||||
import org.junit.jupiter.api.extension.ExecutionCondition;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
/**
|
||||
* Enables tests only when PDFium native binaries are available on the current
|
||||
* platform.
|
||||
*
|
||||
* <p>Delegates to the JVM-wide native-library loader singleton.
|
||||
*/
|
||||
public class PdfiumAvailableCondition implements ExecutionCondition {
|
||||
|
||||
private static final ConditionEvaluationResult ENABLED =
|
||||
ConditionEvaluationResult.enabled("PDFium native library is available");
|
||||
|
||||
private static final Boolean AVAILABLE = probe();
|
||||
|
||||
private static Boolean probe() {
|
||||
try {
|
||||
PdfiumLibrary.initialize();
|
||||
return true;
|
||||
} catch (Exception | UnsatisfiedLinkError e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private static final ConditionEvaluationResult DISABLED =
|
||||
ConditionEvaluationResult.disabled("PDFium native library not available on this platform");
|
||||
|
||||
@Override
|
||||
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
|
||||
if (Boolean.TRUE.equals(AVAILABLE)) {
|
||||
return ENABLED;
|
||||
}
|
||||
return ConditionEvaluationResult.disabled("PDFium native library not available on this platform");
|
||||
return NativeLibraries.get().isPdfiumAvailable() ? ENABLED : DISABLED;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user