Search in sources :

Example 11 with ConfigId

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

the class State method removeExcludedLayersConfiguration.

public void removeExcludedLayersConfiguration(PmSession pmSession, ConfigInfo configuration, String[] layers) throws ProvisioningException, IOException {
    ConfigId id = new ConfigId(configuration.getModel(), configuration.getName());
    Action action = configProvisioning.removeExcludedLayersConfiguration(id, layers);
    config = pushState(action, pmSession);
}
Also used : ConfigId(org.jboss.galleon.config.ConfigId)

Example 12 with ConfigId

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

the class FeaturePackLayout method loadLayers.

public Set<ConfigId> loadLayers() throws ProvisioningException, IOException {
    Path layersDir = getDir().resolve(Constants.LAYERS);
    if (!Files.exists(layersDir)) {
        return Collections.emptySet();
    }
    Set<ConfigId> layers = new HashSet<>();
    Files.walkFileTree(layersDir, new SimpleFileVisitor<Path>() {

        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            if (file.getFileName().toString().equals(Constants.LAYER_SPEC_XML)) {
                ConfigId id;
                Path rootDir = file.getParent().getParent();
                // No model
                if (rootDir.equals(layersDir)) {
                    id = new ConfigId(null, file.getParent().getFileName().toString());
                } else {
                    id = new ConfigId(rootDir.getFileName().toString(), file.getParent().getFileName().toString());
                }
                layers.add(id);
            }
            return FileVisitResult.CONTINUE;
        }
    });
    return layers;
}
Also used : Path(java.nio.file.Path) FileVisitResult(java.nio.file.FileVisitResult) ConfigId(org.jboss.galleon.config.ConfigId) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) HashSet(java.util.HashSet)

Example 13 with ConfigId

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

the class FeaturePackBuilder method build.

