Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mappings support #47

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ url=https://www.spongepowered.org
organization=SpongePowered
projectUrl=https://www.spongepowered.org

gsonVersion=2.8.7
accessWidenerVersion=1.0.2
asmVersion=9.2
checkerVersion=3.15.0
forgeFlowerVersion=1.5.498.12
junitVersion=5.7.2
mergeToolVersion=1.1.4
lorenzVersion=0.5.7
lorenzTinyVersion=4.0.2
mappingIoVersion=0.2.1
featherVersion=0.6.5.3-dev-SNAPSHOT

org.gradle.parallel=true
kotlin.stdlib.default.dependency=false
38 changes: 34 additions & 4 deletions subprojects/gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
id("com.gradle.plugin-publish")
id("net.kyori.indra.publishing.gradle-plugin")
id("org.jetbrains.gradle.plugin.idea-ext")
kotlin("jvm") version "1.5.31"
}

val commonDeps by configurations.creating {
Expand All @@ -19,6 +20,12 @@ val jarDecompile by sourceSets.creating {
val accessWiden by sourceSets.creating {
configurations.named(this.implementationConfigurationName) { extendsFrom(commonDeps) }
}
val remapTiny by sourceSets.creating {
configurations.named(this.implementationConfigurationName) { extendsFrom(commonDeps) }
}
val remapParchment by sourceSets.creating {
configurations.named(this.implementationConfigurationName) { extendsFrom(commonDeps) }
}
val shadow by sourceSets.creating {
configurations.named(this.implementationConfigurationName) { extendsFrom(commonDeps) }
}
Expand All @@ -27,11 +34,17 @@ configurations {
api { extendsFrom(commonDeps) }
}

val gsonVersion: String by project
val accessWidenerVersion: String by project
val asmVersion: String by project
val forgeFlowerVersion: String by project
val junitVersion: String by project
val mergeToolVersion: String by project
val lorenzVersion: String by project
val lorenzTinyVersion: String by project
val mappingIoVersion: String by project
val featherVersion: String by project

dependencies {
// All source sets
commonDeps(gradleApi())
Expand All @@ -43,9 +56,9 @@ dependencies {
}

// Just main
implementation("com.google.code.gson:gson:2.8.7")
implementation("org.cadixdev:lorenz:0.5.7")
implementation("org.cadixdev:lorenz-asm:0.5.7") {
implementation("com.google.code.gson:gson:$gsonVersion")
implementation("org.cadixdev:lorenz:$lorenzVersion")
implementation("org.cadixdev:lorenz-asm:$lorenzVersion") {
exclude("org.ow2.asm") // Use our own ASM
}

Expand Down Expand Up @@ -78,6 +91,18 @@ dependencies {
}
implementation(accessWiden.output)

"remapTinyCompileOnly"("org.cadixdev:lorenz:$lorenzVersion")
"remapTinyCompileOnly"("net.fabricmc:lorenz-tiny:$lorenzTinyVersion") {
isTransitive = false
}
implementation(remapTiny.output)

"remapParchmentCompileOnly"("org.cadixdev:lorenz:$lorenzVersion")
"remapParchmentCompileOnly"("com.google.code.gson:gson:$gsonVersion")
"remapParchmentCompileOnly"("org.parchmentmc:feather:$featherVersion")
"remapParchmentCompileOnly"("org.parchmentmc.feather:io-gson:$featherVersion")
implementation(remapParchment.output)

"shadowCompileOnly"("com.github.jengelman.gradle.plugins:shadow:6.1.0")
implementation(shadow.output)

Expand All @@ -97,7 +122,10 @@ tasks {
"asmVersion" to asmVersion,
"forgeFlowerVersion" to forgeFlowerVersion,
"mergeToolVersion" to mergeToolVersion,
"accessWidenerVersion" to accessWidenerVersion
"accessWidenerVersion" to accessWidenerVersion,
"lorenzTinyVersion" to lorenzTinyVersion,
"mappingIoVersion" to mappingIoVersion,
"featherVersion" to featherVersion
)
inputs.properties(properties)

Expand All @@ -124,6 +152,8 @@ tasks {
from(jarMerge.output)
from(jarDecompile.output)
from(accessWiden.output)
from(remapTiny.output)
from(remapParchment.output)
from(shadow.output)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@

import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.gradle.api.Action;
import org.gradle.api.NamedDomainObjectSet;
import org.gradle.api.PolymorphicDomainObjectContainer;
import org.gradle.api.Project;
import org.gradle.api.provider.Property;
import org.spongepowered.gradle.vanilla.repository.mappings.MappingFormat;
import org.spongepowered.gradle.vanilla.repository.MinecraftPlatform;
import org.spongepowered.gradle.vanilla.repository.MinecraftRepositoryExtension;
import org.spongepowered.gradle.vanilla.repository.mappings.MappingsContainer;
import org.spongepowered.gradle.vanilla.repository.mappings.MappingsEntry;
import org.spongepowered.gradle.vanilla.runs.RunConfigurationContainer;

/**
Expand Down Expand Up @@ -113,6 +119,24 @@ public interface MinecraftExtension extends MinecraftRepositoryExtension {
*/
void accessWideners(Object... file);

PolymorphicDomainObjectContainer<MappingFormat<@NonNull ?>> getMappingFormats();

void mappingFormats(Action<NamedDomainObjectSet<MappingFormat<@NonNull ?>>> configure);

void mappingFormats(@DelegatesTo(value = NamedDomainObjectSet.class, strategy = Closure.DELEGATE_FIRST) Closure<NamedDomainObjectSet<MappingFormat<@NonNull ?>>> configureClosure);

MappingsContainer getMappings();

void mappings(Action<MappingsContainer> configure);

void mappings(@DelegatesTo(value = MappingsContainer.class, strategy = Closure.DELEGATE_FIRST) Closure<MappingsContainer> configureClosure);

Property<String> minecraftMappings();

void minecraftMappings(MappingsEntry mappings);

void minecraftMappings(String mappings);

/**
* Get run configurations configured for this project.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public static final class WorkerDependencies {
public static final String MERGE_TOOL = "net.minecraftforge:mergetool:" + BuildVersions.MERGE_TOOL;
public static final String ACCESS_WIDENER = "net.fabricmc:access-widener:" + BuildVersions.ACCESS_WIDENER;
public static final String FORGE_FLOWER = "net.minecraftforge:forgeflower:" + BuildVersions.FORGEFLOWER;
public static final String LORENZ_TINY = "net.fabricmc:lorenz-tiny:" + BuildVersions.LORENZ_TINY;
public static final String MAPPING_IO = "net.fabricmc:mapping-io:" + BuildVersions.MAPPING_IO;
public static final String FEATHER = "org.parchmentmc:feather:" + BuildVersions.FEATHER;
public static final String FEATHER_IO_GSON = "org.parchmentmc.feather:io-gson:" + BuildVersions.FEATHER;
public static final String FORCED_ASM = BuildVersions.ASM;
public static final String ASM_UTIL = "org.ow2.asm:asm-util:" + WorkerDependencies.FORCED_ASM;

Expand Down Expand Up @@ -135,6 +139,8 @@ public static final class Configurations {
public static final String MINECRAFT_NATIVES = "minecraftNatives";
public static final String MERGETOOL = "mergetool";
public static final String ACCESS_WIDENER = "accessWidener";
public static final String REMAP_TINY = "remapTiny";
public static final String REMAP_PARCHMENT = "remapParchment";
public static final String FORGE_FLOWER = "forgeFlower";
public static final String CLASS_DUMP = "classDump";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@

import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.NamedDomainObjectSet;
import org.gradle.api.PolymorphicDomainObjectContainer;
import org.gradle.api.Project;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.DirectoryProperty;
Expand All @@ -39,6 +42,19 @@
import org.spongepowered.gradle.vanilla.MinecraftExtension;
import org.spongepowered.gradle.vanilla.internal.model.VersionClassifier;
import org.spongepowered.gradle.vanilla.internal.model.VersionDescriptor;
import org.spongepowered.gradle.vanilla.internal.repository.mappings.CSrgMappingFormat;
import org.spongepowered.gradle.vanilla.internal.repository.mappings.ObfMappingsEntry;
import org.spongepowered.gradle.vanilla.internal.repository.mappings.OfficialMappingsEntry;
import org.spongepowered.gradle.vanilla.internal.repository.mappings.ParchmentMappingFormat;
import org.spongepowered.gradle.vanilla.internal.repository.mappings.ProGuardMappingFormat;
import org.spongepowered.gradle.vanilla.internal.repository.mappings.SrgMappingFormat;
import org.spongepowered.gradle.vanilla.internal.repository.mappings.TSrgMappingFormat;
import org.spongepowered.gradle.vanilla.internal.repository.mappings.TinyMappingFormat;
import org.spongepowered.gradle.vanilla.internal.repository.mappings.XSrgMappingFormat;
import org.spongepowered.gradle.vanilla.internal.repository.modifier.MappingsModifier;
import org.spongepowered.gradle.vanilla.repository.mappings.MappingFormat;
import org.spongepowered.gradle.vanilla.repository.mappings.MappingsContainer;
import org.spongepowered.gradle.vanilla.repository.mappings.MappingsEntry;
import org.spongepowered.gradle.vanilla.repository.MinecraftPlatform;
import org.spongepowered.gradle.vanilla.internal.repository.MinecraftProviderService;
import org.spongepowered.gradle.vanilla.internal.repository.MinecraftRepositoryPlugin;
Expand All @@ -51,10 +67,10 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ExecutionException;

import javax.inject.Inject;
Expand All @@ -66,6 +82,9 @@ public class MinecraftExtensionImpl implements MinecraftExtension {
private final Property<String> version;
private final Property<MinecraftPlatform> platform;
private final Property<Boolean> injectRepositories;
private final PolymorphicDomainObjectContainer<MappingFormat<@NonNull ?>> mappingFormats;
private final MappingsContainer mappings;
private final Property<String> minecraftMappings;
private final DirectoryProperty sharedCache;
private final DirectoryProperty projectCache;
private final ConfigurableFileCollection accessWideners;
Expand All @@ -77,17 +96,32 @@ public class MinecraftExtensionImpl implements MinecraftExtension {
// Internals
private final Project project;
private final RunConfigurationContainer runConfigurations;
private volatile Set<ArtifactModifier> lazyModifiers;
private volatile List<ArtifactModifier> lazyModifiers;

@SuppressWarnings("unchecked")
@Inject
public MinecraftExtensionImpl(final Gradle gradle, final ObjectFactory factory, final Project project, final Provider<MinecraftProviderService> providerService) {
this.project = project;
this.providerService = providerService;
this.version = factory.property(String.class);
this.platform = factory.property(MinecraftPlatform.class).convention(MinecraftPlatform.JOINED);
this.injectRepositories = factory.property(Boolean.class).convention(project.provider(() -> !gradle.getPlugins().hasPlugin(MinecraftRepositoryPlugin.class))); // only inject if we aren't already in Settings
this.mappingFormats = factory.polymorphicDomainObjectContainer((Class<MappingFormat<@NonNull ?>>) (Class<?>) MappingFormat.class);
this.mappings = new MappingsContainer(project, this);
this.minecraftMappings = factory.property(String.class).convention(OfficialMappingsEntry.NAME);
this.accessWideners = factory.fileCollection();

this.mappingFormats.add(new ProGuardMappingFormat());
this.mappingFormats.add(new TinyMappingFormat());
this.mappingFormats.add(new ParchmentMappingFormat());
this.mappingFormats.add(new SrgMappingFormat());
this.mappingFormats.add(new TSrgMappingFormat());
this.mappingFormats.add(new CSrgMappingFormat());
this.mappingFormats.add(new XSrgMappingFormat());
this.mappings.add(new ObfMappingsEntry(project, this));
this.mappings.add(new OfficialMappingsEntry(project, this));


this.assetsDirectory = factory.directoryProperty();
this.sharedCache = factory.directoryProperty().convention(providerService.flatMap(it -> it.getParameters().getSharedCache()));
this.sharedCache.disallowChanges();
Expand Down Expand Up @@ -227,14 +261,64 @@ public ConfigurableFileCollection accessWideners() {
return this.accessWideners;
}

public synchronized Set<ArtifactModifier> modifiers() {
@Override
public PolymorphicDomainObjectContainer<MappingFormat<@NonNull ?>> getMappingFormats() {
return mappingFormats;
}

@Override
public void mappingFormats(Action<NamedDomainObjectSet<MappingFormat<@NonNull ?>>> configure) {
configure.execute(mappingFormats);
}

@Override
public void mappingFormats(@DelegatesTo(value = NamedDomainObjectSet.class, strategy = Closure.DELEGATE_FIRST) Closure<NamedDomainObjectSet<MappingFormat<@NonNull ?>>> configureClosure) {
ConfigureUtil.configure(configureClosure, mappingFormats);
}

@Override
public MappingsContainer getMappings() {
return mappings;
}

@Override
public void mappings(Action<MappingsContainer> configure) {
configure.execute(mappings);
}

@Override
public void mappings(@DelegatesTo(value = MappingsContainer.class, strategy = Closure.DELEGATE_FIRST) Closure<MappingsContainer> configureClosure) {
ConfigureUtil.configure(configureClosure, mappings);
}

@Override
public Property<String> minecraftMappings() {
return minecraftMappings;
}

@Override
public void minecraftMappings(MappingsEntry mappings) {
minecraftMappings(mappings.getName());
}

@Override
public void minecraftMappings(String mappings) {
this.minecraftMappings.set(mappings);
}

public synchronized List<ArtifactModifier> modifiers() {
if (this.lazyModifiers == null) {
final List<ArtifactModifier> modifiers = new ArrayList<>();

if (!minecraftMappings.get().equals(ObfMappingsEntry.NAME)) {
modifiers.add(new MappingsModifier(mappings, ObfMappingsEntry.NAME, minecraftMappings.get()));
}

this.accessWideners.disallowChanges();
final Set<ArtifactModifier> modifiers = new HashSet<>();
if (!this.accessWideners.isEmpty()) {
modifiers.add(new AccessWidenerModifier(this.accessWideners.getFiles()));
}
return this.lazyModifiers = Collections.unmodifiableSet(modifiers);
return this.lazyModifiers = Collections.unmodifiableList(modifiers);
}
return this.lazyModifiers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package org.spongepowered.gradle.vanilla.internal.bundler;

import org.immutables.value.Value;
import org.spongepowered.gradle.vanilla.internal.model.GroupArtifactVersion;

/**
* A single entry in a bundle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ public abstract class BundlerMetadata {
/**
* Attempt to read bundler metadata from a jar.
*
* <p>If the jar is not a Minecraft bundler jar, an empty {@link Optional} will be returned.</p>
* <p>If the jar is not a Minecraft bundler jar, an empty {@link Optional} will
* be returned.</p>
*
* @param jar the jar to read
* @return parsed metadata
* @throws IOException if an error occurs while trying to read from the jar
*/
public static Optional<BundlerMetadata> read(final Path jar) throws IOException {
try (final JarFile file = new JarFile(jar)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.spongepowered.gradle.vanilla.resolver.ResolutionResult;

import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import javax.inject.Inject;
Expand Down Expand Up @@ -74,8 +75,10 @@ public void execute(final ComponentMetadataSupplierDetails details) {
final MinecraftResolver resolver = providerService.resolver();
// Request the appropriate jar, block until it's provided
// TODO: maybe validate that the state keys of the provided modifiers actually match the artifact ID?
final ResolutionResult<MinecraftResolver.MinecraftEnvironment>
resolution = resolver.provide(platform.get(), version, providerService.peekModifiers()).get();
final CompletableFuture<ResolutionResult<MinecraftResolver.MinecraftEnvironment>> resolutionFuture = resolver
.provide(platform.get(), version, providerService.peekModifiers());

final ResolutionResult<MinecraftResolver.MinecraftEnvironment> resolution = resolver.processSyncTasksUntilComplete(resolutionFuture);
if (!resolution.isPresent()) {
return;
}
Expand Down
Loading