Skip to content

Commit

Permalink
Fix class load
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauriichan committed Jan 20, 2022
1 parent 6f8df0b commit 8d2685e
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
67 changes: 67 additions & 0 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-updater</artifactId>
<name>vCompatUpdater</name>
<version>1.0.0</version>
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<createDependencyReducedPom>true</createDependencyReducedPom>
<relocations>
<relocation>
<pattern>com.syntaxphoenix.syntaxapi</pattern>
<shadedPattern>net.sourcewriters.minecraft.vcompat.updater.shaded.syntaxapi</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub OWNER Apache Maven Packages</name>
<url>https://maven.pkg.github.com/SourceWriters/vCompatUpdater</url>
</repository>
</distributionManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private CompatUpdater() {
}

public CompatClassLoader getClassLoader() {
return classLoader == null ? new CompatClassLoader(ClassLoader.getSystemClassLoader()) : classLoader;
return classLoader == null ? new CompatClassLoader(getClass().getClassLoader()) : classLoader;
}

public void register(CompatApp app) {
Expand Down Expand Up @@ -130,6 +130,47 @@ public void unregister(CompatApp app) {
} finally {
write.unlock();
}
read.lock();
try {
if(apps.isEmpty()) {
shutdown();
}
} finally {
read.unlock();
}
}

private void shutdown() {
try {
Class<?> control = getClass("net.sourcewriters.minecraft.vcompat.reflection.VersionControl");
if (control != null) {
control.getMethod("shutdown").invoke(control.getMethod("get").invoke(null));
return;
}
Class<?> provider = getClass("net.sourcewriters.minecraft.vcompat.VersionCompatProvider");
control = getClass("net.sourcewriters.minecraft.vcompat.provider.VersionControl");
if(provider != null && control != null) {
Object providerObj = provider.getMethod("get").invoke(null);
control.getMethod("shutdown").invoke(provider.getMethod("getControl").invoke(providerObj));
}
} catch(Exception e) {
// Ignore
}
try {
classLoader.close();
} catch (IOException e) {
// Ignore
}
classLoader = null;
state = State.NONE;
}

private Class<?> getClass(String name) {
try {
return Class.forName(name, false, ClassLoader.getSystemClassLoader());
} catch (ClassNotFoundException e) {
return null;
}
}

public boolean isRegistered(String id) {
Expand Down

0 comments on commit 8d2685e

Please sign in to comment.