Apply eclipse formatting rules
Apply eclipse formatting rules to b2fe2dd9.
See gh-1751
This commit is contained in:
@@ -40,7 +40,8 @@ public class DefaultCommandFactory implements CommandFactory {
|
||||
|
||||
private static final List<Command> DEFAULT_COMMANDS = Arrays.<Command> asList(
|
||||
new VersionCommand(), new RunCommand(), new TestCommand(), new GrabCommand(),
|
||||
new JarCommand(), new InstallCommand(), new UninstallCommand(), new InitCommand());
|
||||
new JarCommand(), new InstallCommand(), new UninstallCommand(),
|
||||
new InitCommand());
|
||||
|
||||
@Override
|
||||
public Collection<Command> getCommands() {
|
||||
|
||||
@@ -31,7 +31,7 @@ class Dependency {
|
||||
private String description;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
@@ -39,7 +39,7 @@ class Dependency {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
@@ -47,10 +47,11 @@ class Dependency {
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.boot.cli.command.init;
|
||||
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
|
||||
import org.springframework.boot.cli.command.Command;
|
||||
import org.springframework.boot.cli.command.OptionParsingCommand;
|
||||
|
||||
@@ -30,7 +29,8 @@ import org.springframework.boot.cli.command.OptionParsingCommand;
|
||||
public class InitCommand extends OptionParsingCommand {
|
||||
|
||||
InitCommand(InitCommandOptionHandler handler) {
|
||||
super("init", "Initialize a new project structure using Spring Initializr", handler);
|
||||
super("init", "Initialize a new project structure from Spring Initializr",
|
||||
handler);
|
||||
}
|
||||
|
||||
public InitCommand() {
|
||||
|
||||
@@ -27,8 +27,8 @@ import java.util.zip.ZipInputStream;
|
||||
|
||||
import joptsimple.OptionSet;
|
||||
import joptsimple.OptionSpec;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.springframework.boot.cli.command.options.OptionHandler;
|
||||
import org.springframework.boot.cli.command.status.ExitStatus;
|
||||
import org.springframework.boot.cli.util.Log;
|
||||
@@ -78,46 +78,61 @@ public class InitCommandOptionHandler extends OptionHandler {
|
||||
|
||||
@Override
|
||||
protected void options() {
|
||||
this.target = option(Arrays.asList("target"),
|
||||
"URL of the service to use").withRequiredArg().defaultsTo(ProjectGenerationRequest.DEFAULT_SERVICE_URL);
|
||||
this.listMetadata = option(Arrays.asList("list", "l"), "List the capabilities of the service. Use it to " +
|
||||
"discover the dependencies and the types that are available.");
|
||||
this.target = option(Arrays.asList("target"), "URL of the service to use")
|
||||
.withRequiredArg().defaultsTo(
|
||||
ProjectGenerationRequest.DEFAULT_SERVICE_URL);
|
||||
this.listMetadata = option(Arrays.asList("list", "l"),
|
||||
"List the capabilities of the service. Use it to "
|
||||
+ "discover the dependencies and the types that are available.");
|
||||
|
||||
// Project generation settings
|
||||
this.bootVersion = option(Arrays.asList("boot-version", "bv"),
|
||||
"Spring Boot version to use (e.g. 1.2.0.RELEASE)").withRequiredArg();
|
||||
this.dependencies = option(Arrays.asList("dependencies", "d"),
|
||||
"Comma separated list of dependencies to include in the generated project").withRequiredArg();
|
||||
"Comma separated list of dependencies to include in the generated project")
|
||||
.withRequiredArg();
|
||||
this.javaVersion = option(Arrays.asList("java-version", "jv"),
|
||||
"Java version to use (e.g. 1.8)").withRequiredArg();
|
||||
this.packaging = option(Arrays.asList("packaging", "p"), "Packaging type to use (e.g. jar)").withRequiredArg();
|
||||
this.packaging = option(Arrays.asList("packaging", "p"),
|
||||
"Packaging type to use (e.g. jar)").withRequiredArg();
|
||||
|
||||
this.build = option("build", "The build system to use (e.g. maven, gradle). To be used alongside " +
|
||||
"--format to uniquely identify one type that is supported by the service. " +
|
||||
"Use --type in case of conflict").withRequiredArg().defaultsTo("maven");
|
||||
this.format = option("format", "The format of the generated content (e.g. build for a build file, " +
|
||||
"project for a project archive). To be used alongside --build to uniquely identify one type " +
|
||||
"that is supported by the service. Use --type in case of conflict")
|
||||
this.build = option(
|
||||
"build",
|
||||
"The build system to use (e.g. maven, gradle). To be used alongside "
|
||||
+ "--format to uniquely identify one type that is supported by the service. "
|
||||
+ "Use --type in case of conflict").withRequiredArg().defaultsTo(
|
||||
"maven");
|
||||
this.format = option(
|
||||
"format",
|
||||
"The format of the generated content (e.g. build for a build file, "
|
||||
+ "project for a project archive). To be used alongside --build to uniquely identify one type "
|
||||
+ "that is supported by the service. Use --type in case of conflict")
|
||||
.withRequiredArg().defaultsTo("project");
|
||||
this.type = option(Arrays.asList("type", "t"), "The project type to use. Not normally needed if you " +
|
||||
"use --build and/or --format. Check the capabilities of the service (--list) for " +
|
||||
"more details.").withRequiredArg();
|
||||
this.type = option(
|
||||
Arrays.asList("type", "t"),
|
||||
"The project type to use. Not normally needed if you "
|
||||
+ "use --build and/or --format. Check the capabilities of the service (--list) for "
|
||||
+ "more details.").withRequiredArg();
|
||||
|
||||
// Others
|
||||
this.extract = option(Arrays.asList("extract", "x"), "Extract the project archive");
|
||||
this.force = option(Arrays.asList("force", "f"), "Force overwrite of existing files");
|
||||
this.output = option(Arrays.asList("output", "o"),
|
||||
"Location of the generated project. Can be an absolute or a relative reference and " +
|
||||
"should refer to a directory when --extract is used.").withRequiredArg();
|
||||
this.extract = option(Arrays.asList("extract", "x"),
|
||||
"Extract the project archive");
|
||||
this.force = option(Arrays.asList("force", "f"),
|
||||
"Force overwrite of existing files");
|
||||
this.output = option(
|
||||
Arrays.asList("output", "o"),
|
||||
"Location of the generated project. Can be an absolute or a relative reference and "
|
||||
+ "should refer to a directory when --extract is used.")
|
||||
.withRequiredArg();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExitStatus run(OptionSet options) throws Exception {
|
||||
if (options.has(listMetadata)) {
|
||||
return listServiceCapabilities(options, httpClient);
|
||||
if (options.has(this.listMetadata)) {
|
||||
return listServiceCapabilities(options, this.httpClient);
|
||||
}
|
||||
else {
|
||||
return generateProject(options, httpClient);
|
||||
return generateProject(options, this.httpClient);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +166,8 @@ public class InitCommandOptionHandler extends OptionHandler {
|
||||
return request;
|
||||
}
|
||||
|
||||
protected ExitStatus listServiceCapabilities(OptionSet options, CloseableHttpClient httpClient) throws IOException {
|
||||
protected ExitStatus listServiceCapabilities(OptionSet options,
|
||||
CloseableHttpClient httpClient) throws IOException {
|
||||
ListMetadataCommand command = new ListMetadataCommand(httpClient);
|
||||
Log.info(command.generateReport(determineServiceUrl(options)));
|
||||
return ExitStatus.OK;
|
||||
@@ -161,19 +177,22 @@ public class InitCommandOptionHandler extends OptionHandler {
|
||||
ProjectGenerationRequest request = createProjectGenerationRequest(options);
|
||||
boolean forceValue = options.has(this.force);
|
||||
try {
|
||||
ProjectGenerationResponse entity = new InitializrServiceHttpInvoker(httpClient).generate(request);
|
||||
ProjectGenerationResponse entity = new InitializrServiceHttpInvoker(
|
||||
httpClient).generate(request);
|
||||
if (options.has(this.extract)) {
|
||||
if (isZipArchive(entity)) {
|
||||
return extractProject(entity, options.valueOf(this.output), forceValue);
|
||||
return extractProject(entity, options.valueOf(this.output),
|
||||
forceValue);
|
||||
}
|
||||
else {
|
||||
Log.info("Could not extract '" + entity.getContentType() + "'");
|
||||
}
|
||||
}
|
||||
String outputFileName = entity.getFileName() != null ? entity.getFileName() : options.valueOf(this.output);
|
||||
String outputFileName = entity.getFileName() != null ? entity.getFileName()
|
||||
: options.valueOf(this.output);
|
||||
if (outputFileName == null) {
|
||||
Log.error("Could not save the project, the server did not set a preferred " +
|
||||
"file name. Use --output to specify the output location for the project.");
|
||||
Log.error("Could not save the project, the server did not set a preferred "
|
||||
+ "file name. Use --output to specify the output location for the project.");
|
||||
return ExitStatus.ERROR;
|
||||
}
|
||||
return writeProject(entity, outputFileName, forceValue);
|
||||
@@ -192,8 +211,8 @@ public class InitCommandOptionHandler extends OptionHandler {
|
||||
return options.valueOf(this.target);
|
||||
}
|
||||
|
||||
private ExitStatus writeProject(ProjectGenerationResponse entity, String outputFileName, boolean overwrite)
|
||||
throws IOException {
|
||||
private ExitStatus writeProject(ProjectGenerationResponse entity,
|
||||
String outputFileName, boolean overwrite) throws IOException {
|
||||
|
||||
File f = new File(outputFileName);
|
||||
if (f.exists()) {
|
||||
@@ -204,8 +223,9 @@ public class InitCommandOptionHandler extends OptionHandler {
|
||||
}
|
||||
}
|
||||
else {
|
||||
Log.error("File '" + f.getName() + "' already exists. Use --force if you want to " +
|
||||
"overwrite or --output to specify an alternate location.");
|
||||
Log.error("File '" + f.getName()
|
||||
+ "' already exists. Use --force if you want to "
|
||||
+ "overwrite or --output to specify an alternate location.");
|
||||
return ExitStatus.ERROR;
|
||||
}
|
||||
}
|
||||
@@ -232,12 +252,15 @@ public class InitCommandOptionHandler extends OptionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private ExitStatus extractProject(ProjectGenerationResponse entity, String outputValue, boolean overwrite) throws IOException {
|
||||
File output = outputValue != null ? new File(outputValue) : new File(System.getProperty("user.dir"));
|
||||
private ExitStatus extractProject(ProjectGenerationResponse entity,
|
||||
String outputValue, boolean overwrite) throws IOException {
|
||||
File output = outputValue != null ? new File(outputValue) : new File(
|
||||
System.getProperty("user.dir"));
|
||||
if (!output.exists()) {
|
||||
output.mkdirs();
|
||||
}
|
||||
ZipInputStream zipIn = new ZipInputStream(new ByteArrayInputStream(entity.getContent()));
|
||||
ZipInputStream zipIn = new ZipInputStream(new ByteArrayInputStream(
|
||||
entity.getContent()));
|
||||
try {
|
||||
ZipEntry entry = zipIn.getNextEntry();
|
||||
while (entry != null) {
|
||||
@@ -245,8 +268,10 @@ public class InitCommandOptionHandler extends OptionHandler {
|
||||
if (f.exists() && !overwrite) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(f.isDirectory() ? "Directory" : "File")
|
||||
.append(" '").append(f.getName()).append("' already exists. Use --force if you want to " +
|
||||
"overwrite or --output to specify an alternate location.");
|
||||
.append(" '")
|
||||
.append(f.getName())
|
||||
.append("' already exists. Use --force if you want to "
|
||||
+ "overwrite or --output to specify an alternate location.");
|
||||
Log.error(sb.toString());
|
||||
return ExitStatus.ERROR;
|
||||
}
|
||||
@@ -268,7 +293,8 @@ public class InitCommandOptionHandler extends OptionHandler {
|
||||
}
|
||||
|
||||
private void extractZipEntry(ZipInputStream in, File outputFile) throws IOException {
|
||||
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outputFile));
|
||||
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(
|
||||
outputFile));
|
||||
try {
|
||||
StreamUtils.copy(in, out);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import org.springframework.boot.cli.util.Log;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -57,7 +56,8 @@ class InitializrServiceHttpInvoker {
|
||||
* Generate a project based on the specified {@link ProjectGenerationRequest}
|
||||
* @return an entity defining the project
|
||||
*/
|
||||
ProjectGenerationResponse generate(ProjectGenerationRequest request) throws IOException {
|
||||
ProjectGenerationResponse generate(ProjectGenerationRequest request)
|
||||
throws IOException {
|
||||
Log.info("Using service at " + request.getServiceUrl());
|
||||
InitializrServiceMetadata metadata = loadMetadata(request.getServiceUrl());
|
||||
URI url = request.generateUrl(metadata);
|
||||
@@ -65,7 +65,8 @@ class InitializrServiceHttpInvoker {
|
||||
|
||||
HttpEntity httpEntity = httpResponse.getEntity();
|
||||
if (httpEntity == null) {
|
||||
throw new ProjectGenerationException("No content received from server using '" + url + "'");
|
||||
throw new ProjectGenerationException(
|
||||
"No content received from server using '" + url + "'");
|
||||
}
|
||||
if (httpResponse.getStatusLine().getStatusCode() != 200) {
|
||||
throw buildProjectGenerationException(request.getServiceUrl(), httpResponse);
|
||||
@@ -79,23 +80,26 @@ class InitializrServiceHttpInvoker {
|
||||
InitializrServiceMetadata loadMetadata(String serviceUrl) throws IOException {
|
||||
CloseableHttpResponse httpResponse = executeInitializrMetadataRetrieval(serviceUrl);
|
||||
if (httpResponse.getEntity() == null) {
|
||||
throw new ProjectGenerationException("No content received from server using '" + serviceUrl + "'");
|
||||
throw new ProjectGenerationException(
|
||||
"No content received from server using '" + serviceUrl + "'");
|
||||
}
|
||||
if (httpResponse.getStatusLine().getStatusCode() != 200) {
|
||||
throw buildProjectGenerationException(serviceUrl, httpResponse);
|
||||
}
|
||||
try {
|
||||
HttpEntity httpEntity = httpResponse.getEntity();
|
||||
JSONObject root = getContentAsJson(getContent(httpEntity), getContentType(httpEntity));
|
||||
JSONObject root = getContentAsJson(getContent(httpEntity),
|
||||
getContentType(httpEntity));
|
||||
return new InitializrServiceMetadata(root);
|
||||
}
|
||||
catch (JSONException e) {
|
||||
throw new ProjectGenerationException("Invalid content received from server (" + e.getMessage() + ")");
|
||||
throw new ProjectGenerationException("Invalid content received from server ("
|
||||
+ e.getMessage() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
private ProjectGenerationResponse createResponse(CloseableHttpResponse httpResponse, HttpEntity httpEntity)
|
||||
throws IOException {
|
||||
private ProjectGenerationResponse createResponse(CloseableHttpResponse httpResponse,
|
||||
HttpEntity httpEntity) throws IOException {
|
||||
ProjectGenerationResponse response = new ProjectGenerationResponse();
|
||||
ContentType contentType = ContentType.getOrDefault(httpEntity);
|
||||
response.setContentType(contentType);
|
||||
@@ -108,7 +112,8 @@ class InitializrServiceHttpInvoker {
|
||||
in.close();
|
||||
}
|
||||
|
||||
String detectedFileName = extractFileName(httpResponse.getFirstHeader("Content-Disposition"));
|
||||
String detectedFileName = extractFileName(httpResponse
|
||||
.getFirstHeader("Content-Disposition"));
|
||||
if (detectedFileName != null) {
|
||||
response.setFileName(detectedFileName);
|
||||
}
|
||||
@@ -124,8 +129,8 @@ class InitializrServiceHttpInvoker {
|
||||
return this.httpClient.execute(get);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new ProjectGenerationException(
|
||||
"Failed to invoke server at '" + url + "' (" + e.getMessage() + ")");
|
||||
throw new ProjectGenerationException("Failed to invoke server at '" + url
|
||||
+ "' (" + e.getMessage() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,11 +145,11 @@ class InitializrServiceHttpInvoker {
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new ProjectGenerationException(
|
||||
"Failed to retrieve metadata from service at '" + serviceUrl + "' (" + e.getMessage() + ")");
|
||||
"Failed to retrieve metadata from service at '" + serviceUrl + "' ("
|
||||
+ e.getMessage() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private byte[] getContent(HttpEntity httpEntity) throws IOException {
|
||||
InputStream in = httpEntity.getContent();
|
||||
try {
|
||||
@@ -160,12 +165,14 @@ class InitializrServiceHttpInvoker {
|
||||
}
|
||||
|
||||
private JSONObject getContentAsJson(byte[] content, ContentType contentType) {
|
||||
Charset charset = contentType.getCharset() != null ? contentType.getCharset() : Charset.forName("UTF-8");
|
||||
Charset charset = contentType.getCharset() != null ? contentType.getCharset()
|
||||
: Charset.forName("UTF-8");
|
||||
String data = new String(content, charset);
|
||||
return new JSONObject(data);
|
||||
}
|
||||
|
||||
private ProjectGenerationException buildProjectGenerationException(String url, CloseableHttpResponse httpResponse) {
|
||||
private ProjectGenerationException buildProjectGenerationException(String url,
|
||||
CloseableHttpResponse httpResponse) {
|
||||
StringBuilder sb = new StringBuilder("Project generation failed using '");
|
||||
sb.append(url).append("' - service returned ")
|
||||
.append(httpResponse.getStatusLine().getReasonPhrase());
|
||||
@@ -174,7 +181,9 @@ class InitializrServiceHttpInvoker {
|
||||
sb.append(": '").append(error).append("'");
|
||||
}
|
||||
else {
|
||||
sb.append(" (unexpected ").append(httpResponse.getStatusLine().getStatusCode()).append(" error)");
|
||||
sb.append(" (unexpected ")
|
||||
.append(httpResponse.getStatusLine().getStatusCode())
|
||||
.append(" error)");
|
||||
}
|
||||
throw new ProjectGenerationException(sb.toString());
|
||||
}
|
||||
@@ -184,7 +193,8 @@ class InitializrServiceHttpInvoker {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
JSONObject error = getContentAsJson(getContent(entity), getContentType(entity));
|
||||
JSONObject error = getContentAsJson(getContent(entity),
|
||||
getContentType(entity));
|
||||
if (error.has("message")) {
|
||||
return error.getString("message");
|
||||
}
|
||||
|
||||
@@ -50,14 +50,12 @@ class InitializrServiceMetadata {
|
||||
|
||||
private static final String DEFAULT_ATTRIBUTE = "default";
|
||||
|
||||
|
||||
private final Map<String, Dependency> dependencies;
|
||||
|
||||
private final MetadataHolder<String, ProjectType> projectTypes;
|
||||
|
||||
private final Map<String, String> defaults;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance using the specified root {@link JSONObject}.
|
||||
*/
|
||||
@@ -70,7 +68,8 @@ class InitializrServiceMetadata {
|
||||
InitializrServiceMetadata(ProjectType defaultProjectType) {
|
||||
this.dependencies = new HashMap<String, Dependency>();
|
||||
this.projectTypes = new MetadataHolder<String, ProjectType>();
|
||||
this.projectTypes.getContent().put(defaultProjectType.getId(), defaultProjectType);
|
||||
this.projectTypes.getContent()
|
||||
.put(defaultProjectType.getId(), defaultProjectType);
|
||||
this.projectTypes.setDefaultItem(defaultProjectType);
|
||||
this.defaults = new HashMap<String, String>();
|
||||
}
|
||||
@@ -79,35 +78,35 @@ class InitializrServiceMetadata {
|
||||
* Return the dependencies supported by the service.
|
||||
*/
|
||||
public Collection<Dependency> getDependencies() {
|
||||
return dependencies.values();
|
||||
return this.dependencies.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the dependency with the specified id or {@code null} if no
|
||||
* such dependency exists.
|
||||
* Return the dependency with the specified id or {@code null} if no such dependency
|
||||
* exists.
|
||||
*/
|
||||
public Dependency getDependency(String id) {
|
||||
return dependencies.get(id);
|
||||
return this.dependencies.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the project types supported by the service.
|
||||
*/
|
||||
public Map<String, ProjectType> getProjectTypes() {
|
||||
return projectTypes.getContent();
|
||||
return this.projectTypes.getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default type to use or {@code null} or the metadata does
|
||||
* not define any default.
|
||||
* Return the default type to use or {@code null} or the metadata does not define any
|
||||
* default.
|
||||
*/
|
||||
public ProjectType getDefaultType() {
|
||||
if (projectTypes.getDefaultItem() != null) {
|
||||
return projectTypes.getDefaultItem();
|
||||
if (this.projectTypes.getDefaultItem() != null) {
|
||||
return this.projectTypes.getDefaultItem();
|
||||
}
|
||||
String defaultTypeId = getDefaults().get("type");
|
||||
if (defaultTypeId != null) {
|
||||
return projectTypes.getContent().get(defaultTypeId);
|
||||
return this.projectTypes.getContent().get(defaultTypeId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -116,7 +115,7 @@ class InitializrServiceMetadata {
|
||||
* Returns the defaults applicable to the service.
|
||||
*/
|
||||
public Map<String, String> getDefaults() {
|
||||
return defaults;
|
||||
return this.defaults;
|
||||
}
|
||||
|
||||
private Map<String, Dependency> parseDependencies(JSONObject root) {
|
||||
@@ -221,11 +220,11 @@ class InitializrServiceMetadata {
|
||||
}
|
||||
|
||||
public Map<K, T> getContent() {
|
||||
return content;
|
||||
return this.content;
|
||||
}
|
||||
|
||||
public T getDefaultItem() {
|
||||
return defaultItem;
|
||||
return this.defaultItem;
|
||||
}
|
||||
|
||||
public void setDefaultItem(T defaultItem) {
|
||||
|
||||
@@ -51,19 +51,19 @@ class ListMetadataCommand {
|
||||
* capabilities as advertized by the root endpoint.
|
||||
*/
|
||||
String generateReport(String serviceUrl) throws IOException {
|
||||
InitializrServiceMetadata metadata = initializrServiceInvoker.loadMetadata(serviceUrl);
|
||||
InitializrServiceMetadata metadata = this.initializrServiceInvoker
|
||||
.loadMetadata(serviceUrl);
|
||||
String header = "Capabilities of " + serviceUrl;
|
||||
int size = header.length();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(StringUtils.repeat("=", size)).append(NEW_LINE)
|
||||
.append(header).append(NEW_LINE)
|
||||
.append(StringUtils.repeat("=", size)).append(NEW_LINE)
|
||||
.append(NEW_LINE)
|
||||
.append("Available dependencies:").append(NEW_LINE)
|
||||
sb.append(StringUtils.repeat("=", size)).append(NEW_LINE).append(header)
|
||||
.append(NEW_LINE).append(StringUtils.repeat("=", size)).append(NEW_LINE)
|
||||
.append(NEW_LINE).append("Available dependencies:").append(NEW_LINE)
|
||||
.append("-----------------------").append(NEW_LINE);
|
||||
|
||||
List<Dependency> dependencies = new ArrayList<Dependency>(metadata.getDependencies());
|
||||
List<Dependency> dependencies = new ArrayList<Dependency>(
|
||||
metadata.getDependencies());
|
||||
Collections.sort(dependencies, new Comparator<Dependency>() {
|
||||
@Override
|
||||
public int compare(Dependency o1, Dependency o2) {
|
||||
@@ -78,8 +78,7 @@ class ListMetadataCommand {
|
||||
sb.append(NEW_LINE);
|
||||
}
|
||||
|
||||
sb.append(NEW_LINE)
|
||||
.append("Available project types:").append(NEW_LINE)
|
||||
sb.append(NEW_LINE).append("Available project types:").append(NEW_LINE)
|
||||
.append("------------------------").append(NEW_LINE);
|
||||
List<String> typeIds = new ArrayList<String>(metadata.getProjectTypes().keySet());
|
||||
Collections.sort(typeIds);
|
||||
@@ -88,7 +87,8 @@ class ListMetadataCommand {
|
||||
sb.append(typeId).append(" - ").append(type.getName());
|
||||
if (!type.getTags().isEmpty()) {
|
||||
sb.append(" [");
|
||||
Iterator<Map.Entry<String, String>> it = type.getTags().entrySet().iterator();
|
||||
Iterator<Map.Entry<String, String>> it = type.getTags().entrySet()
|
||||
.iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<String, String> entry = it.next();
|
||||
sb.append(entry.getKey()).append(":").append(entry.getValue());
|
||||
@@ -104,14 +104,14 @@ class ListMetadataCommand {
|
||||
sb.append(NEW_LINE);
|
||||
}
|
||||
|
||||
sb.append(NEW_LINE)
|
||||
.append("Defaults:").append(NEW_LINE)
|
||||
.append("---------").append(NEW_LINE);
|
||||
sb.append(NEW_LINE).append("Defaults:").append(NEW_LINE).append("---------")
|
||||
.append(NEW_LINE);
|
||||
|
||||
List<String> defaultsKeys = new ArrayList<String>(metadata.getDefaults().keySet());
|
||||
Collections.sort(defaultsKeys);
|
||||
for (String defaultsKey : defaultsKeys) {
|
||||
sb.append(defaultsKey).append(": ").append(metadata.getDefaults().get(defaultsKey)).append(NEW_LINE);
|
||||
sb.append(defaultsKey).append(": ")
|
||||
.append(metadata.getDefaults().get(defaultsKey)).append(NEW_LINE);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class ProjectGenerationRequest {
|
||||
* @see #DEFAULT_SERVICE_URL
|
||||
*/
|
||||
public String getServiceUrl() {
|
||||
return serviceUrl;
|
||||
return this.serviceUrl;
|
||||
}
|
||||
|
||||
public void setServiceUrl(String serviceUrl) {
|
||||
@@ -69,10 +69,10 @@ class ProjectGenerationRequest {
|
||||
}
|
||||
|
||||
/**
|
||||
* The location of the generated project.
|
||||
* The location of the generated project.
|
||||
*/
|
||||
public String getOutput() {
|
||||
return output;
|
||||
return this.output;
|
||||
}
|
||||
|
||||
public void setOutput(String output) {
|
||||
@@ -83,7 +83,7 @@ class ProjectGenerationRequest {
|
||||
* The Spring Boot version to use or {@code null} if it should not be customized.
|
||||
*/
|
||||
public String getBootVersion() {
|
||||
return bootVersion;
|
||||
return this.bootVersion;
|
||||
}
|
||||
|
||||
public void setBootVersion(String bootVersion) {
|
||||
@@ -94,14 +94,14 @@ class ProjectGenerationRequest {
|
||||
* The identifiers of the dependencies to include in the project.
|
||||
*/
|
||||
public List<String> getDependencies() {
|
||||
return dependencies;
|
||||
return this.dependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Java version to use or {@code null} if it should not be customized.
|
||||
*/
|
||||
public String getJavaVersion() {
|
||||
return javaVersion;
|
||||
return this.javaVersion;
|
||||
}
|
||||
|
||||
public void setJavaVersion(String javaVersion) {
|
||||
@@ -112,7 +112,7 @@ class ProjectGenerationRequest {
|
||||
* The packaging type or {@code null} if it should not be customized.
|
||||
*/
|
||||
public String getPackaging() {
|
||||
return packaging;
|
||||
return this.packaging;
|
||||
}
|
||||
|
||||
public void setPackaging(String packaging) {
|
||||
@@ -120,11 +120,11 @@ class ProjectGenerationRequest {
|
||||
}
|
||||
|
||||
/**
|
||||
* The build type to use. Ignored if a type is set. Can be used alongside
|
||||
* the {@link #getFormat() format} to identify the type to use.
|
||||
* The build type to use. Ignored if a type is set. Can be used alongside the
|
||||
* {@link #getFormat() format} to identify the type to use.
|
||||
*/
|
||||
public String getBuild() {
|
||||
return build;
|
||||
return this.build;
|
||||
}
|
||||
|
||||
public void setBuild(String build) {
|
||||
@@ -132,11 +132,11 @@ class ProjectGenerationRequest {
|
||||
}
|
||||
|
||||
/**
|
||||
* The project format to use. Ignored if a type is set. Can be used alongside
|
||||
* the {@link #getBuild() build} to identify the type to use.
|
||||
* The project format to use. Ignored if a type is set. Can be used alongside the
|
||||
* {@link #getBuild() build} to identify the type to use.
|
||||
*/
|
||||
public String getFormat() {
|
||||
return format;
|
||||
return this.format;
|
||||
}
|
||||
|
||||
public void setFormat(String format) {
|
||||
@@ -144,11 +144,10 @@ class ProjectGenerationRequest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify if the type should be detected based on the build
|
||||
* and format value.
|
||||
* Specify if the type should be detected based on the build and format value.
|
||||
*/
|
||||
public boolean isDetectType() {
|
||||
return detectType;
|
||||
return this.detectType;
|
||||
}
|
||||
|
||||
public void setDetectType(boolean detectType) {
|
||||
@@ -156,12 +155,11 @@ class ProjectGenerationRequest {
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of project to generate. Should match one of the advertized type
|
||||
* that the service supports. If not set, the default is retrieved from
|
||||
* the service metadata.
|
||||
* The type of project to generate. Should match one of the advertized type that the
|
||||
* service supports. If not set, the default is retrieved from the service metadata.
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
@@ -169,12 +167,11 @@ class ProjectGenerationRequest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the URL to use to generate a project represented
|
||||
* by this request
|
||||
* Generates the URL to use to generate a project represented by this request
|
||||
*/
|
||||
URI generateUrl(InitializrServiceMetadata metadata) {
|
||||
try {
|
||||
URIBuilder builder = new URIBuilder(serviceUrl);
|
||||
URIBuilder builder = new URIBuilder(this.serviceUrl);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (builder.getPath() != null) {
|
||||
sb.append(builder.getPath());
|
||||
@@ -188,7 +185,7 @@ class ProjectGenerationRequest {
|
||||
if (this.bootVersion != null) {
|
||||
builder.setParameter("bootVersion", this.bootVersion);
|
||||
}
|
||||
for (String dependency : dependencies) {
|
||||
for (String dependency : this.dependencies) {
|
||||
builder.addParameter("style", dependency);
|
||||
}
|
||||
if (this.javaVersion != null) {
|
||||
@@ -204,7 +201,8 @@ class ProjectGenerationRequest {
|
||||
return builder.build();
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
throw new ProjectGenerationException("Invalid service URL (" + e.getMessage() + ")");
|
||||
throw new ProjectGenerationException("Invalid service URL (" + e.getMessage()
|
||||
+ ")");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,12 +210,13 @@ class ProjectGenerationRequest {
|
||||
if (this.type != null) {
|
||||
ProjectType result = metadata.getProjectTypes().get(this.type);
|
||||
if (result == null) {
|
||||
throw new ProjectGenerationException(("No project type with id '" + this.type +
|
||||
"' - check the service capabilities (--list)"));
|
||||
throw new ProjectGenerationException(("No project type with id '"
|
||||
+ this.type + "' - check the service capabilities (--list)"));
|
||||
}
|
||||
}
|
||||
if (isDetectType()) {
|
||||
Map<String, ProjectType> types = new HashMap<String, ProjectType>(metadata.getProjectTypes());
|
||||
Map<String, ProjectType> types = new HashMap<String, ProjectType>(
|
||||
metadata.getProjectTypes());
|
||||
if (this.build != null) {
|
||||
filter(types, "build", this.build);
|
||||
}
|
||||
@@ -228,24 +227,29 @@ class ProjectGenerationRequest {
|
||||
return types.values().iterator().next();
|
||||
}
|
||||
else if (types.size() == 0) {
|
||||
throw new ProjectGenerationException("No type found with build '" + this.build + "' and format '"
|
||||
+ this.format + "' check the service capabilities (--list)");
|
||||
throw new ProjectGenerationException("No type found with build '"
|
||||
+ this.build + "' and format '" + this.format
|
||||
+ "' check the service capabilities (--list)");
|
||||
}
|
||||
else {
|
||||
throw new ProjectGenerationException("Multiple types found with build '" + this.build
|
||||
+ "' and format '" + this.format + "' use --type with a more specific value " + types.keySet());
|
||||
throw new ProjectGenerationException("Multiple types found with build '"
|
||||
+ this.build + "' and format '" + this.format
|
||||
+ "' use --type with a more specific value " + types.keySet());
|
||||
}
|
||||
}
|
||||
ProjectType defaultType = metadata.getDefaultType();
|
||||
if (defaultType == null) {
|
||||
throw new ProjectGenerationException(("No project type is set and no default is defined. " +
|
||||
"Check the service capabilities (--list)"));
|
||||
throw new ProjectGenerationException(
|
||||
("No project type is set and no default is defined. "
|
||||
+ "Check the service capabilities (--list)"));
|
||||
}
|
||||
return defaultType;
|
||||
}
|
||||
|
||||
private static void filter(Map<String, ProjectType> projects, String tag, String tagValue) {
|
||||
for (Iterator<Map.Entry<String, ProjectType>> it = projects.entrySet().iterator(); it.hasNext(); ) {
|
||||
private static void filter(Map<String, ProjectType> projects, String tag,
|
||||
String tagValue) {
|
||||
for (Iterator<Map.Entry<String, ProjectType>> it = projects.entrySet().iterator(); it
|
||||
.hasNext();) {
|
||||
Map.Entry<String, ProjectType> entry = it.next();
|
||||
String value = entry.getValue().getTags().get(tag);
|
||||
if (!tagValue.equals(value)) {
|
||||
|
||||
@@ -50,7 +50,7 @@ class ProjectGenerationResponse {
|
||||
* The generated project archive or file.
|
||||
*/
|
||||
public byte[] getContent() {
|
||||
return content;
|
||||
return this.content;
|
||||
}
|
||||
|
||||
public void setContent(byte[] content) {
|
||||
@@ -58,11 +58,11 @@ class ProjectGenerationResponse {
|
||||
}
|
||||
|
||||
/**
|
||||
* The preferred file name to use to store the entity on disk or {@code null}
|
||||
* if no preferred value has been set.
|
||||
* The preferred file name to use to store the entity on disk or {@code null} if no
|
||||
* preferred value has been set.
|
||||
*/
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
return this.fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
|
||||
@@ -38,7 +38,8 @@ class ProjectType {
|
||||
|
||||
private final Map<String, String> tags = new HashMap<String, String>();
|
||||
|
||||
public ProjectType(String id, String name, String action, boolean defaultType, Map<String, String> tags) {
|
||||
public ProjectType(String id, String name, String action, boolean defaultType,
|
||||
Map<String, String> tags) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.action = action;
|
||||
@@ -49,22 +50,22 @@ class ProjectType {
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getAction() {
|
||||
return action;
|
||||
return this.action;
|
||||
}
|
||||
|
||||
public boolean isDefaultType() {
|
||||
return defaultType;
|
||||
return this.defaultType;
|
||||
}
|
||||
|
||||
public Map<String, String> getTags() {
|
||||
return Collections.unmodifiableMap(tags);
|
||||
return Collections.unmodifiableMap(this.tags);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user