mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-28 04:07:01 -05:00
Fix compile errors
This commit is contained in:
@@ -263,11 +263,11 @@ public abstract class CompileConfiguration implements Runnable {
|
||||
namedMinecraftProvider.provide(provideContext);
|
||||
|
||||
if (extension.isForge()) {
|
||||
final SrgMinecraftProvider<?> srgMinecraftProvider = jarConfiguration.getSrgMinecraftProviderBiFunction().apply(project, minecraftProvider);
|
||||
final SrgMinecraftProvider<?> srgMinecraftProvider = jarConfiguration.createSrgMinecraftProvider(project);
|
||||
extension.setSrgMinecraftProvider(srgMinecraftProvider);
|
||||
srgMinecraftProvider.provide(provideContext);
|
||||
} else if (extension.isNeoForge()) {
|
||||
final MojangMappedMinecraftProvider<?> mojangMappedMinecraftProvider = jarConfiguration.getMojangMappedMinecraftProviderBiFunction().apply(project, minecraftProvider);
|
||||
final MojangMappedMinecraftProvider<?> mojangMappedMinecraftProvider = jarConfiguration.createMojangMappedMinecraftProvider(project);
|
||||
extension.setMojangMappedMinecraftProvider(mojangMappedMinecraftProvider);
|
||||
mojangMappedMinecraftProvider.provide(provideContext);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.configuration.ConfigContext;
|
||||
import net.fabricmc.loom.configuration.providers.forge.MinecraftPatchedProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MergedMinecraftProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMetadataProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.SingleJarMinecraftProvider;
|
||||
|
||||
/**
|
||||
@@ -37,15 +38,15 @@ import net.fabricmc.loom.configuration.providers.minecraft.SingleJarMinecraftPro
|
||||
public interface ForgeMinecraftProvider {
|
||||
MinecraftPatchedProvider getPatchedProvider();
|
||||
|
||||
static MergedMinecraftProvider createMerged(ConfigContext context) {
|
||||
return LoomGradleExtension.get(context.project()).isForgeLike() ? new MergedForgeMinecraftProvider(context) : new MergedMinecraftProvider(context);
|
||||
static MergedMinecraftProvider createMerged(MinecraftMetadataProvider metadataProvider, ConfigContext context) {
|
||||
return LoomGradleExtension.get(context.project()).isForgeLike() ? new MergedForgeMinecraftProvider(metadataProvider, context) : new MergedMinecraftProvider(metadataProvider, context);
|
||||
}
|
||||
|
||||
static SingleJarMinecraftProvider createServerOnly(ConfigContext context) {
|
||||
return LoomGradleExtension.get(context.project()).isForgeLike() ? SingleJarForgeMinecraftProvider.server(context) : SingleJarMinecraftProvider.server(context);
|
||||
static SingleJarMinecraftProvider createServerOnly(MinecraftMetadataProvider metadataProvider, ConfigContext context) {
|
||||
return LoomGradleExtension.get(context.project()).isForgeLike() ? SingleJarForgeMinecraftProvider.forgeServer(metadataProvider, context) : SingleJarMinecraftProvider.server(metadataProvider, context);
|
||||
}
|
||||
|
||||
static SingleJarMinecraftProvider createClientOnly(ConfigContext context) {
|
||||
return LoomGradleExtension.get(context.project()).isForgeLike() ? SingleJarForgeMinecraftProvider.client(context) : SingleJarMinecraftProvider.client(context);
|
||||
static SingleJarMinecraftProvider createClientOnly(MinecraftMetadataProvider metadataProvider, ConfigContext context) {
|
||||
return LoomGradleExtension.get(context.project()).isForgeLike() ? SingleJarForgeMinecraftProvider.forgeClient(metadataProvider, context) : SingleJarMinecraftProvider.client(metadataProvider, context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,12 +31,13 @@ import java.util.List;
|
||||
import net.fabricmc.loom.configuration.ConfigContext;
|
||||
import net.fabricmc.loom.configuration.providers.forge.MinecraftPatchedProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MergedMinecraftProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMetadataProvider;
|
||||
|
||||
public final class MergedForgeMinecraftProvider extends MergedMinecraftProvider implements ForgeMinecraftProvider {
|
||||
private final MinecraftPatchedProvider patchedProvider;
|
||||
|
||||
public MergedForgeMinecraftProvider(ConfigContext configContext) {
|
||||
super(configContext);
|
||||
public MergedForgeMinecraftProvider(MinecraftMetadataProvider metadataProvider, ConfigContext configContext) {
|
||||
super(metadataProvider, configContext);
|
||||
this.patchedProvider = new MinecraftPatchedProvider(configContext.project(), this, MinecraftPatchedProvider.Type.MERGED);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,24 +27,28 @@ package net.fabricmc.loom.configuration.providers.forge.minecraft;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.configuration.ConfigContext;
|
||||
import net.fabricmc.loom.configuration.providers.BundleMetadata;
|
||||
import net.fabricmc.loom.configuration.providers.forge.MinecraftPatchedProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMetadataProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.SingleJarEnvType;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.SingleJarMinecraftProvider;
|
||||
|
||||
public final class SingleJarForgeMinecraftProvider extends SingleJarMinecraftProvider implements ForgeMinecraftProvider {
|
||||
public abstract class SingleJarForgeMinecraftProvider extends SingleJarMinecraftProvider implements ForgeMinecraftProvider {
|
||||
private final MinecraftPatchedProvider patchedProvider;
|
||||
|
||||
private SingleJarForgeMinecraftProvider(ConfigContext configContext, SingleJarMinecraftProvider.Environment environment) {
|
||||
super(configContext, environment);
|
||||
private SingleJarForgeMinecraftProvider(MinecraftMetadataProvider metadataProvider, ConfigContext configContext) {
|
||||
super(metadataProvider, configContext, MappingsNamespace.OFFICIAL);
|
||||
this.patchedProvider = new MinecraftPatchedProvider(configContext.project(), this, provideServer() ? MinecraftPatchedProvider.Type.SERVER_ONLY : MinecraftPatchedProvider.Type.CLIENT_ONLY);
|
||||
}
|
||||
|
||||
public static SingleJarForgeMinecraftProvider server(ConfigContext configContext) {
|
||||
return new SingleJarForgeMinecraftProvider(configContext, new Server());
|
||||
public static SingleJarForgeMinecraftProvider.Server forgeServer(MinecraftMetadataProvider metadataProvider, ConfigContext configContext) {
|
||||
return new SingleJarForgeMinecraftProvider.Server(metadataProvider, configContext);
|
||||
}
|
||||
|
||||
public static SingleJarForgeMinecraftProvider client(ConfigContext configContext) {
|
||||
return new SingleJarForgeMinecraftProvider(configContext, new Client());
|
||||
public static SingleJarForgeMinecraftProvider.Client forgeClient(MinecraftMetadataProvider metadataProvider, ConfigContext configContext) {
|
||||
return new SingleJarForgeMinecraftProvider.Client(metadataProvider, configContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,4 +76,63 @@ public final class SingleJarForgeMinecraftProvider extends SingleJarMinecraftPro
|
||||
public List<Path> getMinecraftJars() {
|
||||
return List.of(patchedProvider.getMinecraftPatchedJar());
|
||||
}
|
||||
|
||||
public static final class Server extends SingleJarForgeMinecraftProvider {
|
||||
private Server(MinecraftMetadataProvider metadataProvider, ConfigContext configContext) {
|
||||
super(metadataProvider, configContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingleJarEnvType type() {
|
||||
return SingleJarEnvType.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getInputJar(SingleJarMinecraftProvider provider) throws Exception {
|
||||
BundleMetadata serverBundleMetadata = provider.getServerBundleMetadata();
|
||||
|
||||
if (serverBundleMetadata == null) {
|
||||
return provider.getMinecraftServerJar().toPath();
|
||||
}
|
||||
|
||||
provider.extractBundledServerJar();
|
||||
return provider.getMinecraftExtractedServerJar().toPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean provideServer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean provideClient() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Client extends SingleJarForgeMinecraftProvider {
|
||||
private Client(MinecraftMetadataProvider metadataProvider, ConfigContext configContext) {
|
||||
super(metadataProvider, configContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingleJarEnvType type() {
|
||||
return SingleJarEnvType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getInputJar(SingleJarMinecraftProvider provider) throws Exception {
|
||||
return provider.getMinecraftClientJar().toPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean provideServer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean provideClient() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ public record MinecraftJarConfiguration<
|
||||
MinecraftProviderFactory<M> minecraftProviderFactory,
|
||||
IntermediaryMinecraftProviderFactory<M> intermediaryMinecraftProviderFactory,
|
||||
NamedMinecraftProviderFactory<M> namedMinecraftProviderFactory,
|
||||
SrgMinecraftProviderFactory<M> srgMinecraftProviderFactory,
|
||||
MojangMappedMinecraftProviderFactory<M> mojangMappedMinecraftProviderFactory,
|
||||
ProcessedNamedMinecraftProviderFactory<M, N> processedNamedMinecraftProviderFactory,
|
||||
DecompileConfigurationFactory<Q> decompileConfigurationFactory,
|
||||
List<String> supportedEnvironments) {
|
||||
@@ -72,6 +74,8 @@ public record MinecraftJarConfiguration<
|
||||
LegacyMergedMinecraftProvider::new,
|
||||
IntermediaryMinecraftProvider.LegacyMergedImpl::new,
|
||||
NamedMinecraftProvider.LegacyMergedImpl::new,
|
||||
SrgMinecraftProvider.LegacyMergedImpl::new,
|
||||
MojangMappedMinecraftProvider.LegacyMergedImpl::new,
|
||||
ProcessedNamedMinecraftProvider.LegacyMergedImpl::new,
|
||||
SingleJarDecompileConfiguration::new,
|
||||
List.of("client", "server")
|
||||
@@ -128,6 +132,14 @@ public record MinecraftJarConfiguration<
|
||||
return namedMinecraftProviderFactory.create(project, getMinecraftProvider(project));
|
||||
}
|
||||
|
||||
public SrgMinecraftProvider<M> createSrgMinecraftProvider(Project project) {
|
||||
return srgMinecraftProviderFactory.create(project, getMinecraftProvider(project));
|
||||
}
|
||||
|
||||
public MojangMappedMinecraftProvider<M> createMojangMappedMinecraftProvider(Project project) {
|
||||
return mojangMappedMinecraftProviderFactory.create(project, getMinecraftProvider(project));
|
||||
}
|
||||
|
||||
public ProcessedNamedMinecraftProvider<M, N> createProcessedNamedMinecraftProvider(NamedMinecraftProvider<?> namedMinecraftProvider, MinecraftJarProcessorManager jarProcessorManager) {
|
||||
return processedNamedMinecraftProviderFactory.create((N) namedMinecraftProvider, jarProcessorManager);
|
||||
}
|
||||
@@ -148,14 +160,6 @@ public record MinecraftJarConfiguration<
|
||||
return (Q) extension.getNamedMinecraftProvider();
|
||||
}
|
||||
|
||||
public BiFunction<Project, MinecraftProvider, SrgMinecraftProvider<?>> getSrgMinecraftProviderBiFunction() {
|
||||
return srgMinecraftProviderBiFunction;
|
||||
}
|
||||
|
||||
public BiFunction<Project, MinecraftProvider, MojangMappedMinecraftProvider<?>> getMojangMappedMinecraftProviderBiFunction() {
|
||||
return mojangMappedMinecraftProviderBiFunction;
|
||||
}
|
||||
|
||||
public List<String> getSupportedEnvironments() {
|
||||
return supportedEnvironments;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public abstract class MinecraftProvider {
|
||||
|
||||
public void provide() throws Exception {
|
||||
if (getExtension().shouldGenerateSrgTiny() && !getExtension().isForgeLike()) {
|
||||
getProject().getDependencies().add(Constants.Configurations.SRG, "de.oceanlabs.mcp:mcp_config:" + minecraftVersion);
|
||||
getProject().getDependencies().add(Constants.Configurations.SRG, "de.oceanlabs.mcp:mcp_config:" + minecraftVersion());
|
||||
}
|
||||
|
||||
initFiles();
|
||||
@@ -135,7 +135,7 @@ public abstract class MinecraftProvider {
|
||||
}
|
||||
}
|
||||
|
||||
protected final void extractBundledServerJar() throws IOException {
|
||||
public final void extractBundledServerJar() throws IOException {
|
||||
Preconditions.checkArgument(provideServer(), "Not configured to provide server jar");
|
||||
Objects.requireNonNull(getServerBundleMetadata(), "Cannot bundled mc jar from none bundled server jar");
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import net.fabricmc.tinyremapper.NonClassCopyMode;
|
||||
import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
|
||||
public abstract sealed class SingleJarMinecraftProvider extends MinecraftProvider permits SingleJarMinecraftProvider.Server, SingleJarMinecraftProvider.Client {
|
||||
public abstract class SingleJarMinecraftProvider extends MinecraftProvider {
|
||||
private final MappingsNamespace officialNamespace;
|
||||
private Path minecraftEnvOnlyJar;
|
||||
|
||||
@@ -127,9 +127,9 @@ public abstract sealed class SingleJarMinecraftProvider extends MinecraftProvide
|
||||
return officialNamespace;
|
||||
}
|
||||
|
||||
abstract SingleJarEnvType type();
|
||||
protected abstract SingleJarEnvType type();
|
||||
|
||||
abstract Path getInputJar(SingleJarMinecraftProvider provider) throws Exception;
|
||||
protected abstract Path getInputJar(SingleJarMinecraftProvider provider) throws Exception;
|
||||
|
||||
public static final class Server extends SingleJarMinecraftProvider {
|
||||
private Server(MinecraftMetadataProvider metadataProvider, ConfigContext configContext, MappingsNamespace officialNamespace) {
|
||||
|
||||
@@ -26,6 +26,8 @@ package net.fabricmc.loom.configuration.providers.minecraft.mapped;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.LegacyMergedMinecraftProvider;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
@@ -37,7 +39,7 @@ import net.fabricmc.loom.configuration.providers.minecraft.SplitMinecraftProvide
|
||||
import net.fabricmc.loom.util.SidedClassVisitor;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
|
||||
public abstract sealed class MojangMappedMinecraftProvider<M extends MinecraftProvider> extends AbstractMappedMinecraftProvider<M> permits MojangMappedMinecraftProvider.MergedImpl, MojangMappedMinecraftProvider.SingleJarImpl, MojangMappedMinecraftProvider.SplitImpl {
|
||||
public abstract sealed class MojangMappedMinecraftProvider<M extends MinecraftProvider> extends AbstractMappedMinecraftProvider<M> permits MojangMappedMinecraftProvider.MergedImpl, MojangMappedMinecraftProvider.LegacyMergedImpl, MojangMappedMinecraftProvider.SingleJarImpl, MojangMappedMinecraftProvider.SplitImpl {
|
||||
public MojangMappedMinecraftProvider(Project project, M minecraftProvider) {
|
||||
super(project, minecraftProvider);
|
||||
}
|
||||
@@ -65,6 +67,18 @@ public abstract sealed class MojangMappedMinecraftProvider<M extends MinecraftPr
|
||||
}
|
||||
}
|
||||
|
||||
public static final class LegacyMergedImpl extends MojangMappedMinecraftProvider<LegacyMergedMinecraftProvider> implements Merged {
|
||||
public LegacyMergedImpl(Project project, LegacyMergedMinecraftProvider minecraftProvider) {
|
||||
super(project, minecraftProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RemappedJars> getRemappedJars() {
|
||||
// The delegate providers will handle the remapping
|
||||
throw new UnsupportedOperationException("LegacyMergedImpl does not support getRemappedJars");
|
||||
}
|
||||
}
|
||||
|
||||
public static final class SplitImpl extends MojangMappedMinecraftProvider<SplitMinecraftProvider> implements Split {
|
||||
public SplitImpl(Project project, SplitMinecraftProvider minecraftProvider) {
|
||||
super(project, minecraftProvider);
|
||||
|
||||
@@ -26,6 +26,8 @@ package net.fabricmc.loom.configuration.providers.minecraft.mapped;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.LegacyMergedMinecraftProvider;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
@@ -37,7 +39,7 @@ import net.fabricmc.loom.configuration.providers.minecraft.SplitMinecraftProvide
|
||||
import net.fabricmc.loom.util.SidedClassVisitor;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
|
||||
public abstract sealed class SrgMinecraftProvider<M extends MinecraftProvider> extends AbstractMappedMinecraftProvider<M> permits SrgMinecraftProvider.MergedImpl, SrgMinecraftProvider.SingleJarImpl, SrgMinecraftProvider.SplitImpl {
|
||||
public abstract sealed class SrgMinecraftProvider<M extends MinecraftProvider> extends AbstractMappedMinecraftProvider<M> permits SrgMinecraftProvider.MergedImpl, SrgMinecraftProvider.LegacyMergedImpl, SrgMinecraftProvider.SingleJarImpl, SrgMinecraftProvider.SplitImpl {
|
||||
public SrgMinecraftProvider(Project project, M minecraftProvider) {
|
||||
super(project, minecraftProvider);
|
||||
}
|
||||
@@ -65,6 +67,18 @@ public abstract sealed class SrgMinecraftProvider<M extends MinecraftProvider> e
|
||||
}
|
||||
}
|
||||
|
||||
public static final class LegacyMergedImpl extends SrgMinecraftProvider<LegacyMergedMinecraftProvider> implements Merged {
|
||||
public LegacyMergedImpl(Project project, LegacyMergedMinecraftProvider minecraftProvider) {
|
||||
super(project, minecraftProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RemappedJars> getRemappedJars() {
|
||||
// The delegate providers will handle the remapping
|
||||
throw new UnsupportedOperationException("LegacyMergedImpl does not support getRemappedJars");
|
||||
}
|
||||
}
|
||||
|
||||
public static final class SplitImpl extends SrgMinecraftProvider<SplitMinecraftProvider> implements Split {
|
||||
public SplitImpl(Project project, SplitMinecraftProvider minecraftProvider) {
|
||||
super(project, minecraftProvider);
|
||||
|
||||
@@ -80,7 +80,7 @@ public class ForgeSourcesRemapper {
|
||||
minecraftJar = minecraftJars.get(0);
|
||||
}
|
||||
|
||||
Path sourcesJar = GenerateSourcesTask.getMappedJarFileWithSuffix("-sources.jar", minecraftJar).toPath();
|
||||
Path sourcesJar = GenerateSourcesTask.getJarFileWithSuffix("-sources.jar", minecraftJar).toPath();
|
||||
|
||||
if (!Files.exists(sourcesJar)) {
|
||||
try (var serviceManager = new ScopedSharedServiceManager()) {
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2022 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.decompilers.linemap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A line map visitor that filters entries based on the class name.
|
||||
*
|
||||
* <p>If the {@code filter} returns false for class, its declaration and
|
||||
* all contained line entries will be skipped.
|
||||
*
|
||||
* @author Juuz
|
||||
*/
|
||||
public final class LineMapClassFilter extends LineMapVisitor {
|
||||
private final Predicate<String> filter;
|
||||
private boolean active = true;
|
||||
|
||||
public LineMapClassFilter(@Nullable LineMapVisitor next, Predicate<String> filter) {
|
||||
super(next);
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitClass(String name, int max, int maxDest) throws IOException {
|
||||
active = filter.test(name);
|
||||
|
||||
if (active) {
|
||||
super.visitClass(name, max, maxDest);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLine(int src, int dest) throws IOException {
|
||||
if (active) {
|
||||
super.visitLine(src, dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2022 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.decompilers.linemap;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A reader for line map files that in the format of {@link net.fabricmc.loom.decompilers.LineNumberRemapper}.
|
||||
* {@linkplain #accept Accepts} a {@link LineMapVisitor} that processes the contents.
|
||||
*
|
||||
* @author Juuz
|
||||
*/
|
||||
public final class LineMapReader implements Closeable {
|
||||
private final BufferedReader reader;
|
||||
|
||||
public LineMapReader(BufferedReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public void accept(LineMapVisitor visitor) throws IOException {
|
||||
String line;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.isBlank()) continue;
|
||||
|
||||
String[] parts = line.trim().split("\t");
|
||||
|
||||
try {
|
||||
if (!line.startsWith("\t")) {
|
||||
visitor.visitClass(parts[0], Integer.parseInt(parts[1]), Integer.parseInt(parts[2]));
|
||||
} else {
|
||||
visitor.visitLine(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]));
|
||||
}
|
||||
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
|
||||
throw new RuntimeException("Could not parse line: " + line, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2022 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.decompilers.linemap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A visitor for line mapping files that can be read with {@link net.fabricmc.loom.decompilers.LineNumberRemapper}.
|
||||
*
|
||||
* <p>Delegates by default to a {@code next} visitor if it's not null, like ASM's {@code ClassVisitor}.
|
||||
*
|
||||
* @author Juuz
|
||||
*/
|
||||
public abstract class LineMapVisitor {
|
||||
private final LineMapVisitor next;
|
||||
|
||||
public LineMapVisitor(@Nullable LineMapVisitor next) {
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a class declaration.
|
||||
*
|
||||
* @param name the internal class name (e.g. {@code a/b/C$Nested})
|
||||
* @param max the original maximum line number in the class
|
||||
* @param maxDest the new maximum line number in the class
|
||||
*/
|
||||
public void visitClass(String name, int max, int maxDest) throws IOException {
|
||||
if (next != null) {
|
||||
next.visitClass(name, max, maxDest);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a line in the {@linkplain #visitClass previously visited class}.
|
||||
*
|
||||
* @param src the original line number
|
||||
* @param dest the mapped line number
|
||||
*/
|
||||
public void visitLine(int src, int dest) throws IOException {
|
||||
if (next != null) {
|
||||
next.visitLine(src, dest);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a line mapping file using an arbitrary visitor.
|
||||
*
|
||||
* @param path the path to the line mapping file
|
||||
* @param visitorFactory a factory that creates a "filtering" line map visitor
|
||||
*/
|
||||
public static void process(Path path, UnaryOperator<LineMapVisitor> visitorFactory) throws IOException {
|
||||
StringWriter sw = new StringWriter();
|
||||
LineMapWriter writer = new LineMapWriter(sw);
|
||||
LineMapVisitor visitor = visitorFactory.apply(writer);
|
||||
|
||||
try (LineMapReader reader = new LineMapReader(Files.newBufferedReader(path, StandardCharsets.UTF_8))) {
|
||||
reader.accept(visitor);
|
||||
}
|
||||
|
||||
Files.writeString(path, sw.toString(), StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2022 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.decompilers.linemap;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* A writer for line maps in the format of {@link net.fabricmc.loom.decompilers.LineNumberRemapper}.
|
||||
*
|
||||
* @author Juuz
|
||||
*/
|
||||
public final class LineMapWriter extends LineMapVisitor implements Closeable {
|
||||
private final Writer writer;
|
||||
|
||||
public LineMapWriter(Writer writer) {
|
||||
super(null);
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitClass(String name, int max, int maxDest) throws IOException {
|
||||
writer.append(name)
|
||||
.append('\t').append(Integer.toString(max))
|
||||
.append('\t').append(Integer.toString(maxDest))
|
||||
.append('\n');
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLine(int src, int dest) throws IOException {
|
||||
writer.append('\t').append(Integer.toString(src))
|
||||
.append('\t').append(Integer.toString(dest))
|
||||
.append('\n');
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public abstract class GenerateForgePatchedSourcesTask extends AbstractLoomTask {
|
||||
|
||||
public GenerateForgePatchedSourcesTask() {
|
||||
getOutputs().upToDateWhen((o) -> false);
|
||||
getOutputJar().fileProvider(getProject().provider(() -> GenerateSourcesTask.getMappedJarFileWithSuffix(getRuntimeJar(), "-sources.jar")));
|
||||
getOutputJar().fileProvider(getProject().provider(() -> GenerateSourcesTask.getJarFileWithSuffix(getRuntimeJar(), "-sources.jar")));
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
|
||||
@@ -41,6 +41,7 @@ import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -93,8 +94,6 @@ import net.fabricmc.loom.decompilers.LineNumberRemapper;
|
||||
import net.fabricmc.loom.decompilers.cache.CachedData;
|
||||
import net.fabricmc.loom.decompilers.cache.CachedFileStoreImpl;
|
||||
import net.fabricmc.loom.decompilers.cache.CachedJarProcessor;
|
||||
import net.fabricmc.loom.decompilers.linemap.LineMapClassFilter;
|
||||
import net.fabricmc.loom.decompilers.linemap.LineMapVisitor;
|
||||
import net.fabricmc.loom.util.Checksum;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.ExceptionUtil;
|
||||
@@ -390,6 +389,14 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
|
||||
getProject().getLogger().warn("Decompile worker logging disabled as Unix Domain Sockets is not supported on your operating system.");
|
||||
|
||||
doWork(null, inputJar, outputJar, lineMapFile, existingJar);
|
||||
|
||||
// Inject Forge's own sources
|
||||
if (getExtension().isForgeLike()) {
|
||||
try (var serviceManager = new ScopedSharedServiceManager()) {
|
||||
ForgeSourcesRemapper.addForgeSources(getProject(), serviceManager, outputJar);
|
||||
}
|
||||
}
|
||||
|
||||
return readLineNumbers(lineMapFile);
|
||||
}
|
||||
|
||||
@@ -409,7 +416,7 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
|
||||
// Inject Forge's own sources
|
||||
if (getExtension().isForgeLike()) {
|
||||
try (var serviceManager = new ScopedSharedServiceManager()) {
|
||||
ForgeSourcesRemapper.addForgeSources(getProject(), serviceManager, getOutputJar().get().getAsFile().toPath());
|
||||
ForgeSourcesRemapper.addForgeSources(getProject(), serviceManager, outputJar);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,18 +429,20 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (getParameters().getForge().get()) {
|
||||
try {
|
||||
if (getExtension().isForgeLike()) {
|
||||
// Remove Forge and NeoForge classes from linemap
|
||||
// TODO: We should instead not decompile Forge's classes at all
|
||||
LineMapVisitor.process(linemap, next -> new LineMapClassFilter(next, name -> {
|
||||
// Skip both Forge and NeoForge classes.
|
||||
return !name.startsWith("net/minecraftforge/") && !name.startsWith("net/neoforged/");
|
||||
}));
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to process linemap", e);
|
||||
var lineMap = new HashMap<String, ClassLineNumbers.Entry>();
|
||||
for (Map.Entry<String, ClassLineNumbers.Entry> entry : lineNumbers.lineMap().entrySet()) {
|
||||
String name = entry.getKey();
|
||||
if (!name.startsWith("net/minecraftforge/") && !name.startsWith("net/neoforged/")) {
|
||||
lineMap.put(name, entry.getValue());
|
||||
}
|
||||
}
|
||||
return new ClassLineNumbers(lineMap);
|
||||
} else {
|
||||
return lineNumbers;
|
||||
}
|
||||
}
|
||||
|
||||
// Re-run the named minecraft provider to give us a fresh jar to decompile.
|
||||
@@ -672,10 +681,6 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
|
||||
}
|
||||
}
|
||||
|
||||
static File getMappedJarFileWithSuffix(RegularFileProperty runtimeJar, String suffix) {
|
||||
return getMappedJarFileWithSuffix(suffix, runtimeJar.get().getAsFile().toPath());
|
||||
}
|
||||
|
||||
private Path getMappings() {
|
||||
Path inputMappings = getExtension().getPlatformMappingFile();
|
||||
|
||||
@@ -744,6 +749,10 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
|
||||
return new File(path.substring(0, path.length() - 4) + suffix);
|
||||
}
|
||||
|
||||
static File getJarFileWithSuffix(RegularFileProperty runtimeJar, String suffix) {
|
||||
return getJarFileWithSuffix(suffix, runtimeJar.get().getAsFile().toPath());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ClassLineNumbers readLineNumbers(Path linemapFile) throws IOException {
|
||||
if (Files.notExists(linemapFile)) {
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2022 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.test.unit
|
||||
|
||||
import spock.lang.Specification
|
||||
|
||||
import net.fabricmc.loom.decompilers.linemap.LineMapClassFilter
|
||||
import net.fabricmc.loom.decompilers.linemap.LineMapReader
|
||||
import net.fabricmc.loom.decompilers.linemap.LineMapWriter
|
||||
|
||||
class LineMapTest extends Specification {
|
||||
LineMapReader reader = new LineMapReader(LineMapTest.getResourceAsStream('/linemap/input.lmap').newReader('UTF-8'))
|
||||
|
||||
private String readExpected(String name) {
|
||||
return LineMapTest.getResourceAsStream("/linemap/${name}.lmap")
|
||||
.getText('UTF-8')
|
||||
.replace('\r\n', '\n')
|
||||
}
|
||||
|
||||
def "roundtrip"() {
|
||||
when:
|
||||
def sw = new StringWriter()
|
||||
reader.accept(new LineMapWriter(sw))
|
||||
reader.close()
|
||||
then:
|
||||
sw.toString() == readExpected('simpleOutput')
|
||||
}
|
||||
|
||||
def "filter"() {
|
||||
when:
|
||||
def sw = new StringWriter()
|
||||
def writer = new LineMapWriter(sw)
|
||||
reader.accept(new LineMapClassFilter(writer, { it.startsWith('test/nested/') }))
|
||||
reader.close()
|
||||
then:
|
||||
sw.toString() == readExpected('filteredOutput')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user