use of org.jboss.galleon.ProvisioningOption in project galleon by wildfly.
the class StateInfoUtil method buildOptionsTable.
private static String buildOptionsTable(Set<ProvisioningOption> options) {
Table t = new Table(Headers.OPTION, Headers.REQUIRED, Headers.DEFAULT_VALUE);
for (ProvisioningOption opt : options) {
t.addLine("--" + opt.getName() + "=", opt.isRequired() ? "Y" : "N", opt.getDefaultValue() == null ? "" : opt.getDefaultValue());
}
t.sort(Table.SortType.ASCENDANT);
return t.build();
}
use of org.jboss.galleon.ProvisioningOption in project galleon by wildfly.
the class UninstallCommand method getDynamicOptions.
@Override
protected List<DynamicOption> getDynamicOptions(State state) throws Exception {
String fpid = getFPID();
Path dir = getAbsolutePath(getUninstallDir(), pmSession.getAeshContext());
// Build layout from this directory.
ProvisioningConfig config = ProvisioningXmlParser.parse(PathsUtils.getProvisioningXml(dir));
if (config != null) {
// Silent resolution.
pmSession.unregisterTrackers();
try {
try (ProvisioningLayout<FeaturePackLayout> layout = pmSession.getLayoutFactory().newConfigLayout(config)) {
layout.uninstall(pmSession.getResolvedLocation(getInstallationDirectory(pmSession.getAeshContext()), fpid).getFPID());
Set<ProvisioningOption> opts = PluginResolver.newResolver(pmSession, layout).resolve().getInstall();
List<DynamicOption> options = new ArrayList<>();
for (ProvisioningOption opt : opts) {
DynamicOption dynOption = new DynamicOption(opt.getName(), opt.isRequired());
options.add(dynOption);
}
return options;
}
} finally {
pmSession.registerTrackers();
}
} else {
return Collections.emptyList();
}
}
use of org.jboss.galleon.ProvisioningOption in project galleon by wildfly.
the class ProvisioningLayout method initPluginOptions.
private void initPluginOptions(Map<String, String> extraOptions, boolean cleanupConfigOptions) throws ProvisioningException {
options = config.getOptions();
if (!extraOptions.isEmpty()) {
options = CollectionUtils.putAll(CollectionUtils.clone(options), extraOptions);
}
final Map<String, ProvisioningOption> recognizedOptions;
final List<ProvisioningOption> overridenOptions;
if (options.isEmpty()) {
recognizedOptions = Collections.emptyMap();
overridenOptions = Collections.emptyList();
} else {
final int size = options.size();
recognizedOptions = new HashMap<>(size);
overridenOptions = new ArrayList<>(size);
}
// process built-in options
processOptions(ProvisioningOption.getStandardList(), extraOptions, recognizedOptions, overridenOptions);
// process plugin options
handle.visitPlugins(new FeaturePackPluginVisitor<InstallPlugin>() {
@Override
public void visitPlugin(InstallPlugin plugin) throws ProvisioningException {
processOptions(plugin.getOptions().values(), extraOptions, recognizedOptions, overridenOptions);
}
}, InstallPlugin.class);
ProvisioningConfig.Builder configBuilder = null;
if (recognizedOptions.size() != options.size()) {
final Set<String> nonRecognized = new HashSet<>(options.keySet());
nonRecognized.removeAll(recognizedOptions.keySet());
if (cleanupConfigOptions) {
final Iterator<String> i = nonRecognized.iterator();
while (i.hasNext()) {
final String optionName = i.next();
if (!config.hasOption(optionName)) {
continue;
}
if (configBuilder == null) {
configBuilder = ProvisioningConfig.builder(config);
}
configBuilder.removeOption(optionName);
i.remove();
}
}
if (!nonRecognized.isEmpty()) {
throw new ProvisioningException(Errors.pluginOptionsNotRecognized(nonRecognized));
}
}
if (!overridenOptions.isEmpty()) {
if (configBuilder == null) {
configBuilder = ProvisioningConfig.builder(config);
}
for (ProvisioningOption option : overridenOptions) {
final String optionName = option.getName();
if (!extraOptions.containsKey(optionName)) {
continue;
}
final String value = extraOptions.get(optionName);
if (option.isPersistent()) {
configBuilder.addOption(optionName, value);
} else if (value == null) {
if (config.getOption(optionName) != null) {
configBuilder.removeOption(optionName);
}
} else if (!value.equals(config.getOption(optionName))) {
configBuilder.removeOption(optionName);
}
}
config = configBuilder.build();
} else if (configBuilder != null) {
config = configBuilder.build();
}
options = CollectionUtils.unmodifiable(options);
}
Aggregations