import org.sonar.api.server.ws.WebService.NewController;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.api.web.page.Page;
+import org.sonar.core.documentation.DocumentationLinkGenerator;
import org.sonar.core.platform.PlatformEditionProvider;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
private final WebAnalyticsLoader webAnalyticsLoader;
private final IssueIndexSyncProgressChecker issueIndexSyncChecker;
private final DefaultAdminCredentialsVerifier defaultAdminCredentialsVerifier;
+ private final DocumentationLinkGenerator documentationLinkGenerator;
public GlobalAction(PageRepository pageRepository, Configuration config, ResourceTypes resourceTypes, Server server,
- NodeInformation nodeInformation, DbClient dbClient, UserSession userSession, PlatformEditionProvider editionProvider,
- WebAnalyticsLoader webAnalyticsLoader, IssueIndexSyncProgressChecker issueIndexSyncChecker,
- DefaultAdminCredentialsVerifier defaultAdminCredentialsVerifier) {
+ NodeInformation nodeInformation, DbClient dbClient, UserSession userSession, PlatformEditionProvider editionProvider,
+ WebAnalyticsLoader webAnalyticsLoader, IssueIndexSyncProgressChecker issueIndexSyncChecker,
+ DefaultAdminCredentialsVerifier defaultAdminCredentialsVerifier, DocumentationLinkGenerator documentationLinkGenerator) {
this.pageRepository = pageRepository;
this.config = config;
this.resourceTypes = resourceTypes;
this.systemSettingValuesByKey = new HashMap<>();
this.issueIndexSyncChecker = issueIndexSyncChecker;
this.defaultAdminCredentialsVerifier = defaultAdminCredentialsVerifier;
+ this.documentationLinkGenerator = documentationLinkGenerator;
}
@Override
writeNeedIssueSync(json);
json.prop("standalone", nodeInformation.isStandalone());
writeWebAnalytics(json);
+ writeDocumentationUrl(json);
json.endObject();
}
}
private void writeWebAnalytics(JsonWriter json) {
webAnalyticsLoader.getUrlPathToJs().ifPresent(p -> json.prop("webAnalyticsJsPath", p));
}
+
+ private void writeDocumentationUrl(JsonWriter json) {
+ json.prop("documentationUrl", documentationLinkGenerator.getDocumentationLink(null));
+ }
}
import org.sonar.api.resources.ResourceTypes;
import org.sonar.api.web.page.Page;
import org.sonar.api.web.page.PageDefinition;
+import org.sonar.core.documentation.DocumentationLinkGenerator;
import org.sonar.core.extension.CoreExtensionRepository;
import org.sonar.core.platform.EditionProvider;
import org.sonar.core.platform.PlatformEditionProvider;
private final PlatformEditionProvider editionProvider = mock(PlatformEditionProvider.class);
private final WebAnalyticsLoader webAnalyticsLoader = mock(WebAnalyticsLoader.class);
private final DefaultAdminCredentialsVerifier defaultAdminCredentialsVerifier = mock(DefaultAdminCredentialsVerifier.class);
+ private final DocumentationLinkGenerator documentationLinkGenerator = mock(DocumentationLinkGenerator.class);
private WsActionTester ws;
when(dbClient.getDatabase().getDialect()).thenReturn(new PostgreSql());
when(nodeInformation.isStandalone()).thenReturn(true);
when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.COMMUNITY));
+ when(documentationLinkGenerator.getDocumentationLink(null)).thenReturn("http://docs.example.com/10.0");
String result = call();
assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString());
assertJson(json).isSimilarTo("{\"webAnalyticsJsPath\":\"" + path + "\"}");
}
+ @Test
+ public void call_shouldReturnDocumentationUrl() {
+ init();
+ String url = "https://docs.sonarqube.org/10.0";
+ when(documentationLinkGenerator.getDocumentationLink(null)).thenReturn(url);
+
+ String json = call();
+ assertJson(json).isSimilarTo("{\"documentationUrl\":\"" + url + "\"}");
+ }
+
private void init() {
init(new org.sonar.api.web.page.Page[] {}, new ResourceTypeTree[] {});
}
pageRepository.start();
GlobalAction wsAction = new GlobalAction(pageRepository, settings.asConfig(), new ResourceTypes(resourceTypeTrees), server,
nodeInformation, dbClient, userSession, editionProvider, webAnalyticsLoader,
- indexSyncProgressChecker, defaultAdminCredentialsVerifier);
+ indexSyncProgressChecker, defaultAdminCredentialsVerifier, documentationLinkGenerator);
ws = new WsActionTester(wsAction);
wsAction.start();
}