Search in sources :

Example 6 with ProvisioningOption

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();
}
Also used : Table(org.jboss.galleon.cli.cmd.Table) ProvisioningOption(org.jboss.galleon.ProvisioningOption)

Example 7 with ProvisioningOption

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();
    }
}
Also used : Path(java.nio.file.Path) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) ProvisioningOption(org.jboss.galleon.ProvisioningOption) ArrayList(java.util.ArrayList)

Example 8 with ProvisioningOption

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);
}
Also used : InstallPlugin(org.jboss.galleon.plugin.InstallPlugin) ProvisioningOption(org.jboss.galleon.ProvisioningOption) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ProvisioningException(org.jboss.galleon.ProvisioningException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

ProvisioningOption (org.jboss.galleon.ProvisioningOption)8 ArrayList (java.util.ArrayList)5 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)4 Path (java.nio.file.Path)2 ProvisioningException (org.jboss.galleon.ProvisioningException)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 AbstractDynamicCommand (org.jboss.galleon.cli.cmd.AbstractDynamicCommand)1 Table (org.jboss.galleon.cli.cmd.Table)1 FeaturePackLayout (org.jboss.galleon.layout.FeaturePackLayout)1 InstallPlugin (org.jboss.galleon.plugin.InstallPlugin)1 ProvisioningRuntime (org.jboss.galleon.runtime.ProvisioningRuntime)1 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)1