コード例 #1
0
ファイル: LogReport.java プロジェクト: irudyak/ant-toolkit
  public void removeEntriesWithPathForAuthor(String path, String author) {
    if (logEntries == null || logEntries.isEmpty()) {
      return;
    }

    int count = logEntries.size();
    int i = 0;

    while (i < count) {
      LogEntry logEntry = logEntries.get(i);
      if (!logEntry.getAuthor().equals(author)) {
        i++;
        continue;
      }

      logEntry.removeEntriesWithPath(path);
      if (logEntry.isEmpty()) {
        logEntries.remove(logEntry);
        count--;
        continue;
      }

      i++;
    }

    isOrdered = false;
  }
コード例 #2
0
ファイル: LogReport.java プロジェクト: irudyak/ant-toolkit
  public void removeNotLastModifications() {
    List<String> uniquePaths = getUniquePaths();
    for (String path : uniquePaths) {
      int lastRevision = getLastModificationRevisionForPath(path);

      int count = logEntries.size();
      int i = 0;

      while (i < count) {
        LogEntry entry = logEntries.get(i);

        if (entry.getRevision() < lastRevision) {
          entry.removeEntriesWithPath(path);
          if (entry.isEmpty()) {
            logEntries.remove(entry);
            count--;
            i--;
          }
        }

        i++;
      }
    }

    isOrdered = false;
  }
コード例 #3
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;
  }
コード例 #4
0
ファイル: LogReport.java プロジェクト: irudyak/ant-toolkit
  public int getMaxLogEntryRevision() {
    if (isEmpty()) {
      return -1;
    }

    List<LogEntry> logEntries = getOrderedLogEntries();

    return logEntries.get(logEntries.size() - 1).getRevision();
  }
コード例 #5
0
ファイル: LogReport.java プロジェクト: irudyak/ant-toolkit
  private List<LogEntry> getUnorderedAuthorLogEntries(String author) {
    List<LogEntry> entries = new LinkedList<LogEntry>();

    for (LogEntry logEntry : logEntries) {
      if (logEntry.getAuthor().equals(author)) {
        entries.add(logEntry);
      }
    }

    return entries;
  }
コード例 #6
0
ファイル: LogReport.java プロジェクト: irudyak/ant-toolkit
  public List<String> getAuthors() {
    List<String> authors = new LinkedList<String>();

    for (LogEntry logEntry : logEntries) {
      if (!authors.contains(logEntry.getAuthor())) {
        authors.add(logEntry.getAuthor());
      }
    }

    Collections.sort(authors);

    return authors;
  }
コード例 #7
0
ファイル: LogReport.java プロジェクト: irudyak/ant-toolkit
  public List<String> getUniquePaths() {
    List<String> uniquePathEntries = new LinkedList<String>();

    for (LogEntry logEntry : logEntries) {
      List<PathEntry> pathEntries = logEntry.getPathEntries();
      for (PathEntry pathEntry : pathEntries) {
        if (!uniquePathEntries.contains(pathEntry.getPath())) {
          uniquePathEntries.add(pathEntry.getPath());
        }
      }
    }

    return uniquePathEntries;
  }
コード例 #8
0
ファイル: LogReport.java プロジェクト: irudyak/ant-toolkit
  public List<PathEntry> getOrderedByRevisionAuthorPathEntries(String author) {
    List<PathEntry> orderedPathEntries = new LinkedList<PathEntry>();

    List<LogEntry> logEntries = getUnorderedAuthorLogEntries(author);
    for (LogEntry logEntry : logEntries) {
      List<PathEntry> pathEntries = logEntry.getPathEntries();
      for (PathEntry pathEntry : pathEntries) {
        orderedPathEntries.add(pathEntry);
      }
    }

    Collections.sort(orderedPathEntries);

    return orderedPathEntries;
  }
コード例 #9
0
ファイル: LogReport.java プロジェクト: irudyak/ant-toolkit
  public List<String> getAuthorUniquePaths(String author) {
    List<LogEntry> logEntries = getUnorderedAuthorLogEntries(author);
    List<String> uniquePathEntries = new LinkedList<String>();

    for (LogEntry logEntry : logEntries) {
      List<PathEntry> pathEntries = logEntry.getPathEntries();
      for (PathEntry pathEntry : pathEntries) {
        if (!uniquePathEntries.contains(pathEntry.getPath())) {
          uniquePathEntries.add(pathEntry.getPath());
        }
      }
    }

    return uniquePathEntries;
  }
