Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
a097f923
Commit
a097f923
authored
Jun 22, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide sensible defaults for launch script properties when using Gradle
Closes gh-4458
parent
b01efb23
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
211 additions
and
36 deletions
+211
-36
deployment.adoc
...roject/spring-boot-docs/src/main/asciidoc/deployment.adoc
+54
-25
BootJar.java
...g/springframework/boot/gradle/tasks/bundling/BootJar.java
+1
-1
BootWar.java
...g/springframework/boot/gradle/tasks/bundling/BootWar.java
+1
-1
LaunchScriptConfiguration.java
...boot/gradle/tasks/bundling/LaunchScriptConfiguration.java
+36
-0
AbstractBootArchiveTests.java
.../boot/gradle/tasks/bundling/AbstractBootArchiveTests.java
+26
-9
LaunchScriptConfigurationTests.java
...gradle/tasks/bundling/LaunchScriptConfigurationTests.java
+93
-0
No files found.
spring-boot-project/spring-boot-docs/src/main/asciidoc/deployment.adoc
View file @
a097f923
...
...
@@ -678,69 +678,98 @@ Spring Boot Maven or Gradle plugins.
The following property substitutions are supported with the default script:
[cols="1,
6
"]
[cols="1,
3,3,3
"]
|===
|Name |Description
|Name |Description
|Gradle default |Maven default
|`mode`
|The script mode. Defaults to `auto`.
|The script mode.
|`auto`
|`auto`
|`initInfoProvides`
|The `Provides` section of "`INIT INFO`". Defaults to `spring-boot-application` for Gradle
and to `${project.artifactId}` for Maven.
|The `Provides` section of "`INIT INFO`"
|`${task.baseName}`
|`${project.artifactId}`
|`initInfoRequiredStart`
|The `Required-Start` section of "`INIT INFO`". Defaults to `$remote_fs $syslog $network`.
|`Required-Start` section of "`INIT INFO`".
|`$remote_fs $syslog $network`
|`$remote_fs $syslog $network`
|`initInfoRequiredStop`
|The `Required-Stop` section of "`INIT INFO`". Defaults to `$remote_fs $syslog $network`.
|`Required-Stop` section of "`INIT INFO`".
|`$remote_fs $syslog $network`
|`$remote_fs $syslog $network`
|`initInfoDefaultStart`
|The `Default-Start` section of "`INIT INFO`". Defaults to `2 3 4 5`.
|`Default-Start` section of "`INIT INFO`".
|`2 3 4 5`
|`2 3 4 5`
|`initInfoDefaultStop`
|The `Default-Stop` section of "`INIT INFO`". Defaults to `0 1 6`.
|`Default-Stop` section of "`INIT INFO`".
|`0 1 6`
|`0 1 6`
|`initInfoShortDescription`
|The `Short-Description` section of "`INIT INFO`". Defaults to `Spring Boot Application`
for Gradle and to `${project.name}` for Maven.
|`Short-Description` section of "`INIT INFO`".
|Single-line version of `${project.description}` (falling back to `${task.baseName}`)
|`${project.name}`
|`initInfoDescription`
|The `Description` section of "`INIT INFO`". Defaults to `Spring Boot Application` for
Gradle and to `${project.description}` (falling back to `${project.name}`) for Maven.
|`Description` section of "`INIT INFO`".
|`${project.description}` (falling back to `${task.baseName}`)
|`${project.description}` (falling back to `${project.name}`)
|`initInfoChkconfig`
|The `chkconfig` section of "`INIT INFO`". Defaults to `2345 99 01`.
|`chkconfig` section of "`INIT INFO`"
|`2345 99 01`
|`2345 99 01`
|`confFolder`
|The default value for `CONF_FOLDER`. Defaults to the folder containing the jar.
|The default value for `CONF_FOLDER`
|Folder containing the jar
|Folder containing the jar
|`inlinedConfScript`
|Reference to a file script that should be inlined in the default launch script.
This can be used to set environmental variables such as `JAVA_OPTS` before any external
config files are loaded.
config files are loaded
|
|
|`logFolder`
|The default value for `LOG_FOLDER`. Only valid for an `init.d` service.
|Default value for `LOG_FOLDER`. Only valid for an `init.d` service
|
|
|`logFilename`
|The default value for `LOG_FILENAME`. Only valid for an `init.d` service.
|Default value for `LOG_FILENAME`. Only valid for an `init.d` service
|
|
|`pidFolder`
|The default value for `PID_FOLDER`. Only valid for an `init.d` service.
|Default value for `PID_FOLDER`. Only valid for an `init.d` service
|
|
|`pidFilename`
|The default value for the name of the PID file in `PID_FOLDER`. Only valid for an
`init.d` service.
|Default value for the name of the PID file in `PID_FOLDER`. Only valid for an
`init.d` service
|
|
|`useStartStopDaemon`
|Whether the `start-stop-daemon` command, when it's available, should be used to control
the process. Defaults to `true`.
the process
|`true`
|`true`
|`stopWaitTime`
|The default value for `STOP_WAIT_TIME`. Only valid for an `init.d` service.
Defaults to 60 seconds.
|Default value for `STOP_WAIT_TIME` in seconds. Only valid for an `init.d` service
|60
|60
|===
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java
View file @
a097f923
...
...
@@ -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
;
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java
View file @
a097f923
...
...
@@ -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
;
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LaunchScriptConfiguration.java
View file @
a097f923
...
...
@@ -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
;
}
}
}
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java
View file @
a097f923
...
...
@@ -24,7 +24,9 @@ import java.nio.file.attribute.PosixFilePermission;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarFile
;
...
...
@@ -64,6 +66,8 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
private
final
String
classesPath
;
private
Project
project
;
private
T
task
;
protected
AbstractBootArchiveTests
(
Class
<
T
>
taskClass
,
String
launcherClass
,
...
...
@@ -77,10 +81,12 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
@Before
public
void
createTask
()
{
try
{
Project
project
=
ProjectBuilder
.
builder
()
.
withProjectDir
(
this
.
temp
.
newFolder
()).
build
();
this
.
project
=
ProjectBuilder
.
builder
().
withProjectDir
(
this
.
temp
.
newFolder
())
.
build
();
this
.
project
.
setDescription
(
"Test project for "
+
this
.
taskClass
.
getSimpleName
());
this
.
task
=
configure
(
project
.
getTasks
().
create
(
"testArchive"
,
this
.
taskClass
));
this
.
project
.
getTasks
().
create
(
"testArchive"
,
this
.
taskClass
));
}
catch
(
IOException
ex
)
{
throw
new
RuntimeException
(
ex
);
...
...
@@ -186,8 +192,12 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this
.
task
.
setMainClassName
(
"com.example.Main"
);
this
.
task
.
launchScript
();
this
.
task
.
execute
();
Map
<
String
,
String
>
properties
=
new
HashMap
<>();
properties
.
put
(
"initInfoProvides"
,
this
.
task
.
getBaseName
());
properties
.
put
(
"initInfoShortDescription"
,
this
.
project
.
getDescription
());
properties
.
put
(
"initInfoDescription"
,
this
.
project
.
getDescription
());
assertThat
(
Files
.
readAllBytes
(
this
.
task
.
getArchivePath
().
toPath
()))
.
startsWith
(
new
DefaultLaunchScript
(
null
,
null
).
toByteArray
());
.
startsWith
(
new
DefaultLaunchScript
(
null
,
properties
).
toByteArray
());
try
{
Set
<
PosixFilePermission
>
permissions
=
Files
.
getPosixFilePermissions
(
this
.
task
.
getArchivePath
().
toPath
());
...
...
@@ -211,13 +221,20 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public
void
launchScript
PropertiesAreReplac
ed
()
throws
IOException
{
public
void
launchScript
InitInfoPropertiesCanBeCustomiz
ed
()
throws
IOException
{
this
.
task
.
setMainClassName
(
"com.example.Main"
);
this
.
task
.
launchScript
((
configuration
)
->
configuration
.
getProperties
()
.
put
(
"initInfoProvides"
,
"test property value"
));
this
.
task
.
launchScript
((
configuration
)
->
{
configuration
.
getProperties
().
put
(
"initInfoProvides"
,
"provides"
);
configuration
.
getProperties
().
put
(
"initInfoShortDescription"
,
"short description"
);
configuration
.
getProperties
().
put
(
"initInfoDescription"
,
"description"
);
});
this
.
task
.
execute
();
assertThat
(
Files
.
readAllBytes
(
this
.
task
.
getArchivePath
().
toPath
()))
.
containsSequence
(
"test property value"
.
getBytes
());
byte
[]
bytes
=
Files
.
readAllBytes
(
this
.
task
.
getArchivePath
().
toPath
());
assertThat
(
bytes
).
containsSequence
(
"Provides: provides"
.
getBytes
());
assertThat
(
bytes
)
.
containsSequence
(
"Short-Description: short description"
.
getBytes
());
assertThat
(
bytes
).
containsSequence
(
"Description: description"
.
getBytes
());
}
@Test
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/LaunchScriptConfigurationTests.java
0 → 100644
View file @
a097f923
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
gradle
.
tasks
.
bundling
;
import
org.gradle.api.Project
;
import
org.gradle.api.tasks.bundling.AbstractArchiveTask
;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* Tests for {@link LaunchScriptConfiguration}.
*
* @author Andy Wilkinson
*/
public
class
LaunchScriptConfigurationTests
{
private
final
AbstractArchiveTask
task
=
mock
(
AbstractArchiveTask
.
class
);
private
final
Project
project
=
mock
(
Project
.
class
);
@Before
public
void
setUp
()
{
given
(
this
.
task
.
getProject
()).
willReturn
(
this
.
project
);
}
@Test
public
void
initInfoProvidesUsesArchiveBaseNameByDefault
()
{
given
(
this
.
task
.
getBaseName
()).
willReturn
(
"base-name"
);
assertThat
(
new
LaunchScriptConfiguration
(
this
.
task
).
getProperties
())
.
containsEntry
(
"initInfoProvides"
,
"base-name"
);
}
@Test
public
void
initInfoShortDescriptionUsesDescriptionByDefault
()
{
given
(
this
.
project
.
getDescription
()).
willReturn
(
"Project description"
);
assertThat
(
new
LaunchScriptConfiguration
(
this
.
task
).
getProperties
())
.
containsEntry
(
"initInfoShortDescription"
,
"Project description"
);
}
@Test
public
void
initInfoShortDescriptionUsesArchiveBaseNameWhenDescriptionIsNull
()
{
given
(
this
.
task
.
getBaseName
()).
willReturn
(
"base-name"
);
assertThat
(
new
LaunchScriptConfiguration
(
this
.
task
).
getProperties
())
.
containsEntry
(
"initInfoShortDescription"
,
"base-name"
);
}
@Test
public
void
initInfoShortDescriptionUsesSingleLineVersionOfMultiLineProjectDescription
()
{
given
(
this
.
project
.
getDescription
()).
willReturn
(
"Project\ndescription"
);
assertThat
(
new
LaunchScriptConfiguration
(
this
.
task
).
getProperties
())
.
containsEntry
(
"initInfoShortDescription"
,
"Project description"
);
}
@Test
public
void
initInfoDescriptionUsesArchiveBaseNameWhenDescriptionIsNull
()
{
given
(
this
.
task
.
getBaseName
()).
willReturn
(
"base-name"
);
assertThat
(
new
LaunchScriptConfiguration
(
this
.
task
).
getProperties
())
.
containsEntry
(
"initInfoDescription"
,
"base-name"
);
}
@Test
public
void
initInfoDescriptionUsesProjectDescriptionByDefault
()
{
given
(
this
.
project
.
getDescription
()).
willReturn
(
"Project description"
);
assertThat
(
new
LaunchScriptConfiguration
(
this
.
task
).
getProperties
())
.
containsEntry
(
"initInfoDescription"
,
"Project description"
);
}
@Test
public
void
initInfoDescriptionUsesCorrectlyFormattedMultiLineProjectDescription
()
{
given
(
this
.
project
.
getDescription
()).
willReturn
(
"The\nproject\ndescription"
);
assertThat
(
new
LaunchScriptConfiguration
(
this
.
task
).
getProperties
())
.
containsEntry
(
"initInfoDescription"
,
"The\n# project\n# description"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment