示例#1
0
文件: View.java 项目: zlosch/jenkins
  public List<Computer> getComputers() {
    Computer[] computers = Jenkins.getInstance().getComputers();

    if (!isFilterExecutors()) {
      return Arrays.asList(computers);
    }

    List<Computer> result = new ArrayList<Computer>();

    boolean roam = false;
    HashSet<Label> labels = new HashSet<Label>();
    for (Item item : getItems()) {
      if (item instanceof AbstractProject<?, ?>) {
        AbstractProject<?, ?> p = (AbstractProject<?, ?>) item;
        Label l = p.getAssignedLabel();
        if (l != null) {
          labels.add(l);
        } else {
          roam = true;
        }
      }
    }

    for (Computer c : computers) {
      Node n = c.getNode();
      if (n != null) {
        if (roam && n.getMode() == Mode.NORMAL
            || !Collections.disjoint(n.getAssignedLabels(), labels)) {
          result.add(c);
        }
      }
    }

    return result;
  }
示例#2
0
 @Override
 protected synchronized JSON data() {
   JSONArray r = new JSONArray();
   for (User u : modified) {
     UserInfo i = users.get(u);
     JSONObject entry =
         new JSONObject()
             .accumulate("id", u.getId())
             .accumulate("fullName", u.getFullName())
             .accumulate("url", u.getUrl())
             .accumulate(
                 "avatar",
                 i.avatar != null
                     ? i.avatar
                     : Stapler.getCurrentRequest().getContextPath()
                         + Functions.getResourcePath()
                         + "/images/"
                         + iconSize
                         + "/user.png")
             .accumulate("timeSortKey", i.getTimeSortKey())
             .accumulate("lastChangeTimeString", i.getLastChangeTimeString());
     AbstractProject<?, ?> p = i.getProject();
     if (p != null) {
       entry
           .accumulate("projectUrl", p.getUrl())
           .accumulate("projectFullDisplayName", p.getFullDisplayName());
     }
     r.add(entry);
   }
   modified.clear();
   return r;
 }
示例#3
0
 @Override
 protected void compute() throws Exception {
   int itemCount = 0;
   for (Item item : items) {
     for (Job<?, ?> job : item.getAllJobs()) {
       if (job instanceof AbstractProject) {
         AbstractProject<?, ?> p = (AbstractProject) job;
         RunList<? extends AbstractBuild<?, ?>> builds = p.getBuilds();
         int buildCount = 0;
         for (AbstractBuild<?, ?> build : builds) {
           if (canceled()) {
             return;
           }
           for (ChangeLogSet.Entry entry : build.getChangeSet()) {
             User user = entry.getAuthor();
             UserInfo info = users.get(user);
             if (info == null) {
               UserInfo userInfo = new UserInfo(user, p, build.getTimestamp());
               userInfo.avatar = UserAvatarResolver.resolveOrNull(user, iconSize);
               synchronized (this) {
                 users.put(user, userInfo);
                 modified.add(user);
               }
             } else if (info.getLastChange().before(build.getTimestamp())) {
               synchronized (this) {
                 info.project = p;
                 info.lastChange = build.getTimestamp();
                 modified.add(user);
               }
             }
           }
           // TODO consider also adding the user of the UserCause when applicable
           buildCount++;
           progress((itemCount + 1.0 * buildCount / builds.size()) / (items.size() + 1));
         }
       }
     }
     itemCount++;
     progress(1.0 * itemCount / (items.size() + /* handling User.getAll */ 1));
   }
   if (unknown != null) {
     if (canceled()) {
       return;
     }
     for (User u : User.getAll()) { // TODO nice to have a method to iterate these lazily
       if (u == unknown) {
         continue;
       }
       if (!users.containsKey(u)) {
         UserInfo userInfo = new UserInfo(u, null, null);
         userInfo.avatar = UserAvatarResolver.resolveOrNull(u, iconSize);
         synchronized (this) {
           users.put(u, userInfo);
           modified.add(u);
         }
       }
     }
   }
 }
