Check with HEAD request if docs are available and remove GerritConfig

The Gerrit client needs to know if documentation is available on the
server so that it can add the Documentation menu bar. The
/config/server/info REST endpoint cannot easily provide this
information since the ServletContext which can be used to check this
is not available in the REST API layer. Instead let the Gerrit client
do a HEAD request to "Documentation/index.html" to check if
documentation is available on the server.

GerritConfig is now no longer used and can be removed.

Change-Id: I759c262a6789193d14bcfdf702f9907854230c01
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin 2015-05-12 14:33:22 +02:00
parent 9480fb45b9
commit 2b753cc777
9 changed files with 59 additions and 115 deletions

View File

@ -1,28 +0,0 @@
// Copyright (C) 2008 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.data;
public class GerritConfig implements Cloneable {
protected boolean documentationAvailable;
public boolean isDocumentationAvailable() {
return documentationAvailable;
}
public void setDocumentationAvailable(final boolean available) {
documentationAvailable = available;
}
}

View File

@ -26,7 +26,6 @@ public class HostPageData {
public Account account; public Account account;
public AccountDiffPreference accountDiffPref; public AccountDiffPreference accountDiffPref;
public String xGerritAuth; public String xGerritAuth;
public GerritConfig config;
public Theme theme; public Theme theme;
public List<String> plugins; public List<String> plugins;
public List<Message> messages; public List<Message> messages;

View File

@ -33,6 +33,4 @@ public interface SystemInfoService extends RemoteJsonService {
void contributorAgreements(AsyncCallback<List<ContributorAgreement>> callback); void contributorAgreements(AsyncCallback<List<ContributorAgreement>> callback);
void clientError(String message, AsyncCallback<VoidResult> callback); void clientError(String message, AsyncCallback<VoidResult> callback);
public void gerritConfig(final AsyncCallback<GerritConfig> callback);
} }

View File

