Cleanup installer json handling, should hopefully fix incorrect dependency versions.

dev/0.11
modmuss50 2019-11-12 18:46:57 +00:00
parent 35437891b5
commit e03bbe0f87
4 changed files with 17 additions and 32 deletions

View File

@ -64,7 +64,6 @@ public class LoomGradleExtension {
private Project project; private Project project;
private LoomDependencyManager dependencyManager; private LoomDependencyManager dependencyManager;
private JsonObject installerJson; private JsonObject installerJson;
private int installerJsonPriority = Integer.MAX_VALUE; // 0+, higher = less prioritized
private MappingSet[] srcMappingCache = new MappingSet[2]; private MappingSet[] srcMappingCache = new MappingSet[2];
private Mercury[] srcMercuryCache = new Mercury[2]; private Mercury[] srcMercuryCache = new Mercury[2];
@ -88,11 +87,8 @@ public class LoomGradleExtension {
return Collections.unmodifiableList(unmappedModsBuilt); return Collections.unmodifiableList(unmappedModsBuilt);
} }
public void setInstallerJson(JsonObject object, int priority) { public void setInstallerJson(JsonObject object) {
if (installerJson == null || priority <= installerJsonPriority) {
this.installerJson = object; this.installerJson = object;
this.installerJsonPriority = priority;
}
} }
public JsonObject getInstallerJson() { public JsonObject getInstallerJson() {

View File

@ -27,15 +27,12 @@ package net.fabricmc.loom.util;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.ExternalModuleDependency; import org.gradle.api.artifacts.ExternalModuleDependency;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository; import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
@ -129,23 +126,20 @@ public class LoomDependencyManager {
if (extension.getInstallerJson() == null) { if (extension.getInstallerJson() == null) {
//If we've not found the installer JSON we've probably skipped remapping Fabric loader, let's go looking //If we've not found the installer JSON we've probably skipped remapping Fabric loader, let's go looking
project.getLogger().info("Didn't find installer JSON, searching through modCompileClasspath"); project.getLogger().info("Searching through modCompileClasspath for installer JSON");
Configuration configuration = project.getConfigurations().getByName(Constants.MOD_COMPILE_CLASSPATH); final Configuration configuration = project.getConfigurations().getByName(Constants.MOD_COMPILE_CLASSPATH);
Set<File> seenFiles = new HashSet<>(); for (File input : configuration.resolve()) {
JsonObject jsonObject = ModProcessor.readInstallerJson(input, project);
for (Dependency dependency : configuration.getDependencies()) {
DependencyInfo info = DependencyInfo.create(project, dependency, configuration);
for (File input : info.resolve()) {
if (seenFiles.add(input)) {
ModProcessor.readInstallerJson(input, project);
if (jsonObject != null) {
if (extension.getInstallerJson() != null) { if (extension.getInstallerJson() != null) {
project.getLogger().info("Found installer JSON in " + info); project.getLogger().info("Found another installer JSON in, ignoring it! " + input);
break; //Found it, probably don't need to look any further continue;
}
} }
project.getLogger().info("Found installer JSON in " + input);
extension.setInstallerJson(jsonObject);
} }
} }
} }

View File

@ -141,8 +141,6 @@ public class ModCompileRemapper {
} else { } else {
project.getLogger().info(output.getName() + " is up to date with " + input.getName()); project.getLogger().info(output.getName() + " is up to date with " + input.getName());
} }
ModProcessor.acknowledgeMod(input, output, project, config);
} }
private static File findSources(DependencyHandler dependencies, ResolvedArtifact artifact) { private static File findSources(DependencyHandler dependencies, ResolvedArtifact artifact) {

View File

@ -73,10 +73,6 @@ public class ModProcessor {
stripNestedJars(output); stripNestedJars(output);
} }
public static void acknowledgeMod(File input, File output, Project project, Configuration config) {
readInstallerJson(input, project);
}
private static void handleNestedJars(File input, Project project, Configuration config) throws IOException { private static void handleNestedJars(File input, Project project, Configuration config) throws IOException {
JarFile jarFile = new JarFile(input); JarFile jarFile = new JarFile(input);
JarEntry modJsonEntry = jarFile.getJarEntry("fabric.mod.json"); JarEntry modJsonEntry = jarFile.getJarEntry("fabric.mod.json");
@ -187,7 +183,7 @@ public class ModProcessor {
} }
} }
static void readInstallerJson(File file, Project project) { static JsonObject readInstallerJson(File file, Project project) {
try { try {
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
String launchMethod = extension.getLoaderLaunchMethod(); String launchMethod = extension.getLoaderLaunchMethod();
@ -211,7 +207,7 @@ public class ModProcessor {
priority++; priority++;
if (entry == null) { if (entry == null) {
return; return null;
} }
} }
@ -221,9 +217,10 @@ public class ModProcessor {
} }
JsonObject jsonObject = GSON.fromJson(jsonStr, JsonObject.class); JsonObject jsonObject = GSON.fromJson(jsonStr, JsonObject.class);
extension.setInstallerJson(jsonObject, priority); return jsonObject;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null;
} }
} }