Smarter output detection for generated projects

Previously, specifying a simple target name for a regular project would
store the (zip) archive in a file matching the target name. Only adding a
slash at the end of the name allows to extract it as a directory. It
turns out that such convention is not easy to catch and if a simple name
is provided on the command-line, the user probably wants to create a
directory with such a name with the content of the project.

Note that if a build file is required and the name does not have any
extension, we still store a file with the required name as auto-detecting
the extension to use is not that easy.

Fixes gh-2056
This commit is contained in:
Stephane Nicoll
2014-12-05 14:33:27 +01:00
parent 61223e709c
commit 8efdffbc0e
2 changed files with 57 additions and 3 deletions

View File

@@ -48,7 +48,7 @@ class ProjectGenerator {
ProjectGenerationResponse response = this.initializrService.generate(request);
String fileName = (request.getOutput() != null ? request.getOutput() : response
.getFileName());
if (request.isExtract()) {
if (shouldExtract(request, response)) {
if (isZipArchive(response)) {
extractProject(response, request.getOutput(), force);
return;
@@ -68,6 +68,20 @@ class ProjectGenerator {
writeProject(response, fileName, force);
}
/**
* Detect if the project should be extracted.
*/
private boolean shouldExtract(ProjectGenerationRequest request, ProjectGenerationResponse response) {
if (request.isExtract()) {
return true;
}
// An explicit name has been provided for an archive and there is no extension in it
if (isZipArchive(response) && request.getOutput() != null && !request.getOutput().contains(".")) {
return true;
}
return false;
}
private boolean isZipArchive(ProjectGenerationResponse entity) {
if (entity.getContentType() != null) {
try {