Apply Gradle fileMode and dirMode consistently in jar and war archives
Fixes gh-37496
This commit is contained in:
@@ -29,6 +29,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -45,6 +46,9 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import org.apache.commons.compress.archivers.zip.UnixStat;
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.zip.ZipFile;
|
||||
import org.gradle.testkit.runner.BuildResult;
|
||||
import org.gradle.testkit.runner.TaskOutcome;
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
@@ -62,6 +66,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Madhura Bhave
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
abstract class AbstractBootArchiveIntegrationTests {
|
||||
|
||||
@@ -515,6 +520,48 @@ abstract class AbstractBootArchiveIntegrationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void defaultDirAndFileModesAreUsed() throws IOException {
|
||||
BuildResult result = this.gradleBuild.build(this.taskName);
|
||||
assertThat(result.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
try (ZipFile jarFile = new ZipFile(new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0])) {
|
||||
Enumeration<ZipArchiveEntry> entries = jarFile.getEntries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipArchiveEntry entry = entries.nextElement();
|
||||
if (entry.getName().startsWith("META-INF/")) {
|
||||
continue;
|
||||
}
|
||||
if (entry.isDirectory()) {
|
||||
assertEntryMode(entry, UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM);
|
||||
}
|
||||
else {
|
||||
assertEntryMode(entry, UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void dirModeAndFileModeAreApplied() throws IOException {
|
||||
BuildResult result = this.gradleBuild.build(this.taskName);
|
||||
assertThat(result.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
try (ZipFile jarFile = new ZipFile(new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0])) {
|
||||
Enumeration<ZipArchiveEntry> entries = jarFile.getEntries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipArchiveEntry entry = entries.nextElement();
|
||||
if (entry.getName().startsWith("META-INF/")) {
|
||||
continue;
|
||||
}
|
||||
if (entry.isDirectory()) {
|
||||
assertEntryMode(entry, 0500);
|
||||
}
|
||||
else {
|
||||
assertEntryMode(entry, 0400);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void copyMainClassApplication() throws IOException {
|
||||
copyApplication("main");
|
||||
}
|
||||
@@ -650,4 +697,11 @@ abstract class AbstractBootArchiveIntegrationTests {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void assertEntryMode(ZipArchiveEntry entry, int expectedMode) {
|
||||
assertThat(entry.getUnixMode())
|
||||
.withFailMessage(() -> "Expected mode " + Integer.toOctalString(expectedMode) + " for entry "
|
||||
+ entry.getName() + " but actual is " + Integer.toOctalString(entry.getUnixMode()))
|
||||
.isEqualTo(expectedMode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user