Skip to content

Commit 555132e

Browse files
Fix archive attributes in Gradle plugin
This commit ensures that file permissions are set on entries that the Gradle plugin adds to an archive. It also reverts the constant date and time used for added entries to a previous value to ensure a time zone offset is not applied. See gh-20927
1 parent dc56608 commit 555132e

File tree

2 files changed

+11
-6
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src

2 files changed

+11
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import java.io.InputStream;
2323
import java.io.OutputStream;
2424
import java.io.OutputStreamWriter;
25-
import java.time.OffsetDateTime;
26-
import java.time.ZoneOffset;
25+
import java.util.Calendar;
2726
import java.util.Collection;
27+
import java.util.GregorianCalendar;
2828
import java.util.LinkedHashSet;
2929
import java.util.List;
3030
import java.util.Map;
@@ -63,11 +63,12 @@
6363
*
6464
* @author Andy Wilkinson
6565
* @author Phillip Webb
66+
* @author Scott Frederick
6667
*/
6768
class BootZipCopyAction implements CopyAction {
6869

69-
static final long CONSTANT_TIME_FOR_ZIP_ENTRIES = OffsetDateTime.of(1980, 2, 1, 0, 0, 0, 0, ZoneOffset.UTC)
70-
.toInstant().toEpochMilli();
70+
static final long CONSTANT_TIME_FOR_ZIP_ENTRIES = new GregorianCalendar(1980, Calendar.FEBRUARY, 1, 0, 0, 0)
71+
.getTimeInMillis();
7172

7273
private final File output;
7374

@@ -261,7 +262,7 @@ private void writeParentDirectoriesIfNecessary(String name, long time) throws IO
261262
if (parentDirectory != null && this.writtenDirectories.add(parentDirectory)) {
262263
writeParentDirectoriesIfNecessary(parentDirectory, time);
263264
ZipArchiveEntry entry = new ZipArchiveEntry(parentDirectory + '/');
264-
entry.setUnixMode(UnixStat.DIR_FLAG);
265+
entry.setUnixMode(UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM);
265266
entry.setTime(time);
266267
this.out.putArchiveEntry(entry);
267268
this.out.closeArchiveEntry();
@@ -372,7 +373,7 @@ private void writeEntry(String name, ZipEntryWriter entryWriter, boolean addToLa
372373
ZipEntryCustomizer entryCustomizer) throws IOException {
373374
writeParentDirectoriesIfNecessary(name, CONSTANT_TIME_FOR_ZIP_ENTRIES);
374375
ZipArchiveEntry entry = new ZipArchiveEntry(name);
375-
entry.setUnixMode(UnixStat.FILE_FLAG);
376+
entry.setUnixMode(UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM);
376377
entry.setTime(CONSTANT_TIME_FOR_ZIP_ENTRIES);
377378
entryCustomizer.customize(entry);
378379
this.out.putArchiveEntry(entry);

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@ void whenJarIsLayeredThenLayersIndexIsPresentAndCorrect() throws IOException {
101101
assertThat(entryNames).contains("BOOT-INF/lib/first-library.jar", "BOOT-INF/lib/second-library.jar",
102102
"BOOT-INF/lib/third-library-SNAPSHOT.jar", "BOOT-INF/classes/com/example/Application.class",
103103
"BOOT-INF/classes/application.properties", "BOOT-INF/classes/static/test.css");
104+
ZipEntry layersIndexEntry = jarFile.getEntry("BOOT-INF/layers.idx");
105+
assertThat(layersIndexEntry.getTime()).isEqualTo(BootZipCopyAction.CONSTANT_TIME_FOR_ZIP_ENTRIES);
104106
List<String> index = entryLines(jarFile, "BOOT-INF/layers.idx");
105107
assertThat(getLayerNames(index)).containsExactly("dependencies", "spring-boot-loader",
106108
"snapshot-dependencies", "application");
107109
String layerToolsJar = "BOOT-INF/lib/" + JarModeLibrary.LAYER_TOOLS.getName();
110+
ZipEntry layerToolsEntry = jarFile.getEntry(layerToolsJar);
111+
assertThat(layerToolsEntry.getTime()).isEqualTo(BootZipCopyAction.CONSTANT_TIME_FOR_ZIP_ENTRIES);
108112
List<String> expected = new ArrayList<>();
109113
expected.add("- \"dependencies\":");
110114
expected.add(" - \"BOOT-INF/lib/first-library.jar\"");

0 commit comments

Comments
 (0)