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
4e1245d9
Commit
4e1245d9
authored
Dec 31, 2013
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restore changes from
03325019
(fix class loader test failure)
parent
e00db0de
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
119 additions
and
19 deletions
+119
-19
pom.xml
spring-boot-cli/pom.xml
+4
-1
PropertiesLauncher.java
...a/org/springframework/boot/loader/PropertiesLauncher.java
+115
-16
PropertiesLauncherTests.java
.../springframework/boot/loader/PropertiesLauncherTests.java
+0
-2
No files found.
spring-boot-cli/pom.xml
View file @
4e1245d9
...
...
@@ -233,11 +233,14 @@
<archive>
<manifest>
<addDefaultImplementationEntries>
true
</addDefaultImplementationEntries>
<mainClass>
org.springframework.boot.loader.
Jar
Launcher
</mainClass>
<mainClass>
org.springframework.boot.loader.
Properties
Launcher
</mainClass>
</manifest>
<manifestEntries>
<Start-Class>
${start-class}
</Start-Class>
</manifestEntries>
<manifestEntries>
<Class-Loader>
groovy.lang.GroovyClassLoader
</Class-Loader>
</manifestEntries>
</archive>
</configuration>
</execution>
...
...
spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java
View file @
4e1245d9
...
...
@@ -33,7 +33,11 @@ import java.util.Arrays;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Properties
;
import
java.util.jar.Manifest
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
org.springframework.boot.loader.archive.Archive
;
import
org.springframework.boot.loader.archive.Archive.Entry
;
...
...
@@ -116,6 +120,8 @@ public class PropertiesLauncher extends Launcher {
private
static
final
List
<
String
>
DEFAULT_PATHS
=
Arrays
.
asList
(
"lib/"
);
private
static
final
Pattern
WORD_SEPARATOR
=
Pattern
.
compile
(
"\\W+"
);
private
final
File
home
;
private
List
<
String
>
paths
=
new
ArrayList
<
String
>(
DEFAULT_PATHS
);
...
...
@@ -123,6 +129,9 @@ public class PropertiesLauncher extends Launcher {
private
Properties
properties
=
new
Properties
();
public
PropertiesLauncher
()
{
if
(!
isDebug
())
{
this
.
logger
.
setLevel
(
Level
.
SEVERE
);
}
try
{
this
.
home
=
getHomeDirectory
();
initializeProperties
(
this
.
home
);
...
...
@@ -133,6 +142,22 @@ public class PropertiesLauncher extends Launcher {
}
}
private
boolean
isDebug
()
{
String
debug
=
System
.
getProperty
(
"debug"
);
if
(
debug
!=
null
&&
!
"false"
.
equals
(
debug
))
{
return
true
;
}
debug
=
System
.
getProperty
(
"DEBUG"
);
if
(
debug
!=
null
&&
!
"false"
.
equals
(
debug
))
{
return
true
;
}
debug
=
System
.
getenv
(
"DEBUG"
);
if
(
debug
!=
null
&&
!
"false"
.
equals
(
debug
))
{
return
true
;
}
return
false
;
}
protected
File
getHomeDirectory
()
{
return
new
File
(
SystemPropertyUtils
.
resolvePlaceholders
(
System
.
getProperty
(
HOME
,
"${user.dir}"
)));
...
...
@@ -290,30 +315,82 @@ public class PropertiesLauncher extends Launcher {
@Override
protected
String
getMainClass
()
throws
Exception
{
String
property
=
SystemPropertyUtils
.
getProperty
(
MAIN
);
String
mainClass
=
getProperty
(
MAIN
,
"Start-Class"
);
if
(
mainClass
==
null
)
{
throw
new
IllegalStateException
(
"No '"
+
MAIN
+
"' or 'Start-Class' specified"
);
}
return
mainClass
;
}
@Override
protected
ClassLoader
createClassLoader
(
List
<
Archive
>
archives
)
throws
Exception
{
ClassLoader
loader
=
super
.
createClassLoader
(
archives
);
String
classLoaderType
=
getProperty
(
"loader.classLoader"
);
if
(
classLoaderType
!=
null
)
{
Class
<?>
type
=
Class
.
forName
(
classLoaderType
,
true
,
loader
);
try
{
loader
=
(
ClassLoader
)
type
.
getConstructor
(
ClassLoader
.
class
)
.
newInstance
(
loader
);
}
catch
(
NoSuchMethodException
e
)
{
try
{
loader
=
(
ClassLoader
)
type
.
getConstructor
(
URL
[].
class
,
ClassLoader
.
class
).
newInstance
(
new
URL
[
0
],
loader
);
}
catch
(
NoSuchMethodException
ex
)
{
loader
=
(
ClassLoader
)
type
.
newInstance
();
}
}
this
.
logger
.
info
(
"Using custom class loader: "
+
classLoaderType
);
}
return
loader
;
}
private
String
getProperty
(
String
propertyKey
)
throws
Exception
{
return
getProperty
(
propertyKey
,
null
);
}
private
String
getProperty
(
String
propertyKey
,
String
manifestKey
)
throws
Exception
{
if
(
manifestKey
==
null
)
{
manifestKey
=
propertyKey
.
replace
(
"."
,
"-"
);
manifestKey
=
toCamelCase
(
manifestKey
);
}
String
property
=
SystemPropertyUtils
.
getProperty
(
propertyKey
);
if
(
property
!=
null
)
{
String
mainClass
=
SystemPropertyUtils
.
resolvePlaceholders
(
property
);
this
.
logger
.
info
(
"Main class from environment: "
+
mainClass
);
return
mainClass
;
String
value
=
SystemPropertyUtils
.
resolvePlaceholders
(
property
);
this
.
logger
.
fine
(
"Property '"
+
propertyKey
+
"' from environment: "
+
value
);
return
value
;
}
if
(
this
.
properties
.
containsKey
(
MAIN
))
{
String
mainClass
=
SystemPropertyUtils
.
resolvePlaceholders
(
this
.
properties
.
getProperty
(
MAIN
));
this
.
logger
.
info
(
"Main class from properties: "
+
mainClass
);
return
mainClass
;
if
(
this
.
properties
.
containsKey
(
propertyKey
))
{
String
value
=
SystemPropertyUtils
.
resolvePlaceholders
(
this
.
properties
.
getProperty
(
propertyKey
));
this
.
logger
.
fine
(
"Property '"
+
propertyKey
+
"' from properties: "
+
value
);
return
value
;
}
try
{
// Prefer home dir for MANIFEST if there is one
String
mainClass
=
new
ExplodedArchive
(
this
.
home
).
getMainClass
();
this
.
logger
.
info
(
"Main class from home directory manifest: "
+
mainClass
);
return
mainClass
;
Manifest
manifest
=
new
ExplodedArchive
(
this
.
home
).
getManifest
();
if
(
manifest
!=
null
)
{
String
value
=
manifest
.
getMainAttributes
().
getValue
(
manifestKey
);
this
.
logger
.
fine
(
"Property '"
+
manifestKey
+
"' from home directory manifest: "
+
value
);
return
value
;
}
}
catch
(
IllegalStateException
ex
)
{
// Otherwise try the parent archive
String
mainClass
=
createArchive
().
getMainClass
();
this
.
logger
.
info
(
"Main class from archive manifest: "
+
mainClass
);
return
mainClass
;
}
// Otherwise try the parent archive
Manifest
manifest
=
createArchive
().
getManifest
();
if
(
manifest
!=
null
)
{
String
value
=
manifest
.
getMainAttributes
().
getValue
(
manifestKey
);
if
(
value
!=
null
)
{
this
.
logger
.
fine
(
"Property '"
+
manifestKey
+
"' from archive manifest: "
+
value
);
return
value
;
}
}
return
null
;
}
@Override
...
...
@@ -448,6 +525,28 @@ public class PropertiesLauncher extends Launcher {
new
PropertiesLauncher
().
launch
(
args
);
}
public
static
String
toCamelCase
(
CharSequence
string
)
{
if
(
string
==
null
)
{
return
null
;
}
StringBuilder
builder
=
new
StringBuilder
();
Matcher
matcher
=
WORD_SEPARATOR
.
matcher
(
string
);
int
pos
=
0
;
while
(
matcher
.
find
())
{
builder
.
append
(
capitalize
(
string
.
subSequence
(
pos
,
matcher
.
end
()).
toString
()));
pos
=
matcher
.
end
();
}
builder
.
append
(
capitalize
(
string
.
subSequence
(
pos
,
string
.
length
()).
toString
()));
return
builder
.
toString
();
}
private
static
Object
capitalize
(
String
str
)
{
StringBuilder
sb
=
new
StringBuilder
(
str
.
length
());
sb
.
append
(
Character
.
toUpperCase
(
str
.
charAt
(
0
)));
sb
.
append
(
str
.
substring
(
1
));
return
sb
.
toString
();
}
/**
* Convenience class for finding nested archives (archive entries that can be
* classpath entries).
...
...
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java
View file @
4e1245d9
...
...
@@ -24,7 +24,6 @@ import java.util.Collections;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Ignore
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.springframework.boot.loader.archive.Archive
;
...
...
@@ -116,7 +115,6 @@ public class PropertiesLauncherTests {
}
@Test
@Ignore
public
void
testCustomClassLoaderCreation
()
throws
Exception
{
System
.
setProperty
(
"loader.classLoader"
,
TestLoader
.
class
.
getName
());
PropertiesLauncher
launcher
=
new
PropertiesLauncher
();
...
...
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