Search in sources :

Example 6 with ConfigModel

use of org.jboss.galleon.config.ConfigModel 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 7 with ConfigModel

use of org.jboss.galleon.config.ConfigModel 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)

Example 8 with ConfigModel

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

the class LayersConfigBuilder method build.

ProvisioningConfig build() throws ProvisioningException, IOException {
    // Reuse existing configuration builder.
    ProvisioningConfig existing = mgr.getProvisioningConfig();
    ProvisioningConfig.Builder builder = null;
    FeaturePackConfig.Builder fpBuilder = null;
    ConfigModel.Builder configBuilder = null;
    if (existing != null) {
        builder = ProvisioningConfig.builder(existing);
        ConfigId id = new ConfigId(model, config);
        if (existing.hasDefinedConfig(id)) {
            ConfigModel cmodel = existing.getDefinedConfig(id);
            configBuilder = ConfigModel.builder(cmodel);
            handleLayers(configBuilder, cmodel);
            builder.removeConfig(id);
        }
        if (builder.hasFeaturePackDep(loc.getProducer())) {
            FeaturePackConfig fp = existing.getFeaturePackDep(loc.getProducer());
            fpBuilder = FeaturePackConfig.builder(fp);
            builder.removeFeaturePackDep(fp.getLocation());
        }
    }
    if (builder == null) {
        builder = ProvisioningConfig.builder();
    }
    if (configBuilder == null) {
        configBuilder = ConfigModel.builder(model, config);
        handleLayers(configBuilder, null);
    }
    if (fpBuilder == null) {
        fpBuilder = FeaturePackConfig.builder(loc).setInheritConfigs(false).setInheritPackages(false);
    }
    builder.addConfig(configBuilder.build());
    builder.addFeaturePackDep(fpBuilder.build());
    return builder.build();
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ConfigModel(org.jboss.galleon.config.ConfigModel) ConfigId(org.jboss.galleon.config.ConfigId) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 9 with ConfigModel

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

the class FeaturePackInstaller method install.

public void install() {
    try (ProvisioningManager manager = ProvisioningManager.builder().addArtifactResolver(LegacyGalleon1RepositoryManager.newInstance(repoHome)).setInstallationHome(installationDir).setRecordState(recordState).build()) {
        System.setProperty("org.wildfly.logging.skipLogManagerCheck", "true");
        ConfigModel config = null;
        if (customConfig != null && Files.exists(customConfig)) {
            try (BufferedReader reader = Files.newBufferedReader(customConfig)) {
                config = ConfigXmlParser.getInstance().parse(reader);
            } catch (XMLStreamException | IOException ex) {
                throw new IllegalArgumentException("Couldn't load the customization configuration " + customConfig, ex);
            }
        }
        if (localPath != null) {
            fpl = manager.getLayoutFactory().addLocal(localPath, false);
        }
        FeaturePackConfig.Builder fpConfigBuilder = FeaturePackConfig.builder(fpl).setInheritPackages(inheritPackages).setInheritConfigs(inheritConfigs);
        if (includedConfigs != null && !includedConfigs.isEmpty()) {
            for (ConfigurationId configId : includedConfigs) {
                if (configId.isModelOnly()) {
                    fpConfigBuilder.includeConfigModel(configId.getId().getModel());
                } else {
                    fpConfigBuilder.includeDefaultConfig(configId.getId());
                }
            }
        }
        if (config != null) {
            fpConfigBuilder.addConfig(config);
        }
        if (includedPackages != null && !includedPackages.isEmpty()) {
            for (String includedPackage : includedPackages) {
                fpConfigBuilder.includePackage(includedPackage);
            }
        }
        if (excludedPackages != null && !excludedPackages.isEmpty()) {
            for (String excludedPackage : excludedPackages) {
                fpConfigBuilder.excludePackage(excludedPackage);
            }
        }
        manager.install(fpConfigBuilder.build(), pluginOptions);
    } catch (ProvisioningException ex) {
        throw new IllegalArgumentException("Couldn't install feature-pack " + fpl, ex);
    } finally {
        System.clearProperty("org.wildfly.logging.skipLogManagerCheck");
    }
}
Also used : ProvisioningManager(org.jboss.galleon.ProvisioningManager) ConfigModel(org.jboss.galleon.config.ConfigModel) XMLStreamException(javax.xml.stream.XMLStreamException) ProvisioningException(org.jboss.galleon.ProvisioningException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 10 with ConfigModel

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

the class ProvisioningRuntimeBuilder method collectDefaultConfigs.

private void collectDefaultConfigs(FeaturePackConfig fpConfig) throws ProvisioningException {
    thisOrigin = layout.getFeaturePack(fpConfig.getLocation().getProducer());
    final FeaturePackRuntimeBuilder parentFp = setOrigin(thisOrigin);
    try {
        if (fpConfig.hasDefinedConfigs()) {
            for (ConfigModel config : fpConfig.getDefinedConfigs()) {
                final ConfigId id = config.getId();
                if (id.isModelOnly() || fpConfigStack.isFilteredOut(thisOrigin.producer, id, true)) {
                    continue;
                }
                ConfigModelStack configStack = configsToBuild.get(id);
                if (configStack == null) {
                    configStack = getConfigStack(id);
                    configsToBuild = CollectionUtils.putLinked(configsToBuild, id, configStack);
                }
            }
        }
        if (!fpConfig.isTransitive()) {
            if (fpConfig.hasIncludedConfigs()) {
                for (ConfigId id : fpConfig.getIncludedConfigs()) {
                    collectConfigIfNotFiltered(thisOrigin.producer, id);
                }
            }
            final FeaturePackSpec currentSpec = currentOrigin.getSpec();
            if (currentSpec.hasDefinedConfigs()) {
                for (ConfigModel config : currentSpec.getDefinedConfigs()) {
                    collectConfigIfNotFiltered(thisOrigin.producer, config.getId());
                }
            }
            if (currentSpec.hasFeaturePackDeps()) {
                boolean extendedStackLevel = false;
                if (currentSpec.hasTransitiveDeps()) {
                    for (FeaturePackConfig fpDep : currentSpec.getTransitiveDeps()) {
                        extendedStackLevel |= fpConfigStack.push(fpDep, extendedStackLevel);
                    }
                }
                for (FeaturePackConfig fpDep : currentSpec.getFeaturePackDeps()) {
                    extendedStackLevel |= fpConfigStack.push(fpDep, extendedStackLevel);
                }
                if (extendedStackLevel) {
                    while (fpConfigStack.hasNext()) {
                        collectDefaultConfigs(fpConfigStack.next());
                    }
                }
                if (extendedStackLevel) {
                    fpConfigStack.popLevel();
                }
            }
        }
    } finally {
        this.thisOrigin = parentFp;
        setOrigin(parentFp);
    }
}
Also used : ConfigModel(org.jboss.galleon.config.ConfigModel) FeaturePackSpec(org.jboss.galleon.spec.FeaturePackSpec) ConfigId(org.jboss.galleon.config.ConfigId) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Aggregations

ConfigModel (org.jboss.galleon.config.ConfigModel)18 ConfigId (org.jboss.galleon.config.ConfigId)12 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 Map (java.util.Map)4 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)4 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)4 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)3 ProvisioningException (org.jboss.galleon.ProvisioningException)3 BufferedReader (java.io.BufferedReader)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 FeaturePackSpec (org.jboss.galleon.spec.FeaturePackSpec)2 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)2 Test (org.junit.Test)2 FileVisitResult (java.nio.file.FileVisitResult)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1