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);
}
}
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);
}
}
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;
}
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);
}
}
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));
}
Aggregations