示例#4
0
文件: View.java 项目: zlosch/jenkins
 public static boolean isApplicable(Collection<? extends Item> items) {
   for (Item item : items) {
     for (Job job : item.getAllJobs()) {
       if (job instanceof AbstractProject) {
         AbstractProject<?, ?> p = (AbstractProject) job;
         for (AbstractBuild<?, ?> build : p.getBuilds()) {
           for (Entry entry : build.getChangeSet()) {
             User user = entry.getAuthor();
             if (user != null) return true;
           }
         }
       }
     }
   }
   return false;
 }
示例#5
0
  private List<Queue.Item> filterQueue(List<Queue.Item> base) {
    if (!isFilterQueue()) {
      return base;
    }

    Collection<TopLevelItem> items = getItems();
    List<Queue.Item> result = new ArrayList<Queue.Item>();
    for (Queue.Item qi : base) {
      if (items.contains(qi.task)) {
        result.add(qi);
      } else if (qi.task instanceof AbstractProject<?, ?>) {
        AbstractProject<?, ?> project = (AbstractProject<?, ?>) qi.task;
        if (items.contains(project.getRootProject())) {
          result.add(qi);
        }
      }
    }
    return result;
  }
示例#6
0
文件: View.java 项目: zlosch/jenkins
    private Map<User, UserInfo> getUserInfo(Collection<? extends Item> items) {
      Map<User, UserInfo> users = new HashMap<User, UserInfo>();
      for (Item item : items) {
        for (Job job : item.getAllJobs()) {
          if (job instanceof AbstractProject) {
            AbstractProject<?, ?> p = (AbstractProject) job;
            for (AbstractBuild<?, ?> build : p.getBuilds()) {
              for (Entry entry : build.getChangeSet()) {
                User user = entry.getAuthor();

                UserInfo info = users.get(user);
                if (info == null) users.put(user, new UserInfo(user, p, build.getTimestamp()));
                else if (info.getLastChange().before(build.getTimestamp())) {
                  info.project = p;
                  info.lastChange = build.getTimestamp();
                }
              }
            }
          }
        }
      }
      return users;
    }
示例#7
0
 @Override
 protected void compute() throws Exception {
   int itemCount = 0;
   for (Item item : items) {
     for (Job<?, ?> job : item.getAllJobs()) {
       if (job instanceof AbstractProject) {
         AbstractProject<?, ?> p = (AbstractProject) job;
         RunList<? extends AbstractBuild<?, ?>> builds = p.getBuilds();
         int buildCount = 0;
         for (AbstractBuild<?, ?> build : builds) {
           if (canceled()) {
             return;
           }
           for (ChangeLogSet.Entry entry : build.getChangeSet()) {
             User user = entry.getAuthor();
             UserInfo info = users.get(user);
             if (info == null) {
               UserInfo userInfo = new UserInfo(user, p, build.getTimestamp());
               userInfo.avatar = UserAvatarResolver.resolveOrNull(user, iconSize);
               synchronized (this) {
                 users.put(user, userInfo);
                 modified.add(user);
               }
             } else if (info.getLastChange().before(build.getTimestamp())) {
               synchronized (this) {
                 info.project = p;
                 info.lastChange = build.getTimestamp();
                 modified.add(user);
               }
             }
           }
           // TODO consider also adding the user of the UserCause when applicable
           buildCount++;
           // TODO this defeats lazy-loading. Should rather do a breadth-first search, as in
           // hudson.plugins.view.dashboard.builds.LatestBuilds
           // (though currently there is no quick implementation of RunMap.size() ~
           // idOnDisk.size(), which would be needed for proper progress)
           progress((itemCount + 1.0 * buildCount / builds.size()) / (items.size() + 1));
         }
       }
     }
     itemCount++;
     progress(1.0 * itemCount / (items.size() + /* handling User.getAll */ 1));
   }
   if (unknown != null) {
     if (canceled()) {
       return;
     }
     for (User u : User.getAll()) { // TODO nice to have a method to iterate these lazily
       if (canceled()) {
         return;
       }
       if (u == unknown) {
         continue;
       }
       if (!users.containsKey(u)) {
         UserInfo userInfo = new UserInfo(u, null, null);
         userInfo.avatar = UserAvatarResolver.resolveOrNull(u, iconSize);
         synchronized (this) {
           users.put(u, userInfo);
           modified.add(u);
         }
       }
     }
   }
 }