@ -30,6 +30,7 @@ import com.google.gerrit.client.changes.ChangeListScreen;
import com.google.gerrit.client.config.AuthInfo; import com.google.gerrit.client.config.AuthInfo;
import com.google.gerrit.client.config.ConfigServerApi; import com.google.gerrit.client.config.ConfigServerApi;
import com.google.gerrit.client.config.ServerInfo; import com.google.gerrit.client.config.ServerInfo;
import com.google.gerrit.client.documentation.DocInfo;
import com.google.gerrit.client.extensions.TopMenu; import com.google.gerrit.client.extensions.TopMenu;
import com.google.gerrit.client.extensions.TopMenuItem; import com.google.gerrit.client.extensions.TopMenuItem;
import com.google.gerrit.client.extensions.TopMenuList; import com.google.gerrit.client.extensions.TopMenuList;
@ -43,7 +44,6 @@ import com.google.gerrit.client.ui.MorphingTabPanel;
import com.google.gerrit.client.ui.ProjectLinkMenuItem; import com.google.gerrit.client.ui.ProjectLinkMenuItem;
import com.google.gerrit.client.ui.Screen; import com.google.gerrit.client.ui.Screen;
import com.google.gerrit.common.PageLinks; import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.data.GerritConfig;
import com.google.gerrit.common.data.HostPageData; import com.google.gerrit.common.data.HostPageData;
import com.google.gerrit.common.data.SystemInfoService; import com.google.gerrit.common.data.SystemInfoService;
import com.google.gerrit.extensions.client.GerritTopMenu; import com.google.gerrit.extensions.client.GerritTopMenu;
@ -65,6 +65,11 @@ import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler; import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.EventBus; import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.SimpleEventBus; import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.http.client.URL; import com.google.gwt.http.client.URL;
import com.google.gwt.http.client.UrlBuilder; import com.google.gwt.http.client.UrlBuilder;
import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Command;
@ -103,10 +108,11 @@ public class Gerrit implements EntryPoint {
public static final EventBus EVENT_BUS = GWT.create(SimpleEventBus.class); public static final EventBus EVENT_BUS = GWT.create(SimpleEventBus.class);
public static final Themer THEMER = GWT.create(Themer.class); public static final Themer THEMER = GWT.create(Themer.class);
public static final String PROJECT_NAME_MENU_VAR = "${projectName}"; public static final String PROJECT_NAME_MENU_VAR = "${projectName}";
public static final String INDEX = "Documentation/index.html";
private static String myHost; private static String myHost;
private static GerritConfig myConfig;
private static ServerInfo myServerInfo; private static ServerInfo myServerInfo;
private static boolean hasDocumentation;
private static HostPageData.Theme myTheme; private static HostPageData.Theme myTheme;
private static Account myAccount; private static Account myAccount;
private static String defaultScreenToken; private static String defaultScreenToken;
@ -284,11 +290,6 @@ public class Gerrit implements EntryPoint {
return bottomMenu; return bottomMenu;
} }
/** Get the public configuration data used by this Gerrit instance. */
public static GerritConfig getConfig() {
return myConfig;
}
/** Get the public configuration data used by this Gerrit instance. */ /** Get the public configuration data used by this Gerrit instance. */
public static ServerInfo info() { public static ServerInfo info() {
return myServerInfo; return myServerInfo;
@ -429,6 +430,12 @@ public class Gerrit implements EntryPoint {
RpcStatus.INSTANCE = new RpcStatus(); RpcStatus.INSTANCE = new RpcStatus();
CallbackGroup cbg = new CallbackGroup(); CallbackGroup cbg = new CallbackGroup();
getDocIndex(cbg.add(new GerritCallback<DocInfo>() {
@Override
public void onSuccess(DocInfo indexInfo) {
hasDocumentation = indexInfo != null;
}
}));
ConfigServerApi.serverInfo(cbg.add(new GerritCallback<ServerInfo>() { ConfigServerApi.serverInfo(cbg.add(new GerritCallback<ServerInfo>() {
@Override @Override
public void onSuccess(ServerInfo info) { public void onSuccess(ServerInfo info) {
@ -440,7 +447,6 @@ public class Gerrit implements EntryPoint {
@Override @Override
public void onSuccess(final HostPageData result) { public void onSuccess(final HostPageData result) {
Document.get().getElementById("gerrit_hostpagedata").removeFromParent(); Document.get().getElementById("gerrit_hostpagedata").removeFromParent();
myConfig = result.config;
myTheme = result.theme; myTheme = result.theme;
isNoteDbEnabled = result.isNoteDbEnabled; isNoteDbEnabled = result.isNoteDbEnabled;
if (result.account != null) { if (result.account != null) {
@ -700,7 +706,7 @@ public class Gerrit implements EntryPoint {
}, CREATE_PROJECT, CREATE_GROUP, VIEW_PLUGINS); }, CREATE_PROJECT, CREATE_GROUP, VIEW_PLUGINS);
} }
if (getConfig().isDocumentationAvailable()) { if (hasDocumentation) {
m = new LinkMenuBar(); m = new LinkMenuBar();
menuBars.put(GerritTopMenu.DOCUMENTATION.menuName, m); menuBars.put(GerritTopMenu.DOCUMENTATION.menuName, m);
addDocLink(m, C.menuDocumentationTOC(), "index.html"); addDocLink(m, C.menuDocumentationTOC(), "index.html");
@ -809,6 +815,32 @@ public class Gerrit implements EntryPoint {
}); });
} }
private static void getDocIndex(final AsyncCallback<DocInfo> cb) {
RequestBuilder req =
new RequestBuilder(RequestBuilder.HEAD, GWT.getHostPageBaseURL()
+ INDEX);
req.setCallback(new RequestCallback() {
@Override
public void onResponseReceived(Request req, Response resp) {
if (resp.getStatusCode() == Response.SC_OK) {
cb.onSuccess(DocInfo.create());
} else {
cb.onSuccess(null);
}
}
@Override
public void onError(Request request, Throwable e) {
cb.onFailure(e);
}
});
try {
req.send();
} catch (RequestException e) {
cb.onFailure(e);
}
}
private static AsyncCallback<Preferences> createMyMenuBarCallback() { private static AsyncCallback<Preferences> createMyMenuBarCallback() {
return new GerritCallback<Preferences>() { return new GerritCallback<Preferences>() {
@Override @Override

View File

@ -22,6 +22,10 @@ public class DocInfo extends JavaScriptObject {
public final native String title() /*-{ return this.title; }-*/; public final native String title() /*-{ return this.title; }-*/;
public final native String url() /*-{ return this.url; }-*/; public final native String url() /*-{ return this.url; }-*/;
public static DocInfo create() {
return (DocInfo) createObject();
}
protected DocInfo() { protected DocInfo() {
} }

View File

@ -1,49 +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.httpd;
import com.google.gerrit.common.data.GerritConfig;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.ProvisionException;
import java.net.MalformedURLException;
import javax.servlet.ServletContext;
class GerritConfigProvider implements Provider<GerritConfig> {
private final ServletContext servletContext;
@Inject
GerritConfigProvider(ServletContext sc) {
servletContext = sc;
}
private GerritConfig create() throws MalformedURLException {
final GerritConfig config = new GerritConfig();
config.setDocumentationAvailable(servletContext
.getResource("/Documentation/index.html") != null);
return config;
}
@Override
public GerritConfig get() {
try {
return create();
} catch (MalformedURLException e) {
throw new ProvisionException("Cannot create GerritConfig instance", e);
}
}
}

View File

@ -17,7 +17,6 @@ package com.google.gerrit.httpd;
import static com.google.gerrit.extensions.registration.PrivateInternals_DynamicTypes.registerInParentInjectors; import static com.google.gerrit.extensions.registration.PrivateInternals_DynamicTypes.registerInParentInjectors;
import com.google.gerrit.common.Nullable; import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.GerritConfig;
import com.google.gerrit.extensions.registration.DynamicSet; import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.extensions.webui.WebUiPlugin; import com.google.gerrit.extensions.webui.WebUiPlugin;
import com.google.gerrit.httpd.auth.become.BecomeAnyAccountModule; import com.google.gerrit.httpd.auth.become.BecomeAnyAccountModule;
@ -80,8 +79,6 @@ public class WebModule extends LifecycleModule {
install(new GitWebModule()); install(new GitWebModule());
} }
bind(GerritConfigProvider.class);
bind(GerritConfig.class).toProvider(GerritConfigProvider.class);
DynamicSet.setOf(binder(), WebUiPlugin.class); DynamicSet.setOf(binder(), WebUiPlugin.class);
install(new AsyncReceiveCommits.Module()); install(new AsyncReceiveCommits.Module());

View File

@ -22,7 +22,6 @@ import com.google.common.hash.Hasher;
import com.google.common.hash.Hashing; import com.google.common.hash.Hashing;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;
import com.google.gerrit.common.Version; import com.google.gerrit.common.Version;
import com.google.gerrit.common.data.GerritConfig;
import com.google.gerrit.common.data.HostPageData; import com.google.gerrit.common.data.HostPageData;
import com.google.gerrit.extensions.registration.DynamicItem; import com.google.gerrit.extensions.registration.DynamicItem;
import com.google.gerrit.extensions.registration.DynamicSet; import com.google.gerrit.extensions.registration.DynamicSet;
@ -77,7 +76,6 @@ public class HostPageServlet extends HttpServlet {
private final Provider<CurrentUser> currentUser; private final Provider<CurrentUser> currentUser;
private final DynamicItem<WebSession> session; private final DynamicItem<WebSession> session;
private final GerritConfig config;
private final DynamicSet<WebUiPlugin> plugins; private final DynamicSet<WebUiPlugin> plugins;
private final DynamicSet<MessageOfTheDay> messages; private final DynamicSet<MessageOfTheDay> messages;
private final HostPageData.Theme signedOutTheme; private final HostPageData.Theme signedOutTheme;
@ -92,18 +90,20 @@ public class HostPageServlet extends HttpServlet {
private volatile Page page; private volatile Page page;
@Inject @Inject
HostPageServlet(final Provider<CurrentUser> cu, final DynamicItem<WebSession> w, HostPageServlet(
final SitePaths sp, final ThemeFactory themeFactory, Provider<CurrentUser> cu,
final GerritConfig gc, final ServletContext servletContext, DynamicItem<WebSession> w,
final DynamicSet<WebUiPlugin> webUiPlugins, SitePaths sp,
final DynamicSet<MessageOfTheDay> motd, ThemeFactory themeFactory,
@GerritServerConfig final Config cfg, ServletContext servletContext,
final StaticServlet ss, DynamicSet<WebUiPlugin> webUiPlugins,
final NotesMigration migration) DynamicSet<MessageOfTheDay> motd,
@GerritServerConfig Config cfg,
StaticServlet ss,
NotesMigration migration)
throws IOException, ServletException { throws IOException, ServletException {
currentUser = cu; currentUser = cu;
session = w; session = w;
config = gc;
plugins = webUiPlugins; plugins = webUiPlugins;
messages = motd; messages = motd;
signedOutTheme = themeFactory.getSignedOutTheme(); signedOutTheme = themeFactory.getSignedOutTheme();
@ -323,7 +323,6 @@ public class HostPageServlet extends HttpServlet {
final HostPageData pageData = new HostPageData(); final HostPageData pageData = new HostPageData();
pageData.version = Version.getVersion(); pageData.version = Version.getVersion();
pageData.config = config;
pageData.isNoteDbEnabled = isNoteDbEnabled; pageData.isNoteDbEnabled = isNoteDbEnabled;
pageData.pluginsLoadTimeout = pluginsLoadTimeout; pageData.pluginsLoadTimeout = pluginsLoadTimeout;

View File

@ -16,7 +16,6 @@ package com.google.gerrit.httpd.rpc;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.gerrit.common.data.ContributorAgreement; import com.google.gerrit.common.data.ContributorAgreement;
import com.google.gerrit.common.data.GerritConfig;
import com.google.gerrit.common.data.SshHostKey; import com.google.gerrit.common.data.SshHostKey;
import com.google.gerrit.common.data.SystemInfoService; import com.google.gerrit.common.data.SystemInfoService;
import com.google.gerrit.server.project.ProjectCache; import com.google.gerrit.server.project.ProjectCache;
@ -46,16 +45,14 @@ class SystemInfoServiceImpl implements SystemInfoService {
private final List<HostKey> hostKeys; private final List<HostKey> hostKeys;
private final Provider<HttpServletRequest> httpRequest; private final Provider<HttpServletRequest> httpRequest;
private final Provider<GerritConfig> config;
private final ProjectCache projectCache; private final ProjectCache projectCache;
@Inject @Inject
SystemInfoServiceImpl(final SshInfo daemon, SystemInfoServiceImpl(SshInfo daemon,
final Provider<HttpServletRequest> hsr, final Provider<GerritConfig> cfg, Provider<HttpServletRequest> hsr,
final ProjectCache pc) { ProjectCache pc) {
hostKeys = daemon.getHostKeys(); hostKeys = daemon.getHostKeys();
httpRequest = hsr; httpRequest = hsr;
config = cfg;
projectCache = pc; projectCache = pc;
} }
@ -95,9 +92,4 @@ class SystemInfoServiceImpl implements SystemInfoService {
log.error("Client UI JavaScript error: User-Agent=" + ua + ": " + message); log.error("Client UI JavaScript error: User-Agent=" + ua + ": " + message);
callback.onSuccess(VoidResult.INSTANCE); callback.onSuccess(VoidResult.INSTANCE);
} }
@Override
public void gerritConfig(final AsyncCallback<GerritConfig> callback) {
callback.onSuccess(config.get());
}
} }