Search in sources :

Example 1 with FeaturePackXmlWriter

use of org.jboss.galleon.xml.FeaturePackXmlWriter 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)

Aggregations

IOException (java.io.IOException)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)1 ProvisioningException (org.jboss.galleon.ProvisioningException)1 ConfigId (org.jboss.galleon.config.ConfigId)1 ConfigModel (org.jboss.galleon.config.ConfigModel)1 FeatureGroup (org.jboss.galleon.config.FeatureGroup)1 ConfigLayerSpec (org.jboss.galleon.spec.ConfigLayerSpec)1 FeaturePackSpec (org.jboss.galleon.spec.FeaturePackSpec)1 FeatureSpec (org.jboss.galleon.spec.FeatureSpec)1 PackageSpec (org.jboss.galleon.spec.PackageSpec)1 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)1 FeatureGroupXmlWriter (org.jboss.galleon.xml.FeatureGroupXmlWriter)1 FeaturePackXmlWriter (org.jboss.galleon.xml.FeaturePackXmlWriter)1 FeatureSpecXmlWriter (org.jboss.galleon.xml.FeatureSpecXmlWriter)1