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);
}
}
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;
}
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;
}
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);
}
}
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");
}
Aggregations