Skip to content

Commit

Permalink
Remove LuaJ from Android dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
gudzpoz committed Apr 3, 2024
1 parent 2d583f5 commit 3982e58
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 54 deletions.
7 changes: 3 additions & 4 deletions android/android-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ ext {
luaVersions = ['lua51', 'lua52', 'lua53', 'lua54', 'luajit']
}

// Lint involves an outdated version of Kotlin, which cause weird errors.
lint.enabled = false

android {
namespace = project(':').group

Expand All @@ -38,7 +41,6 @@ android {
}
}


buildFeatures {
viewBinding true
}
Expand All @@ -53,21 +55,18 @@ android {
}

compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.9'
androidTestImplementation project(':luajava')
androidTestImplementation project(':lua51')
androidTestImplementation project(':lua52')
androidTestImplementation project(':lua53')
androidTestImplementation project(':lua54')
androidTestImplementation project(':luajit')
androidTestImplementation project(':luaj')
androidTestImplementation project(':example:suite')
androidTestImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:core:1.5.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import party.iroiro.luajava.lua53.Lua53;
import party.iroiro.luajava.lua54.Lua54;
import party.iroiro.luajava.luajit.LuaJit;
import party.iroiro.luajava.luaj.LuaJ;

public class AndroidLuaTest {
@Test
Expand Down Expand Up @@ -44,10 +43,4 @@ public void luaJitTest() {
}
}

