Unify shadow version

Dependency rework
Remove class shunting hack
This commit is contained in:
Fury_Phoenix 2023-12-13 21:28:23 -08:00
parent 7319e08e28
commit 94e9c63abd
No known key found for this signature in database
GPG Key ID: 0595F98084987DB8
6 changed files with 8 additions and 222 deletions

View File

@ -1,20 +0,0 @@
plugins {
id 'java-library'
id 'com.diffplug.spotless'
}
repositories {
mavenCentral()
maven { url uri("https://maven.fabricmc.net") }
}
dependencies {
implementation "net.fabricmc:sponge-mixin:0.12.5+"
}
spotless {
java {
removeUnusedImports()
}
}
version = '1.0.0'

View File

@ -1,194 +0,0 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.tools.obfuscation;
import java.util.Set;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeUtils;
/**
* Annotation processor which finds {@link Shadow} and {@link Overwrite}
* annotations in mixin classes and generates new obfuscation mappings
*/
@SupportedAnnotationTypes({
"org.spongepowered.asm.mixin.Mixin",
"org.spongepowered.asm.mixin.Shadow",
"org.spongepowered.asm.mixin.Overwrite",
"org.spongepowered.asm.mixin.gen.Accessor",
"org.spongepowered.asm.mixin.Implements"
})
public class MixinObfuscationProcessorTargets extends MixinObfuscationProcessor {
// Abuse classpath ordering so that the Mixin annotation remains consumable - Fury_Phoenix
/* (non-Javadoc)
* @see javax.annotation.processing.AbstractProcessor
* #process(java.util.Set,
* javax.annotation.processing.RoundEnvironment)
*/
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver()) {
this.postProcess(roundEnv);
return false;
}
this.processMixins(roundEnv);
this.processShadows(roundEnv);
this.processOverwrites(roundEnv);
this.processAccessors(roundEnv);
this.processInvokers(roundEnv);
this.processImplements(roundEnv);
this.postProcess(roundEnv);
return false;
}
@Override
protected void postProcess(RoundEnvironment roundEnv) {
super.postProcess(roundEnv);
try {
this.mixins.writeReferences();
this.mixins.writeMappings();
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* Searches for {@link Shadow} annotations and registers them with their
* parent mixins
*/
private void processShadows(RoundEnvironment roundEnv) {
for (Element elem : roundEnv.getElementsAnnotatedWith(Shadow.class)) {
Element parent = elem.getEnclosingElement();
if (!(parent instanceof TypeElement)) {
this.mixins.printMessage(MessageType.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem);
continue;
}
AnnotationHandle shadow = AnnotationHandle.of(elem, Shadow.class);
if (elem.getKind() == ElementKind.FIELD) {
this.mixins.registerShadow((TypeElement)parent, (VariableElement)elem, shadow);
} else if (elem.getKind() == ElementKind.METHOD) {
this.mixins.registerShadow((TypeElement)parent, (ExecutableElement)elem, shadow);
} else {
this.mixins.printMessage(MessageType.SHADOW_ON_INVALID_ELEMENT, "Element is not a method or field", elem);
}
}
}
/**
* Searches for {@link Overwrite} annotations and registers them with their
* parent mixins
*/
private void processOverwrites(RoundEnvironment roundEnv) {
for (Element elem : roundEnv.getElementsAnnotatedWith(Overwrite.class)) {
Element parent = elem.getEnclosingElement();
if (!(parent instanceof TypeElement)) {
this.mixins.printMessage(MessageType.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem);
continue;
}
if (elem.getKind() == ElementKind.METHOD) {
this.mixins.registerOverwrite((TypeElement)parent, (ExecutableElement)elem);
} else {
this.mixins.printMessage(MessageType.OVERWRITE_ON_NON_METHOD_ELEMENT, "Element is not a method", elem);
}
}
}
/**
* Searches for {@link Accessor} annotations and registers them with their
* parent mixins
*/
private void processAccessors(RoundEnvironment roundEnv) {
for (Element elem : roundEnv.getElementsAnnotatedWith(Accessor.class)) {
Element parent = elem.getEnclosingElement();
if (!(parent instanceof TypeElement)) {
this.mixins.printMessage(MessageType.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem);
continue;
}
if (elem.getKind() == ElementKind.METHOD) {
this.mixins.registerAccessor((TypeElement)parent, (ExecutableElement)elem);
} else {
this.mixins.printMessage(MessageType.ACCESSOR_ON_NON_METHOD_ELEMENT, "Element is not a method", elem);
}
}
}
/**
* Searches for {@link Invoker} annotations and registers them with their
* parent mixins
*/
private void processInvokers(RoundEnvironment roundEnv) {
for (Element elem : roundEnv.getElementsAnnotatedWith(Invoker.class)) {
Element parent = elem.getEnclosingElement();
if (!(parent instanceof TypeElement)) {
this.mixins.printMessage(MessageType.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem);
continue;
}
if (elem.getKind() == ElementKind.METHOD) {
this.mixins.registerInvoker((TypeElement)parent, (ExecutableElement)elem);
} else {
this.mixins.printMessage(MessageType.ACCESSOR_ON_NON_METHOD_ELEMENT, "Element is not a method", elem);
}
}
}
/**
* Searches for {@link Implements} annotations and registers them with their
* parent mixins
*/
private void processImplements(RoundEnvironment roundEnv) {
for (Element elem : roundEnv.getElementsAnnotatedWith(Implements.class)) {
if (elem.getKind() == ElementKind.CLASS || elem.getKind() == ElementKind.INTERFACE) {
AnnotationHandle implementsAnnotation = AnnotationHandle.of(elem, Implements.class);
this.mixins.registerSoftImplements((TypeElement)elem, implementsAnnotation);
} else {
this.mixins.printMessage(MessageType.SOFT_IMPLEMENTS_ON_INVALID_TYPE,
"Found an @Implements annotation on an element which is not a class or interface", elem);
}
}
}
}

View File

@ -1,5 +1,5 @@
plugins {
id "com.github.johnrengelman.shadow" version "7.1.2"
id "com.github.johnrengelman.shadow" version "${rootProject.shadow_version}"
id 'java-library'
id 'com.diffplug.spotless'
}
@ -11,16 +11,15 @@ repositories {
}
dependencies {
implementation 'com.google.guava:guava:21.0'
implementation 'com.google.code.gson:gson:2.10.1'
annotationProcessor 'com.google.auto.service:auto-service:1.1.1'
compileOnly 'com.google.auto.service:auto-service:1.1.1'
shadow "net.fabricmc:sponge-mixin:0.12.5+"
implementation "net.fabricmc:sponge-mixin:0.12.5+"
// Platform classes
runtimeOnly "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
// "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
implementation project(":annotations")
implementation project(":annotation-processor-hack")
}
tasks.withType(JavaCompile) {

View File

@ -1,5 +1,5 @@
plugins {
id "com.github.johnrengelman.shadow" version "7.1.2"
id "com.github.johnrengelman.shadow" version "${rootProject.shadow_version}"
id 'com.adarshr.test-logger' version '3.2.0'
id "modernfix.mod-common-conventions"
id "modernfix.platform-conventions"

View File

@ -1,5 +1,5 @@
plugins {
id "com.github.johnrengelman.shadow" version "7.1.2"
id "com.github.johnrengelman.shadow" version "${rootProject.shadow_version}"
id "modernfix.mod-common-conventions"
id "modernfix.platform-conventions"
}

View File

@ -16,6 +16,7 @@ refined_storage_version=3807951
kubejs_version=1605.3.19-build.299
ctm_version=MC1.16.1-1.1.2.6
supported_minecraft_versions=1.16.4,1.16.5
shadow_version=7.1.2
fabric_loader_version=0.14.21
fabric_api_version=0.42.0+1.16