diff --git a/build.gradle b/build.gradle index f508b68031..5c721675c4 100644 --- a/build.gradle +++ b/build.gradle @@ -35,6 +35,8 @@ plugins { } quiltMappings { + mappingsDir = file('mappings/') + enigmaProfileConfig = file('enigma/enigma_profile.json') unpickMeta = file('unpick/unpick.json') @@ -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 { @@ -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 diff --git a/buildSrc/src/main/java/quilt/internal/QuiltMappingsExtension.java b/buildSrc/src/main/java/quilt/internal/QuiltMappingsExtension.java index 99aca41eb5..04b159848b 100644 --- a/buildSrc/src/main/java/quilt/internal/QuiltMappingsExtension.java +++ b/buildSrc/src/main/java/quilt/internal/QuiltMappingsExtension.java @@ -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; @@ -13,6 +14,8 @@ 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 @@ -20,6 +23,13 @@ public abstract class QuiltMappingsExtension { */ public final Provider enigmaProfile; + /** + * Don't parse this to create an {@link EnigmaProfile}, use {@link #enigmaProfile} instead. + *

+ * This is exposed so it can be passed to external processes. + */ + public abstract RegularFileProperty getEnigmaProfileConfig(); + public abstract RegularFileProperty getUnpickMeta(); private final FileConstants fileConstants; @@ -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 -> { @@ -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 fileProvider) { - this.getEnigmaProfileConfigImpl().set(fileProvider); - } } diff --git a/buildSrc/src/main/java/quilt/internal/QuiltMappingsPlugin.java b/buildSrc/src/main/java/quilt/internal/QuiltMappingsPlugin.java index 41206d3f07..5f5063a8a9 100644 --- a/buildSrc/src/main/java/quilt/internal/QuiltMappingsPlugin.java +++ b/buildSrc/src/main/java/quilt/internal/QuiltMappingsPlugin.java @@ -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; @@ -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; @@ -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 { public static final String INSERT_AUTO_GENERATED_MAPPINGS_TASK_NAME = "insertAutoGeneratedMappings"; @@ -84,6 +99,11 @@ public abstract class QuiltMappingsPlugin implements Plugin { 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"; @@ -92,17 +112,37 @@ public abstract class QuiltMappingsPlugin implements Plugin { 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 provideMappingsDestFile( Provider 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 @@ -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 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." @@ -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" @@ -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") ); @@ -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") ); @@ -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 -> { @@ -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) diff --git a/buildSrc/src/main/java/quilt/internal/tasks/EnigmaProfileConsumingTask.java b/buildSrc/src/main/java/quilt/internal/tasks/EnigmaProfileConsumingTask.java index c609d3a858..3573afafca 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/EnigmaProfileConsumingTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/EnigmaProfileConsumingTask.java @@ -1,34 +1,48 @@ package quilt.internal.tasks; -import org.gradle.api.Project; import org.gradle.api.file.FileCollection; +import org.gradle.api.file.RegularFileProperty; import org.gradle.api.provider.Property; +import org.gradle.api.tasks.InputFile; import org.gradle.api.tasks.InputFiles; import org.gradle.api.tasks.Internal; import org.quiltmc.enigma.api.EnigmaProfile; -import org.quiltmc.enigma.api.service.JarIndexerService; import quilt.internal.QuiltMappingsExtension; import quilt.internal.QuiltMappingsPlugin; -import java.util.Collection; -import java.util.stream.Stream; - -import static org.quiltmc.enigma_plugin.Arguments.SIMPLE_TYPE_FIELD_NAMES_PATH; - /** * A task that takes an {@link EnigmaProfile} as input. *

- * If {@link QuiltMappingsPlugin MappingsPlugin} is applied, any {@code EnigmaProfileConsumingTask}s will use - * {@link QuiltMappingsExtension MappingsExtension}'s - * {@link QuiltMappingsExtension#enigmaProfile enigmaProfile} by default. + * If {@link QuiltMappingsPlugin MappingsPlugin} is applied: + *

*/ -public abstract class EnigmaProfileConsumingTask extends DefaultMappingsTask { +public interface EnigmaProfileConsumingTask extends MappingsTask { @Internal( "An EnigmaProfile cannot be fingerprinted. " + "Up-to-date-ness is ensured by getSimpleTypeFieldNamesFiles and its source, " + "MappingsExtension::getEnigmaProfileFile." ) - public abstract Property getEnigmaProfile(); + Property getEnigmaProfile(); + + /** + * Don't parse this to create an {@link EnigmaProfile}, use {@link #getEnigmaProfile() enigmaProfile} instead. + *

+ * This is exposed so it can be passed to external processes. + */ + @InputFile + RegularFileProperty getEnigmaProfileConfig(); /** * Holds any {@code simple_type_field_names} configuration files obtained from the @@ -38,21 +52,5 @@ public abstract class EnigmaProfileConsumingTask extends DefaultMappingsTask { * so they must be considered for up-to-date checks. */ @InputFiles - protected abstract Property getSimpleTypeFieldNamesFiles(); - - public EnigmaProfileConsumingTask(String group) { - super(group); - - final Project project = this.getProject(); - - this.getSimpleTypeFieldNamesFiles().set( - project.provider(() -> project.files( - this.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() - ) - )); - } + Property getSimpleTypeFieldNamesFiles(); } diff --git a/buildSrc/src/main/java/quilt/internal/tasks/build/AddProposedMappingsTask.java b/buildSrc/src/main/java/quilt/internal/tasks/build/AddProposedMappingsTask.java index 48b52c6d91..dd840faf8b 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/build/AddProposedMappingsTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/build/AddProposedMappingsTask.java @@ -36,10 +36,11 @@ import org.gradle.api.tasks.TaskAction; import org.jetbrains.annotations.VisibleForTesting; import quilt.internal.Constants; +import quilt.internal.tasks.DefaultMappingsTask; import quilt.internal.tasks.EnigmaProfileConsumingTask; import quilt.internal.util.ProviderUtil; -public abstract class AddProposedMappingsTask extends EnigmaProfileConsumingTask { +public abstract class AddProposedMappingsTask extends DefaultMappingsTask implements EnigmaProfileConsumingTask { @InputFile public abstract RegularFileProperty getInputJar(); diff --git a/buildSrc/src/main/java/quilt/internal/tasks/mappings/AbstractEnigmaMappingsTask.java b/buildSrc/src/main/java/quilt/internal/tasks/mappings/AbstractEnigmaMappingsTask.java new file mode 100644 index 0000000000..c5ea11f70f --- /dev/null +++ b/buildSrc/src/main/java/quilt/internal/tasks/mappings/AbstractEnigmaMappingsTask.java @@ -0,0 +1,32 @@ +package quilt.internal.tasks.mappings; + +import org.gradle.api.file.DirectoryProperty; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.tasks.InputDirectory; +import org.gradle.api.tasks.InputFile; +import org.gradle.api.tasks.JavaExec; +import quilt.internal.Constants; +import quilt.internal.tasks.EnigmaProfileConsumingTask; + +public abstract class AbstractEnigmaMappingsTask extends JavaExec implements EnigmaProfileConsumingTask { + @InputFile + public abstract RegularFileProperty getJarToMap(); + + @InputDirectory + public abstract DirectoryProperty getMappingsDir(); + + public AbstractEnigmaMappingsTask() { + this.setGroup(Constants.Groups.MAPPINGS_GROUP); + } + + @Override + public void exec() { + this.args( + "-jar", this.getJarToMap().get().getAsFile().getAbsolutePath(), + "-mappings", this.getMappingsDir().get().getAsFile().getAbsolutePath(), + "-profile", this.getEnigmaProfileConfig().get().getAsFile().getAbsolutePath() + ); + + super.exec(); + } +} diff --git a/buildSrc/src/main/java/quilt/internal/tasks/mappings/EnigmaMappingsServerTask.java b/buildSrc/src/main/java/quilt/internal/tasks/mappings/EnigmaMappingsServerTask.java index 705da0b417..1ceb0eec42 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/mappings/EnigmaMappingsServerTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/mappings/EnigmaMappingsServerTask.java @@ -1,71 +1,75 @@ package quilt.internal.tasks.mappings; -import org.gradle.api.Project; -import org.gradle.api.file.DirectoryProperty; import org.gradle.api.file.RegularFileProperty; -import org.gradle.api.tasks.InputDirectory; -import org.gradle.api.tasks.InputFile; -import org.gradle.api.tasks.JavaExec; -import quilt.internal.Constants; -import quilt.internal.tasks.MappingsTask; +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.Optional; +import org.gradle.api.tasks.OutputFile; +import org.quiltmc.enigma.network.DedicatedEnigmaServer; +import quilt.internal.util.Password; import java.util.ArrayList; import java.util.List; -public abstract class EnigmaMappingsServerTask extends JavaExec implements MappingsTask { - @InputFile - private final RegularFileProperty jarToMap; - @InputDirectory - protected abstract DirectoryProperty getMappings(); +import static quilt.internal.util.ProviderUtil.toOptional; - private final List serverArgs; +/** + * Starts a {@link DedicatedEnigmaServer}. + *

+ * Optional inputs will be passed as command line args if present. + *

+ * If {@link quilt.internal.QuiltMappingsPlugin QuiltMappingsPlugin} is applied + * the follow gradle properties will be searched for default values: + *

    + *
  • {@value quilt.internal.QuiltMappingsPlugin#ENIGMA_SERVER_PORT_PROP} then + * {@value quilt.internal.QuiltMappingsPlugin#PORT_PROP} for {@link #getPort() port} + *
  • {@value quilt.internal.QuiltMappingsPlugin#ENIGMA_SERVER_PASSWORD_PROP} then + * {@value quilt.internal.QuiltMappingsPlugin#PASSWORD_PROP} for {@link #getPassword() password} + *
  • {@value quilt.internal.QuiltMappingsPlugin#ENIGMA_SERVER_LOG_PROP} then + * {@value quilt.internal.QuiltMappingsPlugin#LOG_PROP} for the path to {@link #getLogFile() logFile} + *
  • {@value quilt.internal.QuiltMappingsPlugin#ENIGMA_SERVER_ARGS_PROP} then + * {@value quilt.internal.QuiltMappingsPlugin#ARGS_PROP} for any additional command line args + *
+ */ +public abstract class EnigmaMappingsServerTask extends AbstractEnigmaMappingsTask { + @Optional + @Input + public abstract Property getPort(); - public EnigmaMappingsServerTask() { - final Project project = this.getProject(); - this.setGroup(Constants.Groups.MAPPINGS_GROUP); - this.getMainClass().set("org.quiltmc.enigma.network.DedicatedEnigmaServer"); - this.classpath(project.getConfigurations().getByName("enigmaRuntime")); - this.jvmArgs("-Xmx2048m"); - - this.jarToMap = getObjectFactory().fileProperty(); - this.getMappings().convention(project.getLayout().dir(project.provider(() -> project.file("mappings")))); + @Optional + @Input + public abstract Property getPassword(); - this.serverArgs = new ArrayList<>(); + @Optional + @OutputFile + public abstract RegularFileProperty getLogFile(); - if (project.hasProperty("port")) { - this.serverArgs.add("-port"); - this.serverArgs.add(project.getProperties().get("port").toString()); - } - if (project.hasProperty("password")) { - this.serverArgs.add("-password"); - this.serverArgs.add(project.getProperties().get("password").toString()); - } - if (project.hasProperty("log")) { - this.serverArgs.add("-log"); - this.serverArgs.add(project.getProperties().get("log").toString()); - } else { - this.serverArgs.add("-log"); - this.serverArgs.add("build/logs/server.log"); - } - if (project.hasProperty("args")) { - this.serverArgs.addAll(List.of(project.getProperties().get("args").toString().split(" "))); - } + public EnigmaMappingsServerTask() { + // this configuration can stay here because it's what make this an EnigmaMappingsServerTask + this.getMainClass().convention(DedicatedEnigmaServer.class.getName()); } @Override public void exec() { - var args = new ArrayList<>(List.of( - "-jar", this.jarToMap.get().getAsFile().getAbsolutePath(), - "-mappings", this.getMappings().get().getAsFile().getAbsolutePath(), - "-profile", "enigma_profile.json" - )); - args.addAll(this.serverArgs); + final List optionalArgs = new ArrayList<>(); - args(args); - super.exec(); - } + toOptional(this.getPort()).ifPresent(port -> { + optionalArgs.add("-port"); + optionalArgs.add(port); + }); - public RegularFileProperty getJarToMap() { - return this.jarToMap; + toOptional(this.getPassword().map(Password::password)).ifPresent(password -> { + optionalArgs.add("-password"); + optionalArgs.add(password); + }); + + toOptional(this.getLogFile().getAsFile()).ifPresent(log -> { + optionalArgs.add("-log"); + optionalArgs.add(log.getAbsolutePath()); + }); + + this.args(optionalArgs); + + super.exec(); } } diff --git a/buildSrc/src/main/java/quilt/internal/tasks/mappings/EnigmaMappingsTask.java b/buildSrc/src/main/java/quilt/internal/tasks/mappings/EnigmaMappingsTask.java index 0d239a02df..1bacaa679a 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/mappings/EnigmaMappingsTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/mappings/EnigmaMappingsTask.java @@ -1,33 +1,8 @@ package quilt.internal.tasks.mappings; -import java.util.List; - -import org.gradle.api.file.RegularFileProperty; -import org.gradle.api.tasks.InputFile; -import org.gradle.api.tasks.JavaExec; -import quilt.internal.Constants; -import quilt.internal.tasks.MappingsTask; - -public abstract class EnigmaMappingsTask extends JavaExec implements MappingsTask { - @InputFile - public abstract RegularFileProperty getJarToMap(); - +public abstract class EnigmaMappingsTask extends AbstractEnigmaMappingsTask { public EnigmaMappingsTask() { - this.setGroup(Constants.Groups.MAPPINGS_GROUP); - this.getMainClass().set("org.quiltmc.enigma.gui.Main"); - this.classpath(this.getProject().getConfigurations().getByName("enigmaRuntime")); - this.jvmArgs("-Xmx2048m"); - } - - @Override - public void exec() { - this.args(List.of( - "-jar", this.getJarToMap().get().getAsFile().getAbsolutePath(), - // TODO eliminate project access in task action - "-mappings", this.getProject().file("mappings").getAbsolutePath(), - "-profile", "enigma_profile.json" - )); - - super.exec(); + // this configuration can stay here because it's what make this an EnigmaMappingsTask + this.getMainClass().convention(org.quiltmc.enigma.gui.Main.class.getName()); } } diff --git a/buildSrc/src/main/java/quilt/internal/util/Password.java b/buildSrc/src/main/java/quilt/internal/util/Password.java new file mode 100644 index 0000000000..731c5927b0 --- /dev/null +++ b/buildSrc/src/main/java/quilt/internal/util/Password.java @@ -0,0 +1,8 @@ +package quilt.internal.util; + +public record Password(String password) { + @Override + public String toString() { + return "