@Test
public void luaJTest() {
try (LuaJ L = new LuaJ()) {
new LuaTestSuite<>(L, LuaJit::new).test();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import party.iroiro.luajava.lua53.Lua53;
import party.iroiro.luajava.lua54.Lua54;
import party.iroiro.luajava.luajit.LuaJit;
import party.iroiro.luajava.luaj.LuaJ;

public class AndroidScriptTest {
@Test
Expand Down Expand Up @@ -45,13 +44,6 @@ public void luaJitTest() {
}
}

@Test
public void luaJTest() {
try (LuaJ L = new LuaJ()) {
new LuaScriptSuite<>(L, s -> Log.i("test", s)).test();
}
}

@Test
public void memoryTest() {
//noinspection resource
Expand All @@ -61,7 +53,6 @@ public void memoryTest() {
new Lua53(),
new Lua54(),
new LuaJit(),
new LuaJ(),
};
for (Lua L : Ls) {
LuaScriptSuite.memoryTest(L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import party.iroiro.luajava.lua53.Lua53;
import party.iroiro.luajava.lua54.Lua54;
import party.iroiro.luajava.luajit.LuaJit;
import party.iroiro.luajava.luaj.LuaJ;
import party.iroiro.luajava.value.LuaValueSuite;

public class AndroidValueTest {
Expand Down Expand Up @@ -45,10 +44,4 @@ public void luaJitTest() {
}
}

@Test
public void luaJTest() {
try (LuaJ L = new LuaJ()) {
new LuaValueSuite<>(L).test();
}
}
}
24 changes: 24 additions & 0 deletions example/src/test/java/party/iroiro/luajava/NativesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package party.iroiro.luajava;

import org.junit.jupiter.api.Test;
import org.junit.platform.commons.annotation.Testable;
import party.iroiro.luajava.luaj.LuaJ;
import party.iroiro.luajava.luaj.LuaJNatives;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static party.iroiro.luajava.Lua.LuaType.USERDATA;

@Testable
public class NativesTest {
@Test
public void luaJNativesUserDataTest() {
try (LuaJ L = new LuaJ()) {
new LuaJNatives() {
{
lua_newuserdata(L.getPointer(), new Object());
}
};
assertEquals(USERDATA, L.type(-1));
}
}
}
1 change: 0 additions & 1 deletion example/suite/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ dependencies {
implementation project(':lua53')
implementation project(':lua54')
implementation project(':luajit')
implementation project(':luaj')
implementation 'junit:junit:4.13.2'
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package party.iroiro.luajava;

import party.iroiro.luajava.interfaces.LuaTestConsumer;
import party.iroiro.luajava.luaj.LuaJ;
import party.iroiro.luajava.suite.B;
import party.iroiro.luajava.suite.InvokeSpecialConversionTest;

Expand All @@ -26,6 +25,10 @@ default void test(@SuppressWarnings("ConstantConditions") Object obj) {
}
}
}

static boolean isLuaJ(Lua L) {
return L.getClass().getName().endsWith("LuaJ");
}

public interface DefaultRunnable extends Callable<Integer> {
@Override
Expand All @@ -50,7 +53,7 @@ default void throwsError() {
private final boolean isAndroid;

public DefaultProxyTest(AbstractLua L) {
defaultAvailable = isDefaultAvailable() && !(L instanceof LuaJ);
defaultAvailable = isDefaultAvailable() && !isLuaJ(L);
isAndroid = LuaScriptSuite.isAndroid();
this.L = L;
}
Expand Down Expand Up @@ -104,7 +107,7 @@ public void test() {
* Our classes are desugared on Android and fail the tests.
* Only java.* interfaces should be used to test default methods.
*/
if (L instanceof LuaJ) {
if (isLuaJ(L)) {
assertTrue(assertThrows(UnsupportedOperationException.class, proxy::call)
.getMessage().startsWith("invokespecial not available without JNI"));
} else if (defaultAvailable && !isAndroid) {
Expand All @@ -123,7 +126,7 @@ public void test() {
LuaException exception = assertThrows(LuaException.class, proxy::equals);
assertTrue(exception.getMessage().startsWith("method not implemented: "));

if (L instanceof LuaJ) {
if (isLuaJ(L)) {
assertTrue(assertThrows(UnsupportedOperationException.class, proxy::call)
.getMessage().startsWith("invokespecial not available without JNI"));
} else if (defaultAvailable && !isAndroid) {
Expand Down Expand Up @@ -167,7 +170,7 @@ public void remove() {
};
L.push(iterator, Lua.Conversion.SEMI);

assertThrows((Class<? extends Throwable>) ((defaultAvailable || L instanceof LuaJ)
assertThrows((Class<? extends Throwable>) ((defaultAvailable || isLuaJ(L))
? UnsupportedOperationException.class
: IncompatibleClassChangeError.class),
() -> L.invokeSpecial(iterator,
Expand Down Expand Up @@ -203,7 +206,7 @@ public void remove() {

L.run("return {}");
PrivateNullable priv = (PrivateNullable) L.createProxy(new Class[]{PrivateNullable.class}, Lua.Conversion.SEMI);
if (L instanceof LuaJ) {
if (isLuaJ(L)) {
assertTrue(
assertThrows(UnsupportedOperationException.class, () -> priv.test(null)).getMessage()
.contains("invokespecial not available without JNI")
Expand All @@ -219,7 +222,7 @@ public void remove() {
.startsWith("method not implemented: ")
);
}
if (L instanceof LuaJ) {
if (isLuaJ(L)) {
assertThrows(UnsupportedOperationException.class, () -> priv.test(new Object()));
} else if (defaultAvailable && !isAndroid) {
priv.test(new Object());
Expand All @@ -242,7 +245,7 @@ private void exceptionTest() {
L.run("return {}");
L.push(L.createProxy(new Class[]{A.class}, Lua.Conversion.SEMI), Lua.Conversion.NONE);
L.setGlobal("aa");
if (L instanceof LuaJ) {
if (isLuaJ(L)) {
assertEquals(RUNTIME, L.run("return aa:a() + 1"));
assertTrue(L.toString(-1), Objects.requireNonNull(L.toString(-1))
.contains("invokespecial not available without JNI"));
Expand Down Expand Up @@ -271,7 +274,7 @@ private void callForEachRemaining(Iterator<?> iter, LuaTestConsumer<Object> test
} catch (ClassNotFoundException ignored) {
} catch (NoSuchMethodException ignored) {
} catch (InvocationTargetException e) {
if (!(L instanceof LuaJ)) {
if (!(isLuaJ(L))) {
throw new RuntimeException(e);
}
} catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import party.iroiro.luajava.lua52.Lua52Natives;
import party.iroiro.luajava.lua53.Lua53Natives;
import party.iroiro.luajava.lua54.Lua54Natives;
import party.iroiro.luajava.luaj.LuaJ;
import party.iroiro.luajava.luaj.LuaJNatives;
import party.iroiro.luajava.luajit.LuaJitNatives;

import java.io.IOException;
Expand All @@ -16,6 +14,7 @@
import java.util.Objects;

import static org.junit.Assert.*;
import static party.iroiro.luajava.DefaultProxyTest.isLuaJ;
import static party.iroiro.luajava.Lua.LuaError.OK;
import static party.iroiro.luajava.Lua.LuaError.RUNTIME;

Expand Down Expand Up @@ -45,9 +44,9 @@ public static void addAssertThrows(Lua L) {
L.openLibrary("string");
L.openLibrary("debug");
assertEquals(OK, L.run(LUA_ASSERT_THROWS));
L.push(DefaultProxyTest.isDefaultAvailable() && !(L instanceof LuaJ));
L.push(DefaultProxyTest.isDefaultAvailable() && !(isLuaJ(L)));
L.setGlobal("JAVA8");
L.push(L instanceof LuaJ);
L.push(isLuaJ(L));
L.setGlobal("LUAJ");

// Android: desugar: default methods are separated into another class, failing the tests
Expand Down Expand Up @@ -103,12 +102,10 @@ public static boolean isAndroid() {
lua_newuserdata(L.getPointer(), 1024);
}
};
} else if (C instanceof LuaJNatives) {
new LuaJNatives() {
{
lua_newuserdata(L.getPointer(), new Object());
}
};
} else if (C.getClass().getName().endsWith("LuaJNatives")) {
// This is tested instead in NativesTest,
// because our Android build has trouble desugaring and cannot run LuaJ.
L.pushJavaObject(new Object());
} else {
fail("Not a supported natives");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import party.iroiro.luajava.interfaces.*;
import party.iroiro.luajava.lua51.Lua51;
import party.iroiro.luajava.luaj.LuaJ;
import party.iroiro.luajava.value.LuaValue;

import java.lang.reflect.Array;
Expand All @@ -15,6 +14,7 @@
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.Assert.*;
import static party.iroiro.luajava.DefaultProxyTest.isLuaJ;
import static party.iroiro.luajava.Lua.Conversion.FULL;
import static party.iroiro.luajava.Lua.Conversion.SEMI;
import static party.iroiro.luajava.Lua.LuaError.*;
Expand Down Expand Up @@ -198,7 +198,7 @@ private void testDump() {

// C functions
assertEquals(OK, L.run("return java.new"));
// assertTrue(L.isFunction(-1));
assertTrue(L.isFunction(-1));
assertNull(L.dump());
L.pop(1);

Expand Down Expand Up @@ -256,7 +256,7 @@ private void testGc() {
L.gc();
assertEquals(OK, L.run("return collectgarbage('count')"));
beforeGc.push();
if (!(L instanceof LuaJ)) {
if (!isLuaJ(L)) {
// LuaJ uses Java GC
assertTrue(L.lessThan(-2, -1));
}
Expand All @@ -278,7 +278,7 @@ private void testException() {
assertInstanceOf(RuntimeException.class, L.getJavaError());
assertEquals(message, Objects.requireNonNull(L.getJavaError()).getMessage());
L.run("java.import('java.lang.String')");
if (!(L instanceof LuaJ)) {
if (!isLuaJ(L)) {
assertNull(L.getJavaError());
}

Expand Down
7 changes: 4 additions & 3 deletions example/suite/src/main/resources/suite/proxyTest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ end
if LUAJ then
expects = 'invokespecial not available'
end
assertThrows(expects, iter.remove, iter)
assertThrows(ANDROID and "UnsupportedOperationException" or expects, iter.remove, iter)
res = {}
if JAVA8 then
iter:forEachRemaining(function(this, e) res[e] = true end)
Expand All @@ -78,7 +78,7 @@ B = java.proxy('party.iroiro.luajava.suite.B', 'party.iroiro.luajava.DefaultProx
if JAVA8 and not ANDROID then
return java.method(B, 'party.iroiro.luajava.suite.B:b')()
else
assertThrows(expects, java.method(B, 'party.iroiro.luajava.suite.B:b'))
assertThrows(LUAJ and expects or 'java.lang.IncompatibleClassChangeError', java.method(B, 'party.iroiro.luajava.suite.B:b'))
return 3
end
end
Expand Down Expand Up @@ -114,7 +114,8 @@ obj = java.proxy('party.iroiro.luajava.DefaultProxyTest.D', {
if JAVA8 and not ANDROID then
assert(java.method(iter, 'party.iroiro.luajava.DefaultProxyTest.D:noReturn')() == nil)
else
assertThrows(expects, java.method(iter, 'party.iroiro.luajava.DefaultProxyTest.D:noReturn'))
assertThrows(LUAJ and expects or 'java.lang.IncompatibleClassChangeError',
java.method(iter, 'party.iroiro.luajava.DefaultProxyTest.D:noReturn'))
end
end
})
Expand Down

0 comments on commit 3982e58

Please sign in to comment.