Java Code Examples for org.jboss.forge.addon.ui.result.Results#success()

The following examples show how to use org.jboss.forge.addon.ui.result.Results#success() . 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: Fabric8SetupStep.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    StopWatch watch = new StopWatch();

    log.debug("Starting to setup fabric8 project");

    Project project = getSelectedProject(context.getUIContext());
    if (project == null) {
        return Results.fail("No pom.xml available so cannot edit the project!");
    }

    // setup fabric8-maven-plugin
    setupFabricMavenPlugin(project);
    log.debug("fabric8-maven-plugin now setup");

    // make sure we have resources as we need it later
    facetFactory.install(project, ResourcesFacet.class);

    log.info("execute took " + watch.taken());
    return Results.success();
}
 
Example 2
Source File: WindupUpdateDistributionCommand.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception
{
    if (!context.getPrompt().promptBoolean(
        "Are you sure you want to continue? This command will delete current directories: addons, bin, lib, rules/migration-core"))
    {
        return Results.fail("Updating distribution was aborted.");
    }

    // Find the latest version.
    Coordinate latestDist = this.updater.getLatestReleaseOf("org.jboss.windup", "windup-distribution");
    Version latestVersion = SingleVersion.valueOf(latestDist.getVersion());
    Version installedVersion = currentAddon.getId().getVersion();
    if (latestVersion.compareTo(installedVersion) <= 0)
    {
        return Results.fail(Util.WINDUP_BRAND_NAME_ACRONYM+" CLI is already in the most updated version.");
    }

    distUpdater.replaceWindupDirectoryWithDistribution(latestDist);

    return Results.success("Sucessfully updated "+Util.WINDUP_BRAND_NAME_ACRONYM+" CLI to version " + latestDist.getVersion() + ". Please restart MTA CLI.");
}
 
Example 3
Source File: EndpointListCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@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());
    boolean val3 = "true".equals(explain.getValue());

    org.apache.camel.commands.EndpointListCommand command = new org.apache.camel.commands.EndpointListCommand(name.getValue(), val, val2, val3);
    command.execute(getController(), getOutput(context), getError(context));

    return Results.success();
}
 
Example 4
Source File: CreateTestClassCommand.java    From thorntail-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    Project project = getSelectedProject(context);

    final DependencyFacet dependencyFacet = project.getFacet(DependencyFacet.class);
    if (!isArquillianWildflySwarmDependencyInstalled(dependencyFacet)) {
        installArquillianWildflySwarmDependency(dependencyFacet);
    }

    JavaClassSource test = Roaster.create(JavaClassSource.class)
            .setPackage(targetPackage.getValue())
            .setName(named.getValue());

    addArquillianRunner(test);
    addDefaultDeploymentAnnotation(test, project);
    addArquillianResourceEnricher(test);
    addTestMethod(test);

    JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
    facet.saveTestJavaSource(test);

    return Results.success(String.format("Test Class %s.%s was created", targetPackage.getValue(), named.getValue()));
}
 
Example 5
Source File: ContextInfoCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@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.ContextInfoCommand command = new org.apache.camel.commands.ContextInfoCommand(name.getValue(), val);
    command.setStringEscape(new NoopStringEscape());

    command.execute(getController(), getOutput(context), getError(context));
    return Results.success();
}
 
Example 6
Source File: RouteInfoCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@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.RouteInfoCommand command = new org.apache.camel.commands.RouteInfoCommand(route.getValue(), name.getValue());
    command.setStringEscape(new NoopStringEscape());

    command.execute(getController(), getOutput(context), getError(context));
    return Results.success();
}
 
Example 7
Source File: DisconnectCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public Result execute(UIExecutionContext uiExecutionContext) throws Exception {
    String url = getJolokiaUrl();

    configuration.clearProperty("CamelJolokiaUrl");

    if (url != null) {
        return Results.success("Disconnected from " + url);
    } else {
        return Results.success();
    }
}
 
Example 8
Source File: RestApiDocCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@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.RestApiDocCommand command = new org.apache.camel.commands.RestApiDocCommand(name.getValue());
    command.execute(getController(), getOutput(context), getError(context));

    return Results.success();
}
 
Example 9
Source File: RouteStopCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@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.RouteStopCommand command = new org.apache.camel.commands.RouteStopCommand(route.getValue(), name.getValue());
    command.execute(getController(), getOutput(context), getError(context));
    return Results.success("Stopped " + route.getValue());
}
 
