-
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.
- Loading branch information
1 parent
fb575c1
commit e85aab6
Showing
15 changed files
with
265 additions
and
15 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
74 changes: 74 additions & 0 deletions
74
devtools/cli/src/main/java/io/quarkus/cli/RegistryAddCommand.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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package io.quarkus.cli; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import io.quarkus.cli.registry.BaseRegistryCommand; | ||
import io.quarkus.cli.registry.RegistryClientMixin; | ||
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.JsonRegistryConfig; | ||
import io.quarkus.registry.config.json.RegistriesConfigMapperHelper; | ||
import picocli.CommandLine; | ||
|
||
@CommandLine.Command(name = "add", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, header = "Add a Quarkus extension registry to the registry client configuration", description = "%n" | ||
+ "This command will add a Quarkus extension registry to the registry client configuration unless it's already present", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n") | ||
public class RegistryAddCommand extends BaseRegistryCommand { | ||
|
||
@CommandLine.Mixin | ||
protected RegistryClientMixin registryClient; | ||
|
||
@CommandLine.Parameters(arity = "0..1", paramLabel = "REGISTRY-ID[,REGISTRY-ID]", description = "Registry ID to add to the registry client configuration%n" | ||
+ " Example:%n" | ||
+ " registry.quarkus.io%n" | ||
+ " registry.quarkus.acme.com,registry.quarkus.io%n") | ||
String registryIds; | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
|
||
registryClient.refreshRegistryCache(output); | ||
|
||
Path configYaml; | ||
if (registryClient.getConfigArg() == null) { | ||
configYaml = RegistriesConfigLocator.locateConfigYaml(); | ||
if (configYaml == null) { | ||
configYaml = RegistriesConfigLocator.getDefaultConfigYamlLocation(); | ||
} | ||
} else { | ||
configYaml = Paths.get(registryClient.getConfigArg()); | ||
} | ||
|
||
final RegistriesConfig config; | ||
if (Files.exists(configYaml)) { | ||
config = RegistriesConfigMapperHelper.deserialize(configYaml, JsonRegistriesConfig.class); | ||
} else { | ||
config = new JsonRegistriesConfig(); | ||
} | ||
|
||
final Set<String> existingIds = config.getRegistries().stream().map(RegistryConfig::getId).collect(Collectors.toSet()); | ||
boolean persist = false; | ||
for (String registryId : registryIds.split(",")) { | ||
if (existingIds.add(registryId)) { | ||
persist = true; | ||
final JsonRegistryConfig registry = new JsonRegistryConfig(); | ||
registry.setId(registryId); | ||
config.getRegistries().add(registry); | ||
output.info("Registry " + registryId + " was added"); | ||
} else { | ||
output.info("Registry " + registryId + " was skipped since it is already present"); | ||
} | ||
} | ||
|
||
if (persist) { | ||
RegistriesConfigMapperHelper.serialize(config, configYaml); | ||
} | ||
|
||
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
69 changes: 69 additions & 0 deletions
69
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.quarkus.cli; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
import io.quarkus.cli.registry.BaseRegistryCommand; | ||
import io.quarkus.cli.registry.RegistryClientMixin; | ||
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 from the registry client configuration", 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.Mixin | ||
protected RegistryClientMixin registryClient; | ||
|
||
@CommandLine.Parameters(arity = "0..1", 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; | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
|
||
registryClient.refreshRegistryCache(output); | ||
|
||
Path configYaml; | ||
if (registryClient.getConfigArg() == null) { | ||
configYaml = RegistriesConfigLocator.locateConfigYaml(); | ||
if (configYaml == null) { | ||
output.error("Failed to locate the registry client configuration file"); | ||
return CommandLine.ExitCode.SOFTWARE; | ||
} | ||
} else { | ||
configYaml = Paths.get(registryClient.getConfigArg()); | ||
} | ||
|
||
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; | ||
} | ||
} | ||
|
||
if (persist) { | ||
final JsonRegistriesConfig jsonConfig = new JsonRegistriesConfig(); | ||
jsonConfig.setRegistries(new ArrayList<>(registries.values())); | ||
RegistriesConfigMapperHelper.serialize(jsonConfig, configYaml); | ||
} | ||
|
||
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
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.