Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit bc695ad

Browse files
committedMay 8, 2024
Remove and rename initializer commands
- `initializer new` is now `boot start` - Other initializer removed to possibly bring back later in a better form - Relates #192
1 parent d7b4723 commit bc695ad

File tree

1 file changed

+8
-92
lines changed

1 file changed

+8
-92
lines changed
 

‎src/main/java/org/springframework/cli/command/InitializerCommands.java

Lines changed: 8 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2023 the original author or authors.
2+
* Copyright 2022-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,15 +23,11 @@
2323
import java.util.List;
2424
import java.util.Map;
2525
import java.util.stream.Collectors;
26-
import java.util.stream.Stream;
2726

2827
import org.rauschig.jarchivelib.Archiver;
2928
import org.rauschig.jarchivelib.ArchiverFactory;
3029

3130
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;
3531
import org.springframework.cli.initializr.InitializrClient;
3632
import org.springframework.cli.initializr.InitializrClientCache;
3733
import org.springframework.cli.initializr.InitializrUtils;
@@ -45,20 +41,14 @@
4541
import org.springframework.shell.component.flow.SelectItem;
4642
import org.springframework.shell.component.support.SelectorItem;
4743
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;
5344
import org.springframework.util.ObjectUtils;
54-
import org.springframework.util.StringUtils;
5545

5646
/**
5747
* Commands for spring initializr.
5848
*
5949
* @author Janne Valkealahti
6050
*/
61-
@Command(command = "initializer", group = "Initializer")
51+
@Command(command = "boot", group = "Boot")
6252
public class InitializerCommands extends AbstractShellComponent {
6353

6454
private static final String PATH_NAME = "Path";
@@ -132,22 +122,18 @@ public class InitializerCommands extends AbstractShellComponent {
132122

133123
private final ComponentFlow.Builder componentFlowBuilder;
134124

135-
private final SpringCliUserConfig springCliUserConfig;
136-
137125
private final SpringCliProperties springCliProperties;
138126

139127
InitializerCommands(InitializrClientCache clientCache, ComponentFlow.Builder componentFlowBuilder,
140-
SpringCliUserConfig springCliUserConfig, SpringCliProperties springCliProperties) {
128+
SpringCliProperties springCliProperties) {
141129
this.clientCache = clientCache;
142130
this.componentFlowBuilder = componentFlowBuilder;
143-
this.springCliUserConfig = springCliUserConfig;
144131
this.springCliProperties = springCliProperties;
145132
}
146133

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,
151137
@Option(longNames = "boot-version", description = "Language") String bootVersion,
152138
@Option(description = "Version") String version, @Option(description = "Group") String group,
153139
@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
156142
@Option(description = "Dependencies") List<String> dependencies,
157143
@Option(description = "Packaging") String packaging,
158144
@Option(longNames = "java-version", description = "Java") String javaVersion) {
159-
InitializrClient client = buildClient(serverId);
145+
InitializrClient client = buildClient();
160146
Metadata metadata = client.getMetadata();
161147

162148
Map<String, String> projectSelectItems = metadata.getType()
@@ -360,79 +346,9 @@ public String init(@Option(longNames = "server-id", description = "Server to use
360346
return String.format("Extracted to %s", outFile.getAbsolutePath());
361347
}
362348

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() {
415350
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-
}
422351
return clientCache.get(cacheKey);
423352
}
424353

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-
438354
}

0 commit comments

Comments
 (0)