migrate away fabric-mixin-compile-extensions, fix root/sub project issues wrt mixin/loom presence hopefully once and for all
parent
17b8aa7a70
commit
88796b3c0f
|
@ -41,11 +41,7 @@ dependencies {
|
|||
transitive = false
|
||||
}
|
||||
implementation ('org.jetbrains:intellij-fernflower:1.0.0.8')
|
||||
|
||||
implementation ('net.fabricmc:sponge-mixin:0.7.11.27') {
|
||||
exclude module: 'launchwrapper'
|
||||
exclude module: 'guava'
|
||||
}
|
||||
implementation ('net.fabricmc:fabric-mixin-compile-extensions:0.1.0.+')
|
||||
|
||||
implementation ('org.cadixdev:mercury:0.1.0.fabric-SNAPSHOT')
|
||||
|
||||
|
|
|
@ -34,8 +34,13 @@ import net.fabricmc.loom.util.*;
|
|||
import org.gradle.api.*;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.Dependency;
|
||||
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
|
||||
import org.gradle.api.artifacts.dsl.DependencyHandler;
|
||||
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
|
||||
import org.gradle.api.artifacts.result.DependencyResult;
|
||||
import org.gradle.api.artifacts.result.ResolvedArtifactResult;
|
||||
import org.gradle.api.artifacts.result.ResolvedComponentResult;
|
||||
import org.gradle.api.artifacts.result.ResolvedDependencyResult;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginConvention;
|
||||
import org.gradle.api.publish.Publication;
|
||||
|
@ -54,6 +59,7 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class AbstractPlugin implements Plugin<Project> {
|
||||
protected Project project;
|
||||
|
@ -170,6 +176,39 @@ public class AbstractPlugin implements Plugin<Project> {
|
|||
EclipseModel eclipseModel = (EclipseModel) project.getExtensions().getByName("eclipse");
|
||||
}
|
||||
|
||||
private void addModule(Project proj, String configuration, DependencyResult module) {
|
||||
if (module instanceof ResolvedDependencyResult) {
|
||||
if (module.getFrom().getId() instanceof ModuleComponentIdentifier) {
|
||||
ModuleComponentIdentifier mci = ((ModuleComponentIdentifier) module.getFrom().getId());
|
||||
proj.getDependencies().add(configuration, proj.getDependencies().module(mci.getGroup() + ":" + mci.getModule() + ":" + mci.getVersion()));
|
||||
}
|
||||
|
||||
for (DependencyResult child : ((ResolvedDependencyResult) module).getSelected().getDependencies()) {
|
||||
addModule(proj, configuration, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean findAndAddModule(Project project, String configuration, DependencyResult dep, Predicate<ModuleComponentIdentifier> predicate) {
|
||||
boolean found = false;
|
||||
|
||||
if (dep instanceof ResolvedDependencyResult) {
|
||||
if (dep.getFrom().getId() instanceof ModuleComponentIdentifier) {
|
||||
ModuleComponentIdentifier mci = ((ModuleComponentIdentifier) dep.getFrom().getId());
|
||||
if (predicate.test(mci)) {
|
||||
addModule(project, configuration, dep);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (DependencyResult child : ((ResolvedDependencyResult) dep).getSelected().getDependencies()) {
|
||||
findAndAddModule(project, configuration, child, predicate);
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Minecraft dependencies to compile time
|
||||
*/
|
||||
|
@ -182,6 +221,17 @@ public class AbstractPlugin implements Plugin<Project> {
|
|||
Javadoc javadoc = (Javadoc) project.getTasks().getByName(JavaPlugin.JAVADOC_TASK_NAME);
|
||||
javadoc.setClasspath(main.getOutput().plus(main.getCompileClasspath()));
|
||||
|
||||
// Add Mixin dependencies
|
||||
Project p = project;
|
||||
while (true) {
|
||||
boolean found = false;
|
||||
for (DependencyResult dep : p.getBuildscript().getConfigurations().getByName("classpath").getIncoming().getResolutionResult().getRoot().getDependencies()) {
|
||||
found = findAndAddModule(project, "annotationProcessor", dep, (mci) -> ("net.fabricmc".equals(mci.getGroup()) && "fabric-mixin-compile-extensions".equals(mci.getModule())));
|
||||
}
|
||||
if (found || AbstractPlugin.isRootProject(p)) break;
|
||||
p = p.getRootProject();
|
||||
}
|
||||
|
||||
project.afterEvaluate(project1 -> {
|
||||
LoomGradleExtension extension = project1.getExtensions().getByType(LoomGradleExtension.class);
|
||||
|
||||
|
@ -233,11 +283,6 @@ public class AbstractPlugin implements Plugin<Project> {
|
|||
SetupIntelijRunConfigs.setup(project1);
|
||||
}
|
||||
|
||||
// add dependencies for mixin annotation processor
|
||||
DependencyHandler handler = project1.getDependencies();
|
||||
handler.add("annotationProcessor", "net.fabricmc:sponge-mixin:" + extension.getMixinVersion());
|
||||
handler.add("annotationProcessor", "net.fabricmc:fabric-loom:" + extension.getLoomVersion());
|
||||
|
||||
// Enables the default mod remapper
|
||||
if (extension.remapMod) {
|
||||
AbstractArchiveTask jarTask = (AbstractArchiveTask) project1.getTasks().getByName("jar");
|
||||
|
|
|
@ -42,6 +42,7 @@ import javax.annotation.Nullable;
|
|||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class LoomGradleExtension {
|
||||
|
@ -138,16 +139,13 @@ public class LoomGradleExtension {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
private ResolvedArtifactResult findDependency(Collection<Configuration> configs, BiPredicate<String, String> groupNameFilter) {
|
||||
private static Dependency findDependency(Collection<Configuration> configs, BiPredicate<String, String> groupNameFilter) {
|
||||
for (Configuration config : configs) {
|
||||
for (ResolvedArtifactResult artifact : config.getIncoming().getArtifacts().getArtifacts()) {
|
||||
ComponentIdentifier artifactId = artifact.getId().getComponentIdentifier();
|
||||
if (artifactId instanceof ModuleComponentIdentifier) {
|
||||
String group = ((ModuleComponentIdentifier) artifactId).getGroup();
|
||||
String name = ((ModuleComponentIdentifier) artifactId).getModule();
|
||||
if (groupNameFilter.test(group, name)) {
|
||||
return artifact;
|
||||
}
|
||||
for (Dependency dependency : config.getDependencies()) {
|
||||
String group = dependency.getGroup();
|
||||
String name = dependency.getName();
|
||||
if (groupNameFilter.test(group, name)) {
|
||||
return dependency;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -156,63 +154,47 @@ public class LoomGradleExtension {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
private ResolvedArtifactResult findBuildscriptDependency(BiPredicate<String, String> groupNameFilter) {
|
||||
return findDependency(project.getBuildscript().getConfigurations(), groupNameFilter);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getLoomVersion() {
|
||||
ResolvedArtifactResult dependency = findBuildscriptDependency((group, name) -> {
|
||||
if (name.equalsIgnoreCase("fabric-loom")) {
|
||||
return group.equalsIgnoreCase("net.fabricmc");
|
||||
}
|
||||
|
||||
if (name.equalsIgnoreCase("fabric-loom.gradle.plugin")) {
|
||||
return group.equalsIgnoreCase("fabric-loom");
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if(dependency == null && !AbstractPlugin.isRootProject(project)){
|
||||
try {
|
||||
return project.getRootProject().getExtensions().getByType(LoomGradleExtension.class).getLoomVersion();
|
||||
} catch (UnknownDomainObjectException e){
|
||||
return null;
|
||||
private <T> T recurseProjects(Function<Project, T> projectTFunction) {
|
||||
Project p = this.project;
|
||||
T result;
|
||||
while (!AbstractPlugin.isRootProject(p)) {
|
||||
if ((result = projectTFunction.apply(p)) != null) {
|
||||
return result;
|
||||
}
|
||||
p = p.getRootProject();
|
||||
}
|
||||
|
||||
return dependency != null ? ((ModuleComponentIdentifier) dependency.getId().getComponentIdentifier()).getVersion() : null;
|
||||
result = projectTFunction.apply(p);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ResolvedArtifactResult getMixinDependency() {
|
||||
return findDependency(Collections.singletonList(project.getConfigurations().getByName("compile")), (group, name) -> {
|
||||
if (name.equalsIgnoreCase("mixin") && group.equalsIgnoreCase("org.spongepowered")) {
|
||||
return true;
|
||||
}
|
||||
private Dependency getMixinDependency() {
|
||||
return recurseProjects((p) -> {
|
||||
List<Configuration> configs = new ArrayList<>();
|
||||
// check compile first
|
||||
configs.add(p.getConfigurations().getByName("compile"));
|
||||
// failing that, buildscript
|
||||
configs.addAll(p.getBuildscript().getConfigurations());
|
||||
|
||||
if (name.equalsIgnoreCase("sponge-mixin") && group.equalsIgnoreCase("net.fabricmc")) {
|
||||
return true;
|
||||
}
|
||||
return findDependency(configs, (group, name) -> {
|
||||
if (name.equalsIgnoreCase("mixin") && group.equalsIgnoreCase("org.spongepowered")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
if (name.equalsIgnoreCase("sponge-mixin") && group.equalsIgnoreCase("net.fabricmc")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getMixinVersion() {
|
||||
ResolvedArtifactResult dependency = getMixinDependency();
|
||||
return dependency != null ? ((ModuleComponentIdentifier) dependency.getId().getComponentIdentifier()).getVersion() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getMixinJsonVersion() {
|
||||
ResolvedArtifactResult artifactResult = getMixinDependency();
|
||||
|
||||
if (artifactResult != null) {
|
||||
ModuleComponentIdentifier dependency = ((ModuleComponentIdentifier) artifactResult.getId().getComponentIdentifier());
|
||||
Dependency dependency = getMixinDependency();
|
||||
|
||||
if (dependency != null) {
|
||||
if (dependency.getGroup().equalsIgnoreCase("net.fabricmc")) {
|
||||
if (Objects.requireNonNull(dependency.getVersion()).split("\\.").length >= 4) {
|
||||
return dependency.getVersion().substring(0, dependency.getVersion().lastIndexOf('.')) + "-SNAPSHOT";
|
||||
|
|
|
@ -1,153 +0,0 @@
|
|||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2016, 2017, 2018 FabricMC
|
||||
*
|
||||
* 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 net.fabricmc.loom.mixin;
|
||||
|
||||
import net.fabricmc.mappings.*;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.mapping.common.MappingProvider;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.annotation.processing.Messager;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MixinMappingProviderTiny extends MappingProvider {
|
||||
private final String from, to;
|
||||
|
||||
public MixinMappingProviderTiny(Messager messager, Filer filer, String from, String to) {
|
||||
super(messager, filer);
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
private static String[] removeFirst(String[] src, int count) {
|
||||
if (count >= src.length) {
|
||||
return new String[0];
|
||||
} else {
|
||||
String[] out = new String[src.length - count];
|
||||
System.arraycopy(src, count, out, 0, out.length);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingMethod getMethodMapping(MappingMethod method) {
|
||||
MappingMethod mapped = this.methodMap.get(method);
|
||||
if (mapped != null)
|
||||
return mapped;
|
||||
|
||||
try {
|
||||
Class c = this.getClass().getClassLoader().loadClass(method.getOwner().replace('/', '.'));
|
||||
if (c == null || c == Object.class) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (Class cc : c.getInterfaces()) {
|
||||
mapped = getMethodMapping(method.move(cc.getName().replace('.', '/')));
|
||||
if (mapped != null) {
|
||||
mapped = mapped.move(classMap.getOrDefault(method.getOwner(), method.getOwner()));
|
||||
methodMap.put(method, mapped);
|
||||
return mapped;
|
||||
}
|
||||
}
|
||||
|
||||
if (c.getSuperclass() != null) {
|
||||
mapped = getMethodMapping(method.move(c.getSuperclass().getName().replace('.', '/')));
|
||||
if (mapped != null) {
|
||||
mapped = mapped.move(classMap.getOrDefault(method.getOwner(), method.getOwner()));
|
||||
methodMap.put(method, mapped);
|
||||
return mapped;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingField getFieldMapping(MappingField field) {
|
||||
MappingField mapped = this.fieldMap.get(field);
|
||||
if (mapped != null)
|
||||
return mapped;
|
||||
|
||||
return null;
|
||||
|
||||
/* try {
|
||||
Class c = this.getClass().getClassLoader().loadClass(field.getOwner().replace('/', '.'));
|
||||
if (c == null || c == Object.class) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (c.getSuperclass() != null) {
|
||||
mapped = getFieldMapping(field.move(c.getSuperclass().getName().replace('.', '/')));
|
||||
if (mapped != null)
|
||||
return mapped;
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(File input) throws IOException {
|
||||
Mappings mappings;
|
||||
|
||||
try (FileInputStream stream = new FileInputStream(input)) {
|
||||
mappings = MappingsProvider.readTinyMappings(stream, false);
|
||||
}
|
||||
|
||||
for (ClassEntry entry : mappings.getClassEntries()) {
|
||||
classMap.put(entry.get(from), entry.get(to));
|
||||
}
|
||||
|
||||
for (FieldEntry entry : mappings.getFieldEntries()) {
|
||||
EntryTriple fromEntry = entry.get(from);
|
||||
EntryTriple toEntry = entry.get(to);
|
||||
|
||||
fieldMap.put(
|
||||
new MappingField(fromEntry.getOwner(), fromEntry.getName(), fromEntry.getDesc()),
|
||||
new MappingField(toEntry.getOwner(), toEntry.getName(), toEntry.getDesc())
|
||||
);
|
||||
}
|
||||
|
||||
for (MethodEntry entry : mappings.getMethodEntries()) {
|
||||
EntryTriple fromEntry = entry.get(from);
|
||||
EntryTriple toEntry = entry.get(to);
|
||||
|
||||
methodMap.put(
|
||||
new MappingMethod(fromEntry.getOwner(), fromEntry.getName(), fromEntry.getDesc()),
|
||||
new MappingMethod(toEntry.getOwner(), toEntry.getName(), toEntry.getDesc())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2016, 2017, 2018 FabricMC
|
||||
*
|
||||
* 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 net.fabricmc.loom.mixin;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationType;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer;
|
||||
import org.spongepowered.tools.obfuscation.mapping.common.MappingWriter;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.annotation.processing.Messager;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* Created by asie on 10/9/16.
|
||||
*/
|
||||
public class MixinMappingWriterTiny extends MappingWriter {
|
||||
public MixinMappingWriterTiny(Messager messager, Filer filer) {
|
||||
super(messager, filer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(String output, ObfuscationType type, IMappingConsumer.MappingSet<MappingField> fields, IMappingConsumer.MappingSet<MappingMethod> methods) {
|
||||
if (output != null) {
|
||||
String from = type.getKey().split(":")[0];
|
||||
String to = type.getKey().split(":")[1];
|
||||
|
||||
try (PrintWriter writer = this.openFileWriter(output, type + " output TinyMappings")) {
|
||||
writer.println(String.format("v1\t%s\t%s", from, to));
|
||||
for (IMappingConsumer.MappingSet.Pair<MappingField> pair : fields) {
|
||||
writer.println(String.format("FIELD\t%s\t%s\t%s\t%s", pair.from.getOwner(), pair.from.getDesc(), pair.from.getSimpleName(), pair.to.getSimpleName()));
|
||||
}
|
||||
for (IMappingConsumer.MappingSet.Pair<MappingMethod> pair : methods) {
|
||||
writer.println(String.format("METHOD\t%s\t%s\t%s\t%s", pair.from.getOwner(), pair.from.getDesc(), pair.from.getSimpleName(), pair.to.getSimpleName()));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,189 +0,0 @@
|
|||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2016, 2017, 2018 FabricMC
|
||||
*
|
||||
* 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 net.fabricmc.loom.mixin;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import org.spongepowered.asm.lib.ClassReader;
|
||||
import org.spongepowered.asm.lib.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.service.*;
|
||||
import org.spongepowered.asm.util.ReEntranceLock;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
public class MixinServiceGradle implements IClassBytecodeProvider, IClassProvider, IMixinService {
|
||||
private static List<JarFile> jars = new ArrayList<>();
|
||||
private final ReEntranceLock lock = new ReEntranceLock(1);
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "FabricGradle";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public MixinEnvironment.Phase getInitialPhase() {
|
||||
return MixinEnvironment.Phase.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginPhase() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkEnv(Object bootSource) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReEntranceLock getReEntranceLock() {
|
||||
return lock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClassProvider getClassProvider() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(String name) {
|
||||
for (JarFile file : jars) {
|
||||
ZipEntry entry = file.getEntry(name);
|
||||
if(entry != null){
|
||||
try {
|
||||
return file.getInputStream(entry);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to read mod file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return getClass().getClassLoader().getResourceAsStream(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerInvalidClass(String className) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClassLoaded(String className) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassRestrictions(String className) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ITransformer> getTransformers() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSideName() {
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
public static void setupModFiles(Set<File> mods, File minecraft) throws IOException {
|
||||
jars.clear();
|
||||
for(File mod : mods){
|
||||
JarFile jarFile = new JarFile(mod);
|
||||
jars.add(jarFile);
|
||||
}
|
||||
jars.add(new JarFile(minecraft));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClassBytecodeProvider getBytecodeProvider() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getPlatformAgents() {
|
||||
return Collections.singletonList("org.spongepowered.asm.launch.platform.MixinPlatformAgentDefault");
|
||||
}
|
||||
|
||||
public byte[] getClassBytes(String name, String transformedName) throws IOException {
|
||||
try (InputStream inputStream = getResourceAsStream(name.replace(".", "/") + ".class")) {
|
||||
return ByteStreams.toByteArray(inputStream);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getClassBytes(String name, boolean runTransformers) throws ClassNotFoundException, IOException {
|
||||
return getClassBytes(name, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassNode getClassNode(String name) throws ClassNotFoundException, IOException {
|
||||
ClassReader reader = new ClassReader(getClassBytes(name, name));
|
||||
ClassNode node = new ClassNode();
|
||||
reader.accept(node, 0);
|
||||
return node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL[] getClassPath() {
|
||||
return new URL[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
return Class.forName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> findClass(String name, boolean initialize) throws ClassNotFoundException {
|
||||
return Class.forName(name, initialize, getClass().getClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> findAgentClass(String name, boolean initialize) throws ClassNotFoundException {
|
||||
return Class.forName(name, initialize, getClass().getClassLoader());
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2016, 2017, 2018 FabricMC
|
||||
*
|
||||
* 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 net.fabricmc.loom.mixin;
|
||||
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationEnvironment;
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationType;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingProvider;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingWriter;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.annotation.processing.Messager;
|
||||
|
||||
public class ObfuscationEnvironmentFabric extends ObfuscationEnvironment {
|
||||
protected ObfuscationEnvironmentFabric(ObfuscationType type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IMappingProvider getMappingProvider(Messager messager, Filer filer) {
|
||||
String[] key = type.getKey().split(":");
|
||||
return new MixinMappingProviderTiny(messager, filer, key[0], key[1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IMappingWriter getMappingWriter(Messager messager, Filer filer) {
|
||||
return new MixinMappingWriterTiny(messager, filer);
|
||||
}
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2016, 2017, 2018 FabricMC
|
||||
*
|
||||
* 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 net.fabricmc.loom.mixin;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import net.fabricmc.loom.util.LoomUtil;
|
||||
import org.spongepowered.tools.obfuscation.service.IObfuscationService;
|
||||
import org.spongepowered.tools.obfuscation.service.ObfuscationTypeDescriptor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
public class ObfuscationServiceFabric implements IObfuscationService {
|
||||
public static final String IN_MAP_FILE = "inMapFile";
|
||||
public static final String IN_MAP_EXTRA_FILES = "inMapExtraFiles";
|
||||
public static final String OUT_MAP_FILE = "outMapFile";
|
||||
|
||||
private String asSuffixed(String arg, String from, String to) {
|
||||
return arg + LoomUtil.capitalize(from) + LoomUtil.capitalize(to);
|
||||
}
|
||||
|
||||
private ObfuscationTypeDescriptor createObfuscationType(String from, String to) {
|
||||
return new ObfuscationTypeDescriptor(
|
||||
from + ":" + to,
|
||||
asSuffixed(ObfuscationServiceFabric.IN_MAP_FILE, from, to),
|
||||
asSuffixed(ObfuscationServiceFabric.IN_MAP_EXTRA_FILES, from, to),
|
||||
asSuffixed(ObfuscationServiceFabric.OUT_MAP_FILE, from, to),
|
||||
ObfuscationEnvironmentFabric.class
|
||||
);
|
||||
}
|
||||
|
||||
private void addSupportedOptions(ImmutableSet.Builder<String> builder, String from, String to) {
|
||||
builder.add(asSuffixed(ObfuscationServiceFabric.IN_MAP_FILE, from, to));
|
||||
builder.add(asSuffixed(ObfuscationServiceFabric.IN_MAP_EXTRA_FILES, from, to));
|
||||
builder.add(asSuffixed(ObfuscationServiceFabric.OUT_MAP_FILE, from, to));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedOptions() {
|
||||
ImmutableSet.Builder<String> builder = new ImmutableSet.Builder<>();
|
||||
addSupportedOptions(builder, "official", "intermediary");
|
||||
addSupportedOptions(builder, "official", "named");
|
||||
addSupportedOptions(builder, "intermediary", "official");
|
||||
addSupportedOptions(builder, "intermediary", "named");
|
||||
addSupportedOptions(builder, "named", "official");
|
||||
addSupportedOptions(builder, "named", "intermediary");
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ObfuscationTypeDescriptor> getObfuscationTypes() {
|
||||
return ImmutableSet.of(
|
||||
createObfuscationType("official", "intermediary"),
|
||||
createObfuscationType("official", "named"),
|
||||
createObfuscationType("intermediary", "official"),
|
||||
createObfuscationType("intermediary", "named"),
|
||||
createObfuscationType("named", "official"),
|
||||
createObfuscationType("named", "intermediary")
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2016, 2017, 2018 FabricMC
|
||||
*
|
||||
* 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 net.fabricmc.loom.util;
|
||||
|
||||
public final class LoomUtil {
|
||||
private LoomUtil() {
|
||||
|
||||
}
|
||||
|
||||
public static String capitalize(String s) {
|
||||
return s.substring(0, 1).toUpperCase() + s.substring(1);
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
net.fabricmc.loom.mixin.MixinServiceGradle
|
|
@ -1 +0,0 @@
|
|||
net.fabricmc.loom.mixin.ObfuscationServiceFabric
|
Loading…
Reference in New Issue