tizen-cli

16:53:29.687 INFO  jd.cli.Main - Decompiling tizen-cli.jar
package org.tizen.cli.command;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractCommand
  implements CommandWithParameter
{
  protected Logger logger = LoggerFactory.getLogger(getClass());
}

/* Location:
 * Qualified Name:     org.tizen.cli.command.AbstractCommand
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.cli.command;

import org.tizen.common.core.command.ExecutionContext;

public abstract interface CommandWithParameter
{
  public abstract void process(ExecutionContext paramExecutionContext, String[] paramArrayOfString)
    throws Exception;
}

/* Location:
 * Qualified Name:     org.tizen.cli.command.CommandWithParameter
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.cli.command;

import java.io.IOException;
import java.util.HashMap;
import org.slf4j.Logger;
import org.tizen.cli.util.TemplateModelProvider;
import org.tizen.common.core.command.ExecutionContext;
import org.tizen.common.core.command.Prompter;
import org.tizen.common.verrari.Realm;
import org.tizen.common.verrari.Storage;
import org.tizen.common.verrari.Template;
import org.tizen.common.verrari.TemplateContext;
import org.tizen.common.verrari.TemplateException;
import org.tizen.common.verrari.realm.CommonRealm;
import org.tizen.common.verrari.storage.FileStorage;

public class CreateTemplate
  extends AbstractCommand
  implements CommandWithParameter
{
  public void process(ExecutionContext context, String[] args)
    throws IOException, TemplateException
  {
    if ((null == args) || (0 == args.length))
    {
      context.getPrompter().error("One more template id required.");
      return;
    }
    Realm realm = (Realm)context.getValue("pic.template.realm");
    
    FileStorage storage = new FileStorage(context.getFileHandler());
    
    TemplateModelProvider models = new TemplateModelProvider(context);
    
    TemplateContext.getInstance().setModelProvider(models);
    try
    {
      template(realm, args, models, storage);
    }
    finally
    {
      TemplateContext.clear();
    }
  }
  
  protected void template(Realm realm, String[] names, TemplateModelProvider models, Storage storage)
    throws IOException, TemplateException
  {
    HashMap<String, Template> ret = new HashMap();
    
    template(realm, names, models, storage, ret);
  }
  
  protected void template(Realm realm, String[] names, TemplateModelProvider models, Storage storage, HashMap<String, Template> cache)
    throws IOException, TemplateException
  {
    for (String name : names)
    {
      logger.trace("Template name :{}", name);
      
      ExecutionContext.getCurrentContext().setValue("id", name);
      
      Template template = (Template)cache.get(name);
      if (null == template)
      {
        logger.debug("{} not cached", name);
        template = realm.getTemplate(name);
      }
      cache.put(name, template);
      template.template(models, storage);
      String[] dependencies = CommonRealm.separate(template.getAttribute("Tizen-Template-Dependency"));
      if (null != dependencies) {
        template(realm, dependencies, models, storage, cache);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.tizen.cli.command.CreateTemplate
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.cli.command;

public class PluginConstants
{
  public static final String OBSERVER = "pic.file.observer";
  public static final String PLUGINS = "pic.server.plugin";
  public static final String REALM = "pic.template.realm";
  public static final String PROP_DOCBASE = "document.base";
  public static final String PROP_CWD = "user.dir";
}

/* Location:
 * Qualified Name:     org.tizen.cli.command.PluginConstants
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.cli.command;

import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.TreeSet;
import org.tizen.common.core.command.ExecutionContext;
import org.tizen.common.core.command.Prompter;
import org.tizen.common.util.CollectionUtil;
import org.tizen.common.util.StringUtil;
import org.tizen.common.verrari.AttributeContainer;
import org.tizen.common.verrari.Condition;
import org.tizen.common.verrari.Condition.Operation;
import org.tizen.common.verrari.Realm;
import org.tizen.common.verrari.SearchableRealm;

public class SearchTemplate
  extends AbstractCommand
  implements CommandWithParameter
{
  protected void search(Realm realm, ExecutionContext context, String[] args)
    throws IOException
  {
    if (!(realm instanceof SearchableRealm))
    {
      context.getPrompter().error("Search unsupported realm.");
      return;
    }
    SearchableRealm searchable = (SearchableRealm)realm;
    String keyword = args[0];
    Collection<AttributeContainer> templates = searchable.search(new Condition(Condition.Operation.CaseInsensitiveContains, "keyword", keyword));
    if (CollectionUtil.isEmpty(templates))
    {
      context.getPrompter().notify("No template with '" + keyword + "'.");
      return;
    }
    TreeSet<String> sortTree = new TreeSet();
    for (AttributeContainer template : templates)
    {
      StringBuilder buffer = new StringBuilder();
      String name = template.getAttribute("Tizen-Template-Name");
      String desc = template.getAttribute("Tizen-Template-Description");
      String version = template.getAttribute("Tizen-Template-Version");
      
      buffer.append(name);
      if (!StringUtil.isEmpty(version))
      {
        buffer.append(" ( ");
        buffer.append(version);
        buffer.append(" ) ");
      }
      buffer.append(" - ");
      if (StringUtil.isEmpty(desc)) {
        buffer.append("undescribed");
      } else {
        buffer.append(desc);
      }
      sortTree.add(buffer.toString());
    }
    Iterator<String> iter = sortTree.iterator();
    while (iter.hasNext()) {
      context.getPrompter().notify((String)iter.next() + ".");
    }
  }
  
  public void process(ExecutionContext context, String[] args)
    throws IOException
  {
    if ((null == args) || (0 == args.length))
    {
      context.getPrompter().error("A keyword required.");
      return;
    }
    Realm realm = (Realm)context.getValue("pic.template.realm");
    search(realm, context, args);
  }
}

/* Location:
 * Qualified Name:     org.tizen.cli.command.SearchTemplate
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.cli.exec;

import java.io.IOException;
import java.io.OutputStream;

class AbstractLauncher$1
  extends OutputStream
{
  AbstractLauncher$1(AbstractLauncher paramAbstractLauncher) {}
  
  public void write(int b)
    throws IOException
  {}
}

/* Location:
 * Qualified Name:     org.tizen.cli.exec.AbstractLauncher.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.cli.exec;

import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URL;
import java.nio.charset.Charset;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Properties;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tizen.common.config.Preference;
import org.tizen.common.config.provider.EnvironmentProvider;
import org.tizen.common.config.provider.SystemPropertiesProvider;
import org.tizen.common.core.command.ExecutionContext;
import org.tizen.common.core.command.Executor;
import org.tizen.common.core.command.Prompter;
import org.tizen.common.core.command.policy.PolicyRegistry;
import org.tizen.common.file.FileHandler;
import org.tizen.common.file.FileHandler.Attribute;
import org.tizen.common.util.CollectionUtil;
import org.tizen.common.util.IOUtil;
import org.tizen.common.util.MapUtil;
import org.tizen.common.util.OSChecker;
import org.tizen.common.util.PropertyUtil;
import org.tizen.common.util.StringUtil;

public abstract class AbstractLauncher
{
  protected static final String OPT_HELP = "help";
  protected static final String DESC_HELP = "Print out this page";
  protected static final String OPT_LOG = "log";
  protected static final String DESC_LOG = "Specify log category (error | warn | info | debug | trace)";
  protected static final String OPT_QUIET = "quiet";
  protected static final String DESC_QUIET = "Execute silently";
  protected static final String PROP_PARSER = "tizen.cli.parser";
  protected static final String SUFFIX_CONFIG = ".properties";
  protected final Logger logger = LoggerFactory.getLogger(getClass());
  protected Help help;
  protected CommandLine cmd;
  protected Executor executor;
  protected String inputCmd = "";
  
  protected String convertPath(String path)
    throws IOException
  {
    String target = path;
    if ((!OSChecker.isWindows()) && (target.startsWith("~" + File.separator))) {
      target = path.replaceFirst("~", System.getProperty("user.home"));
    }
    FileHandler fileHandler = getFileHandler();
    return (String)fileHandler.get(target, FileHandler.Attribute.PATH);
  }
  
  protected String getSyntax()
  {
    return getHelp().getSyntax();
  }
  
  protected Options getOptions()
  {
    Options options = new Options();
    
    OptionBuilder.withLongOpt("help");OptionBuilder.withDescription("Print out this page");options.addOption(OptionBuilder.create("help".substring(0, 1)));
    OptionBuilder.hasArg();OptionBuilder.withLongOpt("log");OptionBuilder.withDescription("Specify log category (error | warn | info | debug | trace)");options.addOption(OptionBuilder.create("log".substring(0, 1)));
    OptionBuilder.withLongOpt("quiet");OptionBuilder.withDescription("Execute silently");options.addOption(OptionBuilder.create("quiet".substring(0, 1)));
    
    return options;
  }
  
  protected Options getCommands()
  {
    Options options = new Options();
    return options;
  }
  
  protected Help createHelp()
  {
    return new Help(getOptions());
  }
  
  protected synchronized Help getHelp()
  {
    if (null == help)
    {
      help = createHelp();
      ClassLoader cl = getClass().getClassLoader();
      String resourceName = getClass().getName().replace('.', '/') + ".properties";
      
      logger.trace("Resource name :{}", resourceName);
      try
      {
        Enumeration<URL> iter = cl.getResources(resourceName);
        Properties properties;
        while (iter.hasMoreElements())
        {
          URL url = (URL)iter.nextElement();
          logger.trace("URL :{}", url);
          properties = PropertyUtil.loadProperties(url.openStream());
          logger.debug("Properties :{}", properties);
          for (Object key : properties.keySet())
          {
            String value = properties.getProperty((String)key);
            byte[] contents = IOUtil.getBytes(cl.getResourceAsStream(value), true);
            help.addHelpDetail((String)key, new String(contents, Charset.forName("utf8")));
          }
        }
      }
      catch (IOException e)
      {
        logger.warn("Can't load help", e);
      }
    }
    return help;
  }
  
  protected String printHelpDetail(String option)
  {
    String detailStr = getHelp().getHelpDetail(option);
    getPrompter().error(detailStr);
    return detailStr;
  }
  
  protected String printHelp()
  {
    String helpStr = getHelp().getHelp();
    getPrompter().error(helpStr);
    return helpStr;
  }
  
  protected String printError(String msg)
  {
    String errorStr = "E: Invalid usage";
    if (!StringUtil.isEmpty(msg)) {
      errorStr = MessageFormat.format("E: Invalid usage [{0}]", new Object[] { msg });
    }
    getPrompter().error(errorStr);
    return errorStr;
  }
  
  public void run(String... args)
    throws Exception
  {
    Preference.register("OS", new EnvironmentProvider());
    Preference.register("JVM", new SystemPropertiesProvider());
    executor = new CommandLineExecutor(new ConsolePrompter(System.out, new InputStreamReader(System.in)));
    if (logger.isTraceEnabled())
    {
      logger.trace("OS Environment :\n{}", MapUtil.toString(System.getenv()));
      logger.trace("System properties :\n{}", MapUtil.toString(System.getProperties()));
      logger.trace("Args :{}", CollectionUtil.concatenate(Arrays.asList(args), ","));
    }
    try
    {
      Options cmds = getCommands();
      if ((args.length == 0) && (isPrintHelp()))
      {
        printHelp();
        return;
      }
      if ((cmds.getOptions().size() > 0) && (args.length > 0) && (cmds.hasOption(args[0])))
      {
        inputCmd = args[0];
        String[] newArgs = (String[])Arrays.copyOfRange(args, 1, args.length);
        cmd = parse(newArgs);
      }
      else
      {
        cmd = parse(args);
      }
      if (cmd.hasOption("quiet")) {
        executor = new CommandLineExecutor(new ConsolePrompter(new PrintStream(new OutputStream()
        {
          public void write(int b)
            throws IOException
          {}
        }), new InputStreamReader(System.in)));
      }
      if (cmd.hasOption("help"))
      {
        printHelp();
        
        logger.debug("Help argument :{}", cmd.getArgList());
        for (String keyword : cmd.getArgs()) {
          printHelpDetail(keyword);
        }
        return;
      }
      execute(cmd);
    }
    catch (ParseException e)
    {
      logger.error("Parsing Error: ", e);
      logger.trace("Invalid usage.");
      
      boolean bPrintHelp = false;
      for (String arg : args) {
        if ((("-" + "help".substring(0, 1)).equals(arg)) || ("--help".equals(arg)))
        {
          printHelp();
          bPrintHelp = true;
          break;
        }
      }
      if (!bPrintHelp) {
        printError(e.getMessage());
      }
      if (null != cmd)
      {
        logger.debug("Help argument :{}", cmd.getArgList());
        for (String keyword : cmd.getArgs()) {
          printHelpDetail(keyword);
        }
      }
    }
    catch (Throwable e)
    {
      handleException(e);
    }
  }
  
  protected String getInputCmd()
  {
    return inputCmd;
  }
  
  protected void handleException(Throwable e)
  {
    getPrompter().error(e.getMessage());
    logger.error("Command stop because of exception", e);
    
    Throwable iter = e;
    while (null != iter)
    {
      String localMessage = iter.getLocalizedMessage();
      if (null != localMessage)
      {
        logger.error(localMessage);
        exit(1);
      }
      String message = iter.getMessage();
      if (null != message)
      {
        logger.error(message);
        exit(1);
      }
      iter = iter.getCause();
    }
  }
  
  protected CommandLine parse(String... args)
    throws InstantiationException, IllegalAccessException, ParseException
  {
    CommandLineParser parser = getParser();
    
    Options options = getOptions();
    
    CommandLine cmdLine = parser.parse(options, args);
    
    return cmdLine;
  }
  
  protected static Class<?> getDefaultParserClass()
  {
    return PosixParser.class;
  }
  
  protected CommandLineParser getParser()
    throws InstantiationException, IllegalAccessException
  {
    String parserName = System.getProperty("tizen.cli.parser");
    logger.trace("Parser name :{}", parserName);
    Class<?> parserClazz = getDefaultParserClass();
    try
    {
      if (null != parserName) {
        parserClazz = Class.forName(parserName);
      }
    }
    catch (ClassNotFoundException e)
    {
      if ("posix".equalsIgnoreCase(parserName)) {
        parserClazz = PosixParser.class;
      } else if ("gnu".equalsIgnoreCase(parserName)) {
        parserClazz = GnuParser.class;
      } else {
        logger.warn("Invalid argument parser :" + parserName);
      }
    }
    logger.trace("Parser class :{}", parserClazz);
    
    return (CommandLineParser)parserClazz.newInstance();
  }
  
  protected CommandLine getCommandLine()
  {
    return cmd;
  }
  
  protected Executor getExecutor()
  {
    if (null == executor) {
      executor = new Executor();
    }
    return executor;
  }
  
  protected ExecutionContext getExecutionContext()
  {
    return getExecutor().getContext();
  }
  
  protected PolicyRegistry getPolicy()
  {
    return getExecutionContext().getPolicyRegistry();
  }
  
  protected FileHandler getFileHandler()
  {
    return getExecutionContext().getFileHandler();
  }
  
  protected Prompter getPrompter()
  {
    return getExecutionContext().getPrompter();
  }
  
  protected boolean isPrintHelp()
  {
    return false;
  }
  
  protected String getUsageDescription()
  {
    return "";
  }
  
  protected void exit(int status)
  {
    System.exit(status);
  }
  
  protected abstract void execute(CommandLine paramCommandLine)
    throws Exception;
}

/* Location:
 * Qualified Name:     org.tizen.cli.exec.AbstractLauncher
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.cli.exec;

import java.text.MessageFormat;
import org.tizen.common.Factory;
import org.tizen.common.core.command.ExecutionContext;
import org.tizen.common.core.command.Prompter;
import org.tizen.common.core.command.policy.PolicyRegistry;
import org.tizen.common.file.FileHandler;
import org.tizen.common.file.StandardFileHandler;

class CommandLineExecutor$1
  implements Factory<ExecutionContext>
{
  protected FileHandler fileHandler = new StandardFileHandler();
  protected Factory<PolicyRegistry> factory = new PolicyRegistryFactory();
  
  CommandLineExecutor$1(Prompter paramPrompter) {}
  
  protected PolicyRegistry getRegistry()
  {
    return (PolicyRegistry)factory.create();
  }
  
  protected final ExecutionContext context = new ExecutionContext(getRegistry(), val$prompter, fileHandler);
  
  public ExecutionContext create()
  {
    return context;
  }
  
  public String toString()
  {
    return MessageFormat.format("Policy :{0}, Prompter :{1}, File Handler :{2}", new Object[] { context.getPolicyRegistry(), context.getPrompter(), context.getFileHandler() });
  }
}

/* Location:
 * Qualified Name:     org.tizen.cli.exec.CommandLineExecutor.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.cli.exec;

import java.text.MessageFormat;
import org.tizen.common.Factory;
import org.tizen.common.core.command.ExecutionContext;
import org.tizen.common.core.command.Executor;
import org.tizen.common.core.command.Prompter;
import org.tizen.common.core.command.policy.PolicyRegistry;
import org.tizen.common.file.FileHandler;
import org.tizen.common.file.StandardFileHandler;

public class CommandLineExecutor
  extends Executor
{
  public CommandLineExecutor(Prompter prompter)
  {
    super(new Factory()
    {
      protected FileHandler fileHandler = new StandardFileHandler();
      protected Factory<PolicyRegistry> factory = new PolicyRegistryFactory();
      
      protected PolicyRegistry getRegistry()
      {
        return (PolicyRegistry)factory.create();
      }
      
      protected final ExecutionContext context = new ExecutionContext(getRegistry(), CommandLineExecutor.this, fileHandler);
      
      public ExecutionContext create()
      {
        return context;
      }
      
      public String toString()
      {
        return MessageFormat.format("Policy :{0}, Prompter :{1}, File Handler :{2}", new Object[] { context.getPolicyRegistry(), context.getPrompter(), context.getFileHandler() });
      }
    });
  }
}

/* Location:
 * Qualified Name:     org.tizen.cli.exec.CommandLineExecutor
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.cli.exec;

import java.io.BufferedReader;
import java.io.Console;
import java.io.PrintStream;
import java.io.Reader;
import java.util.Collection;
import java.util.Map;
import org.slf4j.Logger;
import org.tizen.common.core.command.Prompter;
import org.tizen.common.core.command.UserField;
import org.tizen.common.core.command.prompter.AbstractPrompter;
import org.tizen.common.core.command.prompter.ChoiceOption;
import org.tizen.common.core.command.prompter.GenericOption;
import org.tizen.common.core.command.prompter.Option;
import org.tizen.common.util.Assert;
import org.tizen.common.util.CollectionUtil;
import org.tizen.common.util.StringUtil;

public class ConsolePrompter
  extends AbstractPrompter
  implements Prompter
{
  protected final PrintStream out;
  protected final BufferedReader reader;
  
  public ConsolePrompter(PrintStream out, Reader reader)
  {
    Assert.notNull(out);
    this.out = out;
    this.reader = new BufferedReader(reader);
  }
  
  /* Error */
  public Option interact(String question, Option... options)
  {
    // Byte code:
    //   0: new 7	java/util/LinkedHashSet
    //   3: dup
    //   4: invokespecial 8	java/util/LinkedHashSet:<init>	()V
    //   7: astore_3
    //   8: aconst_null
    //   9: astore 4
    //   11: new 9	java/util/ArrayList
    //   14: dup
    //   15: invokespecial 10	java/util/ArrayList:<init>	()V
    //   18: astore 5
    //   20: aload_2
    //   21: astore 6
    //   23: aload 6
    //   25: arraylength
    //   26: istore 7
    //   28: iconst_0
    //   29: istore 8
    //   31: iload 8
    //   33: iload 7
    //   35: if_icmpge +103 -> 138
    //   38: aload 6
    //   40: iload 8
    //   42: aaload
    //   43: astore 9
    //   45: aload_3
    //   46: aload 9
    //   48: invokevirtual 11	java/util/HashSet:contains	(Ljava/lang/Object;)Z
    //   51: ifeq +31 -> 82
    //   54: new 12	java/lang/IllegalArgumentException
    //   57: dup
    //   58: new 13	java/lang/StringBuilder
    //   61: dup
    //   62: invokespecial 14	java/lang/StringBuilder:<init>	()V
    //   65: ldc 15
    //   67: invokevirtual 16	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   70: aload 9
    //   72: invokevirtual 17	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   75: invokevirtual 18	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   78: invokespecial 19	java/lang/IllegalArgumentException:<init>	(Ljava/lang/String;)V
    //   81: athrow
    //   82: aload 5
    //   84: aload 9
    //   86: invokeinterface 20 1 0
    //   91: invokevirtual 21	java/util/ArrayList:add	(Ljava/lang/Object;)Z
    //   94: pop
    //   95: aload_3
    //   96: aload 9
    //   98: invokevirtual 22	java/util/HashSet:add	(Ljava/lang/Object;)Z
    //   101: pop
    //   102: aload 9
    //   104: invokeinterface 23 1 0
    //   109: ifeq +23 -> 132
    //   112: aconst_null
    //   113: aload 4
    //   115: if_acmpeq +13 -> 128
    //   118: new 12	java/lang/IllegalArgumentException
    //   121: dup
    //   122: ldc 24
    //   124: invokespecial 19	java/lang/IllegalArgumentException:<init>	(Ljava/lang/String;)V
    //   127: athrow
    //   128: aload 9
    //   130: astore 4
    //   132: iinc 8 1
    //   135: goto -104 -> 31
    //   138: aconst_null
    //   139: astore 6
    //   141: aload_0
    //   142: aload_1
    //   143: aload_2
    //   144: invokevirtual 25	org/tizen/cli/exec/ConsolePrompter:printQuestion	(Ljava/lang/String;[Lorg/tizen/common/core/command/prompter/Option;)V
    //   147: aload_0
    //   148: getfield 6	org/tizen/cli/exec/ConsolePrompter:reader	Ljava/io/BufferedReader;
    //   151: invokevirtual 26	java/io/BufferedReader:readLine	()Ljava/lang/String;
    //   154: astore 6
    //   156: aload 6
    //   158: invokestatic 27	org/tizen/common/util/StringUtil:isEmpty	(Ljava/lang/CharSequence;)Z
    //   161: ifeq +6 -> 167
    //   164: aload 4
    //   166: areturn
    //   167: aload_2
    //   168: astore 7
    //   170: aload 7
    //   172: arraylength
    //   173: istore 8
    //   175: iconst_0
    //   176: istore 9
    //   178: iload 9
    //   180: iload 8
    //   182: if_icmpge +31 -> 213
    //   185: aload 7
    //   187: iload 9
    //   189: aaload
    //   190: astore 10
    //   192: aload 10
    //   194: aload 6
    //   196: invokeinterface 28 2 0
    //   201: ifeq +6 -> 207
    //   204: aload 10
    //   206: areturn
    //   207: iinc 9 1
    //   210: goto -32 -> 178
    //   213: goto -72 -> 141
    //   216: astore 7
    //   218: new 30	java/lang/IllegalStateException
    //   221: dup
    //   222: aload 7
    //   224: invokespecial 31	java/lang/IllegalStateException:<init>	(Ljava/lang/Throwable;)V
    //   227: athrow
    // Line number table:
    //   Java source line #106	-> byte code offset #0
    //   Java source line #107	-> byte code offset #8
    //   Java source line #108	-> byte code offset #11
    //   Java source line #109	-> byte code offset #20
    //   Java source line #111	-> byte code offset #45
    //   Java source line #113	-> byte code offset #54
    //   Java source line #115	-> byte code offset #82
    //   Java source line #116	-> byte code offset #95
    //   Java source line #117	-> byte code offset #102
    //   Java source line #119	-> byte code offset #112
    //   Java source line #121	-> byte code offset #118
    //   Java source line #126	-> byte code offset #128
    //   Java source line #109	-> byte code offset #132
    //   Java source line #130	-> byte code offset #138
    //   Java source line #135	-> byte code offset #141
    //   Java source line #137	-> byte code offset #147
    //   Java source line #138	-> byte code offset #156
    //   Java source line #140	-> byte code offset #164
    //   Java source line #142	-> byte code offset #167
    //   Java source line #144	-> byte code offset #192
    //   Java source line #146	-> byte code offset #204
    //   Java source line #142	-> byte code offset #207
    //   Java source line #150	-> byte code offset #216
    //   Java source line #152	-> byte code offset #218
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	228	0	this	ConsolePrompter
    //   0	228	1	question	String
    //   0	228	2	options	Option[]
    //   7	89	3	reducedOptions	java.util.HashSet<Option>
    //   9	156	4	defaultOption	Option
    //   18	65	5	optionNames	java.util.ArrayList<String>
    //   21	18	6	arr$	Option[]
    //   139	56	6	choice	String
    //   26	8	7	len$	int
    //   168	18	7	arr$	Option[]
    //   216	7	7	e	java.io.IOException
    //   29	104	8	i$	int
    //   173	8	8	len$	int
    //   43	86	9	option	Option
    //   176	32	9	i$	int
    //   190	15	10	option	Option
    // Exception table:
    //   from	to	target	type
    //   141	166	216	java/io/IOException
    //   167	206	216	java/io/IOException
    //   207	216	216	java/io/IOException
  }
  
  protected void printQuestion(String question, Option... options)
  {
    out.print(getFullQuestion(question, options));
  }
  
  private char[] getFullQuestion(String question, Option[] options)
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append(question + "\n");
    
    int len = options.length - 1;
    for (int i = 0; i < len; i++) {
      if ((options[i] instanceof ChoiceOption))
      {
        ChoiceOption choiceOption = (ChoiceOption)options[i];
        buffer.append(String.format("%s: (%s), ", new Object[] { choiceOption.getName(), choiceOption.getShortName() }));
      }
    }
    if ((options[len] instanceof ChoiceOption))
    {
      ChoiceOption choiceOption = (ChoiceOption)options[len];
      buffer.append(String.format("%s: (%s) ", new Object[] { choiceOption.getName(), choiceOption.getShortName() }));
    }
    buffer.append("?");
    
    return buffer.toString().toCharArray();
  }
  
  public void notify(String message)
  {
    out.println(message);
  }
  
  public void cancel() {}
  
  public Object password(String message)
  {
    out.print(StringUtil.trim(message));
    out.print(" ");
    
    Console console = System.console();
    if (console != null) {
      return console.readPassword();
    }
    throw new IllegalStateException("Cannot get a console environment");
  }
  
  public void error(String message)
  {
    out.println(message);
  }
  
  public void batch(Collection<UserField> userFields, Map<String, Object> options)
  {
    batch(0, userFields);
  }
  
  protected void batch(int depth, Collection<UserField> fields)
  {
    for (UserField child : fields) {
      batch(depth, child);
    }
  }
  
  protected void batch(int depth, UserField field)
  {
    String msg = field.getMessage();
    
    Collection<Object> supports = field.getSupports();
    if ((null != supports) && (!supports.contains("console")))
    {
      logger.warn("{} is not supported in {}", field, this);
      return;
    }
    Class<?> type = field.getType();
    
    boolean bChild = true;
    if (field.canModify()) {
      if (String.class.equals(type))
      {
        GenericOption option = new GenericOption();
        interact(indent(depth, msg), new Option[] { option });
        if ((field.getValue() == null) || (!StringUtil.isEmpty(option.getAnswer()))) {
          field.setValue(option.getAnswer());
        }
      }
      else if ((char[].class.equals(type)) || (Character[].class.equals(type)))
      {
        field.setValue(password(indent(depth, msg)));
      }
      else if ((Boolean.TYPE.equals(type)) || (Boolean.class.equals(type)))
      {
        boolean initValue = null == field.getValue() ? true : ((Boolean)field.getValue()).booleanValue();
        ChoiceOption yes = new ChoiceOption("Yes", initValue);
        ChoiceOption no = new ChoiceOption("No", !initValue);
        Object opt = interact(indent(depth, msg), new Option[] { yes, no });
        bChild = yes.equals(opt);
        field.setValue(Boolean.valueOf(bChild));
      }
    }
    Collection<UserField> children = field.getChildren();
    if ((bChild) && (!CollectionUtil.isEmpty(children)))
    {
      notify(indent(depth, msg));
      batch(depth + 1, children);
    }
  }
  
  protected String indent(int depth, String msg)
  {
    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < depth; i++) {
      buffer.append(" ");
    }
    buffer.append(msg);
    return buffer.toString();
  }
}

