Beispiel #1
0
  @SuppressWarnings("rawtypes")
  private String getHashes(Annotated output, List<Annotated> inputs, Object instance)
      throws NoSuchFieldException, IllegalAccessException, NoSuchAlgorithmException,
          NoSuchMethodException, SecurityException, IllegalArgumentException,
          InvocationTargetException {
    LinkedList<String> hashes = new LinkedList<String>();

    hashes.addAll(HashUtils.hashAll(getProject().file(output.getValue(instance))));

    for (Annotated input : inputs) {
      AnnotatedElement m = input.getElement();
      Object val = input.getValue(instance);

      if (val == null && m.isAnnotationPresent(Optional.class)) {
        hashes.add("null");
      } else if (m.isAnnotationPresent(InputFile.class)) {
        hashes.add(HashUtils.hash(getProject().file(input.getValue(instance))));
        getLogger()
            .info(
                HashUtils.hash(getProject().file(input.getValue(instance)))
                    + " "
                    + input.getValue(instance));
      } else if (m.isAnnotationPresent(InputDirectory.class)) {
        File dir = (File) input.getValue(instance);
        hashes.addAll(HashUtils.hashAll(dir));
      } else if (m.isAnnotationPresent(InputFiles.class)) {
        FileCollection files = getProject().files(input.getValue(instance));
        for (File file : files.getFiles()) {
          String hash = HashUtils.hash(file);
          hashes.add(hash);
          getLogger().info(hash + " " + input.getValue(instance));
        }
      } else
      // just @Input
      {
        Object obj = input.getValue(instance);

        while (obj instanceof Closure) {
          obj = ((Closure) obj).call();
        }

        if (obj instanceof String) {
          hashes.add(HashUtils.hash((String) obj));
          getLogger().info(HashUtils.hash((String) obj) + " " + (String) obj);
        } else if (obj instanceof File) {
          File file = (File) obj;
          if (file.isDirectory()) {
            List<File> files = Arrays.asList(file.listFiles());
            Collections.sort(files);
            for (File i : files) {
              hashes.add(HashUtils.hash(i));
              getLogger().info(HashUtils.hash(i) + " " + i);
            }
          } else {
            hashes.add(HashUtils.hash(file));
            getLogger().info(HashUtils.hash(file) + " " + file);
          }
        } else {
          hashes.add(obj.toString());
        }
      }
    }

    return Joiner.on(Constants.NEWLINE()).join(hashes);
  }