예제 #1
0
 public final SourceFile getBestFileForTarget(String target) {
   if (!this.target.equals(target)) {
     if (next != null) {
       return next.getBestFileForTarget(target);
     }
   }
   return this;
 }
예제 #2
0
  protected Flags runDiff(
      SourceFile vmFile, SourceFile cpFile, String diffFileName, Map<String, String> packageDiffs)
      throws IOException, InterruptedException {
    final String[] cmd = {
      "diff",
      "-b", // Ignore white space change
      // "-E", // Ignore changes due to tab expansion
      // "-w", // Ignore all white space change
      // "-B", // Ignore changes whose lines are all blank
      // "-N", // Treat absent files as empty
      "-au",
      "-I",
      ".*$" + "Id:.*$.*", // Avoid cvs keyword
      // expansion in this string
      vmFile.getFileName(),
      cpFile.getFile().getAbsolutePath()
    };
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final ByteArrayOutputStream err = new ByteArrayOutputStream();
    final PumpStreamHandler streamHandler = new PumpStreamHandler(out, err);
    final Execute exe = new Execute(streamHandler);
    exe.setCommandline(cmd);
    exe.setWorkingDirectory(vmFile.getBaseDir());
    final int rc = exe.execute();
    if ((rc != 0) && (out.size() > 0)) {
      File diffFile = new File(destDir, diffFileName);
      FileOutputStream os = new FileOutputStream(diffFile);
      try {
        final byte[] diff = out.toByteArray();
        os.write(diff);
        os.flush();

        final String diffStr = new String(diff);
        final String pkg = vmFile.getPackageName();
        String pkgDiff;
        if (packageDiffs.containsKey(pkg)) {
          pkgDiff = packageDiffs.get(pkg);
          pkgDiff = pkgDiff + "diff\n" + diffStr;
        } else {
          pkgDiff = diffStr;
        }
        packageDiffs.put(pkg, pkgDiff);

        Flags flags = getFlags(diffStr);
        if (!vmFile.getTarget().equals(cpFile.getTarget())) {
          flags.set(FLAG_TARGET_DIFF);
        }
        flags.set(NEEDS_MERGE);
        return flags;
      } finally {
        os.close();
      }
    } else {
      return new Flags(NO_CHANGE);
    }
  }
예제 #3
0
 protected Flags getFlags(SourceFile file) throws IOException {
   final FileReader fr = new FileReader(file.getFile());
   try {
     final BufferedReader in = new BufferedReader(fr);
     // final StringBuffer b = new StringBuffer();
     String line;
     final Flags flags = new Flags();
     while ((line = in.readLine()) != null) {
       getFlags(line.toString(), flags);
       // b.append(line);
       // b.append('\n');
     }
     return flags;
   } finally {
     fr.close();
   }
 }
예제 #4
0
        @Override
        public Collection<CompareResult> call() throws Exception {
          ArrayList<CompareResult> results = new ArrayList<CompareResult>();
          for (String name : files) {
            SourceFile cpFile = classpathFiles.get(name);
            final SourceFile vmFile = vmFiles.get(name);
            final SourceFile vmSpecificFile = vmSpecificFiles.get(name);

            if (vmSpecificFile != null) {
              // File is found as vm specific source
              results.add(new VmSpecificResult(name, vmSpecificFile.getReportName()));
            } else if (vmFile == null) {
              // file is not found as vmspecific source, nor as vm source
              if (!cpFile.isIgnoreMissing()) {
                results.add(
                    new MissingResult(name, cpFile.getReportName(), type, getFlags(cpFile)));
              }
            } else if (cpFile == null) {
              // File is not found in classpath sources
              results.add(new MissingResult(name, vmFile.getReportName(), "vm", new Flags()));
            } else {
              // We have both the classpath version and the vm version.
              cpFile = cpFile.getBestFileForTarget(vmFile.getTarget());
              // Let's compare them
              final String diffFileName = vmFile.getReportName() + ".diff";
              Flags rc = runDiff(vmFile, cpFile, diffFileName, packageDiffs);
              switch (rc.asInt() & ~FLAGS_MASK) {
                case NO_CHANGE:
                  break;
                case NEEDS_MERGE:
                  results.add(
                      new NeedsMergeResult(
                          name,
                          vmFile.getReportName(),
                          vmFile.getTarget(),
                          diffFileName,
                          rc.mask(FLAGS_MASK)));
                  break;
                default:
                  throw new RuntimeException("Invalid rc " + rc);
              }
              if (rc.isSet(FLAG_VM_SPECIFIC)) {
                results.add(new CounterResult(name, "FLAG_VM_SPECIFIC"));
              }
              if (rc.isSet(FLAG_CLASSPATH_BUGFIX)) {
                results.add(new CounterResult(name, "FLAG_CLASSPATH_BUGFIX"));
              }
              if (rc.isSet(FLAG_NATIVE)) {
                results.add(new CounterResult(name, "FLAG_NATIVE"));
              }
              if (rc.isSet(FLAG_JNODE)) {
                results.add(new CounterResult(name, "FLAG_JNODE"));
              }

              if (rc.getBugIDs().length > 0) {
                results.add(
                    new ClasspathBugsResult(name, vmFile.getReportName(), vmFile.getTarget(), rc));
              }
            }
          }
          return results;
        }