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
bceed130
Commit
bceed130
authored
Jan 29, 2020
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Jar files added after build time should be added to classpath
Fixes gh-19973
parent
b281af0b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
7 deletions
+46
-7
ClassPathIndexFile.java
...a/org/springframework/boot/loader/ClassPathIndexFile.java
+7
-0
ExecutableArchiveLauncher.java
...pringframework/boot/loader/ExecutableArchiveLauncher.java
+5
-4
AbstractExecutableArchiveLauncherTests.java
...k/boot/loader/AbstractExecutableArchiveLauncherTests.java
+7
-2
JarLauncherTests.java
...ava/org/springframework/boot/loader/JarLauncherTests.java
+27
-1
No files found.
spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/ClassPathIndexFile.java
View file @
bceed130
...
...
@@ -72,6 +72,13 @@ final class ClassPathIndexFile {
return
this
.
folders
.
contains
(
name
);
}
boolean
containsEntry
(
String
name
)
{
if
(
name
==
null
||
name
.
isEmpty
())
{
return
false
;
}
return
this
.
lines
.
contains
(
name
);
}
List
<
URL
>
getUrls
()
{
return
Collections
.
unmodifiableList
(
this
.
lines
.
stream
().
map
(
this
::
asUrl
).
collect
(
Collectors
.
toList
()));
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/ExecutableArchiveLauncher.java
View file @
bceed130
...
...
@@ -101,17 +101,18 @@ public abstract class ExecutableArchiveLauncher extends Launcher {
@Override
protected
Iterator
<
Archive
>
getClassPathArchivesIterator
()
throws
Exception
{
Archive
.
EntryFilter
searchFilter
=
(
entry
)
->
isSearchCandidate
(
entry
)
&&
!
isFolderIndexed
(
entry
);
Iterator
<
Archive
>
archives
=
this
.
archive
.
getNestedArchives
(
searchFilter
,
this
::
isNestedArchive
);
Archive
.
EntryFilter
searchFilter
=
this
::
isSearchCandidate
;
Iterator
<
Archive
>
archives
=
this
.
archive
.
getNestedArchives
(
searchFilter
,
(
entry
)
->
isNestedArchive
(
entry
)
&&
!
isEntryIndexed
(
entry
));
if
(
isPostProcessingClassPathArchives
())
{
archives
=
applyClassPathArchivePostProcessing
(
archives
);
}
return
archives
;
}
private
boolean
is
Folder
Indexed
(
Archive
.
Entry
entry
)
{
private
boolean
is
Entry
Indexed
(
Archive
.
Entry
entry
)
{
if
(
this
.
classPathIndex
!=
null
)
{
return
this
.
classPathIndex
.
contains
Folder
(
entry
.
getName
());
return
this
.
classPathIndex
.
contains
Entry
(
entry
.
getName
());
}
return
false
;
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/AbstractExecutableArchiveLauncherTests.java
View file @
bceed130
...
...
@@ -25,6 +25,7 @@ import java.io.Writer;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Collections
;
import
java.util.Enumeration
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
...
...
@@ -52,11 +53,12 @@ public abstract class AbstractExecutableArchiveLauncherTests {
File
tempDir
;
protected
File
createJarArchive
(
String
name
,
String
entryPrefix
)
throws
IOException
{
return
createJarArchive
(
name
,
entryPrefix
,
false
);
return
createJarArchive
(
name
,
entryPrefix
,
false
,
Collections
.
emptyList
()
);
}
@SuppressWarnings
(
"resource"
)
protected
File
createJarArchive
(
String
name
,
String
entryPrefix
,
boolean
indexed
)
throws
IOException
{
protected
File
createJarArchive
(
String
name
,
String
entryPrefix
,
boolean
indexed
,
List
<
String
>
extraLibs
)
throws
IOException
{
File
archive
=
new
File
(
this
.
tempDir
,
name
);
JarOutputStream
jarOutputStream
=
new
JarOutputStream
(
new
FileOutputStream
(
archive
));
jarOutputStream
.
putNextEntry
(
new
JarEntry
(
entryPrefix
+
"/"
));
...
...
@@ -74,6 +76,9 @@ public abstract class AbstractExecutableArchiveLauncherTests {
addNestedJars
(
entryPrefix
,
"/lib/foo.jar"
,
jarOutputStream
);
addNestedJars
(
entryPrefix
,
"/lib/bar.jar"
,
jarOutputStream
);
addNestedJars
(
entryPrefix
,
"/lib/baz.jar"
,
jarOutputStream
);
for
(
String
lib
:
extraLibs
)
{
addNestedJars
(
entryPrefix
,
"/lib/"
+
lib
,
jarOutputStream
);
}
jarOutputStream
.
close
();
return
archive
;
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/JarLauncherTests.java
View file @
bceed130
...
...
@@ -20,6 +20,8 @@ import java.io.File;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.List
;
...
...
@@ -72,7 +74,7 @@ class JarLauncherTests extends AbstractExecutableArchiveLauncherTests {
@Test
void
explodedJarShouldPreserveClasspathOrderWhenIndexPresent
()
throws
Exception
{
File
explodedRoot
=
explode
(
createJarArchive
(
"archive.jar"
,
"BOOT-INF"
,
true
));
File
explodedRoot
=
explode
(
createJarArchive
(
"archive.jar"
,
"BOOT-INF"
,
true
,
Collections
.
emptyList
()
));
JarLauncher
launcher
=
new
JarLauncher
(
new
ExplodedArchive
(
explodedRoot
,
true
));
Iterator
<
Archive
>
archives
=
launcher
.
getClassPathArchivesIterator
();
URLClassLoader
classLoader
=
(
URLClassLoader
)
launcher
.
createClassLoader
(
archives
);
...
...
@@ -80,6 +82,19 @@ class JarLauncherTests extends AbstractExecutableArchiveLauncherTests {
assertThat
(
urls
).
containsExactly
(
getExpectedFileUrls
(
explodedRoot
));
}
@Test
void
jarFilesPresentInBootInfLibsAndNotInClasspathIndexShouldBeAddedAfterBootInfClasses
()
throws
Exception
{
ArrayList
<
String
>
extraLibs
=
new
ArrayList
<>(
Arrays
.
asList
(
"extra-1.jar"
,
"extra-2.jar"
));
File
explodedRoot
=
explode
(
createJarArchive
(
"archive.jar"
,
"BOOT-INF"
,
true
,
extraLibs
));
JarLauncher
launcher
=
new
JarLauncher
(
new
ExplodedArchive
(
explodedRoot
,
true
));
Iterator
<
Archive
>
archives
=
launcher
.
getClassPathArchivesIterator
();
URLClassLoader
classLoader
=
(
URLClassLoader
)
launcher
.
createClassLoader
(
archives
);
URL
[]
urls
=
classLoader
.
getURLs
();
List
<
File
>
expectedFiles
=
getExpectedFilesWithExtraLibs
(
explodedRoot
);
URL
[]
expectedFileUrls
=
expectedFiles
.
stream
().
map
(
this
::
toUrl
).
toArray
(
URL
[]::
new
);
assertThat
(
urls
).
containsExactly
(
expectedFileUrls
);
}
protected
final
URL
[]
getExpectedFileUrls
(
File
explodedRoot
)
{
return
getExpectedFiles
(
explodedRoot
).
stream
().
map
(
this
::
toUrl
).
toArray
(
URL
[]::
new
);
}
...
...
@@ -93,4 +108,15 @@ class JarLauncherTests extends AbstractExecutableArchiveLauncherTests {
return
expected
;
}
protected
final
List
<
File
>
getExpectedFilesWithExtraLibs
(
File
parent
)
{
List
<
File
>
expected
=
new
ArrayList
<>();
expected
.
add
(
new
File
(
parent
,
"BOOT-INF/classes"
));
expected
.
add
(
new
File
(
parent
,
"BOOT-INF/lib/extra-1.jar"
));
expected
.
add
(
new
File
(
parent
,
"BOOT-INF/lib/extra-2.jar"
));
expected
.
add
(
new
File
(
parent
,
"BOOT-INF/lib/foo.jar"
));
expected
.
add
(
new
File
(
parent
,
"BOOT-INF/lib/bar.jar"
));
expected
.
add
(
new
File
(
parent
,
"BOOT-INF/lib/baz.jar"
));
return
expected
;
}
}
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