1
1
/*
2
- * Copyright 2022-2023 the original author or authors.
2
+ * Copyright 2022-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
23
23
import java .util .List ;
24
24
import java .util .Map ;
25
25
import java .util .stream .Collectors ;
26
- import java .util .stream .Stream ;
27
26
28
27
import org .rauschig .jarchivelib .Archiver ;
29
28
import org .rauschig .jarchivelib .ArchiverFactory ;
30
29
31
30
import org .springframework .cli .config .SpringCliProperties ;
32
- import org .springframework .cli .config .SpringCliUserConfig ;
33
- import org .springframework .cli .config .SpringCliUserConfig .Initializr ;
34
- import org .springframework .cli .config .SpringCliUserConfig .Initializrs ;
35
31
import org .springframework .cli .initializr .InitializrClient ;
36
32
import org .springframework .cli .initializr .InitializrClientCache ;
37
33
import org .springframework .cli .initializr .InitializrUtils ;
45
41
import org .springframework .shell .component .flow .SelectItem ;
46
42
import org .springframework .shell .component .support .SelectorItem ;
47
43
import org .springframework .shell .standard .AbstractShellComponent ;
48
- import org .springframework .shell .table .ArrayTableModel ;
49
- import org .springframework .shell .table .BorderStyle ;
50
- import org .springframework .shell .table .Table ;
51
- import org .springframework .shell .table .TableBuilder ;
52
- import org .springframework .shell .table .TableModel ;
53
44
import org .springframework .util .ObjectUtils ;
54
- import org .springframework .util .StringUtils ;
55
45
56
46
/**
57
47
* Commands for spring initializr.
58
48
*
59
49
* @author Janne Valkealahti
60
50
*/
61
- @ Command (command = "initializer " , group = "Initializer " )
51
+ @ Command (command = "boot " , group = "Boot " )
62
52
public class InitializerCommands extends AbstractShellComponent {
63
53
64
54
private static final String PATH_NAME = "Path" ;
@@ -132,22 +122,18 @@ public class InitializerCommands extends AbstractShellComponent {
132
122
133
123
private final ComponentFlow .Builder componentFlowBuilder ;
134
124
135
- private final SpringCliUserConfig springCliUserConfig ;
136
-
137
125
private final SpringCliProperties springCliProperties ;
138
126
139
127
InitializerCommands (InitializrClientCache clientCache , ComponentFlow .Builder componentFlowBuilder ,
140
- SpringCliUserConfig springCliUserConfig , SpringCliProperties springCliProperties ) {
128
+ SpringCliProperties springCliProperties ) {
141
129
this .clientCache = clientCache ;
142
130
this .componentFlowBuilder = componentFlowBuilder ;
143
- this .springCliUserConfig = springCliUserConfig ;
144
131
this .springCliProperties = springCliProperties ;
145
132
}
146
133
147
- @ Command (command = "new" , description = "Create a new project from start.spring.io" )
148
- public String init (@ Option (longNames = "server-id" , description = "Server to use" ) String serverId ,
149
- @ Option (description = "Path to extract" ) String path , @ Option (description = "Project" ) String project ,
150
- @ Option (description = "Language" ) String language ,
134
+ @ Command (command = "start" , description = "Create a new project from start.spring.io" )
135
+ public String init (@ Option (description = "Path to extract" ) String path ,
136
+ @ Option (description = "Project" ) String project , @ Option (description = "Language" ) String language ,
151
137
@ Option (longNames = "boot-version" , description = "Language" ) String bootVersion ,
152
138
@ Option (description = "Version" ) String version , @ Option (description = "Group" ) String group ,
153
139
@ Option (description = "Artifact" ) String artifact , @ Option (description = "Name" ) String name ,
@@ -156,7 +142,7 @@ public String init(@Option(longNames = "server-id", description = "Server to use
156
142
@ Option (description = "Dependencies" ) List <String > dependencies ,
157
143
@ Option (description = "Packaging" ) String packaging ,
158
144
@ Option (longNames = "java-version" , description = "Java" ) String javaVersion ) {
159
- InitializrClient client = buildClient (serverId );
145
+ InitializrClient client = buildClient ();
160
146
Metadata metadata = client .getMetadata ();
161
147
162
148
Map <String , String > projectSelectItems = metadata .getType ()
@@ -360,79 +346,9 @@ public String init(@Option(longNames = "server-id", description = "Server to use
360
346
return String .format ("Extracted to %s" , outFile .getAbsolutePath ());
361
347
}
362
348
363
- @ Command (command = "list" , description = "Show the Initializr server environments" )
364
- public Table list () {
365
- Stream <String []> header = Stream .<String []>of (new String [] { "ServerId" , "Url" });
366
- Stream <String []> rows = this .springCliUserConfig .getInitializrs ()
367
- .entrySet ()
368
- .stream ()
369
- .map (e -> new String [] { e .getKey (), e .getValue ().getUrl () });
370
- String [][] data = Stream .concat (header , rows ).toArray (String [][]::new );
371
-
372
- TableModel model = new ArrayTableModel (data );
373
- TableBuilder tableBuilder = new TableBuilder (model );
374
- return tableBuilder .addFullBorder (BorderStyle .fancy_light ).build ();
375
- }
376
-
377
- @ Command (command = "set" , description = "Set the Initializr server environment" )
378
- public void set (@ Option (longNames = "server-id" , description = "Server to use" ) String serverId ,
379
- @ Option (description = "Server base url" ) String url ) {
380
- Map <String , Initializr > initializrs = this .springCliUserConfig .getInitializrs ();
381
- initializrs .put (serverId , Initializr .of (url ));
382
- this .springCliUserConfig .setInitializrs (Initializrs .of (initializrs ));
383
- }
384
-
385
- @ Command (command = "remove" , description = "Remove the Initializr server environment" )
386
- public void remove (@ Option (longNames = "server-id" , description = "Server to use" ) String serverId ) {
387
- Map <String , Initializr > initializrs = this .springCliUserConfig .getInitializrs ();
388
- initializrs .remove (serverId );
389
- this .springCliUserConfig .setInitializrs (Initializrs .of (initializrs ));
390
- }
391
-
392
- @ Command (command = "dependencies" , description = "List supported dependencies" )
393
- public Table dependencies (@ Option (longNames = "server-id" , description = "Server to use" ) String serverId ,
394
- @ Option (description = "Search string to limit results" ) String search ,
395
- @ Option (description = "Limit to compatibility version" ) String version ) {
396
- InitializrClient client = buildClient (serverId );
397
- Metadata metadata = client .getMetadata ();
398
-
399
- Stream <String []> header = Stream .<String []>of (new String [] { "Id" , "Name" , "Description" , "Required version" });
400
- Stream <String []> rows = metadata .getDependencies ()
401
- .getValues ()
402
- .stream ()
403
- .flatMap (dc -> dc .getValues ().stream ())
404
- .filter (d -> InitializrUtils .isDependencyCompatible (d , version ))
405
- .map (d -> new String [] { d .getId (), d .getName (), d .getDescription (), d .getVersionRange () })
406
- .filter (d -> matches (d , search ));
407
- String [][] data = Stream .concat (header , rows ).toArray (String [][]::new );
408
-
409
- TableModel model = new ArrayTableModel (data );
410
- TableBuilder tableBuilder = new TableBuilder (model );
411
- return tableBuilder .addFullBorder (BorderStyle .fancy_light ).build ();
412
- }
413
-
414
- private InitializrClient buildClient (String serverId ) {
349
+ private InitializrClient buildClient () {
415
350
String cacheKey = this .springCliProperties .getInitializr ().getBaseUrl ();
416
- if (StringUtils .hasText (serverId )) {
417
- Initializr initializr = this .springCliUserConfig .getInitializrs ().get (serverId );
418
- if (initializr != null ) {
419
- cacheKey = initializr .getUrl ();
420
- }
421
- }
422
351
return clientCache .get (cacheKey );
423
352
}
424
353
425
- private static boolean matches (String [] array , String search ) {
426
- if (!StringUtils .hasText (search )) {
427
- return true ;
428
- }
429
- search = search .toLowerCase ();
430
- for (String field : array ) {
431
- if (StringUtils .hasText (field ) && field .toLowerCase ().contains (search )) {
432
- return true ;
433
- }
434
- }
435
- return false ;
436
- }
437
-
438
354
}
0 commit comments