Search in sources :

Example 11 with FeaturePackSpec

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

use of org.jboss.galleon.spec.FeaturePackSpec 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

FeaturePackSpec (org.jboss.galleon.spec.FeaturePackSpec)12 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)6 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)4 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)4 Test (org.junit.Test)4 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)3 ProvisioningException (org.jboss.galleon.ProvisioningException)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 ConfigId (org.jboss.galleon.config.ConfigId)2 ConfigModel (org.jboss.galleon.config.ConfigModel)2 ProducerSpec (org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec)2 BufferedReader (java.io.BufferedReader)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 FeatureConfig (org.jboss.galleon.config.FeatureConfig)1 FeatureGroup (org.jboss.galleon.config.FeatureGroup)1