Skip to content

Commit

Permalink
Add a mappings server task (#644)
Browse files Browse the repository at this point in the history
* Add a mappings server task

* Generate arg list in task constructor

* Fix mappings server task

* Make mappings dir a task input

* Apply suggestions from code review

Co-authored-by: Will <[email protected]>

* Update buildSrc/src/main/java/quilt/internal/tasks/mappings/EnigmaMappingsServerTask.java

Co-authored-by: Will <[email protected]>

---------

Co-authored-by: Will <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 3, 2024
1 parent 9956e25 commit d03d93b
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ import quilt.internal.tasks.build.TransformJarClassesTask
import quilt.internal.tasks.decompile.DecompileTask
import quilt.internal.tasks.jarmapping.MapPerVersionMappingsJarTask
import quilt.internal.tasks.mappings.EnigmaMappingsTask
import quilt.internal.tasks.mappings.EnigmaMappingsServerTask
import quilt.internal.tasks.unpick.RemapUnpickDefinitionsTask
import quilt.internal.tasks.unpick.UnpickJarTask
import quilt.internal.util.MappingsJavadocProvider
Expand Down Expand Up @@ -185,6 +186,14 @@ task mappings(type: EnigmaMappingsTask, dependsOn: "mapPerVersionMappingsJar") {
jarToMap.set mappings.fileConstants.perVersionMappingsJar
}

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

task mappingsServer(type: EnigmaMappingsServerTask, dependsOn: "mapPerVersionMappingsJar") {
jarToMap.set project.extensions.mappings.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
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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 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();

private final List<String> serverArgs;

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"))));

this.serverArgs = new ArrayList<>();

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(" ")));
}
}

@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);

args(args);
super.exec();
}

public RegularFileProperty getJarToMap() {
return this.jarToMap;
}
}

1 comment on commit d03d93b

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No difference between head and target.

Please sign in to comment.