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
e9fd7c96
Commit
e9fd7c96
authored
Sep 19, 2013
by
Phillip Webb
Committed by
Dave Syer
Sep 24, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Loader changes
parent
053c0721
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
249 additions
and
277 deletions
+249
-277
Launcher.java
...c/main/java/org/springframework/boot/loader/Launcher.java
+0
-4
PropertiesLauncher.java
...a/org/springframework/boot/loader/PropertiesLauncher.java
+152
-150
SystemPropertyUtils.java
...springframework/boot/loader/util/SystemPropertyUtils.java
+93
-122
PropertiesLauncherTests.java
.../springframework/boot/loader/PropertiesLauncherTests.java
+4
-1
No files found.
spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java
View file @
e9fd7c96
...
@@ -195,8 +195,4 @@ public abstract class Launcher {
...
@@ -195,8 +195,4 @@ public abstract class Launcher {
return
(
Runnable
)
constructor
.
newInstance
(
mainClass
,
args
);
return
(
Runnable
)
constructor
.
newInstance
(
mainClass
,
args
);
}
}
protected
boolean
isArchive
(
String
name
)
{
return
name
.
endsWith
(
".jar"
)
||
name
.
endsWith
(
".zip"
);
}
}
}
spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java
View file @
e9fd7c96
This diff is collapsed.
Click to expand it.
spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/util/SystemPropertyUtils.java
View file @
e9fd7c96
...
@@ -19,8 +19,6 @@ package org.springframework.boot.loader.util;
...
@@ -19,8 +19,6 @@ package org.springframework.boot.loader.util;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.Set
;
import
org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver
;
/**
/**
* Helper class for resolving placeholders in texts. Usually applied to file paths.
* Helper class for resolving placeholders in texts. Usually applied to file paths.
*
*
...
@@ -50,7 +48,7 @@ public abstract class SystemPropertyUtils {
...
@@ -50,7 +48,7 @@ public abstract class SystemPropertyUtils {
/** Value separator for system property placeholders: ":" */
/** Value separator for system property placeholders: ":" */
public
static
final
String
VALUE_SEPARATOR
=
":"
;
public
static
final
String
VALUE_SEPARATOR
=
":"
;
private
static
final
PropertyPlaceholderHelper
helper
=
new
PropertyPlaceholderHelper
(
);
private
static
final
String
SIMPLE_PREFIX
=
PLACEHOLDER_PREFIX
.
substring
(
1
);
/**
/**
* Resolve ${...} placeholders in the given text, replacing them with corresponding
* Resolve ${...} placeholders in the given text, replacing them with corresponding
...
@@ -62,147 +60,120 @@ public abstract class SystemPropertyUtils {
...
@@ -62,147 +60,120 @@ public abstract class SystemPropertyUtils {
* @throws IllegalArgumentException if there is an unresolvable placeholder
* @throws IllegalArgumentException if there is an unresolvable placeholder
*/
*/
public
static
String
resolvePlaceholders
(
String
text
)
{
public
static
String
resolvePlaceholders
(
String
text
)
{
return
helper
.
replacePlaceholders
(
text
);
if
(
text
==
null
)
{
}
throw
new
IllegalArgumentException
(
"Argument 'value' must not be null."
);
static
protected
class
PropertyPlaceholderHelper
{
private
static
final
String
simplePrefix
=
PLACEHOLDER_PREFIX
.
substring
(
1
);
/**
* Replaces all placeholders of format {@code $ name} with the value returned from
* the supplied {@link PlaceholderResolver}.
* @param value the value containing the placeholders to be replaced.
* @return the supplied value with placeholders replaced inline.
*/
public
String
replacePlaceholders
(
String
value
)
{
Assert
.
notNull
(
value
,
"Argument 'value' must not be null."
);
return
parseStringValue
(
value
,
value
,
new
HashSet
<
String
>());
}
}
return
parseStringValue
(
text
,
text
,
new
HashSet
<
String
>());
}
private
String
parseStringValue
(
String
value
,
String
current
,
private
static
String
parseStringValue
(
String
value
,
String
current
,
Set
<
String
>
visitedPlaceholders
)
{
Set
<
String
>
visitedPlaceholders
)
{
StringBuilder
buf
=
new
StringBuilder
(
current
);
StringBuilder
buf
=
new
StringBuilder
(
current
);
int
startIndex
=
current
.
indexOf
(
PLACEHOLDER_PREFIX
);
int
startIndex
=
current
.
indexOf
(
PLACEHOLDER_PREFIX
);
while
(
startIndex
!=
-
1
)
{
while
(
startIndex
!=
-
1
)
{
int
endIndex
=
findPlaceholderEndIndex
(
buf
,
startIndex
);
int
endIndex
=
findPlaceholderEndIndex
(
buf
,
startIndex
);
if
(
endIndex
!=
-
1
)
{
if
(
endIndex
!=
-
1
)
{
String
placeholder
=
buf
.
substring
(
String
placeholder
=
buf
.
substring
(
startIndex
+
PLACEHOLDER_PREFIX
.
length
(),
endIndex
);
startIndex
+
PLACEHOLDER_PREFIX
.
length
(),
endIndex
);
String
originalPlaceholder
=
placeholder
;
String
originalPlaceholder
=
placeholder
;
if
(!
visitedPlaceholders
.
add
(
originalPlaceholder
))
{
if
(!
visitedPlaceholders
.
add
(
originalPlaceholder
))
{
throw
new
IllegalArgumentException
(
throw
new
IllegalArgumentException
(
"Circular placeholder reference '"
"Circular placeholder reference '"
+
originalPlaceholder
+
originalPlaceholder
+
"' in property definitions"
);
+
"' in property definitions"
);
}
}
// Recursive invocation, parsing placeholders contained in the
// Recursive invocation, parsing placeholders contained in the
// placeholder
// placeholder
// key.
// key.
placeholder
=
parseStringValue
(
value
,
placeholder
,
visitedPlaceholders
);
placeholder
=
parseStringValue
(
value
,
placeholder
,
// Now obtain the value for the fully resolved key...
visitedPlaceholders
);
String
propVal
=
resolvePlaceholder
(
value
,
placeholder
);
// Now obtain the value for the fully resolved key...
if
(
propVal
==
null
&&
VALUE_SEPARATOR
!=
null
)
{
String
propVal
=
resolvePlaceholder
(
value
,
placeholder
);
int
separatorIndex
=
placeholder
.
indexOf
(
VALUE_SEPARATOR
);
if
(
propVal
==
null
&&
VALUE_SEPARATOR
!=
null
)
{
if
(
separatorIndex
!=
-
1
)
{
int
separatorIndex
=
placeholder
.
indexOf
(
VALUE_SEPARATOR
);
String
actualPlaceholder
=
placeholder
.
substring
(
0
,
if
(
separatorIndex
!=
-
1
)
{
separatorIndex
);
String
actualPlaceholder
=
placeholder
.
substring
(
0
,
String
defaultValue
=
placeholder
.
substring
(
separatorIndex
separatorIndex
);
+
VALUE_SEPARATOR
.
length
());
String
defaultValue
=
placeholder
.
substring
(
separatorIndex
propVal
=
resolvePlaceholder
(
value
,
actualPlaceholder
);
+
VALUE_SEPARATOR
.
length
());
if
(
propVal
==
null
)
{
propVal
=
resolvePlaceholder
(
value
,
actualPlaceholder
);
propVal
=
defaultValue
;
if
(
propVal
==
null
)
{
propVal
=
defaultValue
;
}
}
}
}
}
if
(
propVal
!=
null
)
{
}
// Recursive invocation, parsing placeholders contained in the
if
(
propVal
!=
null
)
{
// previously resolved placeholder value.
// Recursive invocation, parsing placeholders contained in the
propVal
=
parseStringValue
(
value
,
propVal
,
visitedPlaceholders
);
// previously resolved placeholder value.
buf
.
replace
(
startIndex
,
endIndex
+
PLACEHOLDER_SUFFIX
.
length
(),
propVal
=
parseStringValue
(
value
,
propVal
,
visitedPlaceholders
);
propVal
);
buf
.
replace
(
startIndex
,
endIndex
+
PLACEHOLDER_SUFFIX
.
length
(),
startIndex
=
buf
.
indexOf
(
PLACEHOLDER_PREFIX
,
propVal
);
startIndex
+
propVal
.
length
());
startIndex
=
buf
.
indexOf
(
PLACEHOLDER_PREFIX
,
}
startIndex
+
propVal
.
length
());
else
{
// Proceed with unprocessed value.
startIndex
=
buf
.
indexOf
(
PLACEHOLDER_PREFIX
,
endIndex
+
PLACEHOLDER_SUFFIX
.
length
());
}
visitedPlaceholders
.
remove
(
originalPlaceholder
);
}
}
else
{
else
{
startIndex
=
-
1
;
// Proceed with unprocessed value.
startIndex
=
buf
.
indexOf
(
PLACEHOLDER_PREFIX
,
endIndex
+
PLACEHOLDER_SUFFIX
.
length
());
}
}
visitedPlaceholders
.
remove
(
originalPlaceholder
);
}
else
{
startIndex
=
-
1
;
}
}
return
buf
.
toString
();
}
}
private
String
resolvePlaceholder
(
String
text
,
String
placeholderName
)
{
return
buf
.
toString
();
try
{
}
String
propVal
=
System
.
getProperty
(
placeholderName
);
if
(
propVal
==
null
)
{
private
static
String
resolvePlaceholder
(
String
text
,
String
placeholderName
)
{
// Fall back to searching the system environment.
try
{
propVal
=
System
.
getenv
(
placeholderName
);
String
propVal
=
System
.
getProperty
(
placeholderName
);
}
if
(
propVal
==
null
)
{
return
propVal
;
// Fall back to searching the system environment.
}
propVal
=
System
.
getenv
(
placeholderName
);
catch
(
Throwable
ex
)
{
System
.
err
.
println
(
"Could not resolve placeholder '"
+
placeholderName
+
"' in ["
+
text
+
"] as system property: "
+
ex
);
return
null
;
}
}
return
propVal
;
}
}
catch
(
Throwable
ex
)
{
System
.
err
.
println
(
"Could not resolve placeholder '"
+
placeholderName
+
"' in ["
+
text
+
"] as system property: "
+
ex
);
return
null
;
}
}
private
int
findPlaceholderEndIndex
(
CharSequence
buf
,
int
startIndex
)
{
private
static
int
findPlaceholderEndIndex
(
CharSequence
buf
,
int
startIndex
)
{
int
index
=
startIndex
+
PLACEHOLDER_PREFIX
.
length
();
int
index
=
startIndex
+
PLACEHOLDER_PREFIX
.
length
();
int
withinNestedPlaceholder
=
0
;
int
withinNestedPlaceholder
=
0
;
while
(
index
<
buf
.
length
())
{
while
(
index
<
buf
.
length
())
{
if
(
substringMatch
(
buf
,
index
,
PLACEHOLDER_SUFFIX
))
{
if
(
substringMatch
(
buf
,
index
,
PLACEHOLDER_SUFFIX
))
{
if
(
withinNestedPlaceholder
>
0
)
{
if
(
withinNestedPlaceholder
>
0
)
{
withinNestedPlaceholder
--;
withinNestedPlaceholder
--;
index
=
index
+
PLACEHOLDER_SUFFIX
.
length
();
index
=
index
+
PLACEHOLDER_SUFFIX
.
length
();
}
else
{
return
index
;
}
}
else
if
(
substringMatch
(
buf
,
index
,
PropertyPlaceholderHelper
.
simplePrefix
))
{
withinNestedPlaceholder
++;
index
=
index
+
PropertyPlaceholderHelper
.
simplePrefix
.
length
();
}
}
else
{
else
{
index
++
;
return
index
;
}
}
}
}
return
-
1
;
else
if
(
substringMatch
(
buf
,
index
,
SIMPLE_PREFIX
))
{
}
withinNestedPlaceholder
++;
index
=
index
+
SIMPLE_PREFIX
.
length
();
private
static
boolean
substringMatch
(
CharSequence
str
,
int
index
,
}
CharSequence
substring
)
{
else
{
for
(
int
j
=
0
;
j
<
substring
.
length
();
j
++)
{
index
++;
int
i
=
index
+
j
;
if
(
i
>=
str
.
length
()
||
str
.
charAt
(
i
)
!=
substring
.
charAt
(
j
))
{
return
false
;
}
}
}
return
true
;
}
}
return
-
1
;
}
private
static
class
Assert
{
private
static
boolean
substringMatch
(
CharSequence
str
,
int
index
,
CharSequence
substring
)
{
public
static
void
notNull
(
Object
target
,
String
message
)
{
for
(
int
j
=
0
;
j
<
substring
.
length
();
j
++
)
{
if
(
target
==
null
)
{
int
i
=
index
+
j
;
throw
new
IllegalStateException
(
message
);
if
(
i
>=
str
.
length
()
||
str
.
charAt
(
i
)
!=
substring
.
charAt
(
j
))
{
}
return
false
;
}
}
}
}
return
true
;
}
}
}
}
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java
View file @
e9fd7c96
...
@@ -16,6 +16,8 @@
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
loader
;
package
org
.
springframework
.
boot
.
loader
;
import
java.io.File
;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.test.util.ReflectionTestUtils
;
...
@@ -40,7 +42,8 @@ public class PropertiesLauncherTests {
...
@@ -40,7 +42,8 @@ public class PropertiesLauncherTests {
@Test
@Test
public
void
testDefaultHome
()
{
public
void
testDefaultHome
()
{
assertEquals
(
System
.
getProperty
(
"user.dir"
),
this
.
launcher
.
getHomeDirectory
());
assertEquals
(
new
File
(
System
.
getProperty
(
"user.dir"
)),
this
.
launcher
.
getHomeDirectory
());
}
}
@Test
@Test
...
...
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