Esempio n. 1
0
 private void log(String message, int severity, Throwable exception) {
   if (exception != null) {
     if (component instanceof Task) {
       component.getProject().log((Task) component, message, exception, severity);
     } else {
       component.getProject().log(message, exception, severity);
     }
   } else {
     component.log(message, severity);
   }
 }
Esempio n. 2
0
 /**
  * Bind the runner to a project component. Properties, targets and references are all added as
  * beans; project is bound to project, and self to the component.
  *
  * @param component to become <code>self</code>
  */
 public void bindToComponent(ProjectComponent component) {
   project = component.getProject();
   addBeans(project.getProperties());
   addBeans(project.getUserProperties());
   addBeans(project.getCopyOfTargets());
   addBeans(project.getCopyOfReferences());
   addBean("project", project);
   addBean("self", component);
 }
Esempio n. 3
0
 /**
  * Log which Resources (if any) have been modified in the future.
  *
  * @param logTo the ProjectComponent to do the logging.
  * @param rc the collection of Resources to check.
  * @param granularity the timestamp granularity to use.
  * @since Ant 1.7
  */
 private static void logFuture(ProjectComponent logTo, ResourceCollection rc, long granularity) {
   long now = System.currentTimeMillis() + granularity;
   Date sel = new Date();
   sel.setMillis(now);
   sel.setWhen(TimeComparison.AFTER);
   Restrict future = new Restrict();
   future.add(sel);
   future.add(rc);
   for (Iterator iter = future.iterator(); iter.hasNext(); ) {
     logTo.log(
         "Warning: " + ((Resource) iter.next()).getName() + " modified in the future.",
         Project.MSG_WARN);
   }
 }
Esempio n. 4
0
 /**
  * This method is called by the Ant runtime by reflection. We use the project reference for
  * registration of this class as BuildListener.
  *
  * @param project project reference
  */
 public void setProject(Project project) {
   // store project reference for logging
   super.setProject(project);
   // check if already registered
   boolean alreadyRegistered = false;
   Vector allListeners = project.getBuildListeners();
   final int size = allListeners.size();
   for (int i = 0; i < size; i++) {
     Object listener = allListeners.get(i);
     if (listener instanceof FailureRecorder) {
       alreadyRegistered = true;
       break;
     }
   }
   // register if needed
   if (!alreadyRegistered) {
     verbose("Register FailureRecorder (@" + this.hashCode() + ") as BuildListener");
     project.addBuildListener(this);
   }
 }
Esempio n. 5
0
 /**
  * Bind the runner to a project component. The project and self are the only beans set.
  *
  * @param component to become <code>self</code>
  */
 public void bindToComponentMinimum(ProjectComponent component) {
   project = component.getProject();
   addBean("project", project);
   addBean("self", component);
 }
Esempio n. 6
0
  /**
   * Tells which sources should be reprocessed based on the last modification date of targets.
   *
   * @param logTo where to send (more or less) interesting output.
   * @param source ResourceCollection.
   * @param mapper filename mapper indicating how to find the target Resources.
   * @param targets object able to map a relative path as a Resource.
   * @param granularity The number of milliseconds leeway to give before deciding a target is out of
   *     date.
   * @return ResourceCollection.
   * @since Ant 1.7
   */
  public static ResourceCollection selectOutOfDateSources(
      ProjectComponent logTo,
      ResourceCollection source,
      FileNameMapper mapper,
      ResourceFactory targets,
      long granularity) {
    if (source.size() == 0) {
      logTo.log("No sources found.", Project.MSG_VERBOSE);
      return Resources.NONE;
    }
    source = Union.getInstance(source);
    logFuture(logTo, source, granularity);

    Union result = new Union();
    for (Iterator iter = source.iterator(); iter.hasNext(); ) {
      Resource sr = (Resource) iter.next();
      String srName = sr.getName();
      srName = srName == null ? srName : srName.replace('/', File.separatorChar);

      String[] targetnames = null;
      try {
        targetnames = mapper.mapFileName(srName);
      } catch (Exception e) {
        logTo.log("Caught " + e + " mapping resource " + sr, Project.MSG_VERBOSE);
      }
      if (targetnames == null || targetnames.length == 0) {
        logTo.log(sr + " skipped - don\'t know how to handle it", Project.MSG_VERBOSE);
        continue;
      }
      Union targetColl = new Union();
      for (int i = 0; i < targetnames.length; i++) {
        targetColl.add(targets.getResource(targetnames[i].replace(File.separatorChar, '/')));
      }
      // find the out-of-date targets:
      Restrict r = new Restrict();
      r.add(
          new And(
              new ResourceSelector[] {
                Type.FILE,
                new Or(new ResourceSelector[] {NOT_EXISTS, new Outdated(sr, granularity)})
              }));
      r.add(targetColl);
      if (r.size() > 0) {
        result.add(sr);
        Resource t = (Resource) (r.iterator().next());
        logTo.log(
            sr.getName()
                + " added as "
                + t.getName()
                + (t.isExists() ? " is outdated." : " doesn\'t exist."),
            Project.MSG_VERBOSE);
        continue;
      }
      // log uptodateness of all targets:
      logTo.log(
          sr.getName()
              + " omitted as "
              + targetColl.toString()
              + (targetColl.size() == 1 ? " is" : " are ")
              + " up to date.",
          Project.MSG_VERBOSE);
    }
    return result;
  }