[Title] add checking exit value of qemu-img
authorjihye kim <jihye1128.kim@samsung.com>
Wed, 27 Jun 2012 07:35:29 +0000 (16:35 +0900)
committerjihye kim <jihye1128.kim@samsung.com>
Wed, 27 Jun 2012 07:35:29 +0000 (16:35 +0900)
[Type] bug fix
[Module] emulator manager
[Priority] major
[Jira#] N_SE-2066
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

src/org/tizen/emulator/manager/vms/Creator.java

index 3b5fb7b..583fe01 100644 (file)
 
 package org.tizen.emulator.manager.vms;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.logging.Level;
 
 import org.tizen.emulator.manager.EmulatorManager;
 import org.tizen.emulator.manager.EmulatorManager.ManagerModeType;
+import org.tizen.emulator.manager.logging.EMLogger;
 import org.tizen.emulator.manager.tool.About;
 import org.tizen.emulator.manager.tool.FileIO;
 import org.tizen.emulator.manager.vms.VMsProperty.Architecture;
@@ -134,7 +138,40 @@ public class Creator {
                
                ProcessBuilder pb = new ProcessBuilder(cmd);
                try {
-                       pb.start();
+                       Process process = pb.start();
+
+                       if (process != null) {
+                               final BufferedReader in = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+                               new Thread(new Runnable() {
+                                       @Override
+                                       public void run() {
+                                               try {
+                                                       String str = null;
+                                                       do {
+                                                               str = in.readLine();
+                                                               if (str!= null) {
+                                                                       EMLogger.getLogger().log(Level.WARNING,
+                                                                               "Error while running qemu-img\n" + str);
+                                                               }
+                                                       } while (str != null);
+                                               } catch (IOException e) {
+                                                       EMLogger.getLogger().log(Level.WARNING,
+                                                                       "Error while running qemu-img\n" + e.getMessage());
+                                               }
+                                       }
+                               }).start();
+
+                               // wait for ending process
+                               try {
+                                       if (process.waitFor() != 0){
+                                               throw new VMsCreatorException("Failed to create the VM because of failed qemu-img processing.\n"
+                                                               + "You can get more information in log file ("
+                                                               + FileIO.getInstance().getTizenVmsArchPath() +  File.separator + "emulator-manager)");
+                                       }
+                               } catch (InterruptedException e) {
+                                       throw new VMsCreatorException("Failed to create the VM while running qemu-img.\n" + e.getMessage());
+                               }
+                       }
                } catch (IOException e) {
                        throw new VMsCreatorException("Failed to create the VM!\n" + e.getMessage());
                }