sunemulator.java

来自「MoMEUnit是一个单元测试的J2ME的应用程序xUnit架构实例。这是来自J」· Java 代码 · 共 135 行

JAVA
135
字号
package org.momeunit.ant.emulator;import java.io.File;import java.io.IOException;import java.util.Enumeration;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.Location;import org.apache.tools.ant.Project;import org.momeunit.ant.core.Utility;/** * Emulator that runs Sun WTK <code>emulator</code> tool. *  * @author Sergio Morozov * @version 1.1.2 */public class SunEmulator extends Emulator{  /**   * Array of emulator executables tested.   */  private static final String[] EXECUTABLES = { "bin/emulator",      "bin/emulatorw.exe", "bin/emulator.exe" };  /**   * Instantiates Sun emulator with given WTK home directory.   *    * @param wtkHome   *          WTK home directory.   * @since 1.1   */  public SunEmulator(File wtkHome)  {    super(wtkHome);  }  /**   * Instantiates Sun emulator.   *    * @since 1.1   */  public SunEmulator()  {    this(null);  }  /**   * Starts Sun WTK <code>emulator</code> tool.   *    * @param midletClass   *          classname of midlet to start. Can be <code>null</code>.   * @param jad   *          JAD descriptor of application to run. Can't be <code>null</code>.   * @param jar   *          Jar archive of application to run. Not used in this version.   * @return {@link Process} associated with running emulator.   * @since 1.1   */  public Process execute(String midletClass, File jad, File jar)  {    if (jad == null) throw new NullPointerException("jad");    if (getWtkHome() == null) throw new NullPointerException("wtkHome");    StringBuffer sb = new StringBuffer();    sb.append(getExecutable());    if (getClasspath() != null && getClasspath().size() > 0) sb.append(        " -classpath ").append(getClasspath().toString());    sb.append(" -Xdescriptor ").append(jad.getAbsolutePath());    for (Enumeration e = enumeratePropertyNames(); e.hasMoreElements();)    {      String name = (String) e.nextElement();      String value = getProperty(name);      if (name.equals("device"))      {        if (value.length() > 0) sb.append(" -Xdevice:").append(value);      } else if (name.equals("debug")) sb.append(" -Xdebug");      else if (name.equals("runjdwp"))      {        if (value.length() > 0) sb.append(" -Xdebug -Xrunjdwp:").append(value);      } else if (name.equals("verbose"))      {        sb.append(" -Xverbose");        if (value.length() > 0) sb.append(':').append(value);      } else if (name.equals("heapsize")) sb.append(" -Xheapsize:").append(          value);      else if (name.equals("ota.install")) sb.append(" -Xjam:install=").append(          value);      else if (name.equals("ota.run")) sb.append(" -Xjam:run=").append(value);      else if (name.equals("ota.remove")) sb.append(" -Xjam:remove=").append(          value);      else if (name.equals("ota.transient")) sb.append(" -Xjam:transient=")          .append(value);      else if (name.equals("ota")) sb.append(" -Xjam:transient=").append(value);      else sb.append(" -D").append(name).append('=').append(value);    }    if (midletClass != null) sb.append(' ').append(midletClass);    Process res = null;    try    {      Utility.log(getTask(), "Emulator command-line " + sb.toString(),          Project.MSG_VERBOSE);      res = Runtime.getRuntime().exec(sb.toString());    } catch (IOException e)    {      throw new BuildException("Error executing emulator.", e,          getTask() != null ? getTask().getLocation()              : Location.UNKNOWN_LOCATION);    }    return res;  }  /**   * Returns existent executable of Sun WTK <code>emulator</code> tool.   *    * @return existent executable of Sun WTK <code>emulator</code> tool.   * @throws BuildException   *           if no executable found.   * @since 1.1   */  public String getExecutable()  {    String res = null;    for (int i = 0; i < EXECUTABLES.length; i++)    {      File executable = new File(getWtkHome().getAbsolutePath() + '/'          + EXECUTABLES[i]);      if (executable.exists() && executable.isFile()) res = executable          .getAbsolutePath();    }    if (res == null) throw new BuildException("No emulator found.");    return res;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?