private void copyAllFilesToLogDir(File node, File parent) throws IOException {
    if (!node.getAbsoluteFile().equals(parent.getAbsoluteFile())
        && node.isFile()
        && !node.getParentFile().equals(parent)) {
      String fileNamePrefix = node.getName().substring(0, node.getName().lastIndexOf('.'));
      String fileNameSuffix = node.getName().substring(node.getName().lastIndexOf('.'));
      String newFilePath =
          node.getParentFile().getAbsolutePath()
              + File.separator
              + fileNamePrefix.replace(".", "_")
              + fileNameSuffix;

      File newNode = new File(newFilePath);
      if (node.renameTo(newNode)) {
        FileUtils.copyFileToDirectory(newNode, parent);
      }
    }
    if (node.isDirectory()) {
      String[] subNote = node.list();
      for (String filename : subNote) {
        copyAllFilesToLogDir(new File(node, filename), parent);
      }
      if (!node.equals(parent)) {
        FileUtils.deleteDirectory(node);
      }
    }
  }
Ejemplo n.º 2
0
  protected static void process(File dir) throws IOException {
    File file = new File(dir, TESTS);
    if (!file.exists()) throw new IOException(file + " not found");
    List<TestCase> test_cases = new ArrayList<>();
    DataInputStream input = new DataInputStream(new FileInputStream(file));
    try {
      for (; ; ) {
        TestCase test_case = new TestCase();
        try {
          test_case.readFrom(input);
          test_cases.add(test_case);
        } catch (Exception e) {
          break;
        }
      }
    } finally {
      Util.close(input);
    }

    if (test_cases.isEmpty()) return;

    Reader stdout_reader = null, stderr_reader = null;
    File tmp = new File(dir, STDOUT);
    if (tmp.exists() && tmp.length() > 0) stdout_reader = new FileReader(tmp);

    tmp = new File(dir, STDERR);
    if (tmp.exists() && tmp.length() > 0) stderr_reader = new FileReader(tmp);
    File parent = dir.getParentFile();
    File xml_file = new File(parent, "TESTS-" + dir.getName() + "-" + parent.getName() + ".xml");
    Writer out = new FileWriter(xml_file);
    String classname = dir.getName();
    String suffix = parent.getName();
    if (suffix != null && !suffix.isEmpty()) classname = classname + "-" + suffix;
    try {
      generateReport(out, classname, test_cases, stdout_reader, stderr_reader);
    } finally {
      out.close();
      if (stdout_reader != null) stdout_reader.close();
      if (stderr_reader != null) stderr_reader.close();
    }
  }