private void printGeneralHelp(final PipeOut out) { out.println("Welcome to " + out.renderColor(ShellColor.YELLOW, "JBoss Forge") + ", a next-generation " + "interactive Shell and project-generation tool. If you find yourself lost, or uncertain how " + "to complete an operation, you may press the " + out.renderColor(ShellColor.BOLD, "<TAB>") + " key for command-completion, or " + out.renderColor(ShellColor.BOLD, "<TAB><TAB>") + " for hints while typing a command."); out.println(); out.println("Type " + out.renderColor(ShellColor.BOLD, "'list-commands'") + " for a list of available " + "commands in the current Resource context."); out.println(); Project currentProject = shell.getCurrentProject(); if (currentProject != null) { out.println("Currently operating on the Project located at [" + currentProject.getProjectRoot().getFullyQualifiedName() + "]"); } else { out.println("You are not working on a project. Type " + out.renderColor(ShellColor.BOLD, "'help new-project'") + " to get started."); } }
@DefaultCommand public void about(final PipeOut out) { out.println(" _____ "); out.println(" | ___|__ _ __ __ _ ___ "); out.println(" | |_ / _ \\| `__/ _` |/ _ \\ " + out.renderColor(ShellColor.YELLOW, "\\\\")); out.println(" | _| (_) | | | (_| | __/ " + out.renderColor(ShellColor.YELLOW, "//")); out.println(" |_| \\___/|_| \\__, |\\___| "); out.println(" |___/ "); out.println(""); out.print(ShellColor.ITALIC, "JBoss Forge"); out.print(", version [ "); out.print(ShellColor.BOLD, environment.getRuntimeVersion()); out.print(" ] - JBoss, by "); out.print(ShellColor.RED, "Red Hat, Inc."); out.println(" [ http://forge.jboss.org ]"); }
@Command("list-alternatives") public void listAlternatives(final PipeOut out) { CDIFacet cdi = project.getFacet(CDIFacet.class); List<String> classes = cdi.getConfig().getAlternativeClasses(); List<String> stereotypes = cdi.getConfig().getAlternativeStereotypes(); if (!out.isPiped()) out.println(ShellColor.BOLD, "Stereotypes:"); for (String s : stereotypes) { out.println(s); } if (!out.isPiped()) out.println(ShellColor.BOLD, "Classes:"); for (String c : classes) { out.println(c); } }
@DefaultCommand(help = "Prints all Java system property information.") public void info(final PipeOut out) { for (Entry<Object, Object> entry : System.getProperties().entrySet()) { if (entry.getKey().toString().startsWith("java")) { out.print(ShellColor.BOLD, entry.getKey().toString() + ": "); out.println(entry.getValue().toString()); } } }
@DefaultCommand public void show(final PipeOut out) { String version = environment.getRuntimeVersion(); out.println("JBoss Forge, version [ " + version + " ] - JBoss, by Red Hat, Inc. [ http://jboss.org/forge ]"); } }
out.print(JavaColorizer.format(out, ((JavaResource) resource).getJavaSource().toString())); if (!out.isPiped()) out.println(); out.println(ShellColor.RED, "[fields]"); String entry = out.renderColor(ShellColor.BLUE, field.getVisibility().scope()); entry += out.renderColor(ShellColor.GREEN, DELIM + field.getType() + ""); entry += DELIM + field.getName() + ";"; output.add(entry); if (out.isPiped()) out.println(); if (!out.isPiped()) out.println(ShellColor.RED, "[methods]"); String entry = out.renderColor(ShellColor.BLUE, method.getVisibility().scope()); String parameterString = "("; entry += out.renderColor(ShellColor.GREEN, DELIM + returnType + ""); output.add(entry); if (out.isPiped()) out.println();
@Override public String format(final int column, final String value) { return value.endsWith("*") ? pipeOut.renderColor(ShellColor.BOLD, value) : value; } };
private static String writeOutToConsole(InputStream istream, PipeOut out) throws IOException { byte[] buf = new byte[10]; int read; String s = null; while ((read = istream.read(buf)) != -1) { out.print(s = new String(buf, 0, read)); } return s; } }
private void displaySkippingResourceMsg(final PipeOut out, final JavaSource<?> entity) { if (!out.isPiped()) { ShellMessages.info(out, "Skipped non-@Entity Java resource [" + entity.getQualifiedName() + "]"); } } }
@DefaultCommand public void set(final PipeOut out, @Option(help = "The alias definition: E.g: 'ls=ls -a'") final String[] tokens) { if ((tokens != null) && (tokens.length > 0)) { String definition = Strings.join(Arrays.asList(tokens), " "); if (definition.contains("=")) { String alias = definition.substring(0, definition.indexOf("=")).trim(); String command = definition.substring(definition.indexOf("=") + 1).trim(); registry.createAlias(alias, command); } } else { for (Entry<String, String> alias : registry.getAliases().entrySet()) { out.println(alias.getKey() + " = " + alias.getValue()); } } } }
@Command("list-properties") public void listProps(final PipeOut out) { DependencyFacet deps = project.getFacet(DependencyFacet.class); Map<String, String> properties = deps.getProperties(); for (Entry<String, String> entry : properties.entrySet()) { out.print(entry.getKey() + "="); out.println(ShellColor.BLUE, entry.getValue()); } }
@Override public String format(int column, String value) { if (value.endsWith("/")) { return out.renderColor(ShellColor.BLUE, value); } else { return value; } } };
@DefaultCommand public void show(final PipeOut out) { FacesFacet facet = project.getFacet(FacesFacet.class); ShellMessages.info(out, "Displaying current JSF configuration:"); out.println(); out.println(out.renderColor(ShellColor.BOLD, "Project State: ") + facet.getProjectStage()); out.println(out.renderColor(ShellColor.BOLD, "FacesServlet Mappings: ") + facet.getEffectiveFacesServletMappings()); out.println(out.renderColor(ShellColor.BOLD, "Faces Default Suffixes: ") + facet.getFacesDefaultSuffixes()); out.println(out.renderColor(ShellColor.BOLD, "Facelets Default Suffixes: ") + facet.getFaceletsDefaultSuffixes()); out.println(out.renderColor(ShellColor.BOLD, "Facelets View Mappings: ") + facet.getFaceletsViewMapping()); }
@Command("list-facets") public void listFacets(PipeOut out) { Set<Class<? extends Facet>> facets = factory.getFacetTypes(); out.println(ShellColor.BOLD, "NOT INSTALLED"); for (Class<? extends Facet> type : facets) { String name = ConstraintInspector.getName(type); if (!project.hasFacet(type)) { out.println("- " + name + "\t[" + type.getName() + "]"); } } out.println(); out.println(ShellColor.BOLD, "INSTALLED"); for (Class<? extends Facet> type : facets) { String name = ConstraintInspector.getName(type); if (project.hasFacet(type) && !project.getFacet(type).isInstalled()) { out.println(ShellColor.RED, "? " + name + "\t[" + type.getName() + " - WARN: facet is no longer available]"); } else if (project.hasFacet(type)) { out.println(ShellColor.GREEN, "+ " + name + "\t[" + type.getName() + "]"); } } }
out.println(config.toString()); return; out.println(); out.println("[Public]"); out.print(out.renderColor(ShellColor.BOLD, "service: ")); out.println(service.getName()); out.print(out.renderColor(ShellColor.BOLD, " interface: ")); if (service.getInterface() != null) { out.println(service.getInterface().getInterface()); } else { out.println(out.renderColor(ShellColor.YELLOW, "inherited")); out.print(out.renderColor(ShellColor.BOLD, " binding: ")); out.println(binding.getType()); out.print(out.renderColor(ShellColor.BOLD, "reference: ")); out.println(reference.getName()); out.print(out.renderColor(ShellColor.BOLD, " interface: ")); if (reference.getInterface() != null) { out.println(reference.getInterface().getInterface()); } else { out.println(out.renderColor(ShellColor.YELLOW, "inherited")); out.print(out.renderColor(ShellColor.BOLD, " binding: ")); out.println(binding.getType()); out.println();
public static void downloadFromURL(final PipeOut out, final URL url, final FileResource<?> resource, boolean speak) throws IOException { HttpGet httpGetManifest = new HttpGet(url.toExternalForm()); if (speak) out.print("Retrieving artifact ... "); HttpResponse response = new DefaultHttpClient().execute(httpGetManifest); switch (response.getStatusLine().getStatusCode()) { case 200: if (speak) out.println("done."); try { resource.setContents(response.getEntity().getContent()); if (speak) out.println("done."); } catch (IOException e) { if (speak) out.println("failed to download: " + e.getMessage()); } default: if (speak) out.println("failed! (server returned status code: " + response.getStatusLine().getStatusCode()); } }
if (pipeOut.isPiped()) if (!pipeOut.isPiped()) pipeOut.println(); pipeOut.println(ShellColor.RED, "[" + entry.getKey().toUpperCase() + "]"); if (!pipeOut.isPiped()) pipeOut.println(); if (showAll) pipeOut.println("(* = command accessible from current context)"); pipeOut.println("(only commands in relevant scope displayed. use --all to see all commands.)");