[Title] check qemu-img process error and change count of max touch point(2 -> 3)
authorjihye kim <jihye1128.kim@samsung.com>
Thu, 5 Jul 2012 04:32:11 +0000 (13:32 +0900)
committerjihye kim <jihye1128.kim@samsung.com>
Thu, 5 Jul 2012 04:32:11 +0000 (13:32 +0900)
[Type] bug fix
[Module] emulator manager
[Priority] major
[Jira#] N_SE-2529 N_SE-2515
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

package/pkginfo.manifest
src/org/tizen/emulator/manager/console/ConsoleCreateVM.java
src/org/tizen/emulator/manager/ui/MessageDialog.java
src/org/tizen/emulator/manager/ui/detail/VMPropertyView.java
src/org/tizen/emulator/manager/vms/Creator.java
src/org/tizen/emulator/manager/vms/QemuImgProc.java [new file with mode: 0644]
src/org/tizen/emulator/manager/vms/VMCreateHelper.java
src/org/tizen/emulator/manager/vms/VMPropertyValue.java
src/org/tizen/emulator/manager/vms/VMsWorker.java

index 29eb092..4629a1f 100644 (file)
@@ -1,5 +1,5 @@
 Package: emulator-manager
-Version: 1.0.65
+Version: 1.0.66
 OS: linux
 Build-host-os: linux
 Maintainer: Yeong-Kyoon Lee<yeongkyoon.lee@samsung.com>
@@ -7,7 +7,7 @@ Source: emulator-manager
 Description: Tizen Emulator Manager
 
 Package: emulator-manager
-Version: 1.0.65
+Version: 1.0.66
 OS: windows
 Build-host-os: windows
 Maintainer: Yeong-Kyoon Lee<yeongkyoon.lee@samsung.com>
index a00a7b2..dc12fa7 100644 (file)
@@ -204,9 +204,9 @@ public class ConsoleCreateVM {
                }
                else if (c.getLongName() == Actions.OP_MAXTOUCH) {
                        int i = Integer.valueOf(c.getCurrentValue());
-                       if (i != 1 && i != 2) {
+                       if (i != 1 && i != 2 && i != 3) {
                                throw new ConsoleException("This value(" + c.getCurrentValue() + ") "
-                                               + "is not avaliable. Avaliable mulit-touch point is 1 or 2.");
+                                               + "is not avaliable. Avaliable mulit-touch point is 1 - 3.");
                        }
                        prop.maxTouchCount = i;
                }
index d81ec72..25a4fa7 100644 (file)
@@ -82,4 +82,8 @@ public class MessageDialog
         msgResponse = dialog.open();
        return msgResponse;
     }
+
+    public void dispose() {
+        shell.dispose();
+    }
 }
