Java Code Examples for org.jboss.forge.addon.ui.controller.CommandController#initialize()

The following examples show how to use org.jboss.forge.addon.ui.controller.CommandController#initialize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NewComponentInstanceTest.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Test
public void testSomething() throws Exception {
    File tempDir = OperatingSystemUtils.createTempDir();
    try {
        Project project = projectFactory.createTempProject();
        Assert.assertNotNull("Should have created a project", project);

        CommandController command = testHarness.createCommandController(CamelSetupCommand.class, project.getRoot());
        command.initialize();
        command.setValueFor("kind", "camel-spring");

        Result result = command.execute();
        Assert.assertFalse("Should setup Camel in the project", result instanceof Failed);

        command = testHarness.createCommandController(CamelGetComponentsCommand.class, project.getRoot());
        command.initialize();

        result = command.execute();
        Assert.assertFalse("Should not fail", result instanceof Failed);

        String message = result.getMessage();
        System.out.println(message);
    } finally {
        tempDir.delete();
    }
}
 
Example 2
Source File: NewNodeXmlTest.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
protected void testDeleteRoute(Project project) throws Exception {
    String key = "_camelContext1/cbr-route/_choice1/_when1/_to1";
    CommandController command = testHarness.createCommandController(CamelDeleteNodeXmlCommand.class, project.getRoot());
    command.initialize();
    command.setValueFor("xml", "META-INF/spring/camel-context.xml");

    setNodeValue(key, command);

    assertValidAndExecutes(command);

    List<ContextDto> contexts = getRoutesXml(project);
    assertFalse("Should have loaded a camelContext", contexts.isEmpty());

    assertNoNodeWithKey(contexts, key);
    assertNodeWithKey(contexts, NEW_ROUTE_KEY);
}
 
Example 3
Source File: NewNodeXmlTest.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
protected List<ContextDto> getRoutesXml(Project project) throws Exception {
    CommandController command = testHarness.createCommandController(CamelGetRoutesXmlCommand.class, project.getRoot());
    command.initialize();
    command.setValueFor("format", "JSON");

    Result result = command.execute();
    assertFalse("Should not fail", result instanceof Failed);

    String message = result.getMessage();

    System.out.println();
    System.out.println();
    System.out.println("JSON: " + message);
    System.out.println();

    List<ContextDto> answer = NodeDtos.parseContexts(message);
    System.out.println();
    System.out.println();
    List<NodeDto> nodeList = NodeDtos.toNodeList(answer);
    for (NodeDto node : nodeList) {
        System.out.println(node.getLabel());
    }
    System.out.println();
    return answer;
}
 
Example 4
Source File: WindupCommandTest.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
private void setupController(CommandController controller, File inputFile, File outputFile) throws Exception
{
    controller.initialize();
    Assert.assertTrue(controller.isEnabled());
    controller.setValueFor(InputPathOption.NAME, Collections.singletonList(inputFile)); // FORGE-2524
    final Object value = controller.getValueFor(InputPathOption.NAME);
    Assume.assumeTrue(value instanceof Collection);
    Assume.assumeTrue(((Collection) value).iterator().hasNext());
    Assume.assumeTrue(((Collection) value).iterator().next() instanceof File);
    Assume.assumeTrue(((Collection) value).iterator().next().equals(inputFile));

    if (outputFile != null)
    {
        controller.setValueFor(OutputPathOption.NAME, outputFile);
    }
    controller.setValueFor(TargetOption.NAME, Collections.singletonList("eap"));

    Assert.assertTrue(controller.canExecute());
    controller.setValueFor("packages", "org.jboss");
    Assert.assertTrue(controller.canExecute());
}
 
Example 5
Source File: ProjectGenerator.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected void useCommand(RestUIContext context, String commandName, boolean shouldExecute) {
    try {
        UICommand command = commandFactory.getCommandByName(context, commandName);
        if (command == null) {
            LOG.warn("No such command! '" + commandName + "'");
            return;
        }
        CommandController controller = commandControllerFactory.createController(context, runtime, command);
        if (controller == null) {
            LOG.warn("No such controller! '" + commandName + "'");
            return;
        }
        controller.initialize();
        WizardCommandController wizardCommandController = assertWizardController(controller);

        Map<String, InputComponent<?, ?>> inputs = controller.getInputs();
        Set<Map.Entry<String, InputComponent<?, ?>>> entries = inputs.entrySet();
        for (Map.Entry<String, InputComponent<?, ?>> entry : entries) {
            String key = entry.getKey();
            InputComponent component = entry.getValue();
            Object value = InputComponents.getValueFor(component);
            Object completions = null;
            UICompleter<?> completer = InputComponents.getCompleterFor(component);
            if (completer != null) {
                completions = completer.getCompletionProposals(context, component, "");
            }
            LOG.info(key + " = " + component + " value: " + value + " completions: " + completions);
        }
        validate(controller);
        wizardCommandController = wizardCommandController.next();

        if (shouldExecute) {
            Result result = controller.execute();
            printResult(result);
        }
    } catch (Exception e) {
        LOG.error("Failed to create the " + commandName + " controller! " + e, e);
    }
}
 
