Skip to content

Commit

Permalink
Work on reflections for VersionCompatProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauriichan committed Jan 20, 2022
1 parent 8870670 commit c46dc3c
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 121 deletions.
110 changes: 54 additions & 56 deletions vcompat-api/pom.xml
Original file line number Diff line number Diff line change
@@ -1,63 +1,61 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-parent</artifactId>
<version>3.0.0</version>
</parent>
<artifactId>vcompat-api</artifactId>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-parent</artifactId>
<version>3.0.0</version>
</parent>
<artifactId>vcompat-api</artifactId>

<dependencies>
<dependencies>

<!-- Syntax Api -->
<!-- Syntax Api -->

<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>java</artifactId>
<version>2.0.14</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>nbt</artifactId>
<version>2.0.12</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>version</artifactId>
<version>2.0.12</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>key</artifactId>
<version>2.0.11</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>random</artifactId>
<version>2.0.11</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>logging</artifactId>
<version>2.0.11</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>json-lib</artifactId>
<version>2.0.11</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>java</artifactId>
<version>2.0.14</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>nbt</artifactId>
<version>2.0.12</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>version</artifactId>
<version>2.0.12</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>key</artifactId>
<version>2.0.11</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>random</artifactId>
<version>2.0.11</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>logging</artifactId>
<version>2.0.11</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>json-lib</artifactId>
<version>2.0.11</version>
</dependency>

<!-- Minecraft -->
<!-- Minecraft -->

<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>2.12.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>2.12.1</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
Expand Down Expand Up @@ -93,4 +91,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.sourcewriters.minecraft.vcompat;

import com.syntaxphoenix.syntaxapi.utils.java.Exceptions;
import com.syntaxphoenix.syntaxapi.utils.java.tools.Container;

import net.sourcewriters.minecraft.vcompat.provider.VersionControl;
Expand All @@ -9,26 +10,35 @@
public abstract class VersionCompatProvider {

protected static final Container<VersionCompatProvider> PROVIDER = Container.of();
private static final String IMPLEMENTATION_PATH = VersionCompatProvider.class.getPackageName() + ".VersionCompat";

public static VersionCompatProvider get() {
if (PROVIDER.isPresent()) {
return PROVIDER.get();
}
Object object = ReflectionTools.createInstance(ReflectionTools.getClass(VersionCompatProvider.class.getPackageName() + ".VersionCompat"));
if (object == null || !(object instanceof VersionCompatProvider)) {
try {
Class<?> clazz = ReflectionTools.getClass(IMPLEMENTATION_PATH);
System.out.println("Class: " + (clazz == null));
System.out.println("Class: " + IMPLEMENTATION_PATH);
Object object = clazz.getConstructor().newInstance();
if (object == null || !(object instanceof VersionCompatProvider)) {
throw new IllegalStateException("Can't initialize VersionCompatProvider!");
}
return PROVIDER.replace((VersionCompatProvider) object).lock().get();
} catch (Exception exp) {
System.out.println(Exceptions.stackTraceToString(exp));
throw new IllegalStateException("Can't initialize VersionCompatProvider!");
}
return PROVIDER.replace((VersionCompatProvider) object).lock().get();
}

protected final ClassLookupProvider lookupProvider = new ClassLookupProvider();

/*
* Impl
*/

public abstract VersionControl getControl();

public final ClassLookupProvider getLookupProvider() {
return lookupProvider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static Class<?> arrayclass(Class<?> clazz) {

public static Class<?> getClass(String classPath) {
try {
return Class.forName(classPath);
return Class.forName(classPath, true, null);
} catch (ClassNotFoundException ignored) {
return null;
}
Expand Down
108 changes: 53 additions & 55 deletions vcompat-core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-parent</artifactId>
<version>3.0.0</version>
</parent>
<artifactId>vcompat</artifactId>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-parent</artifactId>
<version>3.0.0</version>
</parent>
<artifactId>vcompat</artifactId>

<dependencies>
<dependencies>

<!-- vCompat Api -->

Expand All @@ -36,48 +34,48 @@
<artifactId>vcompat-1_18_R1</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
</dependencies>

<build>
<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>
<relocations>
<relocation>
<pattern>com.syntaxphoenix.syntaxapi</pattern>
<shadedPattern>net.sourcewriters.minecraft.vcompat.shaded.syntaxapi</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M2</version>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
<build>
<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>
<relocations>
<relocation>
<pattern>com.syntaxphoenix.syntaxapi</pattern>
<shadedPattern>net.sourcewriters.minecraft.vcompat.shaded.syntaxapi</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M2</version>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import net.sourcewriters.minecraft.vcompat.version.Versions;
import net.sourcewriters.minecraft.vcompat.util.java.tools.ReflectionTools;

final class VersionCompat extends VersionCompatProvider {

public static final String CLASSPATH = "%s.provider.impl.v%s.VersionControl%s";
public final class VersionCompat extends VersionCompatProvider {
private static final String VERSION_PATH = String.format("%s.provider.impl.v%s.VersionControl%s", VersionCompat.class.getPackageName(), Versions.getServerAsString(), Versions.getServerAsString());

private final VersionControl control;

Expand All @@ -16,7 +16,7 @@ public VersionCompat() {
}

private final VersionControl initControl() {
Object object = ReflectionTools.createInstance(ReflectionTools.getClass(String.format(CLASSPATH, VersionCompat.class.getPackageName(), Versions.getServerAsString(), Versions.getServerAsString())));
Object object = ReflectionTools.createInstance(ReflectionTools.getClass(VERSION_PATH));
if (object == null || !(object instanceof VersionControl)) {
throw new IllegalStateException("Can't initialize VersionControl");
}
Expand Down

0 comments on commit c46dc3c

Please sign in to comment.