Skip to content

Commit

Permalink
Runner file name taking into account the quarkus properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdotcosta committed Jan 4, 2023
1 parent b0f782d commit 3bbf5c4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.StringJoiner;
import java.util.*;
import java.util.stream.Collectors;

import org.gradle.api.Action;
Expand Down Expand Up @@ -79,7 +75,8 @@ public void beforeTest(Test task) {
task.environment(BootstrapConstants.TEST_TO_MAIN_MAPPINGS, fileList);
project.getLogger().debug("test dir mapping - {}", fileList);

final String nativeRunner = task.getProject().getBuildDir().toPath().resolve(finalName() + "-runner")
final String nativeRunner = task.getProject().getBuildDir().toPath()
.resolve(buildNativeRunnerName(props))
.toAbsolutePath()
.toString();
props.put("native.image.path", nativeRunner);
Expand All @@ -88,6 +85,28 @@ public void beforeTest(Test task) {
}
}

public String buildNativeRunnerName(final Map<String, Object> taskSystemProps) {
// TODO: Take into account build.gradle configuration properties implemented by PR-29971
Properties properties = new Properties(taskSystemProps.size());
properties.putAll(taskSystemProps);
System.getProperties().entrySet()
.forEach(propEntry -> properties.putIfAbsent(propEntry.getKey(), propEntry.getValue()));
System.getenv().entrySet().forEach(
envEntry -> properties.putIfAbsent(envEntry.getKey(), envEntry.getValue()));
StringBuilder nativeRunnerName = new StringBuilder();
if (properties.containsKey("quarkus.package.output-name")) {
nativeRunnerName.append(properties.get("quarkus.package.output-name"));
} else {
nativeRunnerName.append(finalName());
}
if (!properties.containsKey("quarkus.package.add-runner-suffix")
|| (properties.containsKey("quarkus.package.add-runner-suffix")
&& Boolean.parseBoolean((String) properties.get("quarkus.package.add-runner-suffix")))) {
nativeRunnerName.append("-runner");
}
return nativeRunnerName.toString();
}

public Property<String> getFinalName() {
return finalName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,30 +119,14 @@ public QuarkusBuild manifest(Action<Manifest> action) {
return this;
}

private String buildNativeRunnerName() {
// TODO: Take into account build.gradle configuration properties implemented by PR-29971
StringBuilder nativeRunnerName = new StringBuilder();
if (getQuarkusBuildEnvProperties().containsKey("quarkus.package.output-name")) {
nativeRunnerName.append(getQuarkusBuildEnvProperties().get("quarkus.package.output-name"));
} else {
nativeRunnerName.append(extension().finalName());
}
if (!getQuarkusBuildEnvProperties().containsKey("quarkus.package.add-runner-suffix")
|| (getQuarkusBuildEnvProperties().containsKey("quarkus.package.add-runner-suffix")
&& Boolean.parseBoolean(getQuarkusBuildEnvProperties().get("quarkus.package.add-runner-suffix")))) {
nativeRunnerName.append("-runner");
}
return nativeRunnerName.toString();
}

@OutputFile
public File getRunnerJar() {
return new File(getProject().getBuildDir(), String.format("%s.jar", buildNativeRunnerName()));
return new File(getProject().getBuildDir(), String.format("%s.jar", extension().buildNativeRunnerName(Map.of())));
}

@OutputFile
public File getNativeRunner() {
return new File(getProject().getBuildDir(), buildNativeRunnerName());
return new File(getProject().getBuildDir(), extension().buildNativeRunnerName(Map.of()));
}

@OutputDirectory
Expand Down

0 comments on commit 3bbf5c4

Please sign in to comment.