use of org.jboss.galleon.config.ConfigModel in project wildfly-maven-plugin by wildfly.
the class AbstractProvisionConfiguredMojoTestCase method checkStandaloneWildFlyHome.
public void checkStandaloneWildFlyHome(Path wildflyHome, int numDeployments, String[] layers, String[] excludedLayers, boolean stateRecorded, String... configTokens) throws Exception {
Assert.assertTrue(TestEnvironment.isValidWildFlyHome(wildflyHome));
if (numDeployments > 0) {
// Must retrieve all content directories.
Path rootDir = wildflyHome.resolve("standalone/data/content");
List<Path> deployments = new ArrayList<>();
Files.walkFileTree(rootDir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
if ("content".equals(file.getFileName().toString())) {
deployments.add(file);
}
return FileVisitResult.CONTINUE;
}
});
assertEquals(numDeployments, deployments.size());
} else {
// created.
if (Files.exists(wildflyHome.resolve("standalone/data/content"))) {
assertEquals(0, Files.list(wildflyHome.resolve("standalone/data/content")).count());
}
}
Path history = wildflyHome.resolve("standalone").resolve("configuration").resolve("standalone_xml_history");
assertFalse(Files.exists(history));
Path configFile = wildflyHome.resolve("standalone/configuration/standalone.xml");
assertTrue(Files.exists(configFile));
if (layers != null) {
Path provisioning = PathsUtils.getProvisioningXml(wildflyHome);
assertTrue(Files.exists(provisioning));
ProvisioningConfig config = ProvisioningXmlParser.parse(provisioning);
ConfigModel cm = config.getDefinedConfig(new ConfigId("standalone", "standalone.xml"));
assertNotNull(config.getDefinedConfigs().toString(), cm);
assertEquals(layers.length, cm.getIncludedLayers().size());
for (String layer : layers) {
assertTrue(cm.getIncludedLayers().contains(layer));
}
if (excludedLayers != null) {
for (String layer : excludedLayers) {
assertTrue(cm.getExcludedLayers().contains(layer));
}
}
}
if (configTokens != null) {
String str = new String(Files.readAllBytes(configFile), StandardCharsets.UTF_8);
for (String token : configTokens) {
assertTrue(str, str.contains(token));
}
}
assertEquals(Files.exists(wildflyHome.resolve(".galleon")), stateRecorded);
assertEquals(Files.exists(wildflyHome.resolve(".wildfly-maven-plugin-provisioning.xml")), !stateRecorded);
}
use of org.jboss.galleon.config.ConfigModel in project galleon by wildfly.
the class FeaturePackConfigXmlParsingTestCase method testSimple.
@Test
public void testSimple() throws Exception {
ConfigModel result = parseConfig("featurepack-config.xml");
Assert.assertNotNull(result);
assertEquals(ConfigModel.builder("standalone", "standalone.xml").addConfigItem(FeatureConfig.newConfig("server-root").setParam("name", "test")).build(), result);
}
use of org.jboss.galleon.config.ConfigModel 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.ConfigModel in project galleon by wildfly.
the class FeaturePackRuntimeBuilder method getConfig.
ConfigModel getConfig(ConfigId configId) throws ProvisioningException {
if (configs != null) {
final ConfigModel config = configs.get(configId);
if (config != null) {
return config;
}
}
final Path p = LayoutUtils.getConfigXml(dir, configId, false);
if (!Files.exists(p)) {
return null;
}
try (BufferedReader reader = Files.newBufferedReader(p)) {
final ConfigModel config = ConfigXmlParser.getInstance().parse(reader);
if (configs == null) {
configs = new HashMap<>();
}
configs.put(config.getId(), config);
return config;
} catch (Exception e) {
throw new ProvisioningException(Errors.parseXml(p), e);
}
}
use of org.jboss.galleon.config.ConfigModel in project galleon by wildfly.
the class ProvisioningRuntimeBuilder method collectDefaultConfigs.
private void collectDefaultConfigs() throws ProvisioningException {
if (config.hasDefinedConfigs()) {
for (ConfigModel config : config.getDefinedConfigs()) {
final ConfigId id = config.getId();
if (id.isModelOnly()) {
continue;
}
ConfigModelStack configStack = configsToBuild.get(id);
if (configStack == null) {
configStack = getConfigStack(id);
configsToBuild = CollectionUtils.putLinked(configsToBuild, id, configStack);
}
}
}
if (pushFpDepConfigs(config)) {
while (fpConfigStack.hasNext()) {
collectDefaultConfigs(fpConfigStack.next());
}
fpConfigStack.popLevel();
}
}
Aggregations