import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.tizen.emulator.manager.logging.EMLogger;
import org.tizen.emulator.manager.tool.FileIO;
import org.tizen.emulator.manager.tool.SelectWorkspace;
-import org.tizen.emulator.manager.vms.Launcher;
import org.tizen.emulator.manager.vms.RAM_SIZE;
import org.tizen.emulator.manager.vms.RESOLUTION;
-import org.tizen.emulator.manager.vms.VMCreateHelper;
import org.tizen.emulator.manager.vms.VMPropertyValue;
-import org.tizen.emulator.manager.vms.VMsProperty;
-import org.tizen.emulator.manager.vms.VMsWorkerException;
public class ActionList {
private Global globalAction = null;
}
public void printAction(Action action) {
- System.out.println("\n-------------------------------------------------------------");
+ System.out.println("\n--------------------------------------------------------------------------");
System.out.println("Action: \"" + (action.getAction()) +"\"");
System.out.println(" -> " + action.getDescription());
+ System.out.println("Usage: ");
+ System.out.println(" " + action.getUsage());
System.out.println();
System.out.println("Options: ");
for(Command c : action.getCommandList()) {
public Global() {
this.action = Actions.AC_GLOBAL;
this.description = "Global Options";
- this.usage = "[[-h | --help] | [-v | --verbose]] action [action options]";
+ //this.usage = "[[-h | --help] | [-v | --verbose]] action [action options]";
+ this.usage ="";
commandList.add(new Command("h", Actions.OP_HELP,
"Display information of specific command.", "", false, false));
commandList.add(new Command("v", Actions.OP_VERBOSE,
- "Display information running state", "", false ,false));
+ "Display information running emulator-manager's state", "", false ,false));
}
public boolean process() {
class ListVM extends Action {
public ListVM() {
this.action = Actions.AC_LIST_VM;
- this.description = "Print list of existing 'Virtual Machine'";
- this.usage = "[-d | " + Actions.OP_DETAIL + "]";
+ this.description = "Display list of existing 'Virtual Machine'";
+ this.usage = "list-vm [options]";
commandList.add(new Command("d", Actions.OP_DETAIL,
- "Print more information of VM.","", false, false));
+ "Display more information of VMs.","", false, false));
/*
commandList.add(new Command("c", Actions.AC_COMPACT,
"Compact output(Print list of vm's name).", "", false, false));
class ListImage extends Action {
public ListImage() {
this.action = Actions.AC_LIST_IMAGE;
- this.description = "Print list of existing base disk image";;
- this.usage = "[action options]";
+ this.description = "Display list of existing base disk image";;
+ this.usage = "list-image";
}
@Override
public Detail() {
this.action = Actions.AC_DETAIL;
this.description = "Display more information of selected 'Virtual Target'.";
- this.usage = "[-n | "+ Actions.OP_NAME + "] test";
+ this.usage = "detail -n test";
commandList.add(new Command("n", Actions.OP_NAME,
- "Name of vertual target.\nIf you do not enter a name, emulator manager's information is printed.","", false, true));
+ "Name of vertual target.\n" +
+ " If you do not enter a name, emulator manager's information is printed.","", false, true));
}
@Override
this.action = Actions.AC_WORKSPACE;
this.description = "Set(Get) workspace of emulator manager.";
//+ "Workspace is directory that stores the generated 'Virtual Target'";
- this.usage = String.format("[-s | %s] path\n\t\t\t\t[-g | %s]", Actions.OP_SET, Actions.OP_GET);
+ this.usage = String.format("Set worksapce : workspace -s path\n" +
+ " Get workspace : workspace -g");
commandList.add(new Command("s", Actions.OP_SET,
"Set path of workspace.", FileIO.getInstance().getTizenVmsPath(),
false, true));
commandList.add(new Command("g", Actions.OP_GET,
- "Get current workspace", FileIO.getInstance().getTizenVmsPath(),
+ "Get current workspace path.", FileIO.getInstance().getTizenVmsPath(),
false, false));
}
public Create() {
this.action = Actions.AC_CREATE;
this.description = "Create new 'Virtual Machine'.";
- this.usage = "[-n | --name] test <[-b | --base] 1 | [-p | --path] path>";
+ this.usage = "Standard Image: create -n test -b 1 [options]\n" +
+ " Custom Image: create -n test -p path [options]\n" +
+ " You can not use both '-b' and '-p' at the same time.";
property = VMPropertyValue.getDefault(true);
commandList.add(new Command("n", Actions.OP_NAME,
"Select enable or disable hardware GL acceleration.(yes | no)",
property.isGLAcceleration ? "yes" : "no", false, true));
commandList.add(new Command("t", Actions.OP_MAXTOUCH,
- "Set count of multi touch point.(1 or 2)", Integer.toString(property.maxTouchCount), false, true));
+ "Set count of multi touch point.(1 ~ 3)", Integer.toString(property.maxTouchCount), false, true));
commandList.add(new AddOptions("a", Actions.OP_ADDOPTION,
"Add other qemu's options.", "", false, true));
}
public Modify() {
this.action = Actions.AC_MODIFY;
this.description = "Modify configuration of selected 'Virtual Machine'.";
- this.usage = "[-n | --name] test <options>";
+ this.usage = "modify -n test [options]";
property = VMPropertyValue.getDefault(true);
commandList.add(new Command("n", Actions.OP_NAME,
public Launch() {
this.action = Actions.AC_LAUNCH;
this.description = "Start emulator using selected VM.";
- this.usage = "[-n | --name] test";
+ this.usage = "launch -n test [options]";
commandList.add(new Command("n", Actions.OP_NAME,
"Name of VM to start.","", true, true));
}
ConsoleProcessor processor = new ConsoleProcessor();
- VMsProperty prop = processor.getProperty(name);
-
- if(prop == null) {
- System.out.println("Error: There is no Virtual Machine named " + name);
- return false;
- }
-
- if (path != null) {
- try {
- File f = new File(path).getCanonicalFile();
- if (!f.exists()) {
- System.out.println("Error : \""+ f.getAbsolutePath() + "\" is not exists.");
- return false;
- }
- path = f.getAbsolutePath();
- } catch (IOException e) {
- System.out.println("Error: " + e.getMessage());
- return false;
- }
- }
-
- Launcher launcher = new Launcher();
- List<String> cmd = launcher.getLaunchCommand(prop, path);
-
- if (isTest && EMLogger.getLogger().getLevel() == Level.WARNING) {
- System.out.println("Arguments of emulator : ");
- String temp = cmd.get(0) + " ";
- for (String s : cmd.subList(1, cmd.size())) {
- temp += ("\"" + s + "\" ");
- }
- System.out.println(temp);
- System.out.println();
- }
-
- if (!isTest) {
- if(prop.getWorker().isRunningNow()) {
- System.out.println("Error: Can not execute this VM.\n" +
- "The same name is running now.");
- return false;
- }
-
- if (launcher.launch(cmd)) {
- System.out.println("Success to start emulator.");
- } else {
- System.out.println("Error: Faile to start emulator.");
- return false;
- }
- }
-
- return true;
+ return processor.launchEmulator(name, path, isTest);
}
}
public Delete() {
this.action = Actions.AC_DELETE;
this.description = "Delete selected VM.";
- this.usage = "[-n | --name] test";
+ this.usage = "delete -n test";
commandList.add(new Command("n", Actions.OP_NAME,
"Name of VM to delete.","", true, true));
}
ConsoleProcessor processor = new ConsoleProcessor();
- VMsProperty prop = processor.getProperty(name);
-
- if(prop == null) {
- System.out.println("Error: There is no Virtual Machine named " + name);
- return false;
- }
-
- if(prop.getWorker().isRunningNow()) {
- System.out.println("Error: Canceled delete process!\n"
- + "[" + name + "] is running now...");
- return false;
- }
-
- try {
- prop.getWorker().deleteVM();
- } catch (VMsWorkerException e) {
- System.out.println("Error: " + e.getMessage());
- return false;
- }
-
- System.out.println("Completed delete process!");
- return true;
+ return processor.deleteVM(name);
}
}
public Reset() {
this.action = Actions.AC_RESET;
this.description = "Reset selected VM. VM's child image will be formatted.";
- this.usage = "[-n | --name] test";
+ this.usage = "reset -n test";
commandList.add(new Command("n", Actions.OP_NAME,
"Name of VM to reset image.","", true, true));
}
ConsoleProcessor processor = new ConsoleProcessor();
- VMsProperty prop = processor.getProperty(name);
-
- if(prop == null) {
- System.out.println("Error: There is no Virtual Machine named " + name);
- return false;
- }
-
- if(prop.getWorker().isRunningNow()) {
- System.out.println("Error: Canceled reset process!\n"
- + "[" + name + "] is running now...");
- return false;
- }
-
- try {
- prop.getWorker().resetVM();
- } catch (VMsWorkerException e) {
- System.out.println("Error: " + e.getMessage());
- return false;
- }
-
- System.out.println("Completed reset process!");
- return true;
+ return processor.resetVM(name);
}
}
public CreateBaseImage() {
this.action = Actions.AC_CREATE_IMAGE;
this.description = "Create base target image using VM's child image.";
- this.usage = "[-n | --name] test";
+ this.usage = "create-image -n test [options]";
commandList.add(new Command("n", Actions.OP_NAME,
"Name of VM to create base target image.","", true, true));
}
ConsoleProcessor processor = new ConsoleProcessor();
- VMsProperty prop = processor.getProperty(name);
-
- if(prop == null) {
- System.out.println("Error: There is no Virtual Machine named " + name);
- return false;
- }
-
- if(prop.getWorker().isRunningNow()) {
- System.out.println("Error: Canceled 'Create Base Image' process!\n"
- + "[" + name + "] is running now...");
- return false;
- }
-
- // Check path
- if (new File(path).exists()) {
- System.out.println("Error: This directory does not exist. (Path : " + path + ")");
- }
-
- try {
- prop.getWorker().createNewBaseImage(prop, path);
- } catch (VMsWorkerException e) {
- System.out.println("Error: " + e.getMessage());
- return false;
- }
-
- System.out.println("Succeeded to create 'Base Image'!\nPath: " + path);
- return true;
+ return processor.createBaseIamge(name, path);
}
}
public Clone() {
this.action = Actions.AC_COLONE;
this.description = "Clone new VM which has the same configurations ad you selected..";
- this.usage = "[-n | --name] test [-t | --target-name] target";
+ this.usage = "clone -n test -t target";
commandList.add(new Command("n", Actions.OP_NAME,
"Name of VM to create base target image.","", true, true));
}
ConsoleProcessor processor = new ConsoleProcessor();
- VMsProperty prop = processor.getProperty(name);
-
- if(prop == null) {
- System.out.println("Error: There is no Virtual Machine named " + name);
- return false;
- }
-
- VMCreateHelper helper = new VMCreateHelper();
- if (helper.checkDupulicateName(target)) {
- System.out.println("Error: The target name (" + target + ") already exists!");
- return false;
- }
-
- try {
- prop.getWorker().cloneVM(target);
- } catch (VMsWorkerException e) {
- System.out.println("Error: " + e.getMessage());
- return false;
- }
-
- System.out.println("Emulator cloning completed!");
- return true;
+ return processor.cloneVM(name, target);
}
}
\ No newline at end of file
package org.tizen.emulator.manager.console;
+import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
import org.tizen.emulator.manager.image.BaseImage;
import org.tizen.emulator.manager.image.EmulatorImages;
+import org.tizen.emulator.manager.logging.EMLogger;
import org.tizen.emulator.manager.tool.About;
import org.tizen.emulator.manager.vms.EmulatorVMs;
+import org.tizen.emulator.manager.vms.Launcher;
+import org.tizen.emulator.manager.vms.VMCreateHelper;
import org.tizen.emulator.manager.vms.VMsProperty;
+import org.tizen.emulator.manager.vms.VMsWorkerException;
import org.tizen.emulator.manager.vms.VMsProperty.FSImageType;
public class ConsoleProcessor {
private EmulatorVMs vms = EmulatorVMs.getInstance();
+ public VMsProperty getProperty(String value) {
+ return vms.getProperty(value);
+ }
+
public String getAboutInfo() {
return "Emulator Manager\n"+
About.getInstance().getContents();
}
}
- @SuppressWarnings("finally")
- public String getInfoOfVM(VMsProperty prop) {
- String str = new String();
- try {
- str += String.format("%s\n", prop.getName());
- str+= String.format("\t%-17s : %s\n", "ImageType",prop.getImageType());
- if (prop.getImageType() == FSImageType.standard) {
- str+= String.format("\t%-17s : %s\n", "Version" ,
- prop.getConfiguration().getBaseInformation().getDiskImage().getVersion());
- }
-
- str+= String.format("\t%-17s : %s\n", "Resolution",
- (prop.getConfiguration().getDevice().getDisplay().getResolution().getWidth()
- + "x" + prop.getConfiguration().getDevice().getDisplay().getResolution().getHeight()));
-
- str+= String.format("\t%-17s : %s\n", "DPI",
- prop.getConfiguration().getDevice().getDisplay().getDensity().getValue());
- str+= String.format("\t%-17s : %s\n", "RAM Size",
- prop.getConfiguration().getDevice().getRAM().getSize().getValue());
- } catch (Exception e) {
- } finally {
- return str;
- }
- }
-
public String getDetailInfoOfVM(String value) {
VMsProperty prop = vms.getProperty(value);
if (prop == null) {
}
}
- public VMsProperty getProperty(String value) {
- return vms.getProperty(value);
- }
-
public ArrayList<String> getInfoOfVMList(boolean isDetail) {
ArrayList<String> message = new ArrayList<String>();
VMsProperty[] properties = (VMsProperty[])vms.getProperties();
}
return list;
}
+
+ public boolean launchEmulator(String name, String path, boolean isTest) {
+ VMsProperty prop = getProperty(name);
+
+ if(prop == null) {
+ System.out.println("Error: There is no Virtual Machine named " + name);
+ return false;
+ }
+
+ if (path != null) {
+ try {
+ File f = new File(path).getCanonicalFile();
+ if (!f.exists()) {
+ System.out.println("Error : \""+ f.getAbsolutePath() + "\" is not exists.");
+ return false;
+ }
+ path = f.getAbsolutePath();
+ } catch (IOException e) {
+ System.out.println("Error: " + e.getMessage());
+ return false;
+ }
+ }
+
+ Launcher launcher = new Launcher();
+ List<String> cmd = launcher.getLaunchCommand(prop, path);
+
+ if (isTest && EMLogger.getLogger().getLevel() == Level.WARNING) {
+ System.out.println("Arguments of emulator : ");
+ String temp = cmd.get(0) + " ";
+ for (String s : cmd.subList(1, cmd.size())) {
+ temp += ("\"" + s + "\" ");
+ }
+ System.out.println(temp);
+ System.out.println();
+ }
+
+ if (!isTest) {
+ if(prop.getWorker().isRunningNow()) {
+ System.out.println("Error: Can not execute this VM.\n" +
+ "The same name is running now.");
+ return false;
+ }
+
+ if (launcher.launch(cmd)) {
+ System.out.println("Success to start emulator.");
+ } else {
+ System.out.println("Error: Faile to start emulator.");
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public boolean deleteVM(String name) {
+ VMsProperty prop = getProperty(name);
+
+ if(prop == null) {
+ System.out.println("Error: There is no Virtual Machine named " + name);
+ return false;
+ }
+
+ if(prop.getWorker().isRunningNow()) {
+ System.out.println("Error: Canceled delete process!\n"
+ + "[" + name + "] is running now...");
+ return false;
+ }
+
+ try {
+ prop.getWorker().deleteVM();
+ } catch (VMsWorkerException e) {
+ System.out.println("Error: " + e.getMessage());
+ return false;
+ }
+
+ System.out.println("Completed delete process!");
+ return true;
+ }
+
+ public boolean resetVM(String name) {
+ VMsProperty prop = getProperty(name);
+
+ if(prop == null) {
+ System.out.println("Error: There is no Virtual Machine named " + name);
+ return false;
+ }
+
+ if(prop.getWorker().isRunningNow()) {
+ System.out.println("Error: Canceled reset process!\n"
+ + "[" + name + "] is running now...");
+ return false;
+ }
+
+ try {
+ prop.getWorker().resetVM();
+ } catch (VMsWorkerException e) {
+ System.out.println("Error: " + e.getMessage());
+ return false;
+ }
+
+ System.out.println("Completed reset process!");
+ return true;
+ }
+
+ public boolean createBaseIamge(String name, String path) {
+ VMsProperty prop = getProperty(name);
+
+ if(prop == null) {
+ System.out.println("Error: There is no Virtual Machine named " + name);
+ return false;
+ }
+
+ if(prop.getWorker().isRunningNow()) {
+ System.out.println("Error: Canceled 'Create Base Image' process!\n"
+ + "[" + name + "] is running now...");
+ return false;
+ }
+
+ // Check path
+ if (new File(path).exists()) {
+ System.out.println("Error: This directory does not exist. (Path : " + path + ")");
+ }
+
+ try {
+ prop.getWorker().createNewBaseImage(prop, path);
+ } catch (VMsWorkerException e) {
+ System.out.println("Error: " + e.getMessage());
+ return false;
+ }
+
+ System.out.println("Succeeded to create 'Base Image'!\nPath: " + path);
+ return true;
+ }
+
+ public boolean cloneVM(String name, String target) {
+ VMsProperty prop = getProperty(name);
+
+ if(prop == null) {
+ System.out.println("Error: There is no Virtual Machine named " + name);
+ return false;
+ }
+
+ VMCreateHelper helper = new VMCreateHelper();
+ if (helper.checkDupulicateName(target)) {
+ System.out.println("Error: The target name (" + target + ") already exists!");
+ return false;
+ }
+
+ try {
+ prop.getWorker().cloneVM(target);
+ } catch (VMsWorkerException e) {
+ System.out.println("Error: " + e.getMessage());
+ return false;
+ }
+
+ System.out.println("Emulator cloning completed!");
+ return true;
+ }
}
throw new VMsWorkerException("Failed to create base image!\nFile does not exist :" + childImage);
}
- //long childSize = childImage.length();
- //long baseSize = baseImage.length();
- //final long maxSize = childSize + baseSize;
-
String exe_path = FileIO.getInstance().getBinPath() + File.separator + "qemu-img";
List<String> cmd = new ArrayList<String>();
final QemuImgProc proc = new QemuImgProc(cmd);
/*
+ long childSize = childImage.length();
+ long baseSize = baseImage.length();
+ final long maxSize = childSize + baseSize;
final File destFile = new File(dest);
final CreateBaseImageDialog dialog
- = new CreateBaseImageDialog(EmulatorManager.getInstance().getMainDialog().getShell());
+ = new CreateBaseImageDialog(EmulatorManager.getInstance().getMainDialog().getShell());
dialog.Open(destFile, maxSize);
*/
-
+
workerThread worker = new workerThread(proc);
worker.start();
synchronized(worker) {
- try {
- worker.wait(2000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- } finally {
- if (worker.isError()) {
- throw new VMsWorkerException("Failed to create new base image becauese of failed qemu-img processing!\n"
- + "You can get more information in log file ("
- + FileIO.getInstance().getTizenVmsArchPath() + File.separator + "emulator-manager)");
+ try {
+ worker.wait(3000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } finally {
+ if (worker.isError()) {
+ throw new VMsWorkerException("Failed to create new base image becauese of failed qemu-img processing!\n"
+ + "You can get more information in log file ("
+ + FileIO.getInstance().getTizenVmsArchPath() + File.separator + "emulator-manager)");
+ }
}
}
- }
/*
if (! proc.Running()) {
info.setText("Wait....while creating base image.\n"
+ "This task can take about 30 ~ 60 seconds");
info.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
-
+
bar = new ProgressBar(dialog, SWT.SMOOTH);
bar.setBounds(10, 10, 200, 32);
bar.setMaximum(100);
public void handleEvent(Event event) {
// Empty
}
-
+
});
dialog.addMouseListener(new MouseListener(){
@Override
public void mouseDoubleClick(MouseEvent e) {
// TODO Auto-generated method stub
-
}
@Override
public void mouseDown(MouseEvent e) {
// TODO Auto-generated method stub
-
}
@Override
public void mouseUp(MouseEvent e) {
// TODO Auto-generated method stub
-
}
-
});
}
}
public void Open(final File destFile, final long maxSize) {
dialog.open();
-
- new Thread(new Runnable() {
- public void run() {
- int i = 0;
- while(i != 100 && !dialog.isDisposed()) {
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- break;
- }
- i = (int)((destFile.length() / maxSize) * 100.0);
- setSelection(i);
- }
- }
- }).start();
-
}
public void Close() {