Search in sources :

Example 1 with ConfigLayerSpec

use of org.jboss.galleon.spec.ConfigLayerSpec 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 2 with ConfigLayerSpec

use of org.jboss.galleon.spec.ConfigLayerSpec in project galleon by wildfly.

the class FeaturePackRuntimeBuilder method getConfigLayer.

ConfigLayerSpec getConfigLayer(ConfigId configId) throws ProvisioningException {
    if (layers != null) {
        final ConfigLayerSpec layer = layers.get(configId);
        if (layer != null) {
            return layer;
        }
    }
    final Path p = LayoutUtils.getLayerSpecXml(dir, configId.getModel(), configId.getName(), false);
    if (!Files.exists(p)) {
        return null;
    }
    final ConfigLayerSpec layer = XmlParsers.parseConfigLayerSpec(p, configId.getModel());
    if (layers == null) {
        layers = new HashMap<>();
    }
    layers.put(configId, layer);
    return layer;
}
Also used : Path(java.nio.file.Path) ConfigLayerSpec(org.jboss.galleon.spec.ConfigLayerSpec)

Example 3 with ConfigLayerSpec

use of org.jboss.galleon.spec.ConfigLayerSpec in project galleon by wildfly.

the class ProvisioningRuntimeBuilder method resolveConfigLayer.

private boolean resolveConfigLayer(ProducerSpec producer, ConfigModelStack layerStack, ConfigId layerId) throws ProvisioningException {
    final FeaturePackRuntimeBuilder fp = layout.getFeaturePack(producer);
    if (!setFlag(fp, FeaturePackRuntimeBuilder.RESOLVE_LAYER)) {
        return fp.getConfigLayer(layerId) != null;
    }
    final FeaturePackRuntimeBuilder prevOrigin = currentOrigin;
    try {
        boolean resolved;
        final ConfigLayerSpec configLayer = fp.getConfigLayer(layerId);
        resolved = configLayer != null;
        if (resolved) {
            layerStack.pushGroup(configLayer);
        }
        if (fp.getSpec().hasFeaturePackDeps()) {
            for (FeaturePackConfig depConfig : fp.getSpec().getFeaturePackDeps()) {
                resolved |= resolveConfigLayer(depConfig.getLocation().getProducer(), layerStack, layerId);
            }
        }
        if (configLayer != null) {
            setOrigin(fp);
            processConfigLayer(layerStack, popLayer(layerStack));
        }
        return resolved;
    } finally {
        setOrigin(prevOrigin);
    }
}
Also used : ConfigLayerSpec(org.jboss.galleon.spec.ConfigLayerSpec) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 4 with ConfigLayerSpec

use of org.jboss.galleon.spec.ConfigLayerSpec in project galleon by wildfly.

the class ProvisioningRuntimeBuilder method popLayer.

private FeatureGroupSupport popLayer(ConfigModelStack layerStack) throws ProvisioningException {
    final FeatureGroupSupport fg = layerStack.peekAtGroup();
    if (!(fg instanceof ConfigLayerSpec)) {
        throw new ProvisioningException("Expected config layer but got " + fg);
    }
    final ConfigLayerSpec layer = (ConfigLayerSpec) fg;
    if (layer.hasLayerDeps()) {
        for (ConfigLayerDependency dep : layer.getLayerDeps()) {
            layerStack.addLayerDep(dep);
        }
    }
    layerStack.popGroup();
    return fg;
}
Also used : FeatureGroupSupport(org.jboss.galleon.config.FeatureGroupSupport) ProvisioningException(org.jboss.galleon.ProvisioningException) ConfigLayerSpec(org.jboss.galleon.spec.ConfigLayerSpec) ConfigLayerDependency(org.jboss.galleon.spec.ConfigLayerDependency)

Example 5 with ConfigLayerSpec

use of org.jboss.galleon.spec.ConfigLayerSpec in project galleon by wildfly.

the class LayersConfigBuilder method getAllLayers.

private static Map<String, Map<String, Set<String>>> getAllLayers(ProvisioningLayout<FeaturePackLayout> pLayout, boolean includeDependencies) throws ProvisioningException, IOException {
    Map<String, Map<String, Set<String>>> layersMap = new HashMap<>();
    for (FeaturePackLayout fp : pLayout.getOrderedFeaturePacks()) {
        for (ConfigId layer : fp.loadLayers()) {
            String model = layer.getModel();
            Map<String, Set<String>> names = layersMap.get(model);
            if (names == null) {
                names = new HashMap<>();
                layersMap.put(model, names);
            }
            Set<String> dependencies = new TreeSet<>();
            if (includeDependencies) {
                ConfigLayerSpec spec = fp.loadConfigLayerSpec(model, layer.getName());
                for (ConfigLayerDependency dep : spec.getLayerDeps()) {
                    dependencies.add(dep.getName());
                }
            }
            // Case where a layer is redefined in multiple FP. Add all deps.
            Set<String> existingDependencies = names.get(layer.getName());
            if (existingDependencies != null) {
                existingDependencies.addAll(dependencies);
                dependencies = existingDependencies;
            }
            names.put(layer.getName(), dependencies);
        }
    }
    return layersMap;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ConfigLayerSpec(org.jboss.galleon.spec.ConfigLayerSpec) ConfigLayerDependency(org.jboss.galleon.spec.ConfigLayerDependency) FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) TreeSet(java.util.TreeSet) ConfigId(org.jboss.galleon.config.ConfigId) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ConfigLayerSpec (org.jboss.galleon.spec.ConfigLayerSpec)6 ProvisioningException (org.jboss.galleon.ProvisioningException)3 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConfigId (org.jboss.galleon.config.ConfigId)2 ConfigLayerDependency (org.jboss.galleon.spec.ConfigLayerDependency)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)1 ConfigModel (org.jboss.galleon.config.ConfigModel)1 FeatureGroup (org.jboss.galleon.config.FeatureGroup)1 FeatureGroupSupport (org.jboss.galleon.config.FeatureGroupSupport)1 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)1 FeaturePackLayout (org.jboss.galleon.layout.FeaturePackLayout)1 FeaturePackSpec (org.jboss.galleon.spec.FeaturePackSpec)1 FeatureSpec (org.jboss.galleon.spec.FeatureSpec)1