Exemple #1
0
  /**
   * Calculates SHA1 and MD5 checksums for the files in the directory which match the specified
   * pattern.
   *
   * @param dir
   * @param pattern
   */
  protected void calculateChecksums(File dir, String pattern) {
    if (calculateChecksums) {
      getConsole().debug("calculating checksums for artifacts in {0}", dir);
      FileSet repoSet = new FileSet();
      repoSet.setProject(getProject());
      repoSet.setDir(dir);
      repoSet.setIncludes(pattern);
      repoSet.setExcludes("*.sha1, *.md5, *.sig, *.asc");
      Iterator<?> itr = repoSet.iterator();
      while (itr.hasNext()) {
        FileResource file = (FileResource) itr.next();
        byte[] bytes = FileUtils.readContent(file.getFile());

        // calculate the SHA1 hash of the content and save result
        String sha1 = StringUtils.getSHA1(bytes);
        File sha1File = new File(dir, file.getFile().getName() + ".sha1");
        FileUtils.writeContent(sha1File, sha1);
        getConsole().debug(1, "wrote {0}", sha1File);

        // add sha1 file to installed artifacts path
        reference(sha1File);

        // calculate the MD5 hash of the content and save result
        String md5 = StringUtils.getMD5(bytes);
        File md5File = new File(dir, file.getFile().getName() + ".md5");
        FileUtils.writeContent(md5File, md5);
        getConsole().debug(1, "wrote {0}", md5File);

        // add md5 file to installed artifacts path
        reference(md5File);
      }
    }
  }
  /** Scans the source directories looking for source files to be decompiled. */
  protected void scanSrc() throws BuildException {
    for (@SuppressWarnings("unchecked") Iterator<Resource> it = src.iterator(); it.hasNext(); ) {
      Resource resource = it.next();
      FileResource fileResource = resource instanceof FileResource ? (FileResource) resource : null;
      if (fileResource != null) {
        File file = fileResource.getFile();
        if (file.isDirectory()) {
          DirectoryScanner ds = getDirectoryScanner(file);
          String[] files = ds.getIncludedFiles();

          scanDir(file, destdir != null ? destdir : file, files);
        } else {
          String[] files = new String[] {fileResource.getName()};

          scanDir(
              fileResource.getBaseDir(),
              destdir != null ? destdir : fileResource.getBaseDir(),
              files);
        }
      }
      //			else
      //			{
      //				//FIXME what to do?
      //			}
    }
  }
  /**
   * Returns list of mapped files, that should be transformed. Files can by specified via attributes
   * (srcFile, srcDir) or resources (FileSet, FileList, DirSet, etc). Mapped file represents input
   * and output file for transformation.
   *
   * @return list of mapped files
   */
  public List<MappedFile> getMappedFiles() {
    mappedFiles.clear();

    // one src file
    if (getSrcFile() != null) {
      addMappedFile(getSrcFile());
    }

    if (getSrcDir() != null) {
      addMappedFile(getSrcDir());
    }

    Iterator element = resources.iterator();
    while (element.hasNext()) {
      ResourceCollection rc = (ResourceCollection) element.next();
      if (rc instanceof FileSet && rc.isFilesystemOnly()) {
        FileSet fs = (FileSet) rc;
        File fromDir = fs.getDir(getProject());

        DirectoryScanner ds;
        try {
          ds = fs.getDirectoryScanner(getProject());
        } catch (BuildException ex) {
          log("Could not scan directory " + fromDir, ex, Project.MSG_ERR);
          continue;
        }

        for (String f : ds.getIncludedFiles()) {
          addMappedFile(new File(fromDir + System.getProperty("file.separator") + f), fromDir);
        }
      } else {
        if (!rc.isFilesystemOnly()) {
          log("Only filesystem resources are supported", Project.MSG_WARN);
          continue;
        }
        Iterator rcIt = rc.iterator();
        while (rcIt.hasNext()) {
          Resource r = (Resource) rcIt.next();
          if (!r.isExists()) {
            log("Could not find resource " + r.toLongString(), Project.MSG_VERBOSE);
            continue;
          }

          if (r instanceof FileResource) {
            FileResource fr = (FileResource) r;
            addMappedFile(fr.getFile(), fr.getBaseDir());
          } else {
            log(
                "Only file resources are supported (" + r.getClass().getSimpleName() + " found)",
                Project.MSG_WARN);
            continue;
          }
        }
      }
    }

    return mappedFiles;
  }
Exemple #4
0
  /**
   * Get the list of all Ant files we want to process. These can be project and antlib files.
   *
   * @return antFiles a list of ant files to be processed
   */
  public ArrayList getAntFiles(Project project, boolean homeOnly) {
    ArrayList antFiles = new ArrayList();

    Map targets = project.getTargets();
    Iterator targetsIter = targets.values().iterator();

    String projectHome = null;
    try {
      projectHome = new File(project.getProperty("helium.dir")).getCanonicalPath();

      while (targetsIter.hasNext()) {
        Target target = (Target) targetsIter.next();
        String projectPath = new File(target.getLocation().getFileName()).getCanonicalPath();

        if (!antFiles.contains(projectPath)) {
          if (homeOnly) {
            if (!projectPath.contains(projectHome)) {
              antFiles.add(projectPath);
            }
          } else antFiles.add(projectPath);
        }
      }

      if (rc != null) {
        Iterator extraFilesIter = rc.iterator();
        while (extraFilesIter.hasNext()) {
          FileResource f = (FileResource) extraFilesIter.next();
          String extrafile = f.getFile().getCanonicalPath();

          if (!antFiles.contains(f.toString()) && !f.getFile().getName().startsWith("test_")) {
            if (homeOnly) {
              if (!extrafile.contains(projectHome)) {
                antFiles.add(extrafile);
              }
            } else antFiles.add(extrafile);
          }
        }
      }

    } catch (Exception e) {
      log(e.getMessage(), Project.MSG_ERR);
      e.printStackTrace();
    }
    return antFiles;
  }
 /**
  * Implementation of ResourceSelector.isSelected().
  *
  * @param resource The resource to check
  * @return whether the resource is selected
  * @see ResourceSelector#isSelected(Resource)
  */
 public boolean isSelected(Resource resource) {
   if (resource.isFilesystemOnly()) {
     // We have a 'resourced' file, so reconvert it and use
     // the 'old' implementation.
     FileResource fileResource = (FileResource) resource;
     File file = fileResource.getFile();
     String filename = fileResource.getName();
     File basedir = fileResource.getBaseDir();
     return isSelected(basedir, filename, file);
   } else {
     try {
       // How to handle non-file-Resources? I copy temporarily the
       // resource to a file and use the file-implementation.
       FileUtils fu = FileUtils.getFileUtils();
       File tmpFile = fu.createTempFile("modified-", ".tmp", null, true, false);
       Resource tmpResource = new FileResource(tmpFile);
       ResourceUtils.copyResource(resource, tmpResource);
       boolean isSelected =
           isSelected(tmpFile.getParentFile(), tmpFile.getName(), resource.toLongString());
       tmpFile.delete();
       return isSelected;
     } catch (UnsupportedOperationException uoe) {
       log(
           "The resource '"
               + resource.getName()
               + "' does not provide an InputStream, so it is not checked. "
               + "Akkording to 'selres' attribute value it is "
               + ((selectResourcesWithoutInputStream) ? "" : " not")
               + "selected.",
           Project.MSG_INFO);
       return selectResourcesWithoutInputStream;
     } catch (Exception e) {
       throw new BuildException(e);
     }
   }
 }