Move the GerritConfig to the new Common class
Like the current user's Account.Id having fast access to the (relatively) static GerritConfig is useful in both client and server side code. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -17,6 +17,7 @@ package com.google.gerrit.client;
|
||||
import com.google.gerrit.client.data.GerritConfig;
|
||||
import com.google.gerrit.client.data.SystemInfoService;
|
||||
import com.google.gerrit.client.reviewdb.Account;
|
||||
import com.google.gerrit.client.rpc.Common;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.ui.LinkMenuBar;
|
||||
import com.google.gerrit.client.ui.LinkMenuItem;
|
||||
@@ -54,7 +55,6 @@ public class Gerrit implements EntryPoint {
|
||||
public static final GerritIcons ICONS = GWT.create(GerritIcons.class);
|
||||
public static final SystemInfoService SYSTEM_SVC;
|
||||
|
||||
private static GerritConfig config;
|
||||
private static Account myAccount;
|
||||
private static final ArrayList<SignedInListener> signedInListeners =
|
||||
new ArrayList<SignedInListener>();
|
||||
@@ -101,11 +101,6 @@ public class Gerrit implements EntryPoint {
|
||||
body.add(currentScreen);
|
||||
}
|
||||
|
||||
/** Get the public configuration data used by this Gerrit server. */
|
||||
public static GerritConfig getGerritConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
/** @return the currently signed in user's account data; null if no account */
|
||||
public static Account getUserAccount() {
|
||||
return myAccount;
|
||||
@@ -170,7 +165,7 @@ public class Gerrit implements EntryPoint {
|
||||
JsonUtil.addRpcStatusListener(new RpcStatus(topMenu));
|
||||
SYSTEM_SVC.loadGerritConfig(new GerritCallback<GerritConfig>() {
|
||||
public void onSuccess(final GerritConfig result) {
|
||||
config = result;
|
||||
Common.setGerritConfig(result);
|
||||
onModuleLoad2();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.client.admin;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.data.ApprovalType;
|
||||
import com.google.gerrit.client.data.GerritConfig;
|
||||
import com.google.gerrit.client.reviewdb.AccountGroup;
|
||||
@@ -22,6 +21,7 @@ import com.google.gerrit.client.reviewdb.ApprovalCategory;
|
||||
import com.google.gerrit.client.reviewdb.ApprovalCategoryValue;
|
||||
import com.google.gerrit.client.reviewdb.Project;
|
||||
import com.google.gerrit.client.reviewdb.ProjectRight;
|
||||
import com.google.gerrit.client.rpc.Common;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.ui.AccountGroupSuggestOracle;
|
||||
import com.google.gerrit.client.ui.AccountScreen;
|
||||
@@ -193,11 +193,11 @@ public class ProjectAdminScreen extends AccountScreen {
|
||||
populateRangeBoxes();
|
||||
}
|
||||
});
|
||||
for (final ApprovalType at : Gerrit.getGerritConfig().getApprovalTypes()) {
|
||||
for (final ApprovalType at : Common.getGerritConfig().getApprovalTypes()) {
|
||||
final ApprovalCategory c = at.getCategory();
|
||||
catBox.addItem(c.getName(), c.getId().get());
|
||||
}
|
||||
for (final ApprovalType at : Gerrit.getGerritConfig().getActionTypes()) {
|
||||
for (final ApprovalType at : Common.getGerritConfig().getActionTypes()) {
|
||||
final ApprovalCategory c = at.getCategory();
|
||||
catBox.addItem(c.getName(), c.getId().get());
|
||||
}
|
||||
@@ -285,7 +285,7 @@ public class ProjectAdminScreen extends AccountScreen {
|
||||
return;
|
||||
}
|
||||
at =
|
||||
Gerrit.getGerritConfig().getApprovalType(
|
||||
Common.getGerritConfig().getApprovalType(
|
||||
new ApprovalCategory.Id(catBox.getValue(idx)));
|
||||
if (at == null) {
|
||||
return;
|
||||
@@ -337,7 +337,7 @@ public class ProjectAdminScreen extends AccountScreen {
|
||||
final ApprovalType at;
|
||||
if (idx >= 0) {
|
||||
at =
|
||||
Gerrit.getGerritConfig().getApprovalType(
|
||||
Common.getGerritConfig().getApprovalType(
|
||||
new ApprovalCategory.Id(catBox.getValue(idx)));
|
||||
} else {
|
||||
at = null;
|
||||
@@ -450,7 +450,7 @@ public class ProjectAdminScreen extends AccountScreen {
|
||||
|
||||
void populate(final int row,
|
||||
final Map<AccountGroup.Id, AccountGroup> groups, final ProjectRight k) {
|
||||
final GerritConfig config = Gerrit.getGerritConfig();
|
||||
final GerritConfig config = Common.getGerritConfig();
|
||||
final ApprovalType ar = config.getApprovalType(k.getApprovalCategoryId());
|
||||
final AccountGroup group = groups.get(k.getAccountGroupId());
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.google.gerrit.client.reviewdb.Account;
|
||||
import com.google.gerrit.client.reviewdb.ApprovalCategory;
|
||||
import com.google.gerrit.client.reviewdb.ApprovalCategoryValue;
|
||||
import com.google.gerrit.client.reviewdb.ChangeApproval;
|
||||
import com.google.gerrit.client.rpc.Common;
|
||||
import com.google.gerrit.client.ui.AccountDashboardLink;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
@@ -43,7 +44,7 @@ public class ApprovalTable extends Composite {
|
||||
|
||||
public ApprovalTable() {
|
||||
|
||||
types = Gerrit.getGerritConfig().getApprovalTypes();
|
||||
types = Common.getGerritConfig().getApprovalTypes();
|
||||
table = new Grid(1, 3 + types.size());
|
||||
table.addStyleName("gerrit-InfoTable");
|
||||
displayHeader();
|
||||
|
||||
@@ -16,13 +16,13 @@ package com.google.gerrit.client.changes;
|
||||
|
||||
import com.google.gerrit.client.data.AccountInfoCacheFactory;
|
||||
import com.google.gerrit.client.data.ChangeDetail;
|
||||
import com.google.gerrit.client.data.GerritConfig;
|
||||
import com.google.gerrit.client.data.GroupCache;
|
||||
import com.google.gerrit.client.data.PatchSetDetail;
|
||||
import com.google.gerrit.client.reviewdb.Change;
|
||||
import com.google.gerrit.client.reviewdb.PatchSet;
|
||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.client.rpc.BaseServiceImplementation;
|
||||
import com.google.gerrit.client.rpc.Common;
|
||||
import com.google.gerrit.client.rpc.NoSuchEntityException;
|
||||
import com.google.gerrit.client.workflow.RightRule;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
@@ -32,13 +32,11 @@ import com.google.gwtorm.client.SchemaFactory;
|
||||
public class ChangeDetailServiceImpl extends BaseServiceImplementation
|
||||
implements ChangeDetailService {
|
||||
private final GroupCache groupCache;
|
||||
private final GerritConfig config;
|
||||
|
||||
public ChangeDetailServiceImpl(final SchemaFactory<ReviewDb> rdf,
|
||||
final GroupCache groups, final GerritConfig c) {
|
||||
final GroupCache groups) {
|
||||
super(rdf);
|
||||
groupCache = groups;
|
||||
config = c;
|
||||
}
|
||||
|
||||
public void changeDetail(final Change.Id id,
|
||||
@@ -50,7 +48,8 @@ public class ChangeDetailServiceImpl extends BaseServiceImplementation
|
||||
throw new Failure(new NoSuchEntityException());
|
||||
}
|
||||
|
||||
final RightRule rules = new RightRule(config, groupCache, db);
|
||||
final RightRule rules =
|
||||
new RightRule(Common.getGerritConfig(), groupCache, db);
|
||||
final ChangeDetail d = new ChangeDetail();
|
||||
d.load(db, new AccountInfoCacheFactory(db), rules, change);
|
||||
return d;
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.client.changes;
|
||||
|
||||
import com.google.gerrit.client.FormatUtil;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.data.AccountInfoCache;
|
||||
import com.google.gerrit.client.data.ChangeDetail;
|
||||
import com.google.gerrit.client.data.ChangeInfo;
|
||||
@@ -23,6 +22,7 @@ import com.google.gerrit.client.data.GitwebLink;
|
||||
import com.google.gerrit.client.reviewdb.Change;
|
||||
import com.google.gerrit.client.reviewdb.ChangeMessage;
|
||||
import com.google.gerrit.client.reviewdb.PatchSet;
|
||||
import com.google.gerrit.client.rpc.Common;
|
||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
||||
import com.google.gerrit.client.ui.ComplexDisclosurePanel;
|
||||
import com.google.gerrit.client.ui.ExpandAllCommand;
|
||||
@@ -213,7 +213,7 @@ public class ChangeScreen extends Screen {
|
||||
patchSetPanels.clear();
|
||||
|
||||
final PatchSet currps = detail.getCurrentPatchSet();
|
||||
final GitwebLink gw = Gerrit.getGerritConfig().getGitwebLink();
|
||||
final GitwebLink gw = Common.getGerritConfig().getGitwebLink();
|
||||
for (final PatchSet ps : detail.getPatchSets()) {
|
||||
final ComplexDisclosurePanel panel =
|
||||
new ComplexDisclosurePanel(Util.M.patchSetHeader(ps.getPatchSetId()),
|
||||
|
||||
@@ -15,11 +15,13 @@
|
||||
package com.google.gerrit.client.rpc;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.data.GerritConfig;
|
||||
import com.google.gerrit.client.reviewdb.Account;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
|
||||
public class Common {
|
||||
public static final RpcConstants C;
|
||||
private static GerritConfig config;
|
||||
private static CurrentAccountImpl caImpl;
|
||||
|
||||
static {
|
||||
@@ -36,6 +38,15 @@ public class Common {
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the public configuration data used by this Gerrit instance. */
|
||||
public static GerritConfig getGerritConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public static void setGerritConfig(final GerritConfig imp) {
|
||||
config = imp;
|
||||
}
|
||||
|
||||
/** Get the unique id for this account; null if there is no account. */
|
||||
public static Account.Id getAccountId() {
|
||||
return caImpl.getAccountId();
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.server;
|
||||
|
||||
import com.google.gerrit.client.changes.ChangeDetailServiceImpl;
|
||||
import com.google.gerrit.client.data.GerritConfig;
|
||||
import com.google.gerrit.client.data.GroupCache;
|
||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
@@ -27,7 +26,6 @@ public class ChangeDetailServiceSrv extends GerritJsonServlet {
|
||||
final GerritServer gs = GerritServer.getInstance();
|
||||
final SchemaFactory<ReviewDb> rdf = gs.getDatabase();
|
||||
final GroupCache groups = gs.getGroupCache();
|
||||
final GerritConfig config = gs.getGerritConfig();
|
||||
return new ChangeDetailServiceImpl(rdf, groups, config);
|
||||
return new ChangeDetailServiceImpl(rdf, groups);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.google.gerrit.client.reviewdb.ApprovalCategoryValue;
|
||||
import com.google.gerrit.client.reviewdb.ProjectRight;
|
||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.client.reviewdb.SystemConfig;
|
||||
import com.google.gerrit.client.rpc.Common;
|
||||
import com.google.gerrit.git.RepositoryCache;
|
||||
import com.google.gwtjsonrpc.server.SignedToken;
|
||||
import com.google.gwtjsonrpc.server.XsrfException;
|
||||
@@ -77,7 +78,6 @@ public class GerritServer {
|
||||
|
||||
private final Database<ReviewDb> db;
|
||||
private SystemConfig sConfig;
|
||||
private GerritConfig gerritConfig;
|
||||
private final SignedToken xsrf;
|
||||
private final SignedToken account;
|
||||
private final RepositoryCache repositories;
|
||||
@@ -287,7 +287,7 @@ public class GerritServer {
|
||||
c.getId()).toList()));
|
||||
}
|
||||
|
||||
gerritConfig = r;
|
||||
Common.setGerritConfig(r);
|
||||
}
|
||||
|
||||
/** Get the {@link ReviewDb} schema factory for the server. */
|
||||
@@ -338,11 +338,6 @@ public class GerritServer {
|
||||
return u;
|
||||
}
|
||||
|
||||
/** Get the cached configuration data used by the client. */
|
||||
public GerritConfig getGerritConfig() {
|
||||
return gerritConfig;
|
||||
}
|
||||
|
||||
/** Get the repositories maintained by this server. */
|
||||
public RepositoryCache getRepositoryCache() {
|
||||
return repositories;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server;
|
||||
|
||||
import com.google.gerrit.client.rpc.Common;
|
||||
import com.google.gwt.user.server.rpc.RPCServletUtils;
|
||||
import com.google.gwtjsonrpc.server.XsrfException;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
@@ -66,7 +67,7 @@ public class HostPageServlet extends HttpServlet {
|
||||
if (hostDoc == null) {
|
||||
throw new ServletException("No " + hostPageName + " in CLASSPATH");
|
||||
}
|
||||
injectJson(hostDoc, "gerrit_gerritconfig", srv.getGerritConfig());
|
||||
injectJson(hostDoc, "gerrit_gerritconfig", Common.getGerritConfig());
|
||||
injectCssFile(hostDoc, "gerrit_sitecss", sitePath, "GerritSite.css");
|
||||
injectXmlFile(hostDoc, "gerrit_header", sitePath, "GerritSiteHeader.html");
|
||||
injectXmlFile(hostDoc, "gerrit_footer", sitePath, "GerritSiteFooter.html");
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.google.gerrit.client.data.GerritConfig;
|
||||
import com.google.gerrit.client.data.SystemInfoService;
|
||||
import com.google.gerrit.client.reviewdb.ContributorAgreement;
|
||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.client.rpc.Common;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
|
||||
@@ -31,7 +32,7 @@ public class SystemInfoServiceImpl implements SystemInfoService {
|
||||
}
|
||||
|
||||
public void loadGerritConfig(final AsyncCallback<GerritConfig> callback) {
|
||||
callback.onSuccess(server.getGerritConfig());
|
||||
callback.onSuccess(Common.getGerritConfig());
|
||||
}
|
||||
|
||||
public void contributorAgreements(
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.google.gerrit.client.reviewdb.ChangeApproval;
|
||||
import com.google.gerrit.client.reviewdb.ContactInformation;
|
||||
import com.google.gerrit.client.reviewdb.ContributorAgreement;
|
||||
import com.google.gerrit.client.reviewdb.PatchSet;
|
||||
import com.google.gerrit.client.rpc.Common;
|
||||
import com.google.gerrit.git.PatchSetImporter;
|
||||
import com.google.gerrit.server.GerritServer;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
@@ -466,7 +467,7 @@ class Receive extends AbstractGitCommand {
|
||||
change.setCurrentPatchSet(imp.getPatchSetInfo());
|
||||
db.changes().insert(Collections.singleton(change));
|
||||
|
||||
for (final ApprovalType t : server.getGerritConfig().getApprovalTypes()) {
|
||||
for (final ApprovalType t : Common.getGerritConfig().getApprovalTypes()) {
|
||||
final ApprovalCategoryValue v = t.getMax();
|
||||
if (v != null) {
|
||||
db.changeApprovals().insert(
|
||||
@@ -528,7 +529,7 @@ class Receive extends AbstractGitCommand {
|
||||
db.changeApprovals().update(Collections.singleton(a));
|
||||
}
|
||||
}
|
||||
for (final ApprovalType t : server.getGerritConfig().getApprovalTypes()) {
|
||||
for (final ApprovalType t : Common.getGerritConfig().getApprovalTypes()) {
|
||||
final ApprovalCategoryValue v = t.getMax();
|
||||
if (!have.contains(t.getCategory().getId()) && v != null) {
|
||||
db.changeApprovals().insert(
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.ssh;
|
||||
|
||||
import com.google.gerrit.client.rpc.Common;
|
||||
import com.google.gerrit.server.GerritServer;
|
||||
import com.google.gwtjsonrpc.server.XsrfException;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
@@ -67,7 +68,7 @@ public class SshServlet extends HttpServlet {
|
||||
throw new ServletException("Cannot load GerritServer", e);
|
||||
}
|
||||
|
||||
final int myPort = srv.getGerritConfig().getSshdPort();
|
||||
final int myPort = Common.getGerritConfig().getSshdPort();
|
||||
sshd = SshServer.setUpDefaultServer();
|
||||
sshd.setPort(myPort);
|
||||
sshd.setKeyPairProvider(new FileKeyPairProvider(new String[] {
|
||||
|
||||
Reference in New Issue
Block a user