Example 10
Source File: NewBuildCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    String buildConfigName = buildName.getValue();
    Objects.assertNotNull(buildConfigName, "buildName");
    Map<String, String> labels = BuildConfigs.createBuildLabels(buildConfigName);
    String ouputImageName = imageName.getValue();
    String gitUrlText = getOrFindGitUrl(context, gitUri.getValue());
    String imageText = outputImage.getValue();
    Model mavenModel = getMavenModel(context);
    if (Strings.isNullOrBlank(imageText) && mavenModel != null) {
        imageText = mavenModel.getProperties().getProperty("docker.image");
    }

    String webhookSecretText = webHookSecret.getValue();
    if (Strings.isNullOrBlank(webhookSecretText)) {
        // TODO generate a really good secret!
        webhookSecretText = "secret101";
    }
    BuildConfig buildConfig = BuildConfigs.createBuildConfig(buildConfigName, labels, gitUrlText, ouputImageName, imageText, webhookSecretText);

    System.out.println("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 11
Source File: SetupFractionsStep.java    From thorntail-addon with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Result execute(UIExecutionContext context)
{
    Project project = getSelectedProject(context);
    ThorntailFacet thorntail = project.getFacet(ThorntailFacet.class);
    List<FractionDescriptor> installedFractions = thorntail.getInstalledFractions();
    if (enableJAXRS(installedFractions))
    {
        JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
        JavaClassSource restEndpoint = Roaster.create(JavaClassSource.class)
                    .setPackage(facet.getBasePackage() + ".rest")
                    .setName("HelloWorldEndpoint");
        if (hasCDI(installedFractions))
        {
            restEndpoint.addAnnotation(ApplicationScoped.class);
        }
        restEndpoint.addAnnotation(Path.class).setStringValue("/hello");
        MethodSource<JavaClassSource> method = restEndpoint.addMethod().setPublic().setReturnType(Response.class)
                    .setName("doGet")
                    .setBody("return Response.ok(\"Hello from Thorntail!\").build();");
        method.addAnnotation(GET.class);
        method.addAnnotation(javax.ws.rs.Produces.class).setStringArrayValue(new String[] { MediaType.TEXT_PLAIN });
        facet.saveJavaSource(restEndpoint);
    }
    if (hasTopologyJgroups(installedFractions))
    {
        ThorntailConfiguration config = thorntail.getConfiguration();
        Map<String, String> props = new TreeMap<>(config.getProperties());
        props.put("swarm.bind.address", "127.0.0.1");
        props.put("java.net.preferIPv4Stack", "true");
        props.put("jboss.node.name", "${project.artifactId}");
        thorntail.setConfiguration(ThorntailConfigurationBuilder.create(config).properties(props));
    }
    return Results.success();
}
 
Example 12
Source File: ListFractionsCommand.java    From thorntail-addon with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Result execute(UIExecutionContext executionContext) {
    UIProvider provider = executionContext.getUIContext().getProvider();
    UIOutput output = provider.getOutput();
    PrintStream out = output.out();
    for (FractionDescriptor fraction : ThorntailFacet.getAllFractionDescriptors()) {
        if (!fraction.isInternal()) {
            String msg = String.format("%s: %s (%s)", fraction.getArtifactId(), fraction.getName(),
                    fraction.getDescription());
            out.println(msg);
        }
    }
    return Results.success();
}
 
Example 13
Source File: ContextResumeCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@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 14
Source File: RouteResumeCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@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.RouteResumeCommand command = new org.apache.camel.commands.RouteResumeCommand(route.getValue(), name.getValue());
    command.execute(getController(), getOutput(context), getError(context));
    return Results.success("Resumed " + route.getValue());
}
 
Example 15
Source File: CamelNewComponentCommand.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    return Results.success();
}
 
Example 16
Source File: CamelAddNodeXmlCommand.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    return Results.success();
}
 
