public void testSequence() {
   List<Integer> lst = Iterators.sequence(1, 4);
   assertEquals(1, (int) lst.get(0));
   assertEquals(2, (int) lst.get(1));
   assertEquals(3, (int) lst.get(2));
   assertEquals(3, lst.size());
 }
 /** Gets the last successful {@link Promotion}. */
 public Promotion getLastFailed() {
   PromotionProcess p = getProcess();
   for (Integer n : Iterators.reverse(promotionAttempts)) {
     Promotion b = p.getBuildByNumber(n);
     if (b != null && b.getResult() != Result.SUCCESS) return b;
   }
   return null;
 }
Exemple #3
0
 @Override
 public Iterator<T> iterator() {
   // we need to intercept mutation, so for now don't allow Iterator.remove
   return new AdaptedIterator<ExtensionComponent<T>, T>(
       Iterators.readOnly(ensureLoaded().iterator())) {
     protected T adapt(ExtensionComponent<T> item) {
       return item.getInstance();
     }
   };
 }
 /** Gets all the promotion builds. */
 public List<Promotion> getPromotionBuilds() {
   PromotionProcess p = getProcess();
   List<Promotion> builds = new ArrayList<Promotion>();
   for (Integer n : Iterators.reverse(promotionAttempts)) {
     Promotion b = p.getBuildByNumber(n);
     if (b != null) {
       builds.add(b);
     }
   }
   return builds;
 }
Exemple #5
0
 /**
  * This version is so that the 'hasPermission' can degrade gracefully if "it" is not an {@link
  * AccessControlled} object.
  */
 public static boolean hasPermission(Object object, Permission permission)
     throws IOException, ServletException {
   if (permission == null) return true;
   if (object instanceof AccessControlled)
     return ((AccessControlled) object).hasPermission(permission);
   else {
     List<Ancestor> ancs = Stapler.getCurrentRequest().getAncestors();
     for (Ancestor anc : Iterators.reverse(ancs)) {
       Object o = anc.getObject();
       if (o instanceof AccessControlled) {
         return ((AccessControlled) o).hasPermission(permission);
       }
     }
     return Hudson.getInstance().hasPermission(permission);
   }
 }
Exemple #6
0
  /**
   * This version is so that the 'checkPermission' on <tt>layout.jelly</tt> degrades gracefully if
   * "it" is not an {@link AccessControlled} object. Otherwise it will perform no check and that
   * problem is hard to notice.
   */
  public static void checkPermission(Object object, Permission permission)
      throws IOException, ServletException {
    if (permission == null) return;

    if (object instanceof AccessControlled) checkPermission((AccessControlled) object, permission);
    else {
      List<Ancestor> ancs = Stapler.getCurrentRequest().getAncestors();
      for (Ancestor anc : Iterators.reverse(ancs)) {
        Object o = anc.getObject();
        if (o instanceof AccessControlled) {
          checkPermission((AccessControlled) o, permission);
          return;
        }
      }
      checkPermission(Hudson.getInstance(), permission);
    }
  }