[Title] emulator-manager : merge branch 'develop' into ux
authorjihye1128.kim <jihye1128.kim@samsung.com>
Thu, 18 Apr 2013 06:28:52 +0000 (15:28 +0900)
committerjihye1128.kim <jihye1128.kim@samsung.com>
Thu, 18 Apr 2013 06:28:52 +0000 (15:28 +0900)
[Desc.] merge branch 'develop' into ux
[Issue] N/A

Change-Id: I3e1b30694a9ee9e2d8fc719625adbe60b51ef5f0

12 files changed:
src/org/tizen/emulator/manager/EmulatorManager.java
src/org/tizen/emulator/manager/console/ConsoleProcessor.java
src/org/tizen/emulator/manager/logging/EMLogger.java
src/org/tizen/emulator/manager/tool/CheckVirtualization.java
src/org/tizen/emulator/manager/tool/SelectWorkspace.java
src/org/tizen/emulator/manager/ui/MainDialog.java
src/org/tizen/emulator/manager/ui/VMsMainView.java
src/org/tizen/emulator/manager/ui/detail/PModifyViewPage.java
src/org/tizen/emulator/manager/ui/dialog/CloneDialog.java
src/org/tizen/emulator/manager/vms/Launcher.java
src/org/tizen/emulator/manager/vms/MonitoringEmulator.java [new file with mode: 0644]
src/org/tizen/emulator/manager/vms/VMWorker.java

