use of com.google.gerrit.extensions.client.DiffPreferencesInfo in project gerrit by GerritCodeReview.
the class DiffPreferencesIT method setDiffPreferences.
@Test
public void setDiffPreferences() throws Exception {
DiffPreferencesInfo i = DiffPreferencesInfo.defaults();
// change all default values
i.context *= -1;
i.tabSize *= -1;
i.fontSize *= -1;
i.lineLength *= -1;
i.cursorBlinkRate = 500;
i.theme = Theme.MIDNIGHT;
i.ignoreWhitespace = Whitespace.IGNORE_ALL;
i.expandAllComments ^= true;
i.intralineDifference ^= true;
i.manualReview ^= true;
i.retainHeader ^= true;
i.showLineEndings ^= true;
i.showTabs ^= true;
i.showWhitespaceErrors ^= true;
i.skipDeleted ^= true;
i.skipUnchanged ^= true;
i.skipUncommented ^= true;
i.syntaxHighlighting ^= true;
i.hideTopMenu ^= true;
i.autoHideDiffTableHeader ^= true;
i.hideLineNumbers ^= true;
i.renderEntireFile ^= true;
i.hideEmptyPane ^= true;
i.matchBrackets ^= true;
i.lineWrapping ^= true;
DiffPreferencesInfo o = gApi.accounts().id(admin.getId().toString()).setDiffPreferences(i);
assertPrefs(o, i);
// Partially fill input record
i = new DiffPreferencesInfo();
i.tabSize = 42;
DiffPreferencesInfo a = gApi.accounts().id(admin.getId().toString()).setDiffPreferences(i);
assertPrefs(a, o, "tabSize");
assertThat(a.tabSize).isEqualTo(42);
}
use of com.google.gerrit.extensions.client.DiffPreferencesInfo in project gerrit by GerritCodeReview.
the class DiffPreferencesIT method setDiffPreferences.
@Test
public void setDiffPreferences() throws Exception {
int newLineLength = DiffPreferencesInfo.defaults().lineLength + 10;
DiffPreferencesInfo update = new DiffPreferencesInfo();
update.lineLength = newLineLength;
DiffPreferencesInfo result = gApi.config().server().setDefaultDiffPreferences(update);
assertThat(result.lineLength).named("lineLength").isEqualTo(newLineLength);
result = gApi.config().server().getDefaultDiffPreferences();
DiffPreferencesInfo expected = DiffPreferencesInfo.defaults();
expected.lineLength = newLineLength;
assertPrefs(result, expected);
}
use of com.google.gerrit.extensions.client.DiffPreferencesInfo in project gerrit by GerritCodeReview.
the class Schema_115 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
Map<Account.Id, DiffPreferencesInfo> imports = new HashMap<>();
try (Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM account_diff_preferences")) {
Set<String> availableColumns = getColumns(rs);
while (rs.next()) {
Account.Id accountId = new Account.Id(rs.getInt("id"));
DiffPreferencesInfo prefs = new DiffPreferencesInfo();
if (availableColumns.contains("context")) {
prefs.context = (int) rs.getShort("context");
}
if (availableColumns.contains("expand_all_comments")) {
prefs.expandAllComments = toBoolean(rs.getString("expand_all_comments"));
}
if (availableColumns.contains("hide_line_numbers")) {
prefs.hideLineNumbers = toBoolean(rs.getString("hide_line_numbers"));
}
if (availableColumns.contains("hide_top_menu")) {
prefs.hideTopMenu = toBoolean(rs.getString("hide_top_menu"));
}
if (availableColumns.contains("ignore_whitespace")) {
// Enum with char as value
prefs.ignoreWhitespace = toWhitespace(rs.getString("ignore_whitespace"));
}
if (availableColumns.contains("intraline_difference")) {
prefs.intralineDifference = toBoolean(rs.getString("intraline_difference"));
}
if (availableColumns.contains("line_length")) {
prefs.lineLength = rs.getInt("line_length");
}
if (availableColumns.contains("manual_review")) {
prefs.manualReview = toBoolean(rs.getString("manual_review"));
}
if (availableColumns.contains("render_entire_file")) {
prefs.renderEntireFile = toBoolean(rs.getString("render_entire_file"));
}
if (availableColumns.contains("retain_header")) {
prefs.retainHeader = toBoolean(rs.getString("retain_header"));
}
if (availableColumns.contains("show_line_endings")) {
prefs.showLineEndings = toBoolean(rs.getString("show_line_endings"));
}
if (availableColumns.contains("show_tabs")) {
prefs.showTabs = toBoolean(rs.getString("show_tabs"));
}
if (availableColumns.contains("show_whitespace_errors")) {
prefs.showWhitespaceErrors = toBoolean(rs.getString("show_whitespace_errors"));
}
if (availableColumns.contains("skip_deleted")) {
prefs.skipDeleted = toBoolean(rs.getString("skip_deleted"));
}
if (availableColumns.contains("skip_uncommented")) {
prefs.skipUncommented = toBoolean(rs.getString("skip_uncommented"));
}
if (availableColumns.contains("syntax_highlighting")) {
prefs.syntaxHighlighting = toBoolean(rs.getString("syntax_highlighting"));
}
if (availableColumns.contains("tab_size")) {
prefs.tabSize = rs.getInt("tab_size");
}
if (availableColumns.contains("theme")) {
// Enum with name as values; can be null
prefs.theme = toTheme(rs.getString("theme"));
}
if (availableColumns.contains("hide_empty_pane")) {
prefs.hideEmptyPane = toBoolean(rs.getString("hide_empty_pane"));
}
if (availableColumns.contains("auto_hide_diff_table_header")) {
prefs.autoHideDiffTableHeader = toBoolean(rs.getString("auto_hide_diff_table_header"));
}
imports.put(accountId, prefs);
}
}
if (imports.isEmpty()) {
return;
}
try (Repository git = mgr.openRepository(allUsersName);
RevWalk rw = new RevWalk(git)) {
BatchRefUpdate bru = git.getRefDatabase().newBatchUpdate();
for (Map.Entry<Account.Id, DiffPreferencesInfo> e : imports.entrySet()) {
try (MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, git, bru)) {
md.getCommitBuilder().setAuthor(serverUser);
md.getCommitBuilder().setCommitter(serverUser);
VersionedAccountPreferences p = VersionedAccountPreferences.forUser(e.getKey());
p.load(md);
storeSection(p.getConfig(), UserConfigSections.DIFF, null, e.getValue(), DiffPreferencesInfo.defaults());
p.commit(md);
}
}
bru.execute(rw, NullProgressMonitor.INSTANCE);
} catch (ConfigInvalidException | IOException ex) {
throw new OrmException(ex);
}
}
use of com.google.gerrit.extensions.client.DiffPreferencesInfo in project gerrit by GerritCodeReview.
the class GetDiffPreferences method readFromGit.
static DiffPreferencesInfo readFromGit(GitRepositoryManager gitMgr, AllUsersName allUsersName, DiffPreferencesInfo in) throws IOException, ConfigInvalidException, RepositoryNotFoundException {
try (Repository git = gitMgr.openRepository(allUsersName)) {
// Load all users prefs.
VersionedAccountPreferences dp = VersionedAccountPreferences.forDefault();
dp.load(git);
DiffPreferencesInfo allUserPrefs = new DiffPreferencesInfo();
loadSection(dp.getConfig(), UserConfigSections.DIFF, null, allUserPrefs, DiffPreferencesInfo.defaults(), in);
return allUserPrefs;
}
}
use of com.google.gerrit.extensions.client.DiffPreferencesInfo in project gerrit by GerritCodeReview.
the class SetDiffPreferences method writeToGit.
private DiffPreferencesInfo writeToGit(DiffPreferencesInfo in) throws RepositoryNotFoundException, IOException, ConfigInvalidException {
DiffPreferencesInfo out = new DiffPreferencesInfo();
try (MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName)) {
VersionedAccountPreferences prefs = VersionedAccountPreferences.forDefault();
prefs.load(md);
DiffPreferencesInfo defaults = DiffPreferencesInfo.defaults();
storeSection(prefs.getConfig(), UserConfigSections.DIFF, null, in, defaults);
prefs.commit(md);
loadSection(prefs.getConfig(), UserConfigSections.DIFF, null, out, DiffPreferencesInfo.defaults(), null);
}
return out;
}
Aggregations