diff options
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/ExtensionProvider.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ExtensionProvider.java b/sonar-plugin-api/src/main/java/org/sonar/api/ExtensionProvider.java index 615c57a6631..40dcbba5d97 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/ExtensionProvider.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/ExtensionProvider.java @@ -22,6 +22,33 @@ package org.sonar.api; import org.picocontainer.injectors.Provider; /** + * Factory of extensions. It allows to dynamically create extensions depending upon runtime context. A use-case is + * to create one rule repository by language. + * + * <p>Constraints are : + * <ul> + * <li>the factory is declared in Plugin.getExtensions() as an instance but not as a class</li> + * <li>the factory must have a public method named "provide()"</li> + * <li>the method provide() must return an object or an array of objects. Collections and classes are excluded.</li> + * <li>the methode provide() can accept parameters. These parameters are IoC dependencies. + * </ul> + * </p> + * + * <p>Example: + * <pre> + * public class RuleRepositoryProvider extends ExtensionProvider { + * public RuleRepository[] provide(Language[] languages) { + * RuleRepository[] result = new RuleRepository[languages.length]; + * for(int index=0; index < languages.length ; index++) { + * Language language = languages[index]; + * result[index] = new RuleRepository(...); + * } + * return result; + * } + * } + * </pre> + * </p> + * * @since 2.3 */ public abstract class ExtensionProvider implements Extension, Provider { |