Search in sources :

Example 21 with ProvisioningConfig

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

the class PluginOptionsTestCase method test.

@Test
public void test() throws Exception {
    CliTestUtils.install(cli, universeSpec, PRODUCER1, "1.0.0.Alpha1", PluginTest.class);
    CliTestUtils.install(cli, universeSpec, PRODUCER2, "1.0.0.Alpha1", PluginTest.class);
    Path p = cli.newDir("install", false);
    // Invalid option
    try {
        cli.execute("install " + CliTestUtils.buildFPL(universeSpec, PRODUCER1, "1", "alpha", "1.0.0.Alpha1") + " --dir=" + p + " --foo");
        throw new Exception("Should have failed, --foo beeing unknown");
    } catch (CommandException ex) {
    // XXX OK.
    }
    // missing required option
    try {
        cli.execute("install " + CliTestUtils.buildFPL(universeSpec, PRODUCER1, "1", "alpha", "1.0.0.Alpha1") + " --dir=" + p);
        throw new Exception("Should have failed, --opt1-req is required.");
    } catch (CommandException ex) {
    // XXX OK.
    }
    // successfull installation
    cli.execute("install " + CliTestUtils.buildFPL(universeSpec, PRODUCER1, "1", "alpha", "1.0.0.Alpha1") + " --dir=" + p + " --" + PluginTest.OPT1_REQUIRED + "=XXX");
    cli.execute("install " + CliTestUtils.buildFPL(universeSpec, PRODUCER2, "1", "alpha", "1.0.0.Alpha1") + " --dir=" + p + " --" + PluginTest.OPT1_REQUIRED + "=XXX");
    final Path provisioningXml = cli.newDir("workdir", true).resolve("provisioning.xml");
    try (BufferedWriter writer = Files.newBufferedWriter(provisioningXml)) {
        final ProvisioningConfig config = ProvisioningConfig.builder().addFeaturePackDep(CliTestUtils.buildFPL(universeSpec, PRODUCER1, "1", "alpha", "1.0.0.Alpha1")).addFeaturePackDep(CliTestUtils.buildFPL(universeSpec, PRODUCER2, "1", "alpha", "1.0.0.Alpha1")).build();
        ProvisioningXmlWriter.getInstance().write(config, writer);
    }
    // PROVISION command
    Path target = cli.newDir("target", false);
    // Invalid option
    try {
        cli.execute("provision " + provisioningXml + " --dir=" + target + " --foo");
        throw new Exception("Should have failed, --foo beeing unknown");
    } catch (CommandException ex) {
    // XXX OK.
    }
    // missing required option
    try {
        cli.execute("provision " + provisioningXml + " --dir=" + target);
        throw new Exception("Should have failed, --opt1-req is required.");
    } catch (CommandException ex) {
    // XXX OK.
    }
    // successfull provisioning
    cli.execute("provision " + provisioningXml + " --dir=" + target + " --" + PluginTest.OPT1_REQUIRED + "=XXX");
    // UNINSTALL command, remaining PRODUCER2 expects some options.
    try {
        cli.execute("uninstall " + CliTestUtils.buildFPL(universeSpec, PRODUCER1, "1", "alpha", "1.0.0.Alpha1") + " --dir=" + p + " --foo");
        throw new Exception("Should have failed, --foo beeing unknown");
    } catch (CommandException ex) {
    // XXX OK.
    }
    // the required option has been persisted and does not have to be explicitly provided by the user
    cli.execute("uninstall " + CliTestUtils.buildFPL(universeSpec, PRODUCER1, "1", "alpha", "1.0.0.Alpha1") + " --dir=" + p);
}
Also used : Path(java.nio.file.Path) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) CommandException(org.aesh.command.CommandException) CommandException(org.aesh.command.CommandException) ProvisioningException(org.jboss.galleon.ProvisioningException) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 22 with ProvisioningConfig

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

the class StateTestCase method testTransitiveWithVersion.