Example 17
Source File: AddRouteFromEndpointXmlStep.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
protected Result addOrEditEndpointXml(FileResource file, String uri, String endpointUrl, String endpointInstanceName, String xml, String lineNumber, String lineNumberEnd) throws Exception {
    Document root = XmlLineNumberParser.parseXml(file.getResourceInputStream());
    if (root != null) {
        NodeList camels = getCamelContextElements(root);
        // TODO: what about 2+ camel's ?
        if (camels != null && camels.getLength() == 1) {
            Node camel = camels.item(0);
            Node camelContext = null;

            for (int i = 0; i < camel.getChildNodes().getLength(); i++) {
                if (CamelXmlHelper.isCamelContextOrRoutesNode(camel)) {
                    camelContext = camel;
                }

                Node child = camel.getChildNodes().item(i);
                if (CamelXmlHelper.isCamelContextOrRoutesNode(child)) {
                    camelContext = child;
                }
            }

            if (camelContext == null) {
                return Results.fail("Cannot find <camelContext> or <routes> in XML file " + xml);
            }

            // we need to add after the parent node, so use line number information from the parent
            lineNumber = (String) camelContext.getUserData(XmlLineNumberParser.LINE_NUMBER);
            lineNumberEnd = (String) camelContext.getUserData(XmlLineNumberParser.LINE_NUMBER_END);

            if (lineNumber != null && lineNumberEnd != null) {

                String line1;
                if (routeId != null) {
                    line1 = String.format("<route id=\"%s\">", routeId);
                } else {
                    line1 = "<route>";
                }
                String line2 = String.format("<from uri=\"%s\"/>", uri);
                String line3 = "</route>";

                // if we created a new endpoint, then insert a new line with the endpoint details
                List<String> lines = LineNumberHelper.readLines(file.getResourceInputStream());

                // the list is 0-based, and line number is 1-based
                int idx = Integer.valueOf(lineNumberEnd) - 1;
                int spaces = LineNumberHelper.leadingSpaces(lines, idx);

                line3 = LineNumberHelper.padString(line3, spaces + 2);
                line2 = LineNumberHelper.padString(line2, spaces + 4);
                line1 = LineNumberHelper.padString(line1, spaces + 2);

                // check if previous line is empty or not
                String text = lines.get(idx - 1);
                boolean emptyLine = text == null || text.trim().isEmpty();

                lines.add(idx, "");
                lines.add(idx, line3);
                lines.add(idx, line2);
                lines.add(idx, line1);
                if (!emptyLine) {
                    // insert empty lines around the added route (if needed to avoid 2x empty lines)
                    lines.add(idx, "");
                }

                // and save the file back
                String content = LineNumberHelper.linesToString(lines);
                file.setContents(content);
            }
            return Results.success("Added route");
        }
        return Results.fail("Cannot find Camel node in XML file: " + xml);
    } else {
        return Results.fail("Could not load camel XML");
    }
}
 
Example 18
Source File: SpringBootSetupFlow.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public Result execute(UIExecutionContext uiExecutionContext) throws Exception {
    return Results.success();
}
 
Example 19
Source File: DevOpsPipelineCommand.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    return Results.success();
}
 
Example 20
Source File: AddFromOrToEndpointXmlStep.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@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);

            LOG.info("Add endpoint at line number " + lineNumber + "-" + lineNumberEnd + " at selected node " + selectedNode.getNodeName());

            if (lineNumber != null && lineNumberEnd != null) {

                String line;
                if (isFrom) {
                    line = String.format("<from uri=\"%s\"/>", uri);
                } else {
                    line = String.format("<to uri=\"%s\"/>", uri);
                }

                // read all the lines
                List<String> lines = LineNumberHelper.readLines(file.getResourceInputStream());

                // the list is 0-based, and line number is 1-based
                // if from then use the start line number, otherwise use the end line number
                int idx = isFrom ? Integer.valueOf(lineNumber) : Integer.valueOf(lineNumberEnd);
                // use the same indent from the parent line
                int spaces = LineNumberHelper.leadingSpaces(lines, idx - 1);
                if (isFrom) {
                    // and append 2 if we are starting a new route with <from>
                    spaces += 2;
                }
                line = LineNumberHelper.padString(line, spaces);
                // add the line at the position
                lines.add(idx, line);

                // and save the file back
                String content = LineNumberHelper.linesToString(lines);
                file.setContents(content);
                return Results.success("Added: " + line.trim());
            }
        }
        return Results.fail("Cannot find Camel node in XML file: " + key);
    } else {
        return Results.fail("Cannot load Camel XML file: " + file.getName());
    }
}