Search in sources :

Example 16 with ConfigId

use of org.jboss.galleon.config.ConfigId in project galleon by wildfly.

the class ProvisioningRuntimeBuilder method collectDefaultConfigs.

private void collectDefaultConfigs() throws ProvisioningException {
    if (config.hasDefinedConfigs()) {
        for (ConfigModel config : config.getDefinedConfigs()) {
            final ConfigId id = config.getId();
            if (id.isModelOnly()) {
                continue;
            }
            ConfigModelStack configStack = configsToBuild.get(id);
            if (configStack == null) {
                configStack = getConfigStack(id);
                configsToBuild = CollectionUtils.putLinked(configsToBuild, id, configStack);
            }
        }
    }
    if (pushFpDepConfigs(config)) {
        while (fpConfigStack.hasNext()) {
            collectDefaultConfigs(fpConfigStack.next());
        }
        fpConfigStack.popLevel();
    }
}
Also used : ConfigModel(org.jboss.galleon.config.ConfigModel) ConfigId(org.jboss.galleon.config.ConfigId)

Example 17 with ConfigId

use of org.jboss.galleon.config.ConfigId in project galleon by wildfly.

the class ConfigModelStack method merge.

void merge(ConfigModelStack other) throws ProvisioningException {
    if (!other.props.isEmpty()) {
        if (props.isEmpty()) {
            props = other.props;
        } else {
            for (Map.Entry<String, String> prop : other.props.entrySet()) {
                if (!props.containsKey(prop.getKey())) {
                    props.put(prop.getKey(), prop.getValue());
                }
            }
        }
    }
    if (!other.configDeps.isEmpty()) {
        if (configDeps.isEmpty()) {
            configDeps = other.configDeps;
        } else {
            for (Map.Entry<String, ConfigId> configDep : other.configDeps.entrySet()) {
                if (!configDeps.containsKey(configDep.getKey())) {
                    configDeps.put(configDep.getKey(), configDep.getValue());
                }
            }
        }
    }
    if (other.includedLayers != null && !other.includedLayers.isEmpty()) {
        for (ConfigId layerId : other.includedLayers) {
            if (addLayer(layerId)) {
                includedLayer(layerId);
            }
        }
    }
    if (other.specFeatures.isEmpty()) {
        return;
    }
    for (Map.Entry<ResolvedSpecId, SpecFeatures> entry : other.specFeatures.entrySet()) {
        final SpecFeatures otherSpecFeatures = entry.getValue();
        SpecFeatures specFeatures = null;
        for (ResolvedFeature feature : otherSpecFeatures.getFeatures()) {
            if (lastProcessedScope.isFilteredOut(feature.getSpecId(), feature.id)) {
                continue;
            }
            if (feature.id == null) {
                if (specFeatures == null) {
                    specFeatures = getSpecFeatures(otherSpecFeatures.spec);
                }
                specFeatures.add(feature);
                continue;
            }
            final ResolvedFeature localFeature = features.get(feature.id);
            if (localFeature == null) {
                feature = feature.copy(++featureIncludeCount);
                features.put(feature.id, feature);
                if (specFeatures == null) {
                    specFeatures = getSpecFeatures(otherSpecFeatures.spec);
                }
                specFeatures.add(feature);
            } else {
                localFeature.merge(feature, false);
            }
        }
    }
}
Also used : ConfigId(org.jboss.galleon.config.ConfigId) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 18 with ConfigId

use of org.jboss.galleon.config.ConfigId in project galleon by wildfly.

the class StateInfoUtil method buildConfigs.

