org.jboss.forge.addon.ui.result.Result Java Examples
The following examples show how to use
org.jboss.forge.addon.ui.result.Result.
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: EndpointStatsCommand.java From fabric8-forge with Apache License 2.0 | 6 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { String url = getJolokiaUrl(); if (url == null) { return Results.fail("Not connected to remote jolokia agent. Use camel-connect command first"); } boolean val = "true".equals(decode.getValue()); String[] val2 = null; if (filter.getValue() != null) { String s = filter.getValue().toString(); val2 = s.split(","); } org.apache.camel.commands.EndpointStatisticCommand command = new org.apache.camel.commands.EndpointStatisticCommand(name.getValue(), val, val2); command.execute(getController(), getOutput(context), getError(context)); return Results.success(); }
Example #2
Source File: ConfigureEndpointPropertiesStep.java From fabric8-forge with Apache License 2.0 | 6 votes |
protected Result editEndpointOther(Project project, ResourcesFacet facet, FileResource file, String uri, String endpointUrl, String currentFile, String lineNumber) throws Exception { List<String> lines = LineNumberHelper.readLines(file.getResourceInputStream()); // the list is 0-based, and line number is 1-based int idx = Integer.valueOf(lineNumber) - 1; String line = lines.get(idx); // replace uri with new value line = StringHelper.replaceAll(line, endpointUrl, uri); lines.set(idx, line); LOG.info("Updating " + endpointUrl + " to " + uri + " at line " + lineNumber + " in file " + currentFile); // and save the file back String content = LineNumberHelper.linesToString(lines); file.setContents(content); return Results.success("Update endpoint uri: " + uri + " in file " + currentFile); }
Example #3
Source File: ConfigureEipPropertiesStep.java From fabric8-forge with Apache License 2.0 | 6 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { Map<Object, Object> attributeMap = context.getUIContext().getAttributeMap(); // only execute if we are last if (last) { String kind = mandatoryAttributeValue(attributeMap, "kind"); if ("xml".equals(kind)) { return executeXml(context, attributeMap); } else { throw new UnsupportedOperationException("Java not yet supported"); } } else { return null; } }
Example #4
Source File: NewNodeXmlTest.java From fabric8-forge with Apache License 2.0 | 6 votes |
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 #5
Source File: NewIntegrationTestBuildCommand.java From fabric8-forge with Apache License 2.0 | 6 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { String buildConfigName = buildName.getValue(); Objects.assertNotNull(buildConfigName, "buildName"); Map<String, String> labels = BuildConfigs.createBuildLabels(buildConfigName); String gitUrlText = getOrFindGitUrl(context, gitUri.getValue()); String imageText = image.getValue(); List<EnvVar> envVars = createEnvVars(buildConfigName, gitUrlText, mavenCommand.getValue()); BuildConfig buildConfig = BuildConfigs.createIntegrationTestBuildConfig(buildConfigName, labels, gitUrlText, imageText, envVars); LOG.info("Generated BuildConfig: " + toJson(buildConfig)); ImageStream imageRepository = BuildConfigs.imageRepository(buildConfigName, labels); Controller controller = createController(); controller.applyImageStream(imageRepository, "generated ImageStream: " + toJson(imageRepository)); controller.applyBuildConfig(buildConfig, "generated BuildConfig: " + toJson(buildConfig)); return Results.success("Added BuildConfig: " + Builds.getName(buildConfig) + " to OpenShift at master: " + getKubernetes().getMasterUrl()); }
Example #6
Source File: ConfigureEndpointPropertiesStep.java From fabric8-forge with Apache License 2.0 | 6 votes |
private Result editEndpointXml(List<String> lines, String lineNumber, String endpointUrl, String uri, FileResource file, String xml) { // the list is 0-based, and line number is 1-based int idx = Integer.valueOf(lineNumber) - 1; String line = lines.get(idx); // replace uri with new value line = StringHelper.replaceAll(line, endpointUrl, uri); lines.set(idx, line); LOG.info("Updating " + endpointUrl + " to " + uri + " at line " + lineNumber + " in file " + xml); // and save the file back String content = LineNumberHelper.linesToString(lines); file.setContents(content); return Results.success("Update endpoint uri: " + uri + " in file " + xml); }
Example #7
Source File: CamelCommandsHelper.java From fabric8-forge with Apache License 2.0 | 6 votes |
public static Result ensureCamelArtifactIdAdded(Project project, CamelComponentDetails details, DependencyInstaller dependencyInstaller) { String groupId = details.getGroupId(); String artifactId = details.getArtifactId(); Dependency core = CamelProjectHelper.findCamelCoreDependency(project); if (core == null) { return Results.fail("The project does not include camel-core"); } // we want to use same version as camel-core if its a camel component // otherwise use the version from the dto String version; if ("org.apache.camel".equals(groupId)) { version = core.getCoordinate().getVersion(); } else { version = details.getVersion(); } DependencyBuilder component = DependencyBuilder.create().setGroupId(groupId) .setArtifactId(artifactId).setVersion(version); // install the component dependencyInstaller.install(project, component); return null; }
Example #8
Source File: AddFractionCommand.java From thorntail-addon with Eclipse Public License 1.0 | 6 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { Project project = getSelectedProject(context); ThorntailFacet facet = project.getFacet(ThorntailFacet.class); if (fractionElements.hasValue()) { List<FractionDescriptor> fractions = Lists.toList(fractionElements.getValue()); facet.installFractions(fractions); List<String> artifactIds = fractions.stream().map(FractionDescriptor::getArtifactId) .collect(Collectors.toList()); return Results.success("Thorntail Fractions '" + artifactIds + "' were successfully added to the project descriptor"); } return Results.success(); }
Example #9
Source File: ConfigureEndpointPropertiesStep.java From fabric8-forge with Apache License 2.0 | 6 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { Map<Object, Object> attributeMap = context.getUIContext().getAttributeMap(); // only execute if we are last if (last) { String kind = mandatoryAttributeValue(attributeMap, "kind"); if ("xml".equals(kind)) { return executeXml(context, attributeMap); } else if ("java".equals(kind)) { return executeJava(context, attributeMap); } else { return executeOther(context, attributeMap); } } else { return null; } }
Example #10
Source File: ContextStartCommand.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { String url = getJolokiaUrl(); if (url == null) { return Results.fail("Not connected to remote jolokia agent. Use camel-connect command first"); } org.apache.camel.commands.ContextStartCommand command = new org.apache.camel.commands.ContextStartCommand(name.getValue()); command.execute(getController(), getOutput(context), getError(context)); return Results.success("Started " + name.getValue()); }
Example #11
Source File: ServiceDelete.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { String idText = serviceId.getValue(); Service service = getKubernetes().services().inNamespace(getNamespace()).withName(idText).get(); if (service == null) { System.out.println("No service for id: " + idText); } else { executeService(service); } return null; }
Example #12
Source File: ConfigureEndpointPropertiesStep.java From fabric8-forge with Apache License 2.0 | 5 votes |
private Result addEndpointXml(FileResource file, String uri, String endpointInstanceName, String xml, String cursorPosition) throws Exception { LOG.info("Adding uri " + uri + " at position " + cursorPosition + " in file " + xml); // we do not want to change the current code formatting so we need to search // replace the unformatted class source code StringBuilder sb = new StringBuilder(file.getContents()); int pos = Integer.valueOf(cursorPosition); // move to end if pos is after the content pos = Math.min(sb.length(), pos); LOG.info("Adding endpoint at pos: " + pos + " in file: " + xml); // check if prev and next is a quote and if not then add it automatic int prev = pos - 1; int next = pos + 1; char ch = sb.charAt(prev); char ch2 = next < sb.length() ? sb.charAt(next) : ' '; if (ch != '"' && ch2 != '"') { uri = "\"" + uri + "\""; } // insert uri at position sb.insert(pos, uri); String text = sb.toString(); // use this code currently to save content unformatted file.setContents(text); return Results.success("Added endpoint " + uri + " in " + xml); }
Example #13
Source File: ConfigureEndpointPropertiesStep.java From fabric8-forge with Apache License 2.0 | 5 votes |
protected Result addOrEditEndpointXml(FileResource file, String uri, String endpointUrl, String endpointInstanceName, String xml, String lineNumber, String lineNumberEnd) throws Exception { // if we have a line number then use that to edit the existing value if (lineNumber != null) { List<String> lines = LineNumberHelper.readLines(file.getResourceInputStream()); return editEndpointXml(lines, lineNumber, endpointUrl, uri, file, xml); } else { // we are in add mode, so parse dom to find <camelContext> and insert the endpoint where its needed Document root = XmlLineNumberParser.parseXml(file.getResourceInputStream()); return addEndpointXml(root, endpointInstanceName, uri, file, xml); } }
Example #14
Source File: CamelCommandsHelper.java From fabric8-forge with Apache License 2.0 | 5 votes |
/** * Populates the details for the given component, returning a Result if it fails. */ public static Result loadCamelComponentDetails(CamelCatalog camelCatalog, String camelComponentName, CamelComponentDetails details) { String json = camelCatalog.componentJSonSchema(camelComponentName); if (json == null) { return Results.fail("Could not find catalog entry for component name: " + camelComponentName); } List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("component", json, false); for (Map<String, String> row : data) { String javaType = row.get("javaType"); if (!Strings.isNullOrEmpty(javaType)) { details.setComponentClassQName(javaType); } String groupId = row.get("groupId"); if (!Strings.isNullOrEmpty(groupId)) { details.setGroupId(groupId); } String artifactId = row.get("artifactId"); if (!Strings.isNullOrEmpty(artifactId)) { details.setArtifactId(artifactId); } String version = row.get("version"); if (!Strings.isNullOrEmpty(version)) { details.setVersion(version); } } if (Strings.isNullOrEmpty(details.getComponentClassQName())) { return Results.fail("Could not find fully qualified class name in catalog for component name: " + camelComponentName); } return null; }
Example #15
Source File: EndpointExplainCommand.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { String url = getJolokiaUrl(); if (url == null) { return Results.fail("Not connected to remote jolokia agent. Use camel-connect command first"); } boolean val = "true".equals(verbose.getValue()); org.apache.camel.commands.EndpointExplainCommand command = new org.apache.camel.commands.EndpointExplainCommand(name.getValue(), val, filter.getValue()); command.execute(getController(), getOutput(context), getError(context)); return Results.success(); }
Example #16
Source File: ContextStopCommand.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { String url = getJolokiaUrl(); if (url == null) { return Results.fail("Not connected to remote jolokia agent. Use camel-connect command first"); } org.apache.camel.commands.ContextStopCommand command = new org.apache.camel.commands.ContextStopCommand(name.getValue()); command.execute(getController(), getOutput(context), getError(context)); return Results.success("Stopped " + name.getValue()); }
Example #17
Source File: CamelGetComponentsCommand.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { Project project = getSelectedProject(context); boolean excludeProjectComponents = isValueTrue(excludeProject); Callable<Iterable<ComponentDto>> callable = CamelCommandsHelper.createAllComponentDtoValues(project, getCamelCatalog(), filter, excludeProjectComponents); Iterable<ComponentDto> results = callable.call(); String result = formatResult(results); return Results.success(result); }
Example #18
Source File: ContextResumeCommand.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { String url = getJolokiaUrl(); if (url == null) { return Results.fail("Not connected to remote jolokia agent. Use camel-connect command first"); } org.apache.camel.commands.ContextResumeCommand command = new org.apache.camel.commands.ContextResumeCommand(name.getValue()); command.execute(getController(), getOutput(context), getError(context)); return Results.success("Resumed " + name.getValue()); }
Example #19
Source File: EditFromOrToEndpointXmlStep.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override protected Result addOrEditEndpointXml(FileResource file, String uri, String endpointUrl, String endpointInstanceName, String xml, String lineNumber, String lineNumberEnd) throws Exception { String key = parentNode.getKey(); if (Strings.isNullOrBlank(key)) { return Results.fail("Parent node has no key! " + parentNode + " in file " + file.getName()); } Document root = XmlLineNumberParser.parseXml(file.getResourceInputStream()); if (root != null) { Node selectedNode = CamelXmlHelper.findCamelNodeInDocument(root, key); if (selectedNode != null) { // we need to add after the parent node, so use line number information from the parent lineNumber = (String) selectedNode.getUserData(XmlLineNumberParser.LINE_NUMBER); lineNumberEnd = (String) selectedNode.getUserData(XmlLineNumberParser.LINE_NUMBER_END); if (lineNumber != null && lineNumberEnd != null) { // read all the lines List<String> lines = LineNumberHelper.readLines(file.getResourceInputStream()); // the list is 0-based, and line number is 1-based int idx = Integer.valueOf(lineNumber) - 1; String line = lines.get(idx); // replace uri with new value line = StringHelper.replaceAll(line, endpointUrl, uri); lines.set(idx, line); // and save the file back String content = LineNumberHelper.linesToString(lines); file.setContents(content); return Results.success("Updated: " + line.trim()); } } return Results.fail("Cannot find Camel node in XML file: " + key); } else { return Results.fail("Cannot load Camel XML file: " + file.getName()); } }
Example #20
Source File: CamelGetOverviewCommand.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { Project project = getSelectedProject(context); // does the project already have camel? Dependency core = findCamelCoreDependency(project); if (core == null) { return Results.fail("The project does not include camel-core"); } ProjectDto camelProject = new ProjectDto(); ResourcesFacet resourcesFacet = project.getFacet(ResourcesFacet.class); WebResourcesFacet webResourcesFacet = null; if (project.hasFacet(WebResourcesFacet.class)) { webResourcesFacet = project.getFacet(WebResourcesFacet.class); } // use value choices instead of completer as that works better in web console XmlEndpointsCompleter xmlEndpointCompleter = new XmlEndpointsCompleter(resourcesFacet, webResourcesFacet, null); JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class); // use value choices instead of completer as that works better in web console RouteBuilderEndpointsCompleter javaEndpointsCompleter = new RouteBuilderEndpointsCompleter(javaSourceFacet, null); camelProject.addEndpoints(javaEndpointsCompleter.getEndpoints()); camelProject.addEndpoints(xmlEndpointCompleter.getEndpoints()); CamelCurrentComponentsFinder componentsFinder = new CamelCurrentComponentsFinder(getCamelCatalog(), project); List<ComponentDto> currentComponents = componentsFinder.findCurrentComponents(); camelProject.setComponents(currentComponents); String result = formatResult(camelProject); return Results.success(result); }
Example #21
Source File: ConfigureEipPropertiesStep.java From fabric8-forge with Apache License 2.0 | 5 votes |
protected Result addOrEditModelXml(FileResource file, String pattern, String modelXml, String xml, String lineNumber, String lineNumberEnd, String mode) throws Exception { List<String> lines = LineNumberHelper.readLines(file.getResourceInputStream()); if ("add".equals(mode)) { return addModelXml(pattern, lines, lineNumber, lineNumberEnd, modelXml, file, xml); } else { return editModelXml(pattern, lines, lineNumber, lineNumberEnd, modelXml, file, xml); } }
Example #22
Source File: RestRegistryListCommand.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { String url = getJolokiaUrl(); if (url == null) { return Results.fail("Not connected to remote jolokia agent. Use camel-connect command first"); } boolean val = "true".equals(decode.getValue()); boolean val2 = "true".equals(verbose.getValue()); org.apache.camel.commands.RestRegistryListCommand command = new org.apache.camel.commands.RestRegistryListCommand(name.getValue(), val, val2); command.execute(getController(), getOutput(context), getError(context)); return Results.success(); }
Example #23
Source File: AddNodeXmlStep.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override protected Result addModelXml(String pattern, List<String> lines, String lineNumber, String lineNumberEnd, String modelXml, FileResource file, String xml) throws Exception { // the list is 0-based, and line number is 1-based int idx = Integer.valueOf(lineNumberEnd); if ("route".equals(pattern)) { // we want to add at the end of the existing route, not after the route idx = idx - 1; } // use the same indent from the parent line int spaces = LineNumberHelper.leadingSpaces(lines, idx - 1); LOG.info("Spaces " + spaces); String[] editLines = modelXml.split("\n"); for (String line : editLines) { // use the same indent from the eip we are replacing line = LineNumberHelper.padString(line, spaces); // add the new line at the old starting position lines.add(idx, line); idx++; } // and save the file back String content = LineNumberHelper.linesToString(lines); file.setContents(content); return Results.success("Added: " + modelXml); }
Example #24
Source File: RouteProfileCommand.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { String url = getJolokiaUrl(); if (url == null) { return Results.fail("Not connected to remote jolokia agent. Use camel-connect command first"); } org.apache.camel.commands.RouteProfileCommand command = new org.apache.camel.commands.RouteProfileCommand(route.getValue(), name.getValue()); command.setStringEscape(new NoopStringEscape()); command.execute(getController(), getOutput(context), getError(context)); return Results.success(); }
Example #25
Source File: RouteSuspendCommand.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { String url = getJolokiaUrl(); if (url == null) { return Results.fail("Not connected to remote jolokia agent. Use camel-connect command first"); } org.apache.camel.commands.RouteSuspendCommand command = new org.apache.camel.commands.RouteSuspendCommand(route.getValue(), name.getValue()); command.execute(getController(), getOutput(context), getError(context)); return Results.success("Suspended " + route.getValue()); }
Example #26
Source File: NewNodeXmlTest.java From fabric8-forge with Apache License 2.0 | 5 votes |
protected void assertExecutes(WizardCommandController command) throws Exception { Result result = command.execute(); assertFalse("Should not fail", result instanceof Failed); System.out.println(); String message = getResultMessage(result); System.out.println("Add route result: " + message); System.out.println(); }
Example #27
Source File: WindupUpdateRulesetCommand.java From windup with Eclipse Public License 1.0 | 5 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { return Results.fail("Update was disabled!"); /* temporary disabled update of rules due possible breakage on compatibility and proper * function String updatedTo = updater.replaceRulesetsDirectoryWithLatestReleaseIfAny(); if (updatedTo == null) return Results.fail("The ruleset is already in the most updated version."); else return Results.success("Sucessfully updated the rulesets to version " + updatedTo + " ."); */ }
Example #28
Source File: RouteStartCommand.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { String url = getJolokiaUrl(); if (url == null) { return Results.fail("Not connected to remote jolokia agent. Use camel-connect command first"); } org.apache.camel.commands.RouteStartCommand command = new org.apache.camel.commands.RouteStartCommand(route.getValue(), name.getValue()); command.execute(getController(), getOutput(context), getError(context)); return Results.success("Started " + route.getValue()); }
Example #29
Source File: ContextInflightCommand.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { String url = getJolokiaUrl(); if (url == null) { return Results.fail("Not connected to remote jolokia agent. Use camel-connect command first"); } Boolean value = sortByLongestDuration.getValue(); boolean flag = value != null && value.booleanValue(); org.apache.camel.commands.ContextInflightCommand command = new org.apache.camel.commands.ContextInflightCommand(name.getValue(), route.getValue(), limit.getValue(), flag); command.execute(getController(), getOutput(context), getError(context)); return Results.success(); }
Example #30
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()); } }