Search in sources :

Example 31 with ProvisioningConfig

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

the class AbstractInstallationCommand method getFeatureContainer.

public FeatureContainer getFeatureContainer(PmSession session, ProvisioningLayout<FeaturePackLayout> layout) throws ProvisioningException, CommandExecutionException, IOException {
    FeatureContainer container;
    ProvisioningManager manager = getManager(session);
    if (manager.getProvisionedState() == null) {
        throw new CommandExecutionException("Specified directory doesn't contain an installation");
    }
    if (layout == null) {
        ProvisioningConfig config = manager.getProvisioningConfig();
        try (ProvisioningRuntime runtime = manager.getRuntime(config)) {
            container = FeatureContainers.fromProvisioningRuntime(session, runtime);
        }
    } else {
        try (ProvisioningRuntime runtime = manager.getRuntime(layout)) {
            container = FeatureContainers.fromProvisioningRuntime(session, runtime);
        }
    }
    return container;
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ProvisioningManager(org.jboss.galleon.ProvisioningManager) ProvisioningRuntime(org.jboss.galleon.runtime.ProvisioningRuntime) FeatureContainer(org.jboss.galleon.cli.model.FeatureContainer) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException)

Example 32 with ProvisioningConfig

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

the class StateExportCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
    if (file != null) {
        final Path targetFile = file.toPath();
        State session = invoc.getPmSession().getState();
        try {
            session.export(targetFile);
        } catch (Exception ex) {
            throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), ex);
        }
        invoc.println("Provisioning file generated in " + targetFile);
    } else {
        ByteArrayOutputStream output = null;
        try {
            ProvisioningConfig config = invoc.getPmSession().getState().getConfig();
            output = new ByteArrayOutputStream();
            PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8));
            ProvisioningXmlWriter.getInstance().write(config, writer);
        } catch (Exception e) {
            throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e);
        }
        try {
            invoc.println(output.toString(StandardCharsets.UTF_8.name()));
        } catch (UnsupportedEncodingException e) {
            throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e);
        }
    }
}
Also used : Path(java.nio.file.Path) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) State(org.jboss.galleon.cli.model.state.State) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PrintWriter(java.io.PrintWriter)

Example 33 with ProvisioningConfig

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

the class StateGetInfoCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
    try {
        ProvisioningConfig config = invoc.getPmSession().getContainer().getProvisioningConfig();
        Function<ProvisioningLayout<FeaturePackLayout>, FeatureContainer> supplier = new Function<ProvisioningLayout<FeaturePackLayout>, FeatureContainer>() {

            public FeatureContainer apply(ProvisioningLayout<FeaturePackLayout> layout) {
                return invoc.getPmSession().getState().getContainer();
            }
        };
        StateInfoUtil.displayInfo(invoc, null, config, type, supplier);
    } catch (Exception ex) {
        throw new CommandExecutionException(invoc.getPmSession(), CliErrors.infoFailed(), ex);
    }
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) Function(java.util.function.Function) FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) FeatureContainer(org.jboss.galleon.cli.model.FeatureContainer) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) ProvisioningLayout(org.jboss.galleon.layout.ProvisioningLayout) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException)

Example 34 with ProvisioningConfig

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

the class UninstallCommand method getDynamicOptions.

@Override
protected List<DynamicOption> getDynamicOptions(State state) throws Exception {
    String fpid = getFPID();
    Path dir = getAbsolutePath(getUninstallDir(), pmSession.getAeshContext());
    // Build layout from this directory.
    ProvisioningConfig config = ProvisioningXmlParser.parse(PathsUtils.getProvisioningXml(dir));
    if (config != null) {
        // Silent resolution.
        pmSession.unregisterTrackers();
        try {
            try (ProvisioningLayout<FeaturePackLayout> layout = pmSession.getLayoutFactory().newConfigLayout(config)) {
                layout.uninstall(pmSession.getResolvedLocation(getInstallationDirectory(pmSession.getAeshContext()), fpid).getFPID());
                Set<ProvisioningOption> opts = PluginResolver.newResolver(pmSession, layout).resolve().getInstall();
                List<DynamicOption> options = new ArrayList<>();
                for (ProvisioningOption opt : opts) {
                    DynamicOption dynOption = new DynamicOption(opt.getName(), opt.isRequired());
                    options.add(dynOption);
                }
                return options;
            }
        } finally {
            pmSession.registerTrackers();
        }
    } else {
        return Collections.emptyList();
    }
}
Also used : Path(java.nio.file.Path) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) ProvisioningOption(org.jboss.galleon.ProvisioningOption) ArrayList(java.util.ArrayList)

Example 35 with ProvisioningConfig

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

the class ProvisioningXmlParserTestCase method readValid.

@Test
public void readValid() throws Exception {
    ProvisioningConfig found = validator.validateAndParse("xml/provisioning/provisioning.xml", null, null);
    ProvisioningConfig expected = ProvisioningConfig.builder().addUniverse("universe1", "factory1", "location1").addUniverse(null, "factory2", "location2").addUniverse("universe3", "factory3", "location3").addFeaturePackDep(FeaturePackConfig.forTransitiveDep(FeaturePackLocation.fromString("fp4@maven(universe):0#0.0.4"))).addFeaturePackDep(FeaturePackConfig.forTransitiveDep(FeaturePackLocation.fromString("fp5@maven(universe):0#0.0.5"))).addFeaturePackDep(FeaturePackLocation.fromString("fp1@maven(universe):0#0.0.1")).addFeaturePackDep(FeaturePackLocation.fromString("fp2@maven(universe):0#0.0.2")).addFeaturePackDep(FeaturePackLocation.fromString("fp3@maven(universe):0#0.0.3")).setInheritConfigs(false).setInheritModelOnlyConfigs(false).includeDefaultConfig("model1", "name1").includeDefaultConfig(null, "name2").excludeDefaultConfig("model1", "name2").excludeDefaultConfig(null, "name1").addOption("name1", "value1").addOption("name2", "value2").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