emulator-manager

16:35:35.731 INFO  jd.cli.Main - Decompiling emulator-manager.jar
package org.tizen.emulator.manager;

import org.tizen.emulator.manager.tool.CocoaUtil;

final class EmulatorManager$1
  implements Runnable
{
  public void run()
  {
    new CocoaUtil().removeTopMenuItems();
  }
}

/* Location:
 * Qualified Name:     org.tizen.emulator.manager.EmulatorManager.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.emulator.manager;

public enum EmulatorManager$ManagerModeType
{
  PUBLIC_MODE("public"),  INHOUSE_MODE("inhouse");
  
  private final String value;
  
  private EmulatorManager$ManagerModeType(String v)
  {
    value = v;
  }
  
  public String value()
  {
    return value;
  }
  
  public static ManagerModeType fromValue(String v)
  {
    for (ManagerModeType c : ) {
      if (value.equals(v)) {
        return c;
      }
    }
    throw new IllegalArgumentException(v);
  }
}

/* Location:
 * Qualified Name:     org.tizen.emulator.manager.EmulatorManager.ManagerModeType
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.emulator.manager;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.tizen.emulator.manager.console.Action;
import org.tizen.emulator.manager.console.CommandLineParser;
import org.tizen.emulator.manager.logging.EMLogger;
import org.tizen.emulator.manager.platform.BaseImage;
import org.tizen.emulator.manager.platform.CustomPlatform;
import org.tizen.emulator.manager.platform.Platform;
import org.tizen.emulator.manager.platform.TotalPlatform;
import org.tizen.emulator.manager.resources.FilePathResources;
import org.tizen.emulator.manager.resources.StringResources;
import org.tizen.emulator.manager.tool.About;
import org.tizen.emulator.manager.tool.CheckSDCard;
import org.tizen.emulator.manager.tool.CheckVirtualization;
import org.tizen.emulator.manager.tool.CocoaUtil;
import org.tizen.emulator.manager.tool.SelectWorkspace;
import org.tizen.emulator.manager.ui.MainDialog;
import org.tizen.emulator.manager.ui.dialog.MessageDialog;
import org.tizen.emulator.manager.vms.EmulatorVMList;
import org.tizen.emulator.manager.vms.VMProperty;
import org.tizen.emulator.manager.vms.VMProperty.FSImageType;

public class EmulatorManager
{
  private static ManagerModeType mode;
  private static Display display;
  private static MainDialog mainDialog;
  private static ArrayList<Platform> platformList = null;
  private static CommandLineParser processor = null;
  private static boolean isConsoleMode = true;
  private static boolean isInhoseMode = false;
  private static boolean isDebugMode = false;
  private static String workspacePath = null;
  private static boolean isSave = true;
  private static RandomAccessFile randomAccessFile;
  private static boolean isMac = false;
  private static boolean isWin = false;
  private static boolean isLinux = false;
  
  static
  {
    if (System.getProperty("os.name").toLowerCase().indexOf("linux") > -1) {
      isLinux = true;
    } else if (System.getProperty("os.name").toLowerCase().indexOf("win") > -1) {
      isWin = true;
    } else if (System.getProperty("os.name").toLowerCase().indexOf("mac") > -1) {
      isMac = true;
    }
  }
  
  public static boolean isMac()
  {
    return isMac;
  }
  
  public static boolean isWin()
  {
    return isWin;
  }
  
  public static boolean isLinux()
  {
    return isLinux;
  }
  
  public static ManagerModeType getManagerMode()
  {
    return mode;
  }
  
  public static MainDialog getMainDialog()
  {
    return mainDialog;
  }
  
  private static void preare()
  {
    display = Display.getCurrent();
    mainDialog = new MainDialog(mode);
  }
  
  private static void draw()
  {
    mainDialog.draw();
    mainDialog.open();
    
    display.dispose();
  }
  
  private static void dispose()
  {
    mainDialog.dispose();
  }
  
  public static boolean isDebugMode()
  {
    return isDebugMode;
  }
  
  public static boolean isConsoleMode()
  {
    return isConsoleMode;
  }
  
  private static void startConsoleProcessor()
  {
    Action action = processor.getAction();
    if (!action.process()) {
      exitEmulatorManager(2);
    } else {
      exitEmulatorManager(0);
    }
  }
  
  static void checkConsoleMode(String[] args)
  {
    if (args.length > 0) {
      for (String s : args)
      {
        if ((s.startsWith("--w")) || (s.startsWith("-w")))
        {
          isConsoleMode = false;
          break;
        }
        if ((s.startsWith("--i")) || (s.startsWith("-i")))
        {
          isConsoleMode = false;
          break;
        }
      }
    } else {
      isConsoleMode = false;
    }
  }
  
  static void parseArgs(String[] args)
  {
    String SAVE_TRUE = ",save=true";
    String SAVE_FALSE = ",save=false";
    boolean isArgsError = false;
    if (args.length > 0) {
      for (int i = 0; i < args.length; i++) {
        if ((args[i].equals("--workspace")) || (args[i].equals("-w")))
        {
          if ((args.length == i + 1) || (args[(i + 1)].startsWith("--")))
          {
            isArgsError = true;
          }
          else if (args[(i + 1)].endsWith(",save=true"))
          {
            workspacePath = args[(i = 1)].substring(0, args[(i = 1)].length() - ",save=true".length());
            isSave = true;
          }
          else if (args[(i + 1)].endsWith(",save=false"))
          {
            workspacePath = args[(i = 1)].substring(0, args[(i = 1)].length() - ",save=false".length());
            isSave = false;
          }
          else
          {
            isArgsError = true;
          }
        }
        else if (args[i].equals("--inhouse")) {
          isInhoseMode = true;
        } else if (args[i].equals("--debug")) {
          isDebugMode = true;
        } else {
          isArgsError = true;
        }
      }
    }
    mode = isInhoseMode ? ManagerModeType.INHOUSE_MODE : ManagerModeType.PUBLIC_MODE;
    
    MessageDialog msg = new MessageDialog(new Shell(Display.getCurrent()));
    if (isArgsError == true)
    {
      msg.openWarningDialog("Used option parameter is not proper. Aborting...\n\nSee right examples below.\n--inhouse: Emulator Manager start with inhouse mode. You can use extend function.--debug: Emulator Manager start with debug mode. Print more log at emulator-manager.log--workspace or -w: Set workspace. Created vms are saved in workspace.[--workspace {workspace path},save=true]\n[-w {workspace path},save=true]\n[--workspace {workspace path},save=false]\n[-w {workspace path},save=false]\n\nThe workspace path must be absolute.");
      
      exitEmulatorManager(1);
    }
  }
  
  public static void main(String[] args)
  {
    if (isMac())
    {
      System.setProperty("apple.laf.useScreenMenuBar", "true");
      System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Emulator Manager");
      Display display = Display.getDefault();
      display.syncExec(new Runnable()
      {
        public void run()
        {
          new CocoaUtil().removeTopMenuItems();
        }
      });
    }
    try
    {
      checkConsoleMode(args);
      
      randomAccessFile = new RandomAccessFile(new File(new StringBuilder().append(FilePathResources.getBinPath()).append(File.separator).append(".").append(System.getProperty("user.name")).toString()) + ".lock", "rw");
      if (isConsoleMode)
      {
        EMLogger.getInstance().initLogger();
        try
        {
          FileLock lock = randomAccessFile.getChannel().tryLock();
          if (lock == null)
          {
            EMLogger.getLogger().log(Level.WARNING, "Can not launch Emulator Manager." + StringResources.NEW_LINE + "Another one with the same user name is running now." + StringResources.NEW_LINE);
            
            System.out.println("Can not launch Emulator Manager." + StringResources.NEW_LINE + "Another Emulator Manager is running now.");
            
            exitEmulatorManager(1);
          }
        }
        catch (IOException e)
        {
          EMLogger.getLogger().log(Level.WARNING, "Can not launch Emulator Manager." + StringResources.NEW_LINE + e.getMessage() + StringResources.NEW_LINE);
          
          exitEmulatorManager(1);
        }
        SelectWorkspace.getWorkspace(isConsoleMode);
        
        processor = new CommandLineParser();
        processor.parseArgs(args);
      }
      else
      {
        parseArgs(args);
        if (!SelectWorkspace.setWorkspace(workspacePath, isSave)) {
          exitEmulatorManager(1);
        }
        EMLogger.getInstance().initLogger();
        
        MessageDialog msg = new MessageDialog(new Shell(Display.getCurrent()));
        try
        {
          FileLock lock = randomAccessFile.getChannel().tryLock();
          if (lock == null)
          {
            msg.openInfoDialog("Can not launch Emulator Manager." + StringResources.NEW_LINE + "Another one with the same user name is running now.");
            
            exitEmulatorManager(0);
          }
        }
        catch (IOException e)
        {
          msg.openInfoDialog("Can not launch Emulator Manager." + StringResources.NEW_LINE + e.getMessage());
          
          exitEmulatorManager(1);
        }
      }
      About.initAboutContents();
      
      CheckVirtualization.getInstance().check();
      
      CheckSDCard.CheckSDCardDir();
      CheckSDCard.CheckSwapDir();
      
      makePlatformList();
      if (isConsoleMode)
      {
        startConsoleProcessor();
      }
      else
      {
        EMLogger.getLogger().log(Level.INFO, "Start Emulator Manager!!");
        
        preare();
        draw();
        dispose();
      }
    }
    catch (Throwable e)
    {
      e.printStackTrace();
      
      EMLogger.getLogger().warning("Throw exception: " + e.getMessage());
      EMLogger.printStakTrace(e);
      
      exitEmulatorManager(1);
    }
  }
  
  public static void exitEmulatorManager(int returnValue)
  {
    System.exit(returnValue);
  }
  
  public static ArrayList<Platform> getPlatformList()
  {
    return platformList;
  }
  
  private static CustomPlatform custom = new CustomPlatform();
  private static TotalPlatform total = new TotalPlatform();
  
  public static CustomPlatform getCustomPlatform()
  {
    return custom;
  }
  
  public static TotalPlatform getTotalPlatform()
  {
    return total;
  }
  
  static void makePlatformList()
  {
    platformList = new ArrayList();
    
    File platforms = new File(FilePathResources.getPlatformsPath());
    if ((platforms.isDirectory()) && (platforms.exists())) {
      for (File platform : platforms.listFiles()) {
        if (platform.isDirectory())
        {
          Platform form = new Platform(platform.getName());
          if (!form.getImageList().isEmpty()) {
            platformList.add(form);
          }
        }
      }
    }
    settingVMPropertyList();
  }
  
  public static void settingVMPropertyList()
  {
    EmulatorVMList vms = EmulatorVMList.getInstance();
    vms.refreshProperties();
    
    custom.clearVMs();
    for (Platform p : getPlatformList()) {
      p.clearVMs();
    }
    VMProperty prop;
    for (prop : (VMProperty[])vms.getProperties()) {
      if (prop.getImageType() == VMProperty.FSImageType.custom) {
        custom.addVMsProperty(prop);
      } else {
        for (Platform p : getPlatformList()) {
          if (prop.getImageVersion().equals(p.getName())) {
            for (BaseImage b : p.getImageList()) {
              if (prop.getBaseImageName().equals(b.getName()))
              {
                b.addVMsProperty(prop);
                break;
              }
            }
          }
        }
      }
    }
    total.settingVMProperty();
  }
  
  public static enum ManagerModeType
  {
    PUBLIC_MODE("public"),  INHOUSE_MODE("inhouse");
    
    private final String value;
    
    private ManagerModeType(String v)
    {
      value = v;
    }
    
    public String value()
    {
      return value;
    }
    
    public static ManagerModeType fromValue(String v)
    {
      for (ManagerModeType c : ) {
        if (value.equals(v)) {
          return c;
        }
      }
      throw new IllegalArgumentException(v);
    }
  }
}

/* Location:
 * Qualified Name:     org.tizen.emulator.manager.EmulatorManager
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.emulator.manager.console;

import java.util.ArrayList;

public abstract class Action
{
  protected String action = null;
  protected ArrayList<Command> commandList = null;
  protected String description = null;
  protected String usage = null;
  
  public Action()
  {
    commandList = new ArrayList();
  }
  
  public abstract boolean process();
  
  public String getDescription()
  {
    assert (description == null);
    
    return description;
  }
  
  public ArrayList<Command> getCommandList()
  {
    assert (commandList == null);
    
    return commandList;
  }
  
  public String getAction()
  {
    assert (action == null);
    
    return action;
  }
  
  public String checkMandatory()
  {
    assert (commandList == null);
    
    String message = null;
    for (Command c : commandList) {
      if ((c != null) && 
        (c.isMandatory()) && (!c.isInCommandLine())) {
        message = "--" + c.getLongName() + "(-" + c.getShortName() + ")";
      }
    }
    return message;
  }
  
  public Command findComand(String a)
  {
    assert (commandList == null);
    for (Command c : commandList) {
      if (c != null)
      {
        if (c.getLongName().equals(a)) {
          return c;
        }
        if (c.getShortName().equals(a)) {
          return c;
        }
      }
    }
    return null;
  }
  
  public Command findLongCommand(String a)
  {
    assert (commandList == null);
    for (Command c : commandList) {
      if ((c != null) && 
        (c.getLongName().equals(a))) {
        return c;
      }
    }
    return null;
  }
  
  public Command findShortCommand(String a)
  {
    assert (commandList == null);
    for (Command c : commandList) {
      if ((c != null) && 
        (c.getShortName().equals(a))) {
        return c;
      }
    }
    return null;
  }
  
  public String getUsage()
  {
    assert (usage == null);
    return usage;
  }
}

/* Location:
 * Qualified Name:     org.tizen.emulator.manager.console.Action
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.emulator.manager.console;

import java.io.PrintStream;
import java.util.ArrayList;

public class ActionList
{
  private Global globalAction = null;
  private ArrayList<Action> actionList = new ArrayList();
  
  public ArrayList<Action> getActionList()
  {
    return actionList;
  }
  
  private void addAction(Action action)
  {
    actionList.add(action);
  }
  
  public ActionList()
  {
    globalAction = new Global();
    
    addAction(new ListVM());
    addAction(new ListImage());
    addAction(new Detail());
    addAction(new Launch());
    addAction(new Workspace());
    addAction(new Create());
    addAction(new Modify());
    addAction(new Delete());
    
    addAction(new Reset());
    addAction(new CreateBaseImage());
  }
  
  public Action getGlobalAction()
  {
    return globalAction;
  }
  
  public boolean isGlobalAction(String value)
  {
    if (globalAction.findLongCommand(value) != null) {
      return true;
    }
    if (globalAction.findShortCommand(value) != null) {
      return true;
    }
    return false;
  }
  
  public Action findAction(String value)
  {
    for (Action a : actionList) {
      if (a.getAction().equals(value)) {
        return a;
      }
    }
    return null;
  }
  
  public void printGlobaloptions()
  {
    System.out.println("Global options:");
    for (Command c : globalAction.getCommandList()) {
      System.out.println(c.getKey() + "\t: " + c.getDescription());
    }
  }
  
  public void printActions()
  {
    for (Action a : actionList) {
      System.out.println(String.format("\t%-12s : %s", new Object[] { a.getAction(), a.getDescription() }));
    }
  }
  
  public void printAction(Action action)
  {
    System.out.println("\n--------------------------------------------------------------------------");
    System.out.println("Action: \"" + action.getAction() + "\"");
    System.out.println("\t-> " + action.getDescription());
    System.out.println("Usage: ");
    System.out.println("\t" + action.getUsage());
    System.out.println();
    System.out.println("Options: ");
    for (Command c : action.getCommandList())
    {
      System.out.print(String.format("\t%-15s : %s", new Object[] { c.getKey(), c.getDescription() }));
      if (c.isMandatory()) {
        System.out.print(" [required] ");
      }
      if (c.getDefaultValue() != "") {
        System.out.print(" [default: " + c.getDefaultValue() + "]");
      }
      System.out.println();
    }
  }
}

/* Location:
 * Qualified Name:     org.tizen.emulator.manager.console.ActionList
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.emulator.manager.console;

class Actions
{
  public static final String OP_HELP = "help";
  public static final String OP_SILENT = "silent";
  public static final String OP_VERBOSE = "verbose";
  public static final String AC_GLOBAL = "global";
  public static final String AC_LIST_VM = "list-vm";
  public static final String AC_LIST_IMAGE = "list-image";
  public static final String AC_CREATE = "create";
  public static final String AC_DETAIL = "detail";
  public static final String AC_DELETE = "delete";
  public static final String AC_MODIFY = "modify";
  public static final String AC_COLONE = "clone";
  public static final String AC_RESET = "reset";
  public static final String AC_LAUNCH = "launch";
  public static final String AC_CREATE_IMAGE = "create-image";
  public static final String AC_WORKSPACE = "workspace";
  public static final String OP_STANDARD = "standard";
  public static final String OP_CUSTOM = "custom";
  public static final String OP_SET = "set";
  public static final String OP_GET = "get";
  public static final String OP_NAME = "name";
  public static final String OP_DETAIL = "detail";
  public static final String OP_PATH = "path";
  public static final String OP_BASE = "base";
  public static final String OP_TARGET = "target-name";
  public static final String OP_TEST = "test";
  public static final String OP_COUNT = "count";
  public static final String OP_RESOLUTION = "resolution";
  public static final String OP_DPI = "dpi";
  public static final String OP_SKIN = "skin";
  public static final String OP_KEYTYPE = "key-type";
  public static final String OP_RAM = "ram-size";
  public static final String OP_FILESHARE = "file-sharing";
  public static final String OP_FILESHAREPATH = "file-sharing-path";
  public static final String OP_VIRTUALIZATION = "hw-virtualization";
  public static final String OP_MAXTOUCH = "max-touch-point";
  public static final String OP_ADDOPTION = "add-options";
  public static final String OP_GLACCELERATION = "hw-gl-acceleration";
}

/* Location:
 * Qualified Name:     org.tizen.emulator.manager.console.Actions
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.emulator.manager.console;

class AddOptions
  extends Command
{
  public AddOptions(String shortName, String longName, String description, String defaultValue, boolean isMandatory, boolean needsExtra)
  {
    super(shortName, longName, description, defaultValue, isMandatory, needsExtra);
  }
  
  public boolean checkExtraArg(String arg)
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.tizen.emulator.manager.console.AddOptions
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.emulator.manager.console;

import java.util.ArrayList;

class Clone
  extends Action
{
  public Clone()
  {
    action = "clone";
    description = "Create new VM which has the same configurations as you selected..";
    usage = "clone -n test -t target";
    
    commandList.add(new Command("n", "name", "Name of VM to create base target image.", "", true, true));
    
    commandList.add(new Command("t", "target-name", "Input new VM's name.", "", true, true));
  }
  
  public boolean process()
  {
    String name = null;
    String target = null;
    for (Command c : commandList) {
      if (c.isInCommandLine()) {
        switch (c.getShortName().charAt(0))
        {
        case 'n': 
          name = c.getCurrentValue();
          break;
        case 't': 
          target = c.getCurrentValue();
        }
      }
    }
    ConsoleProcessor processor = new ConsoleProcessor();
    return processor.cloneVM(name, target);
  }
}

/* Location:
 * Qualified Name:     org.tizen.emulator.manager.console.Clone
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.emulator.manager.console;

class Command
{
  private String shortName;
  private String longName;
  private String description;
  private String defaultValue;
  private String currentValue;
  private String key;
  private boolean isMandatory;
  private boolean needsExtra;
  private boolean isInCommandLine;
  
  public Command(String shortName, String longName, String description, String defaultValue, boolean isMandatory, boolean needsExtra)
  {
    this.shortName = shortName;
    this.longName = longName;
    key = ((shortName.isEmpty() ? "" : new StringBuilder().append("-").append(shortName).append(", ").toString()) + "--" + longName);
    
    this.description = description;
    this.defaultValue = defaultValue;
    currentValue = this.defaultValue;
    this.isMandatory = isMandatory;
    this.needsExtra = needsExtra;
    isInCommandLine = false;
  }
  
  public boolean checkExtraArg(String arg)
  {
    if (arg.startsWith("-")) {
      return false;
    }
    return true;
  }
  
  public String getKey()
  {
    return key;
  }
  
  public String getShortName()
  {
    return shortName;
  }
  
  public String getLongName()
  {
    return longName;
  }
  
  public String getDescription()
  {
    return description;
  }
  
  public String getDefaultValue()
  {
    return defaultValue;
  }
  
  public void setCurrentValue(String value)
  {
    currentValue = value;
  }
  
  public String getCurrentValue()
  {
    return currentValue;
  }
  
  public boolean isMandatory()
  {
    return isMandatory;
  }
  
  public boolean isNeedsExtra()
  {
    return needsExtra;
  }
  
  public void setInCommandLine(boolean isInCommandLine)
  {
    this.isInCommandLine = isInCommandLine;
  }
  
  public boolean isInCommandLine()
  {
    return isInCommandLine;
  }
}

/* Location:
 * Qualified Name:     org.tizen.emulator.manager.console.Command
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.emulator.manager.console;

import java.io.PrintStream;
import org.tizen.emulator.manager.EmulatorManager;
import org.tizen.emulator.manager.logging.EMLogger;
import org.tizen.emulator.manager.resources.StringResources;

public class CommandLineParser
{
  private ActionList actionList = null;
  private Action mAction = null;
  
  public CommandLineParser()
  {
    actionList = new ActionList();
  }
  
  public void parseArgs(String[] args)
  {
    Action action = null;
    try
    {
      int count = args.length;
      for (int i = 0; i < count; i++)
      {
        String a = args[i];
        if (action == null)
        {
          if (a.startsWith("-"))
          {
            String temp = a.substring(a.startsWith("--") ? 2 : 1);
            if (actionList.isGlobalAction(temp)) {
              checkGlobalOption(a);
            } else {
              throw new ConsoleException("Option( " + a + ") is not a valid global option.");
            }
          }
          else
          {
            action = actionList.findAction(a);
            if (action == null) {
              throw new ConsoleException("It looks like you didn't provide correct action name. '" + a + "' was not found.");
            }
          }
        }
        else
        {
          Command command = null;
          if (a.startsWith("--")) {
            command = action.findLongCommand(a.substring(2));
          } else if (a.startsWith("-")) {
            command = action.findShortCommand(a.substring(1));
          } else {
            throw new ConsoleException("Flag '" + a + "' is not valid for '" + action.getAction() + "'.");
          }
          if (command == null) {
            throw new ConsoleException("Flag '" + a + "' is not valid for '" + action.getAction() + "'.");
          }
          command.setInCommandLine(true);
          if (command.isNeedsExtra())
          {
            i++;
            if (i >= count) {
              throw new ConsoleException("Missing argument for '" + a + "'.");
            }
            if (!command.checkExtraArg(args[i])) {
              throw new ConsoleException("It(" + args[i] + ") looks like you didn't provide an avliable argument for '" + a + "'");
            }
            command.setCurrentValue(args[i]);
          }
        }
      }
      if (action == null)
      {
        if (isHelpState()) {
          printHelpAndExit(null, null, new Object[0]);
        } else {
          throw new ConsoleException("Missing action name.");
        }
      }
      else
      {
        if (isHelpState()) {
          printHelpAndExit(action, null, new Object[0]);
        }
        String missing = action.checkMandatory();
        if (missing != null) {
          throw new ConsoleException(String.format("The prameter(s) %s must be defined for action '%s'", new Object[] { missing, action.getAction() }));
        }
        mAction = action;
      }
    }
    catch (ConsoleException e)
    {
      printErrorAndExit(e.getMessage(), new Object[0]);
    }
  }
  
  private void checkGlobalOption(String value)
    throws ConsoleException
  {
    Command c = null;
    if (value.startsWith("--")) {
      c = actionList.getGlobalAction().findLongCommand(value.substring(2));
    } else {
      c = actionList.getGlobalAction().findShortCommand(value.substring(1));
    }
    if (c == null) {
      throw new ConsoleException("This (" + value + ") is not global options.");
    }
    if ((isHelpState()) || (isVerboseState())) {
      throw new ConsoleException("Please check global options.");
    }
    c.setInCommandLine(true);
    switch (c.getShortName().charAt(0))
    {
    case 'h': 
      isHelp = true;
      break;
    case 'v': 
      isVerbose = true;
      EMLogger.getInstance().setConsoleLogger();
    }
  }
  
  private boolean isHelp = false;
  private boolean isVerbose = false;
  
  private boolean isHelpState()
  {
    return isHelp;
  }
  
  private boolean isVerboseState()
  {
    return isVerbose;
  }
  
  public Action getAction()
  {
    return mAction;
  }
  
  public void printErrorAndExit(String errorFormat, Object... args)
  {
    if ((errorFormat != null) && (errorFormat.length() > 0)) {
      System.out.println("Error: " + String.format(errorFormat, args));
    }
    EmulatorManager.exitEmulatorManager(errorFormat != null ? 2 : 0);
  }
  
  public void printHelpAndExit(Action action, String errorFormat, Object... args)
  {
    if ((errorFormat != null) && (errorFormat.length() > 0)) {
      System.out.println("Error: " + String.format(errorFormat, args));
    }
    System.out.println(StringResources.NEW_LINE + "Usage:" + StringResources.NEW_LINE + "   emulator-manager [global options] " + (action == null ? "action" : action.getAction()) + " [action options]");
    
    actionList.printGlobaloptions();
    if (action == null)
    {
      System.out.println(StringResources.NEW_LINE + "Valid actions: ");
      actionList.printActions();
    }
    else
    {
      actionList.printAction(action);
    }
    EmulatorManager.exitEmulatorManager(errorFormat != null ? 2 : 0);
  }
}

/* Location:
 * Qualified Name:     org.tizen.emulator.manager.console.CommandLineParser
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.emulator.manager.console;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import org.tizen.emulator.manager.EmulatorManager;
import org.tizen.emulator.manager.platform.BaseImage;
import org.tizen.emulator.manager.platform.Platform;
import org.tizen.emulator.manager.platform.Skin;
import org.tizen.emulator.manager.platform.SkinList;
import org.tizen.emulator.manager.tool.CheckVirtualization;
import org.tizen.emulator.manager.vms.Creator;
import org.tizen.emulator.manager.vms.EmulatorVMList;
import org.tizen.emulator.manager.vms.HelperClass;
import org.tizen.emulator.manager.vms.RAM_SIZE;
import org.tizen.emulator.manager.vms.RESOLUTION;
import org.tizen.emulator.manager.vms.VMPropertyValue;
import org.tizen.emulator.manager.vms.VMWorkerException;

public class ConsoleCreateVM
{
  public boolean createVM(ArrayList<Command> list, VMPropertyValue property)
  {
    boolean isStandard = false;
    boolean isCustom = false;
    for (Command c : list) {
      if (c.isInCommandLine()) {
        switch (c.getShortName().charAt(0))
        {
        case 'b': 
          isStandard = true;
          break;
        case 'p': 
          isCustom = true;
        }
      }
    }
    if ((isStandard) && (isCustom))
    {
      System.out.println("Error: Option of 'create' is allowed only one of two.(--base or --path)");
      return false;
    }
    if ((!isStandard) && (!isCustom))
    {
      System.out.println("Error: One of '--base' and '--path' shoud come as option of 'create'");
      return false;
    }
    if (isStandard)
    {
      isStandard = true;
      return createStandardVM(list, property);
    }
    return createCustomVM(list, property);
  }
  
  public boolean createCustomVM(ArrayList<Command> list, VMPropertyValue prop)
  {
    try
    {
      for (Command c : list) {
        if (c.isInCommandLine()) {
          if (c.getShortName() == "n")
          {
            checkVMName(c.getCurrentValue());
            vmsName = c.getCurrentValue();
          }
          else if (c.getShortName() == "p")
          {
            baseImagePath = checkImagePath(c.getCurrentValue());
            if (baseImagePath.endsWith(".x86"))
            {
              archType = "x86";
              getInstanceCustomArch = "x86";
            }
            else if (baseImagePath.endsWith(".arm"))
            {
              archType = "arm";
              getInstanceCustomArch = "arm";
            }
            else
            {
              throw new ConsoleException("Avaliable format of base image is .x86 or .arm.");
            }
          }
          else
          {
            setOptions(c, prop);
          }
        }
      }
      selectSkin(prop);
    }
    catch (ConsoleException e)
    {
      System.out.println("Error: ");
      System.out.println(e.getMessage());
      return false;
    }
    try
    {
      Creator.create(prop);
    }
    catch (VMWorkerException e)
    {
      System.out.println("Error: ");
      System.out.println(e.getMessage());
      return false;
    }
    System.out.println("Success: To create new Virtual Machine.");
    return true;
  }
  
  public boolean createStandardVM(ArrayList<Command> list, VMPropertyValue prop)
  {
    try
    {
      for (Command c : list) {
        if (c.isInCommandLine()) {
          if (c.getShortName() == "n")
          {
            checkVMName(c.getCurrentValue());
            vmsName = c.getCurrentValue();
          }
          else if (c.getShortName() == "b")
          {
            boolean check = false;
            for (Platform platform : EmulatorManager.getPlatformList()) {
              for (BaseImage image : platform.getImageList()) {
                if (image.getID().equals(c.getCurrentValue()))
                {
                  check = true;
                  image = image;
                  version = image.getVersion();
                  baseName = image.getName();
                  baseImagePath = image.getPath();
                  baseImagePathName = image.getPathName();
                  archType = image.getCpu();
                  break;
                }
              }
            }
            if (!check) {
              throw new ConsoleException("The ID (" + c.getCurrentValue() + ") is not avaliable.");
            }
          }
          else
          {
            setOptions(c, prop);
          }
        }
      }
      selectSkin(prop);
    }
    catch (ConsoleException e)
    {
      System.out.println("Error: ");
      System.out.println(e.getMessage());
      return false;
    }
    try
    {
      Creator.create(prop);
    }
    catch (VMWorkerException e)
    {
      System.out.println("Error: It is failed to create new Virtual Machine.");
      System.out.println(e.getMessage());
      return false;
    }
    System.out.println("Success: To create new Virtual Machine is completed.");
    return true;
  }
  
  private Command skinCommand = null;
  private Command resolutionCommand = null;
  
  public void setOptions(Command c, VMPropertyValue prop)
    throws ConsoleException
  {
    boolean check = false;
    if (c.getLongName() == "resolution")
    {
      resolutionCommand = c;
    }
    else if (c.getLongName() == "dpi")
    {
      check = false;
      int dpi = Integer.valueOf(c.getCurrentValue()).intValue();
      if ((dpi >= 100) && (dpi <= 480))
      {
        dpi = dpi;
        check = true;
      }
      if (!check) {
        throw new ConsoleException("DPI value (" + c.getCurrentValue() + ") is not avaliable.");
      }
    }
    else if (c.getLongName() == "skin")
    {
      skinCommand = c;
    }
    else if (c.getLongName() == "ram-size")
    {
      ramSize = checkRAMSize(c.getCurrentValue()).getSize();
    }
    else if (c.getLongName() == "file-sharing-path")
    {
      if (c.getCurrentValue().isEmpty())
      {
        isFileShareSupport = false;
        fileSharePath = "";
      }
      else
      {
        checkFileSharePath(c.getCurrentValue());
        isFileShareSupport = true;
        fileSharePath = c.getCurrentValue();
      }
    }
    else if (c.getLongName() == "hw-virtualization")
    {
      isHWVirtualization = checkHWVirtualization(c.getCurrentValue(), archType.equals("arm"));
    }
    else if (c.getLongName() == "hw-gl-acceleration")
    {
      isGLAcceleration = checkGLAcceleration(c.getCurrentValue(), archType.equals("arm"));
    }
    else if (c.getLongName() == "max-touch-point")
    {
      int i = Integer.valueOf(c.getCurrentValue()).intValue();
      if ((i != 1) && (i != 2) && (i != 3)) {
        throw new ConsoleException("This value(" + c.getCurrentValue() + ") " + "is not avaliable. Avaliable mulit-touch point is 1 - 3.");
      }
      maxTouchCount = i;
    }
    else if (c.getLongName() == "add-options")
    {
      addOptions = c.getCurrentValue();
    }
  }
  
  public void selectSkin(VMPropertyValue prop)
    throws ConsoleException
  {
    if (resolutionCommand != null)
    {
      RESOLUTION r = checkResolution(resolutionCommand.getCurrentValue());
      resolution = r;
      dpi = r.getDPI();
      ArrayList<Skin> list = SkinList.getInstance().findSkinList(resolution);
      if (!list.isEmpty()) {
        skin = ((Skin)list.get(0));
      } else {
        skin = null;
      }
      if (skin != null) {
        skinPath = skin.getPath();
      } else {
        skinPath = null;
      }
      if (skinCommand != null) {
        System.out.println("Because You change resolution, skin path chage follow reslution.");
      }
    }
    else if (skinCommand != null)
    {
      ArrayList<Skin> list = null;
      int i = 0;
      i = Integer.parseInt(skinCommand.getCurrentValue());
      list = SkinList.getInstance().findSkinList(resolution);
      if (!list.isEmpty())
      {
        if ((i <= 0) || (i > list.size())) {
          throw new ConsoleException("Skin value (" + skinCommand.getCurrentValue() + ") is not avaliable.");
        }
        skin = ((Skin)list.get(i - 1));
      }
      else
      {
        skin = null;
      }
      if (skin != null) {
        skinPath = skin.getPath();
      } else {
        skinPath = null;
      }
    }
  }
  
  private boolean checkGLAcceleration(String currentValue, boolean isArm)
    throws ConsoleException
  {
    String value = currentValue.toLowerCase();
    if (value.equals("yes"))
    {
      if (isArm)
      {
        System.out.println("If base disk image is arm, 'GLAcceleration' value is always false.");
        System.out.println("So this value set false.");
        return false;
      }
      if (!CheckVirtualization.getInstance().isSupportGPU()) {
        throw new ConsoleException("This computer does not support GPU.");
      }
      return true;
    }
    if (value.equals("no")) {
      return false;
    }
    throw new ConsoleException("Please, check your input (" + currentValue + ") " + "Avaliable value is true or false.");
  }
  
  private boolean checkHWVirtualization(String currentValue, boolean isArm)
    throws ConsoleException
  {
    String value = currentValue.toLowerCase();
    if (value.equals("yes"))
    {
      if (isArm)
      {
        System.out.println("If base disk image is arm, 'HWVirtualization' value is always false.");
        System.out.println("So this value set false.");
        return false;
      }
      if (!CheckVirtualization.getInstance().isSupportVirtualization()) {
        throw new ConsoleException("This computer does not support hardware virtualization.");
      }
      return true;
    }
    if (value.equals("no")) {
      return false;
    }
    throw new ConsoleException("Please, check your input (" + currentValue + ") " + "Avaliable value is true or false.");
  }
  
  private RAM_SIZE checkRAMSize(String value)
    throws ConsoleException
  {
    for (RAM_SIZE r : ) {
      if (r.toString().equals(value)) {
        return r;
      }
    }
    throw new ConsoleException("This RAM size (" + value + ") is not avaliable.");
  }
  
  private RESOLUTION checkResolution(String value)
    throws ConsoleException
  {
    for (RESOLUTION r : )
    {
      if (r.getType().equals(value)) {
        return r;
      }
      if (r.getStrValue().equals(value)) {
        return r;
      }
    }
    throw new ConsoleException("This resolution (" + value + ") is not avaliable.");
  }
  
  private void checkFileSharePath(String value)
    throws ConsoleException
  {
    if (value == null) {
      throw new ConsoleException("Path is empty.");
    }
    File f = new File(value);
    if (!f.exists()) {
      throw new ConsoleException("This directory does not exist. (Path : " + value + ")");
    }
  }
  
  private void checkVMName(String name)
    throws ConsoleException
  {
    if (name.length() > 20) {
      throw new ConsoleException("Max length of virtual target name is " + Integer.toString(20) + ".");
    }
    if (!HelperClass.checkString(name)) {
      throw new ConsoleException("Name has invalid character.\nValid Charater : a-z, A-Z, 0-9, 0, _");
    }
    if (HelperClass.checkDupulicateName(name) != null) {
      throw new ConsoleException("The name (" + name + ") already exists!");
    }
    if (name.isEmpty()) {
      throw new ConsoleException("The name is empty. Please enter the name of vm.");
    }
  }
  
  private String checkImagePath(String value)
    throws ConsoleException
  {
    if ((value == null) || (value.isEmpty())) {
      throw new ConsoleException("Path of disk image is empty.");
    }
    File f = new File(value);
    if (!f.exists()) {
      throw new ConsoleException("This directory does not exist. (Path : " + value + ")");
    }
    try
    {
      return f.getCan
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

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