-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20913 from ebullient/jsonParsing
DevTools: consolidate json/yaml parsing
- Loading branch information
Showing
123 changed files
with
16,073 additions
and
2,712 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 23 additions & 31 deletions
54
devtools/cli/src/main/java/io/quarkus/cli/RegistryRemoveCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,57 @@ | ||
package io.quarkus.cli; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.List; | ||
|
||
import io.quarkus.cli.registry.BaseRegistryCommand; | ||
import io.quarkus.registry.config.RegistriesConfig; | ||
import io.quarkus.registry.config.RegistriesConfigLocator; | ||
import io.quarkus.registry.config.RegistryConfig; | ||
import io.quarkus.registry.config.json.JsonRegistriesConfig; | ||
import io.quarkus.registry.config.json.RegistriesConfigMapperHelper; | ||
import picocli.CommandLine; | ||
|
||
@CommandLine.Command(name = "remove", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, header = "Remove a Quarkus extension registry", description = "%n" | ||
+ "This command will remove a Quarkus extension registry from the registry client configuration.", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n") | ||
public class RegistryRemoveCommand extends BaseRegistryCommand { | ||
|
||
@CommandLine.Parameters(arity = "0..1", paramLabel = "REGISTRY-ID[,REGISTRY-ID]", description = "Registry ID to remove from the registry client configuration%n" | ||
@CommandLine.Parameters(arity = "1..*", split = ",", paramLabel = "REGISTRY-ID[,REGISTRY-ID]", description = "Registry ID to remove from the registry client configuration%n" | ||
+ " Example:%n" | ||
+ " registry.quarkus.io%n" | ||
+ " registry.quarkus.acme.com,registry.quarkus.io%n") | ||
String registryIds; | ||
List<String> registryIds; | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
boolean existingConfig = false; | ||
Path configYaml = null; | ||
|
||
registryClient.refreshRegistryCache(output); | ||
// If a configuration was specified, check if it exists | ||
if (registryClient.getConfigArg() != null) { | ||
configYaml = Paths.get(registryClient.getConfigArg()); | ||
existingConfig = Files.exists(configYaml); | ||
} | ||
|
||
Path configYaml; | ||
if (registryClient.getConfigArg() == null) { | ||
configYaml = RegistriesConfigLocator.locateConfigYaml(); | ||
if (configYaml == null) { | ||
output.error("Failed to locate the registry client configuration file"); | ||
final RegistriesConfig.Mutable config; | ||
if (existingConfig) { | ||
registryClient.refreshRegistryCache(output); | ||
config = registryClient.resolveConfig().mutable(); | ||
if (config.getSource().getFilePath() == null) { | ||
output.error("Can only modify file-based configuration. Config source is " + config.getSource().describe()); | ||
return CommandLine.ExitCode.SOFTWARE; | ||
} | ||
} else { | ||
configYaml = Paths.get(registryClient.getConfigArg()); | ||
output.error("Can only remove registries from an existing configuration. The specified config file does not exist: " | ||
+ configYaml); | ||
return CommandLine.ExitCode.SOFTWARE; | ||
} | ||
|
||
final RegistriesConfig config = RegistriesConfigMapperHelper.deserialize(configYaml, JsonRegistriesConfig.class); | ||
|
||
final Map<String, RegistryConfig> registries = new LinkedHashMap<>(config.getRegistries().size()); | ||
config.getRegistries().forEach(r -> registries.put(r.getId(), r)); | ||
boolean persist = false; | ||
for (String registryId : registryIds.split(",")) { | ||
if (registries.remove(registryId) == null) { | ||
output.info("Registry " + registryId + " was not previously configured"); | ||
} else { | ||
output.info("Registry " + registryId + " was removed"); | ||
persist = true; | ||
} | ||
for (String registryId : registryIds) { | ||
persist |= config.removeRegistry(registryId); | ||
} | ||
|
||
if (persist) { | ||
final JsonRegistriesConfig jsonConfig = new JsonRegistriesConfig(); | ||
jsonConfig.setRegistries(new ArrayList<>(registries.values())); | ||
RegistriesConfigMapperHelper.serialize(jsonConfig, configYaml); | ||
config.persist(); | ||
} | ||
|
||
return CommandLine.ExitCode.OK; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.