Search in sources :

Example 1 with ProvisioningConfig

use of org.jboss.galleon.config.ProvisioningConfig in project wildfly-maven-plugin by wildfly.

the class AbstractProvisionServerMojo method provisionServer.

private void provisionServer(Path home) throws ProvisioningException, MojoExecutionException, IOException, XMLStreamException {
    try (ProvisioningManager pm = ProvisioningManager.builder().addArtifactResolver(artifactResolver).setInstallationHome(home).setMessageWriter(new MvnMessageWriter(getLog())).setLogTime(logProvisioningTime).setRecordState(recordProvisioningState).build()) {
        ProvisioningConfig config = null;
        Path resolvedProvisioningFile = resolvePath(project, provisioningFile.toPath());
        boolean provisioningFileExists = Files.exists(resolvedProvisioningFile);
        if (featurePacks.isEmpty()) {
            if (provisioningFileExists) {
                getLog().info("Provisioning server using " + resolvedProvisioningFile + " file.");
                config = GalleonUtils.buildConfig(resolvedProvisioningFile);
            } else {
                config = getDefaultConfig();
                if (config == null) {
                    throw new MojoExecutionException("No feature-pack has been configured, can't provision a server.");
                }
            }
        } else {
            if (provisioningFileExists) {
                getLog().warn("Galleon provisioning file " + provisioningFile + " is ignored, plugin configuration is used.");
            }
            if (layers.isEmpty() && !STANDALONE_XML.equals(layersConfigurationFileName)) {
                throw new MojoExecutionException("layers-configuration-file-name has been set although no layers are defined.");
            }
            config = GalleonUtils.buildConfig(pm, featurePacks, layers, excludedLayers, galleonOptions, layersConfigurationFileName);
        }
        getLog().info("Provisioning server in " + home);
        pm.provision(config);
        // Check that at least the standalone or domain directories have been generated.
        if (!Files.exists(home.resolve("standalone")) && !Files.exists(home.resolve("domain"))) {
            getLog().error("Invalid galleon provisioning, no server provisioned in " + home + ". Make sure " + "that the list of Galleon feature-packs and Galleon layers are properly configured.");
            throw new MojoExecutionException("Invalid plugin configuration, no server provisioned.");
        }
        if (!recordProvisioningState) {
            Path file = home.resolve(PLUGIN_PROVISIONING_FILE);
            try (FileWriter writer = new FileWriter(file.toFile())) {
                ProvisioningXmlWriter.getInstance().write(config, writer);
            }
        }
    }
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) Path(java.nio.file.Path) ProvisioningManager(org.jboss.galleon.ProvisioningManager) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MvnMessageWriter(org.jboss.galleon.maven.plugin.util.MvnMessageWriter) FileWriter(java.io.FileWriter)

Example 2 with ProvisioningConfig

use of org.jboss.galleon.config.ProvisioningConfig 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 3 with ProvisioningConfig

use of org.jboss.galleon.config.ProvisioningConfig in project wildfly-maven-plugin by wildfly.

the class GalleonUtils method buildConfig.

/**
 * Build a Galleon provisioning configuration.
 *
 * @param pm The Galleon provisioning runtime.
 * @param featurePacks The list of feature-packs.
 * @param layers Layers to include.
 * @param excludedLayers Layers to exclude.
 * @param pluginOptions Galleon plugin options.
 * @param layersConfigFileName The name of the configuration generated from layers
 * @return The provisioning config.
 * @throws ProvisioningException
 */
