Merge branch '2.7.x' into 3.0.x

Closes gh-37587
This commit is contained in:
Scott Frederick
2023-09-26 14:06:50 -05:00
6 changed files with 118 additions and 15 deletions

View File

@@ -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;
@@ -44,6 +45,9 @@ import java.util.jar.Manifest;
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;
@@ -61,6 +65,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
* @author Madhura Bhave
* @author Scott Frederick
*/
abstract class AbstractBootArchiveIntegrationTests {
@@ -523,6 +528,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");
}
@@ -660,4 +707,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);
}
}