mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 21:47:42 -05:00
Update mercury, use the java release version to set the merucry source compat version (#773)
This commit is contained in:
@@ -42,7 +42,6 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.task.RemapSourcesJarTask;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.DeletingFileVisitor;
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
import net.fabricmc.loom.util.SourceRemapper;
|
||||
@@ -58,22 +57,24 @@ public final class SourceRemapperService implements SharedService {
|
||||
final String from = task.getSourceNamespace().get();
|
||||
final LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
final String id = extension.getMappingConfiguration().getBuildServiceName("sourceremapper", from, to);
|
||||
final int javaCompileRelease = SourceRemapper.getJavaCompileRelease(project);
|
||||
|
||||
return serviceManager.getOrCreateService(id, () ->
|
||||
new SourceRemapperService(MappingsService.createDefault(project, serviceManager, from, to), task.getClasspath()
|
||||
));
|
||||
new SourceRemapperService(MappingsService.createDefault(project, serviceManager, from, to), task.getClasspath(), javaCompileRelease));
|
||||
}
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SourceRemapperService.class);
|
||||
|
||||
private final MappingsService mappingsService;
|
||||
private final ConfigurableFileCollection classpath;
|
||||
private final int javaCompileRelease;
|
||||
|
||||
private final Supplier<Mercury> mercury = Suppliers.memoize(this::createMercury);
|
||||
|
||||
private SourceRemapperService(MappingsService mappingsService, ConfigurableFileCollection classpath) {
|
||||
private SourceRemapperService(MappingsService mappingsService, ConfigurableFileCollection classpath, int javaCompileRelease) {
|
||||
this.mappingsService = mappingsService;
|
||||
this.classpath = classpath;
|
||||
this.javaCompileRelease = javaCompileRelease;
|
||||
}
|
||||
|
||||
public void remapSourcesJar(Path source, Path destination) throws IOException {
|
||||
@@ -122,7 +123,7 @@ public final class SourceRemapperService implements SharedService {
|
||||
private Mercury createMercury() {
|
||||
var mercury = new Mercury();
|
||||
mercury.setGracefulClasspathChecks(true);
|
||||
mercury.setSourceCompatibility(Constants.MERCURY_SOURCE_VERSION);
|
||||
mercury.setSourceCompatibilityFromRelease(javaCompileRelease);
|
||||
|
||||
try {
|
||||
mercury.getProcessors().add(MercuryRemapper.create(getMappings()));
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
package net.fabricmc.loom.util;
|
||||
|
||||
import org.eclipse.jdt.core.JavaCore;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
public class Constants {
|
||||
@@ -35,7 +34,6 @@ public class Constants {
|
||||
public static final String FABRIC_REPOSITORY = "https://maven.fabricmc.net/";
|
||||
|
||||
public static final int ASM_VERSION = Opcodes.ASM9;
|
||||
public static final String MERCURY_SOURCE_VERSION = JavaCore.VERSION_17;
|
||||
|
||||
private Constants() {
|
||||
}
|
||||
|
||||
@@ -31,13 +31,17 @@ import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.cadixdev.lorenz.MappingSet;
|
||||
import org.cadixdev.mercury.Mercury;
|
||||
import org.cadixdev.mercury.remapper.MercuryRemapper;
|
||||
import org.gradle.api.JavaVersion;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.internal.project.ProjectInternal;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.tasks.compile.JavaCompile;
|
||||
import org.gradle.internal.logging.progress.ProgressLogger;
|
||||
import org.gradle.internal.logging.progress.ProgressLoggerFactory;
|
||||
import org.slf4j.Logger;
|
||||
@@ -175,6 +179,7 @@ public class SourceRemapper {
|
||||
|
||||
Mercury mercury = extension.getOrCreateSrcMercuryCache(toNamed ? 1 : 0, () -> {
|
||||
Mercury m = createMercuryWithClassPath(project, toNamed);
|
||||
m.setSourceCompatibilityFromRelease(getJavaCompileRelease(project));
|
||||
|
||||
for (File file : extension.getUnmappedModCollection()) {
|
||||
Path path = file.toPath();
|
||||
@@ -209,6 +214,30 @@ public class SourceRemapper {
|
||||
return mercury;
|
||||
}
|
||||
|
||||
public static int getJavaCompileRelease(Project project) {
|
||||
AtomicInteger release = new AtomicInteger(-1);
|
||||
|
||||
project.getTasks().withType(JavaCompile.class, javaCompile -> {
|
||||
Property<Integer> releaseProperty = javaCompile.getOptions().getRelease();
|
||||
|
||||
if (!releaseProperty.isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int compileRelease = releaseProperty.get();
|
||||
release.set(Math.max(release.get(), compileRelease));
|
||||
});
|
||||
|
||||
final int i = release.get();
|
||||
|
||||
if (i < 0) {
|
||||
// Unable to find the release used to compile with, default to the current version
|
||||
return Integer.parseInt(JavaVersion.current().getMajorVersion());
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public static void copyNonJavaFiles(Path from, Path to, Logger logger, Path source) throws IOException {
|
||||
Files.walk(from).forEach(path -> {
|
||||
Path targetPath = to.resolve(from.relativize(path).toString());
|
||||
@@ -226,7 +255,6 @@ public class SourceRemapper {
|
||||
public static Mercury createMercuryWithClassPath(Project project, boolean toNamed) {
|
||||
Mercury m = new Mercury();
|
||||
m.setGracefulClasspathChecks(true);
|
||||
m.setSourceCompatibility(Constants.MERCURY_SOURCE_VERSION);
|
||||
|
||||
final List<Path> classPath = new ArrayList<>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user