Skip to content

Commit

Permalink
Merge branch 'NG_7.0' into userdev-compile-only
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n committed Nov 29, 2023
2 parents 6c5adf6 + 9da8a2e commit 469450d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* A simple manager which configures runs based on the IDE it is attached to.
Expand Down Expand Up @@ -123,10 +124,6 @@ public void idea(Project project, IdeaModel idea, ProjectSettings ideaExtension)

}

private static String quoteAndJoin(List<String> args) {
return args.stream().map(arg -> "\"" + arg + "\"").collect(Collectors.joining(" "));
}

@Override
public void eclipse(Project project, EclipseModel eclipse) {
ProjectUtils.afterEvaluate(project, () -> {
Expand All @@ -147,11 +144,8 @@ public void eclipse(Project project, EclipseModel eclipse) {
final JavaApplicationLaunchConfig debugRun =
JavaApplicationLaunchConfig.builder(eclipse.getProject().getName())
.workingDirectory(runImpl.getWorkingDirectory().get().getAsFile().getAbsolutePath())
.vmArgs(runImpl.realiseJvmArguments().toArray(new String[0]))
.args(runImpl.getProgramArguments().get()
.stream()
.map(arg -> "\"" + arg + "\"")
.toArray(String[]::new))
.vmArgs(quoteStream(runImpl.realiseJvmArguments()).toArray(String[]::new))
.args(quoteStream(runImpl.getProgramArguments().get()).toArray(String[]::new))
.envVar(adaptEnvironment(runImpl, RunsUtil::buildRunWithEclipseModClasses))
.useArgumentsFile()
.build(runImpl.getMainClass().get());
Expand Down Expand Up @@ -179,6 +173,25 @@ public void eclipse(Project project, EclipseModel eclipse) {
});
}

private static String quoteAndJoin(List<String> args) {
return quoteStream(args).collect(Collectors.joining(" "));
}

private static Stream<String> quoteStream(List<String> args) {
return args.stream().map(RunsImportAction::quote);
}

/**
* This expects users to escape quotes in their system arguments on their own, which matches
* Gradles own behavior when used in JavaExec.
*/
private static String quote(String arg) {
if (!arg.contains(" ")) {
return arg;
}
return "\"" + arg + "\"";
}

private TaskProvider<?> createIdeBeforeRunTask(Project project, String name, Run run, RunImpl runImpl) {
final TaskProvider<?> ideBeforeRunTask = project.getTasks().register(CommonRuntimeUtils.buildTaskName("ideBeforeRun", name), task -> {
for (SourceSet sourceSet : run.getModSources().get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,14 @@ public void configureInternally(final @NotNull RunType spec) {
public List<String> realiseJvmArguments() {
final List<String> args = new ArrayList<>(getJvmArguments().get());

getSystemProperties().get().forEach((key, value) -> {
args.add(String.format("-D%s=\"%s\"", key, value));
});
// This mirrors the logic found in Gradle itself, which also does not quote key nor value
for (Map.Entry<String, String> entry : getSystemProperties().get().entrySet()) {
if (entry.getValue() != null && !entry.getValue().isEmpty()) {
args.add("-D" + entry.getKey() + "=" + entry.getValue());
} else {
args.add("-D" + entry.getKey());
}
}

return args;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.bundling.Jar;
import org.gradle.language.base.plugins.LifecycleBasePlugin;

public class UserDevProjectPlugin implements Plugin<Project> {
public static final String JAR_JAR_TASK_NAME = "jarJar";
Expand Down Expand Up @@ -39,7 +41,7 @@ protected void configureJarJarTask(Project project, JarJar jarJarExtension) {

JavaPluginExtension javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class);

project.getTasks().register(JAR_JAR_TASK_NAME, net.neoforged.gradle.common.tasks.JarJar.class, jarJar -> {
TaskProvider<net.neoforged.gradle.common.tasks.JarJar> jarJarTask = project.getTasks().register(JAR_JAR_TASK_NAME, net.neoforged.gradle.common.tasks.JarJar.class, jarJar -> {
jarJar.setGroup(JAR_JAR_GROUP);
jarJar.setDescription("Create a combined JAR of project and selected dependencies");
jarJar.getArchiveClassifier().convention("all");
Expand All @@ -54,6 +56,10 @@ protected void configureJarJarTask(Project project, JarJar jarJarExtension) {
jarJar.setEnabled(false);
});

project.getArtifacts().add(JAR_JAR_DEFAULT_CONFIGURATION_NAME, project.getTasks().named(JAR_JAR_TASK_NAME));
project.getArtifacts().add(JAR_JAR_DEFAULT_CONFIGURATION_NAME, jarJarTask);

project.getTasks().named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME, t -> {
t.dependsOn(jarJarTask);
});
}
}

0 comments on commit 469450d

Please sign in to comment.