Skip to content

Commit

Permalink
move mappings, mappingsUnpicked, mappingsServer, and mappingsUnpicked…
Browse files Browse the repository at this point in the history
…Server to QuiltMappingsPlugin (and fix for new enigma profile location)

extract AbstractEnigmaMappingsTask as a superclass of EnigmaMappingsTask and EnigmaMappingsServerTask
move AbstractEnigmaMappingsTasks' confuguration to QuiltMappingsPlugin (except getMainClass configuration)
expose QuiltMappingsExtension::getEnigmaProfileConfig so it can be passed to AbstractEnigmaMappingsTasks
add enigma-server dependency to buildSrc (as part of bundles.enigma.full)
convert EnigmaProfileConsumingTask to an interface
  • Loading branch information
supersaiyansubtlety committed Oct 8, 2024
1 parent 8f84a8f commit c6f2f85
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 161 deletions.
26 changes: 6 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ plugins {
}

quiltMappings {
mappingsDir = file('mappings/')

enigmaProfileConfig = file('enigma/enigma_profile.json')

unpickMeta = file('unpick/unpick.json')
Expand Down Expand Up @@ -87,12 +89,12 @@ repositories {

// TODO move at least some of these to MappingsPlugin
configurations {
enigmaRuntime
// enigmaRuntime
javadocClasspath
decompileClasspath
// decompileClasspath
unpick
hashed
intermediary
// hashed
// intermediary
}

dependencies {
Expand Down Expand Up @@ -158,22 +160,6 @@ task sourcesJar(type: Jar, dependsOn: classes) {
from sourceSets.constants.allSource
}

task mappingsUnpicked(type: EnigmaMappingsTask, dependsOn: unpickHashedJar) {
jarToMap.set unpickHashedJar.outputFile.get()
}

task mappings(type: EnigmaMappingsTask, dependsOn: "mapPerVersionMappingsJar") {
jarToMap.set quiltMappings.fileConstants.perVersionMappingsJar
}

task mappingsUnpickedServer(type: EnigmaMappingsServerTask, dependsOn: unpickHashedJar) {
jarToMap.set unpickHashedJar.outputFile.get()
}

task mappingsServer(type: EnigmaMappingsServerTask, dependsOn: "mapPerVersionMappingsJar") {
jarToMap.set project.extensions.quiltMappings.fileConstants.perVersionMappingsJar
}

// Only build jars for package infos if we need to actually expose stuff like annotation in the future.

build.dependsOn constantsJar, generatePackageInfoMappings
Expand Down
27 changes: 11 additions & 16 deletions buildSrc/src/main/java/quilt/internal/QuiltMappingsExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.RegularFile;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Provider;
Expand All @@ -13,13 +14,22 @@
public abstract class QuiltMappingsExtension {
public static final String EXTENSION_NAME = "quiltMappings";

public abstract DirectoryProperty getMappingsDir();

// TODO see if this can use a BuildService
/**
* {@link QuiltMappingsPlugin} configures all
* {@link quilt.internal.tasks.EnigmaProfileConsumingTask EnigmaProfileConsumingTask}s to use this profile.
*/
public final Provider<EnigmaProfile> enigmaProfile;

/**
* Don't parse this to create an {@link EnigmaProfile}, use {@link #enigmaProfile} instead.
* <p>
* This is exposed so it can be passed to external processes.
*/
public abstract RegularFileProperty getEnigmaProfileConfig();

public abstract RegularFileProperty getUnpickMeta();

private final FileConstants fileConstants;
Expand All @@ -28,12 +38,10 @@ public static QuiltMappingsExtension get(Project project) {
return project.getExtensions().getByType(QuiltMappingsExtension.class);
}

protected abstract RegularFileProperty getEnigmaProfileConfigImpl();

public QuiltMappingsExtension(Project project) {
this.fileConstants = new FileConstants(project);

this.enigmaProfile = this.getEnigmaProfileConfigImpl()
this.enigmaProfile = this.getEnigmaProfileConfig()
.map(RegularFile::getAsFile)
.map(File::toPath)
.map(profilePath -> {
Expand All @@ -48,17 +56,4 @@ public QuiltMappingsExtension(Project project) {
public FileConstants getFileConstants() {
return this.fileConstants;
}

// TODO is there a cleaner way to only expose setters?
public void setEnigmaProfileConfig(File file) {
this.getEnigmaProfileConfigImpl().set(file);
}

public void setEnigmaProfileConfig(RegularFile file) {
this.getEnigmaProfileConfigImpl().set(file);
}

public void setEnigmaProfileConfig(Provider<? extends RegularFile> fileProvider) {
this.getEnigmaProfileConfigImpl().set(fileProvider);
}
}
136 changes: 122 additions & 14 deletions buildSrc/src/main/java/quilt/internal/QuiltMappingsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.file.Directory;
import org.gradle.api.file.RegularFile;
import org.gradle.api.plugins.ExtensionContainer;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.bundling.Jar;
import org.jetbrains.annotations.NotNull;
import org.quiltmc.enigma.api.service.JarIndexerService;
import quilt.internal.decompile.Decompilers;
import quilt.internal.tasks.EnigmaProfileConsumingTask;
import quilt.internal.tasks.build.AddProposedMappingsTask;
Expand Down Expand Up @@ -44,6 +48,9 @@
import quilt.internal.tasks.lint.DownloadDictionaryFileTask;
import quilt.internal.tasks.lint.FindDuplicateMappingFilesTask;
import quilt.internal.tasks.lint.MappingLintTask;
import quilt.internal.tasks.mappings.AbstractEnigmaMappingsTask;
import quilt.internal.tasks.mappings.EnigmaMappingsServerTask;
import quilt.internal.tasks.mappings.EnigmaMappingsTask;
import quilt.internal.tasks.setup.CheckIntermediaryMappingsTask;
import quilt.internal.tasks.setup.DownloadIntermediaryMappingsTask;
import quilt.internal.tasks.setup.DownloadMappingsTask;
Expand All @@ -59,16 +66,24 @@
import quilt.internal.tasks.unpick.UnpickJarTask;
import quilt.internal.tasks.unpick.gen.OpenGlConstantUnpickGenTask;
import quilt.internal.tasks.unpick.gen.UnpickGenTask;
import quilt.internal.util.Password;
import quilt.internal.util.ProviderUtil;

import javax.inject.Inject;
import java.io.File;
import java.nio.file.Path;
import java.util.Collection;
import java.util.stream.Stream;

import static quilt.internal.util.ProviderUtil.provideProjectDir;
import static quilt.internal.util.ProviderUtil.toOptional;

import static org.quiltmc.enigma_plugin.Arguments.SIMPLE_TYPE_FIELD_NAMES_PATH;

// TODO extract common providers, possibly convert FileConstants to providers instead of files

/**
* TODO javadoc, including every configureEach
* TODO javadoc, including every configureEach, every configuration
*/
public abstract class QuiltMappingsPlugin implements Plugin<Project> {
public static final String INSERT_AUTO_GENERATED_MAPPINGS_TASK_NAME = "insertAutoGeneratedMappings";
Expand All @@ -84,6 +99,11 @@ public abstract class QuiltMappingsPlugin implements Plugin<Project> {
public static final String ARCHIVE_FILE_NAME_PREFIX =
Constants.MAPPINGS_NAME + "-" + Constants.MAPPINGS_VERSION + "-";

public static final String ENIGMA_RUNTIME_CONFIGURATION_NAME = "enigmaRuntime";
public static final String DECOMPILE_CLASSPATH_CONFIGURATION_NAME = "decompileClasspath";
public static final String PER_VERSION_MAPPINGS_CONFIGURATION_NAME = Constants.PER_VERSION_MAPPINGS_NAME;
public static final String INTERMEDIARY_MAPPINGS_CONFIGURATION_NAME = Constants.INTERMEDIARY_MAPPINGS_NAME;

public static final String DECOMPILE_TARGET_VINEFLOWER_TASK_NAME = "decompileTargetVineflower";
public static final String CONSTANTS_JAR_TASK_NAME = "constantsJar";
public static final String UNPICK_HASHED_JAR_TASK_NAME = "unpickHashedJar";
Expand All @@ -92,17 +112,37 @@ public abstract class QuiltMappingsPlugin implements Plugin<Project> {
public static final String INTERMEDIARY_V_2_MAPPINGS_JAR_TASK_NAME = "intermediaryV2MappingsJar";
public static final String INTERMEDIARY_V_2_MERGED_MAPPINGS_JAR_TASK_NAME = "intermediaryV2MergedMappingsJar";
public static final String BUILD_INTERMEDIARY_TASK_NAME = "buildIntermediary";
public static final String MAPPINGS_UNPICKED_TASK_NAME = "mappingsUnpicked";
public static final String MAPPINGS_TASK_NAME = "mappings";
public static final String MAPPINGS_UNPICKED_SERVER_TASK_NAME = "mappingsUnpickedServer";
public static final String MAPPINGS_SERVER_TASK_NAME = "mappingsServer";

private static final String QUILT_MAPPINGS_PREFIX = "quilt-mappings-";

private static final String ENIGMA_SERVER_PROP_PREFIX = "enigma_server_";
public static final String PORT_PROP = "port";
public static final String ENIGMA_SERVER_PORT_PROP = ENIGMA_SERVER_PROP_PREFIX + PORT_PROP;
public static final String PASSWORD_PROP = "password";
public static final String ENIGMA_SERVER_PASSWORD_PROP = ENIGMA_SERVER_PROP_PREFIX + PASSWORD_PROP;
public static final String LOG_PROP = "log";
public static final String ENIGMA_SERVER_LOG_PROP = ENIGMA_SERVER_PROP_PREFIX + LOG_PROP;
public static final String ARGS_PROP = "args";
public static final String ENIGMA_SERVER_ARGS_PROP = ENIGMA_SERVER_PROP_PREFIX + ARGS_PROP;

public static Provider<RegularFile> provideMappingsDestFile(
Provider<Directory> destDir, String mappingsName, String fileExt
) {
return destDir.map(dir -> dir.file(Constants.MINECRAFT_VERSION + "-" + mappingsName + "." + fileExt));
}

@Inject
@NotNull
public abstract ProviderFactory getProviders();

@Override
public void apply(@NotNull Project project) {
final ProviderFactory providers = this.getProviders();

final ExtensionContainer extensions = project.getExtensions();

// adds the JavaPluginExtension
Expand All @@ -112,17 +152,38 @@ public void apply(@NotNull Project project) {

final var ext = extensions.create(QuiltMappingsExtension.EXTENSION_NAME, QuiltMappingsExtension.class, project);

final ConfigurationContainer configurations = project.getConfigurations();

final Configuration enigmaRuntime = configurations.create(ENIGMA_RUNTIME_CONFIGURATION_NAME);
final Configuration decompileClasspath = configurations.create(DECOMPILE_CLASSPATH_CONFIGURATION_NAME);
final Configuration preVersionMappings = configurations.create(PER_VERSION_MAPPINGS_CONFIGURATION_NAME);
final Configuration intermediaryMappings = configurations.create(INTERMEDIARY_MAPPINGS_CONFIGURATION_NAME);

final TaskContainer tasks = project.getTasks();

final Provider<Directory> mappingsDestDir =
provideProjectDir(project, ext.getFileConstants().cacheFilesMinecraft);

tasks.withType(EnigmaProfileConsumingTask.class).configureEach(task ->
task.getEnigmaProfile().convention(ext.enigmaProfile)
);
tasks.withType(EnigmaProfileConsumingTask.class).configureEach(task -> {
task.getEnigmaProfile().convention(ext.enigmaProfile);

task.getEnigmaProfileConfig().convention(ext.getEnigmaProfileConfig());

task.getSimpleTypeFieldNamesFiles().convention(
project.provider(() -> project.files(
task.getEnigmaProfile().get().getServiceProfiles(JarIndexerService.TYPE).stream()
.flatMap(service -> service.getArgument(SIMPLE_TYPE_FIELD_NAMES_PATH).stream())
.map(stringOrStrings -> stringOrStrings.mapBoth(Stream::of, Collection::stream))
.flatMap(bothStringStreams ->
bothStringStreams.left().orElseGet(bothStringStreams::rightOrThrow)
)
.toList()
))
);
});

// provide an informative error message if no profile is specified
ext.getEnigmaProfileConfigImpl().convention(() -> {
ext.getEnigmaProfileConfig().convention(() -> {
throw new GradleException(
"No enigma profile specified. " +
"A profile must be specified to use an EnigmaProfileConsumingTask."
Expand Down Expand Up @@ -163,6 +224,7 @@ public void apply(@NotNull Project project) {
ext.getFileConstants().cacheFilesMinecraft,
Constants.MINECRAFT_VERSION + "-client.jar"
));

task.getServerBootstrapJar().convention(() -> new File(
ext.getFileConstants().cacheFilesMinecraft,
Constants.MINECRAFT_VERSION + "-server-bootstrap.jar"
Expand Down Expand Up @@ -212,9 +274,8 @@ public void apply(@NotNull Project project) {
final var downloadPerVersionMappings = tasks.register(
DOWNLOAD_PER_VERSION_MAPPINGS_TASK_NAME, DownloadMappingsTask.class,
task -> {
task.getMappingsConfiguration().convention(
project.getConfigurations().named(Constants.PER_VERSION_MAPPINGS_NAME)
);
task.getMappingsConfiguration().convention(preVersionMappings);

task.getJarFile().convention(
provideMappingsDestFile(mappingsDestDir, Constants.PER_VERSION_MAPPINGS_NAME, "jar")
);
Expand Down Expand Up @@ -349,9 +410,8 @@ public void apply(@NotNull Project project) {
// TODO eliminate this
task.dependsOn(checkIntermediaryMappings);

task.getMappingsConfiguration().convention(
project.getConfigurations().named(Constants.INTERMEDIARY_MAPPINGS_NAME)
);
task.getMappingsConfiguration().convention(intermediaryMappings);

task.getJarFile().convention(
provideMappingsDestFile(mappingsDestDir, Constants.INTERMEDIARY_MAPPINGS_NAME, "jar")
);
Expand Down Expand Up @@ -452,6 +512,56 @@ public void apply(@NotNull Project project) {
task.getOutputJar().convention(() -> ext.getFileConstants().namedJar);
});

tasks.withType(AbstractEnigmaMappingsTask.class).configureEach(task -> {
task.getMappingsDir().convention(ext.getMappingsDir());

task.classpath(enigmaRuntime);

task.jvmArgs("-Xmx2048m");
});

tasks.register(MAPPINGS_UNPICKED_TASK_NAME, EnigmaMappingsTask.class, task -> {
task.getJarToMap().convention(unpickHashedJar.flatMap(UnpickJarTask::getOutputFile));
});

tasks.register(MAPPINGS_TASK_NAME, EnigmaMappingsTask.class, task -> {
task.getJarToMap().convention(mapPerVersionMappingsJar.flatMap(MapPerVersionMappingsJarTask::getOutputJar));
});

tasks.withType(EnigmaMappingsServerTask.class).configureEach(task -> {
task.getPort().convention(
providers.gradleProperty(ENIGMA_SERVER_PORT_PROP)
.orElse(providers.gradleProperty(PORT_PROP))
);

task.getPassword().convention(
providers.gradleProperty(ENIGMA_SERVER_PASSWORD_PROP)
.orElse(providers.gradleProperty(PASSWORD_PROP))
.map(Password::new)
);

task.getLogFile().convention(
providers.gradleProperty(ENIGMA_SERVER_LOG_PROP)
.orElse(providers.gradleProperty(LOG_PROP))
.map(project.getLayout().getProjectDirectory()::file)
.orElse(project.getLayout().getBuildDirectory().file("logs/server.log"))
);

toOptional(
providers.gradleProperty(ENIGMA_SERVER_ARGS_PROP)
.orElse(providers.gradleProperty(ARGS_PROP))
.map(args -> args.split(" "))
).ifPresent(task::args);
});

tasks.register(MAPPINGS_UNPICKED_SERVER_TASK_NAME, EnigmaMappingsServerTask.class, task -> {
task.getJarToMap().convention(unpickHashedJar.flatMap(UnpickJarTask::getOutputFile));
});

tasks.register(MAPPINGS_SERVER_TASK_NAME, EnigmaMappingsServerTask.class, task -> {
task.getJarToMap().convention(mapPerVersionMappingsJar.flatMap(MapJarTask::getOutputJar));
});

final var extractTinyIntermediaryMappings = tasks.register(
EXTRACT_TINY_INTERMEDIARY_MAPPINGS_TASK_NAME, ExtractTinyMappingsTask.class,
task -> {
Expand Down Expand Up @@ -636,9 +746,7 @@ public void apply(@NotNull Project project) {

task.getInput().convention(remapTargetMinecraftJar.flatMap(RemapTargetMinecraftJarTask::getOutputJar));

task.getLibraries().convention(
project.files(project.getConfigurations().named("decompileClasspath"))
);
task.getLibraries().convention(project.files(decompileClasspath));

task.getTargetMappingsFile().convention(
extractTargetMappingsJar.flatMap(ExtractTargetMappingJarTask::getExtractionDest)
Expand Down
Loading

0 comments on commit c6f2f85

Please sign in to comment.