Esempio n. 1
0
  /**
   * 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;
  }
Esempio n. 2
0
  /**
   * Protected method for simplyfied addinng of mapped files
   *
   * @param file file to add
   * @param baseDir base directory for file
   */
  protected void addMappedFile(File file, File baseDir) {
    if (file.isFile()) {
      if (baseDir == null) {
        baseDir = file.getParentFile();
      }
      MappedFile mappedFile = new MappedFile();
      mappedFile.setFrom(file);
      String filename = file.getName();

      String[] names = getMapper().mapFileName(filename);
      // we don't use original filename if no mapping is available
      if (names == null || names.length == 0) {
        return;
      }

      File newFile = new File(file.getParent() + System.getProperty("file.separator") + names[0]);
      if (getDestDir() != null) {
        try {
          newFile =
              new File(
                  newFile
                      .getCanonicalPath()
                      .replace(baseDir.getCanonicalPath(), getDestDir().getCanonicalPath()));
        } catch (IOException ex) {
          log("Couldn't map file", ex, Project.MSG_WARN);
          return;
        }
      }
      mappedFile.setTo(newFile);
      mappedFiles.add(mappedFile);
    } else if (file.isDirectory()) {
      if (baseDir == null) {
        baseDir = file;
      }
      DirectoryScanner ds = new DirectoryScanner();
      ds.setBasedir(file);
      ds.scan();

      for (String fileName : ds.getIncludedFiles()) {
        addMappedFile(new File(file + System.getProperty("file.separator") + fileName), baseDir);
      }
    }
  }
 public String getClasspath() {
   final StringBuilder sb = new StringBuilder();
   boolean firstPass = true;
   final Enumeration<File> componentEnum = this.pathComponents.elements();
   while (componentEnum.hasMoreElements()) {
     if (!firstPass) {
       sb.append(System.getProperty("path.separator"));
     } else {
       firstPass = false;
     }
     sb.append(componentEnum.nextElement().getAbsolutePath());
   }
   return sb.toString();
 }
Esempio n. 4
0
  /**
   * Construct the command line for parallel execution.
   *
   * @param srcFiles The filenames to add to the commandline
   * @param baseDir filenames are relative to this dir
   */
  protected String[] getCommandline(String[] srcFiles, File baseDir) {
    if (targetFilePos == null) {
      return super.getCommandline(srcFiles, baseDir);
    }

    Vector targets = new Vector();
    Hashtable addedFiles = new Hashtable();
    for (int i = 0; i < srcFiles.length; i++) {
      String[] subTargets = mapper.mapFileName(srcFiles[i]);
      if (subTargets != null) {
        for (int j = 0; j < subTargets.length; j++) {
          String name = (new File(destDir, subTargets[j])).getAbsolutePath();
          if (!addedFiles.contains(name)) {
            targets.addElement(name);
            addedFiles.put(name, name);
          }
        }
      }
    }
    String[] targetFiles = new String[targets.size()];
    targets.copyInto(targetFiles);

    String[] orig = cmdl.getCommandline();
    String[] result = new String[orig.length + srcFiles.length + targetFiles.length];

    int srcIndex = orig.length;
    if (srcFilePos != null) {
      srcIndex = srcFilePos.getPosition();
    }
    int targetIndex = targetFilePos.getPosition();

    if (srcIndex < targetIndex || (srcIndex == targetIndex && srcIsFirst)) {
      // 0 --> srcIndex
      System.arraycopy(orig, 0, result, 0, srcIndex);

      // srcIndex --> targetIndex
      System.arraycopy(orig, srcIndex, result, srcIndex + srcFiles.length, targetIndex - srcIndex);

      // targets are already absolute file names
      System.arraycopy(targetFiles, 0, result, targetIndex + srcFiles.length, targetFiles.length);

      // targetIndex --> end
      System.arraycopy(
          orig,
          targetIndex,
          result,
          targetIndex + srcFiles.length + targetFiles.length,
          orig.length - targetIndex);
    } else {
      // 0 --> targetIndex
      System.arraycopy(orig, 0, result, 0, targetIndex);

      // targets are already absolute file names
      System.arraycopy(targetFiles, 0, result, targetIndex, targetFiles.length);

      // targetIndex --> srcIndex
      System.arraycopy(
          orig, targetIndex, result, targetIndex + targetFiles.length, srcIndex - targetIndex);

      // srcIndex --> end
      System.arraycopy(
          orig,
          srcIndex,
          result,
          srcIndex + srcFiles.length + targetFiles.length,
          orig.length - srcIndex);
      srcIndex += targetFiles.length;
    }

    for (int i = 0; i < srcFiles.length; i++) {
      result[srcIndex + i] = (new File(baseDir, srcFiles[i])).getAbsolutePath();
    }
    return result;
  }