index 88cbe0b..4b3fafa 100755 (executable)
@@ -220,7 +220,6 @@ public class EmulatorManager {
 
        public static void main(String[] args) {
                if (isMac()) {
-                       //TODO : event handling of about menu
                        System.setProperty("apple.laf.useScreenMenuBar", "true");
                        System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Emulator Manager");        
                }
index dacf8f3..4baa551 100644 (file)
@@ -40,9 +40,11 @@ import org.tizen.emulator.manager.logging.EMLogger;
 import org.tizen.emulator.manager.platform.BaseImage;
 import org.tizen.emulator.manager.platform.Platform;
 import org.tizen.emulator.manager.tool.About;
+import org.tizen.emulator.manager.vms.CheckingRunningEmulator;
 import org.tizen.emulator.manager.vms.EmulatorVMList;
 import org.tizen.emulator.manager.vms.HelperClass;
 import org.tizen.emulator.manager.vms.Launcher;
+import org.tizen.emulator.manager.vms.MonitoringEmulator;
 import org.tizen.emulator.manager.vms.VMProperty;
 import org.tizen.emulator.manager.vms.VMProperty.FSImageType;
 import org.tizen.emulator.manager.vms.VMWorkerException;
@@ -234,8 +236,20 @@ public class ConsoleProcessor {
                                return false;
                        }
 
-                       if (launcher.launch(cmd)) {
-                               System.out.println("Success: To start emulator is completed.");
+                       CheckingRunningEmulator.addEmulator(prop.getName());
+                       MonitoringEmulator monitor = new MonitoringEmulator(prop);
+                       Process process = launcher.launch(cmd);
+                       if (process != null) {
+                               monitor.setProcess(process, 5);
+                               monitor.start();
+                               try {
+                                       monitor.join();
+                               } catch (InterruptedException e) {
+                                       System.out.println(e.getMessage());
+                               }
+                               if (monitor.isSuccess()) {
+                                       System.out.println("Success: To start emulator is completed.");
+                               }
                        } else {
                                System.out.println("Error: Faile to start emulator.");
                                return false;
index 560a2a1..180fe53 100644 (file)
@@ -90,7 +90,7 @@ public class EMLogger {
                        }
                        logFileHandler = new FileHandler(logFolder.getAbsolutePath() + File.separator + LOG_FILE_NAME);
                        
-                       logger.setLevel(Level.ALL);
+                       logger.setLevel(Level.INFO);
                        logFileHandler.setLevel(Level.INFO);
                        
                        logFileHandler.setFormatter(new LoggerFormatter());
index 3aebbd5..acf97e4 100644 (file)
@@ -152,11 +152,11 @@ public class CheckVirtualization {
                                        exitValue = process.exitValue();
                                        EMLogger.getLogger().log(Level.INFO, "Check-hax.exe's exit value : " + exitValue);
                                } catch (IOException e) {
-                                       EMLogger.getLogger().log(Level.INFO, "IOException" + e.getMessage());
+                                       EMLogger.getLogger().log(Level.WARNING, "IOException" + e.getMessage());
                                }  catch (InterruptedException e) {
-                                       EMLogger.getLogger().log(Level.INFO, "InterruptedException" + e.getMessage());
+                                       EMLogger.getLogger().log(Level.WARNING, "InterruptedException" + e.getMessage());
                                }  catch (Exception e) {
-                                       EMLogger.getLogger().log(Level.INFO, "Exception" + e.getMessage());
+                                       EMLogger.getLogger().log(Level.WARNING, "Exception" + e.getMessage());
                                }
 
                                if(exitValue == 0) {
index 6e07c02..e99c20c 100644 (file)
@@ -77,7 +77,7 @@ public class SelectWorkspace {
                try {
                        inputStream = new FileInputStream(workspaceConfPath);
                } catch (FileNotFoundException e1) {
-                       EMLogger.getLogger().log(Level.WARNING, "Faile to get current workspace: \n"+ e1.getMessage());
+                       EMLogger.getLogger().log(Level.WARNING, "Faile to get current workspace: "+ e1.getMessage());
                        createPropertyFile(workspaceConfPath);
                        return false;
                }
@@ -85,7 +85,7 @@ public class SelectWorkspace {
                try {
                        prop.load(inputStream);
                } catch (IOException e) {
-                       EMLogger.getLogger().log(Level.WARNING, "Faile to get current workspace: \n" + e.getMessage());
+                       EMLogger.getLogger().log(Level.WARNING, "Faile to get current workspace: " + e.getMessage());
                        result = false;
                }
 
@@ -258,7 +258,7 @@ public class SelectWorkspace {
                        }
 
                logger.log(Level.INFO, String.format(
-                               "Network name = %s, MAC = %s\n",
+                               "Network name = %s, MAC = %s",
                                ni.getDisplayName(), macAddr));
        }
 
@@ -274,12 +274,12 @@ public class SelectWorkspace {
                } catch (SocketException e) {
                        logger.log(
                                        Level.WARNING,
-                                       String.format("Failed to get MAC address of host: %s\n",
+                                       String.format("Failed to get MAC address of host: %s",
                                                        e.getMessage()));
                } catch (UnknownHostException e) {
                        logger.log(
                                        Level.WARNING,
-                                       String.format("Failed to get MAC address of host: %s\n",
+                                       String.format("Failed to get MAC address of host: %s",
                                                        e.getMessage()));
                }
 
@@ -386,7 +386,7 @@ public class SelectWorkspace {
                                /* means both MAC_ADDRESS key and value are existed */
                                else {
                                        logger.log(Level.INFO,
-                                                       String.format("Use original MAC = %s\n", macAddr));
+                                                       String.format("Use original MAC = %s", macAddr));
                                }
 
                                if (workspacePath == null) {
@@ -454,11 +454,13 @@ public class SelectWorkspace {
                        if(!fi.mkdirs()) {
                                if (!EmulatorManager.isConsoleMode()) {
                                        MessageDialog msg = new MessageDialog(new Shell(Display.getCurrent()));
-                                       msg.openWarningDialog("Can not organize workspace. Aborting...\n" +
-                                                       "User do not have authority to use [" + path + "]"); 
+                                       msg.openWarningDialog("Can not organize workspace. Aborting..."
+                                                       + StringResources.NEW_LINE
+                                                       + "User do not have authority to use [" + path + "]");
                                }
-                               EMLogger.getLogger().log(Level.WARNING, "Can not organize workspace. Aborting...\n" +
-                                                                               "User do not have authority to use [" + path + "]");
+                               EMLogger.getLogger().log(Level.WARNING, "Can not organize workspace. Aborting..."
+                                                       + StringResources.NEW_LINE
+                                                       + "User do not have authority to use [" + path + "]");
                                EmulatorManager.exitEmulatorManager(-1);
                        }
                }
index 6e676d0..f6d4eec 100644 (file)
@@ -218,9 +218,13 @@ public class MainDialog {
                return statusBar;
        }
 
-       public static void refreshVMPropertyList() {
+       public static void refreshVMPropertyList(boolean isClear) {
                EmulatorManager.settingVMPropertyList();
-               tabFolder.getSelection().draw();
+               if (isClear) {
+                       tabFolder.getSelection().draw();
+               } else {
+                       tabFolder.getSelection().redraw();
+               }
        }
 
        public void dispose() {
@@ -245,7 +249,7 @@ public class MainDialog {
                        @Override
                        public void handleClickEvent(DACustomButton button) {
                                // reload vm list
-                               refreshVMPropertyList();
+                               refreshVMPropertyList(true);
                        }
                });
        }
index 3911947..307957c 100644 (file)
@@ -298,7 +298,7 @@ public class VMsMainView {
 
        public boolean deleteEmulator() {
                handling.deleteVirtualMachine(currentProperty);
-               MainDialog.refreshVMPropertyList();
+               MainDialog.refreshVMPropertyList(true);
                return true;
        }
 
index ee30670..1b072d5 100644 (file)
@@ -133,7 +133,7 @@ public class PModifyViewPage extends DetailViewPage
                        }
                }
 
-               MainDialog.refreshVMPropertyList();
+               MainDialog.refreshVMPropertyList(false);
        }
 
        VMPropertyValue oldValue;
index ccbf1ca..17e0639 100644 (file)
@@ -128,7 +128,7 @@ public class CloneDialog {
                                }
 
                                dialog.close();
-                               MainDialog.refreshVMPropertyList();
+                               MainDialog.refreshVMPropertyList(true);
                                //mainDialog.vmsTree.setSelectProperty(property);
                        }
                        
@@ -142,7 +142,7 @@ public class CloneDialog {
                        @Override
                        public void widgetSelected(SelectionEvent arg0) {
                                dialog.close();
-                               MainDialog.refreshVMPropertyList();
+                               MainDialog.refreshVMPropertyList(true);
                                //mainDialog.vmsTree.setSelectProperty(property);
                        }
                        
index fe28204..79b1575 100644 (file)
 
 package org.tizen.emulator.manager.vms;
 
-import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.logging.Level;
@@ -44,6 +42,7 @@ import org.eclipse.swt.widgets.Shell;
 import org.tizen.emulator.manager.EmulatorManager;
 import org.tizen.emulator.manager.logging.EMLogger;
 import org.tizen.emulator.manager.resources.FilePath;
+import org.tizen.emulator.manager.resources.StringResources;
 import org.tizen.emulator.manager.tool.CheckVirtualization;
 import org.tizen.emulator.manager.tool.PortHelper;
 import org.tizen.emulator.manager.tool.SelectWorkspace;
@@ -68,7 +67,9 @@ public class Launcher {
                /* check available port number */
                portNo = new PortHelper().getPortNo();
                if(portNo == -1) {
-                       String error = "Can not execute emulator.\n All available ports are in use.";
+                       String error = "Can not execute emulator."
+                                       + StringResources.NEW_LINE
+                                       + "All available ports are in use.";
                        if (!isConsole) {
                                MessageDialog alert = new MessageDialog(MainDialog.getShell());
                                alert.openInfoDialog(error);
@@ -383,7 +384,9 @@ public class Launcher {
 
                CheckingRunningEmulator.addEmulator(property.getName());
                MonitoringEmulator monitor = new MonitoringEmulator(property);
-               if (launch(cmd)) {
+               Process process = launch(cmd);
+               if (process != null) {
+                       monitor.setProcess(process);
                        monitor.start();
                        return true;
                } else {
@@ -393,7 +396,7 @@ public class Launcher {
                }
        }
 
-       public boolean launch(List<String> cmd) {
+       public Process launch(List<String> cmd) {
                FilePath fio = FilePath.getInstance();
                ProcessBuilder pb = new ProcessBuilder(cmd);
                
@@ -403,75 +406,17 @@ public class Launcher {
                        pb.directory(new File(this.binPath));
                }
                
+               Process process = null;
                try {
-                       Process process = pb.start();
-
-                       final InputStream in1 = new BufferedInputStream(process.getInputStream());
-                       final InputStream in2 = new BufferedInputStream(process.getErrorStream());
-                       
-                       new Thread(new Runnable() {
-                               @Override
-                               public void run() {
-                                       try {
-                                               in1.read();
-                                       } catch (IOException e) {
-                                               e.printStackTrace();
-                                       }
-                               }
-                       }).start();
-
-                       new Thread(new Runnable() {
-                               @Override
-                               public void run() {
-                                       try {
-                                               in2.read();
-                                       } catch (IOException e) {
-                                               e.printStackTrace();
-                                       }
-                               }
-                       }).start();
-
+                       process = pb.start();
                } catch (IOException e) {
                        if (!isConsole) {                       
                                MessageDialog msg = new MessageDialog(new Shell(Display.getCurrent()));
                                msg.openWarningDialog("Failed to launch\n" + e.getMessage());
                        }
                        EMLogger.getLogger().log(Level.WARNING, "Failed to launch.\n" + e.getMessage());
-                       return false;
                }
                
-               return true;
-       }
-}
-
-class MonitoringEmulator extends Thread {
-       private VMProperty property;
-       public MonitoringEmulator(VMProperty property) {
-               this.property = property;
-               this.setDaemon(true);
-       }
-
-       public void run() {
-               boolean isChecking = false;
-               for (int i = 0; i < 8 ; i++) {
-                       if (VMWorker.checking(property)) {
-                               isChecking = true;
-                               CheckingRunningEmulator.removeEmulator(property.getName());
-                               break;
-                       }
-
-                       synchronized(this) {
-                               try {
-                                       this.wait(1000);
-                               } catch (InterruptedException e) {
-                                       EMLogger.getLogger().warning(e.getMessage());
-                                       break;
-                               }
-                       }
-               }
-
-               if (!isChecking) {
-                       CheckingRunningEmulator.removeEmulator(property.getName());
-               }
+               return process;
        }
 }
\ No newline at end of file
diff --git a/src/org/tizen/emulator/manager/vms/MonitoringEmulator.java b/src/org/tizen/emulator/manager/vms/MonitoringEmulator.java
new file mode 100644 (file)
index 0000000..991f683
--- /dev/null
@@ -0,0 +1,177 @@
+package org.tizen.emulator.manager.vms;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.logging.Level;
+
+import org.eclipse.swt.widgets.Display;
+import org.tizen.emulator.manager.EmulatorManager;
+import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.resources.StringResources;
+import org.tizen.emulator.manager.ui.dialog.MessageDialog;
+
+public class MonitoringEmulator extends Thread {
+       private VMProperty property;
+       private Process process;
+       private int count = 8;
+
+       public MonitoringEmulator(VMProperty property) {
+               this.property = property;
+               this.setDaemon(true);
+       }
+
+       public void setProcess(Process process) {
+               this.process = process;
+       }
+
+       public void setProcess(Process process, int count) {
+               this.process = process;
+               this.count = count;
+       }
+
+       private BufferedReader readerOut   = null;
+       private BufferedReader readerError = null;
+       private StdOut stdOut = null;
+       private StdOut stdErr = null;
+       private boolean success = true;
+
+       public void run() {
+               /*
+               boolean isChecking = false;
+               for (int i = 0; i < 8 ; i++) {
+                       if (VMsWorker.checking(property)) {
+                               isChecking = true;
+                               CheckingRunningEmulator.removeEmulator(property.getName());
+                               break;
+                       }
+
+                       synchronized(this) {
+                               try {
+                                       this.wait(1000);
+                               } catch (InterruptedException e) {
+                                       EMLogger.getLogger().warning(e.getMessage());
+                                       break;
+                               }
+                       }
+               }
+
+               if (!isChecking) {
+                       CheckingRunningEmulator.removeEmulator(property.getName());
+               }
+               */
+               if (process == null || property == null) {
+                       return;
+               }
+
+               InputStreamReader in1 = new InputStreamReader(process.getInputStream());
+               InputStreamReader in2 = new InputStreamReader(process.getErrorStream());
+               readerOut = new BufferedReader(in1);
+               readerError = new BufferedReader(in2);
+
+               stdOut = new StdOut(readerOut, property.getName());
+               stdErr = new StdOut(readerError, property.getName());
+
+               new Thread(stdOut).start();
+               new Thread(stdErr).start();
+
+               for (int i = 0; i < count; i++) {
+                       try {
+                               if (process.exitValue() != 0) {
+                                       setSuccess(false);
+                                       stdOut.printMessageList();
+                                       stdErr.printMessageList();
+                                       EMLogger.getLogger().warning("Emulator has been terminated. Exit value: " + process.exitValue()
+                                                       + StringResources.NEW_LINE
+                                                       + "You can see more information in the emulator-manager.log or "
+                                                       + property.getName() + "'s logs directory.");
+                                       if (!EmulatorManager.isConsoleMode()) {
+                                               Display.getDefault().asyncExec(new Runnable(){
+
+                                                       @Override
+                                                       public void run() {
+                                                               new MessageDialog().openWarningDialog("Emulator has been terminated."
+                                                                               + StringResources.NEW_LINE
+                                                                               + "You can see more information "
+                                                                               + StringResources.NEW_LINE
+                                                                               + "in the emulator-manager.log or "
+                                                                               + property.getName() + "'s logs directory.");
+                                                       }
+
+                                               });
+                                       }
+                                       break;
+                               } else {
+                                       EMLogger.getLogger().warning("Emulator has been terminated. Exit value: " + process.exitValue());
+                                       stdOut.printMessageList();
+                                       stdErr.printMessageList();
+                                       break;
+                               }
+                       } catch(IllegalThreadStateException e) {
+                               // empty
+                               EMLogger.getLogger().log(Level.FINE, e.getMessage());
+                       }
+
+                       synchronized(this) {
+                               try {
+                                       this.wait(1000);
+                               } catch (InterruptedException e) {
+                                       EMLogger.getLogger().warning(e.getMessage());
+                                       break;
+                               }
+                       }
+               }
+
+               CheckingRunningEmulator.removeEmulator(property.getName());
+       }
+
+       public boolean isSuccess() {
+               return success;
+       }
+
+       public void setSuccess(boolean success) {
+               this.success = success;
+       }
+}
+
+class StdOut implements Runnable {
+       private BufferedReader reader;
+       private String emName;
+       private final ArrayList<String> list =  new ArrayList<String>();
+       public StdOut(BufferedReader reader, String name) {
+               this.reader = reader;
+               this.emName = name;
+       }
+
+       public StdOut(InputStreamReader in, String name) {
+               this.reader = new BufferedReader(in);
+               this.emName = name;
+       }
+
+       @ Override
+       public void run() {
+               String msg;
+               do {
+                       try {
+                               msg = reader.readLine();
+                               list.add(msg);
+                       } catch (IOException e) {
+                               EMLogger.getLogger().info(e.getMessage());
+                       }
+
+               } while (CheckingRunningEmulator.isContains(emName));
+               if (error) {
+                       for (String s : list) {
+                               if (s != null && !s.isEmpty()) {
+                                       EMLogger.getLogger().warning("Print Log From Emulator: " + s);
+                               }
+                       }
+               }
+       }
+
+       private boolean error = false;
+       public void printMessageList() {
+               error = true;
+       }
+}
index cd98ebf..317bf76 100644 (file)
@@ -116,7 +116,7 @@ public class VMWorker {
                worker = new WorkerThread(proc);
                worker.start();
                if (EmulatorManager.isConsoleMode()) {
-                       System.out.println("Wait....while creating base image.\n"
+                       System.out.println("Wait....while creating base image." + StringResources.NEW_LINE
                                                                + "This task can take about 30 ~ 60 seconds");
                        synchronized(worker) {
                                try {