public static String buildConfigs(Map<String, List<ConfigInfo>> configs, ProvisioningLayout<FeaturePackLayout> pLayout) throws ProvisioningException, IOException {
    if (!configs.isEmpty()) {
        boolean hasLayers = false;
        List<Table.Node> nodes = new ArrayList<>();
        Map<String, Map<String, Set<String>>> layers = LayersConfigBuilder.getAllLayers(pLayout);
        for (Entry<String, List<ConfigInfo>> entry : configs.entrySet()) {
            if (!entry.getValue().isEmpty()) {
                Table.Node model = new Table.Node(entry.getKey());
                nodes.add(model);
                for (ConfigInfo name : entry.getValue()) {
                    Table.Node nameNode = new Table.Node(name.getName());
                    model.addNext(nameNode);
                    // Compute the direct dependencies only, remove dependencies of dependencies.
                    for (ConfigId id : name.getlayers()) {
                        Map<String, Set<String>> map = layers.get(entry.getKey());
                        boolean foundAsDependency = false;
                        if (map != null) {
                            for (ConfigId l : name.getlayers()) {
                                if (l.getName().equals(id.getName())) {
                                    continue;
                                }
                                Set<String> deps = map.get(l.getName());
                                if (deps != null) {
                                    if (deps.contains(id.getName())) {
                                        foundAsDependency = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (!foundAsDependency) {
                            hasLayers = true;
                            nameNode.addNext(new Table.Node(id.getName()));
                        }
                    }
                    ConfigModel m = pLayout.getConfig().getDefinedConfig(name.getId());
                    if (m != null) {
                        if (m.hasExcludedLayers()) {
                            for (String ex : m.getExcludedLayers()) {
                                hasLayers = true;
                                nameNode.addNext(new Table.Node(ex + "(excluded)"));
                            }
                        }
                    }
                }
            }
        }
        Table.Tree table;
        if (hasLayers) {
            table = new Table.Tree(Headers.CONFIGURATION, Headers.NAME, Headers.LAYERS);
        } else {
            table = new Table.Tree(Headers.CONFIGURATION, Headers.NAME);
        }
        table.addAll(nodes);
        return "Configurations" + Config.getLineSeparator() + table.build();
    }
    return null;
}
Also used : Table(org.jboss.galleon.cli.cmd.Table) Set(java.util.Set) ArrayList(java.util.ArrayList) ConfigInfo(org.jboss.galleon.cli.model.ConfigInfo) ConfigModel(org.jboss.galleon.config.ConfigModel) List(java.util.List) ArrayList(java.util.ArrayList) ConfigId(org.jboss.galleon.config.ConfigId) Map(java.util.Map) HashMap(java.util.HashMap)

Example 19 with ConfigId

use of org.jboss.galleon.config.ConfigId in project galleon by wildfly.

the class ProvisioningXmlParser30 method parseConfigModelRef.

private static void parseConfigModelRef(XMLExtendedStreamReader reader, ConfigCustomizationsBuilder<?> fpBuilder, boolean include) throws XMLStreamException {
    String name = null;
    String model = null;
    Boolean namedConfigsOnly = null;
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i).getLocalPart());
        switch(attribute) {
            case NAME:
                name = reader.getAttributeValue(i);
                break;
            case MODEL:
                model = reader.getAttributeValue(i);
                break;
            case NAMED_MODELS_ONLY:
                namedConfigsOnly = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            default:
                throw ParsingUtils.unexpectedContent(reader);
        }
    }
    try {
        if (include) {
            if (name == null) {
                fpBuilder.includeConfigModel(model);
            } else {
                fpBuilder.includeDefaultConfig(new ConfigId(model, name));
            }
        } else if (name == null) {
            if (namedConfigsOnly != null) {
                fpBuilder.excludeConfigModel(model, namedConfigsOnly);
            } else {
                fpBuilder.excludeConfigModel(model);
            }
        } else {
            fpBuilder.excludeDefaultConfig(model, name);
        }
    } catch (ProvisioningDescriptionException e) {
        throw new XMLStreamException(e);
    }
    ParsingUtils.parseNoContent(reader);
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) ConfigId(org.jboss.galleon.config.ConfigId) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException)

Example 20 with ConfigId

use of org.jboss.galleon.config.ConfigId in project galleon by wildfly.

the class ProvisioningXmlWriter method writeConfigCustomizations.

