/hudson-core/src/main/java/hudson/Extension.java

http://github.com/hudson/hudson · Java · 87 lines · 15 code · 5 blank · 67 comment · 0 complexity · 62440939ff118c1b5280254765061bd3 MD5 · raw file

  1. /*
  2. * The MIT License
  3. *
  4. * Copyright (c) 2004-2010, Sun Microsystems, Inc.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. package hudson;
  25. import net.java.sezpoz.Indexable;
  26. import java.lang.annotation.Documented;
  27. import java.lang.annotation.Retention;
  28. import java.lang.annotation.Target;
  29. import static java.lang.annotation.ElementType.*;
  30. import static java.lang.annotation.RetentionPolicy.RUNTIME;
  31. /**
  32. * Marks a field, a method, or a class for automatic discovery, so that Hudson can locate
  33. * implementations of {@link ExtensionPoint}s automatically.
  34. *
  35. * <p>
  36. * (In contrast, in earlier Hudson, the registration was manual.)
  37. *
  38. * <p>
  39. * In a simplest case, put this on your class, and Hudson will create an instance of it
  40. * and register it to the appropriate {@link ExtensionList}.
  41. *
  42. * <p>
  43. * If you'd like Hudson to call
  44. * a factory method instead of a constructor, put this annotation on your static factory
  45. * method. Hudson will invoke it and if the method returns a non-null instance, it'll be
  46. * registered. The return type of the method is used to determine which {@link ExtensionList}
  47. * will get the instance.
  48. *
  49. * Finally, you can put this annotation on a static field if the field contains a reference
  50. * to an instance that you'd like to register.
  51. *
  52. * <p>
  53. * This is the default way of having your implementations auto-registered to Hudson,
  54. * but Hudson also supports arbitrary DI containers for hosting your implementations.
  55. * See {@link ExtensionFinder} for more details.
  56. *
  57. * @author Kohsuke Kawaguchi
  58. * @since 1.286
  59. * @see <a href="http://java.net/projects/sezpoz/">SezPoz</a>
  60. * @see ExtensionFinder
  61. * @see ExtensionList
  62. */
  63. @Indexable
  64. @Retention(RUNTIME)
  65. @Target({TYPE, FIELD, METHOD})
  66. @Documented
  67. public @interface Extension {
  68. /**
  69. * Used for sorting extensions.
  70. *
  71. * Extensions will be sorted in the descending order of the ordinal.
  72. * This is a rather poor approach to the problem, so its use is generally discouraged.
  73. *
  74. * @since 1.306
  75. */
  76. double ordinal() default 0;
  77. /**
  78. * If an extension is optional, don't log any class loading errors when reading it.
  79. * @since 1.358
  80. */
  81. boolean optional() default false;
  82. }