Search in sources :

Example 1 with ConfigModel

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);
}
Also used : Path(java.nio.file.Path) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ConfigModel(org.jboss.galleon.config.ConfigModel) ArrayList(java.util.ArrayList) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) ConfigId(org.jboss.galleon.config.ConfigId) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 2 with ConfigModel

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);
}
Also used : ConfigModel(org.jboss.galleon.config.ConfigModel) Test(org.junit.Test)

Example 3 with ConfigModel

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);
    }
}
Also used : Path(java.nio.file.Path) FeatureSpec(org.jboss.galleon.spec.FeatureSpec) FeatureGroup(org.jboss.galleon.config.FeatureGroup) ConfigLayerSpec(org.jboss.galleon.spec.ConfigLayerSpec) FeaturePackXmlWriter(org.jboss.galleon.xml.FeaturePackXmlWriter) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) IOException(java.io.IOException) ProvisioningException(org.jboss.galleon.ProvisioningException) ConfigModel(org.jboss.galleon.config.ConfigModel) PackageSpec(org.jboss.galleon.spec.PackageSpec) ProvisioningException(org.jboss.galleon.ProvisioningException) FeaturePackSpec(org.jboss.galleon.spec.FeaturePackSpec) FeatureSpecXmlWriter(org.jboss.galleon.xml.FeatureSpecXmlWriter) ConfigId(org.jboss.galleon.config.ConfigId) FeatureGroupXmlWriter(org.jboss.galleon.xml.FeatureGroupXmlWriter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with ConfigModel

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);
    }
}
Also used : Path(java.nio.file.Path) ConfigModel(org.jboss.galleon.config.ConfigModel) ProvisioningException(org.jboss.galleon.ProvisioningException) BufferedReader(java.io.BufferedReader) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) XMLStreamException(javax.xml.stream.XMLStreamException) UnsatisfiedPackageDependencyException(org.jboss.galleon.UnsatisfiedPackageDependencyException) IOException(java.io.IOException) ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 5 with ConfigModel

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();
    }
}
Also used : ConfigModel(org.jboss.galleon.config.ConfigModel) ConfigId(org.jboss.galleon.config.ConfigId)

Aggregations

ConfigModel (org.jboss.galleon.config.ConfigModel)18 ConfigId (org.jboss.galleon.config.ConfigId)12 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 Map (java.util.Map)4 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)4 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)4 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)3 ProvisioningException (org.jboss.galleon.ProvisioningException)3 BufferedReader (java.io.BufferedReader)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 FeaturePackSpec (org.jboss.galleon.spec.FeaturePackSpec)2 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)2 Test (org.junit.Test)2 FileVisitResult (java.nio.file.FileVisitResult)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1