use of org.jboss.galleon.spec.ConfigLayerSpec 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.spec.ConfigLayerSpec in project galleon by wildfly.
the class FeaturePackRuntimeBuilder method getConfigLayer.
ConfigLayerSpec getConfigLayer(ConfigId configId) throws ProvisioningException {
if (layers != null) {
final ConfigLayerSpec layer = layers.get(configId);
if (layer != null) {
return layer;
}
}
final Path p = LayoutUtils.getLayerSpecXml(dir, configId.getModel(), configId.getName(), false);
if (!Files.exists(p)) {
return null;
}
final ConfigLayerSpec layer = XmlParsers.parseConfigLayerSpec(p, configId.getModel());
if (layers == null) {
layers = new HashMap<>();
}
layers.put(configId, layer);
return layer;
}
use of org.jboss.galleon.spec.ConfigLayerSpec in project galleon by wildfly.
the class ProvisioningRuntimeBuilder method resolveConfigLayer.
private boolean resolveConfigLayer(ProducerSpec producer, ConfigModelStack layerStack, ConfigId layerId) throws ProvisioningException {
final FeaturePackRuntimeBuilder fp = layout.getFeaturePack(producer);
if (!setFlag(fp, FeaturePackRuntimeBuilder.RESOLVE_LAYER)) {
return fp.getConfigLayer(layerId) != null;
}
final FeaturePackRuntimeBuilder prevOrigin = currentOrigin;
try {
boolean resolved;
final ConfigLayerSpec configLayer = fp.getConfigLayer(layerId);
resolved = configLayer != null;
if (resolved) {
layerStack.pushGroup(configLayer);
}
if (fp.getSpec().hasFeaturePackDeps()) {
for (FeaturePackConfig depConfig : fp.getSpec().getFeaturePackDeps()) {
resolved |= resolveConfigLayer(depConfig.getLocation().getProducer(), layerStack, layerId);
}
}
if (configLayer != null) {
setOrigin(fp);
processConfigLayer(layerStack, popLayer(layerStack));
}
return resolved;
} finally {
setOrigin(prevOrigin);
}
}
use of org.jboss.galleon.spec.ConfigLayerSpec in project galleon by wildfly.
the class ProvisioningRuntimeBuilder method popLayer.
private FeatureGroupSupport popLayer(ConfigModelStack layerStack) throws ProvisioningException {
final FeatureGroupSupport fg = layerStack.peekAtGroup();
if (!(fg instanceof ConfigLayerSpec)) {
throw new ProvisioningException("Expected config layer but got " + fg);
}
final ConfigLayerSpec layer = (ConfigLayerSpec) fg;
if (layer.hasLayerDeps()) {
for (ConfigLayerDependency dep : layer.getLayerDeps()) {
layerStack.addLayerDep(dep);
}
}
layerStack.popGroup();
return fg;
}
use of org.jboss.galleon.spec.ConfigLayerSpec in project galleon by wildfly.
the class LayersConfigBuilder method getAllLayers.
private static Map<String, Map<String, Set<String>>> getAllLayers(ProvisioningLayout<FeaturePackLayout> pLayout, boolean includeDependencies) throws ProvisioningException, IOException {
Map<String, Map<String, Set<String>>> layersMap = new HashMap<>();
for (FeaturePackLayout fp : pLayout.getOrderedFeaturePacks()) {
for (ConfigId layer : fp.loadLayers()) {
String model = layer.getModel();
Map<String, Set<String>> names = layersMap.get(model);
if (names == null) {
names = new HashMap<>();
layersMap.put(model, names);
}
Set<String> dependencies = new TreeSet<>();
if (includeDependencies) {
ConfigLayerSpec spec = fp.loadConfigLayerSpec(model, layer.getName());
for (ConfigLayerDependency dep : spec.getLayerDeps()) {
dependencies.add(dep.getName());
}
}
// Case where a layer is redefined in multiple FP. Add all deps.
Set<String> existingDependencies = names.get(layer.getName());
if (existingDependencies != null) {
existingDependencies.addAll(dependencies);
dependencies = existingDependencies;
}
names.put(layer.getName(), dependencies);
}
}
return layersMap;
}
Aggregations