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