/* Location:
 * Qualified Name:     org.tizen.cli.exec.ConsolePrompter
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.cli.exec;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tizen.common.util.FilenameUtil;
import org.tizen.common.util.StringUtil;

public class Help
{
  protected Logger logger = LoggerFactory.getLogger(getClass());
  protected static final String PROP_PRG = "cli.name";
  private static final String DEFAULT_SYNTAX = System.getProperty("cli.name") != null ? FilenameUtil.getTailingPath(System.getProperty("cli.name"), 1) : "";
  protected final Options opts;
  protected String syntax;
  protected HashMap<String, String> keyword2help = new HashMap();
  protected final Options cmds;
  protected final String inputCmd;
  protected final String usageDescription;
  
  public Help(Options opts)
  {
    this(opts, null, "", "");
  }
  
  public Help(Options opts, Options cmds, String inputCmd, String usageDes)
  {
    this.opts = opts;
    this.cmds = cmds;
    this.inputCmd = inputCmd;
    usageDescription = usageDes;
  }
  
  protected Options getOptions()
  {
    return opts;
  }
  
  public void addHelpDetail(String keyword, String help)
  {
    keyword2help.put(keyword.toLowerCase(), help);
    
    logger.info("Help Detail added for {} :\n{}", keyword, help);
  }
  
  public void setSyntax(String syntax)
  {
    this.syntax = syntax;
  }
  
  public String getSyntax()
  {
    return StringUtil.nvl(new String[] { syntax, FilenameUtil.getTailingPath(System.getProperty("cli.name"), 1), "java " + getClass().getName() });
  }
  
  public String getHelp()
  {
    StringBuffer helpBuffer = new StringBuffer();
    
    helpBuffer.append("\n");
    getUsage(helpBuffer);
    helpBuffer.append("\n");
    
    boolean cmdDes = getCmds() != null & StringUtil.isEmpty(getInputCmd());
    if (cmdDes)
    {
      getCommandDescription(helpBuffer);
      helpBuffer.append("\n");
    }
    if (getOptions().getOptions().size() > 0)
    {
      getOptionDescription(helpBuffer);
      helpBuffer.append("\n");
    }
    if (cmdDes)
    {
      getHelpUsage(helpBuffer);
      helpBuffer.append("\n");
    }
    return helpBuffer.toString();
  }
  
  public StringBuffer getHelpUsage(StringBuffer buffer)
  {
    String syntax = StringUtil.nvl(new String[] { DEFAULT_SYNTAX, getSyntax() });
    
    buffer.append(String.format("For more information on a specific command: '%s <command> -h'", new Object[] { syntax }));
    return buffer;
  }
  
  public StringBuffer getCommandDescription(StringBuffer buffer)
  {
    Options cmds = getCmds();
    buffer.append("Commands:\n");
    getOptionDescriptionWithPrefix(cmds, "", "", buffer);
    
    return buffer;
  }
  
  public StringBuffer getOptionDescription(StringBuffer buffer)
  {
    Options opts = getOptions();
    buffer.append("Options:\n");
    getOptionDescriptionWithPrefix(opts, "-", "--", buffer);
    
    return buffer;
  }
  
  public StringBuffer getOptionDescriptionWithPrefix(Options opts, String optPrefix, String longOptPrefix, StringBuffer buffer)
  {
    if ((opts == null) || (opts.getOptions().size() == 0)) {
      return buffer;
    }
    StringWriter writer = new StringWriter();
    PrintWriter stream = new PrintWriter(writer);
    HelpFormatter formatter = new HelpFormatter();
    
    formatter.setOptPrefix(optPrefix);
    formatter.setLongOptPrefix(longOptPrefix);
    formatter.printOptions(stream, formatter.getWidth(), opts, formatter.getLeftPadding(), formatter.getDescPadding());
    
    return buffer.append(writer.toString());
  }
  
  public StringBuffer getUsage(StringBuffer usageBuffer)
  {
    String syntax = StringUtil.nvl(new String[] { DEFAULT_SYNTAX, getSyntax() });
    
    usageBuffer.append(String.format("Usage: %s ", new Object[] { syntax }));
    Options opts = getOptions();
    Options cmds = getCmds();
    String inputCmd = getInputCmd();
    
    String description = "";
    if (cmds != null)
    {
      Option cmd = cmds.getOption(inputCmd);
      if (cmd != null)
      {
        usageBuffer.append(inputCmd + " ");
        description = cmd.getDescription();
      }
      else
      {
        usageBuffer.append("<command> ");
        description = usageDescription;
      }
    }
    int optionSize = opts.getOptions().size();
    int reqOptSize = opts.getRequiredOptions().size();
    if ((optionSize > 0) && (optionSize != reqOptSize)) {
      usageBuffer.append("[options] ");
    }
    getRequiredOptionInUsage(usageBuffer);
    usageBuffer.append(String.format("\n%s\n", new Object[] { description }));
    return usageBuffer;
  }
  
  private StringBuffer getRequiredOptionInUsage(StringBuffer buffer)
  {
    Options opts = getOptions();
    
    List<String> requiredOptKeys = opts.getRequiredOptions();
    for (String key : requiredOptKeys)
    {
      Option opt = opts.getOption(key);
      buffer.append(String.format("-%s ", new Object[] { opt.getOpt() }));
      if (opt.hasArg()) {
        buffer.append(String.format("<%s> ", new Object[] { opt.getArgName() }));
      }
    }
    return buffer;
  }
  
  public Options getCmds()
  {
    return cmds;
  }
  
  public String getInputCmd()
  {
    return inputCmd;
  }
  
  public String getHelpDetail(String keyword)
  {
    if (null == keyword) {
      return "";
    }
    return StringUtil.nvl(new String[] { (String)keyword2help.get(keyword.toLowerCase()) });
  }
}

/* Location:
 * Qualified Name:     org.tizen.cli.exec.Help
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.cli.exec;

public class LaunchOptionConstants
{
  public static final String DESC_FAILED_CANNOT_FIND_WIDGET_ID = "Can't find application ID";
  public static final String DESC_FAILED_CANNOT_FIND_CONNECTED_DEVICE = "Can't find connected device";
  public static final String DESC_FAILED_CANNOT_FIND_SELECTED_DEVICE = "Can't find selected device";
  public static final String DESC_FAILED_MODE_SETTING = "Development mode setting failed";
  public static final String DESC_WIDGETID = "Application id (user-written id in config.xml)";
  public static final String OPT_WIDGETFILE = "widget";
  public static final String DESC_WIDGETFILE = "Widget file (*.wgt)";
  public static final String OPT_WIDGETID = "id";
  public static final String OPT_NAME = "name";
  public static final String DESC_NAME = "Project name";
  public static final String OPT_PATH = "path";
  public static final String DESC_PATH = "Project path";
  public static final String OPT_INCLUDE = "include";
  public static final String DESC_INCLUDE = "File name pattern to include";
  public static final String OPT_EXCLUDE = "exclude";
  public static final String DESC_EXCLUDE = "File name pattern to exclude";
  public static final String OPT_NOCHECK = "nocheck";
  public static final String DESC_NOCHECK = "Skip validation check";
  public static final String OPT_OVERWRITE = "overwrite";
  public static final String DESC_OVERWRITE = "Overwrite output file if it exists";
  public static final String OPT_DEVELOP = "develop";
  public static final String DESC_DEVELOP_PROFILE = "Add the profile information for development automatically";
}

/* Location:
 * Qualified Name:     org.tizen.cli.exec.LaunchOptionConstants
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.cli.exec;

import org.tizen.common.core.command.policy.OptionPolicy;
import org.tizen.common.core.command.prompter.FileHandlingOption;
import org.tizen.common.core.command.prompter.Option;

class PolicyRegistryFactory$1
  extends PolicyRegistryFactory.CLIPolicy
{
  PolicyRegistryFactory$1(PolicyRegistryFactory paramPolicyRegistryFactory, String x0)
  {
    super(paramPolicyRegistryFactory, x0);
  }
  
  public <T> T adapt(Class<T> clazz)
  {
    return new OptionPolicy(new Option[] { FileHandlingOption.OVERWRITE, FileHandlingOption.IGNORE, FileHandlingOption.OVERWRITE_ALL, FileHandlingOption.IGNORE_ALL, FileHandlingOption.CANCEL });
  }
}

/* Location:
 * Qualified Name:     org.tizen.cli.exec.PolicyRegistryFactory.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.cli.exec;

import org.tizen.common.core.command.policy.AbstractPolicy;
import org.tizen.common.core.command.policy.FilePolicy;
import org.tizen.common.core.command.policy.MessagePolicy;

class PolicyRegistryFactory$CLIPolicy
  extends AbstractPolicy
{
  public PolicyRegistryFactory$CLIPolicy(PolicyRegistryFactory paramPolicyRegistryFactory, String name)
  {
    super(name);
  }
  
  public <T> T adapt(Class<T> clazz)
  {
    if (clazz.isAssignableFrom(FilePolicy.class)) {
      return FilePolicy.STOP_PROCESS;
    }
    if (clazz.isAssignableFrom(MessagePolicy.class)) {
      return MessagePolicy.PROMPTER;
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.tizen.cli.exec.PolicyRegistryFactory.CLIPolicy
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
null
package org.tizen.cli.exec;

import java.text.MessageFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tizen.common.core.command.Prompter;
import org.tizen.common.core.command.prompter.ChoiceOption;
import org.tizen.common.core.command.prompter.GenericOption;
import org.tizen.common.core.command.prompter.Option;
import org.tizen.common.core.command.sdb.SmartDevelopmentBridgeManager;
import o
1 2 3 4 5

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd