Merge remote-tracking branch 'upstream/dev/0.2.6' into dev/0.2.6
commit
414f41ab50
|
@ -48,7 +48,6 @@ import net.fabricmc.loom.LoomGradleExtension;
|
||||||
import net.fabricmc.loom.util.Constants;
|
import net.fabricmc.loom.util.Constants;
|
||||||
import net.fabricmc.loom.util.DependencyProvider;
|
import net.fabricmc.loom.util.DependencyProvider;
|
||||||
import net.fabricmc.loom.util.DownloadUtil;
|
import net.fabricmc.loom.util.DownloadUtil;
|
||||||
import net.fabricmc.loom.util.Version;
|
|
||||||
import net.fabricmc.mapping.reader.v2.TinyV2Factory;
|
import net.fabricmc.mapping.reader.v2.TinyV2Factory;
|
||||||
import net.fabricmc.mapping.tree.TinyTree;
|
import net.fabricmc.mapping.tree.TinyTree;
|
||||||
import net.fabricmc.stitch.Command;
|
import net.fabricmc.stitch.Command;
|
||||||
|
@ -93,9 +92,8 @@ public class MappingsProvider extends DependencyProvider {
|
||||||
|
|
||||||
boolean isV2 = doesJarContainV2Mappings(mappingsJar.toPath());
|
boolean isV2 = doesJarContainV2Mappings(mappingsJar.toPath());
|
||||||
|
|
||||||
Version mappingsVersion = new Version(version);
|
this.minecraftVersion = minecraftProvider.minecraftVersion;
|
||||||
this.minecraftVersion = mappingsVersion.getMinecraftVersion();
|
this.mappingsVersion = version + (isV2 ? "-v2" : "");
|
||||||
this.mappingsVersion = mappingsVersion.getMappingsVersion() + (isV2 ? "-v2" : "");
|
|
||||||
|
|
||||||
initFiles(project);
|
initFiles(project);
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,14 @@ package net.fabricmc.loom.task;
|
||||||
|
|
||||||
import org.gradle.api.DefaultTask;
|
import org.gradle.api.DefaultTask;
|
||||||
|
|
||||||
|
import net.fabricmc.loom.LoomGradleExtension;
|
||||||
|
|
||||||
public abstract class AbstractLoomTask extends DefaultTask {
|
public abstract class AbstractLoomTask extends DefaultTask {
|
||||||
public AbstractLoomTask() {
|
public AbstractLoomTask() {
|
||||||
setGroup("fabric");
|
setGroup("fabric");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected LoomGradleExtension getExtension() {
|
||||||
|
return getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ package net.fabricmc.loom.task;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.gradle.api.Project;
|
|
||||||
import org.gradle.api.tasks.TaskAction;
|
import org.gradle.api.tasks.TaskAction;
|
||||||
|
|
||||||
import net.fabricmc.loom.LoomGradleExtension;
|
import net.fabricmc.loom.LoomGradleExtension;
|
||||||
|
@ -35,8 +34,7 @@ import net.fabricmc.loom.LoomGradleExtension;
|
||||||
public class CleanLoomBinaries extends AbstractLoomTask {
|
public class CleanLoomBinaries extends AbstractLoomTask {
|
||||||
@TaskAction
|
@TaskAction
|
||||||
public void run() {
|
public void run() {
|
||||||
Project project = this.getProject();
|
LoomGradleExtension extension = getExtension();
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
|
||||||
extension.getMinecraftProvider().getMergedJar().delete();
|
extension.getMinecraftProvider().getMergedJar().delete();
|
||||||
extension.getMinecraftMappedProvider().getIntermediaryJar().delete();
|
extension.getMinecraftMappedProvider().getIntermediaryJar().delete();
|
||||||
extension.getMinecraftMappedProvider().getMappedJar().delete();
|
extension.getMinecraftMappedProvider().getMappedJar().delete();
|
||||||
|
|
|
@ -27,7 +27,6 @@ package net.fabricmc.loom.task;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
|
||||||
import org.gradle.api.Project;
|
|
||||||
import org.gradle.api.tasks.TaskAction;
|
import org.gradle.api.tasks.TaskAction;
|
||||||
|
|
||||||
import net.fabricmc.loom.LoomGradleExtension;
|
import net.fabricmc.loom.LoomGradleExtension;
|
||||||
|
@ -37,8 +36,7 @@ public class CleanLoomMappings extends AbstractLoomTask {
|
||||||
@TaskAction
|
@TaskAction
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Project project = this.getProject();
|
LoomGradleExtension extension = getExtension();
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
|
||||||
extension.getMappingsProvider().clean();
|
extension.getMappingsProvider().clean();
|
||||||
extension.getMinecraftMappedProvider().getIntermediaryJar().delete();
|
extension.getMinecraftMappedProvider().getIntermediaryJar().delete();
|
||||||
extension.getMinecraftMappedProvider().getMappedJar().delete();
|
extension.getMinecraftMappedProvider().getMappedJar().delete();
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class DownloadAssetsTask extends AbstractLoomTask {
|
||||||
@TaskAction
|
@TaskAction
|
||||||
public void downloadAssets() throws IOException {
|
public void downloadAssets() throws IOException {
|
||||||
Project project = this.getProject();
|
Project project = this.getProject();
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = getExtension();
|
||||||
|
|
||||||
MinecraftAssetsProvider.provide(extension.getMinecraftProvider(), project);
|
MinecraftAssetsProvider.provide(extension.getMinecraftProvider(), project);
|
||||||
MinecraftNativesProvider.provide(extension.getMinecraftProvider(), project);
|
MinecraftNativesProvider.provide(extension.getMinecraftProvider(), project);
|
||||||
|
|
|
@ -31,7 +31,6 @@ import java.nio.charset.StandardCharsets;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.gradle.api.tasks.TaskAction;
|
import org.gradle.api.tasks.TaskAction;
|
||||||
|
|
||||||
import net.fabricmc.loom.LoomGradleExtension;
|
|
||||||
import net.fabricmc.loom.util.RunConfig;
|
import net.fabricmc.loom.util.RunConfig;
|
||||||
|
|
||||||
public class GenEclipseRunsTask extends AbstractLoomTask {
|
public class GenEclipseRunsTask extends AbstractLoomTask {
|
||||||
|
@ -51,7 +50,7 @@ public class GenEclipseRunsTask extends AbstractLoomTask {
|
||||||
FileUtils.writeStringToFile(serverRunConfigs, serverRunConfig, StandardCharsets.UTF_8);
|
FileUtils.writeStringToFile(serverRunConfigs, serverRunConfig, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
File runDir = new File(getProject().getRootDir(), this.getProject().getExtensions().getByType(LoomGradleExtension.class).runDir);
|
File runDir = new File(getProject().getRootDir(), getExtension().runDir);
|
||||||
|
|
||||||
if (!runDir.exists()) {
|
if (!runDir.exists()) {
|
||||||
runDir.mkdirs();
|
runDir.mkdirs();
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class GenIdeaProjectTask extends AbstractLoomTask {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = getExtension();
|
||||||
project.getLogger().lifecycle(":Building idea workspace");
|
project.getLogger().lifecycle(":Building idea workspace");
|
||||||
|
|
||||||
File file = project.file(project.getName() + ".iws");
|
File file = project.file(project.getName() + ".iws");
|
||||||
|
|
|
@ -33,6 +33,7 @@ import java.util.List;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.gradle.api.Project;
|
||||||
import org.gradle.api.tasks.TaskAction;
|
import org.gradle.api.tasks.TaskAction;
|
||||||
|
|
||||||
import net.fabricmc.loom.LoomGradleExtension;
|
import net.fabricmc.loom.LoomGradleExtension;
|
||||||
|
@ -45,8 +46,9 @@ import net.fabricmc.loom.util.RunConfig;
|
||||||
public class GenVsCodeProjectTask extends AbstractLoomTask {
|
public class GenVsCodeProjectTask extends AbstractLoomTask {
|
||||||
@TaskAction
|
@TaskAction
|
||||||
public void genRuns() {
|
public void genRuns() {
|
||||||
LoomGradleExtension extension = getProject().getExtensions().getByType(LoomGradleExtension.class);
|
Project project = getProject();
|
||||||
File projectDir = getProject().file(".vscode");
|
LoomGradleExtension extension = getExtension();
|
||||||
|
File projectDir = project.file(".vscode");
|
||||||
|
|
||||||
if (!projectDir.exists()) {
|
if (!projectDir.exists()) {
|
||||||
projectDir.mkdir();
|
projectDir.mkdir();
|
||||||
|
@ -59,8 +61,8 @@ public class GenVsCodeProjectTask extends AbstractLoomTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
VsCodeLaunch launch = new VsCodeLaunch();
|
VsCodeLaunch launch = new VsCodeLaunch();
|
||||||
launch.add(RunConfig.clientRunConfig(getProject()));
|
launch.add(RunConfig.clientRunConfig(project));
|
||||||
launch.add(RunConfig.serverRunConfig(getProject()));
|
launch.add(RunConfig.serverRunConfig(project));
|
||||||
|
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
String json = gson.toJson(launch);
|
String json = gson.toJson(launch);
|
||||||
|
@ -71,7 +73,7 @@ public class GenVsCodeProjectTask extends AbstractLoomTask {
|
||||||
throw new RuntimeException("Failed to write launch.json", e);
|
throw new RuntimeException("Failed to write launch.json", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
File runDir = new File(getProject().getRootDir(), extension.runDir);
|
File runDir = new File(project.getRootDir(), extension.runDir);
|
||||||
|
|
||||||
if (!runDir.exists()) {
|
if (!runDir.exists()) {
|
||||||
runDir.mkdirs();
|
runDir.mkdirs();
|
||||||
|
|
|
@ -27,27 +27,30 @@ package net.fabricmc.loom.task;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.file.FileSystem;
|
import java.nio.file.FileSystem;
|
||||||
import java.nio.file.FileSystems;
|
import java.nio.file.FileSystems;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
import com.google.common.net.UrlEscapers;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.apache.commons.io.FileUtils;
|
import com.google.common.collect.Iterables;
|
||||||
import org.cadixdev.lorenz.MappingSet;
|
import org.cadixdev.lorenz.MappingSet;
|
||||||
import org.cadixdev.lorenz.io.MappingsReader;
|
import org.cadixdev.lorenz.io.MappingsReader;
|
||||||
import org.cadixdev.lorenz.model.ClassMapping;
|
import org.cadixdev.lorenz.model.ClassMapping;
|
||||||
import org.cadixdev.lorenz.model.Mapping;
|
import org.cadixdev.lorenz.model.Mapping;
|
||||||
import org.cadixdev.mercury.Mercury;
|
import org.cadixdev.mercury.Mercury;
|
||||||
import org.cadixdev.mercury.remapper.MercuryRemapper;
|
import org.cadixdev.mercury.remapper.MercuryRemapper;
|
||||||
|
import org.gradle.api.GradleException;
|
||||||
|
import org.gradle.api.IllegalDependencyNotation;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
import org.gradle.api.tasks.TaskAction;
|
import org.gradle.api.tasks.TaskAction;
|
||||||
|
import org.gradle.api.tasks.options.Option;
|
||||||
|
|
||||||
import net.fabricmc.loom.LoomGradleExtension;
|
import net.fabricmc.loom.LoomGradleExtension;
|
||||||
import net.fabricmc.loom.providers.MappingsProvider;
|
import net.fabricmc.loom.providers.MappingsProvider;
|
||||||
|
@ -61,88 +64,99 @@ import net.fabricmc.mapping.tree.TinyMappingFactory;
|
||||||
import net.fabricmc.mapping.tree.TinyTree;
|
import net.fabricmc.mapping.tree.TinyTree;
|
||||||
|
|
||||||
public class MigrateMappingsTask extends AbstractLoomTask {
|
public class MigrateMappingsTask extends AbstractLoomTask {
|
||||||
|
private Path inputDir;
|
||||||
|
private Path outputDir;
|
||||||
|
private String mappings;
|
||||||
|
|
||||||
|
public MigrateMappingsTask() {
|
||||||
|
inputDir = getProject().file("src/main/java").toPath();
|
||||||
|
outputDir = getProject().file("remappedSrc").toPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Option(option = "input", description = "Java source file directory")
|
||||||
|
public void setInputDir(String inputDir) {
|
||||||
|
this.inputDir = getProject().file(inputDir).toPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Option(option = "output", description = "Remapped source output directory")
|
||||||
|
public void setOutputDir(String outputDir) {
|
||||||
|
this.outputDir = getProject().file(outputDir).toPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Option(option = "mappings", description = "Target mappings")
|
||||||
|
public void setMappings(String mappings) {
|
||||||
|
this.mappings = mappings;
|
||||||
|
}
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
public void doTask() throws Throwable {
|
public void doTask() throws Throwable {
|
||||||
Project project = getProject();
|
Project project = getProject();
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = getExtension();
|
||||||
Map<String, ?> properties = project.getProperties();
|
|
||||||
|
|
||||||
project.getLogger().lifecycle(":loading mappings");
|
project.getLogger().lifecycle(":loading mappings");
|
||||||
|
|
||||||
String inputDir = (String) properties.get("inputDir");
|
if (!Files.exists(inputDir) || !Files.isDirectory(inputDir)) {
|
||||||
if (inputDir == null) inputDir = "src/main/java";
|
throw new IllegalArgumentException("Could not find input directory: " + inputDir.toAbsolutePath());
|
||||||
String outputDir = (String) properties.get("outputDir");
|
|
||||||
if (outputDir == null) outputDir = "remappedSrc";
|
|
||||||
String officialMappingsVersion = (String) properties.get("targetMappings");
|
|
||||||
String localMappingsPath = (String) properties.get("targetLocalMappings");
|
|
||||||
|
|
||||||
if (officialMappingsVersion != null && localMappingsPath != null) {
|
|
||||||
throw new IllegalArgumentException("targetMappings and targetLocalMappings are mutually exclusive;"
|
|
||||||
+ " you either specify an official yarn mappings version with targetMappings, "
|
|
||||||
+ "or a local one with targetLocalMappings.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (officialMappingsVersion == null && localMappingsPath == null) {
|
Files.createDirectories(outputDir);
|
||||||
throw new IllegalArgumentException("You must specify a new mappings version with -PtargetMappings (or local mappings with -PtargetLocalMappings).");
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean useLocalMappings = localMappingsPath != null;
|
|
||||||
|
|
||||||
if (useLocalMappings && !Files.exists(Paths.get(localMappingsPath))) {
|
|
||||||
throw new IllegalArgumentException("Can't find local mappings in specified location: " + localMappingsPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
String targetMappingsName = useLocalMappings ? localMappingsPath : officialMappingsVersion;
|
|
||||||
|
|
||||||
Path inputDirPath = Paths.get(System.getProperty("user.dir"), inputDir);
|
|
||||||
Path outputDirPath = Paths.get(System.getProperty("user.dir"), outputDir);
|
|
||||||
|
|
||||||
if (!Files.exists(inputDirPath) || !Files.isDirectory(inputDirPath)) {
|
|
||||||
throw new IllegalArgumentException("Could not find input directory: " + inputDirPath.toAbsolutePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
Files.createDirectories(outputDirPath);
|
|
||||||
|
|
||||||
|
File mappings = loadMappings();
|
||||||
MappingsProvider mappingsProvider = extension.getMappingsProvider();
|
MappingsProvider mappingsProvider = extension.getMappingsProvider();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TinyTree currentMappings = mappingsProvider.getMappings();
|
TinyTree currentMappings = mappingsProvider.getMappings();
|
||||||
TinyTree targetMappings = getMappings(project, targetMappingsName, useLocalMappings);
|
TinyTree targetMappings = getMappings(mappings);
|
||||||
migrateMappings(project, extension.getMinecraftMappedProvider(), inputDirPath, outputDirPath, currentMappings, targetMappings, extension);
|
migrateMappings(project, extension.getMinecraftMappedProvider(), inputDir, outputDir, currentMappings, targetMappings);
|
||||||
project.getLogger().lifecycle(":remapped project written to " + outputDirPath.toAbsolutePath());
|
project.getLogger().lifecycle(":remapped project written to " + outputDir.toAbsolutePath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IllegalArgumentException("Could not find mappings for version " + officialMappingsVersion, e);
|
throw new IllegalArgumentException("Error while loading mappings", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TinyTree getMappings(Project project, String mappingsVersionOrPath, boolean useLocalMappings) throws IOException {
|
private File loadMappings() {
|
||||||
Path migrateMappingsDir = Files.createTempDirectory("migrate");
|
Project project = getProject();
|
||||||
Path localMappingsOfVersion = migrateMappingsDir.resolve(mappingsVersionOrPath + ".tiny");
|
|
||||||
|
|
||||||
if (!Files.exists(localMappingsOfVersion)) {
|
if (mappings == null || mappings.isEmpty()) {
|
||||||
if (useLocalMappings) {
|
throw new IllegalArgumentException("No mappings were specified. Use --mappings=\"\" to specify target mappings");
|
||||||
Files.copy(Paths.get(mappingsVersionOrPath), localMappingsOfVersion);
|
}
|
||||||
} else {
|
|
||||||
String versionRelativePath = UrlEscapers.urlFragmentEscaper().escape(mappingsVersionOrPath);
|
|
||||||
String artifactUrl = "https://maven.fabricmc.net/net/fabricmc/yarn/" + versionRelativePath + "/yarn-" + versionRelativePath + ".jar";
|
|
||||||
File mappingsJar = File.createTempFile("migrateMappingsJar", ".jar");
|
|
||||||
project.getLogger().lifecycle(":downloading new mappings from " + artifactUrl);
|
|
||||||
FileUtils.copyURLToFile(new URL(artifactUrl), mappingsJar);
|
|
||||||
|
|
||||||
try (FileSystem jar = FileSystems.newFileSystem(mappingsJar.toPath(), null)) {
|
Set<File> files;
|
||||||
if (!Files.exists(migrateMappingsDir)) Files.createDirectory(migrateMappingsDir);
|
|
||||||
MappingsProvider.extractMappings(jar, localMappingsOfVersion);
|
try {
|
||||||
}
|
files = project.getConfigurations().detachedConfiguration(project.getDependencies().create(mappings)).resolve();
|
||||||
|
} catch (IllegalDependencyNotation ignored) {
|
||||||
|
project.getLogger().info("Could not locate mappings, presuming V2 Yarn");
|
||||||
|
|
||||||
|
try {
|
||||||
|
files = project.getConfigurations().detachedConfiguration(project.getDependencies().module(ImmutableMap.of("group", "net.fabricmc", "name", "yarn", "version", mappings, "classifier", "v2"))).resolve();
|
||||||
|
} catch (GradleException ignored2) {
|
||||||
|
project.getLogger().info("Could not locate mappings, presuming V1 Yarn");
|
||||||
|
files = project.getConfigurations().detachedConfiguration(project.getDependencies().module(ImmutableMap.of("group", "net.fabricmc", "name", "yarn", "version", mappings))).resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try (BufferedReader reader = Files.newBufferedReader(localMappingsOfVersion)) {
|
if (files.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Mappings could not be found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Iterables.getOnlyElement(files);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static TinyTree getMappings(File mappings) throws IOException {
|
||||||
|
Path temp = Files.createTempFile("mappings", ".tiny");
|
||||||
|
|
||||||
|
try (FileSystem fileSystem = FileSystems.newFileSystem(mappings.toPath(), null)) {
|
||||||
|
Files.copy(fileSystem.getPath("mappings/mappings.tiny"), temp, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
|
||||||
|
try (BufferedReader reader = Files.newBufferedReader(temp)) {
|
||||||
return TinyMappingFactory.loadWithDetection(reader);
|
return TinyMappingFactory.loadWithDetection(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void migrateMappings(Project project, MinecraftMappedProvider minecraftMappedProvider,
|
private static void migrateMappings(Project project, MinecraftMappedProvider minecraftMappedProvider,
|
||||||
Path inputDir, Path outputDir, TinyTree currentMappings, TinyTree targetMappings, LoomGradleExtension extension
|
Path inputDir, Path outputDir, TinyTree currentMappings, TinyTree targetMappings
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
project.getLogger().lifecycle(":joining mappings");
|
project.getLogger().lifecycle(":joining mappings");
|
||||||
MappingSet mappingSet = new MappingsJoiner(currentMappings, targetMappings,
|
MappingSet mappingSet = new MappingsJoiner(currentMappings, targetMappings,
|
||||||
|
@ -166,7 +180,7 @@ public class MigrateMappingsTask extends AbstractLoomTask {
|
||||||
System.gc();
|
System.gc();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MappingsJoiner extends MappingsReader {
|
private static class MappingsJoiner extends MappingsReader {
|
||||||
private final TinyTree sourceMappings, targetMappings;
|
private final TinyTree sourceMappings, targetMappings;
|
||||||
private final String fromNamespace, toNamespace;
|
private final String fromNamespace, toNamespace;
|
||||||
|
|
||||||
|
@ -179,7 +193,7 @@ public class MigrateMappingsTask extends AbstractLoomTask {
|
||||||
* Since we only use intermediary names (and not descriptors) to match, and intermediary names are unique,
|
* Since we only use intermediary names (and not descriptors) to match, and intermediary names are unique,
|
||||||
* this will migrate methods that have had their signature changed too.
|
* this will migrate methods that have had their signature changed too.
|
||||||
*/
|
*/
|
||||||
public MappingsJoiner(TinyTree sourceMappings, TinyTree targetMappings, String fromNamespace, String toNamespace) {
|
private MappingsJoiner(TinyTree sourceMappings, TinyTree targetMappings, String fromNamespace, String toNamespace) {
|
||||||
this.sourceMappings = sourceMappings;
|
this.sourceMappings = sourceMappings;
|
||||||
this.targetMappings = targetMappings;
|
this.targetMappings = targetMappings;
|
||||||
this.fromNamespace = fromNamespace;
|
this.fromNamespace = fromNamespace;
|
||||||
|
@ -234,4 +248,3 @@ public class MigrateMappingsTask extends AbstractLoomTask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,13 +39,13 @@ import com.google.common.collect.Iterables;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.zeroturnaround.zip.ZipUtil;
|
|
||||||
import org.gradle.api.InvalidUserDataException;
|
import org.gradle.api.InvalidUserDataException;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
import org.gradle.api.artifacts.Configuration;
|
import org.gradle.api.artifacts.Configuration;
|
||||||
import org.gradle.api.artifacts.Dependency;
|
import org.gradle.api.artifacts.Dependency;
|
||||||
import org.gradle.api.artifacts.ResolvedDependency;
|
import org.gradle.api.artifacts.ResolvedDependency;
|
||||||
import org.gradle.api.artifacts.SelfResolvingDependency;
|
import org.gradle.api.artifacts.SelfResolvingDependency;
|
||||||
|
import org.zeroturnaround.zip.ZipUtil;
|
||||||
|
|
||||||
import net.fabricmc.loom.LoomGradleExtension;
|
import net.fabricmc.loom.LoomGradleExtension;
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ public abstract class DependencyProvider {
|
||||||
|
|
||||||
public static class FileDependencyInfo extends DependencyInfo {
|
public static class FileDependencyInfo extends DependencyInfo {
|
||||||
protected final Map<String, File> classifierToFile = new HashMap<>();
|
protected final Map<String, File> classifierToFile = new HashMap<>();
|
||||||
protected final String group = "net.fabricmc.synthetic", name, version;
|
protected final String group, name, version;
|
||||||
|
|
||||||
FileDependencyInfo(Project project, SelfResolvingDependency dependency, Configuration configuration) {
|
FileDependencyInfo(Project project, SelfResolvingDependency dependency, Configuration configuration) {
|
||||||
super(project, dependency, configuration);
|
super(project, dependency, configuration);
|
||||||
|
@ -196,27 +196,34 @@ public abstract class DependencyProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
File root = classifierToFile.get(""); //We've built the classifierToFile map, now to try find a name and version for our dependency
|
if (dependency.getGroup() != null && dependency.getVersion() != null) {
|
||||||
|
group = dependency.getGroup();
|
||||||
if ("jar".equals(FilenameUtils.getExtension(root.getName())) && ZipUtil.containsEntry(root, "fabric.mod.json")) {
|
name = dependency.getName();
|
||||||
//It's a Fabric mod, see how much we can extract out
|
version = dependency.getVersion();
|
||||||
JsonObject json = new Gson().fromJson(new String(ZipUtil.unpackEntry(root, "fabric.mod.json"), StandardCharsets.UTF_8), JsonObject.class);
|
|
||||||
|
|
||||||
if (json == null || !json.has("id") || !json.has("version")) {
|
|
||||||
throw new IllegalArgumentException("Invalid Fabric mod jar: " + root + " (malformed json: " + json + ')');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (json.has("name")) { //Go for the name field if it's got one
|
|
||||||
name = json.get("name").getAsString();
|
|
||||||
} else {
|
|
||||||
name = json.get("id").getAsString();
|
|
||||||
}
|
|
||||||
|
|
||||||
version = json.get("version").getAsString();
|
|
||||||
} else {
|
} else {
|
||||||
//Not a Fabric mod, just have to make something up
|
group = "net.fabricmc.synthetic";
|
||||||
name = FilenameUtils.removeExtension(root.getName());
|
File root = classifierToFile.get(""); //We've built the classifierToFile map, now to try find a name and version for our dependency
|
||||||
version = "1.0";
|
|
||||||
|
if ("jar".equals(FilenameUtils.getExtension(root.getName())) && ZipUtil.containsEntry(root, "fabric.mod.json")) {
|
||||||
|
//It's a Fabric mod, see how much we can extract out
|
||||||
|
JsonObject json = new Gson().fromJson(new String(ZipUtil.unpackEntry(root, "fabric.mod.json"), StandardCharsets.UTF_8), JsonObject.class);
|
||||||
|
|
||||||
|
if (json == null || !json.has("id") || !json.has("version")) {
|
||||||
|
throw new IllegalArgumentException("Invalid Fabric mod jar: " + root + " (malformed json: " + json + ')');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json.has("name")) { //Go for the name field if it's got one
|
||||||
|
name = json.get("name").getAsString();
|
||||||
|
} else {
|
||||||
|
name = json.get("id").getAsString();
|
||||||
|
}
|
||||||
|
|
||||||
|
version = json.get("version").getAsString();
|
||||||
|
} else {
|
||||||
|
//Not a Fabric mod, just have to make something up
|
||||||
|
name = FilenameUtils.removeExtension(root.getName());
|
||||||
|
version = "1.0";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class DownloadUtil {
|
||||||
|
|
||||||
if ((code < 200 || code > 299) && code != HttpURLConnection.HTTP_NOT_MODIFIED) {
|
if ((code < 200 || code > 299) && code != HttpURLConnection.HTTP_NOT_MODIFIED) {
|
||||||
//Didn't get what we expected
|
//Didn't get what we expected
|
||||||
throw new IOException(connection.getResponseMessage());
|
throw new IOException(connection.getResponseMessage() + " for " + from);
|
||||||
}
|
}
|
||||||
|
|
||||||
long modifyTime = connection.getHeaderFieldDate("Last-Modified", -1);
|
long modifyTime = connection.getHeaderFieldDate("Last-Modified", -1);
|
||||||
|
|
|
@ -106,7 +106,7 @@ public class RunConfig {
|
||||||
default:
|
default:
|
||||||
runConfig.mainClass = "net.fabricmc.devlaunchinjector.Main";
|
runConfig.mainClass = "net.fabricmc.devlaunchinjector.Main";
|
||||||
runConfig.programArgs = "";
|
runConfig.programArgs = "";
|
||||||
runConfig.vmArgs = "-Dfabric.dli.config=\"" + extension.getDevLauncherConfig().getAbsolutePath() + "\" -Dfabric.dli.env=" + mode.toLowerCase();
|
runConfig.vmArgs = "-Dfabric.dli.config=" + quoteIfNeeded(extension.getDevLauncherConfig().getAbsolutePath()) + " -Dfabric.dli.env=" + mode.toLowerCase();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,4 +218,12 @@ public class RunConfig {
|
||||||
|
|
||||||
throw new RuntimeException("Failed to find mainclass");
|
throw new RuntimeException("Failed to find mainclass");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String quoteIfNeeded(String input) {
|
||||||
|
if (!input.contains(" ")) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.format("\"%s\"", input);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,59 +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 class Version {
|
|
||||||
private String mappingsVersion;
|
|
||||||
private String minecraftVersion;
|
|
||||||
|
|
||||||
private String version;
|
|
||||||
|
|
||||||
public Version(String version) {
|
|
||||||
this.version = version;
|
|
||||||
|
|
||||||
if (version.contains("+build.")) {
|
|
||||||
this.minecraftVersion = version.substring(0, version.lastIndexOf('+'));
|
|
||||||
this.mappingsVersion = version.substring(version.lastIndexOf('.') + 1);
|
|
||||||
} else {
|
|
||||||
//TODO legacy remove when no longer needed
|
|
||||||
char verSep = version.contains("-") ? '-' : '.';
|
|
||||||
this.minecraftVersion = version.substring(0, version.lastIndexOf(verSep));
|
|
||||||
this.mappingsVersion = version.substring(version.lastIndexOf(verSep) + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMappingsVersion() {
|
|
||||||
return mappingsVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMinecraftVersion() {
|
|
||||||
return minecraftVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue