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:
@@ -519,20 +519,22 @@ public abstract class AbstractDaemonTest {
|
||||
|
||||
protected void setUseContributorAgreements(InheritableBoolean value)
|
||||
throws Exception {
|
||||
MetaDataUpdate md = metaDataUpdateFactory.create(project);
|
||||
ProjectConfig config = ProjectConfig.read(md);
|
||||
config.getProject().setUseContributorAgreements(value);
|
||||
config.commit(md);
|
||||
projectCache.evict(config.getProject());
|
||||
try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
|
||||
ProjectConfig config = ProjectConfig.read(md);
|
||||
config.getProject().setUseContributorAgreements(value);
|
||||
config.commit(md);
|
||||
projectCache.evict(config.getProject());
|
||||
}
|
||||
}
|
||||
|
||||
protected void setUseSignedOffBy(InheritableBoolean value)
|
||||
throws Exception {
|
||||
MetaDataUpdate md = metaDataUpdateFactory.create(project);
|
||||
ProjectConfig config = ProjectConfig.read(md);
|
||||
config.getProject().setUseSignedOffBy(value);
|
||||
config.commit(md);
|
||||
projectCache.evict(config.getProject());
|
||||
try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
|
||||
ProjectConfig config = ProjectConfig.read(md);
|
||||
config.getProject().setUseSignedOffBy(value);
|
||||
config.commit(md);
|
||||
projectCache.evict(config.getProject());
|
||||
}
|
||||
}
|
||||
|
||||
protected void deny(String permission, AccountGroup.UUID id, String ref)
|
||||
@@ -566,17 +568,18 @@ public abstract class AbstractDaemonTest {
|
||||
protected void grant(String permission, Project.NameKey project, String ref,
|
||||
boolean force) throws RepositoryNotFoundException, IOException,
|
||||
ConfigInvalidException {
|
||||
MetaDataUpdate md = metaDataUpdateFactory.create(project);
|
||||
md.setMessage(String.format("Grant %s on %s", permission, ref));
|
||||
ProjectConfig config = ProjectConfig.read(md);
|
||||
AccessSection s = config.getAccessSection(ref, true);
|
||||
Permission p = s.getPermission(permission, true);
|
||||
AccountGroup adminGroup = groupCache.get(new AccountGroup.NameKey("Administrators"));
|
||||
PermissionRule rule = new PermissionRule(config.resolve(adminGroup));
|
||||
rule.setForce(force);
|
||||
p.add(rule);
|
||||
config.commit(md);
|
||||
projectCache.evict(config.getProject());
|
||||
try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
|
||||
md.setMessage(String.format("Grant %s on %s", permission, ref));
|
||||
ProjectConfig config = ProjectConfig.read(md);
|
||||
AccessSection s = config.getAccessSection(ref, true);
|
||||
Permission p = s.getPermission(permission, true);
|
||||
AccountGroup adminGroup = groupCache.get(new AccountGroup.NameKey("Administrators"));
|
||||
PermissionRule rule = new PermissionRule(config.resolve(adminGroup));
|
||||
rule.setForce(force);
|
||||
p.add(rule);
|
||||
config.commit(md);
|
||||
projectCache.evict(config.getProject());
|
||||
}
|
||||
}
|
||||
|
||||
protected void blockRead(String ref) throws Exception {
|
||||
|
@@ -30,12 +30,9 @@ import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.gerrit.server.group.SystemGroupBackend;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ChangeOwnerIT extends AbstractDaemonTest {
|
||||
|
||||
private TestAccount user2;
|
||||
@@ -80,20 +77,20 @@ public class ChangeOwnerIT extends AbstractDaemonTest {
|
||||
approve(a, changeId);
|
||||
}
|
||||
|
||||
private void grantApproveToChangeOwner() throws IOException,
|
||||
ConfigInvalidException {
|
||||
MetaDataUpdate md = metaDataUpdateFactory.create(project);
|
||||
md.setMessage(String.format("Grant approve to change owner"));
|
||||
ProjectConfig config = ProjectConfig.read(md);
|
||||
AccessSection s = config.getAccessSection("refs/heads/*", true);
|
||||
Permission p = s.getPermission(LABEL + "Code-Review", true);
|
||||
PermissionRule rule = new PermissionRule(config
|
||||
.resolve(SystemGroupBackend.getGroup(SystemGroupBackend.CHANGE_OWNER)));
|
||||
rule.setMin(-2);
|
||||
rule.setMax(+2);
|
||||
p.add(rule);
|
||||
config.commit(md);
|
||||
projectCache.evict(config.getProject());
|
||||
private void grantApproveToChangeOwner() throws Exception {
|
||||
try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
|
||||
md.setMessage(String.format("Grant approve to change owner"));
|
||||
ProjectConfig config = ProjectConfig.read(md);
|
||||
AccessSection s = config.getAccessSection("refs/heads/*", true);
|
||||
Permission p = s.getPermission(LABEL + "Code-Review", true);
|
||||
PermissionRule rule = new PermissionRule(config
|
||||
.resolve(SystemGroupBackend.getGroup(SystemGroupBackend.CHANGE_OWNER)));
|
||||
rule.setMin(-2);
|
||||
rule.setMax(+2);
|
||||
p.add(rule);
|
||||
config.commit(md);
|
||||
projectCache.evict(config.getProject());
|
||||
}
|
||||
}
|
||||
|
||||
private String createMyChange() throws Exception {
|
||||
|
@@ -117,12 +117,13 @@ public abstract class AbstractChangeUpdate extends VersionedMetaData {
|
||||
throws IOException {
|
||||
if (migration.writeChanges()) {
|
||||
load();
|
||||
MetaDataUpdate md =
|
||||
updateFactory.create(getProjectName(),
|
||||
repoManager.openMetadataRepository(getProjectName()), getUser(),
|
||||
bru);
|
||||
md.setAllowEmpty(true);
|
||||
return super.openUpdate(md);
|
||||
try (MetaDataUpdate md =
|
||||
updateFactory.create(getProjectName(),
|
||||
repoManager.openMetadataRepository(getProjectName()), getUser(),
|
||||
bru)) {
|
||||
md.setAllowEmpty(true);
|
||||
return super.openUpdate(md);
|
||||
}
|
||||
}
|
||||
return new BatchMetaDataUpdate() {
|
||||
@Override
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -196,10 +196,11 @@ public class LabelNormalizerTest {
|
||||
}
|
||||
|
||||
private void save(ProjectConfig pc) throws Exception {
|
||||
MetaDataUpdate md =
|
||||
metaDataUpdateFactory.create(pc.getProject().getNameKey(), user);
|
||||
pc.commit(md);
|
||||
projectCache.evict(pc.getProject().getNameKey());
|
||||
try(MetaDataUpdate md =
|
||||
metaDataUpdateFactory.create(pc.getProject().getNameKey(), user)) {
|
||||
pc.commit(md);
|
||||
projectCache.evict(pc.getProject().getNameKey());
|
||||
}
|
||||
}
|
||||
|
||||
private PatchSetApproval psa(Account.Id accountId, String label, int value) {
|
||||
|
@@ -249,17 +249,18 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
|
||||
private RevCommit commit(ProjectConfig cfg) throws IOException,
|
||||
MissingObjectException, IncorrectObjectTypeException {
|
||||
MetaDataUpdate md = new MetaDataUpdate(
|
||||
GitReferenceUpdated.DISABLED,
|
||||
cfg.getProject().getNameKey(),
|
||||
db);
|
||||
util.tick(5);
|
||||
util.setAuthorAndCommitter(md.getCommitBuilder());
|
||||
md.setMessage("Edit\n");
|
||||
cfg.commit(md);
|
||||
try (MetaDataUpdate md = new MetaDataUpdate(
|
||||
GitReferenceUpdated.DISABLED,
|
||||
cfg.getProject().getNameKey(),
|
||||
db)) {
|
||||
util.tick(5);
|
||||
util.setAuthorAndCommitter(md.getCommitBuilder());
|
||||
md.setMessage("Edit\n");
|
||||
cfg.commit(md);
|
||||
|
||||
Ref ref = db.getRef(RefNames.REFS_CONFIG);
|
||||
return util.getRevWalk().parseCommit(ref.getObjectId());
|
||||
Ref ref = db.getRef(RefNames.REFS_CONFIG);
|
||||
return util.getRevWalk().parseCommit(ref.getObjectId());
|
||||
}
|
||||
}
|
||||
|
||||
private void update(RevCommit rev) throws Exception {
|
||||
|
Reference in New Issue
Block a user