Пример #1
0
  /** Test of execute method, of class org.netbeans.mobility.antext.RunTask. */
  public void testExecute() throws IOException {
    System.out.println("execute");

    // Prepare test
    File dir = getWorkDir();
    clearWorkDir();
    String path = getGoldenFile("bin").getParent() + File.separator;
    File srcDir = new File(path);
    File jadfile = new File(path + "MobileApplication1.jad");
    File jarfile = new File(path + "MobileApplication1.jad");
    File f = File.createTempFile("cmdline", "", dir);
    File log = null;
    PrintStream out = new PrintStream(new FileOutputStream(f));
    File em = null;
    File exe = null;
    try {
      Project p = new Project();
      RunTask instance = new RunTask();
      instance.setProject(p);
      instance.setClassPath(new Path(p, srcDir.getAbsolutePath()));
      instance.setPlatformHome(srcDir);
      instance.setJadFile(jadfile);
      instance.setJarFile(jarfile);
      instance.setJadUrl(jadfile.toURL().toString());
      instance.setDevice("MyDevice");
      instance.setDebug(true);
      instance.setDebugAddress("MyAddress");
      instance.setDebugServer(true);
      instance.setDebugSuspend(false);

      String name = System.getProperty("os.name");
      StringBuffer commandLine =
          new StringBuffer(Bundle.getMessage("CMD_Run_" + DEFAULT_PLATFORM_TYPE));

      /* Prepare right executable */
      int index = name.indexOf("Windows");
      em = index != -1 ? getGoldenFile("bin/emulator.bin") : getGoldenFile("bin/emulator.sh");
      exe = new File(em.getParent() + "/emulator");
      exe.delete();
      em.renameTo(exe);

      HashMap args = new HashMap();
      args.put("platformhome", srcDir); // No I18N
      args.put("classpath", srcDir.getAbsolutePath()); // No I18N
      args.put("jadfile", jadfile);
      args.put("jarfile", jarfile);
      args.put("jadurl", jadfile.toURL().toString());
      args.put("device", "MyDevice");
      args.put("debug", ""); // NO I18N
      args.put("debugaddress", "MyAddress");
      args.put("debugserver", "y"); // NO I18N
      args.put("debugsuspend", "n"); // NO I18N
      args.put("debugtransport", "dt_socket"); // NO I18N
      args.put("/", File.separator); // NO I18N
      String line = EMapFormat.format(commandLine.toString(), args);

      String[] commands = Commandline.translateCommandline(line);
      if (name.indexOf("Windows") == -1) {
        Process pr = java.lang.Runtime.getRuntime().exec("chmod +x " + commands[0]);
        try {
          assertTrue(pr.waitFor() == 0);
        } catch (InterruptedException ex) {
          fail(ex.getMessage());
        }
      }
      for (int i = 0; i < commands.length; i++) {
        out.println(commands[i]);
      }
      instance.execute();
      String wdir = System.getProperty("user.dir");
      log = new File(wdir + File.separator + "cmdLine.log");
      this.assertFile(log, f);
    } finally {
      out.close();
      clearWorkDir();
      if (f != null) f.delete();
      if (log != null) log.delete();
      if (exe != null) exe.renameTo(em);
    }
  }