コード例 #10
0
ファイル: LogReport.java プロジェクト: irudyak/ant-toolkit
  public void removeLogEntriesWithRevisionLowerThan(int revision) {
    List<LogEntry> logEntries = getOrderedLogEntries();
    if (logEntries.isEmpty()) {
      return;
    }

    int count = this.logEntries.size();
    int i = 0;

    while (i < count) {
      LogEntry entry = this.logEntries.get(i);
      if (entry.getRevision() < revision) {
        this.logEntries.remove(entry);
        count--;
        continue;
      }

      i++;
    }

    isOrdered = false;
  }
コード例 #11
0
ファイル: LogReport.java プロジェクト: irudyak/ant-toolkit
  public void removeEntriesWithPath(String path) {
    if (logEntries == null || logEntries.isEmpty()) {
      return;
    }

    int count = logEntries.size();
    int i = 0;

    while (i < count) {
      LogEntry logEntry = logEntries.get(i);
      logEntry.removeEntriesWithPath(path);

      if (logEntry.isEmpty()) {
        logEntries.remove(logEntry);
        count--;
        continue;
      }

      i++;
    }

    isOrdered = false;
  }
コード例 #12
0
ファイル: LogReport.java プロジェクト: irudyak/ant-toolkit
  private void writeChanges(PrintWriter out) {
    List<String> authors = getAuthors();
    for (String author : authors) {
      List<LogEntry> logEntries = getOrderedAuthorLogEntries(author);
      if (logEntries == null || logEntries.isEmpty()) {
        continue;
      }

      out.println(
          MessageFormat.format(
              AUTHOR_START_NODE,
              new String[] {
                author,
                Integer.toString(getAuthorLogEntriesCount(author)),
                Integer.toString(logEntries.size())
              }));

      for (LogEntry logEntry : logEntries) {
        writeLogEntry(out, logEntry);
      }

      out.println(AUTHOR_END_NODE);
    }
  }
コード例 #13
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);
      }
    }
  }
コード例 #14
0
 @Override
 public void addTask(Task task) {
   tasks.add(task);
 }
コード例 #15
0
  /**
   * Main entry point for this task. It creates transformation specified by classname attribute,
   * passes all parameters and executes it.
   *
   * @throws BuildException if an error occured
   */
  @Override
  public void execute() throws BuildException {
    if (getClassname() == null) {
      throw new BuildException("Classname of transformation is not set.");
    }

    if (getSrcFile() != null && getSrcDir() != null) {
      throw new BuildException("Both srcFile and srcDir were set.");
    }

    if (getDestFile() != null && getDestDir() != null) {
      throw new BuildException("Both destFile and destDir were set.");
    }

    if (!resources.isEmpty() && (getSrcFile() != null || getSrcDir() != null)) {
      throw new BuildException("Resources can't be combined with srcFile or srcDir.");
    }

    initClassloader();

    try {
      TransformationLoader loader =
          new TransformationLoader(Thread.currentThread().getContextClassLoader());
      Transformation transObj = null;
      try {
        transObj = loader.getInstance(getClassname());
      } catch (InstantiationException ex) {
        throw new BuildException("Transformation couldn't be instanciated", ex);
      } catch (IllegalAccessException ex) {
        throw new BuildException("Transformation couldn't be accessed", ex);
      }

      if (transObj == null) {
        throw new BuildException("Transformation " + getClassname() + " couldn't be loaded");
      }

      List<MappedFile> files = getMappedFiles();
      if (files.isEmpty()) {
        log(
            "No files specified, " + transObj.getClass().getSimpleName() + " skipped",
            Project.MSG_INFO);
        return;
      }
      for (MappedFile mf : files) {
        log("Mapped file " + mf.getFrom() + " to " + mf.getTo(), Project.MSG_VERBOSE);
      }

      transObj.setParam("baseDir", getProject().getBaseDir().getPath());
      transObj.setMappedFiles(files);
      transObj.setParams(parameters);

      for (String key : parameters.keySet())
        log(
            "Parsed parameter "
                + key
                + " = "
                + parameters.get(key)
                + " ("
                + parameters.get(key).getClass().getName()
                + ")",
            Project.MSG_VERBOSE);

      try {
        log(
            "Executing transformation "
                + transObj.getClass().getSimpleName()
                + " on "
                + mappedFiles.size()
                + " files");
        transObj.execute();
      } catch (TransformationException ex) {
        log("Transformation has failed", ex, Project.MSG_ERR);
        if (isFailonerror()) {
          throw new BuildException("Transformation has failed.", ex);
        }
      }
    } finally {
      restoreClassloader();
    }
  }
コード例 #16
0
 /**
  * Add resource collection
  *
  * @param rc resource collection to add
  */
 public void add(ResourceCollection rc) {
   resources.add(rc);
 }
コード例 #17
0
ファイル: LogReport.java プロジェクト: irudyak/ant-toolkit
 public void addLogEntry(LogEntry logEntry) {
   logEntries.add(logEntry);
   isOrdered = false;
 }