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
1a76b512
Commit
1a76b512
authored
Nov 23, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
72b14b8a
3cc75098
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
5 deletions
+29
-5
DocumentRoot.java
...springframework/boot/web/servlet/server/DocumentRoot.java
+10
-5
DocumentRootTests.java
...gframework/boot/web/servlet/server/DocumentRootTests.java
+19
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/DocumentRoot.java
View file @
1a76b512
...
@@ -17,7 +17,6 @@
...
@@ -17,7 +17,6 @@
package
org
.
springframework
.
boot
.
web
.
servlet
.
server
;
package
org
.
springframework
.
boot
.
web
.
servlet
.
server
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.JarURLConnection
;
import
java.net.JarURLConnection
;
import
java.net.URL
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.net.URLConnection
;
...
@@ -93,23 +92,29 @@ class DocumentRoot {
...
@@ -93,23 +92,29 @@ class DocumentRoot {
}
}
private
File
getCodeSourceArchive
()
{
private
File
getCodeSourceArchive
()
{
return
getCodeSourceArchive
(
getClass
().
getProtectionDomain
().
getCodeSource
());
}
File
getCodeSourceArchive
(
CodeSource
codeSource
)
{
try
{
try
{
CodeSource
codeSource
=
getClass
().
getProtectionDomain
().
getCodeSource
();
URL
location
=
(
codeSource
==
null
?
null
:
codeSource
.
getLocation
());
URL
location
=
(
codeSource
==
null
?
null
:
codeSource
.
getLocation
());
if
(
location
==
null
)
{
if
(
location
==
null
)
{
return
null
;
return
null
;
}
}
String
path
=
location
.
getPath
()
;
String
path
;
URLConnection
connection
=
location
.
openConnection
();
URLConnection
connection
=
location
.
openConnection
();
if
(
connection
instanceof
JarURLConnection
)
{
if
(
connection
instanceof
JarURLConnection
)
{
path
=
((
JarURLConnection
)
connection
).
getJarFile
().
getName
();
path
=
((
JarURLConnection
)
connection
).
getJarFile
().
getName
();
}
}
if
(
path
.
indexOf
(
"!/"
)
!=
-
1
)
{
else
{
path
=
location
.
toURI
().
getPath
();
}
if
(
path
.
contains
(
"!/"
))
{
path
=
path
.
substring
(
0
,
path
.
indexOf
(
"!/"
));
path
=
path
.
substring
(
0
,
path
.
indexOf
(
"!/"
));
}
}
return
new
File
(
path
);
return
new
File
(
path
);
}
}
catch
(
IO
Exception
ex
)
{
catch
(
Exception
ex
)
{
return
null
;
return
null
;
}
}
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/DocumentRootTests.java
View file @
1a76b512
...
@@ -17,6 +17,9 @@
...
@@ -17,6 +17,9 @@
package
org
.
springframework
.
boot
.
web
.
servlet
.
server
;
package
org
.
springframework
.
boot
.
web
.
servlet
.
server
;
import
java.io.File
;
import
java.io.File
;
import
java.net.URL
;
import
java.security.CodeSource
;
import
java.security.cert.Certificate
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.Rule
;
import
org.junit.Rule
;
...
@@ -53,4 +56,20 @@ public class DocumentRootTests {
...
@@ -53,4 +56,20 @@ public class DocumentRootTests {
assertThat
(
directory
).
isNull
();
assertThat
(
directory
).
isNull
();
}
}
@Test
public
void
codeSourceArchivePath
()
throws
Exception
{
CodeSource
codeSource
=
new
CodeSource
(
new
URL
(
"file"
,
""
,
"/some/test/path/"
),
(
Certificate
[])
null
);
File
codeSourceArchive
=
this
.
documentRoot
.
getCodeSourceArchive
(
codeSource
);
assertThat
(
codeSourceArchive
).
isEqualTo
(
new
File
(
"/some/test/path/"
));
}
@Test
public
void
codeSourceArchivePathContainingSpaces
()
throws
Exception
{
CodeSource
codeSource
=
new
CodeSource
(
new
URL
(
"file"
,
""
,
"/test/path/with%20space/"
),
(
Certificate
[])
null
);
File
codeSourceArchive
=
this
.
documentRoot
.
getCodeSourceArchive
(
codeSource
);
assertThat
(
codeSourceArchive
).
isEqualTo
(
new
File
(
"/test/path/with space/"
));
}
}
}
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