use of org.jboss.galleon.spec.FeaturePackSpec 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.FeaturePackSpec in project galleon by wildfly.
the class ProvisioningRuntimeBuilder method collectDefaultConfigs.
private void collectDefaultConfigs(FeaturePackConfig fpConfig) throws ProvisioningException {
thisOrigin = layout.getFeaturePack(fpConfig.getLocation().getProducer());
final FeaturePackRuntimeBuilder parentFp = setOrigin(thisOrigin);
try {
if (fpConfig.hasDefinedConfigs()) {
for (ConfigModel config : fpConfig.getDefinedConfigs()) {
final ConfigId id = config.getId();
if (id.isModelOnly() || fpConfigStack.isFilteredOut(thisOrigin.producer, id, true)) {
continue;
}
ConfigModelStack configStack = configsToBuild.get(id);
if (configStack == null) {
configStack = getConfigStack(id);
configsToBuild = CollectionUtils.putLinked(configsToBuild, id, configStack);
}
}
}
if (!fpConfig.isTransitive()) {
if (fpConfig.hasIncludedConfigs()) {
for (ConfigId id : fpConfig.getIncludedConfigs()) {
collectConfigIfNotFiltered(thisOrigin.producer, id);
}
}
final FeaturePackSpec currentSpec = currentOrigin.getSpec();
if (currentSpec.hasDefinedConfigs()) {
for (ConfigModel config : currentSpec.getDefinedConfigs()) {
collectConfigIfNotFiltered(thisOrigin.producer, config.getId());
}
}
if (currentSpec.hasFeaturePackDeps()) {
boolean extendedStackLevel = false;
if (currentSpec.hasTransitiveDeps()) {
for (FeaturePackConfig fpDep : currentSpec.getTransitiveDeps()) {
extendedStackLevel |= fpConfigStack.push(fpDep, extendedStackLevel);
}
}
for (FeaturePackConfig fpDep : currentSpec.getFeaturePackDeps()) {
extendedStackLevel |= fpConfigStack.push(fpDep, extendedStackLevel);
}
if (extendedStackLevel) {
while (fpConfigStack.hasNext()) {
collectDefaultConfigs(fpConfigStack.next());
}
}
if (extendedStackLevel) {
fpConfigStack.popLevel();
}
}
}
} finally {
this.thisOrigin = parentFp;
setOrigin(parentFp);
}
}
Aggregations