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");
}
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;
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;
}
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());
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) {
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;
}
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;
}
}
logger.log(Level.INFO, String.format(
- "Network name = %s, MAC = %s\n",
+ "Network name = %s, MAC = %s",
ni.getDisplayName(), macAddr));
}
} 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()));
}
/* 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) {
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);
}
}
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() {
@Override
public void handleClickEvent(DACustomButton button) {
// reload vm list
- refreshVMPropertyList();
+ refreshVMPropertyList(true);
}
});
}
public boolean deleteEmulator() {
handling.deleteVirtualMachine(currentProperty);
- MainDialog.refreshVMPropertyList();
+ MainDialog.refreshVMPropertyList(true);
return true;
}
}
}
- MainDialog.refreshVMPropertyList();
+ MainDialog.refreshVMPropertyList(false);
}
VMPropertyValue oldValue;
}
dialog.close();
- MainDialog.refreshVMPropertyList();
+ MainDialog.refreshVMPropertyList(true);
//mainDialog.vmsTree.setSelectProperty(property);
}
@Override
public void widgetSelected(SelectionEvent arg0) {
dialog.close();
- MainDialog.refreshVMPropertyList();
+ MainDialog.refreshVMPropertyList(true);
//mainDialog.vmsTree.setSelectProperty(property);
}
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;
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;
/* 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);
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 {
}
}
- public boolean launch(List<String> cmd) {
+ public Process launch(List<String> cmd) {
FilePath fio = FilePath.getInstance();
ProcessBuilder pb = new ProcessBuilder(cmd);
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
--- /dev/null
+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;
+ }
+}
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 {