2016-08-16 22:29:10 +00:00
|
|
|
/*
|
|
|
|
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
|
|
|
*
|
2018-10-27 14:14:05 +00:00
|
|
|
* Copyright (c) 2016, 2017, 2018 FabricMC
|
2016-08-16 22:29:10 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2018-10-22 18:25:18 +00:00
|
|
|
package net.fabricmc.loom;
|
2016-08-15 10:22:14 +00:00
|
|
|
|
2019-04-22 11:37:14 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2019-04-23 20:50:28 +00:00
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
2019-04-22 11:37:14 +00:00
|
|
|
import java.util.Locale;
|
2016-08-15 10:22:14 +00:00
|
|
|
|
2019-11-02 20:23:27 +00:00
|
|
|
import org.gradle.api.Project;
|
|
|
|
import org.gradle.api.Task;
|
|
|
|
import org.gradle.api.tasks.TaskContainer;
|
|
|
|
|
|
|
|
import net.fabricmc.loom.providers.MappingsProvider;
|
|
|
|
import net.fabricmc.loom.providers.MinecraftLibraryProvider;
|
|
|
|
import net.fabricmc.loom.task.AbstractDecompileTask;
|
2020-04-26 13:04:49 +00:00
|
|
|
import net.fabricmc.loom.task.CleanEclipseRunsTask;
|
2019-11-02 20:23:27 +00:00
|
|
|
import net.fabricmc.loom.task.CleanLoomBinaries;
|
|
|
|
import net.fabricmc.loom.task.CleanLoomMappings;
|
|
|
|
import net.fabricmc.loom.task.DownloadAssetsTask;
|
|
|
|
import net.fabricmc.loom.task.GenEclipseRunsTask;
|
|
|
|
import net.fabricmc.loom.task.GenIdeaProjectTask;
|
|
|
|
import net.fabricmc.loom.task.GenVsCodeProjectTask;
|
|
|
|
import net.fabricmc.loom.task.MigrateMappingsTask;
|
|
|
|
import net.fabricmc.loom.task.RemapJarTask;
|
|
|
|
import net.fabricmc.loom.task.RemapLineNumbersTask;
|
|
|
|
import net.fabricmc.loom.task.RemapSourcesJarTask;
|
|
|
|
import net.fabricmc.loom.task.RunClientTask;
|
|
|
|
import net.fabricmc.loom.task.RunServerTask;
|
|
|
|
import net.fabricmc.loom.task.fernflower.FernFlowerTask;
|
|
|
|
|
2018-10-22 18:25:18 +00:00
|
|
|
public class LoomGradlePlugin extends AbstractPlugin {
|
0.2.7 refactors (#178)
* Rough work on project based jars, skeleton for AccessEscalators?
* First working draft
* Minor changes
* Add support for mutable, better error checking when parsing file.
Code cleanup
Remap if needed when reading
* Fix inner classes and genSources
* Fix CME
* Caching, only regen jar when input changes
* Some work, untested
* Fix writing, fix checkstyle issues
* More fixes
* Move jars into a maven file structure, cleans up the file structure, and will benefit idea 2020
Add some basic validation to the AccessWidenerRemapper, will present any issues with the mappings when building (May need a way to disable?)
+ Some bugs fixes
* Fix issues with source jars in idea 2020, should be backwards compatible with 2019
* Move to lorenz-tiny
* Build fix + small cleanup
* Remove accesswidener's for now
* Update dev launch injector, should fix all issues with spaces in the path.
2020-03-06 11:15:34 +00:00
|
|
|
public static File getMappedByproduct(Project project, String suffix) {
|
2019-04-22 11:37:14 +00:00
|
|
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
|
|
|
MappingsProvider mappingsProvider = extension.getMappingsProvider();
|
|
|
|
File mappedJar = mappingsProvider.mappedProvider.getMappedJar();
|
|
|
|
String path = mappedJar.getAbsolutePath();
|
2019-11-02 20:23:27 +00:00
|
|
|
|
2019-04-22 11:37:14 +00:00
|
|
|
if (!path.toLowerCase(Locale.ROOT).endsWith(".jar")) {
|
|
|
|
throw new RuntimeException("Invalid mapped JAR path: " + path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new File(path.substring(0, path.length() - 4) + suffix);
|
|
|
|
}
|
|
|
|
|
2016-08-17 16:38:54 +00:00
|
|
|
@Override
|
|
|
|
public void apply(Project target) {
|
|
|
|
super.apply(target);
|
2018-12-09 07:21:32 +00:00
|
|
|
|
2019-04-22 11:37:14 +00:00
|
|
|
TaskContainer tasks = target.getTasks();
|
2019-10-22 19:04:38 +00:00
|
|
|
|
2020-06-01 18:08:17 +00:00
|
|
|
tasks.register("cleanLoomBinaries", CleanLoomBinaries.class, t -> t.setDescription("Removes binary jars created by Loom."));
|
|
|
|
tasks.register("cleanLoomMappings", CleanLoomMappings.class, t -> t.setDescription("Removes mappings downloaded by Loom."));
|
2019-04-22 11:37:14 +00:00
|
|
|
|
2019-10-22 19:04:38 +00:00
|
|
|
tasks.register("cleanLoom").configure(task -> {
|
2020-05-14 00:10:08 +00:00
|
|
|
task.setGroup("fabric");
|
2020-06-01 18:08:17 +00:00
|
|
|
task.setDescription("Runs all Loom cleanup tasks.");
|
2019-10-22 19:04:38 +00:00
|
|
|
task.dependsOn(tasks.getByName("cleanLoomBinaries"));
|
|
|
|
task.dependsOn(tasks.getByName("cleanLoomMappings"));
|
|
|
|
});
|
|
|
|
|
2019-05-10 11:55:17 +00:00
|
|
|
tasks.register("migrateMappings", MigrateMappingsTask.class, t -> {
|
2020-06-01 18:08:17 +00:00
|
|
|
t.setDescription("Migrates mappings to a new version.");
|
2019-05-10 11:32:11 +00:00
|
|
|
t.getOutputs().upToDateWhen((o) -> false);
|
|
|
|
});
|
|
|
|
|
2020-05-14 00:10:08 +00:00
|
|
|
tasks.register("remapJar", RemapJarTask.class, t -> {
|
2020-06-01 18:08:17 +00:00
|
|
|
t.setDescription("Remaps the built project jar to intermediary mappings.");
|
2020-05-14 00:10:08 +00:00
|
|
|
t.setGroup("fabric");
|
|
|
|
});
|
2019-04-22 11:37:14 +00:00
|
|
|
|
2019-05-10 09:48:07 +00:00
|
|
|
tasks.register("genSourcesDecompile", FernFlowerTask.class, t -> {
|
2020-06-01 18:08:17 +00:00
|
|
|
t.setDescription("Decompiles sources for the genSources task.");
|
2019-04-22 11:37:14 +00:00
|
|
|
t.getOutputs().upToDateWhen((o) -> false);
|
|
|
|
});
|
2019-05-10 09:48:07 +00:00
|
|
|
|
|
|
|
tasks.register("genSourcesRemapLineNumbers", RemapLineNumbersTask.class, t -> {
|
2020-06-01 18:08:17 +00:00
|
|
|
t.setDescription("Remaps line numbers for the genSources task.");
|
2019-05-10 09:48:07 +00:00
|
|
|
t.getOutputs().upToDateWhen((o) -> false);
|
|
|
|
});
|
|
|
|
|
|
|
|
tasks.register("genSources", t -> {
|
2020-06-01 18:08:17 +00:00
|
|
|
t.setDescription("Generates a human-readable version of the Minecraft source.");
|
2019-05-10 09:48:07 +00:00
|
|
|
t.getOutputs().upToDateWhen((o) -> false);
|
2019-08-02 14:15:40 +00:00
|
|
|
t.setGroup("fabric");
|
2019-05-10 09:48:07 +00:00
|
|
|
});
|
|
|
|
|
2019-04-22 11:37:14 +00:00
|
|
|
project.afterEvaluate((p) -> {
|
2019-05-10 09:48:07 +00:00
|
|
|
AbstractDecompileTask decompileTask = (AbstractDecompileTask) p.getTasks().getByName("genSourcesDecompile");
|
|
|
|
RemapLineNumbersTask remapLineNumbersTask = (RemapLineNumbersTask) p.getTasks().getByName("genSourcesRemapLineNumbers");
|
|
|
|
Task genSourcesTask = p.getTasks().getByName("genSources");
|
|
|
|
|
|
|
|
genSourcesTask.dependsOn(remapLineNumbersTask);
|
|
|
|
remapLineNumbersTask.dependsOn(decompileTask);
|
2019-04-22 11:37:14 +00:00
|
|
|
|
|
|
|
Project project = this.getProject();
|
|
|
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
0.2.7 refactors (#178)
* Rough work on project based jars, skeleton for AccessEscalators?
* First working draft
* Minor changes
* Add support for mutable, better error checking when parsing file.
Code cleanup
Remap if needed when reading
* Fix inner classes and genSources
* Fix CME
* Caching, only regen jar when input changes
* Some work, untested
* Fix writing, fix checkstyle issues
* More fixes
* Move jars into a maven file structure, cleans up the file structure, and will benefit idea 2020
Add some basic validation to the AccessWidenerRemapper, will present any issues with the mappings when building (May need a way to disable?)
+ Some bugs fixes
* Fix issues with source jars in idea 2020, should be backwards compatible with 2019
* Move to lorenz-tiny
* Build fix + small cleanup
* Remove accesswidener's for now
* Update dev launch injector, should fix all issues with spaces in the path.
2020-03-06 11:15:34 +00:00
|
|
|
MinecraftLibraryProvider libraryProvider = extension.getMinecraftProvider().getLibraryProvider();
|
2019-04-22 11:37:14 +00:00
|
|
|
MappingsProvider mappingsProvider = extension.getMappingsProvider();
|
|
|
|
File mappedJar = mappingsProvider.mappedProvider.getMappedJar();
|
2019-05-10 09:48:07 +00:00
|
|
|
File linemappedJar = getMappedByproduct(project, "-linemapped.jar");
|
2019-04-23 20:50:28 +00:00
|
|
|
File sourcesJar = getMappedByproduct(project, "-sources.jar");
|
2019-04-22 11:37:14 +00:00
|
|
|
File linemapFile = getMappedByproduct(project, "-sources.lmap");
|
|
|
|
|
2019-05-10 09:48:07 +00:00
|
|
|
decompileTask.setInput(mappedJar);
|
|
|
|
decompileTask.setOutput(sourcesJar);
|
|
|
|
decompileTask.setLineMapFile(linemapFile);
|
|
|
|
decompileTask.setLibraries(libraryProvider.getLibraries());
|
2019-04-22 11:37:14 +00:00
|
|
|
|
2019-05-10 09:48:07 +00:00
|
|
|
remapLineNumbersTask.setInput(mappedJar);
|
|
|
|
remapLineNumbersTask.setLineMapFile(linemapFile);
|
|
|
|
remapLineNumbersTask.setOutput(linemappedJar);
|
2019-04-23 20:50:28 +00:00
|
|
|
|
2019-05-10 09:48:07 +00:00
|
|
|
Path mappedJarPath = mappedJar.toPath();
|
|
|
|
Path linemappedJarPath = linemappedJar.toPath();
|
2019-04-23 20:50:28 +00:00
|
|
|
|
2019-05-10 09:48:07 +00:00
|
|
|
genSourcesTask.doLast((tt) -> {
|
|
|
|
if (Files.exists(linemappedJarPath)) {
|
2019-04-23 20:50:28 +00:00
|
|
|
try {
|
|
|
|
Files.deleteIfExists(mappedJarPath);
|
2019-05-10 09:48:07 +00:00
|
|
|
Files.copy(linemappedJarPath, mappedJarPath);
|
2019-04-23 20:50:28 +00:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
2019-04-22 11:37:14 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-01 18:08:17 +00:00
|
|
|
tasks.register("downloadAssets", DownloadAssetsTask.class, t -> t.setDescription("Downloads required assets for Fabric."));
|
2016-08-15 10:22:14 +00:00
|
|
|
|
2019-04-22 11:37:14 +00:00
|
|
|
tasks.register("genIdeaWorkspace", GenIdeaProjectTask.class, t -> {
|
2020-06-01 18:08:17 +00:00
|
|
|
t.setDescription("Generates an IntelliJ IDEA workspace from this project.");
|
2019-04-22 11:37:14 +00:00
|
|
|
t.dependsOn("idea", "downloadAssets");
|
|
|
|
t.setGroup("ide");
|
|
|
|
});
|
2018-11-05 20:33:57 +00:00
|
|
|
|
2019-04-22 11:37:14 +00:00
|
|
|
tasks.register("genEclipseRuns", GenEclipseRunsTask.class, t -> {
|
2020-06-01 18:08:17 +00:00
|
|
|
t.setDescription("Generates Eclipse run configurations for this project.");
|
2019-04-22 11:37:14 +00:00
|
|
|
t.dependsOn("downloadAssets");
|
|
|
|
t.setGroup("ide");
|
|
|
|
});
|
2018-11-30 20:16:42 +00:00
|
|
|
|
2020-04-26 13:04:49 +00:00
|
|
|
tasks.register("cleanEclipseRuns", CleanEclipseRunsTask.class, t -> {
|
2020-06-01 18:08:17 +00:00
|
|
|
t.setDescription("Removes Eclipse run configurations for this project.");
|
2020-04-26 13:04:49 +00:00
|
|
|
t.setGroup("ide");
|
|
|
|
});
|
|
|
|
|
2019-04-22 11:37:14 +00:00
|
|
|
tasks.register("vscode", GenVsCodeProjectTask.class, t -> {
|
2020-06-01 18:08:17 +00:00
|
|
|
t.setDescription("Generates VSCode launch configurations.");
|
2019-04-22 11:37:14 +00:00
|
|
|
t.dependsOn("downloadAssets");
|
|
|
|
t.setGroup("ide");
|
|
|
|
});
|
2019-04-20 18:55:58 +00:00
|
|
|
|
2020-06-01 18:08:17 +00:00
|
|
|
tasks.register("remapSourcesJar", RemapSourcesJarTask.class, t -> t.setDescription("Remaps the project sources jar to intermediary names."));
|
2016-09-20 19:01:10 +00:00
|
|
|
|
2019-04-22 11:37:14 +00:00
|
|
|
tasks.register("runClient", RunClientTask.class, t -> {
|
2020-06-01 18:08:17 +00:00
|
|
|
t.setDescription("Starts a development version of the Minecraft client.");
|
2020-05-13 18:45:13 +00:00
|
|
|
t.dependsOn("jar", "downloadAssets");
|
2020-05-14 00:10:08 +00:00
|
|
|
t.setGroup("fabric");
|
2019-04-22 11:37:14 +00:00
|
|
|
});
|
2018-12-18 22:36:22 +00:00
|
|
|
|
2019-04-22 11:37:14 +00:00
|
|
|
tasks.register("runServer", RunServerTask.class, t -> {
|
2020-06-01 18:08:17 +00:00
|
|
|
t.setDescription("Starts a development version of the Minecraft server.");
|
2020-05-13 18:45:13 +00:00
|
|
|
t.dependsOn("jar");
|
2020-05-14 00:10:08 +00:00
|
|
|
t.setGroup("fabric");
|
2019-04-22 11:37:14 +00:00
|
|
|
});
|
2016-08-17 16:38:54 +00:00
|
|
|
}
|
2016-08-15 10:22:14 +00:00
|
|
|
}
|