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
89beef40
Commit
89beef40
authored
Jan 14, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.2.x'
parents
24fd5037
681a866c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
14 deletions
+62
-14
PropertiesLauncher.java
...a/org/springframework/boot/loader/PropertiesLauncher.java
+32
-13
PropertiesLauncherTests.java
.../springframework/boot/loader/PropertiesLauncherTests.java
+30
-1
No files found.
spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java
View file @
89beef40
...
...
@@ -71,6 +71,7 @@ import org.springframework.boot.loader.util.SystemPropertyUtils;
*
* @author Dave Syer
* @author Janne Valkealahti
* @author Andy Wilkinson
*/
public
class
PropertiesLauncher
extends
Launcher
{
...
...
@@ -131,6 +132,8 @@ public class PropertiesLauncher extends Launcher {
private
final
File
home
;
private
final
JavaAgentDetector
javaAgentDetector
;
private
List
<
String
>
paths
=
new
ArrayList
<
String
>(
DEFAULT_PATHS
);
private
final
Properties
properties
=
new
Properties
();
...
...
@@ -138,11 +141,16 @@ public class PropertiesLauncher extends Launcher {
private
Archive
parent
;
public
PropertiesLauncher
()
{
this
(
new
InputArgumentsJavaAgentDetector
());
}
PropertiesLauncher
(
JavaAgentDetector
javaAgentDetector
)
{
if
(!
isDebug
())
{
logger
.
setLevel
(
Level
.
SEVERE
);
}
try
{
this
.
home
=
getHomeDirectory
();
this
.
javaAgentDetector
=
javaAgentDetector
;
initializeProperties
(
this
.
home
);
initializePaths
();
this
.
parent
=
createArchive
();
...
...
@@ -513,21 +521,12 @@ public class PropertiesLauncher extends Launcher {
ClassLoader
parentClassLoader
=
getClass
().
getClassLoader
();
List
<
Archive
>
urls
=
new
ArrayList
<
Archive
>();
for
(
URL
url
:
getURLs
(
parentClassLoader
))
{
if
(
url
.
toString
().
endsWith
(
".jar"
)
||
url
.
toString
().
endsWith
(
".zip"
))
{
urls
.
add
(
new
JarFileArchive
(
new
File
(
url
.
toURI
())));
}
else
if
(
url
.
toString
().
endsWith
(
"/*"
))
{
String
name
=
url
.
getFile
();
File
dir
=
new
File
(
name
.
substring
(
0
,
name
.
length
()
-
1
));
if
(
dir
.
exists
())
{
urls
.
add
(
new
ExplodedArchive
(
new
File
(
name
.
substring
(
0
,
name
.
length
()
-
1
)),
false
));
if
(!
this
.
javaAgentDetector
.
isJavaAgentJar
(
url
))
{
Archive
archive
=
createArchiveIfPossible
(
url
);
if
(
archive
!=
null
)
{
urls
.
add
(
archive
);
}
}
else
{
String
filename
=
URLDecoder
.
decode
(
url
.
getFile
(),
"UTF-8"
);
urls
.
add
(
new
ExplodedArchive
(
new
File
(
filename
)));
}
}
// The parent archive might have a "lib/" directory, meaning we are running from
// an executable JAR. We add nested entries from there with low priority (i.e. at
...
...
@@ -541,6 +540,26 @@ public class PropertiesLauncher extends Launcher {
}
}
private
Archive
createArchiveIfPossible
(
URL
url
)
throws
IOException
,
URISyntaxException
{
if
(
url
.
toString
().
endsWith
(
".jar"
)
||
url
.
toString
().
endsWith
(
".zip"
))
{
return
new
JarFileArchive
(
new
File
(
url
.
toURI
()));
}
else
if
(
url
.
toString
().
endsWith
(
"/*"
))
{
String
name
=
url
.
getFile
();
File
dir
=
new
File
(
name
.
substring
(
0
,
name
.
length
()
-
1
));
if
(
dir
.
exists
())
{
return
new
ExplodedArchive
(
new
File
(
name
.
substring
(
0
,
name
.
length
()
-
1
)),
false
);
}
}
else
{
String
filename
=
URLDecoder
.
decode
(
url
.
getFile
(),
"UTF-8"
);
return
new
ExplodedArchive
(
new
File
(
filename
));
}
return
null
;
}
private
void
addNestedArchivesFromParent
(
List
<
Archive
>
urls
)
{
int
index
=
findArchive
(
urls
,
this
.
parent
);
if
(
index
>=
0
)
{
...
...
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java
View file @
89beef40
/*
* Copyright 2012-201
3
the original author or authors.
* Copyright 2012-201
6
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -22,32 +22,45 @@ import java.net.URL;
import
java.net.URLClassLoader
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
org.springframework.boot.loader.archive.Archive
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
* Tests for {@link PropertiesLauncher}.
*
* @author Dave Syer
* @author Andy Wilkinson
*/
public
class
PropertiesLauncherTests
{
@Mock
private
JavaAgentDetector
javaAgentDetector
;
@Rule
public
OutputCapture
output
=
new
OutputCapture
();
@Before
public
void
setup
()
throws
IOException
{
MockitoAnnotations
.
initMocks
(
this
);
System
.
setProperty
(
"loader.home"
,
new
File
(
"src/test/resources"
).
getAbsolutePath
());
}
...
...
@@ -186,6 +199,22 @@ public class PropertiesLauncherTests {
assertEquals
(
"[foo, bar]"
,
Arrays
.
asList
(
launcher
.
getArgs
(
"bar"
)).
toString
());
}
@Test
public
void
testJavaAgentJarsAreExcludedFromClasspath
()
throws
Exception
{
List
<
Archive
>
allArchives
=
new
PropertiesLauncher
().
getClassPathArchives
();
URL
[]
parentUrls
=
((
URLClassLoader
)
getClass
().
getClassLoader
()).
getURLs
();
for
(
URL
url
:
parentUrls
)
{
given
(
this
.
javaAgentDetector
.
isJavaAgentJar
(
url
)).
willReturn
(
true
);
}
List
<
Archive
>
nonAgentArchives
=
new
PropertiesLauncher
(
this
.
javaAgentDetector
)
.
getClassPathArchives
();
assertThat
(
nonAgentArchives
.
size
(),
is
(
equalTo
(
allArchives
.
size
()
-
parentUrls
.
length
)));
for
(
URL
url
:
parentUrls
)
{
verify
(
this
.
javaAgentDetector
).
isJavaAgentJar
(
url
);
}
}
private
void
waitFor
(
String
value
)
throws
Exception
{
int
count
=
0
;
boolean
timeout
=
false
;
...
...
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