Provide sensible defaults for launch script properties when using Gradle
Closes gh-4458
This commit is contained in:
@@ -184,7 +184,7 @@ public class BootJar extends Jar implements BootArchive {
|
||||
private LaunchScriptConfiguration enableLaunchScriptIfNecessary() {
|
||||
LaunchScriptConfiguration launchScript = this.support.getLaunchScript();
|
||||
if (launchScript == null) {
|
||||
launchScript = new LaunchScriptConfiguration();
|
||||
launchScript = new LaunchScriptConfiguration(this);
|
||||
this.support.setLaunchScript(launchScript);
|
||||
}
|
||||
return launchScript;
|
||||
|
||||
@@ -162,7 +162,7 @@ public class BootWar extends War implements BootArchive {
|
||||
private LaunchScriptConfiguration enableLaunchScriptIfNecessary() {
|
||||
LaunchScriptConfiguration launchScript = this.support.getLaunchScript();
|
||||
if (launchScript == null) {
|
||||
launchScript = new LaunchScriptConfiguration();
|
||||
launchScript = new LaunchScriptConfiguration(this);
|
||||
this.support.setLaunchScript(launchScript);
|
||||
}
|
||||
return launchScript;
|
||||
|
||||
@@ -22,6 +22,9 @@ import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
|
||||
|
||||
import org.springframework.boot.loader.tools.FileUtils;
|
||||
|
||||
/**
|
||||
@@ -37,6 +40,19 @@ public class LaunchScriptConfiguration implements Serializable {
|
||||
|
||||
private File script;
|
||||
|
||||
public LaunchScriptConfiguration() {
|
||||
|
||||
}
|
||||
|
||||
LaunchScriptConfiguration(AbstractArchiveTask archiveTask) {
|
||||
Project project = archiveTask.getProject();
|
||||
putIfMissing(this.properties, "initInfoProvides", archiveTask.getBaseName());
|
||||
putIfMissing(this.properties, "initInfoShortDescription",
|
||||
removeLineBreaks(project.getDescription()), archiveTask.getBaseName());
|
||||
putIfMissing(this.properties, "initInfoDescription",
|
||||
augmentLineBreaks(project.getDescription()), archiveTask.getBaseName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the properties that are applied to the launch script when it's being
|
||||
* including in the executable archive.
|
||||
@@ -121,4 +137,24 @@ public class LaunchScriptConfiguration implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
private String removeLineBreaks(String string) {
|
||||
return (string != null ? string.replaceAll("\\s+", " ") : null);
|
||||
}
|
||||
|
||||
private String augmentLineBreaks(String string) {
|
||||
return (string != null ? string.replaceAll("\n", "\n# ") : null);
|
||||
}
|
||||
|
||||
private void putIfMissing(Map<String, String> properties, String key,
|
||||
String... valueCandidates) {
|
||||
if (!properties.containsKey(key)) {
|
||||
for (String candidate : valueCandidates) {
|
||||
if (candidate != null && !candidate.isEmpty()) {
|
||||
properties.put(key, candidate);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user