diff --git a/build.gradle b/build.gradle index 7d0715d3..519f137c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,19 +1,21 @@ // Gradle repositories and dependencies buildscript { repositories { - jcenter() + gradlePluginPortal() } dependencies { - classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.11.0' - classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.4' + classpath 'gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:0.16.1' + classpath 'gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0' } } +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + // Apply plugin apply plugin: 'java' -apply plugin: 'license' +apply plugin: 'com.github.hierynomus.license' apply plugin: 'checkstyle' -apply plugin: 'maven' +apply plugin: 'maven-publish' apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'com.github.johnrengelman.shadow' @@ -41,9 +43,9 @@ ext.legacyForgeAsmVersion = project.hasProperty("legacyForgeAsmVersion") ? asmVe // True to do jar signing task ext.doSignJar = project.hasProperty("keyStorePath") -// Minimum version of Java required -sourceCompatibility = '1.6' -targetCompatibility = '1.6' +java { + toolchain.languageVersion = JavaLanguageVersion.of(16) +} // Project repositories repositories { @@ -65,28 +67,47 @@ repositories { } configurations { - deployerJars // maven stuff thinJar stagingJar + + exampleImplementation .extendsFrom implementation + fernflowerImplementation .extendsFrom implementation + launchwrapperImplementation .extendsFrom implementation + agentImplementation .extendsFrom implementation + modlauncherImplementation .extendsFrom implementation + modlauncher9Implementation .extendsFrom modlauncherImplementation + modularityImplementation .extendsFrom modlauncher9Implementation } -// Include annotation processor sourceSet sourceSets { - legacy + legacy { + ext.languageVersion = 8 + ext.compatibility = '1.6' + } main { compileClasspath += legacy.output + ext.languageVersion = 8 + ext.compatibility = '1.6' } ap { compileClasspath += main.output + ext.languageVersion = 8 + ext.compatibility = '1.6' } fernflower { compileClasspath += main.output + ext.languageVersion = 8 + ext.compatibility = '1.6' } agent { compileClasspath += main.output + ext.languageVersion = 8 + ext.compatibility = '1.6' } bridge { compileClasspath += main.output + ext.languageVersion = 8 + ext.compatibility = '1.8' } example { compileClasspath += main.output @@ -94,26 +115,46 @@ sourceSets { } launchwrapper { compileClasspath += main.output - sourceCompatibility = '1.8' - targetCompatibility = '1.8' + ext.languageVersion = 8 + ext.compatibility = '1.8' } modlauncher { compileClasspath += main.output - sourceCompatibility = '1.8' - targetCompatibility = '1.8' + ext.languageVersion = 8 + ext.compatibility = '1.8' + } + modlauncher4 { + compileClasspath += main.output + compileClasspath += modlauncher.output + ext.languageVersion = 8 + ext.compatibility = '1.8' + } + modlauncher9 { + compileClasspath += main.output + compileClasspath += modlauncher.output + } + modularity { + java.srcDirs += [ + sourceSets.legacy.java.srcDirs, + sourceSets.main.java.srcDirs, + sourceSets.ap.java.srcDirs, + sourceSets.agent.java.srcDirs, + sourceSets.modlauncher.java.srcDirs, + sourceSets.modlauncher9.java.srcDirs + ] } } // Project dependencies dependencies { def guava = 'com.google.guava:guava:21.0' // from mc1.12 onwards - def log4j2 = 'org.apache.logging.log4j:log4j-core:2.0-beta9' + def log4j2 = 'org.apache.logging.log4j:log4j-core:2.11.2' - compile guava - compile log4j2 - compile 'com.google.code.gson:gson:2.2.4' + implementation guava + implementation log4j2 + implementation 'com.google.code.gson:gson:2.2.4' if (Float.parseFloat(asmVersion) < 6) { - compile "org.ow2.asm:asm-debug-all:$asmVersion" + implementation "org.ow2.asm:asm-debug-all:$asmVersion" } implementation "org.ow2.asm:asm-tree:$asmVersion" implementation "org.ow2.asm:asm-commons:$asmVersion" @@ -122,53 +163,61 @@ dependencies { thinJar "org.ow2.asm:asm-tree:$asmVersion" thinJar "org.ow2.asm:asm-util:$asmVersion" - // Tests -// testCompile 'junit:junit:4.11' -// testCompile 'org.hamcrest:hamcrest-library:1.3' -// testCompile 'org.mockito:mockito-core:1.9.0' - // Annotation Processor - apCompile "org.ow2.asm:asm-tree:$asmVersion" - apCompile guava + apImplementation "org.ow2.asm:asm-tree:$asmVersion" + apImplementation guava - // AP extension example - exampleCompile configurations.compile - exampleImplementation configurations.implementation - - // Maven FTP - deployerJars 'org.apache.maven.wagon:wagon-ftp:2.7' - // Fernflower decompiler - fernflowerCompile configurations.compile - fernflowerImplementation configurations.implementation - fernflowerCompile 'org.jetbrains.java.decompiler:fernflower:sponge-SNAPSHOT' + fernflowerImplementation 'org.jetbrains.java.decompiler:fernflower:sponge-SNAPSHOT' // LegacyLauncher service - launchwrapperCompile configurations.compile - launchwrapperImplementation configurations.implementation - launchwrapperCompile ('net.minecraft:launchwrapper:1.11') { + launchwrapperImplementation ('net.minecraft:launchwrapper:1.11') { exclude module: 'lwjgl' + exclude module: 'asm-debug-all' + exclude module: 'jopt-simple' } - modlauncherCompile configurations.compile - modlauncherImplementation configurations.implementation - modlauncherCompile 'net.sf.jopt-simple:jopt-simple:5.0.4' - modlauncherCompile "org.ow2.asm:asm-tree:$modlauncherAsmVersion" - modlauncherCompile "org.ow2.asm:asm-commons:$modlauncherAsmVersion" - modlauncherCompile "org.ow2.asm:asm-util:$modlauncherAsmVersion" - modlauncherCompile ("cpw.mods:modlauncher:$modlauncherVersion") { + modlauncherImplementation 'net.sf.jopt-simple:jopt-simple:5.0.4' + modlauncherImplementation ("cpw.mods:modlauncher:$legacyModlauncherVersion") { + exclude module: 'asm' + exclude module: 'asm-analysis' + exclude module: 'asm-commons' + exclude module: 'asm-tree' + exclude module: 'log4j-api' exclude module: 'log4j-core' + exclude module: 'jopt-simple' } - // agent - agentCompile configurations.compile - agentImplementation configurations.implementation + modlauncher4Implementation ("cpw.mods:modlauncher:$legacyModlauncherVersion") { + exclude module: 'asm' + exclude module: 'asm-analysis' + exclude module: 'asm-commons' + exclude module: 'asm-tree' + exclude module: 'log4j-api' + exclude module: 'log4j-core' + exclude module: 'jopt-simple' + } + + modlauncher9Implementation ("cpw.mods:modlauncher:$modlauncherVersion") { + exclude module: 'log4j-api' + exclude module: 'log4j-core' + exclude module: 'jopt-simple' + } + modlauncher9Implementation 'cpw.mods:securejarhandler:0.9.+' // asm bridge - bridgeCompile log4j2 - bridgeCompile "org.ow2.asm:asm-commons:$legacyForgeAsmVersion" + bridgeImplementation log4j2 + bridgeImplementation "org.ow2.asm:asm-commons:$legacyForgeAsmVersion" - legacyCompile "org.ow2.asm:asm-tree:$asmVersion" + legacyImplementation "org.ow2.asm:asm-tree:$asmVersion" +} + +compileModularityJava { + doFirst { + options.compilerArgs = [ + '--module-path', classpath.asPath + ] + } } javadoc { @@ -191,21 +240,21 @@ javadoc { } } -// Eclipse -eclipse.classpath.plusConfigurations += [ - configurations.fernflowerCompile, - configurations.launchwrapperCompile, - configurations.modlauncherCompile, - configurations.bridgeCompile -] - -// IntelliJ -idea.module.scopes.COMPILE.plus += [ - configurations.fernflowerCompile, - configurations.launchwrapperCompile, - configurations.modlauncherCompile, - configurations.bridgeCompile -] +eclipse { + classpath { + containers 'org.eclipse.buildship.core.gradleclasspathcontainer' + file.whenMerged { + // Can't include old modlauncher because it causes issues with modules + entries.removeAll { it.kind == 'lib' && it.path =~ ~/modlauncher-$legacyModlauncherVersion/ } + entries.removeAll { it.kind == 'src' && it.path =~ ~/modlauncher4/ } + + // Mark everything else as a module + entries.findAll { it.kind == "con" && it.path =~ /gradleclasspathcontainer$/ }.each { + it.entryAttributes['module'] = 'true' + } + } + } +} // Filter, process, and include resources processResources { @@ -239,6 +288,7 @@ checkstyle { ] configFile = file("checkstyle.xml") toolVersion = '8.43' + sourceSets -= project.sourceSets['modularity'] } // Source compiler configuration @@ -248,18 +298,28 @@ tasks.withType(JavaCompile) { options.encoding = 'utf8' } +project.sourceSets.each { set -> { + if (set.ext.has("languageVersion")) { + project.tasks[set.compileJavaTaskName].javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(set.ext.languageVersion) + } + } + if (set.ext.has("compatibility")) { + project.tasks[set.compileJavaTaskName].sourceCompatibility = set.ext.compatibility + project.tasks[set.compileJavaTaskName].targetCompatibility = set.ext.compatibility + } +}} + if (JavaVersion.current().isJava8Compatible()) { tasks.withType(Javadoc) { // disable the crazy super-strict doclint tool in Java 8 - options.addStringOption('Xdoclint:none', '-quiet') + options.addStringOption('Xdoclint:syntax', '-quiet') } } -task stagingJar(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { - sourceSets.each { - if (it.name != 'example') { - from it.output - } +task stagingJar(type: ShadowJar) { + sourceSets.findAll { !(it.name =~ /example|modularity/) }.each { + from it.output } configurations = [project.configurations.stagingJar] @@ -269,7 +329,7 @@ task stagingJar(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar "Built-By": System.properties['user.name'], "Created-By": System.properties['java.vm.version'] + " (" + System.properties['java.vm.vendor'] + ")", "Implementation-Title": name, - "Implementation-Version": version + "+" + ciSystem + "-b" + buildNumber + ".git-" + commit, + "Implementation-Version": project.version + "+" + ciSystem + "-b" + buildNumber + ".git-" + commit, "Implementation-Vendor": url, // for hotswap agent "Premain-Class": "org.spongepowered.tools.agent.MixinAgent", @@ -303,7 +363,7 @@ task thinJar(type: Jar) { "Built-By": System.properties['user.name'], "Created-By": System.properties['java.vm.version'] + " (" + System.properties['java.vm.vendor'] + ")", "Implementation-Title": name, - "Implementation-Version": version + "+" + ciSystem + "-b" + buildNumber + ".git-" + commit, + "Implementation-Version": project.version + "+" + ciSystem + "-b" + buildNumber + ".git-" + commit, "Implementation-Vendor": url, ) } @@ -312,8 +372,6 @@ build.dependsOn(thinJar) // generate shadow jar so we can use the AP standalone shadowJar { from sourceSets.ap.output - exclude 'META-INF/*.DSA' - exclude 'META-INF/*.RSA' classifier = 'processor' } build.dependsOn(shadowJar) @@ -352,11 +410,12 @@ task timestamp(type: Jar, dependsOn: build) { } task sourceJar(type: Jar) { - sourceSets.each { + sourceSets.findAll { it.name != 'modularity' }.each { from it.java from it.resources } classifier = "sources" + duplicatesStrategy = DuplicatesStrategy.EXCLUDE } task javadocJar(type: Jar, dependsOn: javadoc) { @@ -376,79 +435,80 @@ artifacts { archives shadowJar } -ext.excludePomDeps = [ - 'asm-tree', - 'asm-commons', - 'asm-util', - 'log4j-core', - 'guava', - 'gson', -] - ext.mavenPom = { - groupId = project.group - version = project.version - artifactId = project.archivesBaseName - project { - name project.archivesBaseName - packaging project.packaging - description project.projectName - url 'http://www.spongepowered.org/' + name = project.archivesBaseName + packaging = project.packaging + description = project.projectName + url = 'http://www.spongepowered.org/' - scm { - url 'https://github.com/SpongePowered/Mixin' - connection 'scm:git:git://github.com/SpongePowered/Mixin.git' - developerConnection 'scm:git:git@github.com:SpongePowered/Mixin.git' - } - - issueManagement { - system 'GitHub Issues' - url 'https://github.com/SpongePowered/Mixin/issues' - } - - licenses { - license { - name 'MIT license' - url 'http://opensource.org/licenses/MIT' - distribution 'repo' - } - } + scm { + url = 'https://github.com/SpongePowered/Mixin' + connection = 'scm:git:git://github.com/SpongePowered/Mixin.git' + developerConnection = 'scm:git:git@github.com:SpongePowered/Mixin.git' } - whenConfigured { - dependencies = dependencies.findAll { - !it.artifactId.matches(excludePomDeps.join('|')) + + issueManagement { + system = 'GitHub Issues' + url = 'https://github.com/SpongePowered/Mixin/issues' + } + + licenses { + license { + name = 'MIT license' + url = 'http://opensource.org/licenses/MIT' + distribution = 'repo' } } } -uploadArchives { +publishing { + publications { + maven(MavenPublication) { + pom mavenPom + groupId = project.group + version = project.version + artifactId = project.archivesBaseName + + if (project.doSignJar) { + artifact signJar.outputs.files[0] + } else { + artifact stagingJar + } + artifact thinJar + artifact sourceJar + artifact javadocJar + artifact shadowJar + } + } + repositories { - // Push releases to release repo - if (buildType == 'RELEASE' && project.hasProperty("releaseRepo")) { - mavenDeployer { - name = "release" - configuration = configurations.deployerJars - pom mavenPom - repository(url: project.releaseRepo) { - authentication(userName: project.releaseRepoUsername, password: project.releaseRepoPassword) + if (buildType == 'RELEASE') { + if (project.hasProperty("releaseRepo")) { + maven { + credentials { + username = project.releaseRepoUsername + password = project.releaseRepoPassword + } + url project.releaseRepo } } - } - - // Push everything to sponge repo - if (project.hasProperty("spongeRepo")) { - mavenDeployer { - name = "sponge" - configuration = configurations.deployerJars - pom mavenPom - repository(url: project.spongeRepo) { - authentication(userName: project.spongeUsername, password: project.spongePassword) + if (project.hasProperty("spongeReleaseRepo")) { + maven { + credentials { + username = project.spongeUsername + password = project.spongePassword + } + url project.spongeReleaseRepo } } + } else if (project.hasProperty("spongeSnapshotRepo")) { + maven { + credentials { + username = project.spongeUsername + password = project.spongePassword + } + url project.spongeSnapshotRepo + } } } } - -install.repositories.mavenInstaller { - pom mavenPom -} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 5e04be0e..5ddd8c4c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,8 @@ url=https://www.spongepowered.org organization=SpongePowered buildVersion=0.8.4 buildType=SNAPSHOT -asmVersion=7.2 +asmVersion=9.2 legacyForgeAsmVersion=5.0.3 -modlauncherAsmVersion=7.2 -modlauncherVersion=7.0.0 \ No newline at end of file +modlauncherAsmVersion=9.1 +modlauncherVersion=9.0.7 +legacyModlauncherVersion=7.0.0 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41affa0d..f8bda6ea 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip diff --git a/src/agent/java/org/spongepowered/tools/agent/MixinAgentClassLoader.java b/src/agent/java/org/spongepowered/tools/agent/MixinAgentClassLoader.java index 2fd768cb..297a5c1b 100644 --- a/src/agent/java/org/spongepowered/tools/agent/MixinAgentClassLoader.java +++ b/src/agent/java/org/spongepowered/tools/agent/MixinAgentClassLoader.java @@ -68,7 +68,7 @@ class MixinAgentClassLoader extends ClassLoader { Class clazz = this.defineClass(name, bytes, 0, bytes.length); // apparently the class needs to be instantiated at least once // to be including in list returned by allClasses() method in jdi api - clazz.newInstance(); + clazz.getDeclaredConstructor().newInstance(); this.mixins.put(clazz, bytes); } catch (Throwable e) { MixinAgentClassLoader.logger.catching(e); diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/MixinObfuscationProcessor.java b/src/ap/java/org/spongepowered/tools/obfuscation/MixinObfuscationProcessor.java index 44192441..30efc09e 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/MixinObfuscationProcessor.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/MixinObfuscationProcessor.java @@ -80,13 +80,7 @@ abstract class MixinObfuscationProcessor extends AbstractProcessor { @Override public SourceVersion getSupportedSourceVersion() { - try { - return SourceVersion.valueOf("RELEASE_8"); - } catch (IllegalArgumentException ex) { - // Java 8 not supported - } - - return super.getSupportedSourceVersion(); + return SourceVersion.latestSupported(); } @Override diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/TargetMap.java b/src/ap/java/org/spongepowered/tools/obfuscation/TargetMap.java index 05c05df2..1cd2fbad 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/TargetMap.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/TargetMap.java @@ -86,7 +86,7 @@ public final class TargetMap extends HashMap> * * @param mixin mixin to add targets for */ - public void registerTargets(AnnotatedMixin mixin) { + void registerTargets(AnnotatedMixin mixin) { this.registerTargets(mixin.getTargets(), mixin.getHandle()); } @@ -96,7 +96,7 @@ public final class TargetMap extends HashMap> * @param targets List of targets * @param mixin Mixin class */ - public void registerTargets(List targets, TypeHandle mixin) { + void registerTargets(List targets, TypeHandle mixin) { for (TypeHandle target : targets) { this.addMixin(target, mixin); } @@ -108,7 +108,7 @@ public final class TargetMap extends HashMap> * @param target Target class * @param mixin Mixin class */ - public void addMixin(TypeHandle target, TypeHandle mixin) { + void addMixin(TypeHandle target, TypeHandle mixin) { this.addMixin(target.getReference(), mixin.getReference()); } @@ -118,7 +118,7 @@ public final class TargetMap extends HashMap> * @param target Target class * @param mixin Mixin class */ - public void addMixin(String target, String mixin) { + void addMixin(String target, String mixin) { this.addMixin(new TypeReference(target), new TypeReference(mixin)); } @@ -128,7 +128,7 @@ public final class TargetMap extends HashMap> * @param target Target class * @param mixin Mixin class */ - public void addMixin(TypeReference target, TypeReference mixin) { + void addMixin(TypeReference target, TypeReference mixin) { Set mixins = this.getMixinsFor(target); mixins.add(mixin); } @@ -139,7 +139,7 @@ public final class TargetMap extends HashMap> * @param target Target class * @return Collection of mixins registered as targetting the specified class */ - public Collection getMixinsTargeting(TypeElement target) { + Collection getMixinsTargeting(TypeElement target) { return this.getMixinsTargeting(new TypeHandle(target)); } @@ -149,7 +149,7 @@ public final class TargetMap extends HashMap> * @param target Target class * @return Collection of mixins registered as targetting the specified class */ - public Collection getMixinsTargeting(TypeHandle target) { + Collection getMixinsTargeting(TypeHandle target) { return this.getMixinsTargeting(target.getReference()); } @@ -159,7 +159,7 @@ public final class TargetMap extends HashMap> * @param target Target class * @return Collection of mixins registered as targetting the specified class */ - public Collection getMixinsTargeting(TypeReference target) { + Collection getMixinsTargeting(TypeReference target) { return Collections.unmodifiableCollection(this.getMixinsFor(target)); } diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IMixinValidator.java b/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IMixinValidator.java index b266c2cc..6a4b5424 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IMixinValidator.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IMixinValidator.java @@ -57,4 +57,5 @@ public interface IMixinValidator { * @return False to halt processing of further validators */ public abstract boolean validate(ValidationPass pass, TypeElement mixin, AnnotationHandle annotation, Collection targets); + } diff --git a/src/launchwrapper/java/org/spongepowered/asm/launch/platform/MixinPlatformAgentFMLLegacy.java b/src/launchwrapper/java/org/spongepowered/asm/launch/platform/MixinPlatformAgentFMLLegacy.java index 56a34f45..bc557700 100644 --- a/src/launchwrapper/java/org/spongepowered/asm/launch/platform/MixinPlatformAgentFMLLegacy.java +++ b/src/launchwrapper/java/org/spongepowered/asm/launch/platform/MixinPlatformAgentFMLLegacy.java @@ -138,6 +138,7 @@ public class MixinPlatformAgentFMLLegacy extends MixinPlatformAgentAbstract impl */ private boolean initInjectionState; + @SuppressWarnings("deprecation") @Override public AcceptResult accept(MixinPlatformManager manager, IContainerHandle handle) { if (this.getCoreModManagerClass() == null) { @@ -521,6 +522,7 @@ public class MixinPlatformAgentFMLLegacy extends MixinPlatformAgentAbstract impl private final IConsumer delegate; + @SuppressWarnings("deprecation") MixinAppender(IConsumer delegate) { super("MixinLogWatcherAppender", null, null); this.delegate = delegate; diff --git a/src/launchwrapper/java/org/spongepowered/asm/service/mojang/LegacyTransformerHandle.java b/src/launchwrapper/java/org/spongepowered/asm/service/mojang/LegacyTransformerHandle.java index 519ccec3..d5213def 100644 --- a/src/launchwrapper/java/org/spongepowered/asm/service/mojang/LegacyTransformerHandle.java +++ b/src/launchwrapper/java/org/spongepowered/asm/service/mojang/LegacyTransformerHandle.java @@ -24,9 +24,11 @@ */ package org.spongepowered.asm.service.mojang; -import javax.annotation.Resource; +import java.lang.annotation.Annotation; +import org.spongepowered.asm.service.IClassProvider; import org.spongepowered.asm.service.ILegacyClassTransformer; +import org.spongepowered.asm.service.MixinService; import net.minecraft.launchwrapper.IClassTransformer; @@ -57,9 +59,16 @@ class LegacyTransformerHandle implements ILegacyClassTransformer { * @see org.spongepowered.asm.service.ILegacyClassTransformer * #isDelegationExcluded() */ + @SuppressWarnings("unchecked") @Override public boolean isDelegationExcluded() { - return this.transformer.getClass().getAnnotation(Resource.class) != null; + try { + IClassProvider classProvider = MixinService.getService().getClassProvider(); + Class clResource = (Class)classProvider.findClass("javax.annotation.Resource"); + return this.transformer.getClass().getAnnotation(clResource) != null; + } catch (ClassNotFoundException ex) { + return false; + } } /* (non-Javadoc) diff --git a/src/main/java/org/spongepowered/asm/launch/platform/MainAttributes.java b/src/main/java/org/spongepowered/asm/launch/platform/MainAttributes.java index 17980cf7..efaf24e2 100644 --- a/src/main/java/org/spongepowered/asm/launch/platform/MainAttributes.java +++ b/src/main/java/org/spongepowered/asm/launch/platform/MainAttributes.java @@ -24,18 +24,24 @@ */ package org.spongepowered.asm.launch.platform; +import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.nio.file.FileSystemNotFoundException; +import java.nio.file.InvalidPathException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; +import org.spongepowered.asm.util.JavaVersion; + import com.google.common.io.ByteSource; -import com.google.common.io.Files; /** * "Main" attribute cache for a URI container, mainly to avoid constantly @@ -54,8 +60,8 @@ public final class MainAttributes { this.attributes = new Attributes(); } - private MainAttributes(File jar) { - this.attributes = MainAttributes.getAttributes(jar); + private MainAttributes(URI codeSource) { + this.attributes = MainAttributes.getAttributes(codeSource); } /** @@ -72,20 +78,28 @@ public final class MainAttributes { return null; } - private static Attributes getAttributes(File codeSource) { + private static Attributes getAttributes(URI codeSource) { if (codeSource == null) { return null; } - if (codeSource.isFile()) { - Attributes attributes = MainAttributes.getJarAttributes(codeSource); - if (attributes != null) { - return attributes; + if ("file".equals(codeSource.getScheme())) { + File file = new File(codeSource); + + if (file.isFile()) { + Attributes attributes = MainAttributes.getJarAttributes(file); + if (attributes != null) { + return attributes; + } + } else if (file.isDirectory()) { + Attributes attributes = MainAttributes.getDirAttributes(file); + if (attributes != null) { + return attributes; + } } - } - - if (codeSource.isDirectory()) { - Attributes attributes = MainAttributes.getDirAttributes(codeSource); + } else if (JavaVersion.current() >= JavaVersion.JAVA_7) { + // Can try getting the resource using nio if we are on Java 7 or later + Attributes attributes = MainAttributes.getNioAttributes(codeSource); if (attributes != null) { return attributes; } @@ -119,7 +133,7 @@ public final class MainAttributes { private static Attributes getDirAttributes(File dir) { File manifestFile = new File(dir, JarFile.MANIFEST_NAME); if (manifestFile.isFile()) { - ByteSource source = Files.asByteSource(manifestFile); + ByteSource source = com.google.common.io.Files.asByteSource(manifestFile); InputStream inputStream = null; try { inputStream = source.openBufferedStream(); @@ -140,7 +154,35 @@ public final class MainAttributes { return null; } - + + private static Attributes getNioAttributes(URI uri) { + try { + Path manifestPath = Paths.get(uri).resolve(JarFile.MANIFEST_NAME); + BufferedInputStream inputStream = null; + try { + inputStream = new BufferedInputStream(java.nio.file.Files.newInputStream(manifestPath)); + Manifest manifest = new Manifest(inputStream); + return manifest.getMainAttributes(); + } catch (IOException ex) { + // be quiet checkstyle + } finally { + try { + if (inputStream != null) { + inputStream.close(); + } + } catch (IOException e) { + // ignore + } + } + } catch (FileSystemNotFoundException ex) { + // No FS available? + ex.printStackTrace(); + } catch (InvalidPathException ex) { + ex.printStackTrace(); + } + + return null; + } /** * Create a MainAttributes instance for the supplied jar file @@ -161,7 +203,7 @@ public final class MainAttributes { public static MainAttributes of(URI uri) { MainAttributes attributes = MainAttributes.instances.get(uri); if (attributes == null) { - attributes = new MainAttributes(new File(uri)); + attributes = new MainAttributes(uri); MainAttributes.instances.put(uri, attributes); } return attributes; diff --git a/src/main/java/org/spongepowered/asm/launch/platform/container/ContainerHandleURI.java b/src/main/java/org/spongepowered/asm/launch/platform/container/ContainerHandleURI.java index 8abb6194..40dd3ba1 100644 --- a/src/main/java/org/spongepowered/asm/launch/platform/container/ContainerHandleURI.java +++ b/src/main/java/org/spongepowered/asm/launch/platform/container/ContainerHandleURI.java @@ -42,11 +42,6 @@ public class ContainerHandleURI implements IContainerHandle { */ private final URI uri; - /** - * File containing this tweaker - */ - private final File file; - /** * "Main" manifest attributes from the container */ @@ -54,7 +49,6 @@ public class ContainerHandleURI implements IContainerHandle { public ContainerHandleURI(URI uri) { this.uri = uri; - this.file = this.uri != null ? new File(this.uri) : null; this.attributes = MainAttributes.of(uri); } @@ -68,8 +62,9 @@ public class ContainerHandleURI implements IContainerHandle { /** * Get the container file */ + @Deprecated public File getFile() { - return this.file; + return this.uri != null && "file".equals(this.uri.getScheme()) ? new File(this.uri) : null; } /* (non-Javadoc) diff --git a/src/main/java/org/spongepowered/asm/launch/platform/container/ContainerHandleVirtual.java b/src/main/java/org/spongepowered/asm/launch/platform/container/ContainerHandleVirtual.java index 3b624a1a..0e7129bc 100644 --- a/src/main/java/org/spongepowered/asm/launch/platform/container/ContainerHandleVirtual.java +++ b/src/main/java/org/spongepowered/asm/launch/platform/container/ContainerHandleVirtual.java @@ -62,6 +62,13 @@ public class ContainerHandleVirtual implements IContainerHandle { this.name = name; } + /** + * Get the name of this container + */ + public String getName() { + return this.name; + } + /** * Set a virtual attribute on this virtual container * diff --git a/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java b/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java index 69869c3c..c0d625fa 100644 --- a/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java +++ b/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java @@ -602,7 +602,7 @@ public final class MixinEnvironment implements ITokenProvider { @Override boolean isSupported() { - return JavaVersion.current() >= 1.7; + return JavaVersion.current() >= JavaVersion.JAVA_7; } }, @@ -614,7 +614,7 @@ public final class MixinEnvironment implements ITokenProvider { @Override boolean isSupported() { - return JavaVersion.current() >= 1.8; + return JavaVersion.current() >= JavaVersion.JAVA_8; } }, @@ -627,7 +627,7 @@ public final class MixinEnvironment implements ITokenProvider { @Override boolean isSupported() { - return JavaVersion.current() >= 9.0; + return JavaVersion.current() >= JavaVersion.JAVA_8; } }, @@ -640,7 +640,7 @@ public final class MixinEnvironment implements ITokenProvider { @Override boolean isSupported() { - return JavaVersion.current() >= 10.0; + return JavaVersion.current() >= JavaVersion.JAVA_10; } }, @@ -653,7 +653,72 @@ public final class MixinEnvironment implements ITokenProvider { @Override boolean isSupported() { - return JavaVersion.current() >= 11.0; + return JavaVersion.current() >= JavaVersion.JAVA_11; + } + + }, + + /** + * Java 12 or above is required + */ + JAVA_12(12, Opcodes.V12, LanguageFeatures.METHODS_IN_INTERFACES | LanguageFeatures.PRIVATE_SYNTHETIC_METHODS_IN_INTERFACES + | LanguageFeatures.PRIVATE_METHODS_IN_INTERFACES | LanguageFeatures.NESTING | LanguageFeatures.DYNAMIC_CONSTANTS) { + + @Override + boolean isSupported() { + return JavaVersion.current() >= JavaVersion.JAVA_12; + } + + }, + + /** + * Java 13 or above is required + */ + JAVA_13(13, Opcodes.V13, LanguageFeatures.METHODS_IN_INTERFACES | LanguageFeatures.PRIVATE_SYNTHETIC_METHODS_IN_INTERFACES + | LanguageFeatures.PRIVATE_METHODS_IN_INTERFACES | LanguageFeatures.NESTING | LanguageFeatures.DYNAMIC_CONSTANTS) { + + @Override + boolean isSupported() { + return JavaVersion.current() >= JavaVersion.JAVA_13; + } + + }, + + /** + * Java 14 or above is required + */ + JAVA_14(14, Opcodes.V14, LanguageFeatures.METHODS_IN_INTERFACES | LanguageFeatures.PRIVATE_SYNTHETIC_METHODS_IN_INTERFACES + | LanguageFeatures.PRIVATE_METHODS_IN_INTERFACES | LanguageFeatures.NESTING | LanguageFeatures.DYNAMIC_CONSTANTS) { + + @Override + boolean isSupported() { + return JavaVersion.current() >= JavaVersion.JAVA_14; + } + + }, + + /** + * Java 15 or above is required + */ + JAVA_15(15, Opcodes.V15, LanguageFeatures.METHODS_IN_INTERFACES | LanguageFeatures.PRIVATE_SYNTHETIC_METHODS_IN_INTERFACES + | LanguageFeatures.PRIVATE_METHODS_IN_INTERFACES | LanguageFeatures.NESTING | LanguageFeatures.DYNAMIC_CONSTANTS) { + + @Override + boolean isSupported() { + return JavaVersion.current() >= JavaVersion.JAVA_15; + } + + }, + + /** + * Java 16 or above is required + */ + JAVA_16(16, Opcodes.V16, LanguageFeatures.METHODS_IN_INTERFACES | LanguageFeatures.PRIVATE_SYNTHETIC_METHODS_IN_INTERFACES + | LanguageFeatures.PRIVATE_METHODS_IN_INTERFACES | LanguageFeatures.NESTING | LanguageFeatures.DYNAMIC_CONSTANTS) { + + @Override + boolean isSupported() { + return JavaVersion.current() >= JavaVersion.JAVA_16; } }; diff --git a/src/main/java/org/spongepowered/asm/mixin/extensibility/IActivityContext.java b/src/main/java/org/spongepowered/asm/mixin/extensibility/IActivityContext.java new file mode 100644 index 00000000..1fa1219b --- /dev/null +++ b/src/main/java/org/spongepowered/asm/mixin/extensibility/IActivityContext.java @@ -0,0 +1,101 @@ +/* + * This file is part of Mixin, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * 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.asm.mixin.extensibility; + +public interface IActivityContext { + + public interface IActivity { + + /** + * End this activity (and any descendants) and begin the next activity + * using the same activity handle + * + * @param descriptionFormat New activity description format + * @param args New activity description args + */ + void next(String descriptionFormat, Object... args); + + /** + * End this activity (and any descendants) and begin the next activity + * using the same activity handle + * + * @param description New activity description + */ + void next(String description); + + /** + * End this activity and remove it (and any descendants) + */ + void end(); + + /** + * Append text to the activity description + * + * @param textFormat Format for text to append + * @param args Format args + */ + void append(String textFormat, Object...args); + + /** + * Append text to the activity description + * + * @param text Text to append + */ + void append(String text); + + } + + /** + * Convert this activity stack to a string representation using the + * specified glue string + * + * @param glue glue string + * @return string representation of this activity stack + */ + public abstract String toString(String glue); + + /** + * Begin a new activity (push it onto this activity stack) + * + * @param descriptionFormat Activity description format + * @param args format args + * @return new activity handle + */ + public abstract IActivity begin(String descriptionFormat, Object... args); + + /** + * Begin a new activity (push it onto this activity stack) + * + * @param description Activity description + * @return new activity handle + */ + public abstract IActivity begin(String description); + + /** + * Clear the activity stack + */ + public abstract void clear(); + +} diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/code/InsnListReadOnly.java b/src/main/java/org/spongepowered/asm/mixin/injection/code/InsnListReadOnly.java index 70c86574..f1e647ef 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/code/InsnListReadOnly.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/code/InsnListReadOnly.java @@ -34,7 +34,7 @@ import org.objectweb.asm.tree.InsnList; * instances so that custom InjectionPoint implementations cannot modify the * insn list whilst inspecting it. */ -class InsnListReadOnly extends InsnList { +public class InsnListReadOnly extends InsnList { private InsnList insnList; diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/selectors/dynamic/DescriptorResolver.java b/src/main/java/org/spongepowered/asm/mixin/injection/selectors/dynamic/DescriptorResolver.java index cd8ff753..1a6f6f60 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/selectors/dynamic/DescriptorResolver.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/selectors/dynamic/DescriptorResolver.java @@ -265,7 +265,7 @@ public final class DescriptorResolver { } public static IResolvedDescriptor resolve(IAnnotationHandle desc, ISelectorContext context) { - return new Descriptor(Collections.emptySet(), desc, context); + return new Descriptor(Collections.emptySet(), desc, context); } /** diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/throwables/InvalidInjectionException.java b/src/main/java/org/spongepowered/asm/mixin/injection/throwables/InvalidInjectionException.java index 5131e261..6ec84bff 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/throwables/InvalidInjectionException.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/throwables/InvalidInjectionException.java @@ -24,9 +24,9 @@ */ package org.spongepowered.asm.mixin.injection.throwables; -import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; +import org.spongepowered.asm.mixin.extensibility.IActivityContext; +import org.spongepowered.asm.mixin.injection.selectors.ISelectorContext; import org.spongepowered.asm.mixin.refmap.IMixinContext; -import org.spongepowered.asm.mixin.transformer.ActivityStack; import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException; /** @@ -37,70 +37,70 @@ public class InvalidInjectionException extends InvalidMixinException { private static final long serialVersionUID = 2L; - private final InjectionInfo info; + private final ISelectorContext selectorContext; public InvalidInjectionException(IMixinContext context, String message) { super(context, message); - this.info = null; + this.selectorContext = null; } - public InvalidInjectionException(IMixinContext context, String message, ActivityStack activityContext) { + public InvalidInjectionException(IMixinContext context, String message, IActivityContext activityContext) { super(context, message, activityContext); - this.info = null; + this.selectorContext = null; } - public InvalidInjectionException(InjectionInfo info, String message) { - super(info.getMixin(), message); - this.info = info; + public InvalidInjectionException(ISelectorContext selectorContext, String message) { + super(selectorContext.getMixin(), message); + this.selectorContext = selectorContext; } - public InvalidInjectionException(InjectionInfo info, String message, ActivityStack activityContext) { - super(info.getMixin(), message, activityContext); - this.info = info; + public InvalidInjectionException(ISelectorContext selectorContext, String message, IActivityContext activityContext) { + super(selectorContext.getMixin(), message, activityContext); + this.selectorContext = selectorContext; } public InvalidInjectionException(IMixinContext context, Throwable cause) { super(context, cause); - this.info = null; + this.selectorContext = null; } - public InvalidInjectionException(IMixinContext context, Throwable cause, ActivityStack activityContext) { + public InvalidInjectionException(IMixinContext context, Throwable cause, IActivityContext activityContext) { super(context, cause, activityContext); - this.info = null; + this.selectorContext = null; } - public InvalidInjectionException(InjectionInfo info, Throwable cause) { - super(info.getMixin(), cause); - this.info = info; + public InvalidInjectionException(ISelectorContext selectorContext, Throwable cause) { + super(selectorContext.getMixin(), cause); + this.selectorContext = selectorContext; } - public InvalidInjectionException(InjectionInfo info, Throwable cause, ActivityStack activityContext) { - super(info.getMixin(), cause, activityContext); - this.info = info; + public InvalidInjectionException(ISelectorContext selectorContext, Throwable cause, IActivityContext activityContext) { + super(selectorContext.getMixin(), cause, activityContext); + this.selectorContext = selectorContext; } public InvalidInjectionException(IMixinContext context, String message, Throwable cause) { super(context, message, cause); - this.info = null; + this.selectorContext = null; } - public InvalidInjectionException(IMixinContext context, String message, Throwable cause, ActivityStack activityContext) { + public InvalidInjectionException(IMixinContext context, String message, Throwable cause, IActivityContext activityContext) { super(context, message, cause, activityContext); - this.info = null; + this.selectorContext = null; } - public InvalidInjectionException(InjectionInfo info, String message, Throwable cause) { - super(info.getMixin(), message, cause); - this.info = info; + public InvalidInjectionException(ISelectorContext selectorContext, String message, Throwable cause) { + super(selectorContext.getMixin(), message, cause); + this.selectorContext = selectorContext; } - public InvalidInjectionException(InjectionInfo info, String message, Throwable cause, ActivityStack activityContext) { - super(info.getMixin(), message, cause, activityContext); - this.info = info; + public InvalidInjectionException(ISelectorContext selectorContext, String message, Throwable cause, IActivityContext activityContext) { + super(selectorContext.getMixin(), message, cause, activityContext); + this.selectorContext = selectorContext; } - public InjectionInfo getInjectionInfo() { - return this.info; + public ISelectorContext getContext() { + return this.selectorContext; } } diff --git a/src/main/java/org/spongepowered/asm/mixin/throwables/ClassMetadataNotFoundException.java b/src/main/java/org/spongepowered/asm/mixin/throwables/ClassMetadataNotFoundException.java index c9eaf10a..3296d708 100644 --- a/src/main/java/org/spongepowered/asm/mixin/throwables/ClassMetadataNotFoundException.java +++ b/src/main/java/org/spongepowered/asm/mixin/throwables/ClassMetadataNotFoundException.java @@ -24,7 +24,7 @@ */ package org.spongepowered.asm.mixin.throwables; -import org.spongepowered.asm.mixin.transformer.ActivityStack; +import org.spongepowered.asm.mixin.extensibility.IActivityContext; import org.spongepowered.asm.mixin.transformer.ClassInfo; /** @@ -42,7 +42,7 @@ public class ClassMetadataNotFoundException extends MixinException { super(message); } - public ClassMetadataNotFoundException(String message, ActivityStack context) { + public ClassMetadataNotFoundException(String message, IActivityContext context) { super(message, context); } @@ -50,7 +50,7 @@ public class ClassMetadataNotFoundException extends MixinException { super(cause); } - public ClassMetadataNotFoundException(Throwable cause, ActivityStack context) { + public ClassMetadataNotFoundException(Throwable cause, IActivityContext context) { super(cause, context); } @@ -58,7 +58,7 @@ public class ClassMetadataNotFoundException extends MixinException { super(message, cause); } - public ClassMetadataNotFoundException(String message, Throwable cause, ActivityStack context) { + public ClassMetadataNotFoundException(String message, Throwable cause, IActivityContext context) { super(message, cause, context); } diff --git a/src/main/java/org/spongepowered/asm/mixin/throwables/MixinException.java b/src/main/java/org/spongepowered/asm/mixin/throwables/MixinException.java index 085bb4f3..46ced9ea 100644 --- a/src/main/java/org/spongepowered/asm/mixin/throwables/MixinException.java +++ b/src/main/java/org/spongepowered/asm/mixin/throwables/MixinException.java @@ -24,6 +24,7 @@ */ package org.spongepowered.asm.mixin.throwables; +import org.spongepowered.asm.mixin.extensibility.IActivityContext; import org.spongepowered.asm.mixin.transformer.ActivityStack; /** @@ -39,7 +40,7 @@ public class MixinException extends RuntimeException { super(message); } - public MixinException(String message, ActivityStack context) { + public MixinException(String message, IActivityContext context) { super(message); this.activityDescriptor = context != null ? context.toString() : null; } @@ -48,7 +49,7 @@ public class MixinException extends RuntimeException { super(cause); } - public MixinException(Throwable cause, ActivityStack context) { + public MixinException(Throwable cause, IActivityContext context) { super(cause); this.activityDescriptor = context != null ? context.toString() : null; } @@ -57,7 +58,7 @@ public class MixinException extends RuntimeException { super(message, cause); } - public MixinException(String message, Throwable cause, ActivityStack context) { + public MixinException(String message, Throwable cause, IActivityContext context) { super(message, cause); this.activityDescriptor = context != null ? context.toString() : null; } @@ -67,7 +68,7 @@ public class MixinException extends RuntimeException { * * @param upstreamContext Upstream activity stack to decorate */ - public void prepend(ActivityStack upstreamContext) { + public void prepend(IActivityContext upstreamContext) { String strContext = upstreamContext.toString(); this.activityDescriptor = this.activityDescriptor != null ? strContext + ActivityStack.GLUE_STRING + this.activityDescriptor : ActivityStack.GLUE_STRING + strContext; diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/ActivityStack.java b/src/main/java/org/spongepowered/asm/mixin/transformer/ActivityStack.java index 4239b66a..f2418f93 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/ActivityStack.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/ActivityStack.java @@ -24,17 +24,19 @@ */ package org.spongepowered.asm.mixin.transformer; +import org.spongepowered.asm.mixin.extensibility.IActivityContext; + /** * Tracker for processors which want to express their activity stack on crash in * a user-readable way. */ -public class ActivityStack { +public class ActivityStack implements IActivityContext { /** * An activity node in the activity stack (yes it's actually a doubly-linked * list). */ - public class Activity { + public class Activity implements IActivity { /** * Description of this activity @@ -56,6 +58,7 @@ public class ActivityStack { * * @param text Text to append */ + @Override public void append(String text) { this.description = this.description != null ? this.description + text : text; } @@ -66,6 +69,7 @@ public class ActivityStack { * @param textFormat Format for text to append * @param args Format args */ + @Override public void append(String textFormat, Object...args) { this.append(String.format(textFormat, args)); } @@ -73,6 +77,7 @@ public class ActivityStack { /** * End this activity and remove it (and any descendants) */ + @Override public void end() { // Cannot end head or ended activity if (this.last != null) { @@ -87,6 +92,7 @@ public class ActivityStack { * * @param description New activity description */ + @Override public void next(String description) { if (this.next != null) { this.next.end(); @@ -101,6 +107,7 @@ public class ActivityStack { * @param descriptionFormat New activity description format * @param args New activity description args */ + @Override public void next(String descriptionFormat, Object... args) { if (descriptionFormat == null) { descriptionFormat = "null"; @@ -133,6 +140,7 @@ public class ActivityStack { /** * Clear the activity stack */ + @Override public void clear() { this.tail = this.head; this.head.next = null; @@ -144,7 +152,8 @@ public class ActivityStack { * @param description Activity description * @return new activity handle */ - public Activity begin(String description) { + @Override + public IActivity begin(String description) { return this.tail = new Activity(this.tail, description != null ? description : "null"); } @@ -155,7 +164,8 @@ public class ActivityStack { * @param args format args * @return new activity handle */ - public Activity begin(String descriptionFormat, Object... args) { + @Override + public IActivity begin(String descriptionFormat, Object... args) { if (descriptionFormat == null) { descriptionFormat = "null"; } @@ -182,6 +192,7 @@ public class ActivityStack { * @param glue glue string * @return string representation of this activity stack */ + @Override public String toString(String glue) { if (this.head.description == null && this.head.next == null) { return "Unknown"; diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorInterface.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorInterface.java index 0d7987a6..d8e90e3e 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorInterface.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorInterface.java @@ -104,7 +104,7 @@ class MixinApplicatorInterface extends MixinApplicatorStandard { throw new InvalidInterfaceMixinException(mixin, injectInfo + " is not supported on interface mixin method " + method.name); } } catch (InvalidInjectionException ex) { - String description = ex.getInjectionInfo() != null ? ex.getInjectionInfo().toString() : "Injection"; + String description = ex.getContext() != null ? ex.getContext().toString() : "Injection"; throw new InvalidInterfaceMixinException(mixin, description + " is not supported in interface mixin"); } } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorStandard.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorStandard.java index dd2ef0e1..7f5b874c 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorStandard.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorStandard.java @@ -41,6 +41,7 @@ import org.spongepowered.asm.mixin.Intrinsic; import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.MixinEnvironment.Option; import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.extensibility.IActivityContext.IActivity; import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Invoker; import org.spongepowered.asm.mixin.injection.Inject; @@ -50,7 +51,6 @@ import org.spongepowered.asm.mixin.injection.ModifyConstant; import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.throwables.MixinError; -import org.spongepowered.asm.mixin.transformer.ActivityStack.Activity; import org.spongepowered.asm.mixin.transformer.ClassInfo.Field; import org.spongepowered.asm.mixin.transformer.ext.extensions.ExtensionClassExporter; import org.spongepowered.asm.mixin.transformer.meta.MixinMerged; @@ -64,8 +64,8 @@ import org.spongepowered.asm.util.Bytecode; import org.spongepowered.asm.util.Bytecode.DelegateInitialiser; import org.spongepowered.asm.util.Constants; import org.spongepowered.asm.util.ConstraintParser; -import org.spongepowered.asm.util.LanguageFeatures; import org.spongepowered.asm.util.ConstraintParser.Constraint; +import org.spongepowered.asm.util.LanguageFeatures; import org.spongepowered.asm.util.perf.Profiler; import org.spongepowered.asm.util.perf.Profiler.Section; import org.spongepowered.asm.util.throwables.ConstraintViolationException; @@ -302,8 +302,8 @@ class MixinApplicatorStandard { this.activities.clear(); try { - Activity activity = this.activities.begin("PreApply Phase"); - Activity preApplyActivity = this.activities.begin("Mixin"); + IActivity activity = this.activities.begin("PreApply Phase"); + IActivity preApplyActivity = this.activities.begin("Mixin"); for (MixinTargetContext context : mixinContexts) { preApplyActivity.next(context.toString()); (current = context).preApply(this.targetName, this.targetClass); @@ -313,7 +313,7 @@ class MixinApplicatorStandard { for (ApplicatorPass pass : ApplicatorPass.values()) { activity.next("%s Applicator Phase", pass); Section timer = this.profiler.begin("pass", pass.name().toLowerCase(Locale.ROOT)); - Activity applyActivity = this.activities.begin("Mixin"); + IActivity applyActivity = this.activities.begin("Mixin"); for (Iterator iter = mixinContexts.iterator(); iter.hasNext();) { current = iter.next(); applyActivity.next(current.toString()); @@ -332,7 +332,7 @@ class MixinApplicatorStandard { } activity.next("PostApply Phase"); - Activity postApplyActivity = this.activities.begin("Mixin"); + IActivity postApplyActivity = this.activities.begin("Mixin"); for (Iterator iter = mixinContexts.iterator(); iter.hasNext();) { current = iter.next(); postApplyActivity.next(current.toString()); @@ -365,7 +365,7 @@ class MixinApplicatorStandard { * @param mixin Mixin to apply */ protected final void applyMixin(MixinTargetContext mixin, ApplicatorPass pass) { - Activity activity = this.activities.begin("Apply"); + IActivity activity = this.activities.begin("Apply"); switch (pass) { case MAIN: activity.next("Apply Signature"); @@ -505,7 +505,7 @@ class MixinApplicatorStandard { * @param mixin mixin target context */ protected void applyMethods(MixinTargetContext mixin) { - Activity activity = this.activities.begin("?"); + IActivity activity = this.activities.begin("?"); for (MethodNode shadow : mixin.getShadowMethods()) { activity.next("@Shadow %s:%s", shadow.desc, shadow.name); this.applyShadowMethod(mixin, shadow); @@ -535,7 +535,7 @@ class MixinApplicatorStandard { this.mergeMethod(mixin, mixinMethod); } else if (Constants.CLINIT.equals(mixinMethod.name)) { // Class initialiser insns get appended - Activity activity = this.activities.begin("Merge CLINIT insns"); + IActivity activity = this.activities.begin("Merge CLINIT insns"); this.appendInsns(mixin, mixinMethod); activity.end(); } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java index f5e7dcaa..97189e65 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java @@ -1335,7 +1335,7 @@ class MixinInfo implements Comparable, IMixinInfo { /** * Called immediately before the mixin is applied to targetClass */ - public void preApply(String transformedName, ClassNode targetClass) { + public void preApply(String transformedName, ClassNode targetClass) throws Exception { if (this.plugin.isAvailable()) { Section pluginTimer = this.profiler.begin("plugin"); try { @@ -1349,7 +1349,7 @@ class MixinInfo implements Comparable, IMixinInfo { /** * Called immediately after the mixin is applied to targetClass */ - public void postApply(String transformedName, ClassNode targetClass) { + public void postApply(String transformedName, ClassNode targetClass) throws Exception { if (this.plugin.isAvailable()) { Section pluginTimer = this.profiler.begin("plugin"); try { diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorStandard.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorStandard.java index ba43f425..27f98400 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorStandard.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorStandard.java @@ -44,12 +44,12 @@ import org.spongepowered.asm.mixin.MixinEnvironment.Option; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.extensibility.IActivityContext.IActivity; import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Invoker; import org.spongepowered.asm.mixin.gen.throwables.InvalidAccessorException; import org.spongepowered.asm.mixin.throwables.ClassMetadataNotFoundException; import org.spongepowered.asm.mixin.throwables.MixinException; -import org.spongepowered.asm.mixin.transformer.ActivityStack.Activity; import org.spongepowered.asm.mixin.transformer.ClassInfo.Field; import org.spongepowered.asm.mixin.transformer.ClassInfo.Method; import org.spongepowered.asm.mixin.transformer.ClassInfo.SearchType; @@ -177,16 +177,16 @@ class MixinPreProcessorStandard { Section prepareTimer = this.profiler.begin("prepare"); try { - Activity activity = this.activities.begin("Prepare method"); + IActivity activity = this.activities.begin("Prepare method"); for (MixinMethodNode mixinMethod : this.classNode.mixinMethods) { Method method = this.mixin.getClassInfo().findMethod(mixinMethod); - Activity methodActivity = this.activities.begin(mixinMethod.toString()); + IActivity methodActivity = this.activities.begin(mixinMethod.toString()); this.prepareMethod(mixinMethod, method); methodActivity.end(); } activity.next("Prepare field"); for (FieldNode mixinField : this.classNode.fields) { - Activity fieldActivity = this.activities.begin(String.format("%s:%s", mixinField.name, mixinField.desc)); + IActivity fieldActivity = this.activities.begin(String.format("%s:%s", mixinField.name, mixinField.desc)); this.prepareField(mixinField); fieldActivity.end(); } @@ -242,7 +242,7 @@ class MixinPreProcessorStandard { for (MixinMethodNode mixinMethod : this.classNode.mixinMethods) { if (mixinMethod.isInjector()) { Method method = this.mixin.getClassInfo().findMethod(mixinMethod, ClassInfo.INCLUDE_ALL); - Activity methodActivity = this.activities.begin("Conform injector %s", mixinMethod); + IActivity methodActivity = this.activities.begin("Conform injector %s", mixinMethod); this.conformInjector(target, mixinMethod, method); methodActivity.end(); } @@ -285,7 +285,7 @@ class MixinPreProcessorStandard { try { // Perform context-sensitive attachment phase Section timer = this.profiler.begin("methods"); - Activity activity = this.activities.begin("Attach method"); + IActivity activity = this.activities.begin("Attach method"); this.attachMethods(context); timer = timer.next("fields"); activity.next("Attach field"); @@ -307,7 +307,7 @@ class MixinPreProcessorStandard { } protected void attachMethods(MixinTargetContext context) { - Activity methodActivity = this.activities.begin("?"); + IActivity methodActivity = this.activities.begin("?"); for (Iterator iter = this.classNode.mixinMethods.iterator(); iter.hasNext();) { MixinMethodNode mixinMethod = iter.next(); methodActivity.next(mixinMethod.toString()); @@ -585,7 +585,7 @@ class MixinPreProcessorStandard { } protected void attachFields(MixinTargetContext context) { - Activity fieldActivity = this.activities.begin("?"); + IActivity fieldActivity = this.activities.begin("?"); for (Iterator iter = this.classNode.getFields().iterator(); iter.hasNext();) { FieldNode mixinField = iter.next(); fieldActivity.next("%s:%s", mixinField.name, mixinField.desc); @@ -716,12 +716,12 @@ class MixinPreProcessorStandard { * accesses in the mixin */ protected void transform(MixinTargetContext context) { - Activity methodActivity = this.activities.begin("method"); + IActivity methodActivity = this.activities.begin("method"); for (MethodNode mixinMethod : this.classNode.methods) { methodActivity.next("Method %s", mixinMethod); for (Iterator iter = mixinMethod.instructions.iterator(); iter.hasNext();) { AbstractInsnNode insn = iter.next(); - Activity activity = this.activities.begin(Bytecode.getOpcodeName(insn)); + IActivity activity = this.activities.begin(Bytecode.getOpcodeName(insn)); if (insn instanceof MethodInsnNode) { this.transformMethod((MethodInsnNode)insn); } else if (insn instanceof FieldInsnNode) { @@ -734,7 +734,7 @@ class MixinPreProcessorStandard { } protected void transformMethod(MethodInsnNode methodNode) { - Activity activity = this.activities.begin("%s::%s%s", methodNode.owner, methodNode.name, methodNode.desc); + IActivity activity = this.activities.begin("%s::%s%s", methodNode.owner, methodNode.name, methodNode.desc); Section metaTimer = this.profiler.begin("meta"); ClassInfo owner = ClassInfo.forDescriptor(methodNode.owner, TypeLookup.DECLARED_TYPE); if (owner == null) { @@ -751,7 +751,7 @@ class MixinPreProcessorStandard { } protected void transformField(FieldInsnNode fieldNode) { - Activity activity = this.activities.begin("%s::%s:%s", fieldNode.owner, fieldNode.name, fieldNode.desc); + IActivity activity = this.activities.begin("%s::%s:%s", fieldNode.owner, fieldNode.name, fieldNode.desc); Section metaTimer = this.profiler.begin("meta"); ClassInfo owner = ClassInfo.forDescriptor(fieldNode.owner, TypeLookup.DECLARED_TYPE); if (owner == null) { diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinProcessor.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinProcessor.java index 8dc8fea7..90a96f96 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinProcessor.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinProcessor.java @@ -654,7 +654,7 @@ class MixinProcessor { try { MixinProcessor.logger.info("Instancing error handler class {}", handlerClassName); Class handlerClass = this.service.getClassProvider().findClass(handlerClassName, true); - IMixinErrorHandler handler = (IMixinErrorHandler)handlerClass.newInstance(); + IMixinErrorHandler handler = (IMixinErrorHandler)handlerClass.getDeclaredConstructor().newInstance(); if (handler != null) { handlers.add(handler); } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java index 96767c46..f40b9e56 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java @@ -49,6 +49,7 @@ import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel; import org.spongepowered.asm.mixin.MixinEnvironment.Option; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.SoftOverride; +import org.spongepowered.asm.mixin.extensibility.IActivityContext.IActivity; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.asm.mixin.gen.AccessorInfo; import org.spongepowered.asm.mixin.injection.Inject; @@ -62,7 +63,6 @@ import org.spongepowered.asm.mixin.refmap.IReferenceMapper; import org.spongepowered.asm.mixin.struct.MemberRef; import org.spongepowered.asm.mixin.struct.SourceMap.File; import org.spongepowered.asm.mixin.throwables.ClassMetadataNotFoundException; -import org.spongepowered.asm.mixin.transformer.ActivityStack.Activity; import org.spongepowered.asm.mixin.transformer.ClassInfo.Field; import org.spongepowered.asm.mixin.transformer.ClassInfo.Method; import org.spongepowered.asm.mixin.transformer.ClassInfo.SearchType; @@ -445,7 +445,7 @@ public class MixinTargetContext extends ClassContext implements IMixinContext { this.activities.clear(); try { - Activity activity = this.activities.begin("Validate"); + IActivity activity = this.activities.begin("Validate"); this.validateMethod(method); activity.next("Transform Descriptor"); this.transformDescriptor(method); @@ -460,7 +460,7 @@ public class MixinTargetContext extends ClassContext implements IMixinContext { AbstractInsnNode lastInsn = null; for (Iterator iter = method.instructions.iterator(); iter.hasNext();) { AbstractInsnNode insn = iter.next(); - Activity insnActivity = this.activities.begin(Bytecode.getOpcodeName(insn) + " "); + IActivity insnActivity = this.activities.begin(Bytecode.getOpcodeName(insn) + " "); if (insn instanceof MethodInsnNode) { MethodInsnNode methodNode = (MethodInsnNode)insn; @@ -537,7 +537,7 @@ public class MixinTargetContext extends ClassContext implements IMixinContext { return; } - Activity localVarActivity = this.activities.begin("?"); + IActivity localVarActivity = this.activities.begin("?"); for (LocalVariableNode local : method.localVariables) { if (local == null || local.desc == null) { continue; @@ -947,7 +947,7 @@ public class MixinTargetContext extends ClassContext implements IMixinContext { } private String transformSingleDescriptor(String desc, boolean isObject) { - Activity descriptorActivity = this.activities.begin("desc=%s", desc); + IActivity descriptorActivity = this.activities.begin("desc=%s", desc); boolean isArray = false; String type = desc; while (type.startsWith("[") || type.startsWith("L")) { @@ -1233,7 +1233,7 @@ public class MixinTargetContext extends ClassContext implements IMixinContext { * @param transformedName Target class's transformed name * @param targetClass Target class */ - void preApply(String transformedName, ClassNode targetClass) { + void preApply(String transformedName, ClassNode targetClass) throws Exception { this.mixin.preApply(transformedName, targetClass); } @@ -1247,7 +1247,7 @@ public class MixinTargetContext extends ClassContext implements IMixinContext { this.activities.clear(); try { - Activity activity = this.activities.begin("Validating Injector Groups"); + IActivity activity = this.activities.begin("Validating Injector Groups"); this.injectorGroups.validateAll(); activity.next("Plugin Post-Application"); this.mixin.postApply(transformedName, targetClass); @@ -1300,10 +1300,10 @@ public class MixinTargetContext extends ClassContext implements IMixinContext { try { this.injectors.clear(); - Activity prepareActivity = this.activities.begin("?"); + IActivity prepareActivity = this.activities.begin("?"); for (MethodNode method : this.mergedMethods) { prepareActivity.next("%s%s", method.name, method.desc); - Activity methodActivity = this.activities.begin("Parse"); + IActivity methodActivity = this.activities.begin("Parse"); InjectionInfo injectInfo = InjectionInfo.parse(this, method); if (injectInfo == null) { continue; @@ -1337,22 +1337,22 @@ public class MixinTargetContext extends ClassContext implements IMixinContext { this.activities.clear(); try { - Activity applyActivity = this.activities.begin("PreInject"); - Activity preInjectActivity = this.activities.begin("?"); + IActivity applyActivity = this.activities.begin("PreInject"); + IActivity preInjectActivity = this.activities.begin("?"); for (InjectionInfo injectInfo : this.injectors) { preInjectActivity.next(injectInfo.toString()); injectInfo.preInject(); } applyActivity.next("Inject"); - Activity injectActivity = this.activities.begin("?"); + IActivity injectActivity = this.activities.begin("?"); for (InjectionInfo injectInfo : this.injectors) { injectActivity.next(injectInfo.toString()); injectInfo.inject(); } applyActivity.next("PostInject"); - Activity postInjectActivity = this.activities.begin("?"); + IActivity postInjectActivity = this.activities.begin("?"); for (InjectionInfo injectInfo : this.injectors) { postInjectActivity.next(injectInfo.toString()); injectInfo.postInject(); @@ -1378,22 +1378,22 @@ public class MixinTargetContext extends ClassContext implements IMixinContext { List methods = new ArrayList(); try { - Activity accessorActivity = this.activities.begin("Locate"); - Activity locateActivity = this.activities.begin("?"); + IActivity accessorActivity = this.activities.begin("Locate"); + IActivity locateActivity = this.activities.begin("?"); for (AccessorInfo accessor : this.accessors) { locateActivity.next(accessor.toString()); accessor.locate(); } accessorActivity.next("Validate"); - Activity validateActivity = this.activities.begin("?"); + IActivity validateActivity = this.activities.begin("?"); for (AccessorInfo accessor : this.accessors) { validateActivity.next(accessor.toString()); accessor.validate(); } accessorActivity.next("Generate"); - Activity generateActivity = this.activities.begin("?"); + IActivity generateActivity = this.activities.begin("?"); for (AccessorInfo accessor : this.accessors) { generateActivity.next(accessor.toString()); MethodNode generated = accessor.generate(); diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/PluginHandle.java b/src/main/java/org/spongepowered/asm/mixin/transformer/PluginHandle.java index 3a8ef03b..47356e73 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/PluginHandle.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/PluginHandle.java @@ -135,7 +135,7 @@ class PluginHandle { /** * Called immediately before the mixin is applied to targetClass */ - public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, MixinInfo mixinInfo) { + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, MixinInfo mixinInfo) throws Exception { if (this.plugin == null) { return; } @@ -166,7 +166,7 @@ class PluginHandle { /** * Called immediately after the mixin is applied to targetClass */ - public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, MixinInfo mixinInfo) { + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, MixinInfo mixinInfo) throws Exception { if (this.plugin == null) { return; } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/InvalidMixinException.java b/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/InvalidMixinException.java index ab996e9c..ddb3a533 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/InvalidMixinException.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/InvalidMixinException.java @@ -24,10 +24,10 @@ */ package org.spongepowered.asm.mixin.transformer.throwables; +import org.spongepowered.asm.mixin.extensibility.IActivityContext; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.asm.mixin.refmap.IMixinContext; import org.spongepowered.asm.mixin.throwables.MixinException; -import org.spongepowered.asm.mixin.transformer.ActivityStack; /** * Thrown by the mixin validator when a mixin fails a pre-flight check @@ -43,7 +43,7 @@ public class InvalidMixinException extends MixinException { this.mixin = mixin; } - public InvalidMixinException(IMixinInfo mixin, String message, ActivityStack activityContext) { + public InvalidMixinException(IMixinInfo mixin, String message, IActivityContext activityContext) { super(message, activityContext); this.mixin = mixin; } @@ -52,7 +52,7 @@ public class InvalidMixinException extends MixinException { this(context.getMixin(), message); } - public InvalidMixinException(IMixinContext context, String message, ActivityStack activityContext) { + public InvalidMixinException(IMixinContext context, String message, IActivityContext activityContext) { this(context.getMixin(), message, activityContext); } @@ -61,7 +61,7 @@ public class InvalidMixinException extends MixinException { this.mixin = mixin; } - public InvalidMixinException(IMixinInfo mixin, Throwable cause, ActivityStack activityContext) { + public InvalidMixinException(IMixinInfo mixin, Throwable cause, IActivityContext activityContext) { super(cause, activityContext); this.mixin = mixin; } @@ -70,7 +70,7 @@ public class InvalidMixinException extends MixinException { this(context.getMixin(), cause); } - public InvalidMixinException(IMixinContext context, Throwable cause, ActivityStack activityContext) { + public InvalidMixinException(IMixinContext context, Throwable cause, IActivityContext activityContext) { this(context.getMixin(), cause, activityContext); } @@ -79,7 +79,7 @@ public class InvalidMixinException extends MixinException { this.mixin = mixin; } - public InvalidMixinException(IMixinInfo mixin, String message, Throwable cause, ActivityStack activityContext) { + public InvalidMixinException(IMixinInfo mixin, String message, Throwable cause, IActivityContext activityContext) { super(message, cause, activityContext); this.mixin = mixin; } @@ -89,7 +89,7 @@ public class InvalidMixinException extends MixinException { this.mixin = context.getMixin(); } - public InvalidMixinException(IMixinContext context, String message, Throwable cause, ActivityStack activityContext) { + public InvalidMixinException(IMixinContext context, String message, Throwable cause, IActivityContext activityContext) { super(message, cause, activityContext); this.mixin = context.getMixin(); } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/MixinApplicatorException.java b/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/MixinApplicatorException.java index 98e5f0ae..925583d0 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/MixinApplicatorException.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/MixinApplicatorException.java @@ -24,6 +24,7 @@ */ package org.spongepowered.asm.mixin.transformer.throwables; +import org.spongepowered.asm.mixin.extensibility.IActivityContext; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.asm.mixin.refmap.IMixinContext; import org.spongepowered.asm.mixin.transformer.ActivityStack; @@ -39,7 +40,7 @@ public class MixinApplicatorException extends InvalidMixinException { super(context, message, (ActivityStack)null); } - public MixinApplicatorException(IMixinInfo context, String message, ActivityStack activityContext) { + public MixinApplicatorException(IMixinInfo context, String message, IActivityContext activityContext) { super(context, message, activityContext); } @@ -47,7 +48,7 @@ public class MixinApplicatorException extends InvalidMixinException { super(context, message, (ActivityStack)null); } - public MixinApplicatorException(IMixinContext context, String message, ActivityStack activityContext) { + public MixinApplicatorException(IMixinContext context, String message, IActivityContext activityContext) { super(context, message, activityContext); } @@ -55,7 +56,7 @@ public class MixinApplicatorException extends InvalidMixinException { super(mixin, message, cause, (ActivityStack)null); } - public MixinApplicatorException(IMixinInfo mixin, String message, Throwable cause, ActivityStack activityContext) { + public MixinApplicatorException(IMixinInfo mixin, String message, Throwable cause, IActivityContext activityContext) { super(mixin, message, cause, activityContext); } @@ -63,7 +64,7 @@ public class MixinApplicatorException extends InvalidMixinException { super(mixin, message, cause, (ActivityStack)null); } - public MixinApplicatorException(IMixinContext mixin, String message, Throwable cause, ActivityStack activityContext) { + public MixinApplicatorException(IMixinContext mixin, String message, Throwable cause, IActivityContext activityContext) { super(mixin, message, cause, activityContext); } @@ -71,7 +72,7 @@ public class MixinApplicatorException extends InvalidMixinException { super(mixin, cause, (ActivityStack)null); } - public MixinApplicatorException(IMixinInfo mixin, Throwable cause, ActivityStack activityContext) { + public MixinApplicatorException(IMixinInfo mixin, Throwable cause, IActivityContext activityContext) { super(mixin, cause, activityContext); } @@ -79,7 +80,7 @@ public class MixinApplicatorException extends InvalidMixinException { super(mixin, cause, (ActivityStack)null); } - public MixinApplicatorException(IMixinContext mixin, Throwable cause, ActivityStack activityContext) { + public MixinApplicatorException(IMixinContext mixin, Throwable cause, IActivityContext activityContext) { super(mixin, cause, activityContext); } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/MixinPreProcessorException.java b/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/MixinPreProcessorException.java index 04aa972d..cdcc2eda 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/MixinPreProcessorException.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/MixinPreProcessorException.java @@ -24,8 +24,8 @@ */ package org.spongepowered.asm.mixin.transformer.throwables; +import org.spongepowered.asm.mixin.extensibility.IActivityContext; import org.spongepowered.asm.mixin.throwables.MixinException; -import org.spongepowered.asm.mixin.transformer.ActivityStack; /** * Exception indicating a problem during pre-processing @@ -34,11 +34,11 @@ public class MixinPreProcessorException extends MixinException { private static final long serialVersionUID = 1L; - public MixinPreProcessorException(String message, ActivityStack context) { + public MixinPreProcessorException(String message, IActivityContext context) { super(message, context); } - public MixinPreProcessorException(String message, Throwable cause, ActivityStack context) { + public MixinPreProcessorException(String message, Throwable cause, IActivityContext context) { super(message, cause, context); } diff --git a/src/main/java/org/spongepowered/asm/util/JavaVersion.java b/src/main/java/org/spongepowered/asm/util/JavaVersion.java index 83731a81..c609a00f 100644 --- a/src/main/java/org/spongepowered/asm/util/JavaVersion.java +++ b/src/main/java/org/spongepowered/asm/util/JavaVersion.java @@ -32,6 +32,61 @@ import java.util.regex.Pattern; */ public abstract class JavaVersion { + /** + * Version number for Java 6 + */ + public static final double JAVA_6 = 1.6; + + /** + * Version number for Java 7 + */ + public static final double JAVA_7 = 1.7; + + /** + * Version number for Java 8 + */ + public static final double JAVA_8 = 1.8; + + /** + * Version number for Java 9 + */ + public static final double JAVA_9 = 9.0; + + /** + * Version number for Java 10 + */ + public static final double JAVA_10 = 10.0; + + /** + * Version number for Java 11 + */ + public static final double JAVA_11 = 11.0; + + /** + * Version number for Java 12 + */ + public static final double JAVA_12 = 12.0; + + /** + * Version number for Java 13 + */ + public static final double JAVA_13 = 13.0; + + /** + * Version number for Java 14 + */ + public static final double JAVA_14 = 14.0; + + /** + * Version number for Java 15 + */ + public static final double JAVA_15 = 15.0; + + /** + * Version number for Java 16 + */ + public static final double JAVA_16 = 16.0; + private static double current = 0.0; private JavaVersion() {} diff --git a/src/modlauncher/java/org/spongepowered/asm/launch/MixinLaunchPlugin.java b/src/modlauncher/java/org/spongepowered/asm/launch/MixinLaunchPluginLegacy.java similarity index 91% rename from src/modlauncher/java/org/spongepowered/asm/launch/MixinLaunchPlugin.java rename to src/modlauncher/java/org/spongepowered/asm/launch/MixinLaunchPluginLegacy.java index 857468cc..c142bd60 100644 --- a/src/modlauncher/java/org/spongepowered/asm/launch/MixinLaunchPlugin.java +++ b/src/modlauncher/java/org/spongepowered/asm/launch/MixinLaunchPluginLegacy.java @@ -30,7 +30,6 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.EnumSet; import java.util.List; -import java.util.Map.Entry; import java.util.function.Consumer; import org.objectweb.asm.ClassReader; @@ -52,7 +51,7 @@ import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; /** * Mixin launch plugin */ -public class MixinLaunchPlugin implements ILaunchPluginService, IClassBytecodeProvider { +public class MixinLaunchPluginLegacy implements ILaunchPluginService, IClassBytecodeProvider { /** * Name used for ModLauncher mixin service components @@ -80,7 +79,7 @@ public class MixinLaunchPlugin implements ILaunchPluginService, IClassBytecodePr */ @Override public String name() { - return MixinLaunchPlugin.NAME; + return MixinLaunchPluginLegacy.NAME; } @Override @@ -90,6 +89,7 @@ public class MixinLaunchPlugin implements ILaunchPluginService, IClassBytecodePr @Override public boolean processClass(Phase phase, ClassNode classNode, Type classType) { + Thread.dumpStack(); throw new IllegalStateException("Outdated ModLauncher"); } @@ -99,7 +99,7 @@ public class MixinLaunchPlugin implements ILaunchPluginService, IClassBytecodePr */ @Override public EnumSet handlesClass(Type classType, boolean isEmpty, final String reason) { - if (MixinLaunchPlugin.NAME.equals(reason)) { + if (MixinLaunchPluginLegacy.NAME.equals(reason)) { return Phases.NONE; } @@ -177,8 +177,9 @@ public class MixinLaunchPlugin implements ILaunchPluginService, IClassBytecodePr this.service.getPrimaryContainer().addResource(name, resource); } + @SuppressWarnings("rawtypes") @Override - public void addResources(List> resources) { + public void addResources(List resources) { this.service.getPrimaryContainer().addResources(resources); } @@ -190,8 +191,12 @@ public class MixinLaunchPlugin implements ILaunchPluginService, IClassBytecodePr return null; } - @Override + // ModLauncher 4-8 public void initializeLaunch(ITransformerLoader transformerLoader, Path[] specialPaths) { + this.initializeLaunch(transformerLoader); + } + + protected void initializeLaunch(ITransformerLoader transformerLoader) { this.transformerLoader = transformerLoader; MixinBootstrap.doInit(CommandLineOptions.of(this.commandLineMixins)); MixinBootstrap.inject(); @@ -209,12 +214,15 @@ public class MixinLaunchPlugin implements ILaunchPluginService, IClassBytecodePr throw new IllegalArgumentException("ModLauncher service does not currently support retrieval of untransformed bytecode"); } + String canonicalName = name.replace('/', '.'); + String internalName = name.replace('.', '/'); + byte[] classBytes; try { - classBytes = this.transformerLoader.buildTransformedClassNodeFor(name); + classBytes = this.transformerLoader.buildTransformedClassNodeFor(canonicalName); } catch (ClassNotFoundException ex) { - URL url = Thread.currentThread().getContextClassLoader().getResource(name.replace('.', '/') + ".class"); + URL url = Thread.currentThread().getContextClassLoader().getResource(internalName + ".class"); if (url == null) { throw ex; } @@ -225,12 +233,12 @@ public class MixinLaunchPlugin implements ILaunchPluginService, IClassBytecodePr } } - if (classBytes == null) { - throw new ClassNotFoundException(name.replace('/', '.')); + if (classBytes == null || classBytes.length == 0) { + throw new ClassNotFoundException(canonicalName); } ClassNode classNode = new ClassNode(); - ClassReader classReader = new MixinClassReader(classBytes, name); + ClassReader classReader = new MixinClassReader(classBytes, canonicalName); classReader.accept(classNode, ClassReader.EXPAND_FRAMES); return classNode; } diff --git a/src/modlauncher/java/org/spongepowered/asm/launch/MixinTransformationService.java b/src/modlauncher/java/org/spongepowered/asm/launch/MixinTransformationServiceAbstract.java similarity index 74% rename from src/modlauncher/java/org/spongepowered/asm/launch/MixinTransformationService.java rename to src/modlauncher/java/org/spongepowered/asm/launch/MixinTransformationServiceAbstract.java index 432bb515..9fd8eff2 100644 --- a/src/modlauncher/java/org/spongepowered/asm/launch/MixinTransformationService.java +++ b/src/modlauncher/java/org/spongepowered/asm/launch/MixinTransformationServiceAbstract.java @@ -24,8 +24,11 @@ */ package org.spongepowered.asm.launch; +import java.nio.file.Path; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.function.BiFunction; @@ -41,17 +44,18 @@ import joptsimple.ArgumentAcceptingOptionSpec; import joptsimple.OptionSpecBuilder; /** - * Service for handling transforms mixin under ModLauncher + * Service for handling transforms mixin under ModLauncher, now abstract to + * support both Modlauncher 9 and previous versions of Modlauncher */ -public class MixinTransformationService implements ITransformationService { +public abstract class MixinTransformationServiceAbstract implements ITransformationService { private ArgumentAcceptingOptionSpec mixinsArgument; private List commandLineMixins = new ArrayList(); - private MixinLaunchPlugin plugin; + private MixinLaunchPluginLegacy plugin; @Override public String name() { - return MixinLaunchPlugin.NAME; + return MixinLaunchPluginLegacy.NAME; } @Override @@ -71,24 +75,34 @@ public class MixinTransformationService implements ITransformationService { @Override public void initialize(IEnvironment environment) { - Optional plugin = environment.findLaunchPlugin(MixinLaunchPlugin.NAME); + Optional plugin = environment.findLaunchPlugin(MixinLaunchPluginLegacy.NAME); if (!plugin.isPresent()) { throw new MixinInitialisationError("Mixin Launch Plugin Service could not be located"); } ILaunchPluginService launchPlugin = plugin.get(); - if (!(launchPlugin instanceof MixinLaunchPlugin)) { + if (!(launchPlugin instanceof MixinLaunchPluginLegacy)) { throw new MixinInitialisationError("Mixin Launch Plugin Service is present but not compatible"); } - this.plugin = (MixinLaunchPlugin)launchPlugin; + this.plugin = (MixinLaunchPluginLegacy)launchPlugin; MixinBootstrap.start(); this.plugin.init(environment, this.commandLineMixins); } - @Override - public void beginScanning(IEnvironment environment) { + /** + * This is "overridden" from Modlauncher 4-8 since it would normally call + * beginScanning which returned void. Since we can't + * override the old method, and omitting it would lead to an Abstract Method + * Error in ML 8, we instead override this method to avoid calling + * the now-removed beginScanning. + * + * @param environment Scanning env + * @return discovered containers + */ + public List> runScan(IEnvironment environment) { + return Collections.emptyList(); } - + @SuppressWarnings("rawtypes") @Override public List transformers() { diff --git a/src/modlauncher/java/org/spongepowered/asm/launch/platform/container/ContainerHandleModLauncher.java b/src/modlauncher/java/org/spongepowered/asm/launch/platform/container/ContainerHandleModLauncher.java index 1d5b0a3f..03463e43 100644 --- a/src/modlauncher/java/org/spongepowered/asm/launch/platform/container/ContainerHandleModLauncher.java +++ b/src/modlauncher/java/org/spongepowered/asm/launch/platform/container/ContainerHandleModLauncher.java @@ -28,15 +28,18 @@ import java.nio.file.Path; import java.util.List; import java.util.Map.Entry; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + /** * ModLauncher root container */ public class ContainerHandleModLauncher extends ContainerHandleVirtual { /** - * Container handle for resources offered by ModLauncher + * Container handle for nio resources offered by ModLauncher */ - public class Resource extends ContainerHandleURI { + class Resource extends ContainerHandleURI { private String name; private Path path; @@ -61,6 +64,11 @@ public class ContainerHandleModLauncher extends ContainerHandleVirtual { } } + + /** + * Logger + */ + protected static final Logger logger = LogManager.getLogger("mixin"); public ContainerHandleModLauncher(String name) { super(name); @@ -76,20 +84,43 @@ public class ContainerHandleModLauncher extends ContainerHandleVirtual { this.add(new Resource(name, path)); } + /** + * Add a resource to to this container + * + * @param entry Resource entry + */ + public void addResource(Entry entry) { + this.add(new Resource(entry.getKey(), entry.getValue())); + } + + /** + * Add a resource to to this container + * + * @param resource Resource + */ + @SuppressWarnings("unchecked") + public void addResource(Object resource) { + if (resource instanceof Entry) { + this.addResource((Entry)resource); + } else { + ContainerHandleModLauncher.logger.error("Unrecognised resource type {} passed to {}", resource.getClass(), this); + } + } + /** * Add a collection of resources to this container * * @param resources Resources to add */ - public void addResources(List> resources) { - for (Entry resource : resources) { - this.addResource(resource.getKey(), resource.getValue()); + public void addResources(List resources) { + for (Object resource : resources) { + this.addResource(resource); } } - + @Override public String toString() { - return String.format("ModLauncher Root Container(%x)", this.hashCode()); + return String.format("ModLauncher Root Container(%s:%x)", this.getName(), this.hashCode()); } } diff --git a/src/modlauncher/java/org/spongepowered/asm/service/modlauncher/MixinServiceModLauncher.java b/src/modlauncher/java/org/spongepowered/asm/service/modlauncher/MixinServiceModLauncher.java index 80791f9e..d7b433b2 100644 --- a/src/modlauncher/java/org/spongepowered/asm/service/modlauncher/MixinServiceModLauncher.java +++ b/src/modlauncher/java/org/spongepowered/asm/service/modlauncher/MixinServiceModLauncher.java @@ -25,6 +25,7 @@ package org.spongepowered.asm.service.modlauncher; import java.io.InputStream; +import java.lang.reflect.Constructor; import java.util.Collection; import org.spongepowered.asm.launch.IClassProcessor; @@ -54,7 +55,20 @@ public class MixinServiceModLauncher extends MixinServiceAbstract { /** * Specification version to check for at startup */ - private static final String MODLAUNCHER_SPECIFICATION_VERSION = "4.0"; + private static final String MODLAUNCHER_4_SPECIFICATION_VERSION = "4.0"; + + /** + * Specification version for ModLauncher versions >= 9.0.4, yes this is + * not a typo, the specification version (API version) is out of step with + * the artefact version in a few previous cases (ML6 has specification + * version 5.0 for example, and ML7 and ML8 both had specification version + * 7.0). + */ + private static final String MODLAUNCHER_9_SPECIFICATION_VERSION = "8.0"; + + private static final String CONTAINER_PACKAGE = MixinServiceAbstract.LAUNCH_PACKAGE + "platform.container."; + private static final String MODLAUNCHER_4_ROOT_CONTAINER_CLASS = MixinServiceModLauncher.CONTAINER_PACKAGE + "ContainerHandleModLauncher"; + private static final String MODLAUNCHER_9_ROOT_CONTAINER_CLASS = MixinServiceModLauncher.CONTAINER_PACKAGE + "ContainerHandleModLauncherEx"; /** * Class provider, either uses hacky internals or provided service @@ -94,7 +108,22 @@ public class MixinServiceModLauncher extends MixinServiceAbstract { /** * Root container */ - private ContainerHandleModLauncher rootContainer = new ContainerHandleModLauncher(this.getName()); + private ContainerHandleModLauncher rootContainer; + + /** + * Minimum compatibility level + */ + private CompatibilityLevel minCompatibilityLevel = CompatibilityLevel.JAVA_8; + + public MixinServiceModLauncher() { + final Package pkg = ITransformationService.class.getPackage(); + if (pkg.isCompatibleWith(MixinServiceModLauncher.MODLAUNCHER_9_SPECIFICATION_VERSION)) { + this.createRootContainer(MixinServiceModLauncher.MODLAUNCHER_9_ROOT_CONTAINER_CLASS); + this.minCompatibilityLevel = CompatibilityLevel.JAVA_16; + } else { + this.createRootContainer(MixinServiceModLauncher.MODLAUNCHER_4_ROOT_CONTAINER_CLASS); + } + } /** * Begin init @@ -109,6 +138,16 @@ public class MixinServiceModLauncher extends MixinServiceAbstract { this.bytecodeProvider = bytecodeProvider; } + private void createRootContainer(String rootContainerClassName) { + try { + Class clRootContainer = this.getClassProvider().findClass(rootContainerClassName); + Constructor ctor = clRootContainer.getDeclaredConstructor(String.class); + this.rootContainer = (ContainerHandleModLauncher)ctor.newInstance(this.getName()); + } catch (ReflectiveOperationException ex) { + ex.printStackTrace(); + } + } + /** * Lifecycle event */ @@ -146,7 +185,7 @@ public class MixinServiceModLauncher extends MixinServiceAbstract { */ @Override public CompatibilityLevel getMinCompatibilityLevel() { - return CompatibilityLevel.JAVA_8; + return this.minCompatibilityLevel; } /* (non-Javadoc) @@ -157,7 +196,7 @@ public class MixinServiceModLauncher extends MixinServiceAbstract { try { Launcher.INSTANCE.hashCode(); final Package pkg = ITransformationService.class.getPackage(); - if (!pkg.isCompatibleWith(MixinServiceModLauncher.MODLAUNCHER_SPECIFICATION_VERSION)) { + if (!pkg.isCompatibleWith(MixinServiceModLauncher.MODLAUNCHER_4_SPECIFICATION_VERSION)) { return false; } } catch (Throwable th) { diff --git a/src/modlauncher/java/org/spongepowered/asm/service/modlauncher/MixinTransformationHandler.java b/src/modlauncher/java/org/spongepowered/asm/service/modlauncher/MixinTransformationHandler.java index 303e1c7e..2861737e 100644 --- a/src/modlauncher/java/org/spongepowered/asm/service/modlauncher/MixinTransformationHandler.java +++ b/src/modlauncher/java/org/spongepowered/asm/service/modlauncher/MixinTransformationHandler.java @@ -29,7 +29,7 @@ import java.util.EnumSet; import org.objectweb.asm.Type; import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.launch.IClassProcessor; -import org.spongepowered.asm.launch.MixinLaunchPlugin; +import org.spongepowered.asm.launch.MixinLaunchPluginLegacy; import org.spongepowered.asm.launch.Phases; import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.transformer.IMixinTransformer; @@ -108,7 +108,7 @@ public class MixinTransformationHandler implements IClassProcessor { } // Don't transform when the reason is mixin (side-loading in progress) - if (MixinLaunchPlugin.NAME.equals(reason)) { + if (MixinLaunchPluginLegacy.NAME.equals(reason)) { return false; } diff --git a/src/modlauncher/resources/META-INF/services/cpw.mods.modlauncher.api.ITransformationService b/src/modlauncher/resources/META-INF/services/cpw.mods.modlauncher.api.ITransformationService deleted file mode 100644 index 43d16497..00000000 --- a/src/modlauncher/resources/META-INF/services/cpw.mods.modlauncher.api.ITransformationService +++ /dev/null @@ -1 +0,0 @@ -org.spongepowered.asm.launch.MixinTransformationService \ No newline at end of file diff --git a/src/modlauncher/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService b/src/modlauncher/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService deleted file mode 100644 index dee143bf..00000000 --- a/src/modlauncher/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService +++ /dev/null @@ -1 +0,0 @@ -org.spongepowered.asm.launch.MixinLaunchPlugin \ No newline at end of file diff --git a/src/modlauncher4/java/org/spongepowered/asm/launch/MixinTransformationServiceLegacy.java b/src/modlauncher4/java/org/spongepowered/asm/launch/MixinTransformationServiceLegacy.java new file mode 100644 index 00000000..f628b99a --- /dev/null +++ b/src/modlauncher4/java/org/spongepowered/asm/launch/MixinTransformationServiceLegacy.java @@ -0,0 +1,35 @@ +/* + * This file is part of Mixin, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * 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.asm.launch; + +import cpw.mods.modlauncher.api.IEnvironment; + +public class MixinTransformationServiceLegacy extends MixinTransformationServiceAbstract { + + @Override + public void beginScanning(IEnvironment environment) { + } + +} diff --git a/src/modlauncher4/resources/META-INF/services/cpw.mods.modlauncher.api.ITransformationService b/src/modlauncher4/resources/META-INF/services/cpw.mods.modlauncher.api.ITransformationService new file mode 100644 index 00000000..bc0fcd3d --- /dev/null +++ b/src/modlauncher4/resources/META-INF/services/cpw.mods.modlauncher.api.ITransformationService @@ -0,0 +1 @@ +org.spongepowered.asm.launch.MixinTransformationServiceLegacy \ No newline at end of file diff --git a/src/modlauncher4/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService b/src/modlauncher4/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService new file mode 100644 index 00000000..ab235d1b --- /dev/null +++ b/src/modlauncher4/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService @@ -0,0 +1 @@ +org.spongepowered.asm.launch.MixinLaunchPluginLegacy \ No newline at end of file diff --git a/src/modlauncher/resources/META-INF/services/org.spongepowered.asm.service.IGlobalPropertyService b/src/modlauncher4/resources/META-INF/services/org.spongepowered.asm.service.IGlobalPropertyService similarity index 100% rename from src/modlauncher/resources/META-INF/services/org.spongepowered.asm.service.IGlobalPropertyService rename to src/modlauncher4/resources/META-INF/services/org.spongepowered.asm.service.IGlobalPropertyService diff --git a/src/modlauncher/resources/META-INF/services/org.spongepowered.asm.service.IMixinService b/src/modlauncher4/resources/META-INF/services/org.spongepowered.asm.service.IMixinService similarity index 100% rename from src/modlauncher/resources/META-INF/services/org.spongepowered.asm.service.IMixinService rename to src/modlauncher4/resources/META-INF/services/org.spongepowered.asm.service.IMixinService diff --git a/src/modlauncher/resources/META-INF/services/org.spongepowered.asm.service.IMixinServiceBootstrap b/src/modlauncher4/resources/META-INF/services/org.spongepowered.asm.service.IMixinServiceBootstrap similarity index 100% rename from src/modlauncher/resources/META-INF/services/org.spongepowered.asm.service.IMixinServiceBootstrap rename to src/modlauncher4/resources/META-INF/services/org.spongepowered.asm.service.IMixinServiceBootstrap diff --git a/src/modlauncher9/java/org/spongepowered/asm/launch/MixinLaunchPlugin.java b/src/modlauncher9/java/org/spongepowered/asm/launch/MixinLaunchPlugin.java new file mode 100644 index 00000000..6190d06e --- /dev/null +++ b/src/modlauncher9/java/org/spongepowered/asm/launch/MixinLaunchPlugin.java @@ -0,0 +1,38 @@ +/* + * This file is part of Mixin, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * 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.asm.launch; + +import cpw.mods.modlauncher.api.NamedPath; +import cpw.mods.modlauncher.serviceapi.ILaunchPluginService.ITransformerLoader; + +public class MixinLaunchPlugin extends MixinLaunchPluginLegacy { + + // ModLauncher 9+ + @Override + public void initializeLaunch(ITransformerLoader transformerLoader, NamedPath[] specialPaths) { + this.initializeLaunch(transformerLoader); + } + +} diff --git a/src/modlauncher9/java/org/spongepowered/asm/launch/MixinTransformationService.java b/src/modlauncher9/java/org/spongepowered/asm/launch/MixinTransformationService.java new file mode 100644 index 00000000..caa2cd8b --- /dev/null +++ b/src/modlauncher9/java/org/spongepowered/asm/launch/MixinTransformationService.java @@ -0,0 +1,34 @@ +/* + * This file is part of Mixin, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * 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.asm.launch; + +/** + * Service for handling transforms mixin under ModLauncher, now just a concrete + * class which extends the abstract base class used for pre-9 versions of + * ModLauncher + */ +public class MixinTransformationService extends MixinTransformationServiceAbstract { + +} diff --git a/src/modlauncher9/java/org/spongepowered/asm/launch/platform/container/ContainerHandleModLauncherEx.java b/src/modlauncher9/java/org/spongepowered/asm/launch/platform/container/ContainerHandleModLauncherEx.java new file mode 100644 index 00000000..a6553ef5 --- /dev/null +++ b/src/modlauncher9/java/org/spongepowered/asm/launch/platform/container/ContainerHandleModLauncherEx.java @@ -0,0 +1,76 @@ +/* + * This file is part of Mixin, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * 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.asm.launch.platform.container; + +import java.nio.file.Path; + +import cpw.mods.jarhandling.SecureJar; + +/** + * ModLauncher root container for ModLauncher 9+ + */ +public class ContainerHandleModLauncherEx extends ContainerHandleModLauncher { + + /** + * Container handle for secure jar resources offered by ModLauncher + */ + static class SecureJarResource extends ContainerHandleURI { + + private SecureJar jar; + + public SecureJarResource(SecureJar resource) { + super(resource.getPrimaryPath().toUri()); + this.jar = resource; + } + + public String getName() { + return this.jar.name(); + } + + public Path getPath() { + return this.jar.getPrimaryPath(); + } + + @Override + public String toString() { + return String.format("SecureJarResource(%s)", this.getName()); + } + + } + + public ContainerHandleModLauncherEx(String name) { + super(name); + } + + @Override + public void addResource(Object resource) { + if (resource instanceof SecureJar) { + this.add(new SecureJarResource((SecureJar)resource)); + } else { + super.addResource(resource); + } + } + +} diff --git a/src/modularity/java/module-info.java b/src/modularity/java/module-info.java new file mode 100644 index 00000000..678435b6 --- /dev/null +++ b/src/modularity/java/module-info.java @@ -0,0 +1,139 @@ +/* + * This file is part of Mixin, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * 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. + */ + +/** + * Mixin module declaration + */ +@SuppressWarnings("module") // Suppress the warnings about gson and gson below +module org.spongepowered.mixin { + + // + // Actual modules we depend on + // + requires transitive cpw.mods.modlauncher; + requires cpw.mods.securejarhandler; + requires transitive java.compiler; + requires transitive java.instrument; + requires transitive org.apache.logging.log4j; + requires org.apache.logging.log4j.core; + requires transitive org.objectweb.asm; + requires transitive org.objectweb.asm.commons; + requires transitive org.objectweb.asm.tree; + requires transitive org.objectweb.asm.tree.analysis; + requires transitive org.objectweb.asm.util; + + // + // Automatic modules we depend on + // + requires jopt.simple; + requires guava; + requires gson; + + // + // Exports + // + exports org.spongepowered.asm.launch; + exports org.spongepowered.asm.launch.platform; + exports org.spongepowered.asm.launch.platform.container; + exports org.spongepowered.asm.lib; + exports org.spongepowered.asm.lib.tree; + exports org.spongepowered.asm.mixin; + exports org.spongepowered.asm.mixin.connect; + exports org.spongepowered.asm.mixin.extensibility; + exports org.spongepowered.asm.mixin.gen; + exports org.spongepowered.asm.mixin.gen.throwables; + exports org.spongepowered.asm.mixin.injection; + exports org.spongepowered.asm.mixin.injection.callback; + exports org.spongepowered.asm.mixin.injection.code; + exports org.spongepowered.asm.mixin.injection.invoke.arg; + exports org.spongepowered.asm.mixin.injection.points; + exports org.spongepowered.asm.mixin.injection.selectors; + exports org.spongepowered.asm.mixin.injection.selectors.dynamic; + exports org.spongepowered.asm.mixin.injection.selectors.throwables; + exports org.spongepowered.asm.mixin.injection.struct; + exports org.spongepowered.asm.mixin.injection.throwables; + exports org.spongepowered.asm.mixin.refmap; + exports org.spongepowered.asm.mixin.throwables; + exports org.spongepowered.asm.mixin.transformer.ext; + exports org.spongepowered.asm.mixin.transformer.throwables; + exports org.spongepowered.asm.obfuscation; + exports org.spongepowered.asm.obfuscation.mapping; + exports org.spongepowered.asm.obfuscation.mapping.common; + exports org.spongepowered.asm.obfuscation.mapping.mcp; + exports org.spongepowered.asm.service; + exports org.spongepowered.asm.service.modlauncher; + exports org.spongepowered.asm.util; + exports org.spongepowered.asm.util.asm; + exports org.spongepowered.asm.util.perf; + exports org.spongepowered.tools.agent; + exports org.spongepowered.tools.obfuscation; + exports org.spongepowered.tools.obfuscation.ext; + exports org.spongepowered.tools.obfuscation.fg3; + exports org.spongepowered.tools.obfuscation.interfaces; + exports org.spongepowered.tools.obfuscation.mapping; + exports org.spongepowered.tools.obfuscation.mapping.common; + exports org.spongepowered.tools.obfuscation.mapping.fg3; + exports org.spongepowered.tools.obfuscation.mapping.mcp; + exports org.spongepowered.tools.obfuscation.mcp; + exports org.spongepowered.tools.obfuscation.mirror; + exports org.spongepowered.tools.obfuscation.service; + + // one of these won't exist, the SuppressWarnings above stops the compiler complaining + opens org.spongepowered.asm.mixin.transformer + to com.google.gson, gson; + + // + // Service wiring + // + uses org.spongepowered.asm.service.IMixinServiceBootstrap; + provides org.spongepowered.asm.service.IMixinServiceBootstrap + with org.spongepowered.asm.service.modlauncher.MixinServiceModLauncherBootstrap; + + uses org.spongepowered.asm.service.IMixinService; + provides org.spongepowered.asm.service.IMixinService + with org.spongepowered.asm.service.modlauncher.MixinServiceModLauncher; + + uses org.spongepowered.asm.service.IGlobalPropertyService; + provides org.spongepowered.asm.service.IGlobalPropertyService + with org.spongepowered.asm.service.modlauncher.Blackboard; + + uses cpw.mods.modlauncher.api.ITransformationService; + provides cpw.mods.modlauncher.api.ITransformationService + with org.spongepowered.asm.launch.MixinTransformationService; + + uses cpw.mods.modlauncher.serviceapi.ILaunchPluginService; + provides cpw.mods.modlauncher.serviceapi.ILaunchPluginService + with org.spongepowered.asm.launch.MixinLaunchPlugin; + + uses javax.annotation.processing.Processor; + provides javax.annotation.processing.Processor + with org.spongepowered.tools.obfuscation.MixinObfuscationProcessorInjection, + org.spongepowered.tools.obfuscation.MixinObfuscationProcessorTargets; + + uses org.spongepowered.tools.obfuscation.service.IObfuscationService; + provides org.spongepowered.tools.obfuscation.service.IObfuscationService + with org.spongepowered.tools.obfuscation.mcp.ObfuscationServiceMCP, + org.spongepowered.tools.obfuscation.fg3.ObfuscationServiceFG3; +}