Commit 555132e0 authored by Scott Frederick's avatar Scott Frederick

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
parent dc566086
......@@ -22,9 +22,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.Calendar;
import java.util.Collection;
import java.util.GregorianCalendar;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
......@@ -63,11 +63,12 @@ import org.springframework.util.StringUtils;
*
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class BootZipCopyAction implements CopyAction {
static final long CONSTANT_TIME_FOR_ZIP_ENTRIES = OffsetDateTime.of(1980, 2, 1, 0, 0, 0, 0, ZoneOffset.UTC)
.toInstant().toEpochMilli();
static final long CONSTANT_TIME_FOR_ZIP_ENTRIES = new GregorianCalendar(1980, Calendar.FEBRUARY, 1, 0, 0, 0)
.getTimeInMillis();
private final File output;
......@@ -261,7 +262,7 @@ class BootZipCopyAction implements CopyAction {
if (parentDirectory != null && this.writtenDirectories.add(parentDirectory)) {
writeParentDirectoriesIfNecessary(parentDirectory, time);
ZipArchiveEntry entry = new ZipArchiveEntry(parentDirectory + '/');
entry.setUnixMode(UnixStat.DIR_FLAG);
entry.setUnixMode(UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM);
entry.setTime(time);
this.out.putArchiveEntry(entry);
this.out.closeArchiveEntry();
......@@ -372,7 +373,7 @@ class BootZipCopyAction implements CopyAction {
ZipEntryCustomizer entryCustomizer) throws IOException {
writeParentDirectoriesIfNecessary(name, CONSTANT_TIME_FOR_ZIP_ENTRIES);
ZipArchiveEntry entry = new ZipArchiveEntry(name);
entry.setUnixMode(UnixStat.FILE_FLAG);
entry.setUnixMode(UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM);
entry.setTime(CONSTANT_TIME_FOR_ZIP_ENTRIES);
entryCustomizer.customize(entry);
this.out.putArchiveEntry(entry);
......
......@@ -101,10 +101,14 @@ class BootJarTests extends AbstractBootArchiveTests<TestBootJar> {
assertThat(entryNames).contains("BOOT-INF/lib/first-library.jar", "BOOT-INF/lib/second-library.jar",
"BOOT-INF/lib/third-library-SNAPSHOT.jar", "BOOT-INF/classes/com/example/Application.class",
"BOOT-INF/classes/application.properties", "BOOT-INF/classes/static/test.css");
ZipEntry layersIndexEntry = jarFile.getEntry("BOOT-INF/layers.idx");
assertThat(layersIndexEntry.getTime()).isEqualTo(BootZipCopyAction.CONSTANT_TIME_FOR_ZIP_ENTRIES);
List<String> index = entryLines(jarFile, "BOOT-INF/layers.idx");
assertThat(getLayerNames(index)).containsExactly("dependencies", "spring-boot-loader",
"snapshot-dependencies", "application");
String layerToolsJar = "BOOT-INF/lib/" + JarModeLibrary.LAYER_TOOLS.getName();
ZipEntry layerToolsEntry = jarFile.getEntry(layerToolsJar);
assertThat(layerToolsEntry.getTime()).isEqualTo(BootZipCopyAction.CONSTANT_TIME_FOR_ZIP_ENTRIES);
List<String> expected = new ArrayList<>();
expected.add("- \"dependencies\":");
expected.add(" - \"BOOT-INF/lib/first-library.jar\"");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment