Search in sources :

Example 16 with StoredConfig

use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.

the class GitblitManager method setSizeAndPosition.

private void setSizeAndPosition() {
    String sz = null;
    String pos = null;
    try {
        StoredConfig config = getConfig();
        sz = config.getString("ui", null, "size");
        pos = config.getString("ui", null, "position");
    } catch (Throwable t) {
        t.printStackTrace();
    }
    // try to restore saved window size
    if (StringUtils.isEmpty(sz)) {
        setSize(850, 500);
    } else {
        String[] chunks = sz.split("x");
        int width = Integer.parseInt(chunks[0]);
        int height = Integer.parseInt(chunks[1]);
        setSize(width, height);
    }
    // try to restore saved window position
    if (StringUtils.isEmpty(pos)) {
        setLocationRelativeTo(null);
    } else {
        String[] chunks = pos.split(",");
        int x = Integer.parseInt(chunks[0]);
        int y = Integer.parseInt(chunks[1]);
        setLocation(x, y);
    }
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Point(java.awt.Point)

Example 17 with StoredConfig

use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.

the class GitblitManager method saveRegistration.

@Override
public boolean saveRegistration(String name, GitblitRegistration reg) {
    try {
        StoredConfig config = getConfig();
        if (!StringUtils.isEmpty(name) && !name.equals(reg.name)) {
            // delete old registration
            registrations.remove(name);
            config.unsetSection(SERVER, name);
        }
        // update registration
        config.setString(SERVER, reg.name, "url", reg.url);
        config.setString(SERVER, reg.name, "account", reg.account);
        if (reg.savePassword) {
            config.setString(SERVER, reg.name, "password", Base64.encodeBytes(new String(reg.password).getBytes("UTF-8")));
        } else {
            config.setString(SERVER, reg.name, "password", "");
        }
        if (reg.lastLogin != null) {
            config.setString(SERVER, reg.name, "lastLogin", dateFormat.format(reg.lastLogin));
        }
        // serialize the feed definitions
        List<String> definitions = new ArrayList<String>();
        for (FeedModel feed : reg.feeds) {
            definitions.add(feed.toString());
        }
        if (definitions.size() > 0) {
            config.setStringList(SERVER, reg.name, FEED, definitions);
        }
        config.save();
        return true;
    } catch (Throwable t) {
        Utils.showException(GitblitManager.this, t);
    }
    return false;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) FeedModel(com.gitblit.models.FeedModel) ArrayList(java.util.ArrayList)

Example 18 with StoredConfig

use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.

the class GitblitManager method deleteRegistrations.

@Override
public boolean deleteRegistrations(List<GitblitRegistration> list) {
    boolean success = false;
    try {
        StoredConfig config = getConfig();
        for (GitblitRegistration reg : list) {
            config.unsetSection(SERVER, reg.name);
            registrations.remove(reg.name);
        }
        config.save();
        success = true;
    } catch (Throwable t) {
        Utils.showException(GitblitManager.this, t);
    }
    return success;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig)

Example 19 with StoredConfig

use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.

the class GitblitManager method loadRegistrations.

private void loadRegistrations() {
    try {
        StoredConfig config = getConfig();
        Set<String> servers = config.getSubsections(SERVER);
        for (String server : servers) {
            Date lastLogin = new Date(0);
            String date = config.getString(SERVER, server, "lastLogin");
            if (!StringUtils.isEmpty(date)) {
                lastLogin = dateFormat.parse(date);
            }
            String url = config.getString(SERVER, server, "url");
            String account = config.getString(SERVER, server, "account");
            char[] password;
            String pw = config.getString(SERVER, server, "password");
            if (StringUtils.isEmpty(pw)) {
                password = new char[0];
            } else {
                password = new String(Base64.decode(pw)).toCharArray();
            }
            GitblitRegistration reg = new GitblitRegistration(server, url, account, password) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void cacheFeeds() {
                    writeFeedCache(this);
                }
            };
            String[] feeds = config.getStringList(SERVER, server, FEED);
            if (feeds != null) {
                // deserialize the field definitions
                for (String definition : feeds) {
                    FeedModel feed = new FeedModel(definition);
                    reg.feeds.add(feed);
                }
            }
            reg.lastLogin = lastLogin;
            loadFeedCache(reg);
            registrations.put(reg.name, reg);
        }
    } catch (Throwable t) {
        Utils.showException(GitblitManager.this, t);
    }
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) FeedModel(com.gitblit.models.FeedModel) Date(java.util.Date)

Example 20 with StoredConfig

use of org.eclipse.jgit.lib.StoredConfig in project gerrit by GerritCodeReview.

the class RepoViewTest method getConfigIsDefensiveCopy.

@Test
public void getConfigIsDefensiveCopy() throws Exception {
    StoredConfig orig = repo.getConfig();
    orig.setString("a", "config", "option", "yes");
    orig.save();
    Config copy = view.getConfig();
    copy.setString("a", "config", "option", "no");
    assertThat(orig.getString("a", "config", "option")).isEqualTo("yes");
    assertThat(repo.getConfig().getString("a", "config", "option")).isEqualTo("yes");
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Config(org.eclipse.jgit.lib.Config) StoredConfig(org.eclipse.jgit.lib.StoredConfig) Test(org.junit.Test)

Aggregations

StoredConfig (org.eclipse.jgit.lib.StoredConfig)40 IOException (java.io.IOException)26 Repository (org.eclipse.jgit.lib.Repository)19 File (java.io.File)9 ArrayList (java.util.ArrayList)8 URISyntaxException (java.net.URISyntaxException)6 GitException (org.eclipse.che.api.git.exception.GitException)6 SimpleDateFormat (java.text.SimpleDateFormat)5 GitBlitException (com.gitblit.GitBlitException)4 RepositoryModel (com.gitblit.models.RepositoryModel)4 Point (java.awt.Point)4 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)4 RemoteConfig (org.eclipse.jgit.transport.RemoteConfig)4 TeamModel (com.gitblit.models.TeamModel)3 Change (com.gitblit.models.TicketModel.Change)3 UserModel (com.gitblit.models.UserModel)3 HashSet (java.util.HashSet)3 Git (org.eclipse.jgit.api.Git)3 RefSpec (org.eclipse.jgit.transport.RefSpec)3 AccessPermission (com.gitblit.Constants.AccessPermission)2