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
1e4e64aa
Commit
1e4e64aa
authored
Sep 26, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Support inlining a conf script into the default launch script"
Closes gh-9590
parent
5ee28a08
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
36 deletions
+35
-36
DefaultLaunchScript.java
...pringframework/boot/loader/tools/DefaultLaunchScript.java
+34
-36
DefaultLaunchScriptTests.java
...framework/boot/loader/tools/DefaultLaunchScriptTests.java
+1
-0
No files found.
spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/DefaultLaunchScript.java
View file @
1e4e64aa
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -16,17 +16,21 @@
...
@@ -16,17 +16,21 @@
package
org
.
springframework
.
boot
.
loader
.
tools
;
package
org
.
springframework
.
boot
.
loader
.
tools
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.nio.charset.Charset
;
import
java.nio.charset.Charset
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
import
org.springframework.util.FileCopyUtils
;
/**
/**
* Default implementation of {@link LaunchScript}. Provides the default Spring Boot launch
* Default implementation of {@link LaunchScript}. Provides the default Spring Boot launch
* script or can load a specific script File. Also support mustache style template
* script or can load a specific script File. Also support mustache style template
...
@@ -40,10 +44,13 @@ public class DefaultLaunchScript implements LaunchScript {
...
@@ -40,10 +44,13 @@ public class DefaultLaunchScript implements LaunchScript {
private
static
final
Charset
UTF_8
=
Charset
.
forName
(
"UTF-8"
);
private
static
final
Charset
UTF_8
=
Charset
.
forName
(
"UTF-8"
);
private
static
final
int
BUFFER_SIZE
=
4096
;
private
static
final
Pattern
PLACEHOLDER_PATTERN
=
Pattern
private
static
final
Pattern
PLACEHOLDER_PATTERN
=
Pattern
.
compile
(
"\\{\\{(\\w+)(:.*?)?\\}\\}(?!\\})"
);
.
compile
(
"\\{\\{(\\w+)(:.*?)?\\}\\}(?!\\})"
);
private
static
final
List
<
String
>
FILE_PATH_KEYS
=
Arrays
.
asList
(
"inlinedConfScript"
);
private
static
final
Set
<
String
>
FILE_PATH_KEYS
=
Collections
.
unmodifiableSet
(
new
HashSet
<>(
Arrays
.
asList
(
"inlinedConfScript"
)));
private
final
String
content
;
private
final
String
content
;
...
@@ -58,32 +65,34 @@ public class DefaultLaunchScript implements LaunchScript {
...
@@ -58,32 +65,34 @@ public class DefaultLaunchScript implements LaunchScript {
this
.
content
=
expandPlaceholders
(
content
,
properties
);
this
.
content
=
expandPlaceholders
(
content
,
properties
);
}
}
/**
* Loads file contents.
* @param file File to load. If null, will load default launch.script
* @return String representation of file contents.
* @throws IOException if file is not found our can't be loaded.
*/
private
String
loadContent
(
File
file
)
throws
IOException
{
private
String
loadContent
(
File
file
)
throws
IOException
{
final
byte
[]
fileBytes
;
if
(
file
==
null
)
{
if
(
file
==
null
)
{
fileBytes
=
FileCopyUtils
return
loadContent
(
getClass
().
getResourceAsStream
(
"launch.script"
));
.
copyToByteArray
(
getClass
().
getResourceAsStream
(
"launch.script"
));
}
}
else
{
return
loadContent
(
new
FileInputStream
(
file
));
fileBytes
=
FileCopyUtils
.
copyToByteArray
(
file
);
}
private
String
loadContent
(
InputStream
inputStream
)
throws
IOException
{
try
{
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
copy
(
inputStream
,
outputStream
);
return
new
String
(
outputStream
.
toByteArray
(),
UTF_8
);
}
finally
{
inputStream
.
close
();
}
}
return
new
String
(
fileBytes
,
UTF_8
);
}
}
/**
private
void
copy
(
InputStream
inputStream
,
OutputStream
outputStream
)
* Replaces variable placeholders in file with specified property values.
throws
IOException
{
* @param content String with variables defined in {{variable:default}} format.
byte
[]
buffer
=
new
byte
[
BUFFER_SIZE
];
* @param properties Key value pairs for variables to replace
int
bytesRead
=
-
1
;
* @return Updated String
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
* @throws IOException if a file property value or path is specified and the file
outputStream
.
write
(
buffer
,
0
,
bytesRead
);
* cannot be loaded.
}
*/
outputStream
.
flush
();
}
private
String
expandPlaceholders
(
String
content
,
Map
<?,
?>
properties
)
private
String
expandPlaceholders
(
String
content
,
Map
<?,
?>
properties
)
throws
IOException
{
throws
IOException
{
StringBuffer
expanded
=
new
StringBuffer
();
StringBuffer
expanded
=
new
StringBuffer
();
...
@@ -111,13 +120,6 @@ public class DefaultLaunchScript implements LaunchScript {
...
@@ -111,13 +120,6 @@ public class DefaultLaunchScript implements LaunchScript {
return
expanded
.
toString
();
return
expanded
.
toString
();
}
}
/**
* Loads file based on File object or String path.
* @param propertyValue File Object or String path to file.
* @return File contents.
* @throws IOException if a file property value or path is specified and the file
* cannot be loaded.
*/
private
String
parseFilePropertyValue
(
Object
propertyValue
)
throws
IOException
{
private
String
parseFilePropertyValue
(
Object
propertyValue
)
throws
IOException
{
if
(
propertyValue
instanceof
File
)
{
if
(
propertyValue
instanceof
File
)
{
return
loadContent
((
File
)
propertyValue
);
return
loadContent
((
File
)
propertyValue
);
...
@@ -127,10 +129,6 @@ public class DefaultLaunchScript implements LaunchScript {
...
@@ -127,10 +129,6 @@ public class DefaultLaunchScript implements LaunchScript {
}
}
}
}
/**
* The content of the launch script as a byte array.
* @return Byte representation of script.
*/
@Override
@Override
public
byte
[]
toByteArray
()
{
public
byte
[]
toByteArray
()
{
return
this
.
content
.
getBytes
(
UTF_8
);
return
this
.
content
.
getBytes
(
UTF_8
);
...
...
spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/DefaultLaunchScriptTests.java
View file @
1e4e64aa
...
@@ -34,6 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -34,6 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
*
* @author Phillip Webb
* @author Phillip Webb
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Justin Rosenberg
*/
*/
public
class
DefaultLaunchScriptTests
{
public
class
DefaultLaunchScriptTests
{
...
...
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