diff --git a/initializr-web/src/main/java/io/spring/initializr/web/controller/ProjectGenerationController.java b/initializr-web/src/main/java/io/spring/initializr/web/controller/ProjectGenerationController.java index 4cb51cfb31..8d521570fd 100644 --- a/initializr-web/src/main/java/io/spring/initializr/web/controller/ProjectGenerationController.java +++ b/initializr-web/src/main/java/io/spring/initializr/web/controller/ProjectGenerationController.java @@ -141,7 +141,9 @@ public ResponseEntity springTgz(R request) throws IOException { private TarArchiveOutputStream createTarArchiveOutputStream(OutputStream output) { try { - return new TarArchiveOutputStream(new GzipCompressorOutputStream(output)); + final TarArchiveOutputStream taos = new TarArchiveOutputStream(new GzipCompressorOutputStream(output)); + taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); + return taos; } catch (IOException ex) { throw new IllegalStateException(ex); diff --git a/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectGenerationControllerIntegrationTests.java b/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectGenerationControllerIntegrationTests.java index dd40484d6c..6c1183fc47 100755 --- a/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectGenerationControllerIntegrationTests.java +++ b/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectGenerationControllerIntegrationTests.java @@ -65,6 +65,15 @@ void simpleTgzProject() { assertThat(project).mavenBuild().hasDependenciesSize(2).hasDependency("org.acme", "foo", "1.3.5"); } + @Test + void tgzProjectWithLongFilenames() { + String queryParams = "name=spring-boot-service&dependencies=org.acme:foo&artifactId=spring-boot-service" + + "&groupId=com.spring.boot.service&baseDir=spring-boot-service"; + + ResponseEntity entity = downloadArchive("/starter.tgz?" + queryParams); + assertArchiveResponseHeaders(entity, MediaType.valueOf("application/x-compress"), "spring-boot-service.tar.gz"); + } + private void assertArchiveResponseHeaders(ResponseEntity entity, MediaType contentType, String fileName) { assertThat(entity.getHeaders().getContentType()).isEqualTo(contentType); assertThat(entity.getHeaders().getContentDisposition()).isNotNull();