index 0c0861c..5a19d49 100644 (file)
@@ -696,7 +696,7 @@ public class VMPropertyView {
 
        private void createTouchArea(Table table) {
                widget.TouchSpinner = new Spinner(table, SWT.BORDER);
-               widget.TouchSpinner.setValues(oldValue.maxTouchCount, 1, 2, 0, 1, 1);
+               widget.TouchSpinner.setValues(oldValue.maxTouchCount, 1, 3, 0, 1, 1);
 
                createTouchListener();
        }
index 2fb9be5..3d87490 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.logging.EMLogger;
 import org.tizen.emulator.manager.tool.About;
 import org.tizen.emulator.manager.tool.FileIO;
 import org.tizen.emulator.manager.vms.VMsProperty.Architecture;
@@ -124,8 +119,6 @@ public class Creator {
                createInitialVMImageInternal(newVM.baseImagePath, targetPath);
        }
 
-       private boolean isError = false;
-       private String errorMsg = null;
        private void checkCustomBaseImage(final String path) throws VMsCreatorException {
                String exe_path = FileIO.getInstance().getBinPath() + File.separator + "qemu-img";
 
@@ -134,6 +127,11 @@ public class Creator {
                cmd.add("info");
                cmd.add(path);
 
+               String errorMsg = new QemuImgProc(cmd).RunningForCheckImg();
+               if (errorMsg != null) {
+                       throw new VMsCreatorException(errorMsg);
+               }
+               /*
                ProcessBuilder pb = new ProcessBuilder(cmd);
                try {
                        Process process = pb.start();
@@ -215,6 +213,7 @@ public class Creator {
                } catch (IOException e) {
                        throw new VMsCreatorException("Failed check base image..." + e.getMessage());
                }
+               */
        }
 
        public void createInitialVMImageInternal(String baseImagePath, String targetImagePath) throws VMsCreatorException {
@@ -228,46 +227,11 @@ public class Creator {
                cmd.add("-f");
                cmd.add("qcow2");
                cmd.add(targetImagePath);
-               
-               ProcessBuilder pb = new ProcessBuilder(cmd);
-               try {
-                       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'(stderr)\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.(Exit vlaue: " +
-                                                               + process.exitValue() +")\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());
+               if (!new QemuImgProc(cmd).Running()) {
+                       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)");
                }
        }
 
diff --git a/src/org/tizen/emulator/manager/vms/QemuImgProc.java b/src/org/tizen/emulator/manager/vms/QemuImgProc.java
new file mode 100644 (file)
index 0000000..e33ce60
--- /dev/null
@@ -0,0 +1,160 @@
+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.List;
+import java.util.logging.Level;
+
+import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.tool.FileIO;
+
+public class QemuImgProc {
+       private List<String> cmd = null;
+       private boolean isError = false;
+       private String errorMsg = null;
+
+       public QemuImgProc(List<String> cmd) {
+               this.cmd = cmd;
+       }
+
+       public String RunningForCheckImg() {
+               assert cmd == null;
+
+               isError  = false;
+               ProcessBuilder pb = new ProcessBuilder(cmd);
+               try {
+                       Process process = pb.start();
+                       if (process != null) {
+                               final BufferedReader error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+                               final BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
+                               new Thread(new Runnable() {
+                                       public void run() {
+                                               try {
+                                                       String str = null;
+                                                       do {
+                                                               str = error.readLine();
+                                                               if (str!= null) {
+                                                                       isError  = true;
+                                                                       EMLogger.getLogger().log(Level.WARNING,
+                                                                                       "Failed check base image...(from qemu-img)\n" + str);
+                                                               }
+                                                       } while (str != null);
+                                               } catch (IOException e) {
+                                                       isError  = true;
+                                                       EMLogger.getLogger().log(Level.WARNING,
+                                                                       "Failed check base image...(stderr of qemu-img)\n" + e.getMessage());
+                                               }
+                                       }
+                               }).start();
+
+                               new Thread(new Runnable() {
+                                       public void run() {
+                                               try {
+                                                       String str = null;
+                                                       do {
+                                                               str = input.readLine();
+                                                               if (str != null) {
+                                                                       if (str.contains("format")) {
+                                                                               if (!str.contains("qcow2")) {
+                                                                                       isError = true;
+                                                                                       errorMsg = "Format of base image is not avaliable.\nBase image path :" + cmd.get(2);
+                                                                                       break;
+                                                                               }
+                                                                       } else if (str != null && str.contains("backing file")) {
+                                                                               isError = true;
+                                                                               errorMsg = "Base image is child image of other base image.\n" +
+                                                                                                       "This image is not using as base image.\n";
+                                                                               break;
+                                                                       }
+                                                               }
+                                                       } while (str != null);
+                                               } catch (IOException e) {
+                                                       isError  = true;
+                                                       EMLogger.getLogger().log(Level.WARNING,
+                                                                       "Failed check base image...(stdout of qemu-img)\n" + e.getMessage());
+                                               }
+                                       }
+                               }).start();
+
+                               // wait for ending process
+                               try {
+                                       if (process.waitFor() != 0){
+                                               isError = true;
+                                               EMLogger.getLogger().log(Level.WARNING,
+                                                               "Error while running 'qemu-img'. Exit value : " + process.exitValue());
+                                               errorMsg = "Error while running 'qemu-img'. Exit value : " + process.exitValue() +
+                                                               "\nYou can get more information in log file ("
+                                                               + FileIO.getInstance().getTizenVmsArchPath() +  File.separator + "emulator-manager)";
+                                       }
+                               } catch (InterruptedException e) {
+                                       isError  = true;
+                                       EMLogger.getLogger().log(Level.WARNING,
+                                                       "Error while running 'qemu-img'.\n" + e.getMessage());
+                               }
+
+                               if (isError) {
+                                       if (errorMsg == null) {
+                                               errorMsg = "Failed check base image...\nPlease, select base image again.";
+                                       }
+                               }
+                       }
+               } catch (IOException e) {
+                       return "Failed check base image..." + e.getMessage();
+               }
+               return errorMsg;
+       }
+       public boolean Running() {
+               assert cmd == null;
+
+               isError  = false;
+               ProcessBuilder pb = new ProcessBuilder(cmd);
+               try {
+                       Process process = pb.start();
+                       if (process != null) {
+                               final BufferedReader error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+                               new Thread(new Runnable() {
+                                       public void run() {
+                                               try {
+                                                       String str = null;
+                                                       do {
+                                                               str = error.readLine();
+                                                               if (str!= null) {
+                                                                       isError  = true;
+                                                                       EMLogger.getLogger().log(Level.WARNING,
+                                                                                       "Error while running 'qemu-img'\n" + str);
+                                                               }
+                                                       } while (str != null);
+                                               } catch (IOException e) {
+                                                       isError  = true;
+                                                       EMLogger.getLogger().log(Level.WARNING,
+                                                                       "Error while running 'qemu-img'(stderr)\n" + e.getMessage());
+                                               }
+                                       }
+                               }).start();
+
+                               // wait for ending process
+                               try {
+                                       if (process.waitFor() != 0){
+                                               isError = true;
+                                               EMLogger.getLogger().log(Level.WARNING,
+                                                               "Error while running 'qemu-img'. Exit value : " + process.exitValue());
+                                       }
+                               } catch (InterruptedException e) {
+                                       isError  = true;
+                                       EMLogger.getLogger().log(Level.WARNING,
+                                                       "Error while running 'qemu-img'.\n" + e.getMessage());
+                               }
+
+                               if (isError) {
+                                       return false;
+                               }
+                       }
+               } catch (IOException e) {
+                       EMLogger.getLogger().log(Level.WARNING, "Failed check base image..." + e.getMessage());
+                       return false;
+               }
+               return true;
+       }
+}
index c95a525..d032245 100644 (file)
@@ -60,13 +60,24 @@ public class VMCreateHelper {
        }
 
        public boolean checkDupulicateName(String t, String arc) {
+               boolean isWindows = false;
+               if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1) {
+                       isWindows = true;
+                       t = t.toLowerCase();
+               }
                VMsProperty[] properties = (VMsProperty[])EmulatorVMs.getInstance().getProperties();
                for (VMsProperty p : properties) {
                        if (p.getArch().toString() !=  arc) {
                                continue;
                        }
-                       if (p.getName().equals(t)) {
-                               return true;
+                       if (isWindows ) {
+                               if (p.getName().toLowerCase().equals(t)) {
+                                       return true;
+                               }
+                       } else {
+                               if (p.getName().equals(t)) {
+                                       return true;
+                               }
                        }
                }
                return false;
index 71e76dc..d1e0d8d 100644 (file)
@@ -117,7 +117,7 @@ public class VMPropertyValue implements Cloneable {
                if (touchType != null) {
                        maxTouchCount = touchType.getMaxTouchPoint();
                } else {
-                       maxTouchCount = 1;
+                       maxTouchCount = 3;
                }
 
                addOptions = property.getConfiguration().getUsability().getAdvancedOptions();
@@ -227,7 +227,7 @@ public class VMPropertyValue implements Cloneable {
                value.isHWVirtualization = true;
                value.isGLAcceleration = true;
 
-               value.maxTouchCount = 2;
+               value.maxTouchCount = 3;
 
                value.addOptions = null;
                return value;
index 551f2bf..1ddd2d6 100644 (file)
@@ -32,7 +32,6 @@ 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;
@@ -46,7 +45,6 @@ import org.tizen.emulator.manager.tool.FileIO;
 import org.tizen.emulator.manager.ui.MessageDialog;
 
 
-
 public class VMsWorker {
        VMsProperty property;
        Launcher launcher;
@@ -74,29 +72,88 @@ public class VMsWorker {
        }
 
        public void createNewBaseImage(VMsProperty property, String dest) throws VMsWorkerException {
-               String childImage = property.getConfiguration().getBaseInformation().getDiskImage().getCurrentDiskImage().getValue();
-               File src1  = new File(childImage);
-               if(!src1.exists()) {
+               File childImage = new File(property.getConfiguration().getBaseInformation().getDiskImage().getCurrentDiskImage().getValue());
+               File baseImage  = new File(property.getConfiguration().getBaseInformation().getDiskImage().getBaseDiskImage().getValue()); 
+               if(!childImage.exists()) {
+                       throw new VMsWorkerException("Failed to create base image!\nFile does not exist :" + childImage);
+               }
+
+               if(!baseImage.exists()) {
                        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>();
                cmd.add(exe_path);
                cmd.add("convert");
                cmd.add("-O");
                cmd.add("qcow2");
-               cmd.add(childImage);
+               cmd.add(childImage.getAbsolutePath());
                cmd.add(dest);
-               EMLogger.getLogger().log(Level.INFO, String.format("%s", cmd));
-               ProcessBuilder pb = new ProcessBuilder(cmd);
+               final QemuImgProc proc = new QemuImgProc(cmd);
+
+               /*
+               final File destFile = new File(dest);
+               final CreateBaseImageDialog dialog
+                       = new CreateBaseImageDialog(EmulatorManager.getInstance().getMainDialog().getShell());
+               dialog.Open(destFile, maxSize);
+               */
+
+               
+               workerThread worker = new workerThread(proc);
+               worker.start();
+               synchronized(worker) {
                try {
-                       pb.start();
-               } catch (IOException e) {
-                       throw new VMsWorkerException("Failed to create new base image!\n" + e.getMessage());
-               }               
+                       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)");
+                       }
+               }
+               }
+
+               /*
+               if (! proc.Running()) {
+                       //dialog.Close();
+                       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)");
+               }
+               //dialog.Close();
+                */
+       }
+
+       class workerThread extends Thread {
+               QemuImgProc proc;
+               boolean isError;
+               public workerThread(QemuImgProc proc) {
+                       this.proc = proc;
+                       isError = false;
+               }
+
+               public void run() {
+                       if (! proc.Running()) {
+                               isError = true;
+                       }
+                       synchronized(this) {
+                               notifyAll();
+                       }
+               }
+
+               public boolean isError() {
+                       return isError;
+               }
        }
-       
+
        public void deleteVM() throws VMsWorkerException {
                File vmDirectory = property.propertyFile.getParentFile();
                
@@ -202,4 +259,92 @@ public class VMsWorker {
                        return false;
                }
        }
-}
\ No newline at end of file
+}
+
+/*
+class CreateBaseImageDialog {
+       private Shell dialog = null;
+       static private ProgressBar bar = null;
+
+       public CreateBaseImageDialog(Shell shell) {
+               Point p = shell.getLocation();
+               p = new Point(p.x + 300, p.y + 300);
+               dialog = new Shell(shell,  SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+               dialog.setText("Info");
+               dialog.setSize(300, 100);
+               dialog.setLayout(new GridLayout(1, true));
+               dialog.setLocation(p);
+               //dialog.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+               Label info = new Label(dialog, SWT.WRAP);
+               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);
+
+               dialog.addListener(SWT.Close, new Listener() {
+                       @Override
+                       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 setSelection(int i) {
+               bar.setSelection(i);
+       }
+       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() {
+               dialog.close();
+       }
+
+       public boolean isDisposed() {
+               return dialog.isDisposed();
+       }
+}
+*/
\ No newline at end of file