public static ProvisioningConfig buildConfig(ProvisioningManager pm, List<FeaturePack> featurePacks, List<String> layers, List<String> excludedLayers, Map<String, String> pluginOptions, String layersConfigFileName) throws ProvisioningException, IllegalArgumentException {
    final ProvisioningConfig.Builder state = ProvisioningConfig.builder();
    boolean hasLayers = !layers.isEmpty();
    boolean fpWithDefaults = true;
    if (!hasLayers) {
        // Check we have all feature-packs with default values only.
        for (FeaturePack fp : featurePacks) {
            if (fp.isInheritConfigs() != null || fp.isInheritPackages() != null || !fp.getIncludedConfigs().isEmpty() || !fp.getExcludedConfigs().isEmpty() || fp.isTransitive() || !fp.getExcludedPackages().isEmpty() || !fp.getIncludedPackages().isEmpty()) {
                fpWithDefaults = false;
                break;
            }
        }
    }
    for (FeaturePack fp : featurePacks) {
        if (fp.getLocation() == null && (fp.getGroupId() == null || fp.getArtifactId() == null) && fp.getNormalizedPath() == null) {
            throw new IllegalArgumentException("Feature-pack location, Maven GAV or feature pack path is missing");
        }
        final FeaturePackLocation fpl;
        if (fp.getNormalizedPath() != null) {
            fpl = pm.getLayoutFactory().addLocal(fp.getNormalizedPath(), false);
        } else if (fp.getGroupId() != null && fp.getArtifactId() != null) {
            String coords = getMavenCoords(fp);
            fpl = FeaturePackLocation.fromString(coords);
        } else {
            fpl = FeaturePackLocation.fromString(fp.getLocation());
        }
        final FeaturePackConfig.Builder fpConfig = fp.isTransitive() ? FeaturePackConfig.transitiveBuilder(fpl) : FeaturePackConfig.builder(fpl);
        if (fp.isInheritConfigs() == null) {
            if (hasLayers) {
                fpConfig.setInheritConfigs(false);
            } else {
                if (fpWithDefaults) {
                    fpConfig.setInheritConfigs(true);
                }
            }
        } else {
            fpConfig.setInheritConfigs(fp.isInheritConfigs());
        }
        if (fp.isInheritPackages() == null) {
            if (hasLayers) {
                fpConfig.setInheritPackages(false);
            } else {
                if (fpWithDefaults) {
                    fpConfig.setInheritConfigs(true);
                }
            }
        } else {
            fpConfig.setInheritPackages(fp.isInheritPackages());
        }
        if (!fp.getExcludedConfigs().isEmpty()) {
            for (ConfigurationId configId : fp.getExcludedConfigs()) {
                if (configId.isModelOnly()) {
                    fpConfig.excludeConfigModel(configId.getId().getModel());
                } else {
                    fpConfig.excludeDefaultConfig(configId.getId());
                }
            }
        }
        if (!fp.getIncludedConfigs().isEmpty()) {
            for (ConfigurationId configId : fp.getIncludedConfigs()) {
                if (configId.isModelOnly()) {
                    fpConfig.includeConfigModel(configId.getId().getModel());
                } else {
                    fpConfig.includeDefaultConfig(configId.getId());
                }
            }
        }
        if (!fp.getIncludedPackages().isEmpty()) {
            for (String includedPackage : fp.getIncludedPackages()) {
                fpConfig.includePackage(includedPackage);
            }
        }
        if (!fp.getExcludedPackages().isEmpty()) {
            for (String excludedPackage : fp.getExcludedPackages()) {
                fpConfig.excludePackage(excludedPackage);
            }
        }
        state.addFeaturePackDep(fpConfig.build());
    }
    if (!layers.isEmpty()) {
        ConfigModel.Builder configBuilder = ConfigModel.builder(STANDALONE, layersConfigFileName);
        for (String layer : layers) {
            configBuilder.includeLayer(layer);
        }
        for (String layer : excludedLayers) {
            configBuilder.excludeLayer(layer);
        }
        state.addConfig(configBuilder.build());
        if (pluginOptions.isEmpty()) {
            pluginOptions = Collections.singletonMap(Constants.OPTIONAL_PACKAGES, Constants.PASSIVE_PLUS);
        } else if (!pluginOptions.containsKey(Constants.OPTIONAL_PACKAGES)) {
            pluginOptions.put(Constants.OPTIONAL_PACKAGES, Constants.PASSIVE_PLUS);
        }
    }
    state.addOptions(pluginOptions);
    return state.build();
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ConfigModel(org.jboss.galleon.config.ConfigModel) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 4 with ProvisioningConfig

use of org.jboss.galleon.config.ProvisioningConfig in project galleon by wildfly.

the class CliTestUtils method installAndCheck.

public static Path installAndCheck(CliWrapper cli, String dirName, FeaturePackLocation toInstall, FeaturePackLocation expected) throws Exception {
    Path dir = cli.newDir(dirName, false);
    cli.execute("install " + toInstall + " --dir=" + dir.toString());
    Assert.assertTrue(dir.toFile().exists());
    ProvisioningConfig config = CliTestUtils.getConfig(dir);
    FeaturePackConfig cf = config.getFeaturePackDep(toInstall.getProducer());
    Assert.assertEquals(cf.getLocation().toString(), expected, cf.getLocation());
    return dir;
}
Also used : Path(java.nio.file.Path) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 5 with ProvisioningConfig

use of org.jboss.galleon.config.ProvisioningConfig in project galleon by wildfly.

the class ProvisioningXmlExcludesIncludesTestCase method readExcludes.

@Test
public void readExcludes() throws Exception {
    ProvisioningConfig found = validator.validateAndParse("xml/provisioning/exclude-package.xml");
    ProvisioningConfig expected = ProvisioningConfig.builder().addFeaturePackDep(FeaturePackConfig.builder(FeaturePackLocation.fromString("fp1@maven(universe):0#0.0.1")).excludePackage("p1").build()).addFeaturePackDep(FeaturePackConfig.builder(FeaturePackLocation.fromString("fp2@maven(universe):0#0.0.2")).excludePackage("p2").excludePackage("p3").build()).addFeaturePackDep(FeaturePackConfig.forLocation(FeaturePackLocation.fromString("fp3@maven(universe):0#0.0.3"))).build();
    Assert.assertEquals(expected, found);
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) Test(org.junit.Test)

Aggregations

ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)47 Test (org.junit.Test)16 Path (java.nio.file.Path)15 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)12 ProvisioningException (org.jboss.galleon.ProvisioningException)10 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)6 ProvisioningManager (org.jboss.galleon.ProvisioningManager)6 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)6 ConfigId (org.jboss.galleon.config.ConfigId)6 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)6 CommandException (org.aesh.command.CommandException)5 ConfigModel (org.jboss.galleon.config.ConfigModel)5 HashMap (java.util.HashMap)4 FeaturePackLayout (org.jboss.galleon.layout.FeaturePackLayout)4 FeaturePackRuntimeBuilder (org.jboss.galleon.runtime.FeaturePackRuntimeBuilder)4 ProvisioningRuntime (org.jboss.galleon.runtime.ProvisioningRuntime)4 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)4 UniverseSpec (org.jboss.galleon.universe.UniverseSpec)4 HashSet (java.util.HashSet)3