Пример #1
0
 protected void removeTableDir() {
   File tableDirFile = new File(getTablePath().toString());
   if (tableDirFile.exists()) {
     // Remove the director where the table will be imported to,
     // prior to running the MapReduce job.
     if (!DirUtil.deleteDir(tableDirFile)) {
       LOG.warn("Could not delete table directory: " + tableDirFile.getAbsolutePath());
     }
   }
 }
Пример #2
0
  @Override
  public void execute() throws BuildException {
    DirUtil.checkDir(dir1, "dir1", false); // $NON-NLS-1$
    DirUtil.checkDir(dir2, "dir2", false); // $NON-NLS-1$

    if (mapper == null) {
      add(new IdentityMapper());
    }
    try {
      DirectoryScanner ds = super.getDirectoryScanner(dir1);
      // use default includes if unset:
      if (!getImplicitFileSet().hasPatterns())
        ds.setIncludes(new String[] {"**/*.properties"}); // $NON-NLS-1$
      ds.scan();
      String[] files = ds.getIncludedFiles();

      for (int i = 0; i < files.length; i++) {
        String prop1Filename = files[i];
        File prop1File = new File(dir1, prop1Filename);
        String[] outFile = mapper.getImplementation().mapFileName(prop1Filename);
        if (outFile == null || outFile.length == 0) {
          if (failOnNull)
            throw new BuildException("Input filename " + prop1File + " mapped to null");
          log("Skipping " + prop1File + ": filename mapped to null", Project.MSG_VERBOSE);
          continue;
        }
        String prop2Filename = outFile[0]; // FIXME support multiple output mappings?
        File prop2File = new File(dir2, prop2Filename);

        Properties props1 = new Properties();
        InputStream in1 = new FileInputStream(prop1File);
        try {
          props1.load(in1);
          Properties props2 = new Properties();
          InputStream in2 = new FileInputStream(prop2File);
          try {
            props2.load(in2);
            int errorCount = 0;
            StringBuilder errors = new StringBuilder();
            errors.append(prop1File.getPath() + " is different from " + prop2File.getPath() + ": ");
            errors.append(System.getProperty("line.separator")); // $NON-NLS-1$

            for (Map.Entry<Object, Object> entry : props1.entrySet()) {
              String propName = (String) entry.getKey();
              String prop1Val = (String) entry.getValue();
              String prop2Val = (String) props2.remove(propName);
              if (!equivalent(prop1Val, prop2Val)) {
                ++errorCount;
                recordError(
                    errors,
                    propName + " -> {" + prop1Val + ", " + prop2Val
                        + "}"); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
              }
            }
            if (!props2.isEmpty()) {
              ++errorCount;
              String message = "second file contains extra keys: " + props2.keySet();
              recordError(errors, message);
            }

            if (errorCount != 0) throw new BuildException(errors.toString());
          } finally {
            in2.close();
          }
        } finally {
          in1.close();
        }
      }
      log("Verified .properties files in " + dir1 + " against " + dir2, Project.MSG_VERBOSE);
    } catch (Exception e) {
      throw new BuildException(e);
    }
  }