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
ad164269
Commit
ad164269
authored
Mar 25, 2020
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update classpath index to use jar name instead of full path
See gh-20564
parent
2ceec65b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
25 additions
and
57 deletions
+25
-57
BootJar.java
...g/springframework/boot/gradle/tasks/bundling/BootJar.java
+2
-1
BootJarTests.java
...ingframework/boot/gradle/tasks/bundling/BootJarTests.java
+4
-6
Packager.java
.../java/org/springframework/boot/loader/tools/Packager.java
+4
-1
AbstractPackagerTests.java
...ingframework/boot/loader/tools/AbstractPackagerTests.java
+5
-5
ClassPathIndexFile.java
...a/org/springframework/boot/loader/ClassPathIndexFile.java
+0
-20
ClassPathIndexFileTests.java
.../springframework/boot/loader/ClassPathIndexFileTests.java
+5
-19
classpath-index-file.idx
.../org/springframework/boot/loader/classpath-index-file.idx
+5
-5
No files found.
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java
View file @
ad164269
...
...
@@ -125,7 +125,8 @@ public class BootJar extends Jar implements BootArchive {
}
private
File
createClasspathIndex
(
List
<
String
>
dependencies
)
{
String
content
=
dependencies
.
stream
().
collect
(
Collectors
.
joining
(
"\n"
,
""
,
"\n"
));
String
content
=
dependencies
.
stream
().
map
((
name
)
->
name
.
substring
(
name
.
lastIndexOf
(
'/'
)
+
1
))
.
collect
(
Collectors
.
joining
(
"\n"
,
""
,
"\n"
));
File
source
=
getProject
().
getResources
().
getText
().
fromString
(
content
).
asFile
();
File
indexFile
=
new
File
(
source
.
getParentFile
(),
"classpath.idx"
);
source
.
renameTo
(
indexFile
);
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java
View file @
ad164269
...
...
@@ -164,10 +164,8 @@ class BootJarTests extends AbstractBootArchiveTests<BootJar> {
@Test
void
whenJarIsLayeredClasspathIndexPointsToLayeredLibs
()
throws
IOException
{
try
(
JarFile
jarFile
=
new
JarFile
(
createLayeredJar
()))
{
assertThat
(
entryLines
(
jarFile
,
"BOOT-INF/classpath.idx"
)).
containsExactly
(
"BOOT-INF/layers/dependencies/lib/first-library.jar"
,
"BOOT-INF/layers/dependencies/lib/second-library.jar"
,
"BOOT-INF/layers/snapshot-dependencies/lib/third-library-SNAPSHOT.jar"
);
assertThat
(
entryLines
(
jarFile
,
"BOOT-INF/classpath.idx"
)).
containsExactly
(
"first-library.jar"
,
"second-library.jar"
,
"third-library-SNAPSHOT.jar"
);
}
}
...
...
@@ -189,8 +187,8 @@ class BootJarTests extends AbstractBootArchiveTests<BootJar> {
try
(
JarFile
jarFile
=
new
JarFile
(
createPopulatedJar
()))
{
assertThat
(
jarFile
.
getManifest
().
getMainAttributes
().
getValue
(
"Spring-Boot-Classpath-Index"
))
.
isEqualTo
(
"BOOT-INF/classpath.idx"
);
assertThat
(
entryLines
(
jarFile
,
"BOOT-INF/classpath.idx"
)).
containsExactly
(
"
BOOT-INF/lib/
first-library.jar"
,
"
BOOT-INF/lib/second-library.jar"
,
"BOOT-INF/lib/
third-library-SNAPSHOT.jar"
);
assertThat
(
entryLines
(
jarFile
,
"BOOT-INF/classpath.idx"
)).
containsExactly
(
"first-library.jar"
,
"
second-library.jar"
,
"
third-library-SNAPSHOT.jar"
);
}
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Packager.java
View file @
ad164269
...
...
@@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
import
java.util.jar.Attributes
;
import
java.util.jar.JarFile
;
import
java.util.jar.Manifest
;
import
java.util.stream.Collectors
;
import
org.apache.commons.compress.archivers.jar.JarArchiveEntry
;
...
...
@@ -492,7 +493,9 @@ public abstract class Packager {
}
if
(
getLayout
()
instanceof
RepackagingLayout
)
{
String
location
=
((
RepackagingLayout
)
getLayout
()).
getClasspathIndexFileLocation
();
writer
.
writeIndexFile
(
location
,
this
.
libraries
.
keySet
());
List
<
String
>
names
=
this
.
libraries
.
keySet
().
stream
()
.
map
((
key
)
->
key
.
substring
(
key
.
lastIndexOf
(
'/'
)
+
1
)).
collect
(
Collectors
.
toList
());
writer
.
writeIndexFile
(
location
,
names
);
}
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/AbstractPackagerTests.java
View file @
ad164269
...
...
@@ -232,8 +232,8 @@ abstract class AbstractPackagerTests<P extends Packager> {
assertThat
(
hasPackagedEntry
(
"BOOT-INF/classpath.idx"
)).
isTrue
();
String
index
=
getPackagedEntryContent
(
"BOOT-INF/classpath.idx"
);
String
[]
libraries
=
index
.
split
(
"\\r?\\n"
);
assertThat
(
Arrays
.
asList
(
libraries
)).
contains
(
"BOOT-INF/lib/"
+
libJarFile1
.
getName
(),
"BOOT-INF/lib/"
+
libJarFile2
.
getName
(),
"BOOT-INF/lib/"
+
libJarFile3
.
getName
());
assertThat
(
Arrays
.
asList
(
libraries
)).
contains
(
libJarFile1
.
getName
(),
libJarFile2
.
getName
(),
libJarFile3
.
getName
());
}
@Test
...
...
@@ -267,7 +267,8 @@ abstract class AbstractPackagerTests<P extends Packager> {
expectedJars
.
add
(
"BOOT-INF/layers/0001/lib/"
+
libJarFile1
.
getName
());
expectedJars
.
add
(
"BOOT-INF/layers/0002/lib/"
+
libJarFile2
.
getName
());
expectedJars
.
add
(
"BOOT-INF/layers/0003/lib/"
+
libJarFile3
.
getName
());
assertThat
(
Arrays
.
asList
(
classpathIndex
.
split
(
"\\n"
))).
containsExactly
(
expectedJars
.
toArray
(
new
String
[
0
]));
assertThat
(
Arrays
.
asList
(
classpathIndex
.
split
(
"\\n"
))).
containsExactly
(
libJarFile1
.
getName
(),
libJarFile2
.
getName
(),
libJarFile3
.
getName
());
assertThat
(
hasPackagedEntry
(
"BOOT-INF/layers.idx"
)).
isTrue
();
String
layersIndex
=
getPackagedEntryContent
(
"BOOT-INF/layers.idx"
);
List
<
String
>
expectedLayers
=
new
ArrayList
<>();
...
...
@@ -288,8 +289,7 @@ abstract class AbstractPackagerTests<P extends Packager> {
execute
(
packager
,
Libraries
.
NONE
);
assertThat
(
hasPackagedEntry
(
"BOOT-INF/classpath.idx"
)).
isTrue
();
String
classpathIndex
=
getPackagedEntryContent
(
"BOOT-INF/classpath.idx"
);
assertThat
(
Arrays
.
asList
(
classpathIndex
.
split
(
"\\n"
)))
.
containsExactly
(
"BOOT-INF/layers/default/lib/spring-boot-jarmode-layertools.jar"
);
assertThat
(
Arrays
.
asList
(
classpathIndex
.
split
(
"\\n"
))).
containsExactly
(
"spring-boot-jarmode-layertools.jar"
);
assertThat
(
hasPackagedEntry
(
"BOOT-INF/layers.idx"
)).
isTrue
();
String
layersIndex
=
getPackagedEntryContent
(
"BOOT-INF/layers.idx"
);
assertThat
(
Arrays
.
asList
(
layersIndex
.
split
(
"\\n"
))).
containsExactly
(
"default"
);
...
...
spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/ClassPathIndexFile.java
View file @
ad164269
...
...
@@ -29,8 +29,6 @@ import java.nio.charset.StandardCharsets;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -45,33 +43,15 @@ final class ClassPathIndexFile {
private
final
List
<
String
>
lines
;
private
final
Set
<
String
>
folders
;
private
ClassPathIndexFile
(
File
root
,
List
<
String
>
lines
)
{
this
.
root
=
root
;
this
.
lines
=
lines
;
this
.
folders
=
this
.
lines
.
stream
().
map
(
this
::
getFolder
).
filter
(
Objects:
:
nonNull
).
collect
(
Collectors
.
toSet
());
}
private
String
getFolder
(
String
name
)
{
int
lastSlash
=
name
.
lastIndexOf
(
'/'
);
return
(
lastSlash
!=
-
1
)
?
name
.
substring
(
0
,
lastSlash
)
:
null
;
}
int
size
()
{
return
this
.
lines
.
size
();
}
boolean
containsFolder
(
String
name
)
{
if
(
name
==
null
||
name
.
isEmpty
())
{
return
false
;
}
if
(
name
.
endsWith
(
"/"
))
{
return
containsFolder
(
name
.
substring
(
0
,
name
.
length
()
-
1
));
}
return
this
.
folders
.
contains
(
name
);
}
boolean
containsEntry
(
String
name
)
{
if
(
name
==
null
||
name
.
isEmpty
())
{
return
false
;
...
...
spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/ClassPathIndexFileTests.java
View file @
ad164269
...
...
@@ -73,30 +73,16 @@ class ClassPathIndexFileTests {
assertThat
(
indexFile
.
size
()).
isEqualTo
(
5
);
}
@Test
void
containsFolderWhenFolderIsPresentReturnsTrue
()
throws
Exception
{
ClassPathIndexFile
indexFile
=
copyAndLoadTestIndexFile
();
assertThat
(
indexFile
.
containsFolder
(
"BOOT-INF/layers/one/lib"
)).
isTrue
();
assertThat
(
indexFile
.
containsFolder
(
"BOOT-INF/layers/one/lib/"
)).
isTrue
();
assertThat
(
indexFile
.
containsFolder
(
"BOOT-INF/layers/two/lib"
)).
isTrue
();
}
@Test
void
containsFolderWhenFolderIsMissingReturnsFalse
()
throws
Exception
{
ClassPathIndexFile
indexFile
=
copyAndLoadTestIndexFile
();
assertThat
(
indexFile
.
containsFolder
(
"BOOT-INF/layers/nope/lib/"
)).
isFalse
();
}
@Test
void
getUrlsReturnsUrls
()
throws
Exception
{
ClassPathIndexFile
indexFile
=
copyAndLoadTestIndexFile
();
List
<
URL
>
urls
=
indexFile
.
getUrls
();
List
<
File
>
expected
=
new
ArrayList
<>();
expected
.
add
(
new
File
(
this
.
temp
,
"
BOOT-INF/layers/one/lib/
a.jar"
));
expected
.
add
(
new
File
(
this
.
temp
,
"
BOOT-INF/layers/one/lib/
b.jar"
));
expected
.
add
(
new
File
(
this
.
temp
,
"
BOOT-INF/layers/one/lib/
c.jar"
));
expected
.
add
(
new
File
(
this
.
temp
,
"
BOOT-INF/layers/two/lib/
d.jar"
));
expected
.
add
(
new
File
(
this
.
temp
,
"
BOOT-INF/layers/two/lib/
e.jar"
));
expected
.
add
(
new
File
(
this
.
temp
,
"a.jar"
));
expected
.
add
(
new
File
(
this
.
temp
,
"b.jar"
));
expected
.
add
(
new
File
(
this
.
temp
,
"c.jar"
));
expected
.
add
(
new
File
(
this
.
temp
,
"d.jar"
));
expected
.
add
(
new
File
(
this
.
temp
,
"e.jar"
));
assertThat
(
urls
).
containsExactly
(
expected
.
stream
().
map
(
this
::
toUrl
).
toArray
(
URL
[]::
new
));
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/resources/org/springframework/boot/loader/classpath-index-file.idx
View file @
ad164269
BOOT-INF/layers/one/lib/
a.jar
BOOT-INF/layers/one/lib/
b.jar
BOOT-INF/layers/one/lib/
c.jar
BOOT-INF/layers/two/lib/
d.jar
BOOT-INF/layers/two/lib/
e.jar
a.jar
b.jar
c.jar
d.jar
e.jar
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