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
4544785a
Commit
4544785a
authored
Mar 17, 2020
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.2.x'
Closes gh-20544
parents
fb8b531b
566f79b0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
3 deletions
+84
-3
ApplicationHome.java
...java/org/springframework/boot/system/ApplicationHome.java
+4
-3
ApplicationHomeTests.java
...org/springframework/boot/system/ApplicationHomeTests.java
+80
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/ApplicationHome.java
View file @
4544785a
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -20,6 +20,7 @@ import java.io.File;
...
@@ -20,6 +20,7 @@ import java.io.File;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.net.JarURLConnection
;
import
java.net.JarURLConnection
;
import
java.net.URISyntaxException
;
import
java.net.URL
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.net.URLConnection
;
import
java.security.CodeSource
;
import
java.security.CodeSource
;
...
@@ -116,12 +117,12 @@ public class ApplicationHome {
...
@@ -116,12 +117,12 @@ public class ApplicationHome {
return
false
;
return
false
;
}
}
private
File
findSource
(
URL
location
)
throws
IOException
{
private
File
findSource
(
URL
location
)
throws
IOException
,
URISyntaxException
{
URLConnection
connection
=
location
.
openConnection
();
URLConnection
connection
=
location
.
openConnection
();
if
(
connection
instanceof
JarURLConnection
)
{
if
(
connection
instanceof
JarURLConnection
)
{
return
getRootJarFile
(((
JarURLConnection
)
connection
).
getJarFile
());
return
getRootJarFile
(((
JarURLConnection
)
connection
).
getJarFile
());
}
}
return
new
File
(
location
.
getPath
());
return
new
File
(
location
.
toURI
());
}
}
private
File
getRootJarFile
(
JarFile
jarFile
)
{
private
File
getRootJarFile
(
JarFile
jarFile
)
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/system/ApplicationHomeTests.java
0 → 100644
View file @
4544785a
/*
* Copyright 2012-2020 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
system
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
net.bytebuddy.ByteBuddy
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.io.TempDir
;
import
org.springframework.util.FileCopyUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ApplicationHome}.
*
* @author Andy Wilkinson
*/
class
ApplicationHomeTests
{
@TempDir
File
tempDir
;
@Test
void
whenSourceClassIsProvidedThenApplicationHomeReflectsItsLocation
()
throws
Exception
{
File
app
=
new
File
(
this
.
tempDir
,
"app"
);
ApplicationHome
applicationHome
=
createApplicationHome
(
app
);
assertThat
(
applicationHome
.
getDir
()).
isEqualTo
(
app
);
}
@Test
void
whenSourceClassIsProvidedWithSpaceInItsPathThenApplicationHomeReflectsItsLocation
()
throws
Exception
{
File
app
=
new
File
(
this
.
tempDir
,
"app location"
);
ApplicationHome
applicationHome
=
createApplicationHome
(
app
);
assertThat
(
applicationHome
.
getDir
()).
isEqualTo
(
app
);
}
private
ApplicationHome
createApplicationHome
(
File
location
)
throws
Exception
{
File
examplePackage
=
new
File
(
location
,
"com/example"
);
examplePackage
.
mkdirs
();
FileCopyUtils
.
copy
(
new
ByteArrayInputStream
(
new
ByteBuddy
().
subclass
(
Object
.
class
).
name
(
"com.example.Source"
).
make
().
getBytes
()),
new
FileOutputStream
(
new
File
(
examplePackage
,
"Source.class"
)));
try
(
URLClassLoader
classLoader
=
new
URLClassLoader
(
new
URL
[]
{
location
.
toURI
().
toURL
()
}))
{
Class
<?>
sourceClass
=
classLoader
.
loadClass
(
"com.example.Source"
);
// Separate thread to bypass stack-based unit test detection in
// ApplicationHome
ExecutorService
executor
=
Executors
.
newSingleThreadExecutor
();
try
{
return
executor
.
submit
(()
->
new
ApplicationHome
(
sourceClass
)).
get
();
}
finally
{
executor
.
shutdown
();
}
}
}
}
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