Convert remaining uses of MetaDataUpdate to try-with-resource
These were not causing a "should be managed in try-with-resource" warning from Eclipse, and were found by manual inspection. Change-Id: I30c09f329c458117ece5878eeaba9c905eee06b2
This commit is contained in:
@@ -114,68 +114,69 @@ public class AllProjectsCreator {
|
||||
|
||||
private void initAllProjects(Repository git)
|
||||
throws IOException, ConfigInvalidException {
|
||||
MetaDataUpdate md = new MetaDataUpdate(
|
||||
GitReferenceUpdated.DISABLED,
|
||||
allProjectsName,
|
||||
git);
|
||||
md.getCommitBuilder().setAuthor(serverUser);
|
||||
md.getCommitBuilder().setCommitter(serverUser);
|
||||
md.setMessage(MoreObjects.firstNonNull(
|
||||
Strings.emptyToNull(message),
|
||||
"Initialized Gerrit Code Review " + Version.getVersion()));
|
||||
try (MetaDataUpdate md = new MetaDataUpdate(
|
||||
GitReferenceUpdated.DISABLED,
|
||||
allProjectsName,
|
||||
git)) {
|
||||
md.getCommitBuilder().setAuthor(serverUser);
|
||||
md.getCommitBuilder().setCommitter(serverUser);
|
||||
md.setMessage(MoreObjects.firstNonNull(
|
||||
Strings.emptyToNull(message),
|
||||
"Initialized Gerrit Code Review " + Version.getVersion()));
|
||||
|
||||
ProjectConfig config = ProjectConfig.read(md);
|
||||
Project p = config.getProject();
|
||||
p.setDescription("Access inherited by all other projects.");
|
||||
p.setRequireChangeID(InheritableBoolean.TRUE);
|
||||
p.setUseContentMerge(InheritableBoolean.TRUE);
|
||||
p.setUseContributorAgreements(InheritableBoolean.FALSE);
|
||||
p.setUseSignedOffBy(InheritableBoolean.FALSE);
|
||||
p.setEnableSignedPush(InheritableBoolean.FALSE);
|
||||
ProjectConfig config = ProjectConfig.read(md);
|
||||
Project p = config.getProject();
|
||||
p.setDescription("Access inherited by all other projects.");
|
||||
p.setRequireChangeID(InheritableBoolean.TRUE);
|
||||
p.setUseContentMerge(InheritableBoolean.TRUE);
|
||||
p.setUseContributorAgreements(InheritableBoolean.FALSE);
|
||||
p.setUseSignedOffBy(InheritableBoolean.FALSE);
|
||||
p.setEnableSignedPush(InheritableBoolean.FALSE);
|
||||
|
||||
AccessSection cap = config.getAccessSection(AccessSection.GLOBAL_CAPABILITIES, true);
|
||||
AccessSection all = config.getAccessSection(AccessSection.ALL, true);
|
||||
AccessSection heads = config.getAccessSection(AccessSection.HEADS, true);
|
||||
AccessSection tags = config.getAccessSection("refs/tags/*", true);
|
||||
AccessSection meta = config.getAccessSection(RefNames.REFS_CONFIG, true);
|
||||
AccessSection magic = config.getAccessSection("refs/for/" + AccessSection.ALL, true);
|
||||
AccessSection cap = config.getAccessSection(AccessSection.GLOBAL_CAPABILITIES, true);
|
||||
AccessSection all = config.getAccessSection(AccessSection.ALL, true);
|
||||
AccessSection heads = config.getAccessSection(AccessSection.HEADS, true);
|
||||
AccessSection tags = config.getAccessSection("refs/tags/*", true);
|
||||
AccessSection meta = config.getAccessSection(RefNames.REFS_CONFIG, true);
|
||||
AccessSection magic = config.getAccessSection("refs/for/" + AccessSection.ALL, true);
|
||||
|
||||
grant(config, cap, GlobalCapability.ADMINISTRATE_SERVER, admin);
|
||||
grant(config, all, Permission.READ, admin, anonymous);
|
||||
grant(config, cap, GlobalCapability.ADMINISTRATE_SERVER, admin);
|
||||
grant(config, all, Permission.READ, admin, anonymous);
|
||||
|
||||
if (batch != null) {
|
||||
Permission priority = cap.getPermission(GlobalCapability.PRIORITY, true);
|
||||
PermissionRule r = rule(config, batch);
|
||||
r.setAction(Action.BATCH);
|
||||
priority.add(r);
|
||||
if (batch != null) {
|
||||
Permission priority = cap.getPermission(GlobalCapability.PRIORITY, true);
|
||||
PermissionRule r = rule(config, batch);
|
||||
r.setAction(Action.BATCH);
|
||||
priority.add(r);
|
||||
|
||||
Permission stream = cap.getPermission(GlobalCapability.STREAM_EVENTS, true);
|
||||
stream.add(rule(config, batch));
|
||||
Permission stream = cap.getPermission(GlobalCapability.STREAM_EVENTS, true);
|
||||
stream.add(rule(config, batch));
|
||||
}
|
||||
|
||||
LabelType cr = initCodeReviewLabel(config);
|
||||
grant(config, heads, cr, -1, 1, registered);
|
||||
grant(config, heads, cr, -2, 2, admin, owners);
|
||||
grant(config, heads, Permission.CREATE, admin, owners);
|
||||
grant(config, heads, Permission.PUSH, admin, owners);
|
||||
grant(config, heads, Permission.SUBMIT, admin, owners);
|
||||
grant(config, heads, Permission.FORGE_AUTHOR, registered);
|
||||
grant(config, heads, Permission.FORGE_COMMITTER, admin, owners);
|
||||
grant(config, heads, Permission.EDIT_TOPIC_NAME, true, admin, owners);
|
||||
|
||||
grant(config, tags, Permission.PUSH_TAG, admin, owners);
|
||||
grant(config, tags, Permission.PUSH_SIGNED_TAG, admin, owners);
|
||||
|
||||
grant(config, magic, Permission.PUSH, registered);
|
||||
grant(config, magic, Permission.PUSH_MERGE, registered);
|
||||
|
||||
meta.getPermission(Permission.READ, true).setExclusiveGroup(true);
|
||||
grant(config, meta, Permission.READ, admin, owners);
|
||||
grant(config, meta, cr, -2, 2, admin, owners);
|
||||
grant(config, meta, Permission.PUSH, admin, owners);
|
||||
grant(config, meta, Permission.SUBMIT, admin, owners);
|
||||
|
||||
config.commitToNewRef(md, RefNames.REFS_CONFIG);
|
||||
}
|
||||
|
||||
LabelType cr = initCodeReviewLabel(config);
|
||||
grant(config, heads, cr, -1, 1, registered);
|
||||
grant(config, heads, cr, -2, 2, admin, owners);
|
||||
grant(config, heads, Permission.CREATE, admin, owners);
|
||||
grant(config, heads, Permission.PUSH, admin, owners);
|
||||
grant(config, heads, Permission.SUBMIT, admin, owners);
|
||||
grant(config, heads, Permission.FORGE_AUTHOR, registered);
|
||||
grant(config, heads, Permission.FORGE_COMMITTER, admin, owners);
|
||||
grant(config, heads, Permission.EDIT_TOPIC_NAME, true, admin, owners);
|
||||
|
||||
grant(config, tags, Permission.PUSH_TAG, admin, owners);
|
||||
grant(config, tags, Permission.PUSH_SIGNED_TAG, admin, owners);
|
||||
|
||||
grant(config, magic, Permission.PUSH, registered);
|
||||
grant(config, magic, Permission.PUSH_MERGE, registered);
|
||||
|
||||
meta.getPermission(Permission.READ, true).setExclusiveGroup(true);
|
||||
grant(config, meta, Permission.READ, admin, owners);
|
||||
grant(config, meta, cr, -2, 2, admin, owners);
|
||||
grant(config, meta, Permission.PUSH, admin, owners);
|
||||
grant(config, meta, Permission.SUBMIT, admin, owners);
|
||||
|
||||
config.commitToNewRef(md, RefNames.REFS_CONFIG);
|
||||
}
|
||||
|
||||
public static LabelType initCodeReviewLabel(ProjectConfig c) {
|
||||
|
@@ -75,29 +75,30 @@ public class AllUsersCreator {
|
||||
|
||||
private void initAllUsers(Repository git)
|
||||
throws IOException, ConfigInvalidException {
|
||||
MetaDataUpdate md = new MetaDataUpdate(
|
||||
GitReferenceUpdated.DISABLED,
|
||||
allUsersName,
|
||||
git);
|
||||
md.getCommitBuilder().setAuthor(serverUser);
|
||||
md.getCommitBuilder().setCommitter(serverUser);
|
||||
md.setMessage("Initialized Gerrit Code Review " + Version.getVersion());
|
||||
try (MetaDataUpdate md = new MetaDataUpdate(
|
||||
GitReferenceUpdated.DISABLED,
|
||||
allUsersName,
|
||||
git)) {
|
||||
md.getCommitBuilder().setAuthor(serverUser);
|
||||
md.getCommitBuilder().setCommitter(serverUser);
|
||||
md.setMessage("Initialized Gerrit Code Review " + Version.getVersion());
|
||||
|
||||
ProjectConfig config = ProjectConfig.read(md);
|
||||
Project project = config.getProject();
|
||||
project.setDescription("Individual user settings and preferences.");
|
||||
ProjectConfig config = ProjectConfig.read(md);
|
||||
Project project = config.getProject();
|
||||
project.setDescription("Individual user settings and preferences.");
|
||||
|
||||
AccessSection all = config.getAccessSection(RefNames.REFS_USERS + "*", true);
|
||||
all.getPermission(Permission.READ, true).setExclusiveGroup(true);
|
||||
AccessSection all = config.getAccessSection(RefNames.REFS_USERS + "*", true);
|
||||
all.getPermission(Permission.READ, true).setExclusiveGroup(true);
|
||||
|
||||
AccessSection defaults = config.getAccessSection(RefNames.REFS_USERS_DEFAULT, true);
|
||||
defaults.getPermission(Permission.READ, true).setExclusiveGroup(true);
|
||||
grant(config, defaults, Permission.READ, admin);
|
||||
defaults.getPermission(Permission.PUSH, true).setExclusiveGroup(true);
|
||||
grant(config, defaults, Permission.PUSH, admin);
|
||||
defaults.getPermission(Permission.CREATE, true).setExclusiveGroup(true);
|
||||
grant(config, defaults, Permission.CREATE, admin);
|
||||
AccessSection defaults = config.getAccessSection(RefNames.REFS_USERS_DEFAULT, true);
|
||||
defaults.getPermission(Permission.READ, true).setExclusiveGroup(true);
|
||||
grant(config, defaults, Permission.READ, admin);
|
||||
defaults.getPermission(Permission.PUSH, true).setExclusiveGroup(true);
|
||||
grant(config, defaults, Permission.PUSH, admin);
|
||||
defaults.getPermission(Permission.CREATE, true).setExclusiveGroup(true);
|
||||
grant(config, defaults, Permission.CREATE, admin);
|
||||
|
||||
config.commit(md);
|
||||
config.commit(md);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user