org.jboss.forge.addon.ui.command.UICommand Java Examples
The following examples show how to use
org.jboss.forge.addon.ui.command.UICommand.
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: CommandsResource.java From fabric8-forge with Apache License 2.0 | 6 votes |
@Override @GET @Path("/commandInput/{name}/{namespace}/{projectName}/{path: .*}") @Produces(MediaType.APPLICATION_JSON) public Response getCommandInput(@PathParam("name") final String name, @PathParam("namespace") String namespace, @PathParam("projectName") String projectName, @PathParam("path") String resourcePath) throws Exception { return withUIContext(namespace, projectName, resourcePath, false, new RestUIFunction<Response>() { @Override public Response apply(RestUIContext context) throws Exception { CommandInputDTO answer = null; UICommand command = getCommandByName(context, name); if (command != null) { CommandController controller = createController(context, command); answer = UICommands.createCommandInputDTO(context, command, controller); } if (answer != null) { return Response.ok(answer).build(); } else { return Response.status(Status.NOT_FOUND).build(); } } }); }
Example #2
Source File: CommandsResource.java From fabric8-forge with Apache License 2.0 | 5 votes |
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 #3
Source File: AngularScaffoldProvider.java From angularjs-addon with Eclipse Public License 1.0 | 5 votes |
@Override public NavigationResult getSetupFlow(ScaffoldSetupContext setupContext) { Project project = setupContext.getProject(); NavigationResultBuilder builder = NavigationResultBuilder.create(); List<Class<? extends UICommand>> setupCommands = new ArrayList<>(); if (!project.hasFacet(JPAFacet.class)) { builder.add(JPASetupWizard.class); } if (!project.hasFacet(CDIFacet.class)) { setupCommands.add(CDISetupCommand.class); } if (!project.hasFacet(EJBFacet.class)) { setupCommands.add(EJBSetupWizard.class); } if (!project.hasFacet(ServletFacet.class)) { // TODO: FORGE-1296. Ensure that this wizard only sets up Servlet 3.0+ setupCommands.add(ServletSetupWizard.class); } if (!project.hasFacet(RestFacet.class)) { setupCommands.add(RestSetupWizard.class); } if (setupCommands.size() > 0) { Metadata compositeSetupMetadata = Metadata.forCommand(setupCommands.get(0)) .name("Setup Facets") .description("Setup all dependent facets for the AngularJS scaffold."); builder.add(compositeSetupMetadata, setupCommands); } return builder.build(); }
Example #4
Source File: SetupCommandTest.java From thorntail-addon with Eclipse Public License 1.0 | 5 votes |
@Test public void testThorntailSetupWithZeroParameters() throws Exception { try (CommandController controller = uiTestHarness.createCommandController(SetupCommand.class, project.getRoot())) { controller.initialize(); controller.setValueFor("httpPort", 0); controller.setValueFor("portOffset", 0); Assert.assertTrue(controller.isValid()); final AtomicBoolean flag = new AtomicBoolean(); controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener() { @Override public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result) { if (result.getMessage().equals("Thorntail is now set up! Enjoy!")) { flag.set(true); } } }); controller.execute(); Assert.assertTrue(flag.get()); ThorntailFacet facet = project.getFacet(ThorntailFacet.class); Assert.assertTrue(facet.isInstalled()); MavenPluginAdapter thorntailPlugin = (MavenPluginAdapter) project.getFacet(MavenPluginFacet.class) .getEffectivePlugin(ThorntailFacet.PLUGIN_COORDINATE); Assert.assertEquals("thorntail-maven-plugin", thorntailPlugin.getCoordinate().getArtifactId()); Assert.assertEquals(1, thorntailPlugin.getExecutions().size()); Assert.assertEquals(0, thorntailPlugin.getConfig().listConfigurationElements().size()); } }
Example #5
Source File: SetupCommandTest.java From thorntail-addon with Eclipse Public License 1.0 | 5 votes |
@Test public void testThorntailSetupWithNullParameters() throws Exception { try (CommandController controller = uiTestHarness.createCommandController(SetupCommand.class, project.getRoot())) { controller.initialize(); controller.setValueFor("httpPort", null); controller.setValueFor("contextPath", null); controller.setValueFor("portOffset", null); Assert.assertTrue(controller.isValid()); final AtomicBoolean flag = new AtomicBoolean(); controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener() { @Override public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result) { if (result.getMessage().equals("Thorntail is now set up! Enjoy!")) { flag.set(true); } } }); controller.execute(); Assert.assertTrue(flag.get()); ThorntailFacet facet = project.getFacet(ThorntailFacet.class); Assert.assertTrue(facet.isInstalled()); MavenPluginAdapter thorntailPlugin = (MavenPluginAdapter) project.getFacet(MavenPluginFacet.class) .getEffectivePlugin(ThorntailFacet.PLUGIN_COORDINATE); Assert.assertEquals("thorntail-maven-plugin", thorntailPlugin.getCoordinate().getArtifactId()); Assert.assertEquals(1, thorntailPlugin.getExecutions().size()); Assert.assertEquals(0, thorntailPlugin.getConfig().listConfigurationElements().size()); } }
Example #6
Source File: SetupCommandTest.java From thorntail-addon with Eclipse Public License 1.0 | 5 votes |
@Test public void testThorntailSetup() throws Exception { try (CommandController controller = uiTestHarness.createCommandController(SetupCommand.class, project.getRoot())) { controller.initialize(); Assert.assertTrue(controller.isValid()); final AtomicBoolean flag = new AtomicBoolean(); controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener() { @Override public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result) { if (result.getMessage().equals("Thorntail is now set up! Enjoy!")) { flag.set(true); } } }); controller.execute(); Assert.assertTrue(flag.get()); ThorntailFacet facet = project.getFacet(ThorntailFacet.class); Assert.assertTrue(facet.isInstalled()); MavenPluginAdapter thorntailPlugin = (MavenPluginAdapter) project.getFacet(MavenPluginFacet.class) .getEffectivePlugin(ThorntailFacet.PLUGIN_COORDINATE); Assert.assertEquals("thorntail-maven-plugin", thorntailPlugin.getCoordinate().getArtifactId()); Assert.assertEquals(1, thorntailPlugin.getExecutions().size()); Assert.assertEquals(0, thorntailPlugin.getConfig().listConfigurationElements().size()); } }
Example #7
Source File: CommandsResource.java From fabric8-forge with Apache License 2.0 | 5 votes |
protected CommandInfoDTO createCommandInfoDTO(RestUIContext context, String name) { CommandInfoDTO answer = null; if (isValidCommandName(name)) { UICommand command = getCommandByName(context, name); if (command != null) { answer = UICommands.createCommandInfoDTO(context, command); } } return answer; }
Example #8
Source File: UICommands.java From fabric8-forge with Apache License 2.0 | 5 votes |
public static CommandInputDTO createCommandInputDTO(RestUIContext context, UICommand command, CommandController controller) throws Exception { CommandInfoDTO info = createCommandInfoDTO(context, command); CommandInputDTO inputInfo = new CommandInputDTO(info); Map<String, InputComponent<?, ?>> inputs = controller.getInputs(); if (inputs != null) { Set<Map.Entry<String, InputComponent<?, ?>>> entries = inputs.entrySet(); for (Map.Entry<String, InputComponent<?, ?>> entry : entries) { String key = entry.getKey(); InputComponent<?, ?> input = entry.getValue(); PropertyDTO dto = UICommands.createInputDTO(context, input); inputInfo.addProperty(key, dto); } } return inputInfo; }
Example #9
Source File: UICommands.java From fabric8-forge with Apache License 2.0 | 5 votes |
public static CommandInfoDTO createCommandInfoDTO(RestUIContext context, UICommand command) { CommandInfoDTO answer; UICommandMetadata metadata = command.getMetadata(context); String metadataName = unshellifyName(metadata.getName()); String id = shellifyName(metadataName); String description = metadata.getDescription(); String category = toStringOrNull(metadata.getCategory()); String docLocation = toStringOrNull(metadata.getDocLocation()); boolean enabled = command.isEnabled(context); answer = new CommandInfoDTO(id, metadataName, description, category, docLocation, enabled); return answer; }
Example #10
Source File: ProjectGenerator.java From fabric8-forge with Apache License 2.0 | 5 votes |
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 #11
Source File: CommandsResource.java From fabric8-forge with Apache License 2.0 | 4 votes |
protected UICommand getCommandByName(RestUIContext context, String name) { return commandFactory.getCommandByName(context, name); }
Example #12
Source File: ProjectGenerator.java From fabric8-forge with Apache License 2.0 | 4 votes |
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 #13
Source File: SetupCommandTest.java From thorntail-addon with Eclipse Public License 1.0 | 4 votes |
@Test public void testThorntailSetupWithParameters() throws Exception { try (CommandController controller = uiTestHarness.createCommandController(SetupCommand.class, project.getRoot())) { controller.initialize(); controller.setValueFor("httpPort", 4242); controller.setValueFor("contextPath", "root"); controller.setValueFor("portOffset", 42); Assert.assertTrue(controller.isValid()); final AtomicBoolean flag = new AtomicBoolean(); controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener() { @Override public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result) { if (result.getMessage().equals("Thorntail is now set up! Enjoy!")) { flag.set(true); } } }); controller.execute(); Assert.assertTrue(flag.get()); ThorntailFacet facet = project.getFacet(ThorntailFacet.class); Assert.assertTrue(facet.isInstalled()); MavenPluginAdapter thorntailPlugin = (MavenPluginAdapter) project.getFacet(MavenPluginFacet.class) .getEffectivePlugin(ThorntailFacet.PLUGIN_COORDINATE); Assert.assertEquals("thorntail-maven-plugin", thorntailPlugin.getCoordinate().getArtifactId()); Assert.assertEquals(1, thorntailPlugin.getExecutions().size()); Configuration config = thorntailPlugin.getConfig(); ConfigurationElement configurationProps = config.getConfigurationElement("properties"); Assert.assertEquals(3, configurationProps.getChildren().size()); Assert.assertEquals("4242", configurationProps.getChildByName("swarm.http.port").getText()); Assert.assertEquals("root", configurationProps.getChildByName("swarm.context.path").getText()); Assert.assertEquals("42", configurationProps.getChildByName("swarm.port.offset").getText()); } }
Example #14
Source File: CreateTestClassCommandTest.java From thorntail-addon with Eclipse Public License 1.0 | 4 votes |
@Test public void should_create_incontainer_test() throws Exception { assertThat(project.hasFacet(ThorntailFacet.class), is(true)); try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class, project.getRoot())) { controller.initialize(); controller.setValueFor("targetPackage", "org.example"); controller.setValueFor("named", "HelloWorldTest"); assertThat(controller.isValid(), is(true)); final AtomicBoolean flag = new AtomicBoolean(); controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener() { @Override public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result) { if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created")) { flag.set(true); } } }); controller.execute(); assertThat(flag.get(), is(true)); } JavaResource javaResource = project.getFacet(JavaSourceFacet.class) .getTestJavaResource("org.example.HelloWorldTest"); assertThat(javaResource.exists(), is(true)); JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents()); assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue()))); final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment"); assertThat(defaultDeployment, is((notNullValue()))); assertThat(defaultDeployment.getValues().size(), is(0)); final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service"); assertThat(testMethod, is(notNullValue())); assertThat(testMethod.getAnnotation(Test.class), is(notNullValue())); }
Example #15
Source File: CreateTestClassCommandTest.java From thorntail-addon with Eclipse Public License 1.0 | 4 votes |
@Test public void should_create_asclient_test() throws Exception { assertThat(project.hasFacet(ThorntailFacet.class), is(true)); try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class, project.getRoot())) { controller.initialize(); controller.setValueFor("targetPackage", "org.example"); controller.setValueFor("named", "HelloWorldTest"); controller.setValueFor("asClient", true); assertThat(controller.isValid(), is(true)); final AtomicBoolean flag = new AtomicBoolean(); controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener() { @Override public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result) { if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created")) { flag.set(true); } } }); controller.execute(); assertThat(flag.get(), is(true)); } JavaResource javaResource = project.getFacet(JavaSourceFacet.class) .getTestJavaResource("org.example.HelloWorldTest"); assertThat(javaResource.exists(), is(true)); JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents()); assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue()))); final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment"); assertThat(defaultDeployment, is((notNullValue()))); final String testable = defaultDeployment.getLiteralValue("testable"); assertThat(testable, is("false")); final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service"); assertThat(testMethod, is(notNullValue())); assertThat(testMethod.getAnnotation(Test.class), is(notNullValue())); }
Example #16
Source File: CreateTestClassCommandTest.java From thorntail-addon with Eclipse Public License 1.0 | 4 votes |
@Test public void should_set_archivetype_test() throws Exception { assertThat(project.hasFacet(ThorntailFacet.class), is(true)); try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class, project.getRoot())) { controller.initialize(); controller.setValueFor("targetPackage", "org.example"); controller.setValueFor("named", "HelloWorldTest"); controller.setValueFor("archiveType", "WAR"); assertThat(controller.isValid(), is(true)); final AtomicBoolean flag = new AtomicBoolean(); controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener() { @Override public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result) { if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created")) { flag.set(true); } } }); controller.execute(); assertThat(flag.get(), is(true)); } JavaResource javaResource = project.getFacet(JavaSourceFacet.class) .getTestJavaResource("org.example.HelloWorldTest"); assertThat(javaResource.exists(), is(true)); JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents()); assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue()))); final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment"); assertThat(defaultDeployment, is((notNullValue()))); final String testable = defaultDeployment.getLiteralValue("type"); assertThat(testable, is("DefaultDeployment.Type.WAR")); final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service"); assertThat(testMethod, is(notNullValue())); assertThat(testMethod.getAnnotation(Test.class), is(notNullValue())); }
Example #17
Source File: ProjectGenerator.java From fabric8-forge with Apache License 2.0 | 4 votes |
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); } }