Пример #1
0
 protected RunListener() {
   Type type = Types.getBaseClass(getClass(), RunListener.class);
   if (type instanceof ParameterizedType)
     targetType = Types.erasure(Types.getTypeArgument(type, 0));
   else
     throw new IllegalStateException(getClass() + " uses the raw type for extending RunListener");
 }
Пример #2
0
 /**
  * Given {@code c=MyList (extends ArrayList<Foo>), base=List}, compute the parameterization of
  * 'base' that's assignable from 'c' (in this case {@code List<Foo>}), and return its n-th type
  * parameter (n=0 would return {@code Foo}).
  *
  * <p>This method is useful for doing type arithmetic.
  *
  * @throws AssertionError if c' is not parameterized.
  */
 public static <B> Class getTypeParameter(Class<? extends B> c, Class<B> base, int n) {
   Type parameterization = Types.getBaseClass(c, base);
   if (parameterization instanceof ParameterizedType) {
     ParameterizedType pt = (ParameterizedType) parameterization;
     return Types.erasure(Types.getTypeArgument(pt, n));
   } else {
     throw new AssertionError(c + " doesn't properly parameterize " + base);
   }
 }
Пример #3
0
    private Class computeItemType() {
      if (clazz.isArray()) {
        return clazz.getComponentType();
      }
      if (Collection.class.isAssignableFrom(clazz)) {
        Type col = Types.getBaseClass(type, Collection.class);

        if (col instanceof ParameterizedType) return Types.erasure(Types.getTypeArgument(col, 0));
        else return Object.class;
      }
      return null;
    }
Пример #4
0
 /** Auto-discovers {@link OptionHandler}s and add them to the given command line parser. */
 protected void registerOptionHandlers() {
   try {
     for (Class c :
         Index.list(
             OptionHandlerExtension.class,
             Jenkins.getInstance().pluginManager.uberClassLoader,
             Class.class)) {
       Type t = Types.getBaseClass(c, OptionHandler.class);
       CmdLineParser.registerHandler(Types.erasure(Types.getTypeArgument(t, 0)), c);
     }
   } catch (IOException e) {
     throw new Error(e);
   }
 }
Пример #5
0
  static {
    // register option handlers that are defined
    ClassLoaders cls = new ClassLoaders();
    Jenkins j = Jenkins.getInstance();
    if (j != null) { // only when running on the master
      cls.put(j.getPluginManager().uberClassLoader);

      ResourceNameIterator servicesIter =
          new DiscoverServiceNames(cls).findResourceNames(OptionHandler.class.getName());
      final ResourceClassIterator itr = new DiscoverClasses(cls).findResourceClasses(servicesIter);

      while (itr.hasNext()) {
        Class h = itr.nextResourceClass().loadClass();
        Class c =
            Types.erasure(Types.getTypeArgument(Types.getBaseClass(h, OptionHandler.class), 0));
        CmdLineParser.registerHandler(c, h);
      }
    }
  }