mirror of
https://gitee.com/dcren/initializr.git
synced 2025-07-17 19:37:35 +08:00
Fix generation of filename with empty artifactId
Closes gh-831
This commit is contained in:
parent
f18c08f88f
commit
24887e1ab3
@ -61,6 +61,7 @@ import org.springframework.http.ResponseEntity.BodyBuilder;
|
|||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.util.DigestUtils;
|
import org.springframework.util.DigestUtils;
|
||||||
import org.springframework.util.StreamUtils;
|
import org.springframework.util.StreamUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
import org.springframework.web.bind.annotation.RequestHeader;
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@ -320,8 +321,11 @@ public class MainController extends AbstractInitializrController {
|
|||||||
"application/x-compress");
|
"application/x-compress");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String generateFileName(ProjectRequest request, String extension) {
|
private String generateFileName(ProjectRequest request, String extension) {
|
||||||
String tmp = request.getArtifactId().replaceAll(" ", "_");
|
String candidate = (StringUtils.hasText(request.getArtifactId())
|
||||||
|
? request.getArtifactId()
|
||||||
|
: this.metadataProvider.get().getArtifactId().getContent());
|
||||||
|
String tmp = candidate.replaceAll(" ", "_");
|
||||||
try {
|
try {
|
||||||
return URLEncoder.encode(tmp, "UTF-8") + "." + extension;
|
return URLEncoder.encode(tmp, "UTF-8") + "." + extension;
|
||||||
}
|
}
|
||||||
|
@ -166,17 +166,17 @@ public abstract class AbstractInitializrIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected ProjectAssert downloadZip(String context) {
|
protected ProjectAssert downloadZip(String context) {
|
||||||
byte[] body = downloadArchive(context);
|
byte[] body = downloadArchive(context).getBody();
|
||||||
return zipProjectAssert(body);
|
return zipProjectAssert(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ProjectAssert downloadTgz(String context) {
|
protected ProjectAssert downloadTgz(String context) {
|
||||||
byte[] body = downloadArchive(context);
|
byte[] body = downloadArchive(context).getBody();
|
||||||
return tgzProjectAssert(body);
|
return tgzProjectAssert(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected byte[] downloadArchive(String context) {
|
protected ResponseEntity<byte[]> downloadArchive(String context) {
|
||||||
return this.restTemplate.getForObject(createUrl(context), byte[].class);
|
return this.restTemplate.getForEntity(createUrl(context), byte[].class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ResponseEntity<String> invokeHome(String userAgentHeader,
|
protected ResponseEntity<String> invokeHome(String userAgentHeader,
|
||||||
|
@ -48,8 +48,12 @@ class MainControllerIntegrationTests
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void simpleZipProject() {
|
void simpleZipProject() {
|
||||||
downloadZip("/starter.zip?style=web&style=jpa").isJavaProject()
|
ResponseEntity<byte[]> entity = downloadArchive(
|
||||||
.hasFile(".gitignore").hasExecutableFile("mvnw").isMavenProject()
|
"/starter.zip?style=web&style=jpa");
|
||||||
|
assertArchiveResponseHeaders(entity, MediaType.valueOf("application/zip"),
|
||||||
|
"demo.zip");
|
||||||
|
zipProjectAssert(entity.getBody()).isJavaProject().hasFile(".gitignore")
|
||||||
|
.hasExecutableFile("mvnw").isMavenProject()
|
||||||
.hasStaticAndTemplatesResources(true).pomAssert().hasDependenciesCount(3)
|
.hasStaticAndTemplatesResources(true).pomAssert().hasDependenciesCount(3)
|
||||||
.hasSpringBootStarterDependency("web")
|
.hasSpringBootStarterDependency("web")
|
||||||
.hasSpringBootStarterDependency("data-jpa") // alias jpa -> data-jpa
|
.hasSpringBootStarterDependency("data-jpa") // alias jpa -> data-jpa
|
||||||
@ -58,12 +62,24 @@ class MainControllerIntegrationTests
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void simpleTgzProject() {
|
void simpleTgzProject() {
|
||||||
downloadTgz("/starter.tgz?style=org.acme:foo").isJavaProject()
|
ResponseEntity<byte[]> entity = downloadArchive(
|
||||||
.hasFile(".gitignore").hasExecutableFile("mvnw").isMavenProject()
|
"/starter.tgz?style=org.acme:foo");
|
||||||
|
assertArchiveResponseHeaders(entity, MediaType.valueOf("application/x-compress"),
|
||||||
|
"demo.tar.gz");
|
||||||
|
tgzProjectAssert(entity.getBody()).isJavaProject().hasFile(".gitignore")
|
||||||
|
.hasExecutableFile("mvnw").isMavenProject()
|
||||||
.hasStaticAndTemplatesResources(false).pomAssert().hasDependenciesCount(2)
|
.hasStaticAndTemplatesResources(false).pomAssert().hasDependenciesCount(2)
|
||||||
.hasDependency("org.acme", "foo", "1.3.5");
|
.hasDependency("org.acme", "foo", "1.3.5");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertArchiveResponseHeaders(ResponseEntity<byte[]> entity,
|
||||||
|
MediaType contentType, String fileName) {
|
||||||
|
assertThat(entity.getHeaders().getContentType()).isEqualTo(contentType);
|
||||||
|
assertThat(entity.getHeaders().getContentDisposition()).isNotNull();
|
||||||
|
assertThat(entity.getHeaders().getContentDisposition().getFilename())
|
||||||
|
.isEqualTo(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void dependencyInRange() {
|
void dependencyInRange() {
|
||||||
Dependency biz = Dependency.create("org.acme", "biz", "1.3.5", "runtime");
|
Dependency biz = Dependency.create("org.acme", "biz", "1.3.5", "runtime");
|
||||||
|
Loading…
Reference in New Issue
Block a user