Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion luaj-jse/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,38 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<!-- Don’t generate a dependency-reduced-pom (avoids messing up parent pom) -->
<createDependencyReducedPom>false</createDependencyReducedPom>
<relocations>
<!-- Optional: relocate luaj-core to avoid conflicts -->
<!--
<relocation>
<pattern>org.luaj.vm2</pattern>
<shadedPattern>my.shaded.org.luaj.vm2</shadedPattern>
</relocation>
-->
</relocations>
<transformers>
<!-- Fix MANIFEST.MF so you can run with java -jar -->
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.luaj.vm2.Lua</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.helger.maven</groupId>
<artifactId>ph-javacc-maven-plugin</artifactId>
Expand Down Expand Up @@ -71,7 +103,15 @@
</execution>
</executions>
</plugin>
</plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
5 changes: 4 additions & 1 deletion luaj-jse/src/main/java/org/luaj/vm2/lib/jse/JavaMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
******************************************************************************/
package org.luaj.vm2.lib.jse;

import java.lang.reflect.InaccessibleObjectException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
Expand Down Expand Up @@ -60,13 +61,15 @@ static LuaFunction forMethods(JavaMethod[] m) {

final Method method;

private final boolean test = false;

private JavaMethod(Method m) {
super(m.getParameterTypes(), m.getModifiers());
this.method = m;
try {
if (!m.isAccessible())
m.setAccessible(true);
} catch (SecurityException s) {
} catch (SecurityException | InaccessibleObjectException ignored) {
}
}

Expand Down
14 changes: 12 additions & 2 deletions luaj-jse/src/main/java/org/luaj/vm2/lib/jse/LuajavaLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public class LuajavaLib extends VarArgFunction {

static final int METHOD_MODIFIERS_VARARGS = 0x80;

private ClassLoader classloader;

public LuajavaLib(final ClassLoader classloader) {
this.classloader = classloader;
}

public LuajavaLib() {
}

Expand Down Expand Up @@ -151,7 +157,7 @@ public Varargs invoke(Varargs args) {
InvocationHandler handler = new ProxyInvocationHandler(lobj);

// create the proxy object
Object proxy = Proxy.newProxyInstance(getClass().getClassLoader(), ifaces, handler);
Object proxy = Proxy.newProxyInstance(this.classloader == null ? getClass().getClassLoader() : this.classloader, ifaces, handler);

// return the proxy
return LuaValue.userdataOf(proxy);
Expand Down Expand Up @@ -183,7 +189,11 @@ public Varargs invoke(Varargs args) {

// load classes using app loader to allow luaj to be used as an extension
protected Class classForName(String name) throws ClassNotFoundException {
return Class.forName(name, true, ClassLoader.getSystemClassLoader());
return Class.forName(name, true, this.classloader == null ? getClass().getClassLoader() : this.classloader);
}

public void setClassloader(final ClassLoader classloader) {
this.classloader = classloader;
}

private static final class ProxyInvocationHandler implements InvocationHandler {
Expand Down