/** @param args the command line arguments */
  public static void main(String[] args) {

    try {
      ChildTargetModuleIDTester deployer = getDeployer(args);
      TargetModuleID[] ids = deployer.deploy(args);
      if (deployer.test(ids, args[6])) {
        log("Test Passed");
        System.exit(0);
      } else {
        log("Test FAILED");
        deployer.dumpModulesIDs("", ids);
        System.exit(1);
      }

    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }
  protected boolean test(TargetModuleID[] moduleIDs, String path) throws Exception {

    // hack for std modules

    TargetModuleID[] aTargetModuleIDs = findApplication("sayhello", ModuleType.WAR, null);

    dumpModulesIDs("war", aTargetModuleIDs);

    if (moduleIDs.length == 0) {
      // deployment failed ?
      log("Deployment failed, got zero TargetModuleID");
      System.exit(1);
    }

    // we are loading the deployed file and checking that the moduleIDs are
    // correct
    Application app = ApplicationArchivist.openArchive(new File(path));

    // check of non running modules
    ModuleType modType;
    if (app.isVirtual()) {
      modType = app.getStandaloneBundleDescriptor().getModuleType();
    } else {
      modType = ModuleType.EAR;
    }

    // now we need to start the application
    for (int i = 0; i < moduleIDs.length; i++) {
      TargetModuleID aTargetModuleID = moduleIDs[i];

      // should be part of the non running
      TargetModuleID[] targetModuleIDs =
          findApplication(aTargetModuleID.getModuleID(), modType, Boolean.FALSE);
      check(path, app, targetModuleIDs);

      // should be part of the available apps
      targetModuleIDs = findApplication(aTargetModuleID.getModuleID(), modType, null);
      check(path, app, targetModuleIDs);

      // now we start it..
      start(aTargetModuleID.getModuleID());

      // should be part of the running
      targetModuleIDs = findApplication(aTargetModuleID.getModuleID(), modType, Boolean.TRUE);
      check(path, app, targetModuleIDs);

      // should be part of the available apps
      targetModuleIDs = findApplication(aTargetModuleID.getModuleID(), modType, null);
      check(path, app, targetModuleIDs);
    }
    return true;
  }
  protected TargetModuleID[] deploy(String[] args) throws Exception {

    File inputFile = new File(args[6]);
    if (!inputFile.exists()) {
      error("File not found : " + inputFile.getPath());
      System.exit(1);
    }
    File deploymentFile = null;
    if (args.length > 6) {
      deploymentFile = new File(args[7]);
      if (!args[7].equals("null")) {
        if (!deploymentFile.exists()) {
          error("Deployment File not found : " + deploymentFile.getPath());
          System.exit(1);
        }
      }
    }

    log("Deploying " + inputFile + " plan: " + deploymentFile);
    ProgressObject po = deploy(inputFile, deploymentFile, false);
    return po.getResultTargetModuleIDs();
  }