Search in sources :

Example 6 with DiffPreferencesInfo

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);
}
Also used : DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 7 with DiffPreferencesInfo

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);
}
Also used : DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 8 with DiffPreferencesInfo

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);
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) HashMap(java.util.HashMap) Statement(java.sql.Statement) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Repository(org.eclipse.jgit.lib.Repository) OrmException(com.google.gwtorm.server.OrmException) ResultSet(java.sql.ResultSet) VersionedAccountPreferences(com.google.gerrit.server.account.VersionedAccountPreferences) DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo) HashMap(java.util.HashMap) Map(java.util.Map) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 9 with DiffPreferencesInfo

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;
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) VersionedAccountPreferences(com.google.gerrit.server.account.VersionedAccountPreferences) DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo)

Example 10 with DiffPreferencesInfo

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;
}
Also used : VersionedAccountPreferences(com.google.gerrit.server.account.VersionedAccountPreferences) DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Aggregations

DiffPreferencesInfo (com.google.gerrit.extensions.client.DiffPreferencesInfo)13 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)6 Test (org.junit.Test)6 VersionedAccountPreferences (com.google.gerrit.server.account.VersionedAccountPreferences)3 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)3 Repository (org.eclipse.jgit.lib.Repository)3 PatchScript (com.google.gerrit.common.data.PatchScript)1 DiffInfo (com.google.gerrit.extensions.common.DiffInfo)1 FileMeta (com.google.gerrit.extensions.common.DiffInfo.FileMeta)1 DiffWebLinkInfo (com.google.gerrit.extensions.common.DiffWebLinkInfo)1 IdString (com.google.gerrit.extensions.restapi.IdString)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 SparseFileContent (com.google.gerrit.prettify.common.SparseFileContent)1 Account (com.google.gerrit.reviewdb.client.Account)1 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 LargeObjectException (com.google.gerrit.server.git.LargeObjectException)1 PatchScriptFactory (com.google.gerrit.server.patch.PatchScriptFactory)1 NoSuchChangeException (com.google.gerrit.server.project.NoSuchChangeException)1 ProjectState (com.google.gerrit.server.project.ProjectState)1