Skip to content

Commit

Permalink
Allow for multiple run types
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Nov 21, 2023
1 parent 23ec387 commit 5331692
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class RunImpl implements ConfigurableDSLElement<Run>, Run {
private MapProperty<String, String> environmentVariables;
private ListProperty<String> programArguments;
private MapProperty<String, String> systemProperties;
private final Property<RunType> runType;
private final ListProperty<RunType> runTypes;

private final Set<TaskProvider<? extends Task>> dependencies = Sets.newHashSet();

Expand All @@ -43,7 +43,7 @@ public RunImpl(final Project project, final String name) {
this.environmentVariables = this.project.getObjects().mapProperty(String.class, String.class);
this.programArguments = this.project.getObjects().listProperty(String.class);
this.systemProperties = this.project.getObjects().mapProperty(String.class, String.class);
this.runType = this.project.getObjects().property(RunType.class);
this.runTypes = this.project.getObjects().listProperty(RunType.class);

getIsSingleInstance().convention(true);
getIsClient().convention(false);
Expand Down Expand Up @@ -118,29 +118,30 @@ public Set<TaskProvider<? extends Task>> getTaskDependencies() {

@Override
public final void configure() {
if (getConfigureFromTypeWithName().get() && !runType.isPresent()) {
runType.set(getRunTypeProviderByName(name));
if (getConfigureFromTypeWithName().get()) {
configureInternally(getRunTypeProviderByName(name).get());
}

if (runType.isPresent()) {
configureInternally(runType.get());
for (RunType runType : runTypes.get()) {
configureInternally(runType);
}
}

@Override
public final void configure(final @NotNull String name) {
runType.set(getRunTypeProviderByName(name));
getConfigureFromTypeWithName().set(false); // Don't re-configure
runTypes.add(getRunTypeProviderByName(name));
}

@Override
public final void configure(final @NotNull RunType runType) {
getConfigureFromTypeWithName().set(false); // Don't re-configure
this.runType.set(runType);
this.runTypes.add(runType);
}

@Override
public void configure(@NotNull Provider<RunType> typeProvider) {
this.runType.set(typeProvider);
this.runTypes.add(typeProvider);
}

@SafeVarargs
Expand All @@ -150,6 +151,7 @@ public final void dependsOn(TaskProvider<? extends Task>... tasks) {
}

public void configureInternally(final @NotNull RunType spec) {
project.getLogger().debug("Configuring run {} with run type {}", name, spec.getName());
getEnvironmentVariables().putAll(spec.getEnvironmentVariables());
getMainClass().convention(spec.getMainClass());
getProgramArguments().addAll(spec.getArguments());
Expand Down

0 comments on commit 5331692

Please sign in to comment.