Example 6
Source File: CommandsResource.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected CommandController createController(RestUIContext context, UICommand command) throws Exception {
    RestUIRuntime runtime = new RestUIRuntime();
    CommandController controller = commandControllerFactory.createController(context, runtime,
            command);
    controller.initialize();
    return controller;
}
 
Example 7
Source File: ProjectGenerator.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
public void createNewSpringBootProject() throws Exception {

        LOG.info("Creating new project");

        String name = "my-project";

        RestUIContext context = new RestUIContext();
        UICommand projectNewCommand = commandFactory.getCommandByName(context, "project-new");

        File outputDir = projectsOutputFolder;
        outputDir.mkdirs();

        CommandController controller = commandControllerFactory.createController(context, runtime, projectNewCommand);
        controller.initialize();

        controller.setValueFor("named", name);
        controller.setValueFor("topLevelPackage", "org.example");
        controller.setValueFor("version", "1.0.0-SNAPSHOT");
        controller.setValueFor("targetLocation", outputDir.getAbsolutePath());
        controller.setValueFor("buildSystem", "Maven");
        controller.setValueFor("type", "Spring Boot");

        WizardCommandController wizardCommandController = assertWizardController(controller);
        validate(wizardCommandController);
        wizardCommandController = wizardCommandController.next();
        LOG.info("Next result: " + wizardCommandController);

        wizardCommandController.setValueFor("springBootVersion", "1.3.7");

        // due to furnace/forge classloading we need to find the dto from the existing choices
        // and then select the dependencies we want to use
        SpringBootDependencyDTO web = null;
        UISelectMany many = (UISelectMany) wizardCommandController.getInput("dependencies");
        for (Object c : many.getValueChoices()) {
            SpringBootDependencyDTO dto = (SpringBootDependencyDTO) c;
            if ("web".equals(dto.getId())) {
                web = dto;
                break;
            }
        }

        wizardCommandController.setValueFor("dependencies", web);

        validate(wizardCommandController);
        try {

            Result result = wizardCommandController.execute();
            printResult(result);

            useNewProject(outputDir, name);
        } catch (Exception e) {
            LOG.error("Failed to create project " + name + " " + e, e);
        }
    }
 
Example 8
Source File: ProjectGenerator.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
public void createProjectFromArchetype(String archetype) throws Exception {
        String archetypeUri = "io.fabric8.archetypes:" + archetype + ":" + FABRIC8_ARCHETYPE_VERSION;

        LOG.info("Creating archetype: " + archetypeUri);

        RestUIContext context = new RestUIContext();
        UICommand projectNewCommand = commandFactory.getCommandByName(context, "project-new");

        File outputDir = new File(projectsOutputFolder, archetype);
        outputDir.mkdirs();

        CommandController controller = commandControllerFactory.createController(context, runtime, projectNewCommand);
        controller.initialize();

        String name = Strings.stripSuffix("my-" + archetype, "-archetype");
        controller.setValueFor("named", name);
        controller.setValueFor("topLevelPackage", "org.example");
        controller.setValueFor("version", "1.0.0-SNAPSHOT");
        controller.setValueFor("targetLocation", outputDir.getAbsolutePath());
        controller.setValueFor("buildSystem", "Maven");
        controller.setValueFor("type", "From Archetype Catalog");

        WizardCommandController wizardCommandController = assertWizardController(controller);
        validate(wizardCommandController);
        wizardCommandController = wizardCommandController.next();
        LOG.info("Next result: " + wizardCommandController);

/*
        InputComponent<?, ?> archetypeInput = wizardCommandController.getInputs().get("archetype");
        archetypeInput.get
*/

        wizardCommandController.setValueFor("catalog", "fabric8");
        wizardCommandController.setValueFor("archetype", archetypeUri);

        validate(wizardCommandController);
        try {

            Result result = wizardCommandController.execute();
            printResult(result);

            useProjectFromArchetype(archetype, outputDir, name);
        } catch (Exception e) {
            LOG.error("Failed to create project " + archetypeUri + " " + e, e);
        }
    }