001/* 002 * SonarQube 003 * Copyright (C) 2009-2017 SonarSource SA 004 * mailto:info 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.web.page; 021 022import org.sonar.api.ExtensionPoint; 023import org.sonar.api.server.ServerSide; 024 025/** 026 * Defines the Javascript pages added to SonarQube. 027 * <br> 028 * This interface replaces the deprecated class {@link org.sonar.api.web.Page}. Moreover, the technology changed from Ruby to Javascript 029 * <br> 030 * <h3>How to define pages</h3> 031 * <pre> 032 * import org.sonar.api.web.page.Page.Qualifier; 033 * 034 * public class MyPluginPagesDefinition implements PagesDefinition { 035 * {@literal @Override} 036 * public void define(Context context) { 037 * context 038 * // Global page by default 039 * .addPage(Page.builder("my_plugin/global_page").setName("Global Page").build()) 040 * // Global admin page 041 * .addPage(Page.builder("my_plugin/global_admin_page").setName("Admin Global Page").setAdmin(true).build()) 042 * // Project page 043 * .addPage(Page.builder("my_plugin/project_page").setName("Project Page").setScope(Scope.COMPONENT).setQualifiers(Qualifier.PROJECT).build()) 044 * // Admin project or module page 045 * .addPage(Page.builder("my_plugin/project_admin_page").setName("Admin Page for Project or Module").setAdmin(true) 046 * .setScope(Scope.COMPONENT).setQualifiers(Qualifier.PROJECT, Qualifier.MODULE).build()) 047 * // Page on all components (see Qualifier class) supported 048 * .addPage(Page.builder("my_plugin/component_page").setName("Component Page").setScope(Scope.COMPONENT).build()); 049 * // Organization page (when organizations are enabled) 050 * .addPage(Page.builder("my_plugin/org_page").setName("Organization Page").setScope(Scope.ORGANIZATION).build()); 051 * } 052 * } 053 * </pre> 054 * <h3>How to test a page definition</h3> 055 * <pre> 056 * public class PageDefinitionTest { 057 * {@literal @Test} 058 * public void test_page_definition() { 059 * PageDefinition underTest = context -> context.addPage(Page.builder("my_plugin/my_page").setName("My Page").build()); 060 * Context context = new Context(); 061 * 062 * underTest.define(context); 063 * 064 * assertThat(context.getPages()).extracting(Page::getKey).contains("my_plugin/my_page"); 065 * } 066 * </pre> 067 * 068 * @since 6.3 069 */ 070 071@ServerSide 072@ExtensionPoint 073public interface PageDefinition { 074 /** 075 * This method is executed when server is started 076 */ 077 void define(Context context); 078}