static void writeConfigCustomizations(ElementNode parent, String ns, ConfigCustomizations configCustoms) {
    ElementNode defConfigsE = null;
    final Boolean inheritConfigs = configCustoms.getInheritConfigs();
    if (inheritConfigs != null) {
        defConfigsE = addElement(parent, Element.DEFAULT_CONFIGS.getLocalName(), ns);
        addAttribute(defConfigsE, Attribute.INHERIT, inheritConfigs.toString());
    }
    if (!configCustoms.isInheritModelOnlyConfigs()) {
        if (defConfigsE == null) {
            defConfigsE = addElement(parent, Element.DEFAULT_CONFIGS.getLocalName(), ns);
        }
        addAttribute(defConfigsE, Attribute.INHERIT_UNNAMED_MODELS, FALSE);
    }
    if (configCustoms.hasFullModelsExcluded()) {
        if (defConfigsE == null) {
            defConfigsE = addElement(parent, Element.DEFAULT_CONFIGS.getLocalName(), ns);
        }
        for (Map.Entry<String, Boolean> excluded : configCustoms.getFullModelsExcluded().entrySet()) {
            final ElementNode exclude = addElement(defConfigsE, Element.EXCLUDE.getLocalName(), ns);
            addAttribute(exclude, Attribute.MODEL, excluded.getKey());
            if (!excluded.getValue()) {
                addAttribute(exclude, Attribute.NAMED_MODELS_ONLY, FALSE);
            }
        }
    }
    if (configCustoms.hasFullModelsIncluded()) {
        if (defConfigsE == null) {
            defConfigsE = addElement(parent, Element.DEFAULT_CONFIGS.getLocalName(), ns);
        }
        final String[] array = configCustoms.getFullModelsIncluded().toArray(new String[configCustoms.getFullModelsIncluded().size()]);
        Arrays.sort(array);
        for (String modelName : array) {
            final ElementNode included = addElement(defConfigsE, Element.INCLUDE.getLocalName(), ns);
            addAttribute(included, Attribute.MODEL, modelName);
        }
    }
    if (configCustoms.hasExcludedConfigs()) {
        if (defConfigsE == null) {
            defConfigsE = addElement(parent, Element.DEFAULT_CONFIGS.getLocalName(), ns);
        }
        for (ConfigId configId : configCustoms.getExcludedConfigs()) {
            final ElementNode excluded = addElement(defConfigsE, Element.EXCLUDE.getLocalName(), ns);
            if (configId.getModel() != null) {
                addAttribute(excluded, Attribute.MODEL, configId.getModel());
            }
            if (configId.getName() != null) {
                addAttribute(excluded, Attribute.NAME, configId.getName());
            }
        }
    }
    if (configCustoms.hasIncludedConfigs()) {
        if (defConfigsE == null) {
            defConfigsE = addElement(parent, Element.DEFAULT_CONFIGS.getLocalName(), ns);
        }
        for (ConfigId config : configCustoms.getIncludedConfigs()) {
            final ElementNode includeElement = addElement(defConfigsE, Element.INCLUDE.getLocalName(), ns);
            if (config.getModel() != null) {
                addAttribute(includeElement, Attribute.MODEL, config.getModel());
            }
            if (config.getName() != null) {
                addAttribute(includeElement, Attribute.NAME, config.getName());
            }
        }
    }
    if (configCustoms.hasDefinedConfigs()) {
        for (ConfigModel config : configCustoms.getDefinedConfigs()) {
            parent.addChild(ConfigXmlWriter.getInstance().toElement(config, ns));
        }
    }
}
Also used : ConfigModel(org.jboss.galleon.config.ConfigModel) ConfigId(org.jboss.galleon.config.ConfigId) ElementNode(org.jboss.galleon.xml.util.ElementNode) Map(java.util.Map)

Aggregations

ConfigId (org.jboss.galleon.config.ConfigId)39 ConfigModel (org.jboss.galleon.config.ConfigModel)12 Path (java.nio.file.Path)11 Map (java.util.Map)10 ProvisioningException (org.jboss.galleon.ProvisioningException)9 IOException (java.io.IOException)7 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)6 HashMap (java.util.HashMap)5 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)5 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)3 ElementNode (org.jboss.galleon.xml.util.ElementNode)3 BufferedWriter (java.io.BufferedWriter)2 FileVisitResult (java.nio.file.FileVisitResult)2