Now stores files in the user gradle folder, will prevent downloading assets for each project

dev/0.11
modmuss50 2016-08-25 12:42:23 +01:00
parent 547c242ff0
commit 3eb9b77746
8 changed files with 60 additions and 24 deletions

View File

@ -56,6 +56,7 @@ public class AbstractPlugin implements Plugin<Project> {
project.apply(ImmutableMap.of("plugin", "idea"));
project.getExtensions().create("minecraft", LoomGradleExtension.class);
project.getExtensions().getByType(LoomGradleExtension.class).project = project;
// Force add Mojang repository
addMavenRepo(target, "Mojang", "https://libraries.minecraft.net/");
@ -152,6 +153,11 @@ public class AbstractPlugin implements Plugin<Project> {
flatDirectoryArtifactRepository.setName("LoomCacheFiles");
});
project1.getRepositories().flatDir(flatDirectoryArtifactRepository -> {
flatDirectoryArtifactRepository.dir(extension.getFabricUserCache());
flatDirectoryArtifactRepository.setName("UserCacheFiles");
});
project1.getRepositories().maven(mavenArtifactRepository -> {
mavenArtifactRepository.setName("FabricMC");
mavenArtifactRepository.setUrl("http://maven.fabricmc.net/");
@ -175,7 +181,7 @@ public class AbstractPlugin implements Plugin<Project> {
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() != null) {
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")) {
configName = Constants.CONFIG_MC_DEPENDENCIES_CLIENT;

View File

@ -24,8 +24,34 @@
package net.fabricmc.loom;
import org.gradle.api.Project;
import java.io.File;
public class LoomGradleExtension {
public String version;
public String runDir = "run";
public String fabricVersion;
//Not to be set in the build.gradle
public Project project;
public String getVersionString() {
if (isModWorkspace()) {
return version + "-" + fabricVersion;
}
return version;
}
public boolean isModWorkspace() {
return fabricVersion != null && !fabricVersion.isEmpty();
}
public File getFabricUserCache() {
File userCache = new File(project.getGradle().getGradleUserHomeDir(), "caches" + File.separator + "loom");
if (!userCache.exists()) {
userCache.mkdirs();
}
return userCache;
}
}

View File

@ -80,7 +80,7 @@ public class DownloadTask extends DefaultTask {
if (getProject().getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).getState() == Configuration.State.UNRESOLVED) {
for (Version.Library library : version.libraries) {
if (library.allowed() && library.getFile() != null) {
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")) {
@ -100,7 +100,7 @@ public class DownloadTask extends DefaultTask {
Version.AssetIndex assetIndex = version.assetIndex;
File assets = new File(Constants.CACHE_FILES, "assets");
File assets = new File(extension.getFabricUserCache(), "assets-" + extension.version);
if (!assets.exists()) {
assets.mkdirs();
}
@ -143,8 +143,8 @@ public class DownloadTask extends DefaultTask {
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);
ManifestVersion mcManifest = new GsonBuilder().create().fromJson(FileUtils.readFileToString(Constants.VERSION_MANIFEST), ManifestVersion.class);
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)), ManifestVersion.class);
Optional<ManifestVersion.Versions> optionalVersion = mcManifest.versions.stream().filter(versions -> versions.id.equalsIgnoreCase(extension.version)).findFirst();
if (optionalVersion.isPresent()) {

View File

@ -24,6 +24,7 @@
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.TaskAction;
@ -35,9 +36,10 @@ import java.io.FileNotFoundException;
public class ExtractNativesTask extends DefaultTask {
@TaskAction
public void extractNatives() throws FileNotFoundException {
if (!Constants.MINECRAFT_NATIVES.exists()) {
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);
ZipUtil.unpack(source, Constants.MINECRAFT_NATIVES.get(extension));
}
}
}

View File

@ -103,7 +103,7 @@ public class GenIdeaProjectTask extends DefaultTask {
Version version = gson.fromJson(new FileReader(Constants.MINECRAFT_JSON.get(extension)), Version.class);
for (Version.Library library : version.libraries) {
if (library.allowed() && library.getFile() != null && library.getFile().exists()) {
if (library.allowed() && library.getFile(extension) != null && library.getFile(extension).exists()) {
Element node = doc.createElement("orderEntry");
node.setAttribute("type", "module-library");
Element libraryElement = doc.createElement("library");
@ -111,7 +111,7 @@ public class GenIdeaProjectTask extends DefaultTask {
Element javadoc = doc.createElement("JAVADOC");
Element sources = doc.createElement("SOURCES");
Element root = doc.createElement("root");
root.setAttribute("url", "jar://" + library.getFile().getAbsolutePath() + "!/");
root.setAttribute("url", "jar://" + library.getFile(extension).getAbsolutePath() + "!/");
classes.appendChild(root);
libraryElement.appendChild(classes);
libraryElement.appendChild(javadoc);
@ -119,7 +119,7 @@ public class GenIdeaProjectTask extends DefaultTask {
node.appendChild(libraryElement);
component.appendChild(node);
} else if (!library.allowed()) {
this.getLogger().info(":" + library.getFile().getName() + " is not allowed on this os");
this.getLogger().info(":" + library.getFile(extension).getName() + " is not allowed on this os");
}
}
@ -172,7 +172,7 @@ public class GenIdeaProjectTask extends DefaultTask {
ideaClient.configName = "Minecraft Client";
ideaClient.runDir = "file://$PROJECT_DIR$/" + extension.runDir;
ideaClient.vmArgs = "-Djava.library.path=../.gradle/minecraft/natives/ -Dfabric.development=true";
ideaClient.programArgs = "--tweakClass net.fabricmc.base.launch.FabricClientTweaker --assetIndex " + version.assetIndex.id + " --assetsDir " + new File(Constants.CACHE_FILES, "assets").getAbsolutePath();
ideaClient.programArgs = "--tweakClass net.fabricmc.base.launch.FabricClientTweaker --assetIndex " + version.assetIndex.id + " --assetsDir " + new File(extension.getFabricUserCache(), "assets-" + extension.version).getAbsolutePath();
runManager.appendChild(ideaClient.genRuns(runManager));

View File

@ -49,10 +49,14 @@ public class MapJarsTask extends DefaultTask {
if (Constants.MAPPINGS_DIR.exists()) {
FileUtils.deleteDirectory(Constants.MAPPINGS_DIR);
}
if (Constants.MINECRAFT_MAPPED_JAR.get(extension).exists()) {
Constants.MINECRAFT_MAPPED_JAR.get(extension).delete();
}
ZipUtil.unpack(Constants.MAPPINGS_ZIP, Constants.MAPPINGS_DIR);
File tempFile = new File(Constants.CACHE_FILES, "tempJar.jar");
if (tempFile.exists()) {
//This should not happen, just want to be safe
tempFile.delete();
}

View File

@ -37,22 +37,19 @@ 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 IDelayed<File> MINECRAFT_CLIENT_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.version + "-client.jar"));
public static final IDelayed<File> MINECRAFT_SERVER_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.version + "-server.jar"));
public static final IDelayed<File> MINECRAFT_MERGED_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.version + "-merged.jar"));
public static final IDelayed<File> MINECRAFT_MAPPED_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.version + "-mapped.jar"));
public static final IDelayed<File> MINECRAFT_CLIENT_JAR = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-client.jar"));
public static final IDelayed<File> MINECRAFT_SERVER_JAR = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-server.jar"));
public static final IDelayed<File> MINECRAFT_MERGED_JAR = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-merged.jar"));
public static final IDelayed<File> MINECRAFT_MAPPED_JAR = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.getVersionString() + "-mapped.jar"));
public static final File MAPPINGS_ZIP = new File(CACHE_FILES, "mappings.zip");
public static final File MAPPINGS_DIR = new File(CACHE_FILES, "mappings");
public static final File MINECRAFT_LIBS = new File(CACHE_FILES, "libs");
public static final File MINECRAFT_NATIVES = new File(CACHE_FILES, "natives");
public static final IDelayed<File> MINECRAFT_JSON = new DelayedFile(extension -> new File(CACHE_FILES, extension.version + "-info.json"));
public static final IDelayed<File> MINECRAFT_LIBS = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-libs"));
public static final IDelayed<File> MINECRAFT_NATIVES = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-natives"));
public static final IDelayed<File> MINECRAFT_JSON = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-info.json"));
public static final File MINECRAFT_ROOT = new File(WORKING_DIRECTORY, "minecraft");
public static final IDelayed<File> MAPPING_SRG = new DelayedFile(extension -> new File(WORKING_DIRECTORY, "mappings.srg"));
public static final File VERSION_MANIFEST = new File(CACHE_FILES, "version_manifest.json");
public static final IDelayed<File> VERSION_MANIFEST = new DelayedFile(extension -> new File(extension.getFabricUserCache(), "version_manifest.json"));
public static final String LIBRARIES_BASE = "https://libraries.minecraft.net/";
public static final String RESOURCES_BASE = "http://resources.download.minecraft.net/";

View File

@ -25,6 +25,7 @@
package net.fabricmc.loom.util;
import com.google.gson.JsonObject;
import net.fabricmc.loom.LoomGradleExtension;
import java.io.File;
import java.util.List;
@ -60,9 +61,9 @@ public class Version {
return Constants.LIBRARIES_BASE + path;
}
public File getFile() {
public File getFile(LoomGradleExtension extension) {
String[] parts = this.name.split(":", 3);
return new File(Constants.MINECRAFT_LIBS, parts[0].replace(".", File.separator) + File.separator + parts[1] + File.separator + parts[2] + File.separator + parts[1] + "-" + parts[2] + getClassifier() + ".jar");
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");
}
public String getSha1() {