示例#1
0
  /**
   * Returns a fully configured FileNameMapper implementation.
   *
   * @return a FileNameMapper object to be configured
   * @throws BuildException on error
   */
  public FileNameMapper getImplementation() throws BuildException {
    if (isReference()) {
      return getRef().getImplementation();
    }

    if (type == null && classname == null && container == null) {
      throw new BuildException(
          "nested mapper or " + "one of the attributes type or classname is required");
    }

    if (container != null) {
      return container;
    }

    if (type != null && classname != null) {
      throw new BuildException("must not specify both type and classname attribute");
    }

    try {
      FileNameMapper m = (FileNameMapper) (getImplementationClass().newInstance());
      final Project p = getProject();
      if (p != null) {
        p.setProjectReference(m);
      }
      m.setFrom(from);
      m.setTo(to);

      return m;
    } catch (BuildException be) {
      throw be;
    } catch (Throwable t) {
      throw new BuildException(t);
    }
  }
示例#2
0
 public String toString() {
   StringBuffer buf = new StringBuffer("{presentselector targetdir: ");
   if (targetdir == null) {
     buf.append("NOT YET SET");
   } else {
     buf.append(targetdir.getName());
   }
   buf.append(" present: ");
   if (destmustexist) {
     buf.append("both");
   } else {
     buf.append("srconly");
   }
   if (map != null) {
     buf.append(map.toString());
   } else if (mapperElement != null) {
     buf.append(mapperElement.toString());
   }
   buf.append("}");
   return buf.toString();
 }
示例#3
0
  /**
   * The heart of the matter. This is where the selector gets to decide on the inclusion of a file
   * in a particular fileset.
   *
   * @param basedir the base directory the scan is being done from
   * @param filename is the name of the file to check
   * @param file is a java.io.File object the selector can use
   * @return whether the file should be selected or not
   */
  public boolean isSelected(File basedir, String filename, File file) {

    // throw BuildException on error
    validate();

    // Determine file whose existence is to be checked
    String[] destfiles = map.mapFileName(filename);
    // If filename does not match the To attribute of the mapper
    // then filter it out of the files we are considering
    if (destfiles == null) {
      return false;
    }
    // Sanity check
    if (destfiles.length != 1 || destfiles[0] == null) {
      throw new BuildException(
          "Invalid destination file results for " + targetdir + " with filename " + filename);
    }
    String destname = destfiles[0];
    File destfile = new File(targetdir, destname);
    return destfile.exists() == destmustexist;
  }
示例#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;
  }