Skip to content

Commit b89e5e0

Browse files
committed
Apply eclipse formatting rules
Apply eclipse formatting rules to b2fe2dd. See gh-1751
1 parent 8e16dfc commit b89e5e0

19 files changed

+840
-763
lines changed

spring-boot-cli/src/main/java/org/springframework/boot/cli/DefaultCommandFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public class DefaultCommandFactory implements CommandFactory {
4040

4141
private static final List<Command> DEFAULT_COMMANDS = Arrays.<Command> asList(
4242
new VersionCommand(), new RunCommand(), new TestCommand(), new GrabCommand(),
43-
new JarCommand(), new InstallCommand(), new UninstallCommand(), new InitCommand());
43+
new JarCommand(), new InstallCommand(), new UninstallCommand(),
44+
new InitCommand());
4445

4546
@Override
4647
public Collection<Command> getCommands() {

spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/Dependency.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,27 @@ class Dependency {
3131
private String description;
3232

3333
public String getId() {
34-
return id;
34+
return this.id;
3535
}
3636

3737
public void setId(String id) {
3838
this.id = id;
3939
}
4040

4141
public String getName() {
42-
return name;
42+
return this.name;
4343
}
4444

4545
public void setName(String name) {
4646
this.name = name;
4747
}
4848

4949
public String getDescription() {
50-
return description;
50+
return this.description;
5151
}
5252

5353
public void setDescription(String description) {
5454
this.description = description;
5555
}
56+
5657
}

spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.boot.cli.command.init;
1818

1919
import org.apache.http.impl.client.HttpClientBuilder;
20-
2120
import org.springframework.boot.cli.command.Command;
2221
import org.springframework.boot.cli.command.OptionParsingCommand;
2322

@@ -30,7 +29,8 @@
3029
public class InitCommand extends OptionParsingCommand {
3130

3231
InitCommand(InitCommandOptionHandler handler) {
33-
super("init", "Initialize a new project structure using Spring Initializr", handler);
32+
super("init", "Initialize a new project structure from Spring Initializr",
33+
handler);
3434
}
3535

3636
public InitCommand() {

spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommandOptionHandler.java

Lines changed: 67 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
import joptsimple.OptionSet;
2929
import joptsimple.OptionSpec;
30-
import org.apache.http.impl.client.CloseableHttpClient;
3130

31+
import org.apache.http.impl.client.CloseableHttpClient;
3232
import org.springframework.boot.cli.command.options.OptionHandler;
3333
import org.springframework.boot.cli.command.status.ExitStatus;
3434
import org.springframework.boot.cli.util.Log;
@@ -78,46 +78,61 @@ public class InitCommandOptionHandler extends OptionHandler {
7878

7979
@Override
8080
protected void options() {
81-
this.target = option(Arrays.asList("target"),
82-
"URL of the service to use").withRequiredArg().defaultsTo(ProjectGenerationRequest.DEFAULT_SERVICE_URL);
83-
this.listMetadata = option(Arrays.asList("list", "l"), "List the capabilities of the service. Use it to " +
84-
"discover the dependencies and the types that are available.");
81+
this.target = option(Arrays.asList("target"), "URL of the service to use")
82+
.withRequiredArg().defaultsTo(
83+
ProjectGenerationRequest.DEFAULT_SERVICE_URL);
84+
this.listMetadata = option(Arrays.asList("list", "l"),
85+
"List the capabilities of the service. Use it to "
86+
+ "discover the dependencies and the types that are available.");
8587

8688
// Project generation settings
8789
this.bootVersion = option(Arrays.asList("boot-version", "bv"),
8890
"Spring Boot version to use (e.g. 1.2.0.RELEASE)").withRequiredArg();
8991
this.dependencies = option(Arrays.asList("dependencies", "d"),
90-
"Comma separated list of dependencies to include in the generated project").withRequiredArg();
92+
"Comma separated list of dependencies to include in the generated project")
93+
.withRequiredArg();
9194
this.javaVersion = option(Arrays.asList("java-version", "jv"),
9295
"Java version to use (e.g. 1.8)").withRequiredArg();
93-
this.packaging = option(Arrays.asList("packaging", "p"), "Packaging type to use (e.g. jar)").withRequiredArg();
94-
95-
this.build = option("build", "The build system to use (e.g. maven, gradle). To be used alongside " +
96-
"--format to uniquely identify one type that is supported by the service. " +
97-
"Use --type in case of conflict").withRequiredArg().defaultsTo("maven");
98-
this.format = option("format", "The format of the generated content (e.g. build for a build file, " +
99-
"project for a project archive). To be used alongside --build to uniquely identify one type " +
100-
"that is supported by the service. Use --type in case of conflict")
96+
this.packaging = option(Arrays.asList("packaging", "p"),
97+
"Packaging type to use (e.g. jar)").withRequiredArg();
98+
99+
this.build = option(
100+
"build",
101+
"The build system to use (e.g. maven, gradle). To be used alongside "
102+
+ "--format to uniquely identify one type that is supported by the service. "
103+
+ "Use --type in case of conflict").withRequiredArg().defaultsTo(
104+
"maven");
105+
this.format = option(
106+
"format",
107+
"The format of the generated content (e.g. build for a build file, "
108+
+ "project for a project archive). To be used alongside --build to uniquely identify one type "
109+
+ "that is supported by the service. Use --type in case of conflict")
101110
.withRequiredArg().defaultsTo("project");
102-
this.type = option(Arrays.asList("type", "t"), "The project type to use. Not normally needed if you " +
103-
"use --build and/or --format. Check the capabilities of the service (--list) for " +
104-
"more details.").withRequiredArg();
111+
this.type = option(
112+
Arrays.asList("type", "t"),
113+
"The project type to use. Not normally needed if you "
114+
+ "use --build and/or --format. Check the capabilities of the service (--list) for "
115+
+ "more details.").withRequiredArg();
105116

106117
// Others
107-
this.extract = option(Arrays.asList("extract", "x"), "Extract the project archive");
108-
this.force = option(Arrays.asList("force", "f"), "Force overwrite of existing files");
109-
this.output = option(Arrays.asList("output", "o"),
110-
"Location of the generated project. Can be an absolute or a relative reference and " +
111-
"should refer to a directory when --extract is used.").withRequiredArg();
118+
this.extract = option(Arrays.asList("extract", "x"),
119+
"Extract the project archive");
120+
this.force = option(Arrays.asList("force", "f"),
121+
"Force overwrite of existing files");
122+
this.output = option(
123+
Arrays.asList("output", "o"),
124+
"Location of the generated project. Can be an absolute or a relative reference and "
125+
+ "should refer to a directory when --extract is used.")
126+
.withRequiredArg();
112127
}
113128

114129
@Override
115130
protected ExitStatus run(OptionSet options) throws Exception {
116-
if (options.has(listMetadata)) {
117-
return listServiceCapabilities(options, httpClient);
131+
if (options.has(this.listMetadata)) {
132+
return listServiceCapabilities(options, this.httpClient);
118133
}
119134
else {
120-
return generateProject(options, httpClient);
135+
return generateProject(options, this.httpClient);
121136
}
122137
}
123138

@@ -151,7 +166,8 @@ public ProjectGenerationRequest createProjectGenerationRequest(OptionSet options
151166
return request;
152167
}
153168

154-
protected ExitStatus listServiceCapabilities(OptionSet options, CloseableHttpClient httpClient) throws IOException {
169+
protected ExitStatus listServiceCapabilities(OptionSet options,
170+
CloseableHttpClient httpClient) throws IOException {
155171
ListMetadataCommand command = new ListMetadataCommand(httpClient);
156172
Log.info(command.generateReport(determineServiceUrl(options)));
157173
return ExitStatus.OK;
@@ -161,19 +177,22 @@ protected ExitStatus generateProject(OptionSet options, CloseableHttpClient http
161177
ProjectGenerationRequest request = createProjectGenerationRequest(options);
162178
boolean forceValue = options.has(this.force);
163179
try {
164-
ProjectGenerationResponse entity = new InitializrServiceHttpInvoker(httpClient).generate(request);
180+
ProjectGenerationResponse entity = new InitializrServiceHttpInvoker(
181+
httpClient).generate(request);
165182
if (options.has(this.extract)) {
166183
if (isZipArchive(entity)) {
167-
return extractProject(entity, options.valueOf(this.output), forceValue);
184+
return extractProject(entity, options.valueOf(this.output),
185+
forceValue);
168186
}
169187
else {
170188
Log.info("Could not extract '" + entity.getContentType() + "'");
171189
}
172190
}
173-
String outputFileName = entity.getFileName() != null ? entity.getFileName() : options.valueOf(this.output);
191+
String outputFileName = entity.getFileName() != null ? entity.getFileName()
192+
: options.valueOf(this.output);
174193
if (outputFileName == null) {
175-
Log.error("Could not save the project, the server did not set a preferred " +
176-
"file name. Use --output to specify the output location for the project.");
194+
Log.error("Could not save the project, the server did not set a preferred "
195+
+ "file name. Use --output to specify the output location for the project.");
177196
return ExitStatus.ERROR;
178197
}
179198
return writeProject(entity, outputFileName, forceValue);
@@ -192,8 +211,8 @@ private String determineServiceUrl(OptionSet options) {
192211
return options.valueOf(this.target);
193212
}
194213

195-
private ExitStatus writeProject(ProjectGenerationResponse entity, String outputFileName, boolean overwrite)
196-
throws IOException {
214+
private ExitStatus writeProject(ProjectGenerationResponse entity,
215+
String outputFileName, boolean overwrite) throws IOException {
197216

198217
File f = new File(outputFileName);
199218
if (f.exists()) {
@@ -204,8 +223,9 @@ private ExitStatus writeProject(ProjectGenerationResponse entity, String outputF
204223
}
205224
}
206225
else {
207-
Log.error("File '" + f.getName() + "' already exists. Use --force if you want to " +
208-
"overwrite or --output to specify an alternate location.");
226+
Log.error("File '" + f.getName()
227+
+ "' already exists. Use --force if you want to "
228+
+ "overwrite or --output to specify an alternate location.");
209229
return ExitStatus.ERROR;
210230
}
211231
}
@@ -232,21 +252,26 @@ private boolean isZipArchive(ProjectGenerationResponse entity) {
232252
}
233253
}
234254

235-
private ExitStatus extractProject(ProjectGenerationResponse entity, String outputValue, boolean overwrite) throws IOException {
236-
File output = outputValue != null ? new File(outputValue) : new File(System.getProperty("user.dir"));
255+
private ExitStatus extractProject(ProjectGenerationResponse entity,
256+
String outputValue, boolean overwrite) throws IOException {
257+
File output = outputValue != null ? new File(outputValue) : new File(
258+
System.getProperty("user.dir"));
237259
if (!output.exists()) {
238260
output.mkdirs();
239261
}
240-
ZipInputStream zipIn = new ZipInputStream(new ByteArrayInputStream(entity.getContent()));
262+
ZipInputStream zipIn = new ZipInputStream(new ByteArrayInputStream(
263+
entity.getContent()));
241264
try {
242265
ZipEntry entry = zipIn.getNextEntry();
243266
while (entry != null) {
244267
File f = new File(output, entry.getName());
245268
if (f.exists() && !overwrite) {
246269
StringBuilder sb = new StringBuilder();
247270
sb.append(f.isDirectory() ? "Directory" : "File")
248-
.append(" '").append(f.getName()).append("' already exists. Use --force if you want to " +
249-
"overwrite or --output to specify an alternate location.");
271+
.append(" '")
272+
.append(f.getName())
273+
.append("' already exists. Use --force if you want to "
274+
+ "overwrite or --output to specify an alternate location.");
250275
Log.error(sb.toString());
251276
return ExitStatus.ERROR;
252277
}
@@ -268,7 +293,8 @@ private ExitStatus extractProject(ProjectGenerationResponse entity, String outpu
268293
}
269294

270295
private void extractZipEntry(ZipInputStream in, File outputFile) throws IOException {
271-
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outputFile));
296+
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(
297+
outputFile));
272298
try {
273299
StreamUtils.copy(in, out);
274300
}

spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitializrServiceHttpInvoker.java

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.apache.http.message.BasicHeader;
3232
import org.json.JSONException;
3333
import org.json.JSONObject;
34-
3534
import org.springframework.boot.cli.util.Log;
3635
import org.springframework.util.StreamUtils;
3736
import org.springframework.util.StringUtils;
@@ -57,15 +56,17 @@ class InitializrServiceHttpInvoker {
5756
* Generate a project based on the specified {@link ProjectGenerationRequest}
5857
* @return an entity defining the project
5958
*/
60-
ProjectGenerationResponse generate(ProjectGenerationRequest request) throws IOException {
59+
ProjectGenerationResponse generate(ProjectGenerationRequest request)
60+
throws IOException {
6161
Log.info("Using service at " + request.getServiceUrl());
6262
InitializrServiceMetadata metadata = loadMetadata(request.getServiceUrl());
6363
URI url = request.generateUrl(metadata);
6464
CloseableHttpResponse httpResponse = executeProjectGenerationRequest(url);
6565

6666
HttpEntity httpEntity = httpResponse.getEntity();
6767
if (httpEntity == null) {
68-
throw new ProjectGenerationException("No content received from server using '" + url + "'");
68+
throw new ProjectGenerationException(
69+
"No content received from server using '" + url + "'");
6970
}
7071
if (httpResponse.getStatusLine().getStatusCode() != 200) {
7172
throw buildProjectGenerationException(request.getServiceUrl(), httpResponse);
@@ -79,23 +80,26 @@ ProjectGenerationResponse generate(ProjectGenerationRequest request) throws IOEx
7980
InitializrServiceMetadata loadMetadata(String serviceUrl) throws IOException {
8081
CloseableHttpResponse httpResponse = executeInitializrMetadataRetrieval(serviceUrl);
8182
if (httpResponse.getEntity() == null) {
82-
throw new ProjectGenerationException("No content received from server using '" + serviceUrl + "'");
83+
throw new ProjectGenerationException(
84+
"No content received from server using '" + serviceUrl + "'");
8385
}
8486
if (httpResponse.getStatusLine().getStatusCode() != 200) {
8587
throw buildProjectGenerationException(serviceUrl, httpResponse);
8688
}
8789
try {
8890
HttpEntity httpEntity = httpResponse.getEntity();
89-
JSONObject root = getContentAsJson(getContent(httpEntity), getContentType(httpEntity));
91+
JSONObject root = getContentAsJson(getContent(httpEntity),
92+
getContentType(httpEntity));
9093
return new InitializrServiceMetadata(root);
9194
}
9295
catch (JSONException e) {
93-
throw new ProjectGenerationException("Invalid content received from server (" + e.getMessage() + ")");
96+
throw new ProjectGenerationException("Invalid content received from server ("
97+
+ e.getMessage() + ")");
9498
}
9599
}
96100

97-
private ProjectGenerationResponse createResponse(CloseableHttpResponse httpResponse, HttpEntity httpEntity)
98-
throws IOException {
101+
private ProjectGenerationResponse createResponse(CloseableHttpResponse httpResponse,
102+
HttpEntity httpEntity) throws IOException {
99103
ProjectGenerationResponse response = new ProjectGenerationResponse();
100104
ContentType contentType = ContentType.getOrDefault(httpEntity);
101105
response.setContentType(contentType);
@@ -108,7 +112,8 @@ private ProjectGenerationResponse createResponse(CloseableHttpResponse httpRespo
108112
in.close();
109113
}
110114

111-
String detectedFileName = extractFileName(httpResponse.getFirstHeader("Content-Disposition"));
115+
String detectedFileName = extractFileName(httpResponse
116+
.getFirstHeader("Content-Disposition"));
112117
if (detectedFileName != null) {
113118
response.setFileName(detectedFileName);
114119
}
@@ -124,8 +129,8 @@ private CloseableHttpResponse executeProjectGenerationRequest(URI url) {
124129
return this.httpClient.execute(get);
125130
}
126131
catch (IOException e) {
127-
throw new ProjectGenerationException(
128-
"Failed to invoke server at '" + url + "' (" + e.getMessage() + ")");
132+
throw new ProjectGenerationException("Failed to invoke server at '" + url
133+
+ "' (" + e.getMessage() + ")");
129134
}
130135
}
131136

@@ -140,11 +145,11 @@ private CloseableHttpResponse executeInitializrMetadataRetrieval(String serviceU
140145
}
141146
catch (IOException e) {
142147
throw new ProjectGenerationException(
143-
"Failed to retrieve metadata from service at '" + serviceUrl + "' (" + e.getMessage() + ")");
148+
"Failed to retrieve metadata from service at '" + serviceUrl + "' ("
149+
+ e.getMessage() + ")");
144150
}
145151
}
146152

147-
148153
private byte[] getContent(HttpEntity httpEntity) throws IOException {
149154
InputStream in = httpEntity.getContent();
150155
try {
@@ -160,12 +165,14 @@ private ContentType getContentType(HttpEntity httpEntity) {
160165
}
161166

162167
private JSONObject getContentAsJson(byte[] content, ContentType contentType) {
163-
Charset charset = contentType.getCharset() != null ? contentType.getCharset() : Charset.forName("UTF-8");
168+
Charset charset = contentType.getCharset() != null ? contentType.getCharset()
169+
: Charset.forName("UTF-8");
164170
String data = new String(content, charset);
165171
return new JSONObject(data);
166172
}
167173

168-
private ProjectGenerationException buildProjectGenerationException(String url, CloseableHttpResponse httpResponse) {
174+
private ProjectGenerationException buildProjectGenerationException(String url,
175+
CloseableHttpResponse httpResponse) {
169176
StringBuilder sb = new StringBuilder("Project generation failed using '");
170177
sb.append(url).append("' - service returned ")
171178
.append(httpResponse.getStatusLine().getReasonPhrase());
@@ -174,7 +181,9 @@ private ProjectGenerationException buildProjectGenerationException(String url, C
174181
sb.append(": '").append(error).append("'");
175182
}
176183
else {
177-
sb.append(" (unexpected ").append(httpResponse.getStatusLine().getStatusCode()).append(" error)");
184+
sb.append(" (unexpected ")
185+
.append(httpResponse.getStatusLine().getStatusCode())
186+
.append(" error)");
178187
}
179188
throw new ProjectGenerationException(sb.toString());
180189
}
@@ -184,7 +193,8 @@ private String extractMessage(HttpEntity entity) {
184193
return null;
185194
}
186195
try {
187-
JSONObject error = getContentAsJson(getContent(entity), getContentType(entity));
196+
JSONObject error = getContentAsJson(getContent(entity),
197+
getContentType(entity));
188198
if (error.has("message")) {
189199
return error.getString("message");
190200
}

0 commit comments

Comments
 (0)