001/* 002 * SonarQube 003 * Copyright (C) 2009-2016 SonarSource SA 004 * mailto:contact AT sonarsource DOT com 005 * 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.api; 021 022/** 023 * Factory of extensions. It allows to dynamically create extensions depending upon runtime context. A use-case is 024 * to create one rule repository by language. 025 * 026 * <p>Notes : 027 * <ul> 028 * <li>the provider is declared in Plugin.getExtensions()</li> 029 * <li>the provider must also implement ServerExtension and/or BatchExtension</li> 030 * <li>the provider can accept dependencies (parameters) in its constructors.</li> 031 * <li>the method provide() is executed once by sonar</li> 032 * <li>the method provide() must return an object, a class or an Iterable of objects. <strong>Arrays are excluded</strong>.</li> 033 * </ul> 034 * 035 * 036 * <p>Example: 037 * <pre> 038 * {@code 039 * public class RuleRepositoryProvider extends ExtensionProvider implements ServerExtension { 040 * private Language[] languages; 041 * 042 * public RuleRepositoryProvider(Language[] languages) { 043 * this.languages = languages; 044 * } 045 * 046 * public List<RuleRepository> provide() { 047 * List<RuleRepository> result = new ArrayList<RuleRepository>(); 048 * for(Language language: languages) { 049 * result.add(new RuleRepository(..., language, ...)); 050 * } 051 * return result; 052 * } 053 * } 054 * } 055 * </pre> 056 * 057 * 058 * @since 2.3 059 */ 060public abstract class ExtensionProvider implements Extension { 061 062 public abstract Object provide(); 063}