List of usage examples for org.apache.commons.lang StringUtils rightPad
public static String rightPad(String str, int size)
Right pad a String with spaces (' ').
From source file:org.eclim.command.Main.java
public static void usage(String cmd, PrintStream out) { ArrayList<org.eclim.annotation.Command> commands = new ArrayList<org.eclim.annotation.Command>(); for (Class<? extends Command> command : Services.getCommandClasses()) { commands.add(command.getAnnotation(org.eclim.annotation.Command.class)); }// w w w .j ava 2 s .co m Collections.sort(commands, new Comparator<org.eclim.annotation.Command>() { public int compare(org.eclim.annotation.Command o1, org.eclim.annotation.Command o2) { return o1.name().compareTo(o2.name()); } }); boolean cmdFound = cmd == null; if (cmd == null) { String osOpts = StringUtils.EMPTY; if (SystemUtils.IS_OS_UNIX) { osOpts = " [-f eclimrc] [--nailgun-port port]"; } out.println("Usage: eclim" + osOpts + " -command command [args]"); out.println(" To view a full list of available commands:"); out.println(" eclim -? commands"); out.println(" To view info for a specific command:"); out.println(" eclim -? <command_name>"); out.println(" Ex."); out.println(" eclim -? project_create"); } else if (cmd.equals("commands")) { out.println("Available Commands:"); } else { out.println("Requested Command:"); } for (org.eclim.annotation.Command command : commands) { if (cmd == null || (!cmd.equals(command.name()) && !cmd.equals("commands"))) { continue; } cmdFound = true; Collection<Option> options = new Options().parseOptions(command.options()); StringBuffer opts = new StringBuffer(); Iterator<Option> iterator = options.iterator(); for (int ii = 0; iterator.hasNext(); ii++) { Option option = iterator.next(); opts.append(option.isRequired() ? " " : " ["); opts.append('-').append(option.getOpt()); if (option.hasArg()) { opts.append(' ').append(option.getLongOpt()); } if (!option.isRequired()) { opts.append(']'); } // wrap every 4 options if ((ii + 1) % 4 == 0 && ii != options.size() - 1) { opts.append(StringUtils.rightPad("\n", command.name().length() + 5)); } } StringBuffer info = new StringBuffer().append(" ").append(command.name()).append(opts); out.println(info); if (!command.description().equals(StringUtils.EMPTY)) { out.println(" " + command.description()); } } if (!cmdFound) { out.println(" No Such Command: " + cmd); } }
From source file:org.eclim.plugin.core.command.admin.PingCommand.java
/** * {@inheritDoc}/*w ww .jav a2s . c o m*/ */ public String execute(CommandLine commandLine) throws Exception { if (version == null) { PluginResources resources = Services.getPluginResources("org.eclim"); String eclim_name = "eclim"; String eclipse_name = "eclipse"; int pad = Math.max(eclim_name.length(), eclipse_name.length()); String eclim_version = StringUtils.rightPad(eclim_name, pad) + ' ' + resources.getProperty("pluginVersion"); String eclipse_version = getVersion(); eclipse_version = StringUtils.rightPad(eclipse_name, pad) + ' ' + eclipse_version; version = eclim_version + '\n' + eclipse_version; } return version; }
From source file:org.eclim.plugin.core.command.project.ProjectListCommand.java
/** * {@inheritDoc}/*from w ww . j av a2 s .com*/ */ public String execute(CommandLine commandLine) throws Exception { ArrayList<String> results = new ArrayList<String>(); IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); String natureId = null; if (commandLine.hasOption(Options.NATURE_OPTION)) { String alias = commandLine.getValue(Options.NATURE_OPTION); natureId = ProjectNatureFactory.getNatureForAlias(alias); ArrayList<IProject> filtered = new ArrayList<IProject>(); for (IProject project : projects) { if (project.isOpen() && project.hasNature(natureId)) { filtered.add(project); } } projects = (IProject[]) filtered.toArray(new IProject[filtered.size()]); } String open = Services.getMessage("project.status.open"); String closed = Services.getMessage("project.status.closed"); // pad status string int pad = Math.max(open.length(), closed.length()); closed = StringUtils.rightPad(closed, pad); open = StringUtils.rightPad(open, pad); // find longest project name for padding. int length = 0; for (int ii = 0; ii < projects.length; ii++) { String name = projects[ii].getName(); if (name.length() > length) { length = name.length(); } } for (int ii = 0; ii < projects.length; ii++) { if (projects[ii].exists()) { StringBuffer info = new StringBuffer().append(StringUtils.rightPad(projects[ii].getName(), length)) .append(" - ").append(projects[ii].isOpen() ? open : closed).append(" - ") .append(ProjectUtils.getPath(projects[ii])); results.add(info.toString()); } } return StringUtils.join(results, '\n'); }
From source file:org.eclim.plugin.core.command.project.ProjectNaturesCommand.java
/** * {@inheritDoc}/*from ww w .ja va 2 s . c om*/ */ public String execute(CommandLine commandLine) throws Exception { String name = commandLine.getValue(Options.PROJECT_OPTION); // list all projects. if (name == null) { ArrayList<String> results = new ArrayList<String>(); IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); // find longest project name for padding. int length = 0; for (IProject project : projects) { if (project.isOpen()) { name = project.getName(); if (name.length() > length) { length = name.length(); } } } for (IProject project : projects) { if (project.isOpen()) { String[] aliases = ProjectNatureFactory.getProjectNatureAliases(project); if (aliases.length == 0) { aliases = new String[] { "none" }; } StringBuffer info = new StringBuffer().append(StringUtils.rightPad(project.getName(), length)) .append(" - ").append(StringUtils.join(aliases, ' ')); results.add(info.toString()); } } return StringUtils.join((String[]) results.toArray(new String[results.size()]), '\n'); } // list for requested project. String[] aliases = ProjectNatureFactory.getProjectNatureAliases(ProjectUtils.getProject(name)); if (aliases.length == 0) { aliases = new String[] { "none" }; } return name + " - " + StringUtils.join(aliases, ' '); }
From source file:org.eclim.plugin.dltk.command.buildpath.BuildpathVariablesFilter.java
/** * {@inheritDoc}/*from w ww .j a va 2 s. co m*/ */ public String filter(CommandLine commandLine, List<BuildpathVariable> results) { StringBuffer buffer = new StringBuffer(); Collections.sort(results); int length = 0; for (BuildpathVariable variable : results) { length = variable.getName().length() > length ? variable.getName().length() : length; } for (BuildpathVariable variable : results) { if (buffer.length() > 0) { buffer.append('\n'); } buffer.append(StringUtils.rightPad(variable.getName(), length)).append(" - ") .append(variable.getPath()); } return buffer.toString(); }
From source file:org.eclim.plugin.jdt.command.classpath.ClasspathVariablesFilter.java
/** * {@inheritDoc}/*from ww w. j a v a2s . c om*/ */ public String filter(CommandLine commandLine, List<ClasspathVariable> results) { StringBuffer buffer = new StringBuffer(); Collections.sort(results); int length = 0; for (ClasspathVariable variable : results) { length = variable.getName().length() > length ? variable.getName().length() : length; } for (ClasspathVariable variable : results) { if (buffer.length() > 0) { buffer.append('\n'); } buffer.append(StringUtils.rightPad(variable.getName(), length)).append(" - ") .append(variable.getPath()); } return buffer.toString(); }
From source file:org.eclipse.jubula.tools.internal.utils.ZipUtil.java
/** * Extracts all JAR files from the given ZIP file into temporary JAR files. * The directory structure of the extracted contents is not maintained. * A mapping from ZIP file to extracted JARs is maintained by this class, * so multiple calls to this method for a single ZIP file will extract JAR * files once and return references to those files for each subsequent call. * The extracted JAR files are deleted on VM exit. * @param srcZip The ZIP file to extract. * @return all extracted files.// w ww . java 2 s .co m * @throws IOException */ public static File[] unzipTempJars(File srcZip) throws IOException { if (zipToTempJars.containsKey(srcZip)) { return zipToTempJars.get(srcZip); } IZipEntryFilter filter = new IZipEntryFilter() { public boolean accept(ZipEntry entry) { return entry.getName().toLowerCase().endsWith(JAR_FILE_EXT); } }; ZipFile archive = new ZipFile(srcZip); Enumeration e = archive.entries(); List<File> extractedFiles = new ArrayList<File>(); while (e.hasMoreElements()) { ZipEntry entry = (ZipEntry) e.nextElement(); if (filter.accept(entry)) { if (!entry.isDirectory()) { String prefix = entry.getName().substring(entry.getName().lastIndexOf("/") + 1, //$NON-NLS-1$ entry.getName().toLowerCase().lastIndexOf(JAR_FILE_EXT)); File file = File.createTempFile(StringUtils.rightPad(prefix, 3), JAR_FILE_EXT); extractedFiles.add(file); file.deleteOnExit(); unzipFile(archive, file, entry); } } } File[] files = extractedFiles.toArray(new File[extractedFiles.size()]); zipToTempJars.put(srcZip, files); return files; }
From source file:org.eclipse.jubula.tools.utils.ZipUtil.java
/** * Extracts all JAR files from the given ZIP file into temporary JAR files. * The directory structure of the extracted contents is not maintained. * A mapping from ZIP file to extracted JARs is maintained by this class, * so multiple calls to this method for a single ZIP file will extract JAR * files once and return references to those files for each subsequent call. * The extracted JAR files are deleted on VM exit. * @param srcZip The ZIP file to extract. * @return all extracted files.//from w ww. j a v a2s .com * @throws IOException */ public static File[] unzipTempJars(File srcZip) throws IOException { if (zipToTempJars.containsKey(srcZip)) { return (File[]) zipToTempJars.get(srcZip); } IZipEntryFilter filter = new IZipEntryFilter() { public boolean accept(ZipEntry entry) { return entry.getName().toLowerCase().endsWith(JAR_FILE_EXT); } }; ZipFile archive = new ZipFile(srcZip); Enumeration e = archive.entries(); List extractedFiles = new ArrayList(); while (e.hasMoreElements()) { ZipEntry entry = (ZipEntry) e.nextElement(); if (filter.accept(entry)) { if (!entry.isDirectory()) { String prefix = entry.getName().substring(entry.getName().lastIndexOf("/") + 1, //$NON-NLS-1$ entry.getName().toLowerCase().lastIndexOf(JAR_FILE_EXT)); File file = File.createTempFile(StringUtils.rightPad(prefix, 3), JAR_FILE_EXT); extractedFiles.add(file); file.deleteOnExit(); unzipFile(archive, file, entry); } } } File[] files = (File[]) extractedFiles.toArray(new File[extractedFiles.size()]); zipToTempJars.put(srcZip, files); return files; }
From source file:org.ejbca.ui.cli.service.ServiceInfoCommand.java
/** Displays "name: value" with proper alignment */ private void info(String name, String value) { if (value == null) { value = "null"; }/*from w w w . ja va 2 s .com*/ value = value.replaceAll("\r?\n", "\n" + StringUtils.repeat(" ", 15)); getLogger().info(StringUtils.rightPad(name, 13) + ": " + value); }
From source file:org.ejbca.ui.cli.service.ServiceListCommand.java
@Override public CommandResult execute(ParameterContainer parameters) { final ServiceSessionRemote serviceSession = EjbRemoteHelper.INSTANCE .getRemoteSession(ServiceSessionRemote.class); Collection<Integer> availableServicesIds = serviceSession .getAuthorizedVisibleServiceIds(getAuthenticationToken()); if (availableServicesIds.size() == 0) { getLogger().info("No services are available."); return CommandResult.SUCCESS; }/*from w w w . j a v a2 s . c om*/ getLogger().info("Actv| Service name | Worker | Interval | Action "); getLogger().info("----+-----------------+------------------+------------------+------------------"); for (Integer serviceId : availableServicesIds) { StringBuilder row = new StringBuilder(); ServiceConfiguration serviceConfig = serviceSession.getServiceConfiguration(getAuthenticationToken(), serviceId); // Active row.append(serviceConfig.isActive() ? " X |" : " |"); // Name row.append(' '); String serviceName = serviceSession.getServiceName(serviceId.intValue()); row.append(StringUtils.rightPad(StringUtils.abbreviate(serviceName, 15), 16)); row.append('|'); // Class paths addClassPath(row, serviceConfig.getWorkerClassPath()); row.append('|'); addClassPath(row, serviceConfig.getIntervalClassPath()); row.append('|'); addClassPath(row, serviceConfig.getActionClassPath()); getLogger().info(row.toString()); } return CommandResult.SUCCESS; }