void build() throws ProvisioningException {
    final FeaturePackLocation fps = fpBuilder.getFPID().getLocation();
    if (fps == null) {
        throw new ProvisioningDescriptionException("Feature-pack location has not been set");
    }
    if (fps.getProducerName() == null) {
        throw new ProvisioningDescriptionException("Feature-pack producer has not been set");
    }
    /*
        if(fps.getChannelName() == null) {
            throw new ProvisioningDescriptionException("Feature-pack channel has not been set");
        }
        */
    if (fps.getBuild() == null) {
        throw new ProvisioningDescriptionException("Feature-pack build number has not been set");
    }
    final Path fpWorkDir = LayoutUtils.getFeaturePackDir(creator.getWorkDir(), fps.getFPID(), false);
    final FeaturePackSpec fpSpec;
    try {
        ensureDir(fpWorkDir);
        for (PackageBuilder pkg : pkgs) {
            final PackageSpec pkgDescr = pkg.build(fpWorkDir);
            if (pkg.isDefault()) {
                fpBuilder.addDefaultPackage(pkgDescr.getName());
            }
        }
        if (!specs.isEmpty()) {
            final Path featuresDir = fpWorkDir.resolve(Constants.FEATURES);
            final FeatureSpecXmlWriter specWriter = FeatureSpecXmlWriter.getInstance();
            for (FeatureSpec spec : specs.values()) {
                final Path featureDir = featuresDir.resolve(spec.getName());
                ensureDir(featureDir);
                specWriter.write(spec, featureDir.resolve(Constants.SPEC_XML));
            }
        }
        if (!featureGroups.isEmpty()) {
            final Path fgsDir = fpWorkDir.resolve(Constants.FEATURE_GROUPS);
            ensureDir(fgsDir);
            final FeatureGroupXmlWriter fgWriter = FeatureGroupXmlWriter.getInstance();
            for (FeatureGroup fg : featureGroups.values()) {
                fgWriter.write(fg, fgsDir.resolve(fg.getName() + ".xml"));
            }
        }
        if (!classes.isEmpty()) {
            createPluginJar(classes, services, fpWorkDir.resolve(Constants.PLUGINS).resolve(pluginFileName));
        }
        if (!plugins.isEmpty()) {
            final Path pluginsDir = fpWorkDir.resolve(Constants.PLUGINS);
            ensureDir(pluginsDir);
            for (Path plugin : plugins) {
                Files.copy(plugin, pluginsDir.resolve(plugin.getFileName()));
            }
        }
        if (!layers.isEmpty()) {
            for (Map.Entry<ConfigId, ConfigLayerSpec> entry : layers.entrySet()) {
                final ConfigId id = entry.getKey();
                final Path xml = LayoutUtils.getLayerSpecXml(fpWorkDir, id.getModel(), id.getName(), false);
                if (Files.exists(xml)) {
                    throw new ProvisioningException("Failed to create feature-pack: " + xml + " already exists");
                }
                ConfigLayerXmlWriter.getInstance().write(entry.getValue(), xml);
            }
        }
        if (!configs.isEmpty()) {
            for (ConfigModel config : configs.values()) {
                final Path modelXml = LayoutUtils.getConfigXml(fpWorkDir, config.getId(), false);
                if (Files.exists(modelXml)) {
                    throw new ProvisioningException("Failed to create feature-pack: " + modelXml + " already exists");
                }
                ConfigXmlWriter.getInstance().write(config, modelXml);
            }
        }
        fpSpec = fpBuilder.build();
        final FeaturePackXmlWriter writer = FeaturePackXmlWriter.getInstance();
        writer.write(fpSpec, fpWorkDir.resolve(Constants.FEATURE_PACK_XML));
        if (tasks != null && !tasks.isEmpty()) {
            tasks.execute(FsTaskContext.builder().setTargetRoot(fpWorkDir.resolve(Constants.RESOURCES)).build());
        }
        creator.install(fps.getFPID(), fpWorkDir);
    } catch (ProvisioningDescriptionException e) {
        throw e;
    } catch (Exception e) {
        throw new IllegalStateException(e);
    } finally {
        IoUtils.recursiveDelete(fpWorkDir);
    }
}
Also used : Path(java.nio.file.Path) FeatureSpec(org.jboss.galleon.spec.FeatureSpec) FeatureGroup(org.jboss.galleon.config.FeatureGroup) ConfigLayerSpec(org.jboss.galleon.spec.ConfigLayerSpec) FeaturePackXmlWriter(org.jboss.galleon.xml.FeaturePackXmlWriter) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) IOException(java.io.IOException) ProvisioningException(org.jboss.galleon.ProvisioningException) ConfigModel(org.jboss.galleon.config.ConfigModel) PackageSpec(org.jboss.galleon.spec.PackageSpec) ProvisioningException(org.jboss.galleon.ProvisioningException) FeaturePackSpec(org.jboss.galleon.spec.FeaturePackSpec) FeatureSpecXmlWriter(org.jboss.galleon.xml.FeatureSpecXmlWriter) ConfigId(org.jboss.galleon.config.ConfigId) FeatureGroupXmlWriter(org.jboss.galleon.xml.FeatureGroupXmlWriter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with ConfigId

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

the class ProvisioningRuntimeBuilder method orderConfig.

private void orderConfig(ConfigModelStack config, List<ProvisionedConfig> configList, Set<ConfigId> scheduledIds) throws ProvisioningException {
    if (!config.hasConfigDeps()) {
        configList.add(ResolvedConfig.build(config));
        return;
    }
    scheduledIds = CollectionUtils.add(scheduledIds, config.id);
    for (ConfigId depId : config.getConfigDeps().values()) {
        if (scheduledIds.contains(depId) || contains(configList, depId)) {
            continue;
        }
        if (depId.isModelOnly()) {
            final Map<String, ConfigModelStack> configs = namedModelConfigs.get(depId.getModel());
            if (configs == null) {
                throw new ProvisioningDescriptionException("Config " + config.id + " has unsatisfied dependency on config " + depId);
            }
            for (ConfigModelStack dep : configs.values()) {
                if (contains(configList, dep.id)) {
                    continue;
                }
                orderConfig(dep, configList, scheduledIds);
            }
        } else {
            final ConfigModelStack configStack;
            if (depId.getModel() == null) {
                configStack = nameOnlyConfigs.get(depId.getName());
            } else {
                final Map<String, ConfigModelStack> configs = namedModelConfigs.get(depId.getModel());
                if (configs == null) {
                    throw new ProvisioningDescriptionException("Config " + config.id + " has unsatisfied dependency on config " + depId);
                }
                configStack = configs.get(depId.getName());
            }
            if (configStack == null) {
                throw new ProvisioningDescriptionException("Config " + config.id + " has unsatisfied dependency on config " + depId);
            }
            if (contains(configList, configStack.id)) {
                continue;
            }
            orderConfig(configStack, configList, scheduledIds);
        }
    }
    scheduledIds = CollectionUtils.remove(scheduledIds, config.id);
    configList.add(ResolvedConfig.build(config));
}
Also used : ConfigId(org.jboss.galleon.config.ConfigId) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException)

Example 15 with ConfigId

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

the class ProvisioningRuntimeBuilder method mergeModelOnlyConfigs.

private void mergeModelOnlyConfigs() throws ProvisioningException {
    if (namedModelConfigs.isEmpty()) {
        return;
    }
    for (Map.Entry<String, Map<String, ConfigModelStack>> entry : namedModelConfigs.entrySet()) {
        final ConfigId modelOnlyId = new ConfigId(entry.getKey(), null);
        final ConfigModelStack modelOnlyStack = resolveModelOnlyConfig(modelOnlyId);
        if (modelOnlyStack == null) {
            continue;
        }
        for (ConfigModelStack configStack : entry.getValue().values()) {
            configStack.merge(modelOnlyStack);
        }
    }
}
Also used : ConfigId(org.jboss.galleon.config.ConfigId) LinkedHashMap(java.util.LinkedHashMap) 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