Remove some mixin prebaker stuff we no longer need
This commit is contained in:
		
							parent
							
								
									9a2b847772
								
							
						
					
					
						commit
						8481ccc478
					
				
					 7 changed files with 5 additions and 476 deletions
				
			
		|  | @ -35,8 +35,7 @@ public class LoomGradlePlugin extends AbstractPlugin { | |||
| 
 | ||||
| 		makeTask("download", DownloadTask.class); | ||||
| 		makeTask("mergeJars", MergeJarsTask.class).dependsOn("download"); | ||||
| 		makeTask("processMods", ProcessModsTask.class).dependsOn("mergeJars"); | ||||
| 		makeTask("mapJars", MapJarsTask.class).dependsOn("processMods"); | ||||
| 		makeTask("mapJars", MapJarsTask.class).dependsOn("mergeJars"); | ||||
| 		makeTask("finaliseJars", FinaliseJar.class).dependsOn("mapJars"); | ||||
| 		makeTask("setup", DefaultTask.class).dependsOn("finaliseJars").setGroup("fabric"); | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,8 +1,6 @@ | |||
| package net.fabricmc.loom.mixin; | ||||
| 
 | ||||
| import com.google.common.io.ByteStreams; | ||||
| import net.fabricmc.loom.task.ProcessModsTask; | ||||
| import net.fabricmc.loom.util.proccessing.MixinPrebaker; | ||||
| import org.spongepowered.asm.service.IClassBytecodeProvider; | ||||
| import org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapper; | ||||
| 
 | ||||
|  | @ -27,9 +25,6 @@ public class MixinServiceGradle extends MixinServiceLaunchWrapper implements ICl | |||
| 
 | ||||
| 	@Override | ||||
| 	public InputStream getResourceAsStream(String name) { | ||||
| 		if(MixinPrebaker.jarFileCache.containsKey(name)){ | ||||
| 			return MixinPrebaker.jarFileCache.get(name); | ||||
| 		} | ||||
| 		for(JarFile file : jars){ | ||||
| 			ZipEntry entry = file.getEntry(name); | ||||
| 			if(entry != null){ | ||||
|  | @ -53,14 +48,6 @@ public class MixinServiceGradle extends MixinServiceLaunchWrapper implements ICl | |||
| 		jars.add(new JarFile(minecraft)); | ||||
| 	} | ||||
| 
 | ||||
| 	public static void addMCDeps(Set<File> deps, Object object) throws IOException { | ||||
| 		for(File mod : deps){ | ||||
| 			JarFile jarFile = new JarFile(mod); | ||||
| 			jars.add(jarFile); | ||||
| 			ProcessModsTask.addFile(mod, object); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public IClassBytecodeProvider getBytecodeProvider() { | ||||
| 		return this; | ||||
|  |  | |||
|  | @ -51,7 +51,7 @@ public class MapJarsTask extends DefaultTask { | |||
| 			} | ||||
| 			if(!extension.hasPomf()){ | ||||
| 				this.getLogger().lifecycle("POMF version not set, skipping mapping!"); | ||||
| 				FileUtils.copyFile(Constants.MINECRAFT_MIXED_JAR.get(extension), Constants.MINECRAFT_MAPPED_JAR.get(extension)); | ||||
| 				FileUtils.copyFile(Constants.MINECRAFT_MERGED_JAR.get(extension), Constants.MINECRAFT_MAPPED_JAR.get(extension)); | ||||
| 				return; | ||||
| 			} | ||||
| 
 | ||||
|  | @ -72,10 +72,10 @@ public class MapJarsTask extends DefaultTask { | |||
| 			try { | ||||
| 				OutputConsumerPath outputConsumer = new OutputConsumerPath(Constants.MINECRAFT_MAPPED_JAR.get(extension).toPath()); | ||||
| 				//Rebof the mixed mc jar | ||||
| 				outputConsumer.addNonClassFiles(Constants.MINECRAFT_MIXED_JAR.get(extension).toPath()); | ||||
| 				remapper.read(Constants.MINECRAFT_MIXED_JAR.get(extension).toPath()); | ||||
| 				outputConsumer.addNonClassFiles(Constants.MINECRAFT_MERGED_JAR.get(extension).toPath()); | ||||
| 				remapper.read(Constants.MINECRAFT_MERGED_JAR.get(extension).toPath()); | ||||
| 				remapper.read(classpath); | ||||
| 				remapper.apply(Constants.MINECRAFT_MIXED_JAR.get(extension).toPath(), outputConsumer); | ||||
| 				remapper.apply(Constants.MINECRAFT_MERGED_JAR.get(extension).toPath(), outputConsumer); | ||||
| 				outputConsumer.finish(); | ||||
| 				remapper.finish(); | ||||
| 			} catch (Exception e){ | ||||
|  |  | |||
|  | @ -1,86 +0,0 @@ | |||
| /* | ||||
|  * This file is part of fabric-loom, licensed under the MIT License (MIT). | ||||
|  * | ||||
|  * Copyright (c) 2016 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.task; | ||||
| 
 | ||||
| import net.fabricmc.loom.LoomGradleExtension; | ||||
| import net.fabricmc.loom.util.Constants; | ||||
| import net.fabricmc.loom.util.proccessing.PreBakeMixins; | ||||
| import org.apache.commons.io.FileUtils; | ||||
| import org.gradle.api.DefaultTask; | ||||
| import org.gradle.api.artifacts.Configuration; | ||||
| import org.gradle.api.artifacts.ResolvedArtifact; | ||||
| import org.gradle.api.tasks.TaskAction; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| import java.lang.reflect.InvocationTargetException; | ||||
| import java.lang.reflect.Method; | ||||
| import java.net.MalformedURLException; | ||||
| import java.net.URL; | ||||
| import java.net.URLClassLoader; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| 
 | ||||
| public class ProcessModsTask extends DefaultTask { | ||||
| 	@TaskAction | ||||
| 	public void mix() throws InvocationTargetException, NoSuchMethodException, IllegalAccessException, IOException { | ||||
| 		LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class); | ||||
| 		Configuration configuration = getProject().getConfigurations().getByName(Constants.COMPILE_MODS); | ||||
| 		List<File> mods = new ArrayList<>(); | ||||
| 		for (ResolvedArtifact artifact : configuration.getResolvedConfiguration().getResolvedArtifacts()) { | ||||
| 			//getProject().getLogger().lifecycle(":found mod to mix:" + artifact.getFile().getName()); | ||||
| 			mods.add(artifact.getFile()); | ||||
| 		} | ||||
| 		if (Constants.MINECRAFT_FINAL_JAR.get(extension).exists()) { | ||||
| 			Constants.MINECRAFT_FINAL_JAR.get(extension).delete(); | ||||
| 		} | ||||
| 		if (mods.size() == 0 || extension.skipPrebake) { | ||||
| 			getProject().getLogger().lifecycle(":skipping mixin prebake"); | ||||
| 			FileUtils.copyFile(Constants.MINECRAFT_MERGED_JAR.get(extension), Constants.MINECRAFT_MIXED_JAR.get(extension)); | ||||
| 		} else { | ||||
| 			downloadRequiredDeps(extension); | ||||
| 			new PreBakeMixins().proccess(getProject(), extension, mods); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	public void downloadRequiredDeps(LoomGradleExtension extension) { | ||||
| 		Configuration configuration = getProject().getConfigurations().getByName(Constants.PROCESS_MODS_DEPENDENCIES); | ||||
| 		for (ResolvedArtifact artifact : configuration.getResolvedConfiguration().getResolvedArtifacts()) { | ||||
| 			addFile(artifact.getFile(), this); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	public static void addFile(File file, Object object) { | ||||
| 		try { | ||||
| 			URLClassLoader classLoader = (URLClassLoader) object.getClass().getClassLoader(); | ||||
| 			Class urlClassLoaderClass = URLClassLoader.class; | ||||
| 			Method method = urlClassLoaderClass.getDeclaredMethod("addURL", URL.class); | ||||
| 			method.setAccessible(true); | ||||
| 			method.invoke(classLoader, file.toURI().toURL()); | ||||
| 		} catch (NoSuchMethodException | IllegalAccessException | MalformedURLException | InvocationTargetException e) { | ||||
| 			e.printStackTrace(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | @ -40,7 +40,6 @@ public class Constants { | |||
| 	public static final IDelayed<File> MINECRAFT_CLIENT_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-client.jar")); | ||||
| 	public static final IDelayed<File> MINECRAFT_SERVER_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-server.jar")); | ||||
| 	public static final IDelayed<File> MINECRAFT_MERGED_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-merged.jar")); | ||||
| 	public static final IDelayed<File> MINECRAFT_MIXED_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-mixed.jar")); | ||||
| 	public static final IDelayed<File> MINECRAFT_MAPPED_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-mapped-" + extension.pomfVersion + ".jar")); | ||||
| 	public static final IDelayed<File> MINECRAFT_FINAL_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.version + "-final-" + extension.pomfVersion + ".jar")); | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,317 +0,0 @@ | |||
| /* | ||||
|  * Copyright 2016 FabricMC | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *     http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| package net.fabricmc.loom.util.proccessing; | ||||
| 
 | ||||
| import com.google.common.base.Charsets; | ||||
| import com.google.common.base.Predicate; | ||||
| import com.google.common.io.ByteStreams; | ||||
| import com.google.gson.Gson; | ||||
| import com.google.gson.JsonArray; | ||||
| import com.google.gson.JsonObject; | ||||
| import net.fabricmc.loom.mixin.MixinServiceGradle; | ||||
| import net.minecraft.launchwrapper.Launch; | ||||
| import net.minecraft.launchwrapper.LaunchClassLoader; | ||||
| import org.gradle.api.Project; | ||||
| import org.objectweb.asm.*; | ||||
| import org.spongepowered.asm.launch.GlobalProperties; | ||||
| import org.spongepowered.asm.launch.MixinBootstrap; | ||||
| import org.spongepowered.asm.mixin.EnvironmentStateTweaker; | ||||
| import org.spongepowered.asm.mixin.MixinEnvironment; | ||||
| import org.spongepowered.asm.mixin.Mixins; | ||||
| import org.spongepowered.asm.mixin.transformer.MixinTransformer; | ||||
| import org.spongepowered.asm.service.MixinService; | ||||
| import org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapper; | ||||
| 
 | ||||
| import javax.annotation.Nonnull; | ||||
| import java.io.*; | ||||
| import java.net.URLClassLoader; | ||||
| import java.nio.file.Files; | ||||
| import java.nio.file.attribute.FileTime; | ||||
| import java.time.Instant; | ||||
| import java.util.*; | ||||
| import java.util.jar.JarEntry; | ||||
| import java.util.jar.JarFile; | ||||
| import java.util.jar.JarInputStream; | ||||
| import java.util.jar.JarOutputStream; | ||||
| import java.util.stream.Collectors; | ||||
| import java.util.zip.ZipEntry; | ||||
| 
 | ||||
| /** | ||||
|  * The purpose of this class is to provide an utility for baking mixins from | ||||
|  * mods into a JAR file at compile time to make accessing APIs provided by them | ||||
|  * more intuitive in development environment. | ||||
|  */ | ||||
| public class MixinPrebaker { | ||||
| 	private static class DesprinklingFieldVisitor extends FieldVisitor { | ||||
| 		public DesprinklingFieldVisitor(int api, FieldVisitor fv) { | ||||
| 			super(api, fv); | ||||
| 		} | ||||
| 
 | ||||
| 		@Override | ||||
| 		public AnnotationVisitor visitAnnotation(String desc, boolean visible) { | ||||
| 			if (isSprinkledAnnotation(desc)) { | ||||
| 				return null; | ||||
| 			} | ||||
| 			return super.visitAnnotation(desc, visible); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	private static class DesprinklingMethodVisitor extends MethodVisitor { | ||||
| 		public DesprinklingMethodVisitor(int api, MethodVisitor mv) { | ||||
| 			super(api, mv); | ||||
| 		} | ||||
| 
 | ||||
| 		@Override | ||||
| 		public AnnotationVisitor visitAnnotation(String desc, boolean visible) { | ||||
| 			if (isSprinkledAnnotation(desc)) { | ||||
| 				return null; | ||||
| 			} | ||||
| 			return super.visitAnnotation(desc, visible); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	private static class DesprinklingClassVisitor extends ClassVisitor { | ||||
| 		public DesprinklingClassVisitor(int api, ClassVisitor cv) { | ||||
| 			super(api, cv); | ||||
| 		} | ||||
| 
 | ||||
| 		@Override | ||||
| 		public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { | ||||
| 			return new DesprinklingFieldVisitor(Opcodes.ASM5, super.visitField(access, name, desc, signature, value)); | ||||
| 		} | ||||
| 
 | ||||
| 		@Override | ||||
| 		public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { | ||||
| 			return new DesprinklingMethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)); | ||||
| 		} | ||||
| 
 | ||||
| 		@Override | ||||
| 		public AnnotationVisitor visitAnnotation(String desc, boolean visible) { | ||||
| 			if (isSprinkledAnnotation(desc)) { | ||||
| 				return null; | ||||
| 			} | ||||
| 			return super.visitAnnotation(desc, visible); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	private static boolean isSprinkledAnnotation(String desc) { | ||||
| 		//System.out.println(desc); | ||||
| 		return desc.startsWith("Lorg/spongepowered/asm/mixin/transformer/meta"); | ||||
| 	} | ||||
| 
 | ||||
| 	// Term proposed by Mumfrey, don't blame me | ||||
| 	public static byte[] desprinkle(byte[] cls) { | ||||
| 		ClassReader reader = new ClassReader(cls); | ||||
| 		ClassWriter writer = new ClassWriter(0); | ||||
| 
 | ||||
| 		reader.accept(new DesprinklingClassVisitor(Opcodes.ASM5, writer), 0); | ||||
| 		return writer.toByteArray(); | ||||
| 	} | ||||
| 
 | ||||
| 	public static final String APPLIED_MIXIN_CONFIGS_FILENAME = ".fabric-applied-mixin-configs"; | ||||
| 	public static final String MAPPINGS_FILENAME = ".fabric-dev-mappings.tiny"; | ||||
| 
 | ||||
| 	public static Map<String, InputStream> jarFileCache = new HashMap<>(); | ||||
| 
 | ||||
| 	public static void main(String[] args, Project project) throws IOException { | ||||
| 		boolean hasMappingsFile = false; | ||||
| 
 | ||||
| 		if (args.length < 3) { | ||||
| 			System.out.println("usage: MixinPrebaker [-m mapping-file] <input-jar> <output-jar> <mod-jars...>"); | ||||
| 			return; | ||||
| 		} | ||||
| 
 | ||||
| 		File mappingsFile = null; | ||||
| 		int argOffset; | ||||
| 		for (argOffset = 0; argOffset < args.length; argOffset++) { | ||||
| 			if ("-m".equals(args[argOffset])) { | ||||
| 				hasMappingsFile = true; | ||||
| 				mappingsFile = new File(args[++argOffset]); | ||||
| 				//TODO this is prob what was handling the mixin remmapping, this may need to be added back | ||||
| 				//FabricMixinBootstrap.setMappingFile(); | ||||
| 			} else { | ||||
| 				break; | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 		Set<File> modFiles = new HashSet<>(); | ||||
| 		for (int i = argOffset + 2; i < args.length; i++) { | ||||
| 			modFiles.add(new File(args[i])); | ||||
| 		} | ||||
| 
 | ||||
| 		URLClassLoader ucl = (URLClassLoader) MixinPrebaker.class.getClassLoader(); | ||||
| 		Launch.classLoader = new LaunchClassLoader(ucl.getURLs()); | ||||
| 		Launch.blackboard = new HashMap<>(); | ||||
| 		Launch.blackboard.put(MixinServiceLaunchWrapper.BLACKBOARD_KEY_TWEAKS, Collections.emptyList()); | ||||
| 
 | ||||
| 		List<JsonObject> mods = findModInfo(modFiles); | ||||
| 		System.out.println("Found " + mods.size() + " mods"); | ||||
| 		List<String> mixins = new ArrayList<>(); | ||||
| 		for(JsonObject modObject : mods){ | ||||
| 			mixins.addAll(findMixins(modObject.getAsJsonArray("mixins"))); | ||||
| 			mixins.addAll(findMixins(modObject.getAsJsonArray("clientMixins"))); | ||||
| 			mixins.addAll(findMixins(modObject.getAsJsonArray("serverMixins"))); | ||||
| 		} | ||||
| 		System.out.println("Found " + mixins.size() + " mixins to pre bake"); | ||||
| 
 | ||||
| 		List<String> tweakers = new ArrayList<>(); | ||||
| 		tweakers.add("net.fabricmc.base.launch.FabricTweaker"); | ||||
| 		GlobalProperties.put("TweakClasses", tweakers); | ||||
| 
 | ||||
| 		MixinBootstrap.init(); | ||||
| 		mixins.forEach(Mixins::addConfiguration); | ||||
| 
 | ||||
| 		MixinServiceGradle.setupModFiles(modFiles, new File(args[argOffset + 0])); | ||||
| 
 | ||||
| 
 | ||||
| 		EnvironmentStateTweaker tweaker = new EnvironmentStateTweaker(); | ||||
| 		tweaker.getLaunchArguments(); | ||||
| 		tweaker.injectIntoClassLoader(Launch.classLoader); | ||||
| 
 | ||||
| 		//MixinServiceGradle.addMCDeps(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).getFiles(), tweaker); | ||||
| 
 | ||||
| 		MixinEnvironment mixinEnvironment = MixinEnvironment.getDefaultEnvironment(); | ||||
| 
 | ||||
| 		System.out.println("Loading mappings: " + mappingsFile); | ||||
| 		InputStream mappingStream = new FileInputStream(mappingsFile); | ||||
| 		MixinDevRemapper devRemapper = new MixinDevRemapper(); | ||||
| 		devRemapper.readMapping(new BufferedReader(new InputStreamReader(mappingStream)), "pomf", "mojang"); | ||||
| 		mappingStream.close(); | ||||
| 		mixinEnvironment.getRemappers().add(devRemapper); | ||||
| 
 | ||||
| 		mixinEnvironment.setSide(MixinEnvironment.Side.CLIENT); //TODO have an all side? | ||||
| 
 | ||||
| 
 | ||||
| 		MixinTransformer mixinTransformer = GlobalProperties.get(GlobalProperties.Keys.TRANSFORMER); | ||||
| 		if(mixinTransformer == null){ | ||||
| 			MixinService.getService().beginPhase(); | ||||
| 			mixinTransformer = GlobalProperties.get(GlobalProperties.Keys.TRANSFORMER); | ||||
| 		} | ||||
| 		mixinTransformer.audit(mixinEnvironment); | ||||
| 
 | ||||
| 
 | ||||
| 		try { | ||||
| 			JarInputStream input = new JarInputStream(new FileInputStream(new File(args[argOffset + 0]))); | ||||
| 			JarOutputStream output = new JarOutputStream(new FileOutputStream(new File(args[argOffset + 1]))); | ||||
| 			JarEntry entry; | ||||
| 			while ((entry = input.getNextJarEntry()) != null) { | ||||
| 				if (entry.getName().equals(APPLIED_MIXIN_CONFIGS_FILENAME)) { | ||||
| 					continue; | ||||
| 				} | ||||
| 
 | ||||
| 				if (hasMappingsFile && entry.getName().equals(MAPPINGS_FILENAME)) { | ||||
| 					continue; | ||||
| 				} | ||||
| 
 | ||||
| 				if (entry.getName().endsWith(".class")) { | ||||
| 					byte[] classIn = ByteStreams.toByteArray(input); | ||||
| 					String className = entry.getName().substring(0, entry.getName().length() - 6).replace('/', '.'); | ||||
| 					byte[] classOut = mixinTransformer.transformClassBytes(className, className, classIn); | ||||
| 					if (classIn != classOut) { | ||||
| 						System.out.println("Transformed " + className); | ||||
| 						classOut = desprinkle(classOut); | ||||
| 					} | ||||
| 					JarEntry newEntry = new JarEntry(entry.getName()); | ||||
| 					newEntry.setComment(entry.getComment()); | ||||
| 					newEntry.setSize(classOut.length); | ||||
| 					newEntry.setLastModifiedTime(FileTime.from(Instant.now())); | ||||
| 					output.putNextEntry(newEntry); | ||||
| 					output.write(classOut); | ||||
| 				} else { | ||||
| 					output.putNextEntry(entry); | ||||
| 					ByteStreams.copy(input, output); | ||||
| 				} | ||||
| 			} | ||||
| 
 | ||||
| 			output.putNextEntry(new JarEntry(APPLIED_MIXIN_CONFIGS_FILENAME)); | ||||
| 			output.write(String.join("\n", mixins).getBytes(Charsets.UTF_8)); | ||||
| 
 | ||||
| 			if (hasMappingsFile) { | ||||
| 				output.putNextEntry(new JarEntry(MAPPINGS_FILENAME)); | ||||
| 				Files.copy(mappingsFile.toPath(), output); | ||||
| 			} | ||||
| 
 | ||||
| 			input.close(); | ||||
| 			output.close(); | ||||
| 		} catch (IOException e) { | ||||
| 			throw new RuntimeException(e); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	private static List<String> findMixins(JsonArray jsonArray){ | ||||
| 		if(jsonArray == null || jsonArray.size() == 0){ | ||||
| 			return Collections.emptyList(); | ||||
| 		} | ||||
| 		List<String> mixinList = new ArrayList<>(); | ||||
| 		for (int i = 0; i < jsonArray.size(); i++) { | ||||
| 			mixinList.add(jsonArray.get(i).getAsString()); | ||||
| 		} | ||||
| 		return mixinList; | ||||
| 	} | ||||
| 
 | ||||
| 	private static List<JsonObject> findModInfo(Set<File> mods){ | ||||
| 		List<JsonArray> modFiles = mods.stream().map(file -> { | ||||
| 			try { | ||||
| 				JarFile jar = new JarFile(file); | ||||
| 				return readModInfoFromJar(jar); | ||||
| 			} catch (IOException e) { | ||||
| 				throw new RuntimeException("Failed to mod " + file.getName(), e); | ||||
| 			} | ||||
| 		}).filter((Predicate<JsonArray>) Objects::nonNull).collect(Collectors.toList()); | ||||
| 
 | ||||
| 		List<JsonObject> containedMods = new ArrayList<>(); | ||||
| 		for(JsonArray modFile : modFiles){ | ||||
| 			for (int i = 0; i < modFile.size(); i++) { | ||||
| 				containedMods.add(modFile.get(i).getAsJsonObject()); | ||||
| 			} | ||||
| 		} | ||||
| 		return containedMods; | ||||
| 	} | ||||
| 
 | ||||
| 	private static JsonArray readModInfoFromJar(@Nonnull JarFile file) throws IOException { | ||||
| 		Gson gson = new Gson(); | ||||
| 		ZipEntry entry = file.getEntry("mod.json"); | ||||
| 		if (entry == null) | ||||
| 			return null; | ||||
| 
 | ||||
| 		InputStreamReader stream = new InputStreamReader(file.getInputStream(entry)); | ||||
| 		JsonArray jsonArray = gson.fromJson(stream, JsonArray.class); | ||||
| 		stream.close(); | ||||
| 
 | ||||
| 		List<String> mixins = new ArrayList<>(); | ||||
| 		for (int i = 0; i < jsonArray.size(); i++) { | ||||
| 			JsonObject modObject = jsonArray.get(i).getAsJsonObject(); | ||||
| 			mixins.addAll(findMixins(modObject.getAsJsonArray("mixins"))); | ||||
| 			mixins.addAll(findMixins(modObject.getAsJsonArray("clientMixins"))); | ||||
| 			mixins.addAll(findMixins(modObject.getAsJsonArray("serverMixins"))); | ||||
| 		} | ||||
| 
 | ||||
| 		System.out.println("Found: " + mixins.size() + " mixins in " + file.getName()); | ||||
| 
 | ||||
| 		mixins.forEach(s -> { | ||||
| 			ZipEntry entry1 = file.getEntry(s); | ||||
| 			try { | ||||
| 				jarFileCache.put(s, file.getInputStream(entry1)); | ||||
| 			} catch (IOException e) { | ||||
| 				throw new RuntimeException("Failed to load jar", e); | ||||
| 			} | ||||
| 		}); | ||||
| 		return jsonArray; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  | @ -1,53 +0,0 @@ | |||
| /* | ||||
|  * This file is part of fabric-loom, licensed under the MIT License (MIT). | ||||
|  * | ||||
|  * Copyright (c) 2016 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.proccessing; | ||||
| 
 | ||||
| import net.fabricmc.loom.LoomGradleExtension; | ||||
| import net.fabricmc.loom.task.ProcessModsTask; | ||||
| import net.fabricmc.loom.util.Constants; | ||||
| import org.gradle.api.Project; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| import java.util.List; | ||||
| 
 | ||||
| public class PreBakeMixins { | ||||
| 
 | ||||
| 	public void proccess(Project project, LoomGradleExtension extension, List<File> mods) throws IOException { | ||||
| 		project.getLogger().lifecycle(":Found " + mods.size() + " mods to prebake"); | ||||
| 		String[] args = new String[mods.size() + 4]; | ||||
| 		args[0] = "-m"; | ||||
| 		args[1] = Constants.MAPPINGS_TINY.get(extension).getAbsolutePath(); | ||||
| 		args[2] = Constants.MINECRAFT_MERGED_JAR.get(extension).getAbsolutePath(); | ||||
| 		args[3] = Constants.MINECRAFT_MIXED_JAR.get(extension).getAbsolutePath(); | ||||
| 		for (int i = 0; i < mods.size(); i++) { | ||||
| 			args[i + 4] = mods.get(i).getAbsolutePath(); | ||||
| 		} | ||||
| 		project.getLogger().lifecycle(":preBaking mixins"); | ||||
| 		ProcessModsTask.addFile(Constants.MINECRAFT_MIXED_JAR.get(extension), this); | ||||
| 		MixinPrebaker.main(args, project); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
		Loading…
	
		Reference in a new issue