Change some stuff in hope that it helps things
parent
bbf5e341e3
commit
d0e649766b
|
@ -11,7 +11,7 @@ targetCompatibility = 1.8
|
|||
|
||||
group = 'net.fabricmc'
|
||||
archivesBaseName = project.name
|
||||
version = '0.0.12-SNAPSHOT'
|
||||
version = '0.0.13-SNAPSHOT'
|
||||
|
||||
def build = "local"
|
||||
def ENV = System.getenv()
|
||||
|
@ -47,7 +47,7 @@ dependencies {
|
|||
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'Implementation-Version': version + " Build(" + build + ")"
|
||||
attributes 'Implementation-MinecraftVersionInfo': version + " Build(" + build + ")"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ set DEFAULT_JVM_OPTS=
|
|||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
%JAVA_EXE% -minecraftVersionInfo >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
|
|
|
@ -28,10 +28,9 @@ import com.google.common.collect.ImmutableMap;
|
|||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.fabricmc.loom.task.DownloadTask;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.ModRemapper;
|
||||
import net.fabricmc.loom.util.Version;
|
||||
import net.fabricmc.loom.providers.MinecraftProvider;
|
||||
import net.fabricmc.loom.providers.ModRemapperProvider;
|
||||
import net.fabricmc.loom.util.*;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
|
@ -70,22 +69,13 @@ public class AbstractPlugin implements Plugin<Project> {
|
|||
project.getExtensions().create("minecraft", LoomGradleExtension.class, project);
|
||||
|
||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
readModJson(extension);
|
||||
|
||||
// Force add Mojang repository
|
||||
addMavenRepo(target, "Mojang", "https://libraries.minecraft.net/");
|
||||
|
||||
// Minecraft libraries configuration
|
||||
project.getConfigurations().maybeCreate(Constants.CONFIG_MINECRAFT);
|
||||
project.getConfigurations().maybeCreate(Constants.CONFIG_MC_DEPENDENCIES);
|
||||
project.getConfigurations().maybeCreate(Constants.CONFIG_MC_DEPENDENCIES_CLIENT);
|
||||
project.getConfigurations().maybeCreate(Constants.CONFIG_NATIVES);
|
||||
|
||||
Configuration compileModsConfig = project.getConfigurations().maybeCreate(Constants.COMPILE_MODS);
|
||||
|
||||
compileModsConfig.setTransitive(false); //Dont get transitive deps of mods
|
||||
|
||||
// Common libraries extends from client libraries, CONFIG_MC_DEPENDENCIES will contains all MC dependencies
|
||||
project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT).extendsFrom(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).extendsFrom(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES_CLIENT)));
|
||||
project.getConfigurations().maybeCreate(Constants.MINECRAFT);
|
||||
|
||||
configureIDEs();
|
||||
configureCompile();
|
||||
|
@ -95,21 +85,17 @@ public class AbstractPlugin implements Plugin<Project> {
|
|||
Project project = entry.getKey();
|
||||
Set<Task> taskSet = entry.getValue();
|
||||
for (Task task : taskSet) {
|
||||
if (task instanceof GeneratorTask) {
|
||||
task.dependsOn("setup");
|
||||
}
|
||||
|
||||
if (task instanceof JavaCompile
|
||||
&& !(task.getName().contains("Test")) && !(task.getName().contains("test"))) {
|
||||
JavaCompile javaCompileTask = (JavaCompile) task;
|
||||
javaCompileTask.doFirst(task1 -> {
|
||||
project.getLogger().lifecycle(":setting java compiler args");
|
||||
try {
|
||||
javaCompileTask.getClasspath().add(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT));
|
||||
javaCompileTask.getClasspath().add(target.files(this.getClass().getProtectionDomain().getCodeSource().getLocation()));
|
||||
//javaCompileTask.getClasspath().add(target.files(this.getClass().getProtectionDomain().getCodeSource().getLocation()));
|
||||
|
||||
javaCompileTask.getOptions().getCompilerArgs().add("-AinMapFileNamedIntermediary=" + Constants.MAPPINGS_TINY.get(extension).getCanonicalPath());
|
||||
javaCompileTask.getOptions().getCompilerArgs().add("-AoutMapFileNamedIntermediary=" + Constants.MAPPINGS_MIXIN_EXPORT.get(extension).getCanonicalPath());
|
||||
|
||||
javaCompileTask.getOptions().getCompilerArgs().add("-AinMapFileNamedIntermediary=" + extension.getMinecraftProvider().pomfProvider.MAPPINGS_TINY.getCanonicalPath());
|
||||
javaCompileTask.getOptions().getCompilerArgs().add("-AoutMapFileNamedIntermediary=" + extension.getMinecraftProvider().pomfProvider.MAPPINGS_MIXIN_EXPORT.getCanonicalPath());
|
||||
if(extension.refmapName == null || extension.refmapName.isEmpty()){
|
||||
project.getLogger().error("Could not find refmap definition, will be using default name: " + project.getName() + "-refmap.json");
|
||||
extension.refmapName = project.getName() + "-refmap.json";
|
||||
|
@ -176,11 +162,9 @@ public class AbstractPlugin implements Plugin<Project> {
|
|||
ideaModel.getModule().setDownloadJavadoc(true);
|
||||
ideaModel.getModule().setDownloadSources(true);
|
||||
ideaModel.getModule().setInheritOutputDirs(true);
|
||||
ideaModel.getModule().getScopes().get("COMPILE").get("plus").add(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT));
|
||||
|
||||
// ECLIPSE
|
||||
EclipseModel eclipseModel = (EclipseModel) project.getExtensions().getByName("eclipse");
|
||||
eclipseModel.getClasspath().getPlusConfigurations().add(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -192,11 +176,6 @@ public class AbstractPlugin implements Plugin<Project> {
|
|||
SourceSet main = javaModule.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
|
||||
SourceSet test = javaModule.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);
|
||||
|
||||
main.setCompileClasspath(main.getCompileClasspath().plus(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT)));
|
||||
test.setCompileClasspath(test.getCompileClasspath().plus(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT)));
|
||||
main.setRuntimeClasspath(main.getCompileClasspath().plus(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT)));
|
||||
test.setCompileClasspath(test.getCompileClasspath().plus(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT)));
|
||||
|
||||
Javadoc javadoc = (Javadoc) project.getTasks().getByName(JavaPlugin.JAVADOC_TASK_NAME);
|
||||
javadoc.setClasspath(main.getOutput().plus(main.getCompileClasspath()));
|
||||
|
||||
|
@ -231,74 +210,25 @@ public class AbstractPlugin implements Plugin<Project> {
|
|||
project1.getRepositories().mavenCentral();
|
||||
project1.getRepositories().jcenter();
|
||||
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
DownloadTask.downloadMcJson(extension, project1.getLogger());
|
||||
Version version = gson.fromJson(new FileReader(Constants.MINECRAFT_JSON.get(extension)), Version.class);
|
||||
for (Version.Library library : version.libraries) {
|
||||
if (library.allowed() && library.getFile(extension) != null) {
|
||||
String configName = Constants.CONFIG_MC_DEPENDENCIES;
|
||||
if (library.name.contains("java3d") || library.name.contains("paulscode") || library.name.contains("lwjgl") || library.name.contains("twitch") || library.name.contains("jinput") || library.name.contains("text2speech") || library.name.contains("objc")) {
|
||||
configName = Constants.CONFIG_MC_DEPENDENCIES_CLIENT;
|
||||
}
|
||||
project1.getDependencies().add(configName, library.getArtifactName());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
project1.getDependencies().add(Constants.CONFIG_MINECRAFT, "net.minecraft:" + Constants.MINECRAFT_FINAL_JAR.get(extension).getName().replace(".jar", ""));
|
||||
LoomDependencyManager dependencyManager = new LoomDependencyManager();
|
||||
extension.setDependencyManager(dependencyManager);
|
||||
|
||||
if (extension.isModWorkspace()) {
|
||||
//only add this when not in a dev env
|
||||
project1.getDependencies().add(Constants.COMPILE_MODS, "net.fabricmc:fabric-loader:" + extension.getVersionString());
|
||||
}
|
||||
dependencyManager.addProvider(new MinecraftProvider());
|
||||
dependencyManager.addProvider(new ModRemapperProvider());
|
||||
|
||||
dependencyManager.handleDependencies(project1);
|
||||
|
||||
project1.getTasks().getByName("idea").finalizedBy(project1.getTasks().getByName("genIdeaWorkspace"));
|
||||
});
|
||||
|
||||
project.getTasks().getByName("jar").doLast(task -> {
|
||||
project.getLogger().lifecycle(":remapping mods");
|
||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
try {
|
||||
if(extension.hasPomf()){
|
||||
ModRemapper.remap(project);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
project.afterEvaluate(project12 -> {
|
||||
project12.getTasks().getByName("idea").dependsOn(project12.getTasks().getByName("cleanIdea")).dependsOn(project12.getTasks().getByName("setup")).dependsOn(project12.getTasks().getByName("extractNatives"));
|
||||
project12.getTasks().getByName("idea").finalizedBy(project12.getTasks().getByName("genIdeaWorkspace"));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void readModJson(LoomGradleExtension extension) {
|
||||
File resDir = new File(project.getProjectDir(), "src" + File.separator + "main" + File.separator + "resources");
|
||||
File modJson = new File(resDir, "mod.json");
|
||||
if (modJson.exists()) {
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
JsonElement jsonElement = gson.fromJson(new FileReader(modJson), JsonElement.class);
|
||||
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||
if ((extension.version == null || extension.version.isEmpty()) && jsonObject.has("version")) {
|
||||
project.setVersion(jsonObject.get("version").getAsString());
|
||||
}
|
||||
if (jsonObject.has("group")) {
|
||||
project.setGroup(jsonObject.get("group").getAsString());
|
||||
}
|
||||
if (jsonObject.has("description")) {
|
||||
project.setDescription(jsonObject.get("description").getAsString());
|
||||
}
|
||||
//TODO load deps
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
//This wont happen as we have checked for it
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,38 +24,24 @@
|
|||
|
||||
package net.fabricmc.loom;
|
||||
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.providers.MinecraftProvider;
|
||||
import net.fabricmc.loom.util.LoomDependencyManager;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class LoomGradleExtension {
|
||||
public String version;
|
||||
public String runDir = "run";
|
||||
public String fabricVersion;
|
||||
public String pomfVersion;
|
||||
public String refmapName;
|
||||
public String jarMapper = Constants.JAR_MAPPER_TINY; // enigma, tiny
|
||||
public boolean localMappings = false;
|
||||
|
||||
//Not to be set in the build.gradle
|
||||
private Project project;
|
||||
private LoomDependencyManager dependencyManager;
|
||||
|
||||
public LoomGradleExtension(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public String getVersionString() {
|
||||
if (isModWorkspace()) {
|
||||
return version + "-" + fabricVersion;
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
public boolean isModWorkspace() {
|
||||
return fabricVersion != null && !fabricVersion.isEmpty();
|
||||
}
|
||||
|
||||
public File getUserCache() {
|
||||
File userCache = new File(project.getGradle().getGradleUserHomeDir(), "caches" + File.separator + "fabric-loom");
|
||||
if (!userCache.exists()) {
|
||||
|
@ -64,10 +50,15 @@ public class LoomGradleExtension {
|
|||
return userCache;
|
||||
}
|
||||
|
||||
public boolean hasPomf(){
|
||||
if (localMappings) {
|
||||
return true;
|
||||
public LoomDependencyManager getDependencyManager() {
|
||||
return dependencyManager;
|
||||
}
|
||||
return pomfVersion != null && !pomfVersion.isEmpty();
|
||||
|
||||
public MinecraftProvider getMinecraftProvider(){
|
||||
return getDependencyManager().getProvider(MinecraftProvider.class);
|
||||
}
|
||||
|
||||
public void setDependencyManager(LoomDependencyManager dependencyManager) {
|
||||
this.dependencyManager = dependencyManager;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,16 +32,8 @@ public class LoomGradlePlugin extends AbstractPlugin {
|
|||
public void apply(Project target) {
|
||||
super.apply(target);
|
||||
|
||||
makeTask("download", DownloadTask.class);
|
||||
makeTask("mergeJars", MergeJarsTask.class).dependsOn("download");
|
||||
makeTask("mapJars", MapJarsTask.class).dependsOn("mergeJars");
|
||||
makeTask("setup", SetupTask.class).dependsOn("mapJars").setGroup("fabric");
|
||||
|
||||
makeTask("extractNatives", ExtractNativesTask.class).dependsOn("download");
|
||||
makeTask("genIdeaWorkspace", GenIdeaProjectTask.class).dependsOn("idea").setGroup("ide");
|
||||
|
||||
makeTask("vscode", GenVSCodeProjectTask.class).dependsOn("extractNatives").setGroup("ide");
|
||||
|
||||
makeTask("runClient", RunClientTask.class).dependsOn("buildNeeded").setGroup("minecraft");
|
||||
makeTask("runServer", RunServerTask.class).dependsOn("buildNeeded").setGroup("minecraft");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* 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.providers;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.MapJarsTiny;
|
||||
import net.fabricmc.stitch.merge.JarMerger;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
public class MinecraftJarProvider {
|
||||
|
||||
public File MINECRAFT_INTERMEDIARY_JAR;
|
||||
public File MINECRAFT_MERGED_JAR;
|
||||
public File MINECRAFT_MAPPED_JAR;
|
||||
|
||||
MinecraftProvider minecraftProvider;
|
||||
|
||||
public MinecraftJarProvider(Project project, MinecraftProvider minecraftProvider) throws IOException {
|
||||
this.minecraftProvider = minecraftProvider;
|
||||
initFiles(project, minecraftProvider);
|
||||
proccess(project, minecraftProvider);
|
||||
}
|
||||
|
||||
private void proccess(Project project, MinecraftProvider minecraftProvider) throws IOException {
|
||||
if (!MINECRAFT_MERGED_JAR.exists()) {
|
||||
mergeJars(project);
|
||||
}
|
||||
|
||||
if (getMappedJar().exists()) {
|
||||
getMappedJar().delete();
|
||||
}
|
||||
if (getIntermediaryJar().exists()) {
|
||||
getIntermediaryJar().delete();
|
||||
}
|
||||
new MapJarsTiny().mapJars(this, project);
|
||||
|
||||
if (!MINECRAFT_MAPPED_JAR.exists()) {
|
||||
throw new RuntimeException("mapped jar not found");
|
||||
}
|
||||
minecraftProvider.addDep(MINECRAFT_MAPPED_JAR, project);
|
||||
}
|
||||
|
||||
public void mergeJars(Project project) throws IOException {
|
||||
project.getLogger().lifecycle(":merging jars");
|
||||
FileInputStream client = new FileInputStream(minecraftProvider.MINECRAFT_CLIENT_JAR);
|
||||
FileInputStream server = new FileInputStream(minecraftProvider.MINECRAFT_SERVER_JAR);
|
||||
FileOutputStream merged = new FileOutputStream(MINECRAFT_MERGED_JAR);
|
||||
|
||||
JarMerger jarMerger = new JarMerger(client, server, merged);
|
||||
|
||||
jarMerger.merge();
|
||||
jarMerger.close();
|
||||
|
||||
client.close();
|
||||
server.close();
|
||||
merged.close();
|
||||
}
|
||||
|
||||
private void initFiles(Project project, MinecraftProvider minecraftProvider) {
|
||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
MINECRAFT_INTERMEDIARY_JAR = new File(extension.getUserCache(), minecraftProvider.minecraftVersion + "-intermediary.jar");
|
||||
MINECRAFT_MERGED_JAR = new File(extension.getUserCache(), minecraftProvider.minecraftVersion + "-merged.jar");
|
||||
MINECRAFT_MAPPED_JAR = new File(extension.getUserCache(), minecraftProvider.minecraftVersion + "-mapped-" + minecraftProvider.pomfVersion + ".jar");
|
||||
|
||||
}
|
||||
|
||||
public File getMappingFile() {
|
||||
return minecraftProvider.pomfProvider.MAPPINGS_TINY;
|
||||
}
|
||||
|
||||
public Collection<File> getMapperPaths() {
|
||||
return minecraftProvider.libraryProvider.getLibraries();
|
||||
}
|
||||
|
||||
public File getInputJar() {
|
||||
return MINECRAFT_MERGED_JAR;
|
||||
}
|
||||
|
||||
public File getIntermediaryJar() {
|
||||
return MINECRAFT_INTERMEDIARY_JAR;
|
||||
}
|
||||
|
||||
public File getMappedJar() {
|
||||
return MINECRAFT_MAPPED_JAR;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
* 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.providers;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.gson.Gson;
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Checksum;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.MinecraftVersionInfo;
|
||||
import net.fabricmc.loom.util.assets.AssetIndex;
|
||||
import net.fabricmc.loom.util.assets.AssetObject;
|
||||
import net.fabricmc.loom.util.progress.ProgressLogger;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class MinecraftLibraryProvider {
|
||||
|
||||
public File MINECRAFT_LIBS;
|
||||
public File MINECRAFT_NATIVES;
|
||||
|
||||
private Collection<File> libs = new HashSet<>();
|
||||
|
||||
public void provide(MinecraftProvider minecraftProvider, Project project) throws IOException {
|
||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
MinecraftVersionInfo versionInfo = minecraftProvider.versionInfo;
|
||||
|
||||
initFiles(project, minecraftProvider);
|
||||
|
||||
for (MinecraftVersionInfo.Library library : versionInfo.libraries) {
|
||||
if (library.allowed() && library.getFile(MINECRAFT_LIBS) != null) {
|
||||
// By default, they are all available on all sides
|
||||
boolean isClientOnly = false;
|
||||
if (library.name.contains("java3d") || library.name.contains("paulscode") || library.name.contains("lwjgl") || library.name.contains("twitch") || library.name.contains("jinput") || library.name.contains("text2speech") || library.name.contains("objc")) {
|
||||
isClientOnly = true;
|
||||
}
|
||||
if(!library.getFile(MINECRAFT_LIBS).exists()){
|
||||
project.getLogger().lifecycle(":downloading " + library.getURL());
|
||||
FileUtils.copyURLToFile(new URL(library.getURL()), library.getFile(MINECRAFT_LIBS));
|
||||
}
|
||||
libs.add(library.getFile(MINECRAFT_LIBS));
|
||||
minecraftProvider.addDep(library.getFile(MINECRAFT_LIBS), project);
|
||||
}
|
||||
}
|
||||
|
||||
//adds the natvies to compile //TODO extract natives
|
||||
versionInfo.libraries.stream().filter(lib -> lib.natives != null).forEach(lib -> minecraftProvider.addDep(lib.getArtifactName(), project));
|
||||
|
||||
// for (File source : getProject().getConfigurations().getByName(Constants.CONFIG_NATIVES)) {
|
||||
// ZipUtil.unpack(source, Constants.MINECRAFT_NATIVES.get(extension));
|
||||
// }
|
||||
|
||||
MinecraftVersionInfo.AssetIndex assetIndex = versionInfo.assetIndex;
|
||||
|
||||
// get existing cache files
|
||||
project.getLogger().lifecycle(":checking for existing asset files");
|
||||
Multimap<String, File> assetFilenameToFile = HashMultimap.create();
|
||||
for (File assetDir : Objects.requireNonNull(extension.getUserCache().listFiles((f) -> f.isDirectory() && f.getName().startsWith("assets-")))) {
|
||||
File objectsDir = new File(assetDir, "objects");
|
||||
if (objectsDir.exists() && objectsDir.isDirectory()) {
|
||||
for (File subDir : Objects.requireNonNull(objectsDir.listFiles(File::isDirectory))) {
|
||||
for (File subFile : Objects.requireNonNull(subDir.listFiles(File::isFile))) {
|
||||
assetFilenameToFile.put("objects" + File.separator + subDir.getName() + File.separator + subFile.getName(), subFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File assets = new File(extension.getUserCache(), "assets-" + minecraftProvider.minecraftVersion);
|
||||
if (!assets.exists()) {
|
||||
assets.mkdirs();
|
||||
}
|
||||
|
||||
File assetsInfo = new File(assets, "indexes" + File.separator + assetIndex.id + ".json");
|
||||
if (!assetsInfo.exists() || !Checksum.equals(assetsInfo, assetIndex.sha1)) {
|
||||
project.getLogger().lifecycle(":downloading asset index");
|
||||
FileUtils.copyURLToFile(new URL(assetIndex.url), assetsInfo);
|
||||
}
|
||||
|
||||
ProgressLogger progressLogger = ProgressLogger.getProgressFactory(project, getClass().getName());
|
||||
progressLogger.start("Downloading assets...", "assets");
|
||||
FileReader fileReader = new FileReader(assetsInfo);
|
||||
AssetIndex index = new Gson().fromJson(fileReader, AssetIndex.class);
|
||||
fileReader.close();
|
||||
Map<String, AssetObject> parent = index.getFileMap();
|
||||
final int totalSize = parent.size();
|
||||
int position = 0;
|
||||
project.getLogger().lifecycle(":downloading assets...");
|
||||
for (Map.Entry<String, AssetObject> entry : parent.entrySet()) {
|
||||
AssetObject object = entry.getValue();
|
||||
String sha1 = object.getHash();
|
||||
String filename = "objects" + File.separator + sha1.substring(0, 2) + File.separator + sha1;
|
||||
File file = new File(assets, filename);
|
||||
if (!file.exists() && assetFilenameToFile.containsKey(filename)) {
|
||||
project.getLogger().debug(":copying asset " + entry.getKey());
|
||||
for (File srcFile : assetFilenameToFile.get(filename)) {
|
||||
if (Checksum.equals(srcFile, sha1)) {
|
||||
FileUtils.copyFile(srcFile, file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!file.exists() || !Checksum.equals(file, sha1)) {
|
||||
project.getLogger().debug(":downloading asset " + entry.getKey());
|
||||
FileUtils.copyURLToFile(new URL(Constants.RESOURCES_BASE + sha1.substring(0, 2) + "/" + sha1), file);
|
||||
}
|
||||
String assetName = entry.getKey();
|
||||
int end = assetName.lastIndexOf("/") + 1;
|
||||
if (end > 0) {
|
||||
assetName = assetName.substring(end);
|
||||
}
|
||||
progressLogger.progress(assetName + " - " + position + "/" + totalSize + " (" + (int) ((position / (double) totalSize) * 100) + "%) assets downloaded");
|
||||
position++;
|
||||
}
|
||||
progressLogger.completed();
|
||||
}
|
||||
|
||||
public Collection<File> getLibraries() {
|
||||
return libs;
|
||||
}
|
||||
|
||||
private void initFiles(Project project, MinecraftProvider minecraftProvider) {
|
||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
MINECRAFT_LIBS = new File(extension.getUserCache(), minecraftProvider.minecraftVersion + "-libs");
|
||||
MINECRAFT_NATIVES = new File(extension.getUserCache(), minecraftProvider.minecraftVersion + "-natives");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* 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.providers;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.*;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Optional;
|
||||
|
||||
public class MinecraftProvider extends DependencyProvider {
|
||||
|
||||
public String minecraftVersion;
|
||||
public String pomfVersion;
|
||||
|
||||
public PomfProvider pomfProvider;
|
||||
public MinecraftVersionInfo versionInfo;
|
||||
public MinecraftLibraryProvider libraryProvider;
|
||||
public MinecraftJarProvider jarProvider;
|
||||
|
||||
File MINECRAFT_JSON;
|
||||
File MINECRAFT_CLIENT_JAR;
|
||||
File MINECRAFT_SERVER_JAR;
|
||||
File MINECRAFT_MERGED_JAR;
|
||||
|
||||
Gson gson = new Gson();
|
||||
|
||||
@Override
|
||||
public void provide(DependcyInfo dependency, Project project, LoomGradleExtension extension) throws Exception {
|
||||
minecraftVersion = dependency.getDependency().getName();
|
||||
pomfVersion = dependency.getDependency().getVersion();
|
||||
|
||||
initFiles(project);
|
||||
|
||||
downloadMcJson();
|
||||
versionInfo = gson.fromJson(new FileReader(MINECRAFT_JSON), MinecraftVersionInfo.class);
|
||||
|
||||
downloadJars();
|
||||
|
||||
libraryProvider = new MinecraftLibraryProvider();
|
||||
libraryProvider.provide(this, project);
|
||||
|
||||
//Downloads and setups up pomf
|
||||
pomfProvider = new PomfProvider(pomfVersion, minecraftVersion, project);
|
||||
|
||||
jarProvider = new MinecraftJarProvider(project, this);
|
||||
}
|
||||
|
||||
private void initFiles(Project project) {
|
||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
MINECRAFT_JSON = new File(extension.getUserCache(), minecraftVersion + "-info.jar");
|
||||
MINECRAFT_CLIENT_JAR = new File(extension.getUserCache(), minecraftVersion + "-client.jar");
|
||||
MINECRAFT_SERVER_JAR = new File(extension.getUserCache(), minecraftVersion + "-server.jar");
|
||||
MINECRAFT_MERGED_JAR = new File(extension.getUserCache(), minecraftVersion + "-merged.jar");
|
||||
|
||||
}
|
||||
|
||||
private void downloadMcJson() throws IOException {
|
||||
String versionManifest = IOUtils.toString(new URL("https://launchermeta.mojang.com/mc/game/version_manifest.json"), StandardCharsets.UTF_8);
|
||||
ManifestVersion mcManifest = new GsonBuilder().create().fromJson(versionManifest, ManifestVersion.class);
|
||||
|
||||
Optional<ManifestVersion.Versions> optionalVersion = mcManifest.versions.stream().filter(versions -> versions.id.equalsIgnoreCase(minecraftVersion)).findFirst();
|
||||
if (optionalVersion.isPresent()) {
|
||||
FileUtils.copyURLToFile(new URL(optionalVersion.get().url), MINECRAFT_JSON);
|
||||
} else {
|
||||
throw new RuntimeException("Failed to download minecraft json");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void downloadJars() throws IOException {
|
||||
if (!MINECRAFT_CLIENT_JAR.exists() || !Checksum.equals(MINECRAFT_CLIENT_JAR, versionInfo.downloads.get("client").sha1)) {
|
||||
FileUtils.copyURLToFile(new URL(versionInfo.downloads.get("client").url), MINECRAFT_CLIENT_JAR);
|
||||
}
|
||||
|
||||
if (!MINECRAFT_SERVER_JAR.exists() || !Checksum.equals(MINECRAFT_SERVER_JAR, versionInfo.downloads.get("server").sha1)) {
|
||||
FileUtils.copyURLToFile(new URL(versionInfo.downloads.get("server").url), MINECRAFT_SERVER_JAR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetConfig() {
|
||||
return Constants.MINECRAFT;
|
||||
}
|
||||
}
|
|
@ -22,25 +22,35 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.task;
|
||||
package net.fabricmc.loom.providers;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
import org.zeroturnaround.zip.ZipUtil;
|
||||
import net.fabricmc.loom.util.DependencyProvider;
|
||||
import net.fabricmc.loom.util.ModProcessor;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
public class ExtractNativesTask extends DefaultTask {
|
||||
@TaskAction
|
||||
public void extractNatives() throws FileNotFoundException {
|
||||
LoomGradleExtension extension = getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||
if (!Constants.MINECRAFT_NATIVES.get(extension).exists()) {
|
||||
for (File source : getProject().getConfigurations().getByName(Constants.CONFIG_NATIVES)) {
|
||||
ZipUtil.unpack(source, Constants.MINECRAFT_NATIVES.get(extension));
|
||||
}
|
||||
public class ModRemapperProvider extends DependencyProvider {
|
||||
@Override
|
||||
public void provide(DependcyInfo dependency, Project project, LoomGradleExtension extension) {
|
||||
File input = dependency.resolveFile();
|
||||
|
||||
project.getLogger().lifecycle("Providing " + dependency.getDepString());
|
||||
|
||||
MinecraftProvider minecraftProvider = getDependencyManager().getProvider(MinecraftProvider.class);
|
||||
|
||||
String outputName = input.getName().substring(0, input.getName().length() - 4) + "-mapped-" + minecraftProvider.pomfVersion + ".jar";//TODO use the hash of the input file or something?
|
||||
File output = new File(Constants.REMAPPED_MODS_STORE, outputName);
|
||||
|
||||
ModProcessor.handleMod(input, output, project);
|
||||
|
||||
addDep(output, project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetConfig() {
|
||||
return Constants.COMPILE_MODS;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* 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.providers;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
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.util.zip.GZIPInputStream;
|
||||
|
||||
//TODO fix local mappings
|
||||
//TODO possibly use maven for mappings, can fix above at the same time
|
||||
public class PomfProvider {
|
||||
|
||||
public String minecraftVersion;
|
||||
public String pomfVersion;
|
||||
|
||||
public File POMF_DIR;
|
||||
public File MAPPINGS_TINY_GZ;
|
||||
public File MAPPINGS_TINY;
|
||||
public File MAPPINGS_MIXIN_EXPORT;
|
||||
|
||||
public PomfProvider(String pomfVersion, String minecraftVersion, Project project) {
|
||||
this.pomfVersion = pomfVersion;
|
||||
this.minecraftVersion = minecraftVersion;
|
||||
initFiles(project);
|
||||
try {
|
||||
init(project);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to setup pomf", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void init(Project project) throws IOException {
|
||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
project.getLogger().lifecycle(":setting up pomf " + pomfVersion);
|
||||
|
||||
if (!POMF_DIR.exists()) {
|
||||
POMF_DIR.mkdir();
|
||||
}
|
||||
|
||||
if (!MAPPINGS_TINY_GZ.exists()) {
|
||||
FileUtils.copyURLToFile(
|
||||
new URL(String.format("%1$s%2$s.%3$s/pomf-%2$s.%3$s-tiny.gz", Constants.POMF_MAVEN_SERVER, minecraftVersion, pomfVersion)),
|
||||
MAPPINGS_TINY_GZ);
|
||||
}
|
||||
|
||||
if (!MAPPINGS_TINY.exists()) {
|
||||
GZIPInputStream gzipInputStream = new GZIPInputStream(new FileInputStream(MAPPINGS_TINY_GZ));
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(MAPPINGS_TINY);
|
||||
int length;
|
||||
byte[] buffer = new byte[1024];
|
||||
while ((length = gzipInputStream.read(buffer)) > 0) {
|
||||
fileOutputStream.write(buffer, 0, length);
|
||||
}
|
||||
gzipInputStream.close();
|
||||
fileOutputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void initFiles(Project project) {
|
||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
POMF_DIR = new File(extension.getUserCache(), "pomf");
|
||||
|
||||
MAPPINGS_TINY_GZ = new File(POMF_DIR, "pomf-tiny-" + minecraftVersion + "." + pomfVersion + ".gz");
|
||||
MAPPINGS_TINY = new File(POMF_DIR, "pomf-tiny-" + minecraftVersion + "." + pomfVersion);
|
||||
MAPPINGS_MIXIN_EXPORT = new File(Constants.CACHE_FILES, "mixin-map-" + minecraftVersion + "." + pomfVersion + ".tiny");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,155 +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.task;
|
||||
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.progress.ProgressLogger;
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.tasks.Input;
|
||||
import org.gradle.api.tasks.OutputFile;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
|
||||
/**
|
||||
* Generic Download class compatible with ProgressLogger
|
||||
*/
|
||||
public class DownloadNewTask extends DefaultTask {
|
||||
@Input
|
||||
private Object output;
|
||||
|
||||
@OutputFile
|
||||
private String url;
|
||||
private String taskName;
|
||||
|
||||
@TaskAction
|
||||
public void download() throws IOException {
|
||||
File outputFile = getProject().file(getOutput());
|
||||
outputFile.getParentFile().mkdirs();
|
||||
outputFile.createNewFile();
|
||||
|
||||
getLogger().info("Downloading " + getURL());
|
||||
|
||||
URL url = new URL(getURL());
|
||||
HttpURLConnection connect = (HttpURLConnection) url.openConnection();
|
||||
connect.setRequestProperty("User-Agent", Constants.USER_AGENT);
|
||||
connect.setInstanceFollowRedirects(true);
|
||||
|
||||
ProgressLogger progressLogger = ProgressLogger.getProgressFactory(getProject(), getClass().getName());
|
||||
progressLogger.setDescription("Downloading " + getURL());
|
||||
ReadableByteChannel inChannel = new DownloadChannel(Channels.newChannel(connect.getInputStream()), getContentLength(url), progressLogger);
|
||||
FileChannel outChannel = new FileOutputStream(outputFile).getChannel();
|
||||
outChannel.transferFrom(inChannel, 0, Long.MAX_VALUE);
|
||||
outChannel.close();
|
||||
inChannel.close();
|
||||
progressLogger.completed();
|
||||
getLogger().info("Download complete");
|
||||
}
|
||||
|
||||
private int getContentLength(URL url) {
|
||||
HttpURLConnection connection;
|
||||
int contentLength = -1;
|
||||
try {
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
contentLength = connection.getContentLength();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return contentLength;
|
||||
}
|
||||
|
||||
public File getOutput() {
|
||||
return getProject().file(output);
|
||||
}
|
||||
|
||||
public void setOutput(Object output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
public String getURL() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setURL(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public void setTaskName(String taskName) {
|
||||
this.taskName = taskName;
|
||||
}
|
||||
|
||||
public String getTaskName() {
|
||||
return taskName;
|
||||
}
|
||||
|
||||
class DownloadChannel implements ReadableByteChannel {
|
||||
ProgressLogger logger;
|
||||
String formattedSize;
|
||||
ReadableByteChannel rbc;
|
||||
long totalBytes;
|
||||
|
||||
DownloadChannel(ReadableByteChannel rbc, long expectedSize, ProgressLogger logger) {
|
||||
this.logger = logger;
|
||||
this.formattedSize = toHumanReadableLength(expectedSize);
|
||||
this.rbc = rbc;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
rbc.close();
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return rbc.isOpen();
|
||||
}
|
||||
|
||||
public int read(ByteBuffer buffer) throws IOException {
|
||||
int processedBytes;
|
||||
if ((processedBytes = rbc.read(buffer)) > 0) {
|
||||
totalBytes += processedBytes;
|
||||
logger.progress(toHumanReadableLength(totalBytes) + "/" + formattedSize + " downloaded");
|
||||
}
|
||||
return processedBytes;
|
||||
}
|
||||
|
||||
private String toHumanReadableLength(long bytes) {
|
||||
if (bytes < 1024) {
|
||||
return bytes + " B";
|
||||
} else if (bytes < 1024 * 1024) {
|
||||
return (bytes / 1024) + " KB";
|
||||
} else if (bytes < 1024 * 1024 * 1024) {
|
||||
return String.format("%.2f MB", bytes / (1024.0 * 1024.0));
|
||||
} else {
|
||||
return String.format("%.2f GB", bytes / (1024.0 * 1024.0 * 1024.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,247 +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.task;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Checksum;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.ManifestVersion;
|
||||
import net.fabricmc.loom.util.Version;
|
||||
import net.fabricmc.loom.util.assets.AssetIndex;
|
||||
import net.fabricmc.loom.util.assets.AssetObject;
|
||||
import net.fabricmc.loom.util.progress.ProgressLogger;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.dsl.DependencyHandler;
|
||||
import org.gradle.api.logging.Logger;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class DownloadTask extends DefaultTask {
|
||||
@TaskAction
|
||||
public void download() {
|
||||
try {
|
||||
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||
|
||||
downloadMcJson(extension, getLogger());
|
||||
|
||||
Gson gson = new Gson();
|
||||
Version version = gson.fromJson(new FileReader(Constants.MINECRAFT_JSON.get(extension)), Version.class);
|
||||
|
||||
if (!Constants.MINECRAFT_CLIENT_JAR.get(extension).exists() || !Checksum.equals(Constants.MINECRAFT_CLIENT_JAR.get(extension), version.downloads.get("client").sha1)) {
|
||||
this.getLogger().lifecycle(":downloading client");
|
||||
FileUtils.copyURLToFile(new URL(version.downloads.get("client").url), Constants.MINECRAFT_CLIENT_JAR.get(extension));
|
||||
}
|
||||
|
||||
if (!Constants.MINECRAFT_SERVER_JAR.get(extension).exists() || !Checksum.equals(Constants.MINECRAFT_SERVER_JAR.get(extension), version.downloads.get("server").sha1)) {
|
||||
this.getLogger().lifecycle(":downloading server");
|
||||
FileUtils.copyURLToFile(new URL(version.downloads.get("server").url), Constants.MINECRAFT_SERVER_JAR.get(extension));
|
||||
}
|
||||
|
||||
if (!Constants.POMF_DIR.get(extension).exists()) {
|
||||
Constants.POMF_DIR.get(extension).mkdir();
|
||||
}
|
||||
|
||||
if (Constants.JAR_MAPPER_ENIGMA.equals(extension.jarMapper)) {
|
||||
if (!Constants.MAPPINGS_ENIGMA_ZIP.get(extension).exists() && extension.hasPomf()) {
|
||||
this.getLogger().lifecycle(":downloading enigma mappings");
|
||||
try {
|
||||
FileUtils.copyURLToFile(
|
||||
new URL(String.format("%1$s%2$s.%3$s/pomf-%2$s.%3$s-engima.zip", Constants.POMF_MAVEN_SERVER, extension.version, extension.pomfVersion)),
|
||||
Constants.MAPPINGS_ENIGMA_ZIP.get(extension)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to download mappings", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!extension.hasPomf()) {
|
||||
if (Constants.MAPPINGS_DIR_LOCAL.get(extension).exists()) {
|
||||
if (Constants.MAPPINGS_TINY_GZ_LOCAL.get(extension).exists() && (!Constants.JAR_MAPPER_ENIGMA.equals(extension.jarMapper) || Constants.MAPPINGS_ENIGMA_ZIP_LOCAL.get(extension).exists())) {
|
||||
this.getLogger().lifecycle(":using local mappings!");
|
||||
extension.localMappings = true;
|
||||
|
||||
//We delete this to make sure they are always re extracted.
|
||||
deleteIfExists(Constants.MAPPINGS_ENIGMA_DIR.get(extension));
|
||||
deleteIfExists(Constants.MAPPINGS_ENIGMA_ZIP.get(extension));
|
||||
deleteIfExists(Constants.MAPPINGS_TINY_GZ.get(extension));
|
||||
deleteIfExists(Constants.MAPPINGS_TINY.get(extension));
|
||||
|
||||
Constants.MAPPINGS_TINY_GZ = Constants.MAPPINGS_TINY_GZ_LOCAL;
|
||||
Constants.MAPPINGS_ENIGMA_ZIP = Constants.MAPPINGS_ENIGMA_ZIP_LOCAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!Constants.MAPPINGS_TINY.get(extension).exists() && extension.hasPomf()) {
|
||||
if (!Constants.MAPPINGS_TINY_GZ.get(extension).exists() && !extension.localMappings) {
|
||||
getLogger().lifecycle(":downloading tiny mappings");
|
||||
try {
|
||||
FileUtils.copyURLToFile(new URL(String.format("%1$s%2$s.%3$s/pomf-%2$s.%3$s-tiny.gz", Constants.POMF_MAVEN_SERVER, extension.version, extension.pomfVersion)), Constants.MAPPINGS_TINY_GZ.get(extension));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to download mappings", e);
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
DependencyHandler dependencyHandler = getProject().getDependencies();
|
||||
|
||||
if (getProject().getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).getState() == Configuration.State.UNRESOLVED) {
|
||||
for (Version.Library library : version.libraries) {
|
||||
if (library.allowed() && library.getFile(extension) != null) {
|
||||
// By default, they are all available on all sides
|
||||
String configName = Constants.CONFIG_MC_DEPENDENCIES;
|
||||
if (library.name.contains("java3d") || library.name.contains("paulscode") || library.name.contains("lwjgl") || library.name.contains("twitch") || library.name.contains("jinput") || library.name.contains("text2speech") || library.name.contains("objc")) {
|
||||
configName = Constants.CONFIG_MC_DEPENDENCIES_CLIENT;
|
||||
}
|
||||
dependencyHandler.add(configName, library.getArtifactName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (getProject().getConfigurations().getByName(Constants.CONFIG_NATIVES).getState() == Configuration.State.UNRESOLVED) {
|
||||
version.libraries.stream().filter(lib -> lib.natives != null).forEach(lib -> dependencyHandler.add(Constants.CONFIG_NATIVES, lib.getArtifactName()));
|
||||
}
|
||||
|
||||
Version.AssetIndex assetIndex = version.assetIndex;
|
||||
|
||||
// get existing cache files
|
||||
this.getLogger().lifecycle(":checking for existing asset files");
|
||||
Multimap<String, File> assetFilenameToFile = HashMultimap.create();
|
||||
for (File assetDir : Objects.requireNonNull(extension.getUserCache().listFiles((f) -> f.isDirectory() && f.getName().startsWith("assets-")))) {
|
||||
File objectsDir = new File(assetDir, "objects");
|
||||
if (objectsDir.exists() && objectsDir.isDirectory()) {
|
||||
for (File subDir : Objects.requireNonNull(objectsDir.listFiles(File::isDirectory))) {
|
||||
for (File subFile : Objects.requireNonNull(subDir.listFiles(File::isFile))) {
|
||||
assetFilenameToFile.put("objects" + File.separator + subDir.getName() + File.separator + subFile.getName(), subFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File assets = new File(extension.getUserCache(), "assets-" + extension.version);
|
||||
if (!assets.exists()) {
|
||||
assets.mkdirs();
|
||||
}
|
||||
|
||||
File assetsInfo = new File(assets, "indexes" + File.separator + assetIndex.id + ".json");
|
||||
if (!assetsInfo.exists() || !Checksum.equals(assetsInfo, assetIndex.sha1)) {
|
||||
this.getLogger().lifecycle(":downloading asset index");
|
||||
FileUtils.copyURLToFile(new URL(assetIndex.url), assetsInfo);
|
||||
}
|
||||
|
||||
ProgressLogger progressLogger = ProgressLogger.getProgressFactory(getProject(), getClass().getName());
|
||||
progressLogger.start("Downloading assets...", "assets");
|
||||
AssetIndex index = new Gson().fromJson(new FileReader(assetsInfo), AssetIndex.class);
|
||||
Map<String, AssetObject> parent = index.getFileMap();
|
||||
final int totalSize = parent.size();
|
||||
int position = 0;
|
||||
this.getLogger().lifecycle(":downloading assets...");
|
||||
for (Map.Entry<String, AssetObject> entry : parent.entrySet()) {
|
||||
AssetObject object = entry.getValue();
|
||||
String sha1 = object.getHash();
|
||||
String filename = "objects" + File.separator + sha1.substring(0, 2) + File.separator + sha1;
|
||||
File file = new File(assets, filename);
|
||||
if (!file.exists() && assetFilenameToFile.containsKey(filename)) {
|
||||
this.getLogger().debug(":copying asset " + entry.getKey());
|
||||
for (File srcFile : assetFilenameToFile.get(filename)) {
|
||||
if (Checksum.equals(srcFile, sha1)) {
|
||||
FileUtils.copyFile(srcFile, file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!file.exists() || !Checksum.equals(file, sha1)) {
|
||||
this.getLogger().debug(":downloading asset " + entry.getKey());
|
||||
FileUtils.copyURLToFile(new URL(Constants.RESOURCES_BASE + sha1.substring(0, 2) + "/" + sha1), file);
|
||||
}
|
||||
String assetName = entry.getKey();
|
||||
int end = assetName.lastIndexOf("/") + 1;
|
||||
if (end > 0) {
|
||||
assetName = assetName.substring(end);
|
||||
}
|
||||
progressLogger.progress(assetName + " - " + position + "/" + totalSize + " (" + (int) ((position / (double) totalSize) * 100) + "%) assets downloaded");
|
||||
position++;
|
||||
}
|
||||
progressLogger.completed();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void downloadMcJson(LoomGradleExtension extension, Logger logger) throws IOException {
|
||||
if (!Constants.MINECRAFT_JSON.get(extension).exists()) {
|
||||
logger.lifecycle(":downloading minecraft json");
|
||||
FileUtils.copyURLToFile(new URL("https://launchermeta.mojang.com/mc/game/version_manifest.json"), Constants.VERSION_MANIFEST.get(extension));
|
||||
ManifestVersion mcManifest = new GsonBuilder().create().fromJson(FileUtils.readFileToString(Constants.VERSION_MANIFEST.get(extension), "UTF-8"), ManifestVersion.class);
|
||||
|
||||
Optional<ManifestVersion.Versions> optionalVersion = mcManifest.versions.stream().filter(versions -> versions.id.equalsIgnoreCase(extension.version)).findFirst();
|
||||
if (optionalVersion.isPresent()) {
|
||||
FileUtils.copyURLToFile(new URL(optionalVersion.get().url), Constants.MINECRAFT_JSON.get(extension));
|
||||
} else {
|
||||
logger.info(":failed downloading minecraft json");
|
||||
throw new RuntimeException("Failed downloading Minecraft json");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean deleteIfExists(File file) {
|
||||
if (file.exists()) {
|
||||
if (file.isDirectory()) {
|
||||
try {
|
||||
FileUtils.deleteDirectory(file);
|
||||
return file.mkdir();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return file.delete();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -26,9 +26,10 @@ package net.fabricmc.loom.task;
|
|||
|
||||
import com.google.gson.Gson;
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.providers.MinecraftProvider;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.IdeaRunConfig;
|
||||
import net.fabricmc.loom.util.Version;
|
||||
import net.fabricmc.loom.util.MinecraftVersionInfo;
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
@ -104,7 +105,8 @@ public class GenIdeaProjectTask extends DefaultTask {
|
|||
|
||||
Gson gson = new Gson();
|
||||
|
||||
Version version = gson.fromJson(new FileReader(Constants.MINECRAFT_JSON.get(extension)), Version.class);
|
||||
MinecraftProvider minecraftProvider = extension.getDependencyManager().getProvider(MinecraftProvider.class);
|
||||
MinecraftVersionInfo minecraftVersionInfo = minecraftProvider.versionInfo;
|
||||
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
|
@ -139,8 +141,8 @@ public class GenIdeaProjectTask extends DefaultTask {
|
|||
ideaClient.projectName = project.getName();
|
||||
ideaClient.configName = "Minecraft Client";
|
||||
ideaClient.runDir = "file://$PROJECT_DIR$/" + extension.runDir;
|
||||
ideaClient.vmArgs = "-Djava.library.path=" + Constants.MINECRAFT_NATIVES.get(extension).getAbsolutePath() + " -Dfabric.development=true";
|
||||
ideaClient.programArgs = "--tweakClass " + Constants.FABRIC_CLIENT_TWEAKER + " --assetIndex " + version.assetIndex.id + " --assetsDir \"" + new File(extension.getUserCache(), "assets-" + extension.version).getAbsolutePath() + "\" --fabricMappingFile \"" + Constants.MAPPINGS_TINY.get(extension).getAbsolutePath() + "\"";
|
||||
ideaClient.vmArgs = "-Djava.library.path=" + extension.getMinecraftProvider().libraryProvider.MINECRAFT_NATIVES.getAbsolutePath() + " -Dfabric.development=true";
|
||||
ideaClient.programArgs = "--tweakClass " + Constants.FABRIC_CLIENT_TWEAKER + " --assetIndex " + minecraftVersionInfo.assetIndex.id + " --assetsDir \"" + new File(extension.getUserCache(), "assets-" + minecraftProvider.minecraftVersion).getAbsolutePath() + "\" --fabricMappingFile \"" + minecraftProvider.pomfProvider.MAPPINGS_TINY.getAbsolutePath() + "\"";
|
||||
|
||||
runManager.appendChild(ideaClient.genRuns(runManager));
|
||||
|
||||
|
@ -150,7 +152,7 @@ public class GenIdeaProjectTask extends DefaultTask {
|
|||
ideaServer.configName = "Minecraft Server";
|
||||
ideaServer.runDir = "file://$PROJECT_DIR$/" + extension.runDir;
|
||||
ideaServer.vmArgs = "-Dfabric.development=true";
|
||||
ideaServer.programArgs = "--tweakClass " + Constants.FABRIC_SERVER_TWEAKER + " --fabricMappingFile \"" + Constants.MAPPINGS_TINY.get(extension).getAbsolutePath() + "\"";
|
||||
ideaServer.programArgs = "--tweakClass " + Constants.FABRIC_SERVER_TWEAKER + " --fabricMappingFile \"" + minecraftProvider.pomfProvider.MAPPINGS_TINY.getAbsolutePath() + "\"";
|
||||
|
||||
runManager.appendChild(ideaServer.genRuns(runManager));
|
||||
|
||||
|
|
|
@ -1,82 +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.task;
|
||||
|
||||
import com.google.gson.*;
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.Version;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Install https://marketplace.visualstudio.com/items?itemName=georgewfraser.vscode-javac into vscode
|
||||
*/
|
||||
public class GenVSCodeProjectTask extends DefaultTask {
|
||||
|
||||
@TaskAction
|
||||
public void genVsCodeProject() throws IOException {
|
||||
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||
File classPathFile = new File("vscodeClasspath.txt");
|
||||
File configFile = new File("javaconfig.json");
|
||||
|
||||
Gson gson = new Gson();
|
||||
Version version = gson.fromJson(new FileReader(Constants.MINECRAFT_JSON.get(extension)), Version.class);
|
||||
|
||||
List<String> libs = new ArrayList<>();
|
||||
for (Version.Library library : version.libraries) {
|
||||
if (library.allowed() && library.getFile(extension) != null && library.getFile(extension).exists()) {
|
||||
libs.add(library.getFile(extension).getAbsolutePath());
|
||||
}
|
||||
}
|
||||
libs.add(Constants.MINECRAFT_FINAL_JAR.get(extension).getAbsolutePath());
|
||||
for (File file : getProject().getConfigurations().getByName("compile").getFiles()) {
|
||||
libs.add(file.getAbsolutePath());
|
||||
}
|
||||
FileUtils.writeLines(classPathFile, libs);
|
||||
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
jsonArray.add("src/main/java");
|
||||
jsonArray.add("src/main/resources");
|
||||
jsonArray.add("src/test/java");
|
||||
jsonArray.add("src/test/resources");
|
||||
jsonObject.add("sourcePath", jsonArray);
|
||||
JsonElement element = new JsonPrimitive(classPathFile.getName());
|
||||
jsonObject.add("classPathFile", element);
|
||||
element = new JsonPrimitive("vscode");
|
||||
jsonObject.add("outputDirectory", element);
|
||||
|
||||
FileUtils.writeStringToFile(configFile, gson.toJson(jsonObject), "UTF-8");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,38 +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.task;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.delayed.IDelayed;
|
||||
import org.gradle.api.DefaultTask;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class LoomBaseTask extends DefaultTask {
|
||||
protected final File getFile(IDelayed<File> file) {
|
||||
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||
return file.get(extension);
|
||||
}
|
||||
}
|
|
@ -1,122 +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.task;
|
||||
|
||||
|
||||
/* import cuchaz.enigma.Deobfuscator;
|
||||
import cuchaz.enigma.TranslatingTypeLoader;
|
||||
import cuchaz.enigma.mapping.MappingsEnigmaReader;
|
||||
import cuchaz.enigma.mapping.TranslationDirection;
|
||||
import cuchaz.enigma.mapping.Translator;
|
||||
import cuchaz.enigma.mapping.entry.ReferencedEntryPool;
|
||||
import cuchaz.enigma.throwables.MappingParseException; */
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
import net.fabricmc.tinyremapper.TinyUtils;
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
import org.zeroturnaround.zip.ZipUtil;
|
||||
import org.zeroturnaround.zip.commons.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
public class MapJarsEnigma {
|
||||
public void mapJars(MapJarsTask task) {
|
||||
throw new RuntimeException("Currently unsupported!");
|
||||
}
|
||||
|
||||
/* Deobfuscator deobfuscator;
|
||||
|
||||
public void mapJars(MapJarsTask task) throws IOException, MappingParseException {
|
||||
LoomGradleExtension extension = task.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||
if (!Constants.MINECRAFT_MAPPED_JAR.get(extension).exists() || extension.localMappings || true) {
|
||||
if(Constants.MINECRAFT_MAPPED_JAR.get(extension).exists()){
|
||||
Constants.MINECRAFT_MAPPED_JAR.get(extension).delete();
|
||||
}
|
||||
|
||||
if (!extension.hasPomf()) {
|
||||
task.getLogger().lifecycle("POMF version not set, skipping mapping!");
|
||||
FileUtils.copyFile(Constants.MINECRAFT_MERGED_JAR.get(extension), Constants.MINECRAFT_MAPPED_JAR.get(extension));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Constants.MAPPINGS_ENIGMA_DIR.get(extension).exists() || extension.localMappings) {
|
||||
task.getLogger().lifecycle(":unpacking mappings");
|
||||
FileUtils.deleteDirectory(Constants.MAPPINGS_ENIGMA_DIR.get(extension));
|
||||
ZipUtil.unpack(Constants.MAPPINGS_ENIGMA_ZIP.get(extension), Constants.MAPPINGS_ENIGMA_DIR.get(extension));
|
||||
}
|
||||
|
||||
task.getLogger().lifecycle(":remapping jar (Enigma)");
|
||||
deobfuscator = new Deobfuscator(new JarFile(Constants.MINECRAFT_MERGED_JAR.get(extension)));
|
||||
deobfuscator.setMappings(new MappingsEnigmaReader().read(Constants.MAPPINGS_ENIGMA_DIR.get(extension)));
|
||||
writeJar(Constants.MINECRAFT_PARTIAL_ENIGMA_JAR.get(extension), new ProgressListener(), deobfuscator);
|
||||
|
||||
File tempAssets = new File(Constants.CACHE_FILES, "tempAssets");
|
||||
if (tempAssets.exists()) {
|
||||
FileUtils.deleteDirectory(tempAssets);
|
||||
}
|
||||
tempAssets.mkdir();
|
||||
|
||||
ZipUtil.unpack(Constants.MINECRAFT_CLIENT_JAR.get(extension), tempAssets, name -> {
|
||||
if (!name.endsWith(".class") && !name.startsWith("META-INF")) {
|
||||
return name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
ZipUtil.unpack(Constants.MINECRAFT_PARTIAL_ENIGMA_JAR.get(extension), tempAssets);
|
||||
|
||||
ZipUtil.pack(tempAssets, Constants.MINECRAFT_MAPPED_JAR.get(extension));
|
||||
FileUtils.deleteDirectory(tempAssets);
|
||||
} else {
|
||||
task.getLogger().lifecycle(Constants.MINECRAFT_MAPPED_JAR.get(extension).getAbsolutePath());
|
||||
task.getLogger().lifecycle(":mapped jar found, skipping mapping");
|
||||
}
|
||||
}
|
||||
|
||||
public void writeJar(File out, Deobfuscator.ProgressListener progress, Deobfuscator deobfuscator) {
|
||||
Translator obfuscationTranslator = deobfuscator.getTranslator(TranslationDirection.OBFUSCATING);
|
||||
Translator deobfuscationTranslator = deobfuscator.getTranslator(TranslationDirection.DEOBFUSCATING);
|
||||
TranslatingTypeLoader loader = new TranslatingTypeLoader(deobfuscator.getJar(), deobfuscator.getJarIndex(), new ReferencedEntryPool(), obfuscationTranslator, deobfuscationTranslator);
|
||||
deobfuscator.transformJar(out, progress, loader::transformInto);
|
||||
}
|
||||
|
||||
public static class ProgressListener implements Deobfuscator.ProgressListener {
|
||||
@Override
|
||||
public void init(int i, String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(int i, String s) {
|
||||
|
||||
}
|
||||
} */
|
||||
}
|
|
@ -1,107 +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.task;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.tasks.*;
|
||||
import org.zeroturnaround.zip.commons.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
public class MapJarsTask extends LoomBaseTask {
|
||||
@InputFiles
|
||||
@Classpath
|
||||
public Collection<File> getMapperPaths() {
|
||||
return this.getProject().getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).getFiles();
|
||||
}
|
||||
|
||||
@InputFile
|
||||
public File getMappingFile() {
|
||||
return getFile(Constants.MAPPINGS_TINY);
|
||||
}
|
||||
|
||||
@InputFile
|
||||
public File getInputJar() {
|
||||
return getFile(Constants.MINECRAFT_MERGED_JAR);
|
||||
}
|
||||
|
||||
@OutputFile
|
||||
public File getIntermediaryJar() {
|
||||
return getFile(Constants.MINECRAFT_INTERMEDIARY_JAR);
|
||||
}
|
||||
|
||||
@OutputFile
|
||||
public File getMappedJar() {
|
||||
return getFile(Constants.MINECRAFT_MAPPED_JAR);
|
||||
}
|
||||
|
||||
@Input
|
||||
public boolean localMappings() {
|
||||
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||
return extension.localMappings;
|
||||
}
|
||||
|
||||
@Input
|
||||
public String pomfVersion() {
|
||||
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||
return extension.pomfVersion;
|
||||
}
|
||||
|
||||
@Input
|
||||
public String jarMapper() {
|
||||
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||
return extension.jarMapper;
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
public void mapJars() throws Exception {
|
||||
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||
|
||||
if (getMappedJar().exists()) {
|
||||
getMappedJar().delete();
|
||||
}
|
||||
|
||||
if (getIntermediaryJar().exists()) {
|
||||
getIntermediaryJar().delete();
|
||||
}
|
||||
|
||||
if (!extension.hasPomf()) {
|
||||
this.getLogger().lifecycle("Mapping version not set, skipping mapping!");
|
||||
FileUtils.copyFile(Constants.MINECRAFT_MERGED_JAR.get(extension), getMappedJar());
|
||||
return;
|
||||
}
|
||||
|
||||
if (Constants.JAR_MAPPER_ENIGMA.equals(jarMapper())) {
|
||||
new MapJarsEnigma().mapJars(this);
|
||||
} else if (Constants.JAR_MAPPER_TINY.equals(jarMapper())) {
|
||||
new MapJarsTiny().mapJars(this);
|
||||
} else {
|
||||
throw new RuntimeException("Unknown JAR mapper type: " + jarMapper());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,74 +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.task;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.delayed.IDelayed;
|
||||
import net.fabricmc.stitch.merge.JarMerger;
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.tasks.InputFile;
|
||||
import org.gradle.api.tasks.OutputFile;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MergeJarsTask extends LoomBaseTask {
|
||||
@InputFile
|
||||
public File getClientJar() {
|
||||
return getFile(Constants.MINECRAFT_CLIENT_JAR);
|
||||
}
|
||||
|
||||
@InputFile
|
||||
public File getServerJar() {
|
||||
return getFile(Constants.MINECRAFT_SERVER_JAR);
|
||||
}
|
||||
|
||||
@OutputFile
|
||||
public File getMergedJar() {
|
||||
return getFile(Constants.MINECRAFT_MERGED_JAR);
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
public void mergeJars() throws IOException {
|
||||
this.getLogger().lifecycle(":merging jars");
|
||||
FileInputStream client = new FileInputStream(getClientJar());
|
||||
FileInputStream server = new FileInputStream(getServerJar());
|
||||
FileOutputStream merged = new FileOutputStream(getMergedJar());
|
||||
|
||||
JarMerger jarMerger = new JarMerger(client, server, merged);
|
||||
|
||||
jarMerger.merge();
|
||||
jarMerger.close();
|
||||
|
||||
client.close();
|
||||
server.close();
|
||||
merged.close();
|
||||
}
|
||||
|
||||
}
|
|
@ -24,15 +24,12 @@
|
|||
|
||||
package net.fabricmc.loom.task;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.Version;
|
||||
import net.fabricmc.loom.util.MinecraftVersionInfo;
|
||||
import org.gradle.api.tasks.JavaExec;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -41,35 +38,22 @@ public class RunClientTask extends JavaExec {
|
|||
@Override
|
||||
public void exec() {
|
||||
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||
Gson gson = new Gson();
|
||||
Version version = null;
|
||||
try {
|
||||
version = gson.fromJson(new FileReader(Constants.MINECRAFT_JSON.get(extension)), Version.class);
|
||||
} catch (FileNotFoundException e) {
|
||||
getLogger().error("Failed to retrieve version from minecraft json", e);
|
||||
}
|
||||
MinecraftVersionInfo minecraftVersionInfo = extension.getMinecraftProvider().versionInfo;
|
||||
|
||||
|
||||
List<String> libs = new ArrayList<>();
|
||||
for (File file : getProject().getConfigurations().getByName("compile").getFiles()) {
|
||||
libs.add(file.getAbsolutePath());
|
||||
}
|
||||
for (File file : getProject().getConfigurations().getByName(Constants.CONFIG_MINECRAFT).getFiles()) {
|
||||
libs.add(file.getAbsolutePath());
|
||||
}
|
||||
//Used to add the fabric jar that has been built
|
||||
for (File file : new File(getProject().getBuildDir(), "libs").listFiles()) {
|
||||
if (file.isFile()) {
|
||||
libs.add(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
libs.add(Constants.MINECRAFT_CLIENT_JAR.get(extension).getAbsolutePath());
|
||||
|
||||
//Removes the deobf jars
|
||||
libs.removeIf(s -> s.contains(Constants.MINECRAFT_FINAL_JAR.get(extension).getName()));
|
||||
|
||||
classpath(libs);
|
||||
|
||||
args("--tweakClass", Constants.FABRIC_CLIENT_TWEAKER, "--assetIndex", version.assetIndex.id, "--assetsDir", new File(extension.getUserCache(), "assets-" + extension.version).getAbsolutePath(), "--fabricMappingFile", Constants.MAPPINGS_TINY.get(extension).getAbsolutePath());
|
||||
args("--tweakClass", Constants.FABRIC_CLIENT_TWEAKER, "--assetIndex", minecraftVersionInfo.assetIndex.id, "--assetsDir", new File(extension.getUserCache(), "assets-" + extension.getMinecraftProvider().minecraftVersion).getAbsolutePath(), "--fabricMappingFile", extension.getMinecraftProvider().pomfProvider.MAPPINGS_TINY.getAbsolutePath());
|
||||
|
||||
setWorkingDir(new File(getProject().getRootDir(), "run"));
|
||||
|
||||
|
@ -93,7 +77,7 @@ public class RunClientTask extends JavaExec {
|
|||
public List<String> getJvmArgs() {
|
||||
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||
List<String> args = new ArrayList<>();
|
||||
args.add("-Djava.library.path=" + Constants.MINECRAFT_NATIVES.get(extension).getAbsolutePath());
|
||||
args.add("-Djava.library.path=" + extension.getMinecraftProvider().libraryProvider.MINECRAFT_NATIVES.getAbsolutePath());
|
||||
//args.add("-XstartOnFirstThread"); //Fixes lwjgl starting on an incorrect thread
|
||||
return args;
|
||||
}
|
||||
|
|
|
@ -24,15 +24,11 @@
|
|||
|
||||
package net.fabricmc.loom.task;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.Version;
|
||||
import org.gradle.api.tasks.JavaExec;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -41,31 +37,20 @@ public class RunServerTask extends JavaExec {
|
|||
@Override
|
||||
public void exec() {
|
||||
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||
Gson gson = new Gson();
|
||||
Version version = null;
|
||||
try {
|
||||
version = gson.fromJson(new FileReader(Constants.MINECRAFT_JSON.get(extension)), Version.class);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
List<String> libs = new ArrayList<>();
|
||||
for (File file : getProject().getConfigurations().getByName("compile").getFiles()) {
|
||||
libs.add(file.getAbsolutePath());
|
||||
}
|
||||
for (File file : getProject().getConfigurations().getByName(Constants.CONFIG_MINECRAFT).getFiles()) {
|
||||
libs.add(file.getAbsolutePath());
|
||||
}
|
||||
//Used to add the fabric jar that has been built
|
||||
for (File file : new File(getProject().getBuildDir(), "libs").listFiles()) {
|
||||
if (file.isFile()) {
|
||||
libs.add(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
libs.add(Constants.MINECRAFT_FINAL_JAR.get(extension).getAbsolutePath());
|
||||
classpath(libs);
|
||||
|
||||
args("--tweakClass", Constants.FABRIC_SERVER_TWEAKER, "--fabricMappingFile", Constants.MAPPINGS_TINY.get(extension).getAbsolutePath());
|
||||
args("--tweakClass", Constants.FABRIC_SERVER_TWEAKER, "--fabricMappingFile", extension.getMinecraftProvider().pomfProvider.MAPPINGS_TINY.getAbsolutePath());
|
||||
|
||||
setWorkingDir(new File(getProject().getRootDir(), "run"));
|
||||
|
||||
|
@ -89,7 +74,6 @@ public class RunServerTask extends JavaExec {
|
|||
public List<String> getJvmArgs() {
|
||||
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||
List<String> args = new ArrayList<>();
|
||||
args.add("-Djava.library.path=" + Constants.MINECRAFT_NATIVES.get(extension).getAbsolutePath());
|
||||
args.add("-Dfabric.development=true");
|
||||
return args;
|
||||
}
|
||||
|
|
|
@ -1,62 +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.task;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.ModProcessor;
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SetupTask extends DefaultTask {
|
||||
|
||||
@TaskAction
|
||||
public void setup(){
|
||||
configureModRemapper();
|
||||
}
|
||||
|
||||
public void configureModRemapper(){
|
||||
LoomGradleExtension extension = getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||
Configuration inputConfig = getProject().getConfigurations().getByName(Constants.COMPILE_MODS);
|
||||
|
||||
inputConfig.getResolvedConfiguration().getFiles().stream()
|
||||
.filter(file -> file.getName().endsWith(".jar"))
|
||||
.forEach(input -> {
|
||||
String outputName = input.getName().substring(0, input.getName().length() - 4) + "-mapped-" + extension.pomfVersion + ".jar";//TODO use the hash of the input file or something?
|
||||
File output = new File(Constants.REMAPPED_MODS_STORE.get(extension), outputName);
|
||||
if(!output.getParentFile().exists()){
|
||||
output.mkdirs();
|
||||
}
|
||||
ModProcessor.handleMod(input, output, getProject());
|
||||
if (!output.exists()) {
|
||||
throw new RuntimeException("Output does not exist!");
|
||||
}
|
||||
getProject().getDependencies().add(Constants.CONFIG_MINECRAFT, getProject().files(output.getPath()));
|
||||
});
|
||||
}
|
||||
}
|
|
@ -24,49 +24,14 @@
|
|||
|
||||
package net.fabricmc.loom.util;
|
||||
|
||||
import net.fabricmc.loom.util.delayed.DelayedFile;
|
||||
import net.fabricmc.loom.util.delayed.IDelayed;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Constants {
|
||||
public static final File WORKING_DIRECTORY = new File(".");
|
||||
public static final File CACHE_FILES = new File(WORKING_DIRECTORY, ".gradle/minecraft");
|
||||
|
||||
public static final String JAR_MAPPER_ENIGMA = "enigma";
|
||||
public static final String JAR_MAPPER_TINY = "tiny";
|
||||
public static final File REMAPPED_MODS_STORE = new File(CACHE_FILES, "remapped_mods");
|
||||
|
||||
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_MAPPED_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-mapped-" + extension.pomfVersion + ".jar"));
|
||||
public static final IDelayed<File> MINECRAFT_INTERMEDIARY_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-intermediary.jar"));
|
||||
// public static final IDelayed<File> MINECRAFT_PARTIAL_ENIGMA_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-partial-enigma-" + extension.pomfVersion + ".jar"));
|
||||
// public static final IDelayed<File> MINECRAFT_FINAL_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.version + "-final-" + extension.pomfVersion + ".jar"));
|
||||
public static final IDelayed<File> MINECRAFT_FINAL_JAR = MINECRAFT_MAPPED_JAR;
|
||||
|
||||
public static final IDelayed<File> POMF_DIR = new DelayedFile(extension -> new File(extension.getUserCache(), "pomf"));
|
||||
public static 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> MAPPINGS_MIXIN_EXPORT = new DelayedFile(extension -> new File(CACHE_FILES, "mixin-map-" + extension.version + "." + extension.pomfVersion + ".tiny"));
|
||||
public static IDelayed<File> MAPPINGS_ENIGMA_ZIP = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-enigma-" + extension.version + "." + extension.pomfVersion + ".zip"));
|
||||
public static final IDelayed<File> MAPPINGS_ENIGMA_DIR = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-enigma-" + extension.version + "." + extension.pomfVersion + ""));
|
||||
|
||||
public static final IDelayed<File> MAPPINGS_DIR_LOCAL = new DelayedFile(extension -> new File(WORKING_DIRECTORY, "mappings"));
|
||||
public static final IDelayed<File> MAPPINGS_ENIGMA_ZIP_LOCAL = new DelayedFile(extension -> new File(MAPPINGS_DIR_LOCAL.get(extension), "pomf-enigma-" + extension.version + ".zip"));
|
||||
public static final IDelayed<File> MAPPINGS_TINY_GZ_LOCAL = new DelayedFile(extension -> new File(MAPPINGS_DIR_LOCAL.get(extension), "pomf-tiny-" + extension.version + ".gz"));
|
||||
|
||||
public static final IDelayed<File> REMAPPED_MODS_STORE = new DelayedFile(extension -> new File(CACHE_FILES, "remapped_mods"));
|
||||
|
||||
public static final IDelayed<File> MINECRAFT_LIBS = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-libs"));
|
||||
public static final IDelayed<File> MINECRAFT_NATIVES = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-natives"));
|
||||
public static final IDelayed<File> MINECRAFT_JSON = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-info.json"));
|
||||
|
||||
public static final IDelayed<File> VERSION_MANIFEST = new DelayedFile(extension -> new File(extension.getUserCache(), "version_manifest.json"));
|
||||
|
||||
public static final String FABRIC_CLIENT_TWEAKER = "net.fabricmc.loader.launch.FabricClientTweaker";
|
||||
public static final String FABRIC_SERVER_TWEAKER = "net.fabricmc.loader.launch.FabricServerTweaker";
|
||||
|
@ -75,21 +40,8 @@ public class Constants {
|
|||
public static final String LIBRARIES_BASE = "https://libraries.minecraft.net/";
|
||||
public static final String RESOURCES_BASE = "http://resources.download.minecraft.net/";
|
||||
|
||||
public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11";
|
||||
|
||||
public static final String CONFIG_NATIVES = "MC_NATIVES";
|
||||
public static final String CONFIG_MC_DEPENDENCIES = "MC_DEPENDENCIES";
|
||||
public static final String CONFIG_MINECRAFT = "MINECRAFT";
|
||||
public static final String CONFIG_MC_DEPENDENCIES_CLIENT = "MC_DEPENDENCIES_CLIENT";
|
||||
public static final String SYSTEM_ARCH = System.getProperty("os.arch").equals("64") ? "64" : "32";
|
||||
public static final String COMPILE_MODS = "modCompile";
|
||||
|
||||
public static List<String> getClassPath() {
|
||||
URL[] urls = ((URLClassLoader) Constants.class.getClassLoader()).getURLs();
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
for (URL url : urls) {
|
||||
list.add(url.getPath());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
public static final String COMPILE_MODS = "modCompile";
|
||||
public static final String MINECRAFT = "minecraft";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.Dependency;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class DependencyProvider {
|
||||
|
||||
private LoomDependencyManager dependencyManager;
|
||||
|
||||
public abstract void provide(DependcyInfo dependency, Project project, LoomGradleExtension extension) throws Exception;
|
||||
|
||||
public abstract String getTargetConfig();
|
||||
|
||||
public void addDep(Object object, Project project){
|
||||
if(object instanceof File){
|
||||
object = project.files(object);
|
||||
}
|
||||
project.getDependencies().add("compile", object);
|
||||
}
|
||||
|
||||
public void register(LoomDependencyManager dependencyManager){
|
||||
this.dependencyManager = dependencyManager;
|
||||
}
|
||||
|
||||
public LoomDependencyManager getDependencyManager() {
|
||||
return dependencyManager;
|
||||
}
|
||||
|
||||
public static class DependcyInfo {
|
||||
final Dependency dependency;
|
||||
final Configuration sourceConfiguration;
|
||||
|
||||
public DependcyInfo(Dependency dependency, Configuration sourceConfiguration) {
|
||||
this.dependency = dependency;
|
||||
this.sourceConfiguration = sourceConfiguration;
|
||||
}
|
||||
|
||||
public Dependency getDependency() {
|
||||
return dependency;
|
||||
}
|
||||
|
||||
public Configuration getSourceConfiguration() {
|
||||
return sourceConfiguration;
|
||||
}
|
||||
|
||||
public Set<File> resolve(){
|
||||
return sourceConfiguration.files(dependency);
|
||||
}
|
||||
|
||||
public File resolveFile(){
|
||||
Set<File> files = resolve();
|
||||
if(files.size() != 1){
|
||||
throw new RuntimeException(dependency + " resolves to more than one file");
|
||||
}
|
||||
File file = files.stream().findFirst().orElse(null);
|
||||
return file;
|
||||
}
|
||||
|
||||
public String getDepString(){
|
||||
return dependency.getGroup() + ":" + dependency.getName() + ":" + dependency.getVersion();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class LoomDependencyManager {
|
||||
|
||||
private List<DependencyProvider> dependencyProviderList = new ArrayList<>();
|
||||
|
||||
public void addProvider(DependencyProvider provider){
|
||||
if(dependencyProviderList.contains(provider)){
|
||||
throw new RuntimeException("Provider is already registered");
|
||||
}
|
||||
if(getProvider(provider.getClass()) != null){
|
||||
throw new RuntimeException("Provider of this type is already registered");
|
||||
}
|
||||
provider.register(this);
|
||||
dependencyProviderList.add(provider);
|
||||
}
|
||||
|
||||
public <T> T getProvider(Class<T> clazz){
|
||||
for(DependencyProvider provider : dependencyProviderList){
|
||||
if(provider.getClass() == clazz){
|
||||
return (T) provider;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void handleDependencies(Project project){
|
||||
project.getLogger().lifecycle(":setting up loom dependencies");
|
||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
Set<String> targetConfigs = new HashSet<>();
|
||||
for(DependencyProvider provider : dependencyProviderList){
|
||||
targetConfigs.add(provider.getTargetConfig());
|
||||
}
|
||||
for(String config : targetConfigs){
|
||||
Configuration configuration = project.getConfigurations().getByName(config);
|
||||
configuration.getDependencies().stream().forEach(dependency -> {
|
||||
for(DependencyProvider provider : dependencyProviderList){
|
||||
if(provider.getTargetConfig().equals(config)){
|
||||
DependencyProvider.DependcyInfo info = new DependencyProvider.DependcyInfo(dependency, configuration);
|
||||
try {
|
||||
provider.provide(info, project, extension);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to provide", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,15 +22,14 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.task;
|
||||
package net.fabricmc.loom.util;
|
||||
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.providers.MinecraftJarProvider;
|
||||
import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
import net.fabricmc.tinyremapper.TinyUtils;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -39,22 +38,22 @@ import java.util.Arrays;
|
|||
|
||||
public class MapJarsTiny {
|
||||
|
||||
public void mapJars(MapJarsTask task) throws IOException {
|
||||
public void mapJars(MinecraftJarProvider jarProvider, Project project) throws IOException {
|
||||
String fromM = "official";
|
||||
|
||||
Path mappings = task.getMappingFile().toPath();
|
||||
Path[] classpath = task.getMapperPaths().stream()
|
||||
Path mappings = jarProvider.getMappingFile().toPath();
|
||||
Path[] classpath = jarProvider.getMapperPaths().stream()
|
||||
.map(File::toPath)
|
||||
.toArray(Path[]::new);
|
||||
|
||||
Path input = task.getInputJar().toPath();
|
||||
Path outputMapped = task.getMappedJar().toPath();
|
||||
Path outputIntermediary = task.getIntermediaryJar().toPath();
|
||||
Path input = jarProvider.getInputJar().toPath();
|
||||
Path outputMapped = jarProvider.getMappedJar().toPath();
|
||||
Path outputIntermediary = jarProvider.getIntermediaryJar().toPath();
|
||||
|
||||
for (String toM : Arrays.asList("named", "intermediary")) {
|
||||
Path output = "named".equals(toM) ? outputMapped : outputIntermediary;
|
||||
|
||||
task.getLogger().lifecycle(":remapping minecraft (TinyRemapper, " + fromM + " -> " + toM + ")");
|
||||
project.getLogger().lifecycle(":remapping minecraft (TinyRemapper, " + fromM + " -> " + toM + ")");
|
||||
|
||||
TinyRemapper remapper = TinyRemapper.newRemapper()
|
||||
.withMappings(TinyUtils.createTinyMappingProvider(mappings, fromM, toM))
|
|
@ -27,12 +27,13 @@ package net.fabricmc.loom.util;
|
|||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.providers.MinecraftLibraryProvider;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Version {
|
||||
public class MinecraftVersionInfo {
|
||||
public List<Library> libraries;
|
||||
public Map<String, Downloads> downloads;
|
||||
public AssetIndex assetIndex;
|
||||
|
@ -62,9 +63,9 @@ public class Version {
|
|||
return Constants.LIBRARIES_BASE + path;
|
||||
}
|
||||
|
||||
public File getFile(LoomGradleExtension extension) {
|
||||
public File getFile(File baseDir) {
|
||||
String[] parts = this.name.split(":", 3);
|
||||
return new File(Constants.MINECRAFT_LIBS.get(extension), parts[0].replace(".", File.separator) + File.separator + parts[1] + File.separator + parts[2] + File.separator + parts[1] + "-" + parts[2] + getClassifier() + ".jar");
|
||||
return new File(baseDir, parts[0].replace(".", File.separator) + File.separator + parts[1] + File.separator + parts[2] + File.separator + parts[1] + "-" + parts[2] + getClassifier() + ".jar");
|
||||
}
|
||||
|
||||
public String getSha1() {
|
|
@ -29,6 +29,7 @@ import com.google.gson.GsonBuilder;
|
|||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.providers.MinecraftProvider;
|
||||
import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
import net.fabricmc.tinyremapper.TinyUtils;
|
||||
|
@ -77,10 +78,12 @@ public class ModProcessor {
|
|||
String fromM = "intermediary";
|
||||
String toM = "named";
|
||||
|
||||
File mappingsFile = Constants.MAPPINGS_TINY.get(extension);
|
||||
MinecraftProvider minecraftProvider = extension.getMinecraftProvider();
|
||||
|
||||
File mappingsFile = minecraftProvider.pomfProvider.MAPPINGS_TINY;
|
||||
Path mappings = mappingsFile.toPath();
|
||||
Path mc = Constants.MINECRAFT_INTERMEDIARY_JAR.get(extension).toPath();
|
||||
Path[] mcDeps = project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).getFiles().stream()
|
||||
Path mc = minecraftProvider.jarProvider.MINECRAFT_INTERMEDIARY_JAR.toPath();
|
||||
Path[] mcDeps = minecraftProvider.jarProvider.getMapperPaths().stream()
|
||||
.map(File::toPath)
|
||||
.toArray(Path[]::new);
|
||||
Collection<File> modCompileFiles = project.getConfigurations().getByName(Constants.COMPILE_MODS).getFiles();
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
package net.fabricmc.loom.util;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.providers.MinecraftProvider;
|
||||
import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
import net.fabricmc.tinyremapper.TinyUtils;
|
||||
|
@ -49,18 +50,19 @@ public class ModRemapper {
|
|||
return;
|
||||
}
|
||||
|
||||
Path mappings = Constants.MAPPINGS_TINY.get(extension).toPath();
|
||||
MinecraftProvider minecraftProvider = extension.getMinecraftProvider();
|
||||
|
||||
Path mappings = minecraftProvider.pomfProvider.MAPPINGS_TINY.toPath();
|
||||
|
||||
String fromM = "named";
|
||||
String toM = "intermediary";
|
||||
|
||||
List<File> classpathFiles = new ArrayList<>();
|
||||
classpathFiles.addAll(project.getConfigurations().getByName("compile").getFiles());
|
||||
classpathFiles.addAll(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT).getFiles());
|
||||
|
||||
Path[] classpath = classpathFiles.stream().map(File::toPath).toArray(Path[]::new);
|
||||
|
||||
File mixinMapFile = Constants.MAPPINGS_MIXIN_EXPORT.get(extension);
|
||||
File mixinMapFile = extension.getMinecraftProvider().jarProvider.MINECRAFT_MAPPED_JAR;
|
||||
Path mixinMapPath = mixinMapFile.toPath();
|
||||
|
||||
TinyRemapper.Builder remapperBuilder = TinyRemapper.newRemapper();
|
||||
|
|
|
@ -1,46 +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.delayed;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class DelayedFile implements IDelayed<File> {
|
||||
private File file;
|
||||
private Function<LoomGradleExtension, File> function;
|
||||
|
||||
public DelayedFile(Function<LoomGradleExtension, File> function) {
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File get(LoomGradleExtension extension) {
|
||||
// TODO: Figure out caching issues
|
||||
this.file = this.function.apply(extension);
|
||||
return this.file;
|
||||
}
|
||||
}
|
|
@ -1,31 +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.delayed;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
|
||||
public interface IDelayed<T> {
|
||||
T get(LoomGradleExtension extension);
|
||||
}
|
Loading…
Reference in New Issue