Initial untested work on mod remapping
parent
85d51cb1a1
commit
b43793b3fc
|
@ -58,6 +58,7 @@ dependencies {
|
||||||
shade 'com.google.guava:guava:19.0'
|
shade 'com.google.guava:guava:19.0'
|
||||||
shade 'net.fabricmc:weave:0.1.0.6'
|
shade 'net.fabricmc:weave:0.1.0.6'
|
||||||
shade 'cuchaz:enigma:0.11.0.5:lib'
|
shade 'cuchaz:enigma:0.11.0.5:lib'
|
||||||
|
shade 'net.fabricmc:tiny-remapper:+'
|
||||||
|
|
||||||
compile 'net.fabricmc:fabric-base:16w38a-0.0.4-SNAPSHOT'
|
compile 'net.fabricmc:fabric-base:16w38a-0.0.4-SNAPSHOT'
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,10 +30,9 @@ import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import net.fabricmc.loom.task.DownloadTask;
|
import net.fabricmc.loom.task.DownloadTask;
|
||||||
import net.fabricmc.loom.task.GenIdeaProjectTask;
|
import net.fabricmc.loom.task.GenIdeaProjectTask;
|
||||||
import net.fabricmc.loom.util.BuidRemapper;
|
import net.fabricmc.loom.util.ModRemapper;
|
||||||
import net.fabricmc.loom.util.Constants;
|
import net.fabricmc.loom.util.Constants;
|
||||||
import net.fabricmc.loom.util.Version;
|
import net.fabricmc.loom.util.Version;
|
||||||
import org.gradle.api.Action;
|
|
||||||
import org.gradle.api.Plugin;
|
import org.gradle.api.Plugin;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
import org.gradle.api.Task;
|
import org.gradle.api.Task;
|
||||||
|
@ -41,7 +40,6 @@ import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
|
||||||
import org.gradle.api.plugins.JavaPlugin;
|
import org.gradle.api.plugins.JavaPlugin;
|
||||||
import org.gradle.api.plugins.JavaPluginConvention;
|
import org.gradle.api.plugins.JavaPluginConvention;
|
||||||
import org.gradle.api.tasks.SourceSet;
|
import org.gradle.api.tasks.SourceSet;
|
||||||
import org.gradle.api.tasks.compile.JavaCompile;
|
|
||||||
import org.gradle.api.tasks.javadoc.Javadoc;
|
import org.gradle.api.tasks.javadoc.Javadoc;
|
||||||
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
|
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
|
||||||
import org.gradle.plugins.ide.idea.model.IdeaModel;
|
import org.gradle.plugins.ide.idea.model.IdeaModel;
|
||||||
|
@ -53,8 +51,6 @@ import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class AbstractPlugin implements Plugin<Project> {
|
public class AbstractPlugin implements Plugin<Project> {
|
||||||
protected Project project;
|
protected Project project;
|
||||||
|
@ -91,27 +87,27 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||||
configureIDEs();
|
configureIDEs();
|
||||||
configureCompile();
|
configureCompile();
|
||||||
|
|
||||||
//TODO other languages?
|
//TODO wait for AP thing
|
||||||
Map<Project, Set<Task>> taskMap = project.getAllTasks(true);
|
// Map<Project, Set<Task>> taskMap = project.getAllTasks(true);
|
||||||
for (Map.Entry<Project, Set<Task>> entry : taskMap.entrySet()) {
|
// for (Map.Entry<Project, Set<Task>> entry : taskMap.entrySet()) {
|
||||||
Project project = entry.getKey();
|
// Project project = entry.getKey();
|
||||||
Set<Task> taskSet = entry.getValue();
|
// Set<Task> taskSet = entry.getValue();
|
||||||
for (Task task : taskSet) {
|
// for (Task task : taskSet) {
|
||||||
if (task instanceof JavaCompile) {
|
// if (task instanceof JavaCompile) {
|
||||||
JavaCompile javaCompileTask = (JavaCompile) task;
|
// JavaCompile javaCompileTask = (JavaCompile) task;
|
||||||
javaCompileTask.doFirst(task1 -> {
|
// javaCompileTask.doFirst(task1 -> {
|
||||||
project.getLogger().lifecycle(":setting java compiler args");
|
// project.getLogger().lifecycle(":setting java compiler args");
|
||||||
try {
|
// try {
|
||||||
javaCompileTask.getOptions().getCompilerArgs().add("-AreobfNotchSrgFile=" + Constants.MAPPINGS_SRG.get(extension).getCanonicalPath());
|
// javaCompileTask.getOptions().getCompilerArgs().add("-AreobfNotchSrgFile=" + Constants.MAPPINGS_SRG.get(extension).getCanonicalPath());
|
||||||
javaCompileTask.getOptions().getCompilerArgs().add("-AdefaultObfuscationEnv=notch");
|
// javaCompileTask.getOptions().getCompilerArgs().add("-AdefaultObfuscationEnv=notch");
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +242,11 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||||
|
|
||||||
project.getTasks().getByName("build").doLast(task -> {
|
project.getTasks().getByName("build").doLast(task -> {
|
||||||
project.getLogger().lifecycle(":remapping mods");
|
project.getLogger().lifecycle(":remapping mods");
|
||||||
BuidRemapper.reamp(project);
|
try {
|
||||||
|
ModRemapper.remap(project);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
project.afterEvaluate(project12 -> {
|
project.afterEvaluate(project12 -> {
|
||||||
|
|
|
@ -1,34 +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;
|
|
||||||
|
|
||||||
import org.gradle.api.Project;
|
|
||||||
|
|
||||||
public class BuidRemapper {
|
|
||||||
|
|
||||||
public static void reamp(Project project){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -47,7 +47,8 @@ public class Constants {
|
||||||
public static final IDelayed<File> POMF_DIR = new DelayedFile(extension -> new File(extension.getFabricUserCache(), "pomf"));
|
public static final IDelayed<File> POMF_DIR = new DelayedFile(extension -> new File(extension.getFabricUserCache(), "pomf"));
|
||||||
public static final IDelayed<File> MAPPINGS_ZIP = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-enigma-" + extension.version + "." + extension.pomfVersion + ".zip"));
|
public static final IDelayed<File> MAPPINGS_ZIP = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-enigma-" + extension.version + "." + extension.pomfVersion + ".zip"));
|
||||||
public static final IDelayed<File> MAPPINGS_DIR = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-enigma-" + extension.version + "." + extension.pomfVersion + ""));
|
public static final IDelayed<File> MAPPINGS_DIR = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-enigma-" + extension.version + "." + extension.pomfVersion + ""));
|
||||||
public static final IDelayed<File> MAPPINGS_SRG = new DelayedFile(extension -> new File(WORKING_DIRECTORY, "mappings.srg"));
|
public static final IDelayed<File> MAPPINGS_TINY_GZ = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-tiny-" + extension.version + "." + extension.pomfVersion + ".gz"));
|
||||||
|
public static final IDelayed<File> MAPPINGS_TINY = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-tiny-" + extension.version + "." + extension.pomfVersion));
|
||||||
|
|
||||||
public static final IDelayed<File> REF_MAP = new DelayedFile(extension -> new File(WORKING_DIRECTORY, "RefMap.json"));
|
public static final IDelayed<File> REF_MAP = new DelayedFile(extension -> new File(WORKING_DIRECTORY, "RefMap.json"));
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import net.fabricmc.loom.LoomGradleExtension;
|
||||||
|
import net.fabricmc.tinyremapper.OutputConsumerJar;
|
||||||
|
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||||
|
import net.fabricmc.tinyremapper.TinyUtils;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.gradle.api.Project;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
public class ModRemapper {
|
||||||
|
|
||||||
|
public static void remap(Project project) throws IOException {
|
||||||
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
|
//TODO whats the proper way of doing this???
|
||||||
|
File libsDir = new File(project.getBuildDir(), "libs");
|
||||||
|
File modJar = new File(libsDir, project.getName() + "-" + project.getVersion() + ".jar");
|
||||||
|
File modOutputJar = new File(libsDir, project.getName() + "-" + project.getVersion() + "-final.jar");
|
||||||
|
if (!modJar.exists()) {
|
||||||
|
project.getLogger().error("Could not find mod jar @" + modJar.getAbsolutePath());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!Constants.MAPPINGS_TINY.get(extension).exists()) {
|
||||||
|
if (!Constants.MAPPINGS_TINY_GZ.get(extension).exists()) {
|
||||||
|
project.getLogger().lifecycle(":downloading tiny mappings");
|
||||||
|
FileUtils.copyURLToFile(new URL("http://asie.pl:8080/job/pomf/" + extension.pomfVersion + "/artifact/build/libs/pomf-tiny-" + extension.version + "." + extension.pomfVersion + ".gz"), Constants.MAPPINGS_TINY_GZ.get(extension));
|
||||||
|
}
|
||||||
|
GZIPInputStream gzipInputStream = new GZIPInputStream(new FileInputStream(Constants.MAPPINGS_TINY_GZ.get(extension)));
|
||||||
|
FileOutputStream fileOutputStream = new FileOutputStream(Constants.MAPPINGS_TINY.get(extension));
|
||||||
|
int length;
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
while ((length = gzipInputStream.read(buffer)) > 0) {
|
||||||
|
fileOutputStream.write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
gzipInputStream.close();
|
||||||
|
fileOutputStream.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
Path mappings = Constants.MAPPINGS_TINY.get(extension).toPath();
|
||||||
|
|
||||||
|
String fromM = "pomf";
|
||||||
|
String toM = "mojang";
|
||||||
|
|
||||||
|
List<File> classpathFiles = new ArrayList<>();
|
||||||
|
classpathFiles.addAll(project.getConfigurations().getByName("compile").getFiles());
|
||||||
|
classpathFiles.addAll(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES_CLIENT).getFiles());
|
||||||
|
classpathFiles.addAll(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).getFiles());
|
||||||
|
classpathFiles.add(Constants.MINECRAFT_FINAL_JAR.get(extension));
|
||||||
|
|
||||||
|
Path[] classpath = new Path[classpathFiles.size()];
|
||||||
|
for (int i = 0; i < classpathFiles.size(); i++) {
|
||||||
|
classpath[i] = classpathFiles.get(i).toPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
TinyRemapper remapper = TinyRemapper.newRemapper()
|
||||||
|
.withMappings(TinyUtils.createTinyMappingProvider(mappings, fromM, toM))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
OutputConsumerJar outputConsumer = new OutputConsumerJar(modOutputJar);
|
||||||
|
outputConsumer.addNonClassFiles(modJar);
|
||||||
|
remapper.read(modJar.toPath());
|
||||||
|
remapper.read(classpath);
|
||||||
|
remapper.apply(modJar.toPath(), outputConsumer);
|
||||||
|
outputConsumer.finish();
|
||||||
|
remapper.finish();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue