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
ee7141cf
Commit
ee7141cf
authored
Oct 24, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow PropertyLauncher loader.path to be configured using manifest
Closes gh-7178
parent
a638dcd5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
21 deletions
+68
-21
appendix-executable-jar-format.adoc
...ocs/src/main/asciidoc/appendix-executable-jar-format.adoc
+38
-11
PropertiesLauncher.java
...a/org/springframework/boot/loader/PropertiesLauncher.java
+5
-9
PropertiesLauncherTests.java
.../springframework/boot/loader/PropertiesLauncherTests.java
+25
-0
application.properties
...rc/test/resources/BOOT-INF/classes/application.properties
+0
-1
No files found.
spring-boot-docs/src/main/asciidoc/appendix-executable-jar-format.adoc
View file @
ee7141cf
...
@@ -200,12 +200,12 @@ the appropriate launcher:
...
@@ -200,12 +200,12 @@ the appropriate launcher:
properties (System properties, environment variables, manifest entries or
properties (System properties, environment variables, manifest entries or
`application.properties`).
`application.properties`).
[cols="2,4"]
|===
|===
|Key |Purpose
|Key |Purpose
|`loader.path`
|`loader.path`
|Comma-separated Classpath, e.g. `lib,${HOME}/app/lib`. Earlier entries take precedence, just like a regular `-classpath` on the `javac` command line.
|Comma-separated Classpath, e.g. `lib,${HOME}/app/lib`. Earlier entries take precedence,
just like a regular `-classpath` on the `javac` command line.
|`loader.home`
|`loader.home`
|Location of additional properties file, e.g. `file:///opt/app`
|Location of additional properties file, e.g. `file:///opt/app`
...
@@ -227,25 +227,52 @@ properties (System properties, environment variables, manifest entries or
...
@@ -227,25 +227,52 @@ properties (System properties, environment variables, manifest entries or
|`loader.system`
|`loader.system`
|Boolean flag to indicate that all properties should be added to System properties
|Boolean flag to indicate that all properties should be added to System properties
(defaults to `false`)
(defaults to `false`)
|===
|===
Manifest entry keys are formed by capitalizing initial letters of words and changing the
When specified as environment variables or manifest entries, the following names should
separator to "`-`" from "`.`" (e.g. `Loader-Path`). The exception is `loader.main` which
be used:
is looked up as `Start-Class` in the manifest for compatibility with `JarLauncher`).
|===
|Key | Manifest entry | Environment variable
|`loader.path`
|`Loader-Path`
|`LOADER_PATH`
|`loader.home`
|
|`LOADER_HOME`
|`loader.args`
|`Loader-Args`
|`LOADER_ARGS`
|`loader.main`
|`Start-Class`
|`LOADER_MAIN`
|`loader.config.location`
|
|`LOADER_CONFIG_LOCATION`
|`loader.system`
|
|`LOADER_SYSTEM`
|===
TIP: Build plugins automatically move the `Main-Class` attribute to `Start-Class` when
TIP: Build plugins automatically move the `Main-Class` attribute to `Start-Class` when
the fat jar is built. If you are using that, specify the name of the class to launch using
the fat jar is built. If you are using that, specify the name of the class to launch using
the `Main-Class` attribute and leave out `Start-Class`.
the `Main-Class` attribute and leave out `Start-Class`.
Environment variables can be capitalized with underscore separators instead of periods.
* `loader.home` is the directory location of an additional properties file (overriding
* `loader.home` is the directory location of an additional properties file (overriding
the default) as long as `loader.config.location` is
not specified.
the default) as long as `loader.config.location` is not specified.
* `loader.path` can contain directories (scanned recursively for jar and zip files),
* `loader.path` can contain directories (scanned recursively for jar and zip files),
archive paths, or wildcard patterns (for the default JVM behavior).
archive paths, or wildcard patterns (for the default JVM behavior).
* `loader.path` (if empty) defaults to `
lib` (meaning a local directory or a nested one if
* `loader.path` (if empty) defaults to `
BOOT-INF/lib` (meaning a local directory or a
running from an archive). Because of this `PropertiesLauncher` behaves the same as
nested one if running from an archive). Because of this `PropertiesLauncher` behaves the
`JarLauncher` when no additional configuration is provided.
same as
`JarLauncher` when no additional configuration is provided.
* Placeholder replacement is done from System and environment variables plus the
* Placeholder replacement is done from System and environment variables plus the
properties file itself on all values before use.
properties file itself on all values before use.
...
...
spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java
View file @
ee7141cf
...
@@ -132,7 +132,7 @@ public class PropertiesLauncher extends Launcher {
...
@@ -132,7 +132,7 @@ public class PropertiesLauncher extends Launcher {
public
PropertiesLauncher
()
{
public
PropertiesLauncher
()
{
try
{
try
{
this
.
home
=
getHomeDirectory
();
this
.
home
=
getHomeDirectory
();
initializeProperties
(
this
.
home
);
initializeProperties
();
initializePaths
();
initializePaths
();
this
.
parent
=
createArchive
();
this
.
parent
=
createArchive
();
}
}
...
@@ -146,7 +146,7 @@ public class PropertiesLauncher extends Launcher {
...
@@ -146,7 +146,7 @@ public class PropertiesLauncher extends Launcher {
.
resolvePlaceholders
(
System
.
getProperty
(
HOME
,
"${user.dir}"
)));
.
resolvePlaceholders
(
System
.
getProperty
(
HOME
,
"${user.dir}"
)));
}
}
private
void
initializeProperties
(
File
home
)
throws
Exception
,
IOException
{
private
void
initializeProperties
()
throws
Exception
,
IOException
{
String
config
=
"classpath:BOOT-INF/classes/"
String
config
=
"classpath:BOOT-INF/classes/"
+
SystemPropertyUtils
.
resolvePlaceholders
(
+
SystemPropertyUtils
.
resolvePlaceholders
(
SystemPropertyUtils
.
getProperty
(
CONFIG_NAME
,
"application"
))
SystemPropertyUtils
.
getProperty
(
CONFIG_NAME
,
"application"
))
...
@@ -273,14 +273,10 @@ public class PropertiesLauncher extends Launcher {
...
@@ -273,14 +273,10 @@ public class PropertiesLauncher extends Launcher {
}
}
}
}
private
void
initializePaths
()
throws
IOException
{
private
void
initializePaths
()
throws
Exception
{
String
path
=
SystemPropertyUtils
.
getProperty
(
PATH
);
String
path
=
getProperty
(
PATH
);
if
(
path
==
null
)
{
path
=
this
.
properties
.
getProperty
(
PATH
);
}
if
(
path
!=
null
)
{
if
(
path
!=
null
)
{
this
.
paths
=
parsePathsProperty
(
this
.
paths
=
parsePathsProperty
(
path
);
SystemPropertyUtils
.
resolvePlaceholders
(
path
));
}
}
log
(
"Nested archive paths: "
+
this
.
paths
);
log
(
"Nested archive paths: "
+
this
.
paths
);
}
}
...
...
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java
View file @
ee7141cf
...
@@ -17,16 +17,21 @@
...
@@ -17,16 +17,21 @@
package
org
.
springframework
.
boot
.
loader
;
package
org
.
springframework
.
boot
.
loader
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.net.URLClassLoader
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.jar.Attributes
;
import
java.util.jar.Manifest
;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.rules.TemporaryFolder
;
import
org.mockito.MockitoAnnotations
;
import
org.mockito.MockitoAnnotations
;
import
org.springframework.boot.loader.archive.Archive
;
import
org.springframework.boot.loader.archive.Archive
;
...
@@ -45,6 +50,9 @@ public class PropertiesLauncherTests {
...
@@ -45,6 +50,9 @@ public class PropertiesLauncherTests {
@Rule
@Rule
public
InternalOutputCapture
output
=
new
InternalOutputCapture
();
public
InternalOutputCapture
output
=
new
InternalOutputCapture
();
@Rule
public
TemporaryFolder
temporaryFolder
=
new
TemporaryFolder
();
@Before
@Before
public
void
setup
()
throws
IOException
{
public
void
setup
()
throws
IOException
{
MockitoAnnotations
.
initMocks
(
this
);
MockitoAnnotations
.
initMocks
(
this
);
...
@@ -207,6 +215,23 @@ public class PropertiesLauncherTests {
...
@@ -207,6 +215,23 @@ public class PropertiesLauncherTests {
.
isEqualTo
(
"[foo, bar]"
);
.
isEqualTo
(
"[foo, bar]"
);
}
}
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testLoadPathCustomizedUsingManifest
()
throws
Exception
{
System
.
setProperty
(
"loader.home"
,
this
.
temporaryFolder
.
getRoot
().
getAbsolutePath
());
Manifest
manifest
=
new
Manifest
();
manifest
.
getMainAttributes
().
put
(
Attributes
.
Name
.
MANIFEST_VERSION
,
"1.0"
);
manifest
.
getMainAttributes
().
putValue
(
"Loader-Path"
,
"/foo.jar, /bar"
);
File
manifestFile
=
new
File
(
this
.
temporaryFolder
.
getRoot
(),
"META-INF/MANIFEST.MF"
);
manifestFile
.
getParentFile
().
mkdirs
();
manifest
.
write
(
new
FileOutputStream
(
manifestFile
));
PropertiesLauncher
launcher
=
new
PropertiesLauncher
();
assertThat
((
List
<
String
>)
ReflectionTestUtils
.
getField
(
launcher
,
"paths"
))
.
containsExactly
(
"/foo.jar"
,
"/bar/"
);
}
private
void
waitFor
(
String
value
)
throws
Exception
{
private
void
waitFor
(
String
value
)
throws
Exception
{
int
count
=
0
;
int
count
=
0
;
boolean
timeout
=
false
;
boolean
timeout
=
false
;
...
...
spring-boot-tools/spring-boot-loader/src/test/resources/BOOT-INF/classes/application.properties
View file @
ee7141cf
loader.main
:
demo.Application
loader.main
:
demo.Application
loader.path
:
etc/,lib,.
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