Skip to content

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Feb 23, 2021
2 parents e83b718 + b1ec92a commit 18c1d15
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 19 deletions.
15 changes: 9 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,6 @@
<artifactId>maven-jdk-tools-wrapper</artifactId>
<version>0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.nqzero/permit-reflect -->
<dependency>
<groupId>com.nqzero</groupId>
<artifactId>permit-reflect</artifactId>
<version>0.4</version>
</dependency>
<!--- Testing -->
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
Expand Down Expand Up @@ -525,6 +519,15 @@
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>java/**</exclude>
</excludes>
</configuration>
</plugin>
<!-- Bug/quality enforcement
mvn spotbugs:spotbugs - create report
mvn spotbugs:gui - show gui
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/java/lang/Module.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package java.lang;

import java.util.Set;

/**
* Dummy java compatibility class
*
* @author Matt
*/
public abstract class Module {

//CHECKSTYLE:OFF
public ModuleLayer getLayer() { throw new UnsupportedOperationException(); }
public Set<String> getPackages() { throw new UnsupportedOperationException(); }
//CHECKSTYLE:ON
}
20 changes: 20 additions & 0 deletions src/main/java/java/lang/ModuleLayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package java.lang;

import java.util.Set;

/**
* Dummy java compatibility class
*
* @author xxDark
*/
public abstract class ModuleLayer {

//CHECKSTYLE:OFF
public Set<Module> modules() {
throw new UnsupportedOperationException();
}
public static ModuleLayer boot() {
throw new UnsupportedOperationException();
}
//CHECKSTYLE:ON
}
8 changes: 0 additions & 8 deletions src/main/java/java/lang/module/Module.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/java/lang/module/ModuleFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public interface ModuleFinder {
//CHECKSTYLE:OFF
static ModuleFinder ofSystem() {
return null;
throw new UnsupportedOperationException();
}
Set<ModuleReference> findAll();
//CHECKSTYLE:ON
Expand Down
65 changes: 65 additions & 0 deletions src/main/java/me/coley/recaf/util/Java9Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package me.coley.recaf.util;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
import java.lang.reflect.Field;

/**
* Package-private util to deal with modules.
*
* @author xxDark
*/
final class Java9Util {

private static final MethodHandle CLASS_MODULE;
private static final MethodHandle CLASS_LOADER_MDOULE;

/**
* Deny all constructions.
*/
private Java9Util() {
}

/**
* @param klass {@link Class} to get module from.
* @return {@link Module} of the class.
*/
static Module getClassModule(Class<?> klass) {
try {
return (Module) CLASS_MODULE.invokeExact(klass);
} catch (Throwable t) {
// That should never happen.
throw new AssertionError(t);
}
}


/**
* @param loader {@link ClassLoader} to get module from.
* @return {@link Module} of the class.
*/
static Module getLoaderModule(ClassLoader loader) {
try {
return (Module) CLASS_LOADER_MDOULE.invokeExact(loader);
} catch (Throwable t) {
// That should never happen.
throw new AssertionError(t);
}
}

static {
try {
Field field = Lookup.class.getDeclaredField("IMPL_LOOKUP");
field.setAccessible(true);
MethodHandles.publicLookup();
Lookup lookup = (Lookup) field.get(null);
MethodType type = MethodType.methodType(Module.class);
CLASS_MODULE = lookup.findVirtual(Class.class, "getModule", type);
CLASS_LOADER_MDOULE = lookup.findVirtual(ClassLoader.class, "getUnnamedModule", type);
} catch (NoSuchMethodException | IllegalAccessException | NoSuchFieldException ex) {
throw new ExceptionInInitializerError(ex);
}
}
}
35 changes: 32 additions & 3 deletions src/main/java/me/coley/recaf/util/VMUtil.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.coley.recaf.util;

import com.nqzero.permit.Permit;
import com.sun.javafx.application.PlatformImpl;
import java.util.HashSet;
import javafx.application.Platform;

import java.io.IOException;
Expand Down Expand Up @@ -212,12 +212,41 @@ public static Path getJavaPath() {
*/
public static void patch() {
if (getVmVersion() > 8) {
Permit.godMode();
Permit.unLog();
openPackages();
patchReflectionFilters();
}
}

/**
* Opens all packages.
*/
private static void openPackages() {
try {
Method export = Module.class.getDeclaredMethod("implAddOpens",String.class);
export.setAccessible(true);
HashSet<Module> modules = new HashSet<>();
Class<?> classBase = VMUtil.class;
Module base = Java9Util.getClassModule(classBase);
if (base.getLayer() != null)
modules.addAll(base.getLayer().modules());
modules.addAll(ModuleLayer.boot().modules());
for (ClassLoader cl = classBase.getClassLoader(); cl != null; cl = cl.getParent()) {
modules.add(Java9Util.getLoaderModule(cl));
}
for (Module module : modules) {
for (String name : module.getPackages()) {
try {
export.invoke(module, name);
} catch (Exception ex) {
Log.error(ex, "Could not export package {} in module {}", name, module);
}
}
}
} catch (Exception ex) {
Log.error(ex, "Could not export packages");
}
}

/**
* Patches reflection filters.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;
import java.lang.instrument.UnmodifiableClassException;
import java.lang.module.Module;
import java.security.ProtectionDomain;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
Expand Down

0 comments on commit 18c1d15

Please sign in to comment.