Search in sources :

Example 11 with ProvisioningDescriptionException

use of org.jboss.galleon.ProvisioningDescriptionException in project galleon by wildfly.

the class ResolvedFeatureSpec method resolveIdFromForeignKey.

ResolvedFeatureId resolveIdFromForeignKey(ResolvedFeatureId parentId, String parentRef, Map<String, String> params) throws ProvisioningException {
    if (!xmlSpec.hasId()) {
        return null;
    }
    if (parentId == null) {
        final StringBuilder buf = new StringBuilder();
        buf.append("Failed to initialize foreign key parameters of ").append(id).append(": the referenced feature has not ID ");
        throw new ProvisioningException(buf.toString());
    }
    if (parentRef == null) {
        parentRef = parentId.specId.name;
    }
    final List<FeatureParameterSpec> idParamSpecs = xmlSpec.getIdParams();
    final Map<String, Object> resolvedParams = new HashMap<>(idParamSpecs.size());
    final FeatureReferenceSpec refSpec = xmlSpec.getFeatureRef(parentRef);
    try {
        if (refSpec.hasMappedParams()) {
            for (Map.Entry<String, String> mapping : refSpec.getMappedParams().entrySet()) {
                final FeatureParameterSpec param = xmlSpec.getParam(mapping.getKey());
                if (!param.isFeatureId()) {
                    continue;
                }
                final Object idValue = parentId.params.get(mapping.getValue());
                if (idValue == null) {
                    throw new ProvisioningDescriptionException(id + " expects ID parameter '" + mapping.getValue() + "' in " + parentId);
                }
                resolvedParams.put(mapping.getKey(), idValue);
            }
            for (FeatureParameterSpec idParamSpec : idParamSpecs) {
                String configValue = params.get(idParamSpec.getName());
                if (configValue != null) {
                    final Object childValue = paramFromString(idParamSpec.getName(), configValue);
                    final Object idValue = resolvedParams.put(idParamSpec.getName(), childValue);
                    if (idValue != null && !idValue.equals(childValue)) {
                        throw new ProvisioningDescriptionException(Errors.idParamForeignKeyInitConflict(id, idParamSpec.getName(), childValue, idValue));
                    }
                    continue;
                }
                if (resolvedParams.containsKey(idParamSpec.getName())) {
                    continue;
                }
                final Object childValue = getResolvedParam(idParamSpec.getName()).defaultValue;
                if (childValue == null) {
                    throw new ProvisioningDescriptionException(Errors.nonNillableParameterIsNull(id, idParamSpec.getName()));
                }
                resolvedParams.put(idParamSpec.getName(), childValue);
            }
        } else {
            for (FeatureParameterSpec idParamSpec : idParamSpecs) {
                final Object parentValue = parentId.params.get(idParamSpec.getName());
                String configValue = params.get(idParamSpec.getName());
                if (configValue != null) {
                    final Object childValue = paramFromString(idParamSpec.getName(), configValue);
                    if (parentValue != null && !parentValue.equals(childValue)) {
                        throw new ProvisioningDescriptionException(Errors.idParamForeignKeyInitConflict(id, idParamSpec.getName(), childValue, parentValue));
                    }
                    resolvedParams.put(idParamSpec.getName(), childValue);
                    continue;
                }
                if (parentValue != null) {
                    resolvedParams.put(idParamSpec.getName(), parentValue);
                    continue;
                }
                final Object childValue = getResolvedParam(idParamSpec.getName()).defaultValue;
                if (childValue == null) {
                    throw new ProvisioningDescriptionException(Errors.nonNillableParameterIsNull(id, idParamSpec.getName()));
                }
                resolvedParams.put(idParamSpec.getName(), childValue);
            }
        }
        return new ResolvedFeatureId(id, resolvedParams);
    } catch (ProvisioningException e) {
        final StringBuilder buf = new StringBuilder();
        buf.append("Failed to initialize foreign key parameters of ").append(id).append(" spec referencing feature ").append(parentId).append(" with parameters ");
        StringUtils.append(buf, params.entrySet());
        throw new ProvisioningException(Errors.failedToInitializeForeignKeyParams(id, parentId, params), e);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) FeatureReferenceSpec(org.jboss.galleon.spec.FeatureReferenceSpec) FeatureParameterSpec(org.jboss.galleon.spec.FeatureParameterSpec) ProvisioningException(org.jboss.galleon.ProvisioningException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 12 with ProvisioningDescriptionException

use of org.jboss.galleon.ProvisioningDescriptionException 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 13 with ProvisioningDescriptionException

use of org.jboss.galleon.ProvisioningDescriptionException in project galleon by wildfly.

the class PackageBuilder method build.

public PackageSpec build(Path fpDir) {
    final PackageSpec pkgSpec = pkg.build();
    final Path pkgDir;
    try {
        pkgDir = LayoutUtils.getPackageDir(fpDir, pkgSpec.getName(), false);
    } catch (ProvisioningDescriptionException e) {
        throw new IllegalStateException(e);
    }
    try {
        Files.createDirectories(pkgDir);
        if (tasks != null && !tasks.isEmpty()) {
            tasks.execute(FsTaskContext.builder().setTargetRoot(pkgDir).build());
        }
        PackageXmlWriter.getInstance().write(pkgSpec, pkgDir.resolve(Constants.PACKAGE_XML));
    } catch (XMLStreamException | IOException e) {
        throw new IllegalStateException(e);
    }
    return pkgSpec;
}
Also used : Path(java.nio.file.Path) XMLStreamException(javax.xml.stream.XMLStreamException) PackageSpec(org.jboss.galleon.spec.PackageSpec) IOException(java.io.IOException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException)

Example 14 with ProvisioningDescriptionException

use of org.jboss.galleon.ProvisioningDescriptionException in project galleon by wildfly.

the class FeaturePackRuntimeBuilder method getFeatureSpec.

public ResolvedFeatureSpec getFeatureSpec(String name) throws ProvisioningException {
    if (featureSpecs != null) {
        final ResolvedFeatureSpec resolvedSpec = featureSpecs.get(name);
        if (resolvedSpec != null) {
            return resolvedSpec;
        }
    }
    final Path specXml = dir.resolve(Constants.FEATURES).resolve(name).resolve(Constants.SPEC_XML);
    if (!Files.exists(specXml)) {
        return null;
    }
    try (BufferedReader reader = Files.newBufferedReader(specXml)) {
        final FeatureSpec xmlSpec = FeatureSpecXmlParser.getInstance().parse(reader);
        if (!xmlSpec.getName().equals(name)) {
            throw new ProvisioningDescriptionException("Feature-pack " + getFPID() + " feature spec " + xmlSpec.getName() + " does not match the requested feature spec name " + name);
        }
        final ResolvedFeatureSpec resolvedSpec = new ResolvedFeatureSpec(new ResolvedSpecId(producer, xmlSpec.getName()), featureParamTypeProvider, xmlSpec);
        if (featureSpecs == null) {
            featureSpecs = new HashMap<>();
        }
        featureSpecs.put(name, resolvedSpec);
        return resolvedSpec;
    } catch (Exception e) {
        throw new ProvisioningDescriptionException(Errors.parseXml(specXml), e);
    }
}
Also used : Path(java.nio.file.Path) FeatureSpec(org.jboss.galleon.spec.FeatureSpec) 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 15 with ProvisioningDescriptionException

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

Aggregations

ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)41 XMLStreamException (javax.xml.stream.XMLStreamException)19 Path (java.nio.file.Path)12 IOException (java.io.IOException)9 ProvisioningException (org.jboss.galleon.ProvisioningException)8 BufferedReader (java.io.BufferedReader)6 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)6 ProducerSpec (org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec)5 HashMap (java.util.HashMap)4 FeatureGroup (org.jboss.galleon.config.FeatureGroup)4 FeaturePackSpec (org.jboss.galleon.spec.FeaturePackSpec)4 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)4 UnsatisfiedPackageDependencyException (org.jboss.galleon.UnsatisfiedPackageDependencyException)3 ConfigId (org.jboss.galleon.config.ConfigId)3 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)3 Reader (java.io.Reader)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ConfigModel (org.jboss.galleon.config.ConfigModel)2 FeatureConfig (org.jboss.galleon.config.FeatureConfig)2