From 8f1c7fdeb71bbb2ddc498f240e1806aee5b72213 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Fri, 10 May 2013 14:01:43 -0700 Subject: [PATCH] Populate version from HTML and not compiled into GWT JS Avoid rebuilding the GWT JS every time the Git commit changes by obtaining the version of the UI from the server as part of the host HTML page. This enables BUCK to avoid recompiling GWT code simply because the user modified server code. Change-Id: I4ac5167228bce20fd2dc89af5c1cea13ad3cf739 --- gerrit-common/BUCK | 5 +--- .../google/gerrit/common/ClientVersion.java | 24 ------------------- .../gerrit/common/data/HostPageData.java | 1 + gerrit-gwtui/DEFS | 5 +--- .../java/com/google/gerrit/client/Gerrit.java | 15 ++++-------- .../gerrit/httpd/raw/HostPageServlet.java | 4 +++- 6 files changed, 10 insertions(+), 44 deletions(-) delete mode 100644 gerrit-common/src/main/java/com/google/gerrit/common/ClientVersion.java diff --git a/gerrit-common/BUCK b/gerrit-common/BUCK index 7423e35976..8dfdbb70d0 100644 --- a/gerrit-common/BUCK +++ b/gerrit-common/BUCK @@ -16,10 +16,7 @@ gwt_module( java_library( name = 'server', - srcs = glob( - [SRC + 'common/**/*.java'], - excludes = [SRC + 'common/ClientVersion.java'], - ), + srcs = glob([SRC + 'common/**/*.java']), deps = [ '//gerrit-patch-jgit:server', '//gerrit-prettify:server', diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/ClientVersion.java b/gerrit-common/src/main/java/com/google/gerrit/common/ClientVersion.java deleted file mode 100644 index 42ee5dd3d9..0000000000 --- a/gerrit-common/src/main/java/com/google/gerrit/common/ClientVersion.java +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2009 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.gerrit.common; - -import com.google.gwt.resources.client.ClientBundle; -import com.google.gwt.resources.client.TextResource; - -public interface ClientVersion extends ClientBundle { - /** Version number of this client software build. */ - @Source("Version") - TextResource version(); -} diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/HostPageData.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/HostPageData.java index f014f5fd53..f143405ab0 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/HostPageData.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/HostPageData.java @@ -21,6 +21,7 @@ import java.util.List; /** Data sent as part of the host page, to bootstrap the UI. */ public class HostPageData { + public String version; public Account account; public AccountDiffPreference accountDiffPref; public String xGerritAuth; diff --git a/gerrit-gwtui/DEFS b/gerrit-gwtui/DEFS index baffdbb7e0..6ace5bf68f 100644 --- a/gerrit-gwtui/DEFS +++ b/gerrit-gwtui/DEFS @@ -31,10 +31,7 @@ DEBUG_OPTS = [ '-optimize', '0', ] -APP_DEPS = [ - ':ui_module', - '//gerrit-common:version', -] +APP_DEPS = [':ui_module'] def gwt_user_agent_permutations( name, diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java index 2a9cb71b12..62662c9d3b 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java @@ -31,7 +31,6 @@ import com.google.gerrit.client.ui.MorphingTabPanel; import com.google.gerrit.client.ui.PatchLink; import com.google.gerrit.client.ui.Screen; import com.google.gerrit.client.ui.ScreenLoadEvent; -import com.google.gerrit.common.ClientVersion; import com.google.gerrit.common.PageLinks; import com.google.gerrit.common.data.GerritConfig; import com.google.gerrit.common.data.GitwebConfig; @@ -434,19 +433,13 @@ public class Gerrit implements EntryPoint { } } - private static void populateBottomMenu(final RootPanel btmmenu) { + private static void populateBottomMenu(RootPanel btmmenu, HostPageData hpd) { final Label keyHelp = new Label(C.keyHelp()); keyHelp.setStyleName(RESOURCES.css().keyhelp()); btmmenu.add(keyHelp); - String vs; - if (GWT.isScript()) { - final ClientVersion v = GWT.create(ClientVersion.class); - vs = v.version().getText(); - if (vs.startsWith("v")) { - vs = vs.substring(1); - } - } else { + String vs = hpd.version; + if (vs == null || vs.isEmpty()) { vs = "dev"; } @@ -539,7 +532,7 @@ public class Gerrit implements EntryPoint { applyUserPreferences(); initHistoryHooks(); - populateBottomMenu(gBottomMenu); + populateBottomMenu(gBottomMenu, hpd); refreshMenuBar(); History.addValueChangeHandler(new ValueChangeHandler() { diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java index ea2168a8a4..b1fd412981 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java @@ -14,10 +14,11 @@ package com.google.gerrit.httpd.raw; +import com.google.common.collect.Lists; import com.google.common.hash.Hasher; import com.google.common.hash.Hashing; -import com.google.common.collect.Lists; import com.google.common.primitives.Bytes; +import com.google.gerrit.common.Version; import com.google.gerrit.common.data.GerritConfig; import com.google.gerrit.common.data.HostPageData; import com.google.gerrit.extensions.registration.DynamicSet; @@ -275,6 +276,7 @@ public class HostPageServlet extends HttpServlet { footer = injectXmlFile(hostDoc, "gerrit_footer", site.site_footer); final HostPageData pageData = new HostPageData(); + pageData.version = Version.getVersion(); pageData.config = config; final StringWriter w = new StringWriter();