Skip to content

Commit af37f59

Browse files
committed
Merge branch '2.4.x' into 2.5.x
Closes gh-27056
2 parents 5139c79 + b790c82 commit af37f59

File tree

18 files changed

+344
-108
lines changed

18 files changed

+344
-108
lines changed

spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/archive/ArchiveCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ private List<Library> createLibraries(List<URL> dependencies) throws URISyntaxEx
198198
List<Library> libraries = new ArrayList<>();
199199
for (URL dependency : dependencies) {
200200
File file = new File(dependency.toURI());
201-
libraries.add(new Library(file, getLibraryScope(file)));
201+
libraries.add(new Library(null, file, getLibraryScope(file), null, false, false, true));
202202
}
203203
return libraries;
204204
}
@@ -256,7 +256,7 @@ private List<Library> addClasspathEntries(JarWriter writer, List<MatchedResource
256256
List<Library> libraries = new ArrayList<>();
257257
for (MatchedResource entry : entries) {
258258
if (entry.isRoot()) {
259-
libraries.add(new Library(entry.getFile(), LibraryScope.COMPILE));
259+
libraries.add(new Library(null, entry.getFile(), LibraryScope.COMPILE, null, false, false, true));
260260
}
261261
else {
262262
writeClasspathEntry(writer, entry);

spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/buildtoolplugins/otherbuildsystems/examplerepackageimplementation/MyBuildTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void build() throws IOException {
3737
private void getLibraries(LibraryCallback callback) throws IOException {
3838
// Build system specific implementation, callback for each dependency
3939
for (File nestedJar : getCompileScopeJars()) {
40-
callback.library(new Library(nestedJar, LibraryScope.COMPILE));
40+
callback.library(new Library(null, nestedJar, LibraryScope.COMPILE, null, false, false, true));
4141
}
4242
// ...
4343
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LayerResolver.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.boot.gradle.tasks.bundling.ResolvedDependencies.DependencyDescriptor;
2525
import org.springframework.boot.loader.tools.Layer;
2626
import org.springframework.boot.loader.tools.Library;
27+
import org.springframework.boot.loader.tools.LibraryCoordinates;
2728

2829
/**
2930
* Resolver backed by a {@link LayeredSpec} that provides the destination {@link Layer}
@@ -77,9 +78,12 @@ Iterable<Layer> getLayers() {
7778
private Library asLibrary(FileCopyDetails details) {
7879
File file = details.getFile();
7980
DependencyDescriptor dependency = this.resolvedDependencies.find(file);
80-
return (dependency != null)
81-
? new Library(null, file, null, dependency.getCoordinates(), false, dependency.isProjectDependency())
82-
: new Library(file, null);
81+
if (dependency == null) {
82+
return new Library(null, file, null, null, false, false, true);
83+
}
84+
LibraryCoordinates coordinates = dependency.getCoordinates();
85+
boolean projectDependency = dependency.isProjectDependency();
86+
return new Library(null, file, null, coordinates, false, projectDependency, true);
8387
}
8488

8589
}

spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/AbstractJarWriter.java

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.util.Enumeration;
3131
import java.util.HashSet;
3232
import java.util.Set;
33-
import java.util.function.Predicate;
33+
import java.util.function.Function;
3434
import java.util.jar.JarEntry;
3535
import java.util.jar.JarFile;
3636
import java.util.jar.JarInputStream;
@@ -89,24 +89,33 @@ public void writeManifest(Manifest manifest) throws IOException {
8989
* Write all entries from the specified jar file.
9090
* @param jarFile the source jar file
9191
* @throws IOException if the entries cannot be written
92+
* @deprecated since 2.4.8 for removal in 2.6.0
9293
*/
94+
@Deprecated
9395
public void writeEntries(JarFile jarFile) throws IOException {
94-
writeEntries(jarFile, EntryTransformer.NONE, UnpackHandler.NEVER, (name) -> false);
96+
writeEntries(jarFile, EntryTransformer.NONE, UnpackHandler.NEVER, (entry) -> null);
9597
}
9698

9799
final void writeEntries(JarFile jarFile, EntryTransformer entryTransformer, UnpackHandler unpackHandler,
98-
Predicate<String> libraryPredicate) throws IOException {
100+
Function<JarEntry, Library> libraryLookup) throws IOException {
99101
Enumeration<JarEntry> entries = jarFile.entries();
100102
while (entries.hasMoreElements()) {
101-
JarArchiveEntry entry = new JarArchiveEntry(entries.nextElement());
102-
setUpEntry(jarFile, entry);
103-
try (ZipHeaderPeekInputStream inputStream = new ZipHeaderPeekInputStream(jarFile.getInputStream(entry))) {
104-
EntryWriter entryWriter = new InputStreamEntryWriter(inputStream);
105-
JarArchiveEntry transformedEntry = entryTransformer.transform(entry);
106-
if (transformedEntry != null) {
107-
boolean updateLayerIndex = !libraryPredicate.test(entry.getName());
108-
writeEntry(transformedEntry, entryWriter, unpackHandler, updateLayerIndex);
109-
}
103+
JarEntry entry = entries.nextElement();
104+
Library library = libraryLookup.apply(entry);
105+
if (library == null || library.isIncluded()) {
106+
writeEntry(jarFile, entryTransformer, unpackHandler, new JarArchiveEntry(entry), library);
107+
}
108+
}
109+
}
110+
111+
private void writeEntry(JarFile jarFile, EntryTransformer entryTransformer, UnpackHandler unpackHandler,
112+
JarArchiveEntry entry, Library library) throws IOException {
113+
setUpEntry(jarFile, entry);
114+
try (ZipHeaderPeekInputStream inputStream = new ZipHeaderPeekInputStream(jarFile.getInputStream(entry))) {
115+
EntryWriter entryWriter = new InputStreamEntryWriter(inputStream);
116+
JarArchiveEntry transformedEntry = entryTransformer.transform(entry);
117+
if (transformedEntry != null) {
118+
writeEntry(transformedEntry, library, entryWriter, unpackHandler);
110119
}
111120
}
112121
}
@@ -160,15 +169,7 @@ public void writeNestedLibrary(String location, Library library) throws IOExcept
160169
entry.setTime(getNestedLibraryTime(library));
161170
new CrcAndSize(library::openStream).setupStoredEntry(entry);
162171
try (InputStream inputStream = library.openStream()) {
163-
writeEntry(entry, new InputStreamEntryWriter(inputStream), new LibraryUnpackHandler(library), false);
164-
updateLayerIndex(entry.getName(), library);
165-
}
166-
}
167-
168-
private void updateLayerIndex(String name, Library library) {
169-
if (this.layers != null) {
170-
Layer layer = this.layers.getLayer(library);
171-
this.layersIndex.add(layer, name);
172+
writeEntry(entry, library, new InputStreamEntryWriter(inputStream), new LibraryUnpackHandler(library));
172173
}
173174
}
174175

@@ -249,20 +250,20 @@ private boolean isClassEntry(JarEntry entry) {
249250
}
250251

251252
private void writeEntry(JarArchiveEntry entry, EntryWriter entryWriter) throws IOException {
252-
writeEntry(entry, entryWriter, UnpackHandler.NEVER, true);
253+
writeEntry(entry, null, entryWriter, UnpackHandler.NEVER);
253254
}
254255

255256
/**
256257
* Perform the actual write of a {@link JarEntry}. All other write methods delegate to
257258
* this one.
258259
* @param entry the entry to write
260+
* @param library the library for the entry or {@code null}
259261
* @param entryWriter the entry writer or {@code null} if there is no content
260262
* @param unpackHandler handles possible unpacking for the entry
261-
* @param updateLayerIndex if the layer index should be updated
262263
* @throws IOException in case of I/O errors
263264
*/
264-
private void writeEntry(JarArchiveEntry entry, EntryWriter entryWriter, UnpackHandler unpackHandler,
265-
boolean updateLayerIndex) throws IOException {
265+
private void writeEntry(JarArchiveEntry entry, Library library, EntryWriter entryWriter,
266+
UnpackHandler unpackHandler) throws IOException {
266267
String name = entry.getName();
267268
writeParentDirectoryEntries(name);
268269
if (this.writtenEntries.add(name)) {
@@ -273,16 +274,14 @@ private void writeEntry(JarArchiveEntry entry, EntryWriter entryWriter, UnpackHa
273274
entry.setSize(entryWriter.size());
274275
}
275276
entryWriter = addUnpackCommentIfNecessary(entry, entryWriter, unpackHandler);
276-
if (updateLayerIndex) {
277-
updateLayerIndex(entry);
278-
}
277+
updateLayerIndex(entry, library);
279278
writeToArchive(entry, entryWriter);
280279
}
281280
}
282281

283-
private void updateLayerIndex(JarArchiveEntry entry) {
282+
private void updateLayerIndex(JarArchiveEntry entry, Library library) {
284283
if (this.layers != null && !entry.getName().endsWith("/")) {
285-
Layer layer = this.layers.getLayer(entry.getName());
284+
Layer layer = (library != null) ? this.layers.getLayer(library) : this.layers.getLayer(entry.getName());
286285
this.layersIndex.add(layer, entry.getName());
287286
}
288287
}
@@ -294,7 +293,7 @@ private void writeParentDirectoryEntries(String name) throws IOException {
294293
while (parent.lastIndexOf('/') != -1) {
295294
parent = parent.substring(0, parent.lastIndexOf('/'));
296295
if (!parent.isEmpty()) {
297-
writeEntry(new JarArchiveEntry(parent + "/"), null, UnpackHandler.NEVER, false);
296+
writeEntry(new JarArchiveEntry(parent + "/"), null, null, UnpackHandler.NEVER);
298297
}
299298
}
300299
}

spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/JarModeLibrary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class JarModeLibrary extends Library {
4242
}
4343

4444
public JarModeLibrary(LibraryCoordinates coordinates) {
45-
super(getJarName(coordinates), null, LibraryScope.RUNTIME, coordinates, false);
45+
super(getJarName(coordinates), null, LibraryScope.RUNTIME, coordinates, false, false, true);
4646
}
4747

4848
private static LibraryCoordinates createCoordinates(String artifactId) {

spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Library.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,16 @@ public class Library {
4343

4444
private final boolean local;
4545

46+
private final boolean included;
47+
4648
/**
4749
* Create a new {@link Library}.
4850
* @param file the source file
4951
* @param scope the scope of the library
52+
* @deprecated since 2.4.8 for removal in 2.6.0 in favor of
53+
* {@link #Library(String, File, LibraryScope, LibraryCoordinates, boolean, boolean, boolean)}
5054
*/
55+
@Deprecated
5156
public Library(File file, LibraryScope scope) {
5257
this(file, scope, false);
5358
}
@@ -57,7 +62,10 @@ public Library(File file, LibraryScope scope) {
5762
* @param file the source file
5863
* @param scope the scope of the library
5964
* @param unpackRequired if the library needs to be unpacked before it can be used
65+
* @deprecated since 2.4.8 for removal in 2.6.0 in favor of
66+
* {@link #Library(String, File, LibraryScope, LibraryCoordinates, boolean, boolean, boolean)}
6067
*/
68+
@Deprecated
6169
public Library(File file, LibraryScope scope, boolean unpackRequired) {
6270
this(null, file, scope, unpackRequired);
6371
}
@@ -69,7 +77,10 @@ public Library(File file, LibraryScope scope, boolean unpackRequired) {
6977
* @param file the source file
7078
* @param scope the scope of the library
7179
* @param unpackRequired if the library needs to be unpacked before it can be used
80+
* @deprecated since 2.4.8 for removal in 2.6.0 in favor of
81+
* {@link #Library(String, File, LibraryScope, LibraryCoordinates, boolean, boolean, boolean)}
7282
*/
83+
@Deprecated
7384
public Library(String name, File file, LibraryScope scope, boolean unpackRequired) {
7485
this(name, file, scope, null, unpackRequired);
7586
}
@@ -82,7 +93,10 @@ public Library(String name, File file, LibraryScope scope, boolean unpackRequire
8293
* @param scope the scope of the library
8394
* @param coordinates the library coordinates or {@code null}
8495
* @param unpackRequired if the library needs to be unpacked before it can be used
96+
* @deprecated since 2.4.8 for removal in 2.6.0 in favor of
97+
* {@link #Library(String, File, LibraryScope, LibraryCoordinates, boolean, boolean, boolean)}
8598
*/
99+
@Deprecated
86100
public Library(String name, File file, LibraryScope scope, LibraryCoordinates coordinates, boolean unpackRequired) {
87101
this(name, file, scope, coordinates, unpackRequired, false);
88102
}
@@ -98,15 +112,37 @@ public Library(String name, File file, LibraryScope scope, LibraryCoordinates co
98112
* @param local if the library is local (part of the same build) to the application
99113
* that is being packaged
100114
* @since 2.4.0
115+
* @deprecated since 2.4.8 for removal in 2.6.0 in favor of
116+
* {@link #Library(String, File, LibraryScope, LibraryCoordinates, boolean, boolean, boolean)}
101117
*/
118+
@Deprecated
102119
public Library(String name, File file, LibraryScope scope, LibraryCoordinates coordinates, boolean unpackRequired,
103120
boolean local) {
121+
this(name, file, scope, coordinates, unpackRequired, local, true);
122+
}
123+
124+
/**
125+
* Create a new {@link Library}.
126+
* @param name the name of the library as it should be written or {@code null} to use
127+
* the file name
128+
* @param file the source file
129+
* @param scope the scope of the library
130+
* @param coordinates the library coordinates or {@code null}
131+
* @param unpackRequired if the library needs to be unpacked before it can be used
132+
* @param local if the library is local (part of the same build) to the application
133+
* that is being packaged
134+
* @param included if the library is included in the fat jar
135+
* @since 2.4.8
136+
*/
137+
public Library(String name, File file, LibraryScope scope, LibraryCoordinates coordinates, boolean unpackRequired,
138+
boolean local, boolean included) {
104139
this.name = (name != null) ? name : file.getName();
105140
this.file = file;
106141
this.scope = scope;
107142
this.coordinates = coordinates;
108143
this.unpackRequired = unpackRequired;
109144
this.local = local;
145+
this.included = included;
110146
}
111147

112148
/**
@@ -172,4 +208,12 @@ public boolean isLocal() {
172208
return this.local;
173209
}
174210

211+
/**
212+
* Return if the library is included in the fat jar.
213+
* @return if the library is included
214+
*/
215+
public boolean isIncluded() {
216+
return this.included;
217+
}
218+
175219
}

0 commit comments

Comments
 (0)