Skip to content

Commit

Permalink
fix: update gradle & use Muon environment types
Browse files Browse the repository at this point in the history
  • Loading branch information
sylv256 committed Aug 15, 2024
1 parent bffc9bc commit 7aff934
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 42 deletions.
30 changes: 15 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ plugins {
id "net.minecrell.licenser" version "0.4.1"
}

sourceCompatibility = 1.8

def ENV = System.getenv()
version = "0.6.2" + (ENV.GITHUB_ACTIONS ? "" : "+local")
version = "0.6.3" + (ENV.GITHUB_ACTIONS ? "" : "+local")

group = 'net.fabricmc'
archivesBaseName = project.name.toLowerCase()
base.archivesName = project.name.toLowerCase()

repositories {
mavenCentral()
Expand All @@ -35,7 +33,7 @@ dependencies {
ship 'org.ow2.asm:asm-tree:9.1'
ship 'org.ow2.asm:asm-util:9.1'
ship 'net.fabricmc:tiny-mappings-parser:0.3.0+build.17'
implementation 'com.google.guava:guava:28.0-jre'
implementation 'com.google.guava:guava:32.0.0-jre'
compileOnly 'org.jetbrains:annotations:20.1.0'

enigma 'cuchaz:enigma:0.23.2'
Expand All @@ -57,7 +55,7 @@ jar {
}
}

task allJar(type: Jar) {
tasks.register('allJar', Jar) {
from {
configurations.ship.collect {
it.isDirectory() ? it : zipTree(it)
Expand All @@ -74,6 +72,8 @@ task allJar(type: Jar) {

java {
withSourcesJar()
sourceCompatibility = 8
targetCompatibility = 8
}

tasks.withType(JavaCompile).configureEach {
Expand Down Expand Up @@ -112,15 +112,15 @@ test {
}

// A task to ensure that the version being released has not already been released.
task checkVersion {
// doFirst {
// def xml = new URL("https://maven.fabricmc.net/net/fabricmc/stitch/maven-metadata.xml").text
// def metadata = new XmlSlurper().parseText(xml)
// def versions = metadata.versioning.versions.version*.text();
// if (versions.contains(version)) {
// throw new RuntimeException("${version} has already been released!")
// }
// }
tasks.register('checkVersion') {
doFirst {
def xml = new URL("https://maven.muonmc.org/net/fabricmc/stitch/maven-metadata.xml").text
def metadata = new XmlSlurper().parseText(xml)
def versions = metadata.versioning.versions.version*.text();
if (versions.contains(version)) {
throw new RuntimeException("${version} has already been released!")
}
}
}

publish.mustRunAfter checkVersion
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name = stitch
description = Fabric auxillary Tiny tools
url = https://github.com/FabricMC/stitch
url = https://github.com/MuonMC/stitch
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
44 changes: 19 additions & 25 deletions src/main/java/net/fabricmc/stitch/merge/ClassMerger.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
import java.util.*;

public class ClassMerger {
private static final String SIDE_DESCRIPTOR = "Lnet/fabricmc/api/EnvType;";
private static final String ITF_DESCRIPTOR = "Lnet/fabricmc/api/EnvironmentInterface;";
private static final String ITF_LIST_DESCRIPTOR = "Lnet/fabricmc/api/EnvironmentInterfaces;";
private static final String SIDED_DESCRIPTOR = "Lnet/fabricmc/api/Environment;";
private static final String CLIENT_ONLY_DESCRIPTOR = "org/muonmc/loader/api/game/minecraft/ClientOnly";
private static final String DEDICATED_SERVER_ONLY_DESCRIPTOR = "org/muonmc/loader/api/game/minecraft/DedicatedServerOnly";

private abstract class Merger<T> {
private final Map<String, T> entriesClient, entriesServer;
Expand All @@ -45,7 +43,7 @@ public Merger(List<T> entriesClient, List<T> entriesServer) {
public abstract String getName(T entry);
public abstract void applySide(T entry, String side);

private final List<String> toMap(List<T> entries, Map<String, T> map) {
private List<String> toMap(List<T> entries, Map<String, T> map) {
List<String> list = new ArrayList<>(entries.size());
for (T entry : entries) {
String name = getName(entry);
Expand Down Expand Up @@ -73,16 +71,20 @@ public void merge(List<T> list) {
}
}

private static void visitSideAnnotation(AnnotationVisitor av, String side) {
av.visitEnum("value", SIDE_DESCRIPTOR, side.toUpperCase(Locale.ROOT));
av.visitEnd();
private static String getSidedDescriptor(String side) {
switch (side) {
case "CLIENT":
return CLIENT_ONLY_DESCRIPTOR;
case "SERVER":
return DEDICATED_SERVER_ONLY_DESCRIPTOR;
default:
throw new RuntimeException("Invalid side " + side);
}
}

private static void visitItfAnnotation(AnnotationVisitor av, String side, List<String> itfDescriptors) {
for (String itf : itfDescriptors) {
AnnotationVisitor avItf = av.visitAnnotation(null, ITF_DESCRIPTOR);
avItf.visitEnum("value", SIDE_DESCRIPTOR, side.toUpperCase(Locale.ROOT));
avItf.visit("itf", Type.getType("L" + itf + ";"));
for (String ignored : itfDescriptors) {
AnnotationVisitor avItf = av.visitAnnotation(null, getSidedDescriptor(side));
avItf.visitEnd();
}
}
Expand All @@ -97,8 +99,7 @@ public SidedClassVisitor(int api, ClassVisitor cv, String side) {

@Override
public void visitEnd() {
AnnotationVisitor av = cv.visitAnnotation(SIDED_DESCRIPTOR, true);
visitSideAnnotation(av, side);
cv.visitAnnotation(getSidedDescriptor(side), true);
super.visitEnd();
}
}
Expand Down Expand Up @@ -169,17 +170,12 @@ public byte[] merge(byte[] classClient, byte[] classServer) {
}

if (!clientItfs.isEmpty() || !serverItfs.isEmpty()) {
AnnotationVisitor envInterfaces = nodeOut.visitAnnotation(ITF_LIST_DESCRIPTOR, false);
AnnotationVisitor eiArray = envInterfaces.visitArray("value");

if (!clientItfs.isEmpty()) {
visitItfAnnotation(eiArray, "CLIENT", clientItfs);
// do nothing
}
if (!serverItfs.isEmpty()) {
visitItfAnnotation(eiArray, "SERVER", serverItfs);
// do nothing
}
eiArray.visitEnd();
envInterfaces.visitEnd();
}

new Merger<InnerClassNode>(nodeC.innerClasses, nodeS.innerClasses) {
Expand All @@ -201,8 +197,7 @@ public String getName(FieldNode entry) {

@Override
public void applySide(FieldNode entry, String side) {
AnnotationVisitor av = entry.visitAnnotation(SIDED_DESCRIPTOR, false);
visitSideAnnotation(av, side);
entry.visitAnnotation(getSidedDescriptor(side), true);
}
}.merge(nodeOut.fields);

Expand All @@ -214,8 +209,7 @@ public String getName(MethodNode entry) {

@Override
public void applySide(MethodNode entry, String side) {
AnnotationVisitor av = entry.visitAnnotation(SIDED_DESCRIPTOR, false);
visitSideAnnotation(av, side);
entry.visitAnnotation(getSidedDescriptor(side), true);
}
}.merge(nodeOut.methods);

Expand Down

0 comments on commit 7aff934

Please sign in to comment.