Search in sources :

Example 1 with FeatureGroup

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

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

the class ProvisioningRuntimeBuilder method getFeatureGroupSpec.

private FeatureGroup getFeatureGroupSpec(FeaturePackRuntimeBuilder origin, String name) throws ProvisioningException {
    final FeaturePackDepsConfig fpDeps;
    if (origin != null) {
        if (origin.isFlagOn(FeaturePackRuntimeBuilder.VISIT)) {
            return null;
        }
        final FeatureGroup fg = origin.getFeatureGroupSpec(name);
        if (fg != null) {
            currentOrigin = origin;
            return fg;
        }
        fpDeps = origin.getSpec();
        setFlag(origin, FeaturePackRuntimeBuilder.VISIT);
    } else {
        fpDeps = config;
    }
    if (!fpDeps.hasFeaturePackDeps()) {
        return null;
    }
    for (FeaturePackConfig fpDep : fpDeps.getFeaturePackDeps()) {
        final FeatureGroup fg = getFeatureGroupSpec(layout.getFeaturePack(fpDep.getLocation().getProducer()), name);
        if (fg != null) {
            return fg;
        }
    }
    return null;
}
Also used : FeatureGroup(org.jboss.galleon.config.FeatureGroup) FeaturePackDepsConfig(org.jboss.galleon.config.FeaturePackDepsConfig) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 3 with FeatureGroup

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

the class FeatureGroupXml method readFeatureGroupDependency.

private static FeatureGroup readFeatureGroupDependency(String origin, XMLExtendedStreamReader reader) throws XMLStreamException {
    String name = null;
    Boolean inheritFeatures = null;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        switch(attribute) {
            case NAME:
                name = reader.getAttributeValue(i);
                break;
            case INHERIT_FEATURES:
                inheritFeatures = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            default:
                throw ParsingUtils.unexpectedAttribute(reader, i);
        }
    }
    if (name == null && inheritFeatures != null) {
        throw new XMLStreamException(Attribute.INHERIT_FEATURES + " attribute can't be used w/o attribute " + Attribute.NAME);
    }
    final FeatureGroup.Builder depBuilder = FeatureGroup.builder(name).setOrigin(origin);
    if (inheritFeatures != null) {
        depBuilder.setInheritFeatures(inheritFeatures);
    }
    readFeatureGroupConfigBody(reader, depBuilder);
    try {
        return depBuilder.build();
    } catch (ProvisioningDescriptionException e) {
        throw new XMLStreamException("Failed to parse feature group dependency", reader.getLocation(), e);
    }
}
Also used : FeatureGroup(org.jboss.galleon.config.FeatureGroup) XMLStreamException(javax.xml.stream.XMLStreamException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException)

Example 4 with FeatureGroup

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

the class FeaturePackRuntimeBuilder method getFeatureGroupSpec.

FeatureGroup getFeatureGroupSpec(String name) throws ProvisioningException {
    if (fgSpecs != null) {
        final FeatureGroup fgSpec = fgSpecs.get(name);
        if (fgSpec != null) {
            return fgSpec;
        }
    }
    final Path specXml = dir.resolve(Constants.FEATURE_GROUPS).resolve(name + ".xml");
    if (!Files.exists(specXml)) {
        return null;
    }
    try (BufferedReader reader = Files.newBufferedReader(specXml)) {
        final FeatureGroup fgSpec = FeatureGroupXmlParser.getInstance().parse(reader);
        if (!fgSpec.getName().equals(name)) {
            throw new ProvisioningDescriptionException("Feature-pack " + getFPID() + " feature group " + fgSpec.getName() + " does not match the requested feature group name " + name);
        }
        if (fgSpecs == null) {
            fgSpecs = new HashMap<>();
        }
        fgSpecs.put(name, fgSpec);
        return fgSpec;
    } catch (Exception e) {
        throw new ProvisioningException(Errors.parseXml(specXml), e);
    }
}
Also used : Path(java.nio.file.Path) FeatureGroup(org.jboss.galleon.config.FeatureGroup) ProvisioningException(org.jboss.galleon.ProvisioningException) BufferedReader(java.io.BufferedReader) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) XMLStreamException(javax.xml.stream.XMLStreamException) UnsatisfiedPackageDependencyException(org.jboss.galleon.UnsatisfiedPackageDependencyException) IOException(java.io.IOException) ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 5 with FeatureGroup

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

the class ProvisioningRuntimeBuilder method getFeatureGroupSpec.

/**
 * NOTE: this method will change the current origin to the origin of the group!
 */
private FeatureGroup getFeatureGroupSpec(String name) throws ProvisioningException {
    final FeatureGroup fg = getFeatureGroupSpec(currentOrigin, name);
    clearFlag(FeaturePackRuntimeBuilder.VISIT);
    if (fg == null) {
        throw new ProvisioningDescriptionException("Failed to locate feature group '" + name + "' in " + (currentOrigin == null ? "the provisioning configuration" : currentOrigin.producer + " and its dependencies"));
    }
    return fg;
}
Also used : FeatureGroup(org.jboss.galleon.config.FeatureGroup) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException)

Aggregations

FeatureGroup (org.jboss.galleon.config.FeatureGroup)8 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)4 Map (java.util.Map)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 ProvisioningException (org.jboss.galleon.ProvisioningException)2 BufferedReader (java.io.BufferedReader)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 UnsatisfiedPackageDependencyException (org.jboss.galleon.UnsatisfiedPackageDependencyException)1 ConfigId (org.jboss.galleon.config.ConfigId)1 ConfigModel (org.jboss.galleon.config.ConfigModel)1 FeatureConfig (org.jboss.galleon.config.FeatureConfig)1 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)1 FeaturePackDepsConfig (org.jboss.galleon.config.FeaturePackDepsConfig)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