Exemplo n.º 1
0
  private boolean processDirectory(boolean populate, File directory, IObject target)
      throws Throwable {
    String iniFilePath = directory + File.separator + "test_setup.ini";
    log.info("INI file path: " + iniFilePath);
    // Load up the main ini file
    TestEngineIniFile iniFile = new TestEngineIniFile(new File(iniFilePath));
    interceptor.setIniFile(iniFile);

    String[] fileTypes = iniFile.getFileTypes();

    if (populate = true && fileTypes != null) {
      // get all files in the directory
      File[] datasetFiles = directory.listFiles();

      for (File datasetFile : datasetFiles) {
        for (String fileType : fileTypes) {
          if (datasetFile.isFile()
              && datasetFile.getName().endsWith("." + fileType)
              && !datasetFile.getName().startsWith(".")) {
            iniFile.addFile(datasetFile.getName());
          }
        }
      }
    } else if (populate = true && fileTypes == null) {
      log.error("No filetypes for " + iniFilePath);
    }

    // The filtered list of files we're to attempt to import
    String[] fileList = iniFile.getFileList();

    // Sanity check
    if (fileList.length < 1) {
      log.error("No files available to import.");
    }

    for (int j = 0; j < fileList.length; j++) {
      if (fileList[j].equals("populate_options")) continue;
      File file = new File(directory + File.separator + fileList[j]);

      // Import and return pixels list
      log.info("------Importing file: " + file + "------");

      // Skip missing files
      if (!file.exists()) {
        log.warn("Image file " + file.getName() + " missing but referenced in test_setup.ini");
        continue;
      }

      try {
        // Do import
        start = new Date();
        interceptor.setSourceFile(file);
        ImportContainer ic = new ImportContainer(file, target, null, null, null, null);
        ic.setUserSpecifiedName(fileList[j]);
        importLibrary.importImage(ic, 0, 0, 1);
        iniFile.flush();
      } catch (Throwable e) {
        // Flush our file log to disk
        try {
          iniFile.flush();
        } catch (Throwable e1) {
          log.error("Failed on flushing ini file" + e1);
        }
        // store.logout();

        log.error("Failed on file: " + file.getAbsolutePath(), e);
        errors += 1;
        sendRequest("", "TestEngine Error", e, file);
        // throw e;
      }
    }
    return true;
  }