From 992fa1cac72b5fbaba7d71b5656320346c9a2817 Mon Sep 17 00:00:00 2001 From: Eric Hartmann Date: Mon, 25 Jun 2018 14:36:10 +0200 Subject: [PATCH] SONAR-10890 Add official flag to index.html --- .../org/sonar/server/platform/web/WebPagesCache.java | 9 ++++++--- .../org/sonar/server/platform/web/WebPagesCacheTest.java | 3 ++- server/sonar-web/public/index.html | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/web/WebPagesCache.java b/server/sonar-server/src/main/java/org/sonar/server/platform/web/WebPagesCache.java index 98a15d69c0e..e2070b4fa35 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/web/WebPagesCache.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/web/WebPagesCache.java @@ -43,6 +43,7 @@ public class WebPagesCache { private static final String WEB_CONTEXT_PLACEHOLDER = "%WEB_CONTEXT%"; private static final String SERVER_STATUS_PLACEHOLDER = "%SERVER_STATUS%"; private static final String INSTANCE_PLACEHOLDER = "%INSTANCE%"; + private static final String OFFICIAL_PLACEHOLDER = "%OFFICIAL%"; private static final String SONARCLOUD_INSTANCE_VALUE = "SonarCloud"; private static final String SONARQUBE_INSTANCE_VALUE = "SonarQube"; @@ -53,15 +54,17 @@ public class WebPagesCache { private final Platform platform; private final Configuration configuration; + private final OfficialDistribution officialDistribution; private ServletContext servletContext; private Map indexHtmlByPath; private Status status; - public WebPagesCache(Platform platform, Configuration configuration) { + public WebPagesCache(Platform platform, Configuration configuration, OfficialDistribution officialDistribution) { this.platform = platform; this.configuration = configuration; this.indexHtmlByPath = new HashMap<>(); + this.officialDistribution = officialDistribution; } public void init(ServletContext servletContext) { @@ -101,10 +104,10 @@ public class WebPagesCache { return template .replaceAll(WEB_CONTEXT_PLACEHOLDER, servletContext.getContextPath()) .replaceAll(SERVER_STATUS_PLACEHOLDER, serverStatus) - .replaceAll(INSTANCE_PLACEHOLDER, instance); + .replaceAll(INSTANCE_PLACEHOLDER, instance) + .replaceAll(OFFICIAL_PLACEHOLDER, String.valueOf(officialDistribution.check())); } catch (Exception e) { throw new IllegalStateException("Fail to load file " + path, e); } } - } diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/web/WebPagesCacheTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/web/WebPagesCacheTest.java index 2c2ca03f50f..51fb3a11e7d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/web/WebPagesCacheTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/web/WebPagesCacheTest.java @@ -48,10 +48,11 @@ public class WebPagesCacheTest { private ServletContext servletContext = mock(ServletContext.class); + private OfficialDistribution officialDistribution = mock(OfficialDistribution.class); private Platform platform = mock(Platform.class); private MapSettings mapSettings = new MapSettings(); - private WebPagesCache underTest = new WebPagesCache(platform, mapSettings.asConfig()); + private WebPagesCache underTest = new WebPagesCache(platform, mapSettings.asConfig(), officialDistribution); @Before public void setUp() throws Exception { diff --git a/server/sonar-web/public/index.html b/server/sonar-web/public/index.html index 812681b41f7..ede7fb15e0e 100644 --- a/server/sonar-web/public/index.html +++ b/server/sonar-web/public/index.html @@ -41,6 +41,7 @@ window.baseUrl = '%WEB_CONTEXT%'; window.serverStatus = '%SERVER_STATUS%'; window.instance = '%INSTANCE%'; + window.official = '%OFFICIAL%' <% for (let chunk in htmlWebpackPlugin.files.chunks) { %> -- 2.39.5