Example #1
0
  /**
   * This method will movie files from the source directory to the destination directory based on
   * the pattern.
   *
   * @param inSourceDirectory The source directory to copy from.
   * @param inDestinationDirectory The destination directory to copy to.
   * @param inPattern The file pattern to match to locate files to copy.
   */
  protected void moveFiles(
      final String inSourceDirectory, final String inDestinationDirectory, final String inPattern) {
    Move moveTask = (Move) antProject.createTask("move");

    FileSet fileSet = AntUtils.createFileset(inSourceDirectory, inPattern, new ArrayList());
    moveTask.setTodir(new File(inDestinationDirectory));
    moveTask.addFileset(fileSet);
    moveTask.execute();
  }
  /**
   * Executes the task.
   *
   * @throws BuildException is there is a problem in the task execution.
   */
  public void execute() throws BuildException {

    // first off, make sure that we've got a from and to extension
    if (fromExtension == null || toExtension == null || srcDir == null) {
      throw new BuildException(
          "srcDir, fromExtension and toExtension " + "attributes must be set!");
    }

    log("DEPRECATED - The renameext task is deprecated.  Use move instead.", Project.MSG_WARN);
    log("Replace this with:", Project.MSG_INFO);
    log("<move todir=\"" + srcDir + "\" overwrite=\"" + replace + "\">", Project.MSG_INFO);
    log("  <fileset dir=\"" + srcDir + "\" />", Project.MSG_INFO);
    log("  <mapper type=\"glob\"", Project.MSG_INFO);
    log("          from=\"*" + fromExtension + "\"", Project.MSG_INFO);
    log("          to=\"*" + toExtension + "\" />", Project.MSG_INFO);
    log("</move>", Project.MSG_INFO);
    log("using the same patterns on <fileset> as you\'ve used here", Project.MSG_INFO);

    Move move = new Move();
    move.bindToOwner(this);
    move.setOwningTarget(getOwningTarget());
    move.setTaskName(getTaskName());
    move.setLocation(getLocation());
    move.setTodir(srcDir);
    move.setOverwrite(replace);

    fileset.setDir(srcDir);
    move.addFileset(fileset);

    Mapper me = move.createMapper();
    me.setType(globType);
    me.setFrom("*" + fromExtension);
    me.setTo("*" + toExtension);

    move.execute();
  }