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
da753300
Commit
da753300
authored
Oct 23, 2020
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.3.x'
Closes gh-23819
parents
1725594a
f84323fe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
48 deletions
+48
-48
AbstractJarWriter.java
.../springframework/boot/loader/tools/AbstractJarWriter.java
+39
-6
Packager.java
.../java/org/springframework/boot/loader/tools/Packager.java
+9
-42
No files found.
spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/AbstractJarWriter.java
View file @
da753300
...
@@ -60,6 +60,20 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
...
@@ -60,6 +60,20 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
private
final
Set
<
String
>
writtenEntries
=
new
HashSet
<>();
private
final
Set
<
String
>
writtenEntries
=
new
HashSet
<>();
private
Layers
layers
;
private
LayersIndex
layersIndex
;
/**
* Update this writer to use specific layers.
* @param layers the layers to use
* @param layersIndex the layers index to update
*/
void
useLayers
(
Layers
layers
,
LayersIndex
layersIndex
)
{
this
.
layers
=
layers
;
this
.
layersIndex
=
layersIndex
;
}
/**
/**
* Write the specified manifest.
* Write the specified manifest.
* @param manifest the manifest to write
* @param manifest the manifest to write
...
@@ -89,7 +103,7 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
...
@@ -89,7 +103,7 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
EntryWriter
entryWriter
=
new
InputStreamEntryWriter
(
inputStream
);
EntryWriter
entryWriter
=
new
InputStreamEntryWriter
(
inputStream
);
JarArchiveEntry
transformedEntry
=
entryTransformer
.
transform
(
entry
);
JarArchiveEntry
transformedEntry
=
entryTransformer
.
transform
(
entry
);
if
(
transformedEntry
!=
null
)
{
if
(
transformedEntry
!=
null
)
{
writeEntry
(
transformedEntry
,
entryWriter
,
unpackHandler
);
writeEntry
(
transformedEntry
,
entryWriter
,
unpackHandler
,
true
);
}
}
}
}
}
}
...
@@ -144,7 +158,15 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
...
@@ -144,7 +158,15 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
entry
.
setTime
(
getNestedLibraryTime
(
library
));
entry
.
setTime
(
getNestedLibraryTime
(
library
));
new
CrcAndSize
(
library:
:
openStream
).
setupStoredEntry
(
entry
);
new
CrcAndSize
(
library:
:
openStream
).
setupStoredEntry
(
entry
);
try
(
InputStream
inputStream
=
library
.
openStream
())
{
try
(
InputStream
inputStream
=
library
.
openStream
())
{
writeEntry
(
entry
,
new
InputStreamEntryWriter
(
inputStream
),
new
LibraryUnpackHandler
(
library
));
writeEntry
(
entry
,
new
InputStreamEntryWriter
(
inputStream
),
new
LibraryUnpackHandler
(
library
),
false
);
updateLayerIndex
(
entry
.
getName
(),
library
);
}
}
private
void
updateLayerIndex
(
String
name
,
Library
library
)
{
if
(
this
.
layers
!=
null
)
{
Layer
layer
=
this
.
layers
.
getLayer
(
library
);
this
.
layersIndex
.
add
(
layer
,
name
);
}
}
}
}
...
@@ -225,7 +247,7 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
...
@@ -225,7 +247,7 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
}
}
private
void
writeEntry
(
JarArchiveEntry
entry
,
EntryWriter
entryWriter
)
throws
IOException
{
private
void
writeEntry
(
JarArchiveEntry
entry
,
EntryWriter
entryWriter
)
throws
IOException
{
writeEntry
(
entry
,
entryWriter
,
UnpackHandler
.
NEVER
);
writeEntry
(
entry
,
entryWriter
,
UnpackHandler
.
NEVER
,
true
);
}
}
/**
/**
...
@@ -234,10 +256,11 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
...
@@ -234,10 +256,11 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
* @param entry the entry to write
* @param entry the entry to write
* @param entryWriter the entry writer or {@code null} if there is no content
* @param entryWriter the entry writer or {@code null} if there is no content
* @param unpackHandler handles possible unpacking for the entry
* @param unpackHandler handles possible unpacking for the entry
* @param updateLayerIndex if the layer index should be updated
* @throws IOException in case of I/O errors
* @throws IOException in case of I/O errors
*/
*/
private
void
writeEntry
(
JarArchiveEntry
entry
,
EntryWriter
entryWriter
,
UnpackHandler
unpackHandler
)
private
void
writeEntry
(
JarArchiveEntry
entry
,
EntryWriter
entryWriter
,
UnpackHandler
unpackHandler
,
throws
IOException
{
boolean
updateLayerIndex
)
throws
IOException
{
String
name
=
entry
.
getName
();
String
name
=
entry
.
getName
();
writeParentDirectoryEntries
(
name
);
writeParentDirectoryEntries
(
name
);
if
(
this
.
writtenEntries
.
add
(
name
))
{
if
(
this
.
writtenEntries
.
add
(
name
))
{
...
@@ -248,10 +271,20 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
...
@@ -248,10 +271,20 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
entry
.
setSize
(
entryWriter
.
size
());
entry
.
setSize
(
entryWriter
.
size
());
}
}
entryWriter
=
addUnpackCommentIfNecessary
(
entry
,
entryWriter
,
unpackHandler
);
entryWriter
=
addUnpackCommentIfNecessary
(
entry
,
entryWriter
,
unpackHandler
);
if
(
updateLayerIndex
)
{
updateLayerIndex
(
entry
);
}
writeToArchive
(
entry
,
entryWriter
);
writeToArchive
(
entry
,
entryWriter
);
}
}
}
}
private
void
updateLayerIndex
(
JarArchiveEntry
entry
)
{
if
(
this
.
layers
!=
null
&&
!
entry
.
getName
().
endsWith
(
"/"
))
{
Layer
layer
=
this
.
layers
.
getLayer
(
entry
.
getName
());
this
.
layersIndex
.
add
(
layer
,
entry
.
getName
());
}
}
protected
abstract
void
writeToArchive
(
ZipEntry
entry
,
EntryWriter
entryWriter
)
throws
IOException
;
protected
abstract
void
writeToArchive
(
ZipEntry
entry
,
EntryWriter
entryWriter
)
throws
IOException
;
private
void
writeParentDirectoryEntries
(
String
name
)
throws
IOException
{
private
void
writeParentDirectoryEntries
(
String
name
)
throws
IOException
{
...
@@ -259,7 +292,7 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
...
@@ -259,7 +292,7 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
while
(
parent
.
lastIndexOf
(
'/'
)
!=
-
1
)
{
while
(
parent
.
lastIndexOf
(
'/'
)
!=
-
1
)
{
parent
=
parent
.
substring
(
0
,
parent
.
lastIndexOf
(
'/'
));
parent
=
parent
.
substring
(
0
,
parent
.
lastIndexOf
(
'/'
));
if
(!
parent
.
isEmpty
())
{
if
(!
parent
.
isEmpty
())
{
writeEntry
(
new
JarArchiveEntry
(
parent
+
"/"
),
null
,
UnpackHandler
.
NEVER
);
writeEntry
(
new
JarArchiveEntry
(
parent
+
"/"
),
null
,
UnpackHandler
.
NEVER
,
false
);
}
}
}
}
}
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Packager.java
View file @
da753300
...
@@ -29,7 +29,6 @@ import java.util.jar.Attributes;
...
@@ -29,7 +29,6 @@ import java.util.jar.Attributes;
import
java.util.jar.JarFile
;
import
java.util.jar.JarFile
;
import
java.util.jar.Manifest
;
import
java.util.jar.Manifest
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
java.util.zip.ZipEntry
;
import
org.apache.commons.compress.archivers.jar.JarArchiveEntry
;
import
org.apache.commons.compress.archivers.jar.JarArchiveEntry
;
...
@@ -168,25 +167,18 @@ public abstract class Packager {
...
@@ -168,25 +167,18 @@ public abstract class Packager {
protected
final
void
write
(
JarFile
sourceJar
,
Libraries
libraries
,
AbstractJarWriter
writer
)
throws
IOException
{
protected
final
void
write
(
JarFile
sourceJar
,
Libraries
libraries
,
AbstractJarWriter
writer
)
throws
IOException
{
Assert
.
notNull
(
libraries
,
"Libraries must not be null"
);
Assert
.
notNull
(
libraries
,
"Libraries must not be null"
);
WritableLibraries
writeableLibraries
=
new
WritableLibraries
(
libraries
);
WritableLibraries
writeableLibraries
=
new
WritableLibraries
(
libraries
);
if
(
isLayer
sEnabl
ed
())
{
if
(
isLayered
())
{
writer
=
new
LayerTrackingEntryWriter
(
writer
);
writer
.
useLayers
(
this
.
layers
,
this
.
layersIndex
);
}
}
writer
.
writeManifest
(
buildManifest
(
sourceJar
));
writer
.
writeManifest
(
buildManifest
(
sourceJar
));
writeLoaderClasses
(
writer
);
writeLoaderClasses
(
writer
);
writer
.
writeEntries
(
sourceJar
,
getEntityTransformer
(),
writeableLibraries
);
writer
.
writeEntries
(
sourceJar
,
getEntityTransformer
(),
writeableLibraries
);
writeableLibraries
.
write
(
writer
);
writeableLibraries
.
write
(
writer
);
if
(
isLayer
sEnabl
ed
())
{
if
(
isLayered
())
{
writeLayerIndex
(
writer
);
writeLayerIndex
(
writer
);
}
}
}
}
private
boolean
isLayersEnabled
()
{
if
(!(
getLayout
()
instanceof
Layouts
.
Jar
))
{
return
false
;
}
return
this
.
layers
!=
null
;
}
private
void
writeLoaderClasses
(
AbstractJarWriter
writer
)
throws
IOException
{
private
void
writeLoaderClasses
(
AbstractJarWriter
writer
)
throws
IOException
{
Layout
layout
=
getLayout
();
Layout
layout
=
getLayout
();
if
(
layout
instanceof
CustomLoaderLayout
)
{
if
(
layout
instanceof
CustomLoaderLayout
)
{
...
@@ -339,7 +331,7 @@ public abstract class Packager {
...
@@ -339,7 +331,7 @@ public abstract class Packager {
attributes
.
putValue
(
BOOT_CLASSES_ATTRIBUTE
,
layout
.
getRepackagedClassesLocation
());
attributes
.
putValue
(
BOOT_CLASSES_ATTRIBUTE
,
layout
.
getRepackagedClassesLocation
());
putIfHasLength
(
attributes
,
BOOT_LIB_ATTRIBUTE
,
getLayout
().
getLibraryLocation
(
""
,
LibraryScope
.
COMPILE
));
putIfHasLength
(
attributes
,
BOOT_LIB_ATTRIBUTE
,
getLayout
().
getLibraryLocation
(
""
,
LibraryScope
.
COMPILE
));
putIfHasLength
(
attributes
,
BOOT_CLASSPATH_INDEX_ATTRIBUTE
,
layout
.
getClasspathIndexFileLocation
());
putIfHasLength
(
attributes
,
BOOT_CLASSPATH_INDEX_ATTRIBUTE
,
layout
.
getClasspathIndexFileLocation
());
if
(
isLayer
sEnabl
ed
())
{
if
(
isLayered
())
{
putIfHasLength
(
attributes
,
BOOT_LAYERS_INDEX_ATTRIBUTE
,
layout
.
getLayersIndexFileLocation
());
putIfHasLength
(
attributes
,
BOOT_LAYERS_INDEX_ATTRIBUTE
,
layout
.
getLayersIndexFileLocation
());
}
}
}
}
...
@@ -355,6 +347,10 @@ public abstract class Packager {
...
@@ -355,6 +347,10 @@ public abstract class Packager {
}
}
}
}
private
boolean
isLayered
()
{
return
this
.
layers
!=
null
&&
getLayout
()
instanceof
Layouts
.
Jar
;
}
/**
/**
* Callback interface used to present a warning when finding the main class takes too
* Callback interface used to present a warning when finding the main class takes too
* long.
* long.
...
@@ -429,35 +425,6 @@ public abstract class Packager {
...
@@ -429,35 +425,6 @@ public abstract class Packager {
}
}
/**
* Decorator to track the layers as entries are written.
*/
private
final
class
LayerTrackingEntryWriter
extends
AbstractJarWriter
{
private
final
AbstractJarWriter
writer
;
private
LayerTrackingEntryWriter
(
AbstractJarWriter
writer
)
{
this
.
writer
=
writer
;
}
@Override
public
void
writeNestedLibrary
(
String
location
,
Library
library
)
throws
IOException
{
this
.
writer
.
writeNestedLibrary
(
location
,
library
);
Layer
layer
=
Packager
.
this
.
layers
.
getLayer
(
library
);
Packager
.
this
.
layersIndex
.
add
(
layer
,
location
+
library
.
getName
());
}
@Override
protected
void
writeToArchive
(
ZipEntry
entry
,
EntryWriter
entryWriter
)
throws
IOException
{
this
.
writer
.
writeToArchive
(
entry
,
entryWriter
);
if
(!
entry
.
getName
().
endsWith
(
"/"
))
{
Layer
layer
=
Packager
.
this
.
layers
.
getLayer
(
entry
.
getName
());
Packager
.
this
.
layersIndex
.
add
(
layer
,
entry
.
getName
());
}
}
}
/**
/**
* An {@link UnpackHandler} that determines that an entry needs to be unpacked if a
* An {@link UnpackHandler} that determines that an entry needs to be unpacked if a
* library that requires unpacking has a matching entry name.
* library that requires unpacking has a matching entry name.
...
@@ -472,7 +439,7 @@ public abstract class Packager {
...
@@ -472,7 +439,7 @@ public abstract class Packager {
addLibrary
(
library
);
addLibrary
(
library
);
}
}
});
});
if
(
isLayer
sEnabl
ed
()
&&
Packager
.
this
.
includeRelevantJarModeJars
)
{
if
(
isLayered
()
&&
Packager
.
this
.
includeRelevantJarModeJars
)
{
addLibrary
(
JarModeLibrary
.
LAYER_TOOLS
);
addLibrary
(
JarModeLibrary
.
LAYER_TOOLS
);
}
}
}
}
...
...
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