Make MetaDataUpdate auto-closeable
And convert users to instantiate it in try-with-resource blocks. Change-Id: Ief1a42ccbf4b3d943a7987b2c9b8077175695515
This commit is contained in:
@@ -552,11 +552,8 @@ public abstract class AbstractDaemonTest {
|
|||||||
|
|
||||||
protected void saveProjectConfig(Project.NameKey p, ProjectConfig cfg)
|
protected void saveProjectConfig(Project.NameKey p, ProjectConfig cfg)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
MetaDataUpdate md = metaDataUpdateFactory.create(p);
|
try (MetaDataUpdate md = metaDataUpdateFactory.create(p)) {
|
||||||
try {
|
|
||||||
cfg.commit(md);
|
cfg.commit(md);
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
}
|
||||||
projectCache.evict(cfg.getProject());
|
projectCache.evict(cfg.getProject());
|
||||||
}
|
}
|
||||||
|
@@ -83,11 +83,8 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void saveProjectConfig(ProjectConfig cfg) throws Exception {
|
private void saveProjectConfig(ProjectConfig cfg) throws Exception {
|
||||||
MetaDataUpdate md = metaDataUpdateFactory.create(project);
|
try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
|
||||||
try {
|
|
||||||
cfg.commit(md);
|
cfg.commit(md);
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -321,11 +321,8 @@ public class LabelTypeIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void saveProjectConfig(ProjectConfig cfg) throws Exception {
|
private void saveProjectConfig(ProjectConfig cfg) throws Exception {
|
||||||
MetaDataUpdate md = metaDataUpdateFactory.create(project);
|
try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
|
||||||
try {
|
|
||||||
cfg.commit(md);
|
cfg.commit(md);
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -100,8 +100,7 @@ class ProjectAccessFactory extends Handler<ProjectAccess> {
|
|||||||
// state, force a cache flush now.
|
// state, force a cache flush now.
|
||||||
//
|
//
|
||||||
ProjectConfig config;
|
ProjectConfig config;
|
||||||
MetaDataUpdate md = metaDataUpdateFactory.create(projectName);
|
try (MetaDataUpdate md = metaDataUpdateFactory.create(projectName)) {
|
||||||
try {
|
|
||||||
config = ProjectConfig.read(md);
|
config = ProjectConfig.read(md);
|
||||||
|
|
||||||
if (config.updateGroupNames(groupBackend)) {
|
if (config.updateGroupNames(groupBackend)) {
|
||||||
@@ -115,8 +114,6 @@ class ProjectAccessFactory extends Handler<ProjectAccess> {
|
|||||||
projectCache.evict(config.getProject());
|
projectCache.evict(config.getProject());
|
||||||
pc = open();
|
pc = open();
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final RefControl metaConfigControl = pc.controlForRef(RefNames.REFS_CONFIG);
|
final RefControl metaConfigControl = pc.controlForRef(RefNames.REFS_CONFIG);
|
||||||
|
@@ -92,13 +92,7 @@ public abstract class ProjectAccessHandler<T> extends Handler<T> {
|
|||||||
final ProjectControl projectControl =
|
final ProjectControl projectControl =
|
||||||
projectControlFactory.controlFor(projectName);
|
projectControlFactory.controlFor(projectName);
|
||||||
|
|
||||||
final MetaDataUpdate md;
|
try (MetaDataUpdate md = metaDataUpdateFactory.create(projectName)) {
|
||||||
try {
|
|
||||||
md = metaDataUpdateFactory.create(projectName);
|
|
||||||
} catch (RepositoryNotFoundException notFound) {
|
|
||||||
throw new NoSuchProjectException(projectName);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ProjectConfig config = ProjectConfig.read(md, base);
|
ProjectConfig config = ProjectConfig.read(md, base);
|
||||||
Set<String> toDelete = scanSectionNames(config);
|
Set<String> toDelete = scanSectionNames(config);
|
||||||
|
|
||||||
@@ -163,8 +157,8 @@ public abstract class ProjectAccessHandler<T> extends Handler<T> {
|
|||||||
|
|
||||||
return updateProjectConfig(projectControl, config, md,
|
return updateProjectConfig(projectControl, config, md,
|
||||||
parentProjectUpdate);
|
parentProjectUpdate);
|
||||||
} finally {
|
} catch (RepositoryNotFoundException notFound) {
|
||||||
md.close();
|
throw new NoSuchProjectException(projectName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -93,40 +93,32 @@ public class ListAccess implements RestReadView<TopLevelResource> {
|
|||||||
throws ResourceNotFoundException, ResourceConflictException, IOException {
|
throws ResourceNotFoundException, ResourceConflictException, IOException {
|
||||||
Map<String, ProjectAccessInfo> access = Maps.newTreeMap();
|
Map<String, ProjectAccessInfo> access = Maps.newTreeMap();
|
||||||
for (String p: projects) {
|
for (String p: projects) {
|
||||||
|
// Load the current configuration from the repository, ensuring it's the most
|
||||||
|
// recent version available. If it differs from what was in the project
|
||||||
|
// state, force a cache flush now.
|
||||||
|
//
|
||||||
Project.NameKey projectName = new Project.NameKey(p);
|
Project.NameKey projectName = new Project.NameKey(p);
|
||||||
ProjectControl pc = open(projectName);
|
try (MetaDataUpdate md = metaDataUpdateFactory.create(projectName)) {
|
||||||
ProjectConfig config;
|
ProjectControl pc = open(projectName);
|
||||||
|
ProjectConfig config = ProjectConfig.read(md);
|
||||||
|
|
||||||
try {
|
if (config.updateGroupNames(groupBackend)) {
|
||||||
// Load the current configuration from the repository, ensuring it's the most
|
md.setMessage("Update group names\n");
|
||||||
// recent version available. If it differs from what was in the project
|
config.commit(md);
|
||||||
// state, force a cache flush now.
|
projectCache.evict(config.getProject());
|
||||||
//
|
pc = open(projectName);
|
||||||
MetaDataUpdate md = metaDataUpdateFactory.create(projectName);
|
} else if (config.getRevision() != null
|
||||||
try {
|
&& !config.getRevision().equals(
|
||||||
config = ProjectConfig.read(md);
|
pc.getProjectState().getConfig().getRevision())) {
|
||||||
|
projectCache.evict(config.getProject());
|
||||||
if (config.updateGroupNames(groupBackend)) {
|
pc = open(projectName);
|
||||||
md.setMessage("Update group names\n");
|
|
||||||
config.commit(md);
|
|
||||||
projectCache.evict(config.getProject());
|
|
||||||
pc = open(projectName);
|
|
||||||
} else if (config.getRevision() != null
|
|
||||||
&& !config.getRevision().equals(
|
|
||||||
pc.getProjectState().getConfig().getRevision())) {
|
|
||||||
projectCache.evict(config.getProject());
|
|
||||||
pc = open(projectName);
|
|
||||||
}
|
|
||||||
} catch (ConfigInvalidException e) {
|
|
||||||
throw new ResourceConflictException(e.getMessage());
|
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
}
|
||||||
|
access.put(p, new ProjectAccessInfo(pc, config));
|
||||||
|
} catch (ConfigInvalidException e) {
|
||||||
|
throw new ResourceConflictException(e.getMessage());
|
||||||
} catch (RepositoryNotFoundException e) {
|
} catch (RepositoryNotFoundException e) {
|
||||||
throw new ResourceNotFoundException(p);
|
throw new ResourceNotFoundException(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
access.put(p, new ProjectAccessInfo(pc, config));
|
|
||||||
}
|
}
|
||||||
return access;
|
return access;
|
||||||
}
|
}
|
||||||
|
@@ -77,10 +77,8 @@ public class SetDiffPreferences implements
|
|||||||
private DiffPreferencesInfo writeToGit(DiffPreferencesInfo in,
|
private DiffPreferencesInfo writeToGit(DiffPreferencesInfo in,
|
||||||
Account.Id userId) throws RepositoryNotFoundException, IOException,
|
Account.Id userId) throws RepositoryNotFoundException, IOException,
|
||||||
ConfigInvalidException {
|
ConfigInvalidException {
|
||||||
MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName);
|
|
||||||
|
|
||||||
DiffPreferencesInfo out = new DiffPreferencesInfo();
|
DiffPreferencesInfo out = new DiffPreferencesInfo();
|
||||||
try {
|
try (MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName)) {
|
||||||
VersionedAccountPreferences prefs = VersionedAccountPreferences.forUser(
|
VersionedAccountPreferences prefs = VersionedAccountPreferences.forUser(
|
||||||
userId);
|
userId);
|
||||||
prefs.load(md);
|
prefs.load(md);
|
||||||
@@ -90,8 +88,6 @@ public class SetDiffPreferences implements
|
|||||||
prefs.commit(md);
|
prefs.commit(md);
|
||||||
loadSection(prefs.getConfig(), UserConfigSections.DIFF, null, out,
|
loadSection(prefs.getConfig(), UserConfigSections.DIFF, null, out,
|
||||||
DiffPreferencesInfo.defaults(), null);
|
DiffPreferencesInfo.defaults(), null);
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@@ -71,18 +71,15 @@ public class SetEditPreferences implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
Account.Id accountId = rsrc.getUser().getAccountId();
|
Account.Id accountId = rsrc.getUser().getAccountId();
|
||||||
MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName);
|
|
||||||
|
|
||||||
VersionedAccountPreferences prefs;
|
VersionedAccountPreferences prefs;
|
||||||
try {
|
try (MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName)) {
|
||||||
prefs = VersionedAccountPreferences.forUser(accountId);
|
prefs = VersionedAccountPreferences.forUser(accountId);
|
||||||
prefs.load(md);
|
prefs.load(md);
|
||||||
storeSection(prefs.getConfig(), UserConfigSections.EDIT, null,
|
storeSection(prefs.getConfig(), UserConfigSections.EDIT, null,
|
||||||
readFromGit(accountId, gitMgr, allUsersName, in),
|
readFromGit(accountId, gitMgr, allUsersName, in),
|
||||||
EditPreferencesInfo.defaults());
|
EditPreferencesInfo.defaults());
|
||||||
prefs.commit(md);
|
prefs.commit(md);
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response.none();
|
return Response.none();
|
||||||
|
@@ -115,9 +115,8 @@ public class SetPreferences implements RestModifyView<AccountResource, Input> {
|
|||||||
Account.Id accountId = rsrc.getUser().getAccountId();
|
Account.Id accountId = rsrc.getUser().getAccountId();
|
||||||
AccountGeneralPreferences p;
|
AccountGeneralPreferences p;
|
||||||
VersionedAccountPreferences versionedPrefs;
|
VersionedAccountPreferences versionedPrefs;
|
||||||
MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName);
|
|
||||||
db.get().accounts().beginTransaction(accountId);
|
db.get().accounts().beginTransaction(accountId);
|
||||||
try {
|
try (MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName)) {
|
||||||
Account a = db.get().accounts().get(accountId);
|
Account a = db.get().accounts().get(accountId);
|
||||||
if (a == null) {
|
if (a == null) {
|
||||||
throw new ResourceNotFoundException();
|
throw new ResourceNotFoundException();
|
||||||
@@ -184,7 +183,6 @@ public class SetPreferences implements RestModifyView<AccountResource, Input> {
|
|||||||
return new GetPreferences.PreferenceInfo(
|
return new GetPreferences.PreferenceInfo(
|
||||||
p, versionedPrefs, md.getRepository());
|
p, versionedPrefs, md.getRepository());
|
||||||
} finally {
|
} finally {
|
||||||
md.close();
|
|
||||||
db.get().rollback();
|
db.get().rollback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -60,15 +60,12 @@ public class SetPreferences implements RestModifyView<ConfigResource, Input> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VersionedAccountPreferences p;
|
VersionedAccountPreferences p;
|
||||||
MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName);
|
try (MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName)) {
|
||||||
try {
|
|
||||||
p = VersionedAccountPreferences.forDefault();
|
p = VersionedAccountPreferences.forDefault();
|
||||||
p.load(md);
|
p.load(md);
|
||||||
com.google.gerrit.server.account.SetPreferences.storeMyMenus(p, i.my);
|
com.google.gerrit.server.account.SetPreferences.storeMyMenus(p, i.my);
|
||||||
p.commit(md);
|
p.commit(md);
|
||||||
return new PreferenceInfo(null, p, md.getRepository());
|
return new PreferenceInfo(null, p, md.getRepository());
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,7 +34,7 @@ import org.eclipse.jgit.lib.Repository;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/** Helps with the updating of a {@link VersionedMetaData}. */
|
/** Helps with the updating of a {@link VersionedMetaData}. */
|
||||||
public class MetaDataUpdate {
|
public class MetaDataUpdate implements AutoCloseable {
|
||||||
public static class User {
|
public static class User {
|
||||||
private final InternalFactory factory;
|
private final InternalFactory factory;
|
||||||
private final GitRepositoryManager mgr;
|
private final GitRepositoryManager mgr;
|
||||||
@@ -191,6 +191,7 @@ public class MetaDataUpdate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Close the cached Repository handle. */
|
/** Close the cached Repository handle. */
|
||||||
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
getRepository().close();
|
getRepository().close();
|
||||||
}
|
}
|
||||||
|
@@ -83,13 +83,8 @@ public class RenameGroupOp extends DefaultQueueOp {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try (MetaDataUpdate md = metaDataUpdateFactory.create(projectName)) {
|
||||||
MetaDataUpdate md = metaDataUpdateFactory.create(projectName);
|
rename(md);
|
||||||
try {
|
|
||||||
rename(md);
|
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
|
||||||
} catch (RepositoryNotFoundException noProject) {
|
} catch (RepositoryNotFoundException noProject) {
|
||||||
continue;
|
continue;
|
||||||
} catch (ConfigInvalidException | IOException err) {
|
} catch (ConfigInvalidException | IOException err) {
|
||||||
|
@@ -284,9 +284,7 @@ public class CreateProject implements RestModifyView<TopLevelResource, ProjectIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createProjectConfig(CreateProjectArgs args) throws IOException, ConfigInvalidException {
|
private void createProjectConfig(CreateProjectArgs args) throws IOException, ConfigInvalidException {
|
||||||
MetaDataUpdate md =
|
try (MetaDataUpdate md = metaDataUpdateFactory.create(args.getProject())) {
|
||||||
metaDataUpdateFactory.create(args.getProject());
|
|
||||||
try {
|
|
||||||
ProjectConfig config = ProjectConfig.read(md);
|
ProjectConfig config = ProjectConfig.read(md);
|
||||||
config.load(md);
|
config.load(md);
|
||||||
|
|
||||||
@@ -321,8 +319,6 @@ public class CreateProject implements RestModifyView<TopLevelResource, ProjectIn
|
|||||||
|
|
||||||
md.setMessage("Created project\n");
|
md.setMessage("Created project\n");
|
||||||
config.commit(md);
|
config.commit(md);
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
}
|
||||||
projectCache.onCreateProject(args.getProject());
|
projectCache.onCreateProject(args.getProject());
|
||||||
repoManager.setProjectDescription(args.getProject(),
|
repoManager.setProjectDescription(args.getProject(),
|
||||||
|
@@ -139,15 +139,7 @@ public class PutConfig implements RestModifyView<ProjectResource, Input> {
|
|||||||
throw new BadRequestException("config is required");
|
throw new BadRequestException("config is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
final MetaDataUpdate md;
|
try (MetaDataUpdate md = metaDataUpdateFactory.get().create(projectName)) {
|
||||||
try {
|
|
||||||
md = metaDataUpdateFactory.get().create(projectName);
|
|
||||||
} catch (RepositoryNotFoundException notFound) {
|
|
||||||
throw new ResourceNotFoundException(projectName.get());
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new ResourceNotFoundException(projectName.get(), e);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ProjectConfig projectConfig = ProjectConfig.read(md);
|
ProjectConfig projectConfig = ProjectConfig.read(md);
|
||||||
Project p = projectConfig.getProject();
|
Project p = projectConfig.getProject();
|
||||||
|
|
||||||
@@ -226,12 +218,12 @@ public class PutConfig implements RestModifyView<ProjectResource, Input> {
|
|||||||
return new ConfigInfo(serverEnableSignedPush,
|
return new ConfigInfo(serverEnableSignedPush,
|
||||||
state.controlFor(user.get()), config, pluginConfigEntries,
|
state.controlFor(user.get()), config, pluginConfigEntries,
|
||||||
cfgFactory, allProjects, views);
|
cfgFactory, allProjects, views);
|
||||||
|
} catch (RepositoryNotFoundException notFound) {
|
||||||
|
throw new ResourceNotFoundException(projectName.get());
|
||||||
} catch (ConfigInvalidException err) {
|
} catch (ConfigInvalidException err) {
|
||||||
throw new ResourceConflictException("Cannot read project " + projectName, err);
|
throw new ResourceConflictException("Cannot read project " + projectName, err);
|
||||||
} catch (IOException err) {
|
} catch (IOException err) {
|
||||||
throw new ResourceConflictException("Cannot update project " + projectName, err);
|
throw new ResourceConflictException("Cannot update project " + projectName, err);
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -76,42 +76,37 @@ public class PutDescription implements RestModifyView<ProjectResource, PutDescri
|
|||||||
throw new AuthException("not project owner");
|
throw new AuthException("not project owner");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try (MetaDataUpdate md = updateFactory.create(resource.getNameKey())) {
|
||||||
MetaDataUpdate md = updateFactory.create(resource.getNameKey());
|
ProjectConfig config = ProjectConfig.read(md);
|
||||||
try {
|
Project project = config.getProject();
|
||||||
ProjectConfig config = ProjectConfig.read(md);
|
project.setDescription(Strings.emptyToNull(input.description));
|
||||||
Project project = config.getProject();
|
|
||||||
project.setDescription(Strings.emptyToNull(input.description));
|
|
||||||
|
|
||||||
String msg = MoreObjects.firstNonNull(
|
String msg = MoreObjects.firstNonNull(
|
||||||
Strings.emptyToNull(input.commitMessage),
|
Strings.emptyToNull(input.commitMessage),
|
||||||
"Updated description.\n");
|
"Updated description.\n");
|
||||||
if (!msg.endsWith("\n")) {
|
if (!msg.endsWith("\n")) {
|
||||||
msg += "\n";
|
msg += "\n";
|
||||||
}
|
|
||||||
md.setAuthor(user);
|
|
||||||
md.setMessage(msg);
|
|
||||||
ObjectId baseRev = config.getRevision();
|
|
||||||
ObjectId commitRev = config.commit(md);
|
|
||||||
// Only fire hook if project was actually changed.
|
|
||||||
if (!Objects.equals(baseRev, commitRev)) {
|
|
||||||
gitRefUpdated.fire(resource.getNameKey(), RefNames.REFS_CONFIG,
|
|
||||||
baseRev, commitRev);
|
|
||||||
hooks.doRefUpdatedHook(
|
|
||||||
new Branch.NameKey(resource.getNameKey(), RefNames.REFS_CONFIG),
|
|
||||||
baseRev, commitRev, user.getAccount());
|
|
||||||
}
|
|
||||||
cache.evict(ctl.getProject());
|
|
||||||
gitMgr.setProjectDescription(
|
|
||||||
resource.getNameKey(),
|
|
||||||
project.getDescription());
|
|
||||||
|
|
||||||
return Strings.isNullOrEmpty(project.getDescription())
|
|
||||||
? Response.<String>none()
|
|
||||||
: Response.ok(project.getDescription());
|
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
}
|
||||||
|
md.setAuthor(user);
|
||||||
|
md.setMessage(msg);
|
||||||
|
ObjectId baseRev = config.getRevision();
|
||||||
|
ObjectId commitRev = config.commit(md);
|
||||||
|
// Only fire hook if project was actually changed.
|
||||||
|
if (!Objects.equals(baseRev, commitRev)) {
|
||||||
|
gitRefUpdated.fire(resource.getNameKey(), RefNames.REFS_CONFIG,
|
||||||
|
baseRev, commitRev);
|
||||||
|
hooks.doRefUpdatedHook(
|
||||||
|
new Branch.NameKey(resource.getNameKey(), RefNames.REFS_CONFIG),
|
||||||
|
baseRev, commitRev, user.getAccount());
|
||||||
|
}
|
||||||
|
cache.evict(ctl.getProject());
|
||||||
|
gitMgr.setProjectDescription(
|
||||||
|
resource.getNameKey(),
|
||||||
|
project.getDescription());
|
||||||
|
|
||||||
|
return Strings.isNullOrEmpty(project.getDescription())
|
||||||
|
? Response.<String>none()
|
||||||
|
: Response.ok(project.getDescription());
|
||||||
} catch (RepositoryNotFoundException notFound) {
|
} catch (RepositoryNotFoundException notFound) {
|
||||||
throw new ResourceNotFoundException(resource.getName());
|
throw new ResourceNotFoundException(resource.getName());
|
||||||
} catch (ConfigInvalidException e) {
|
} catch (ConfigInvalidException e) {
|
||||||
|
@@ -84,39 +84,34 @@ class SetDefaultDashboard implements RestModifyView<DashboardResource, Input> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try (MetaDataUpdate md = updateFactory.create(ctl.getProject().getNameKey())) {
|
||||||
MetaDataUpdate md = updateFactory.create(ctl.getProject().getNameKey());
|
ProjectConfig config = ProjectConfig.read(md);
|
||||||
try {
|
Project project = config.getProject();
|
||||||
ProjectConfig config = ProjectConfig.read(md);
|
if (inherited) {
|
||||||
Project project = config.getProject();
|
project.setDefaultDashboard(input.id);
|
||||||
if (inherited) {
|
} else {
|
||||||
project.setDefaultDashboard(input.id);
|
project.setLocalDefaultDashboard(input.id);
|
||||||
} else {
|
|
||||||
project.setLocalDefaultDashboard(input.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
String msg = MoreObjects.firstNonNull(
|
|
||||||
Strings.emptyToNull(input.commitMessage),
|
|
||||||
input.id == null
|
|
||||||
? "Removed default dashboard.\n"
|
|
||||||
: String.format("Changed default dashboard to %s.\n", input.id));
|
|
||||||
if (!msg.endsWith("\n")) {
|
|
||||||
msg += "\n";
|
|
||||||
}
|
|
||||||
md.setAuthor(ctl.getUser().asIdentifiedUser());
|
|
||||||
md.setMessage(msg);
|
|
||||||
config.commit(md);
|
|
||||||
cache.evict(ctl.getProject());
|
|
||||||
|
|
||||||
if (target != null) {
|
|
||||||
DashboardInfo info = get.get().apply(target);
|
|
||||||
info.isDefault = true;
|
|
||||||
return Response.ok(info);
|
|
||||||
}
|
|
||||||
return Response.none();
|
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String msg = MoreObjects.firstNonNull(
|
||||||
|
Strings.emptyToNull(input.commitMessage),
|
||||||
|
input.id == null
|
||||||
|
? "Removed default dashboard.\n"
|
||||||
|
: String.format("Changed default dashboard to %s.\n", input.id));
|
||||||
|
if (!msg.endsWith("\n")) {
|
||||||
|
msg += "\n";
|
||||||
|
}
|
||||||
|
md.setAuthor(ctl.getUser().asIdentifiedUser());
|
||||||
|
md.setMessage(msg);
|
||||||
|
config.commit(md);
|
||||||
|
cache.evict(ctl.getProject());
|
||||||
|
|
||||||
|
if (target != null) {
|
||||||
|
DashboardInfo info = get.get().apply(target);
|
||||||
|
info.isDefault = true;
|
||||||
|
return Response.ok(info);
|
||||||
|
}
|
||||||
|
return Response.none();
|
||||||
} catch (RepositoryNotFoundException notFound) {
|
} catch (RepositoryNotFoundException notFound) {
|
||||||
throw new ResourceNotFoundException(ctl.getProject().getName());
|
throw new ResourceNotFoundException(ctl.getProject().getName());
|
||||||
} catch (ConfigInvalidException e) {
|
} catch (ConfigInvalidException e) {
|
||||||
|
@@ -71,32 +71,27 @@ public class SetParent implements RestModifyView<ProjectResource, Input> {
|
|||||||
ResourceNotFoundException, UnprocessableEntityException, IOException {
|
ResourceNotFoundException, UnprocessableEntityException, IOException {
|
||||||
ProjectControl ctl = rsrc.getControl();
|
ProjectControl ctl = rsrc.getControl();
|
||||||
validateParentUpdate(ctl, input.parent, checkIfAdmin);
|
validateParentUpdate(ctl, input.parent, checkIfAdmin);
|
||||||
try {
|
try (MetaDataUpdate md = updateFactory.create(rsrc.getNameKey())) {
|
||||||
MetaDataUpdate md = updateFactory.create(rsrc.getNameKey());
|
ProjectConfig config = ProjectConfig.read(md);
|
||||||
try {
|
Project project = config.getProject();
|
||||||
ProjectConfig config = ProjectConfig.read(md);
|
project.setParentName(Strings.emptyToNull(input.parent));
|
||||||
Project project = config.getProject();
|
|
||||||
project.setParentName(Strings.emptyToNull(input.parent));
|
|
||||||
|
|
||||||
String msg = Strings.emptyToNull(input.commitMessage);
|
String msg = Strings.emptyToNull(input.commitMessage);
|
||||||
if (msg == null) {
|
if (msg == null) {
|
||||||
msg = String.format(
|
msg = String.format(
|
||||||
"Changed parent to %s.\n",
|
"Changed parent to %s.\n",
|
||||||
MoreObjects.firstNonNull(project.getParentName(),
|
MoreObjects.firstNonNull(project.getParentName(),
|
||||||
allProjects.get()));
|
allProjects.get()));
|
||||||
} else if (!msg.endsWith("\n")) {
|
} else if (!msg.endsWith("\n")) {
|
||||||
msg += "\n";
|
msg += "\n";
|
||||||
}
|
|
||||||
md.setAuthor(ctl.getUser().asIdentifiedUser());
|
|
||||||
md.setMessage(msg);
|
|
||||||
config.commit(md);
|
|
||||||
cache.evict(ctl.getProject());
|
|
||||||
|
|
||||||
Project.NameKey parentName = project.getParent(allProjects);
|
|
||||||
return parentName != null ? parentName.get() : "";
|
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
}
|
||||||
|
md.setAuthor(ctl.getUser().asIdentifiedUser());
|
||||||
|
md.setMessage(msg);
|
||||||
|
config.commit(md);
|
||||||
|
cache.evict(ctl.getProject());
|
||||||
|
|
||||||
|
Project.NameKey parentName = project.getParent(allProjects);
|
||||||
|
return parentName != null ? parentName.get() : "";
|
||||||
} catch (RepositoryNotFoundException notFound) {
|
} catch (RepositoryNotFoundException notFound) {
|
||||||
throw new ResourceNotFoundException(rsrc.getName());
|
throw new ResourceNotFoundException(rsrc.getName());
|
||||||
} catch (ConfigInvalidException e) {
|
} catch (ConfigInvalidException e) {
|
||||||
|
@@ -145,17 +145,12 @@ final class AdminSetParent extends SshCommand {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try (MetaDataUpdate md = metaDataUpdateFactory.create(nameKey)) {
|
||||||
MetaDataUpdate md = metaDataUpdateFactory.create(nameKey);
|
ProjectConfig config = ProjectConfig.read(md);
|
||||||
try {
|
config.getProject().setParentName(newParentKey);
|
||||||
ProjectConfig config = ProjectConfig.read(md);
|
md.setMessage("Inherit access from "
|
||||||
config.getProject().setParentName(newParentKey);
|
+ (newParentKey != null ? newParentKey.get() : allProjectsName.get()) + "\n");
|
||||||
md.setMessage("Inherit access from "
|
config.commit(md);
|
||||||
+ (newParentKey != null ? newParentKey.get() : allProjectsName.get()) + "\n");
|
|
||||||
config.commit(md);
|
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
|
||||||
} catch (RepositoryNotFoundException notFound) {
|
} catch (RepositoryNotFoundException notFound) {
|
||||||
err.append("error: Project ").append(name).append(" not found\n");
|
err.append("error: Project ").append(name).append(" not found\n");
|
||||||
} catch (IOException | ConfigInvalidException e) {
|
} catch (IOException | ConfigInvalidException e) {
|
||||||
|
@@ -124,41 +124,36 @@ final class SetProjectCommand extends SshCommand {
|
|||||||
String name = ctlProject.getName();
|
String name = ctlProject.getName();
|
||||||
final StringBuilder err = new StringBuilder();
|
final StringBuilder err = new StringBuilder();
|
||||||
|
|
||||||
try {
|
try (MetaDataUpdate md = metaDataUpdateFactory.create(nameKey)) {
|
||||||
MetaDataUpdate md = metaDataUpdateFactory.create(nameKey);
|
ProjectConfig config = ProjectConfig.read(md);
|
||||||
try {
|
Project project = config.getProject();
|
||||||
ProjectConfig config = ProjectConfig.read(md);
|
|
||||||
Project project = config.getProject();
|
|
||||||
|
|
||||||
if (requireChangeID != null) {
|
if (requireChangeID != null) {
|
||||||
project.setRequireChangeID(requireChangeID);
|
project.setRequireChangeID(requireChangeID);
|
||||||
}
|
|
||||||
if (submitType != null) {
|
|
||||||
project.setSubmitType(submitType);
|
|
||||||
}
|
|
||||||
if (contentMerge != null) {
|
|
||||||
project.setUseContentMerge(contentMerge);
|
|
||||||
}
|
|
||||||
if (contributorAgreements != null) {
|
|
||||||
project.setUseContributorAgreements(contributorAgreements);
|
|
||||||
}
|
|
||||||
if (signedOffBy != null) {
|
|
||||||
project.setUseSignedOffBy(signedOffBy);
|
|
||||||
}
|
|
||||||
if (projectDescription != null) {
|
|
||||||
project.setDescription(projectDescription);
|
|
||||||
}
|
|
||||||
if (state != null) {
|
|
||||||
project.setState(state);
|
|
||||||
}
|
|
||||||
if (maxObjectSizeLimit != null) {
|
|
||||||
project.setMaxObjectSizeLimit(maxObjectSizeLimit);
|
|
||||||
}
|
|
||||||
md.setMessage("Project settings updated");
|
|
||||||
config.commit(md);
|
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
}
|
||||||
|
if (submitType != null) {
|
||||||
|
project.setSubmitType(submitType);
|
||||||
|
}
|
||||||
|
if (contentMerge != null) {
|
||||||
|
project.setUseContentMerge(contentMerge);
|
||||||
|
}
|
||||||
|
if (contributorAgreements != null) {
|
||||||
|
project.setUseContributorAgreements(contributorAgreements);
|
||||||
|
}
|
||||||
|
if (signedOffBy != null) {
|
||||||
|
project.setUseSignedOffBy(signedOffBy);
|
||||||
|
}
|
||||||
|
if (projectDescription != null) {
|
||||||
|
project.setDescription(projectDescription);
|
||||||
|
}
|
||||||
|
if (state != null) {
|
||||||
|
project.setState(state);
|
||||||
|
}
|
||||||
|
if (maxObjectSizeLimit != null) {
|
||||||
|
project.setMaxObjectSizeLimit(maxObjectSizeLimit);
|
||||||
|
}
|
||||||
|
md.setMessage("Project settings updated");
|
||||||
|
config.commit(md);
|
||||||
} catch (RepositoryNotFoundException notFound) {
|
} catch (RepositoryNotFoundException notFound) {
|
||||||
err.append("error: Project ").append(name).append(" not found\n");
|
err.append("error: Project ").append(name).append(" not found\n");
|
||||||
} catch (IOException | ConfigInvalidException e) {
|
} catch (IOException | ConfigInvalidException e) {
|
||||||
|
Reference in New Issue
Block a user