Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ gradle.beforeProject { Project project ->
project.repositories {
mavenCentral()
maven project.gradleutils.forgeMaven
//mavenLocal()
mavenLocal()
}
}
}
Expand All @@ -30,7 +30,7 @@ dependencyResolutionManagement.versionCatalogs.register('libs') {

library 'gson', 'com.google.code.gson', 'gson' version '2.10.1'
library 'jopt', 'net.sf.jopt-simple', 'jopt-simple' version '6.0-alpha-3'
library 'jver', 'net.minecraftforge', 'java-provisioner' version '1.0.10'
library 'jver', 'net.minecraftforge', 'java-provisioner' version '2.0.0'
library 'srgutils', 'net.minecraftforge', 'srgutils' version '0.5.14'
library 'diff', 'io.codechicken', 'DiffPatch' version '2.0.0.36' // Fuzzy patching

Expand All @@ -41,8 +41,9 @@ dependencyResolutionManagement.versionCatalogs.register('libs') {
library 'utils-download', 'net.minecraftforge', 'download-utils' version '0.3.1'
library 'utils-files', 'net.minecraftforge', 'file-utils' version '0.3.1'
library 'utils-hash', 'net.minecraftforge', 'hash-utils' version '0.1.9'
library 'utils-data', 'net.minecraftforge', 'json-data-utils' version '0.2.3'
library 'utils-data', 'net.minecraftforge', 'json-data-utils' version '0.4.0'
library 'utils-logging', 'net.minecraftforge', 'log-utils' version '0.3.1'
bundle 'utils', ['utils-download', 'utils-files', 'utils-hash', 'utils-data', 'utils-logging']
library 'utils-os', 'net.minecraftforge', 'os-utils' version '0.1.0'
bundle 'utils', ['utils-download', 'utils-files', 'utils-hash', 'utils-data', 'utils-logging', 'utils-os']
}
//formatter:on
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package net.minecraftforge.mcmaven.impl;

import net.minecraftforge.util.logging.Log;
import net.minecraftforge.util.os.OS;

public final class GlobalOptions {
private static boolean offline = false;
Expand Down Expand Up @@ -37,6 +38,7 @@ public static void assertNotCacheOnly() {
if (cacheOnly) {
throw new IllegalArgumentException("Cache is out of date! Please run without --cache-only");
} else if (!cacheMiss) {
Log.warn("Cache miss!", new Exception("Cache miss!"));
cacheMiss = true;
Log.release();
}
Expand Down
23 changes: 10 additions & 13 deletions src/main/java/net/minecraftforge/mcmaven/impl/cache/JDKCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
/** Represents the JDK cache for this tool. */
public final class JDKCache {
private boolean attemptedLocate = false;
private final List<Throwable> attemptedLocateErrors = new ArrayList<>();
private final File root;
private final Map<Integer, File> jdks = new HashMap<>();
private final IJavaLocator disco;
Expand All @@ -48,7 +49,7 @@ public File root() {
* @param version The version to get
* @return The JDK, or {@code null} if it could not be found or downloaded
*/
public @Nullable File get(int version) {
public File get(int version) throws Exception {
if (!attemptedLocate)
attemptLocate();

Expand All @@ -57,26 +58,19 @@ public File root() {
if (ret != null) return ret;

try {
var downloaded = disco.provision(version); // Implementation detail, we only download jdks, so no need to check here
if (downloaded == null) {
Log.error("Failed to find JDK for " + version);
for (var line : disco.logOutput())
Log.error(" " + line);
return null;
}
ret = downloaded.home();
ret = disco.provision(version).home(); // Implementation detail, we only download jdks, so no need to check here
} catch (Exception e) {
Log.error("Failed to provision JDK " + version);
e.printStackTrace(Log.getLog(Level.ERROR));
return null;
throw e;
}

// not sure how this would ever hit. but just in case...
var old = jdks.putIfAbsent(version, ret);
if (old != null) {
Log.error("JDKCache: Downloaded JDK " + version + " is replacing an existing download! It was probably downloaded by another thread.");
Log.error("JDKCache: Old JDK: " + old);
// TODO Throw exception here
// TODO [Mavenizer][Provisioner] Properly account for parallel Mavenizer instances
}

return ret;
Expand All @@ -94,8 +88,11 @@ private void attemptLocate() {
List<IJavaInstall> installs = new ArrayList<>();

for (IJavaLocator locator : locators) {
List<IJavaInstall> found = locator.findAll();
installs.addAll(found);
try {
installs.addAll(locator.findAll().installs());
} catch (Exception e) {
attemptedLocateErrors.add(e);
}
}

// Remove duplicates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraftforge.util.file.FileUtils;
import net.minecraftforge.util.hash.HashFunction;
import net.minecraftforge.mcmaven.impl.util.Util;
import net.minecraftforge.util.os.OS;

/** Represents the Minecraft maven cache for this tool. */
public final class MinecraftMavenCache extends MavenCache {
Expand All @@ -22,7 +23,7 @@ public final class MinecraftMavenCache extends MavenCache {
HashFunction.SHA1
};

private static final File LOCAL_MCLIBS = new File(MCJsonUtils.getMCDir(), "libraries");
private static final File LOCAL_MCLIBS = new File(MCJsonUtils.getMCDir(OS.current()), "libraries");

/**
* Initializes a new maven cache with the given cache directory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,12 @@ private File getMappings(MCPSide side, Task srgMappings, Task clientTask, Task s
output.getAbsolutePath()
);

var jdk = side.getMCP().getCache().jdks().get(Constants.INSTALLER_TOOLS_JAVA_VERSION);
if (jdk == null)
throw new IllegalStateException("Failed to find JDK for version " + Constants.INSTALLER_TOOLS_JAVA_VERSION);
File jdk;
try {
jdk = side.getMCP().getCache().jdks().get(Constants.INSTALLER_TOOLS_JAVA_VERSION);
} catch (Exception e) {
throw new IllegalStateException("Failed to find JDK for version " + Constants.INSTALLER_TOOLS_JAVA_VERSION, e);
}

var ret = ProcessUtils.runJar(jdk, log.getParentFile(), log, tool, Collections.emptyList(), args);
if (ret.exitCode != 0)
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/net/minecraftforge/mcmaven/impl/repo/Repo.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -73,6 +75,13 @@ protected Supplier<GradleModule.Variant[]> sourceVariant(Mappings mappings) {
};
}

protected Supplier<GradleModule.Variant[]> metadataVariant() {
return () -> new GradleModule.Variant[] {
GradleModule.Variant.of("metadata")
.attribute("org.gradle.usage", "metadata")
};
}

protected static Task variantTask(Task parent, Supplier<GradleModule.Variant[]> supplier) {
return Task.named(parent.name() + "[variants]", Task.deps(parent), () -> {
var variants = supplier.get();
Expand Down Expand Up @@ -105,15 +114,17 @@ protected GradleModule.Variant[] classVariants(Mappings mappings, MCPSide side,
var natives = new HashMap<GradleAttributes.OperatingSystemFamily, List<Artifact>>();

for (var artifact : side.getMCLibraries()) {
var variant = GradleAttributes.OperatingSystemFamily.from(artifact.getOs());
if (variant == null)
var osVariants = artifact.getOs().stream().map(GradleAttributes.OperatingSystemFamily::from).filter(Objects::nonNull).collect(Collectors.toSet());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather avoid streams like this.

if (osVariants.isEmpty()) {
all.add(artifact);
else
natives.computeIfAbsent(variant, k -> new ArrayList<>()).add(artifact);
} else {
for (var variant : osVariants) {
natives.computeIfAbsent(variant, k -> new ArrayList<>()).add(artifact);
}
}
}

for (var artifact : side.getMCPConfigLibraries())
all.add(artifact);
all.addAll(side.getMCPConfigLibraries());

for (var extra : extraDeps) {
if (extra != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private List<PendingArtifact> processV3(String version, Mappings mappings) {

var sources = pending("Sources", sourcesTask, name.withClassifier("sources"), true, sourceVariant(mappings));
var classes = pending("Classes", classesTask, name, false, () -> classVariants(mappings, patcher, extraCoords, mappingCoords));
var metadata = pending("Metadata", metadata(build, patcher), name.withClassifier("metadata").withExtension("zip"), false);
var metadata = pending("Metadata", metadata(build, patcher), name.withClassifier("metadata").withExtension("zip"), false, metadataVariant());

var pom = pending("Maven POM", pom(build, patcher, version, extraCoords, mappingCoords), name.withExtension("pom"), false);

Expand Down Expand Up @@ -174,8 +174,9 @@ private static Task metadata(File build, Patcher patcher) {

var cache = HashStore
.fromFile(output)
.add("data", patcher.getDataHash())
.add(versionJson)
.add(versionProperties)
.add("data", patcher.getDataHash())
.addKnown("version", "1");
if (output.exists() && cache.isSame())
return output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ private File injectDataImpl(Task inputTask, File outputJar) {
cache.clear().add("recompiled", recompiledJar);

try {
var jars = new ArrayList<File>();
jars.addAll(universals);
var jars = new ArrayList<>(universals);
universals.forEach(cache::add);

jars.add(recompiledJar);

FileUtils.mergeJars(outputJar, true, (file, name) -> file == recompiledJar || !name.endsWith(".class"), jars.toArray(File[]::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,12 @@ public static File modifyAccess(File globalBase, Task inputTask, File cfg, Cache
"--outJar", output.getAbsolutePath()
);

var jdk = dlCache.jdks().get(Constants.ACCESS_TRANSFORMER_JAVA_VERSION);
if (jdk == null)
throw new IllegalStateException("Failed to find JDK for version " + Constants.ACCESS_TRANSFORMER_JAVA_VERSION);
File jdk;
try {
jdk = dlCache.jdks().get(Constants.ACCESS_TRANSFORMER_JAVA_VERSION);
} catch (Exception e) {
throw new IllegalStateException("Failed to find JDK for version " + Constants.ACCESS_TRANSFORMER_JAVA_VERSION, e);
}

var ret = ProcessUtils.runJar(jdk, globalBase, log, tool, Collections.emptyList(), args);
if (ret.exitCode != 0)
Expand Down Expand Up @@ -465,9 +468,12 @@ public static File stripSides(File globalBase, Task inputTask, File cfg, Cache d
args.add("--output");
args.add(output.getAbsolutePath());

var jdk = dlCache.jdks().get(Constants.SIDE_STRIPPER_JAVA_VERSION);
if (jdk == null)
throw new IllegalStateException("Failed to find JDK for version " + Constants.SIDE_STRIPPER_JAVA_VERSION);
File jdk;
try {
jdk = dlCache.jdks().get(Constants.SIDE_STRIPPER_JAVA_VERSION);
} catch (Exception e) {
throw new IllegalStateException("Failed to find JDK for version " + Constants.SIDE_STRIPPER_JAVA_VERSION, e);
}

var ret = ProcessUtils.runJar(jdk, globalBase, log, tool, Collections.emptyList(), args);
if (ret.exitCode != 0)
Expand Down Expand Up @@ -536,10 +542,12 @@ private File postProcess(Task inputTask, PatcherConfig.V2.DataFunction data, Fil

int java_version = data.getJavaVersion(this.getMCP().getConfig());
var jdks = this.getMCP().getCache().jdks();
var jdk = jdks.get(java_version);
if (jdk == null)
throw new IllegalStateException("Failed to find JDK for version " + java_version);

File jdk;
try {
jdk = jdks.get(java_version);
} catch (Exception e) {
throw new IllegalStateException("Failed to find JDK for version " + java_version, e);
}

var ret = ProcessUtils.runJar(jdk, log.getParentFile(), log, tool, data.getJvmArgs(), args);
if (ret.exitCode != 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public List<PendingArtifact> process(Artifact artifact, Mappings mappings) {

var sources = pending("Sources", sourcesTask, name.withClassifier("sources"), true, sourceVariant(mappings));
var classes = pending("Classes", classesTask, name, false, () -> classVariants(mappings, mcpSide));
var metadata = pending("Metadata", metadata(build, mcpSide), name.withClassifier("metadata").withExtension("zip"), false);
var metadata = pending("Metadata", metadata(build, mcpSide), name.withClassifier("metadata").withExtension("zip"), false, metadataVariant());
var pom = pending("Maven POM", pom(build, side, mcpSide, version), name.withExtension("pom"), false);

pending.addAll(List.of(
Expand Down Expand Up @@ -183,7 +183,7 @@ private static Task mergeExtra(File build, String side, Task recompiled, Task ex

private static Task metadata(File build, MCPSide side) {
var minecraftTasks = side.getMCP().getMinecraftTasks();
return Task.named("metadata[forge]", Task.deps(minecraftTasks.versionJson), () -> {
return Task.named("metadata[" + side + ']', Task.deps(minecraftTasks.versionJson), () -> {
var output = new File(build, "metadata.zip");

// metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import net.minecraftforge.mcmaven.impl.cache.MavenCache;
import net.minecraftforge.mcmaven.impl.util.Artifact;
import net.minecraftforge.mcmaven.impl.util.Constants;
import net.minecraftforge.util.data.OS;
import net.minecraftforge.util.os.OS;
import net.minecraftforge.util.data.json.JsonData;
import net.minecraftforge.util.data.json.MCPConfig;
import net.minecraftforge.util.file.FileUtils;
Expand Down Expand Up @@ -600,8 +600,14 @@ private File listLibraries(Task jsonTask, File output) {
cache.addKnown(lib.coord, lib.dl.sha1);

if (output.exists() && libsVarCache.exists() && cache.isSame()) {
this.libraries = JsonData.<List<Lib.Cached>>fromJson(libsVarCache, new TypeToken<>() { }).stream().map(Lib.Cached::resolve).toList();
return output;
try {
this.libraries = JsonData.<List<Lib.Cached>>fromJson(libsVarCache, new TypeToken<>() { }).stream().map(Lib.Cached::resolve).toList();
return output;
} catch (Exception e) {
Log.error("Failed to load cached libraries, regenerating...");
Log.error("Cached file: " + libsVarCache.getAbsolutePath());
e.printStackTrace(Log.ERROR);
}
}

GlobalOptions.assertNotCacheOnly();
Expand All @@ -618,9 +624,7 @@ private File listLibraries(Task jsonTask, File output) {

buf.append("-e=").append(target.getAbsolutePath()).append('\n');

var artifact = Artifact.from(lib.coord);
if (lib.os != null && lib.os != OS.UNKNOWN)
artifact = artifact.withOS(lib.os);
var artifact = Artifact.from(lib.coord).withOS(lib.os);

downloadedLibs.add(new Lib(artifact, target));
cache.add(lib.coord, target);
Expand Down Expand Up @@ -845,9 +849,12 @@ private File execute(List<TaskOrArg> jvmArgs, List<TaskOrArg> runArgs, MCPConfig

int java_version = func.getJavaVersion(this.side.getMCP().getConfig());
var jdks = this.side.getMCP().getCache().jdks();
var jdk = jdks.get(java_version);
if (jdk == null)
throw new IllegalStateException("Failed to find JDK for version " + java_version);
File jdk;
try {
jdk = jdks.get(java_version);
} catch (Exception e) {
throw new IllegalStateException("Failed to find JDK for version " + java_version, e);
}

var ret = ProcessUtils.runJar(jdk, log.getParentFile(), log, tool, jvm, run);
if (ret.exitCode != 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ private File recompileSourcesImpl(Task inputTask, File outputJar) {

GlobalOptions.assertNotCacheOnly();

var jdk = this.mcp.getCache().jdks().get(javaTarget);
if (jdk == null) {
throw new IllegalStateException("JDK not found: " + javaTarget);
File jdk;
try {
jdk = this.mcp.getCache().jdks().get(javaTarget);
} catch (Exception e) {
throw new IllegalStateException("JDK not found: " + javaTarget, e);
}

ProcessUtils.recompileJar(jdk, this.classpath.get(), sourcesJar, outputJar, this.build);
Expand Down
Loading