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
96bf799b
Commit
96bf799b
authored
Sep 21, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simply Gradle plugin DSL for configuring a jar or war's launch script
Closes gh-9948
parent
56d82eb6
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
57 additions
and
51 deletions
+57
-51
boot-jar-custom-launch-script.gradle
...ain/gradle/packaging/boot-jar-custom-launch-script.gradle
+0
-1
boot-jar-include-launch-script.gradle
...in/gradle/packaging/boot-jar-include-launch-script.gradle
+1
-3
boot-jar-launch-script-properties.gradle
...gradle/packaging/boot-jar-launch-script-properties.gradle
+0
-1
BootArchive.java
...ringframework/boot/gradle/tasks/bundling/BootArchive.java
+12
-5
BootArchiveSupport.java
...mework/boot/gradle/tasks/bundling/BootArchiveSupport.java
+1
-1
BootJar.java
...g/springframework/boot/gradle/tasks/bundling/BootJar.java
+15
-1
BootWar.java
...g/springframework/boot/gradle/tasks/bundling/BootWar.java
+15
-1
BootZipCopyAction.java
...amework/boot/gradle/tasks/bundling/BootZipCopyAction.java
+1
-1
LaunchScriptConfiguration.java
...boot/gradle/tasks/bundling/LaunchScriptConfiguration.java
+0
-24
AbstractBootArchiveTests.java
.../boot/gradle/tasks/bundling/AbstractBootArchiveTests.java
+4
-7
BootJarIntegrationTests.gradle
...boot/gradle/tasks/bundling/BootJarIntegrationTests.gradle
+4
-3
BootWarIntegrationTests.gradle
...boot/gradle/tasks/bundling/BootWarIntegrationTests.gradle
+4
-3
No files found.
spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/packaging/boot-jar-custom-launch-script.gradle
View file @
96bf799b
...
...
@@ -14,7 +14,6 @@ bootJar {
// tag::custom-launch-script[]
bootJar
{
launchScript
{
included
=
true
script
=
file
(
'src/custom.script'
)
}
}
...
...
spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/packaging/boot-jar-include-launch-script.gradle
View file @
96bf799b
...
...
@@ -13,8 +13,6 @@ bootJar {
// tag::include-launch-script[]
bootJar
{
launchScript
{
included
=
true
}
launchScript
()
}
// end::include-launch-script[]
spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/packaging/boot-jar-launch-script-properties.gradle
View file @
96bf799b
...
...
@@ -14,7 +14,6 @@ bootJar {
// tag::launch-script-properties[]
bootJar
{
launchScript
{
included
=
true
properties
'logFilename'
:
'example-app.log'
}
}
...
...
spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchive.java
View file @
96bf799b
...
...
@@ -67,17 +67,24 @@ public interface BootArchive extends Task {
void
requiresUnpack
(
Spec
<
FileTreeElement
>
spec
);
/**
* Returns the {@link LaunchScriptConfiguration} that will control the script
, if any,
*
that is
prepended to the archive.
* Returns the {@link LaunchScriptConfiguration} that will control the script
that is
* prepended to the archive.
*
* @return the launch script configuration
* @return the launch script configuration, or {@code null} if the launch script has
* not been configured.
*/
@Input
@Optional
LaunchScriptConfiguration
getLaunchScript
();
/**
* Applies the given {@code action} to the {@link LaunchScriptConfiguration} of this
* archive.
* Configures the archive to have a prepended launch script.
*/
void
launchScript
();
/**
* Configures the archive to have a prepended launch script, customizing its
* configuration using the given {@code action}.
*
* @param action the action to apply
*/
...
...
spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchiveSupport.java
View file @
96bf799b
...
...
@@ -61,7 +61,7 @@ class BootArchiveSupport {
private
final
String
loaderMainClass
;
private
LaunchScriptConfiguration
launchScript
=
new
LaunchScriptConfiguration
()
;
private
LaunchScriptConfiguration
launchScript
;
private
boolean
excludeDevtools
=
true
;
...
...
spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java
View file @
96bf799b
...
...
@@ -97,9 +97,14 @@ public class BootJar extends Jar implements BootArchive {
return
this
.
support
.
getLaunchScript
();
}
@Override
public
void
launchScript
()
{
enableLaunchScriptIfNecessary
();
}
@Override
public
void
launchScript
(
Action
<
LaunchScriptConfiguration
>
action
)
{
action
.
execute
(
getLaunchScript
());
action
.
execute
(
enableLaunchScriptIfNecessary
());
}
@Override
...
...
@@ -142,4 +147,13 @@ public class BootJar extends Jar implements BootArchive {
return
ZipCompression
.
DEFLATED
;
}
private
LaunchScriptConfiguration
enableLaunchScriptIfNecessary
()
{
LaunchScriptConfiguration
launchScript
=
this
.
support
.
getLaunchScript
();
if
(
launchScript
==
null
)
{
launchScript
=
new
LaunchScriptConfiguration
();
this
.
support
.
setLaunchScript
(
launchScript
);
}
return
launchScript
;
}
}
spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java
View file @
96bf799b
...
...
@@ -91,9 +91,14 @@ public class BootWar extends War implements BootArchive {
return
this
.
support
.
getLaunchScript
();
}
@Override
public
void
launchScript
()
{
enableLaunchScriptIfNecessary
();
}
@Override
public
void
launchScript
(
Action
<
LaunchScriptConfiguration
>
action
)
{
action
.
execute
(
getLaunchScript
());
action
.
execute
(
enableLaunchScriptIfNecessary
());
}
/**
...
...
@@ -150,4 +155,13 @@ public class BootWar extends War implements BootArchive {
return
ZipCompression
.
DEFLATED
;
}
private
LaunchScriptConfiguration
enableLaunchScriptIfNecessary
()
{
LaunchScriptConfiguration
launchScript
=
this
.
support
.
getLaunchScript
();
if
(
launchScript
==
null
)
{
launchScript
=
new
LaunchScriptConfiguration
();
this
.
support
.
setLaunchScript
(
launchScript
);
}
return
launchScript
;
}
}
spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java
View file @
96bf799b
...
...
@@ -183,7 +183,7 @@ class BootZipCopyAction implements CopyAction {
private
void
writeLaunchScriptIfNecessary
(
FileOutputStream
fileStream
)
{
try
{
if
(
this
.
launchScript
.
isIncluded
()
)
{
if
(
this
.
launchScript
!=
null
)
{
fileStream
.
write
(
new
DefaultLaunchScript
(
this
.
launchScript
.
getScript
(),
this
.
launchScript
.
getProperties
()).
toByteArray
());
this
.
output
.
setExecutable
(
true
);
...
...
spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LaunchScriptConfiguration.java
View file @
96bf799b
...
...
@@ -32,30 +32,10 @@ import org.springframework.boot.loader.tools.FileUtils;
*/
public
class
LaunchScriptConfiguration
implements
Serializable
{
private
boolean
included
=
false
;
private
final
Map
<
String
,
String
>
properties
=
new
HashMap
<>();
private
File
script
;
/**
* Returns whether the launch script is included. Defaults to {@code false}.
*
* @return {@code true} is the script is included, otherwise {@code false}.
*/
public
boolean
isIncluded
()
{
return
this
.
included
;
}
/**
* Sets whether the launch script is included. Defaults to {@code false}.
*
* @param included {@code true} is the script is included, otherwise {@code false}.
*/
public
void
setIncluded
(
boolean
included
)
{
this
.
included
=
included
;
}
/**
* Returns the properties that are applied to the launch script when it's being
* including in the executable archive.
...
...
@@ -100,7 +80,6 @@ public class LaunchScriptConfiguration implements Serializable {
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
(
this
.
included
?
1231
:
1237
);
result
=
prime
*
result
+
((
this
.
properties
==
null
)
?
0
:
this
.
properties
.
hashCode
());
result
=
prime
*
result
+
((
this
.
script
==
null
)
?
0
:
this
.
script
.
hashCode
());
...
...
@@ -119,9 +98,6 @@ public class LaunchScriptConfiguration implements Serializable {
return
false
;
}
LaunchScriptConfiguration
other
=
(
LaunchScriptConfiguration
)
obj
;
if
(
this
.
included
!=
other
.
included
)
{
return
false
;
}
if
(!
this
.
properties
.
equals
(
other
.
properties
))
{
return
false
;
}
...
...
spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java
View file @
96bf799b
...
...
@@ -184,7 +184,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
@Test
public
void
launchScriptCanBePrepended
()
throws
IOException
{
this
.
task
.
setMainClass
(
"com.example.Main"
);
this
.
task
.
getLaunchScript
().
setIncluded
(
true
);
this
.
task
.
launchScript
(
);
this
.
task
.
execute
();
assertThat
(
Files
.
readAllBytes
(
this
.
task
.
getArchivePath
().
toPath
()))
.
startsWith
(
new
DefaultLaunchScript
(
null
,
null
).
toByteArray
());
...
...
@@ -201,12 +201,10 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
@Test
public
void
customLaunchScriptCanBePrepended
()
throws
IOException
{
this
.
task
.
setMainClass
(
"com.example.Main"
);
LaunchScriptConfiguration
launchScript
=
this
.
task
.
getLaunchScript
();
launchScript
.
setIncluded
(
true
);
File
customScript
=
this
.
temp
.
newFile
(
"custom.script"
);
Files
.
write
(
customScript
.
toPath
(),
Arrays
.
asList
(
"custom script"
),
StandardOpenOption
.
CREATE
);
launchScript
.
setScript
(
customScript
);
this
.
task
.
launchScript
((
configuration
)
->
configuration
.
setScript
(
customScript
)
);
this
.
task
.
execute
();
assertThat
(
Files
.
readAllBytes
(
this
.
task
.
getArchivePath
().
toPath
()))
.
startsWith
(
"custom script"
.
getBytes
());
...
...
@@ -215,9 +213,8 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
@Test
public
void
launchScriptPropertiesAreReplaced
()
throws
IOException
{
this
.
task
.
setMainClass
(
"com.example.Main"
);
LaunchScriptConfiguration
launchScript
=
this
.
task
.
getLaunchScript
();
launchScript
.
setIncluded
(
true
);
launchScript
.
getProperties
().
put
(
"initInfoProvides"
,
"test property value"
);
this
.
task
.
launchScript
((
configuration
)
->
configuration
.
getProperties
()
.
put
(
"initInfoProvides"
,
"test property value"
));
this
.
task
.
execute
();
assertThat
(
Files
.
readAllBytes
(
this
.
task
.
getArchivePath
().
toPath
()))
.
containsSequence
(
"test property value"
.
getBytes
());
...
...
spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests.gradle
View file @
96bf799b
...
...
@@ -9,8 +9,9 @@ apply plugin: 'org.springframework.boot'
bootJar
{
mainClass
=
'com.example.Application'
launchScript
{
included
=
project
.
hasProperty
(
'includeLaunchScript'
)
?
includeLaunchScript
:
false
properties
'prop'
:
project
.
hasProperty
(
'launchScriptProperty'
)
?
launchScriptProperty
:
'default'
if
(
project
.
hasProperty
(
'includeLaunchScript'
)
?
includeLaunchScript
:
false
)
{
launchScript
{
properties
'prop'
:
project
.
hasProperty
(
'launchScriptProperty'
)
?
launchScriptProperty
:
'default'
}
}
}
spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests.gradle
View file @
96bf799b
...
...
@@ -9,8 +9,9 @@ apply plugin: 'org.springframework.boot'
bootWar
{
mainClass
=
'com.example.Application'
launchScript
{
included
=
project
.
hasProperty
(
'includeLaunchScript'
)
?
includeLaunchScript
:
false
properties
'prop'
:
project
.
hasProperty
(
'launchScriptProperty'
)
?
launchScriptProperty
:
'default'
if
(
project
.
hasProperty
(
'includeLaunchScript'
)
?
includeLaunchScript
:
false
)
{
launchScript
{
properties
'prop'
:
project
.
hasProperty
(
'launchScriptProperty'
)
?
launchScriptProperty
:
'default'
}
}
}
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