aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/mixins
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2024-04-22 11:45:08 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2024-04-22 11:45:08 +0200
commite76b3561bf60f62afcf4a4d667492beb85f35f85 (patch)
treeb98c2e9277a083699b5fbe14fc5e768506c1ca64 /src/main/java/at/hannibal2/skyhanni/mixins
parent59d5e664cd5cd5b6fc4a40d4ecfee3842871bb2e (diff)
downloadskyhanni-e76b3561bf60f62afcf4a4d667492beb85f35f85.tar.gz
skyhanni-e76b3561bf60f62afcf4a4d667492beb85f35f85.tar.bz2
skyhanni-e76b3561bf60f62afcf4a4d667492beb85f35f85.zip
Revert "Backend: Add unimined build system (#1456)"
This reverts commit 40309bc8acb7afb37bbc99d7a758c24ffd962b4c.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/mixins')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/init/SkyhanniMixinPlugin.java91
1 files changed, 89 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/init/SkyhanniMixinPlugin.java b/src/main/java/at/hannibal2/skyhanni/mixins/init/SkyhanniMixinPlugin.java
index eb4009ce5..1f1b0e1fe 100644
--- a/src/main/java/at/hannibal2/skyhanni/mixins/init/SkyhanniMixinPlugin.java
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/init/SkyhanniMixinPlugin.java
@@ -4,13 +4,24 @@ import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
+import java.util.stream.Stream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
public class SkyhanniMixinPlugin implements IMixinConfigPlugin {
@Override
public void onLoad(String mixinPackage) {
+
}
@Override
@@ -20,7 +31,7 @@ public class SkyhanniMixinPlugin implements IMixinConfigPlugin {
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
- return true;
+ return false;
}
@Override
@@ -28,9 +39,85 @@ public class SkyhanniMixinPlugin implements IMixinConfigPlugin {
}
+ public URL baseUrl(URL classUrl) {
+ String string = classUrl.toString();
+ if (classUrl.getProtocol().equals("jar")) {
+ try {
+ return new URL(string.substring(4).split("!")[0]);
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ if (string.endsWith(".class")) {
+ try {
+ return new URL(string.replace("\\", "/")
+ .replace(getClass().getCanonicalName().replace(".", "/") + ".class", ""));
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return classUrl;
+ }
+
+ String mixinBasePackage = "at.hannibal2.skyhanni.mixins.transformers.";
+ String mixinBaseDir = mixinBasePackage.replace(".", "/");
+
+ List<String> mixins = null;
+
+ public void tryAddMixinClass(String className) {
+ String norm = (className.endsWith(".class") ? className.substring(0, className.length() - ".class".length()) : className)
+ .replace("\\", "/")
+ .replace("/", ".");
+ if (norm.startsWith(mixinBasePackage) && !norm.endsWith(".")) {
+ mixins.add(norm.substring(mixinBasePackage.length()));
+ }
+ }
+
+ public void walkDir(Path file) {
+ System.out.println("Trying to find mixins from directory");
+ try (Stream<Path> classes = Files.walk(file.resolve(mixinBaseDir))) {
+ classes.map(it -> file.relativize(it).toString())
+ .forEach(this::tryAddMixinClass);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
@Override
public List<String> getMixins() {
- return new ArrayList<>();
+ if (mixins != null) return mixins;
+ System.out.println("Trying to discover mixins");
+ mixins = new ArrayList<>();
+ URL classUrl = getClass().getProtectionDomain().getCodeSource().getLocation();
+ System.out.println("Found classes at " + classUrl);
+ Path file;
+ try {
+ file = Paths.get(baseUrl(classUrl).toURI());
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ System.out.println("Base directory found at " + file);
+ if (Files.isDirectory(file)) {
+ walkDir(file);
+ } else {
+ walkJar(file);
+ }
+ System.out.println("Found mixins: " + mixins);
+
+ return mixins;
+ }
+
+ private void walkJar(Path file) {
+ System.out.println("Trying to find mixins from jar file");
+ try (ZipInputStream zis = new ZipInputStream(Files.newInputStream(file))) {
+ ZipEntry next;
+ while ((next = zis.getNextEntry()) != null) {
+ tryAddMixinClass(next.getName());
+ zis.closeEntry();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
}
@Override