Skip to content

Commit

Permalink
use JavaExec::getArgumentProviders instead of overriding task action …
Browse files Browse the repository at this point in the history
…in AbstractEnigmaMappingsTask, EnigmaMappingsServerTask, and UnpickJarTask
  • Loading branch information
supersaiyansubtlety committed Oct 28, 2024
1 parent 6fc7423 commit de9df65
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 52 deletions.
9 changes: 5 additions & 4 deletions buildSrc/src/main/java/quilt/internal/plugin/MapV2Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@
* <ul>
* <li> creates the {@value UNPICK_CONFIGURATION_NAME} {@link Configuration}
* <li> adds the the {@value UNPICK_CONFIGURATION_NAME} {@link Configuration} to
* {@link UnpickJarTask}s' {@link JavaExec#classpath(Object...) classpath};
* {@value UNPICK_CONFIGURATION_NAME} must include
* {@link daomephsta.unpick.cli.Main} in order to use {@link UnpickJarTask}s
* <li> {@link TaskCollection#configureEach(Action) configures}
* {@linkplain TaskCollection#configureEach(Action) each} {@link UnpickJarTask}s'
* {@link JavaExec#classpath(Object...) classpath};<br>
* {@value UNPICK_CONFIGURATION_NAME} must include {@link daomephsta.unpick.cli.Main}
* and its dependencies in order to use {@link UnpickJarTask}s
* <li> {@linkplain TaskCollection#configureEach(Action) configures}
* the following defaults for {@link MappingsV2JarTask}s:
* <ul>
* <li> {@link MappingsV2JarTask#getUnpickMeta() unpickMeta}: {@link QuiltMappingsExtension}'s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,29 @@
import quilt.internal.task.EnigmaProfileConsumingTask;
import quilt.internal.task.MappingsDirConsumingTask;

import java.util.List;

/**
* @see QuiltMappingsBasePlugin QuiltMappingsBasePlugin's configureEach
*/
// TODO use getArgumentProviders instead of overriding exec,
// see if classpath can be set directly without the need for a configuration
@UntrackedTask(because =
"""
These input and output to the same directory, which doesn't work with Gradle's task graph.
These tasks' outputs should not be consumed by other tasks.
"""
)
public abstract class AbstractEnigmaMappingsTask extends JavaExec
implements EnigmaProfileConsumingTask, MappingsDirConsumingTask {
public abstract class AbstractEnigmaMappingsTask extends JavaExec implements
EnigmaProfileConsumingTask, MappingsDirConsumingTask {
@InputFile
public abstract RegularFileProperty getJarToMap();

public AbstractEnigmaMappingsTask() {
this.setGroup(Groups.MAPPINGS);
}

@Override
public void exec() {
this.args(
this.getArgumentProviders().add(() -> List.of(
"-jar", this.getJarToMap().get().getAsFile().getAbsolutePath(),
"-mappings", this.getMappingsDir().get().getAsFile().getAbsolutePath(),
"-profile", this.getEnigmaProfileConfig().get().getAsFile().getAbsolutePath()
);

super.exec();
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.quiltmc.enigma.network.DedicatedEnigmaServer;
import quilt.internal.plugin.EnigmaMappingsPlugin;
import quilt.internal.plugin.QuiltMappingsBasePlugin;
import quilt.internal.plugin.QuiltMappingsPlugin;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -61,29 +60,26 @@ public abstract class EnigmaMappingsServerTask extends AbstractEnigmaMappingsTas
public EnigmaMappingsServerTask() {
this.getMainClass().set(DedicatedEnigmaServer.class.getName());
this.getMainClass().finalizeValue();
}

@Override
public void exec() {
final List<String> optionalArgs = new ArrayList<>();

toOptional(this.getPort()).ifPresent(port -> {
optionalArgs.add("-" + PORT_OPTION);
optionalArgs.add(port);
});
this.getArgumentProviders().add(() -> {
final List<String> optionalArgs = new ArrayList<>();

toOptional(this.getPassword()).ifPresent(password -> {
optionalArgs.add("-" + PASSWORD_OPTION);
optionalArgs.add(password);
});
toOptional(this.getPort()).ifPresent(port -> {
optionalArgs.add("-" + PORT_OPTION);
optionalArgs.add(port);
});

toOptional(this.getLog().getAsFile()).ifPresent(log -> {
optionalArgs.add("-" + LOG_OPTION);
optionalArgs.add(log.getAbsolutePath());
});
toOptional(this.getPassword()).ifPresent(password -> {
optionalArgs.add("-" + PASSWORD_OPTION);
optionalArgs.add(password);
});

this.args(optionalArgs);
toOptional(this.getLog().getAsFile()).ifPresent(log -> {
optionalArgs.add("-" + LOG_OPTION);
optionalArgs.add(log.getAbsolutePath());
});

super.exec();
return optionalArgs;
});
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package quilt.internal.task.unpick;

import java.util.List;
import java.io.File;
import java.util.stream.Stream;

import com.google.common.collect.Streams;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.JavaExec;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskCollection;
import org.gradle.api.tasks.TaskContainer;
import quilt.internal.Constants.Groups;
import quilt.internal.plugin.MapV2Plugin;
Expand All @@ -17,7 +18,7 @@
/**
* Unpicks a jar file using {@link daomephsta.unpick.cli.Main}.
*
* @see MapV2Plugin MapV2Plugin's configuration
* @see MapV2Plugin MapV2Plugin's configureEach
*/
public abstract class UnpickJarTask extends JavaExec implements MappingsTask {
/**
Expand All @@ -42,23 +43,21 @@ public abstract class UnpickJarTask extends JavaExec implements MappingsTask {

public UnpickJarTask() {
this.setGroup(Groups.UNPICK);
// TODO see if daomephsta.unpick.cli.Main can be added to the classpath here, directly,
// eliminating the need for the unpick configuration

this.getMainClass().set(daomephsta.unpick.cli.Main.class.getName());
this.getMainClass().finalizeValue();
}

@Override
public void exec() {
this.args(List.of(
this.getInputFile().get().getAsFile().getAbsolutePath(),
this.getOutputFile().get().getAsFile().getAbsolutePath(),
this.getUnpickDefinition().get().getAsFile().getAbsolutePath(),
this.getUnpickConstantsJar().get().getAsFile().getAbsolutePath()
));

this.args(this.getDecompileClasspathFiles().getAsFileTree().getFiles());
super.exec();
this.getArgumentProviders().add(() ->
Streams.concat(
Stream.of(
this.getInputFile().get().getAsFile().getAbsolutePath(),
this.getOutputFile().get().getAsFile().getAbsolutePath(),
this.getUnpickDefinition().get().getAsFile().getAbsolutePath(),
this.getUnpickConstantsJar().get().getAsFile().getAbsolutePath()
),
this.getDecompileClasspathFiles().getAsFileTree().getFiles().stream()
.map(File::getAbsolutePath)
).toList()
);
}
}

1 comment on commit de9df65

@github-actions
Copy link

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.