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
006decea
Commit
006decea
authored
Mar 27, 2018
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
88faabaa
345b2c5d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
4 deletions
+33
-4
ModifiedClassPathRunner.java
...testsupport/runner/classpath/ModifiedClassPathRunner.java
+33
-4
No files found.
spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/runner/classpath/ModifiedClassPathRunner.java
View file @
006decea
...
@@ -28,6 +28,7 @@ import java.util.Collections;
...
@@ -28,6 +28,7 @@ import java.util.Collections;
import
java.util.List
;
import
java.util.List
;
import
java.util.jar.Attributes
;
import
java.util.jar.Attributes
;
import
java.util.jar.JarFile
;
import
java.util.jar.JarFile
;
import
java.util.regex.Pattern
;
import
java.util.stream.Stream
;
import
java.util.stream.Stream
;
import
org.apache.maven.repository.internal.MavenRepositorySystemUtils
;
import
org.apache.maven.repository.internal.MavenRepositorySystemUtils
;
...
@@ -66,6 +67,9 @@ import org.springframework.util.StringUtils;
...
@@ -66,6 +67,9 @@ import org.springframework.util.StringUtils;
*/
*/
public
class
ModifiedClassPathRunner
extends
BlockJUnit4ClassRunner
{
public
class
ModifiedClassPathRunner
extends
BlockJUnit4ClassRunner
{
private
static
final
Pattern
INTELLIJ_CLASSPATH_JAR_PATTERN
=
Pattern
.
compile
(
".*classpath(\\d+)?.jar"
);
public
ModifiedClassPathRunner
(
Class
<?>
testClass
)
throws
InitializationError
{
public
ModifiedClassPathRunner
(
Class
<?>
testClass
)
throws
InitializationError
{
super
(
testClass
);
super
(
testClass
);
}
}
...
@@ -98,7 +102,7 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
...
@@ -98,7 +102,7 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
private
URL
[]
extractUrls
(
ClassLoader
classLoader
)
throws
Exception
{
private
URL
[]
extractUrls
(
ClassLoader
classLoader
)
throws
Exception
{
List
<
URL
>
extractedUrls
=
new
ArrayList
<>();
List
<
URL
>
extractedUrls
=
new
ArrayList
<>();
doExtractUrls
(
classLoader
).
forEach
((
URL
url
)
->
{
doExtractUrls
(
classLoader
).
forEach
((
URL
url
)
->
{
if
(
is
SurefireBooter
Jar
(
url
))
{
if
(
is
ManifestOnly
Jar
(
url
))
{
extractedUrls
.
addAll
(
extractUrlsFromManifestClassPath
(
url
));
extractedUrls
.
addAll
(
extractUrlsFromManifestClassPath
(
url
));
}
}
else
{
else
{
...
@@ -125,10 +129,30 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
...
@@ -125,10 +129,30 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
}
}
}
}
private
boolean
isManifestOnlyJar
(
URL
url
)
{
return
isSurefireBooterJar
(
url
)
||
isShortenedIntelliJJar
(
url
);
}
private
boolean
isSurefireBooterJar
(
URL
url
)
{
private
boolean
isSurefireBooterJar
(
URL
url
)
{
return
url
.
getPath
().
contains
(
"surefirebooter"
);
return
url
.
getPath
().
contains
(
"surefirebooter"
);
}
}
private
boolean
isShortenedIntelliJJar
(
URL
url
)
{
String
urlPath
=
url
.
getPath
();
boolean
isCandidate
=
INTELLIJ_CLASSPATH_JAR_PATTERN
.
matcher
(
urlPath
).
matches
();
if
(
isCandidate
)
{
try
{
Attributes
attributes
=
getManifestMainAttributesFromUrl
(
url
);
String
createdBy
=
attributes
.
getValue
(
"Created-By"
);
return
createdBy
!=
null
&&
createdBy
.
contains
(
"IntelliJ"
);
}
catch
(
Exception
ex
)
{
return
false
;
}
}
return
false
;
}
private
List
<
URL
>
extractUrlsFromManifestClassPath
(
URL
booterJar
)
{
private
List
<
URL
>
extractUrlsFromManifestClassPath
(
URL
booterJar
)
{
List
<
URL
>
urls
=
new
ArrayList
<>();
List
<
URL
>
urls
=
new
ArrayList
<>();
try
{
try
{
...
@@ -143,9 +167,14 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
...
@@ -143,9 +167,14 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
}
}
private
String
[]
getClassPath
(
URL
booterJar
)
throws
Exception
{
private
String
[]
getClassPath
(
URL
booterJar
)
throws
Exception
{
try
(
JarFile
jarFile
=
new
JarFile
(
new
File
(
booterJar
.
toURI
())))
{
Attributes
attributes
=
getManifestMainAttributesFromUrl
(
booterJar
);
return
StringUtils
.
delimitedListToStringArray
(
jarFile
.
getManifest
()
return
StringUtils
.
delimitedListToStringArray
(
attributes
.
getMainAttributes
().
getValue
(
Attributes
.
Name
.
CLASS_PATH
),
" "
);
.
getValue
(
Attributes
.
Name
.
CLASS_PATH
),
" "
);
}
private
Attributes
getManifestMainAttributesFromUrl
(
URL
url
)
throws
Exception
{
try
(
JarFile
jarFile
=
new
JarFile
(
new
File
(
url
.
toURI
())))
{
return
jarFile
.
getManifest
().
getMainAttributes
();
}
}
}
}
...
...
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