@Test
public void testTransitiveWithVersion() throws Exception {
    ProvisioningConfig config = ProvisioningConfig.builder().addFeaturePackDep(locWithTransitive).addTransitiveDep(transitive).build();
    Path p = cli.newDir("version_transitive", false);
    // Provision a config with a transitive with version set.
    ProvisioningManager mgr1 = cli.getSession().newProvisioningManager(p, true);
    mgr1.provision(config);
    cli.execute("state edit " + p.toFile().getAbsolutePath());
    try {
        cli.execute("get-info --type=optional-packages");
        Assert.assertTrue(cli.getOutput(), cli.getOutput().contains("p1"));
        Assert.assertTrue(cli.getOutput(), cli.getOutput().contains(PRODUCER3));
        cli.execute("exclude-package " + transitive.getProducer() + "/p1");
        cli.execute("get-info --type=optional-packages");
        Assert.assertFalse(cli.getOutput(), cli.getOutput().contains("p1"));
        Assert.assertFalse(cli.getOutput(), cli.getOutput().contains(PRODUCER3));
        cli.execute("undo");
        // Check that we still have the transitive dep.
        ProvisioningManager mgr2 = ProvisioningManager.builder().setInstallationHome(p).build();
        Assert.assertTrue(mgr2.getProvisioningConfig().getTransitiveDeps().size() == 1);
        Assert.assertTrue(mgr2.getProvisioningConfig().getTransitiveDeps().iterator().next().getExcludedPackages().isEmpty());
    } finally {
        cli.execute("leave-state");
    }
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) Path(java.nio.file.Path) ProvisioningManager(org.jboss.galleon.ProvisioningManager) Test(org.junit.Test)

Example 23 with ProvisioningConfig

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

the class LayoutTestBase method main.

@Test
public void main() throws Exception {
    try (ProvisioningLayout<FeaturePackLayout> layout = buildLayout()) {
        if (pmErrors() != null) {
            Assert.fail("Errors expected");
        }
        assertLayout(layout);
        final ProvisioningConfig expectedConfig = expectedLayoutConfig();
        if (expectedConfig == null) {
            assertLayoutConfig(layout.getConfig());
        } else {
            assertEquals(expectedConfig, layout.getConfig());
        }
    } catch (ProvisioningException e) {
        final String[] errors = pmErrors();
        if (errors == null) {
            throw e;
        }
        Throwable t = e;
        int i = 0;
        while (t != null) {
            if (i == errors.length) {
                Assert.fail("There are more error messages than expected");
            }
            assertEquals(errors[i++], t.getMessage());
            t = e.getCause();
        }
    }
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ProvisioningException(org.jboss.galleon.ProvisioningException) Test(org.junit.Test)

Example 24 with ProvisioningConfig

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

the class AbstractFPProvisionedCommand method getProvisionedFP.

public FeaturePackConfig getProvisionedFP(PmSession session) throws CommandExecutionException {
    ProducerSpec producer = getProducer(session);
    if (producer == null) {
        return null;
    }
    ProvisioningConfig config = session.getState().getConfig();
    for (FeaturePackConfig dep : config.getFeaturePackDeps()) {
        if (dep.getLocation().getProducer().equals(producer)) {
            return dep;
        }
    }
    for (FeaturePackConfig dep : config.getTransitiveDeps()) {
        if (dep.getLocation().getProducer().equals(producer)) {
            return dep;
        }
    }
    return null;
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ProducerSpec(org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 25 with ProvisioningConfig

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

the class UpdateCommand method getDynamicOptions.

@Override
protected List<DynamicOption> getDynamicOptions(State state) throws Exception {
    String targetDirArg = (String) getValue(DIR_OPTION_NAME);
    if (targetDirArg == null) {
        // Check in argument or option, that is the option completion case.
        targetDirArg = getOptionValue(DIR_OPTION_NAME);
    }
    Path installation = getAbsolutePath(targetDirArg, pmSession.getAeshContext());
    ProvisioningConfig config = pmSession.newProvisioningManager(installation, false).getProvisioningConfig();
    Set<ProvisioningOption> opts = pmSession.getResolver().get(null, PluginResolver.newResolver(pmSession, config)).getDiff();
    List<DynamicOption> options = new ArrayList<>();
    for (ProvisioningOption opt : opts) {
        DynamicOption dynOption = new DynamicOption(opt.getName(), opt.isRequired());
        options.add(dynOption);
    }
    return options;
}
Also used : Path(java.nio.file.Path) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ProvisioningOption(org.jboss.galleon.ProvisioningOption) ArrayList(java.util.ArrayList)

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