List of usage examples for org.eclipse.jgit.lib StoredConfig unsetSection
public void unsetSection(String section, String subsection)
From source file:com.gitblit.client.GitblitManager.java
License:Apache License
@Override public boolean saveRegistration(String name, GitblitRegistration reg) { try {/*from www. j a v a 2 s . co m*/ 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; }
From source file:com.gitblit.client.GitblitManager.java
License:Apache License
@Override public boolean deleteRegistrations(List<GitblitRegistration> list) { boolean success = false; try {//from ww w .j a va2 s .c om 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; }
From source file:com.gitblit.GitBlit.java
License:Apache License
/** * Updates the Gitblit configuration for the specified repository. * /*from w w w . j ava 2 s . co m*/ * @param r * the Git repository * @param repository * the Gitblit repository model */ public void updateConfiguration(Repository r, RepositoryModel repository) { StoredConfig config = r.getConfig(); config.setString(Constants.CONFIG_GITBLIT, null, "description", repository.description); config.setString(Constants.CONFIG_GITBLIT, null, "owner", repository.owner); config.setBoolean(Constants.CONFIG_GITBLIT, null, "useTickets", repository.useTickets); config.setBoolean(Constants.CONFIG_GITBLIT, null, "useDocs", repository.useDocs); config.setBoolean(Constants.CONFIG_GITBLIT, null, "allowForks", repository.allowForks); config.setString(Constants.CONFIG_GITBLIT, null, "accessRestriction", repository.accessRestriction.name()); config.setString(Constants.CONFIG_GITBLIT, null, "authorizationControl", repository.authorizationControl.name()); config.setBoolean(Constants.CONFIG_GITBLIT, null, "showRemoteBranches", repository.showRemoteBranches); config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFrozen", repository.isFrozen); config.setBoolean(Constants.CONFIG_GITBLIT, null, "showReadme", repository.showReadme); config.setBoolean(Constants.CONFIG_GITBLIT, null, "skipSizeCalculation", repository.skipSizeCalculation); config.setBoolean(Constants.CONFIG_GITBLIT, null, "skipSummaryMetrics", repository.skipSummaryMetrics); config.setString(Constants.CONFIG_GITBLIT, null, "federationStrategy", repository.federationStrategy.name()); config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFederated", repository.isFederated); updateList(config, "federationSets", repository.federationSets); updateList(config, "preReceiveScript", repository.preReceiveScripts); updateList(config, "postReceiveScript", repository.postReceiveScripts); updateList(config, "mailingList", repository.mailingLists); updateList(config, "indexBranch", repository.indexedBranches); // User Defined Properties if (repository.customFields != null) { if (repository.customFields.size() == 0) { // clear section config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS); } else { for (Entry<String, String> property : repository.customFields.entrySet()) { // set field String key = property.getKey(); String value = property.getValue(); config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, key, value); } } } try { config.save(); } catch (IOException e) { logger.error("Failed to save repository config!", e); } }
From source file:com.gitblit.manager.RepositoryManager.java
License:Apache License
/** * Updates the Gitblit configuration for the specified repository. * * @param r// w w w . j a va 2s .c om * the Git repository * @param repository * the Gitblit repository model */ @Override public void updateConfiguration(Repository r, RepositoryModel repository) { StoredConfig config = r.getConfig(); config.setString(Constants.CONFIG_GITBLIT, null, "description", repository.description); config.setString(Constants.CONFIG_GITBLIT, null, "originRepository", repository.originRepository); config.setString(Constants.CONFIG_GITBLIT, null, "owner", ArrayUtils.toString(repository.owners)); config.setBoolean(Constants.CONFIG_GITBLIT, null, "acceptNewPatchsets", repository.acceptNewPatchsets); config.setBoolean(Constants.CONFIG_GITBLIT, null, "acceptNewTickets", repository.acceptNewTickets); if (settings.getBoolean(Keys.tickets.requireApproval, false) == repository.requireApproval) { // use default config.unset(Constants.CONFIG_GITBLIT, null, "requireApproval"); } else { // override default config.setBoolean(Constants.CONFIG_GITBLIT, null, "requireApproval", repository.requireApproval); } if (!StringUtils.isEmpty(repository.mergeTo)) { config.setString(Constants.CONFIG_GITBLIT, null, "mergeTo", repository.mergeTo); } if (repository.mergeType == null || repository.mergeType == MergeType.fromName(settings.getString(Keys.tickets.mergeType, null))) { // use default config.unset(Constants.CONFIG_GITBLIT, null, "mergeType"); } else { // override default config.setString(Constants.CONFIG_GITBLIT, null, "mergeType", repository.mergeType.name()); } config.setBoolean(Constants.CONFIG_GITBLIT, null, "useIncrementalPushTags", repository.useIncrementalPushTags); if (StringUtils.isEmpty(repository.incrementalPushTagPrefix) || repository.incrementalPushTagPrefix .equals(settings.getString(Keys.git.defaultIncrementalPushTagPrefix, "r"))) { config.unset(Constants.CONFIG_GITBLIT, null, "incrementalPushTagPrefix"); } else { config.setString(Constants.CONFIG_GITBLIT, null, "incrementalPushTagPrefix", repository.incrementalPushTagPrefix); } config.setBoolean(Constants.CONFIG_GITBLIT, null, "allowForks", repository.allowForks); config.setString(Constants.CONFIG_GITBLIT, null, "accessRestriction", repository.accessRestriction.name()); config.setString(Constants.CONFIG_GITBLIT, null, "authorizationControl", repository.authorizationControl.name()); config.setBoolean(Constants.CONFIG_GITBLIT, null, "verifyCommitter", repository.verifyCommitter); config.setBoolean(Constants.CONFIG_GITBLIT, null, "showRemoteBranches", repository.showRemoteBranches); config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFrozen", repository.isFrozen); config.setBoolean(Constants.CONFIG_GITBLIT, null, "skipSizeCalculation", repository.skipSizeCalculation); config.setBoolean(Constants.CONFIG_GITBLIT, null, "skipSummaryMetrics", repository.skipSummaryMetrics); config.setString(Constants.CONFIG_GITBLIT, null, "federationStrategy", repository.federationStrategy.name()); config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFederated", repository.isFederated); config.setString(Constants.CONFIG_GITBLIT, null, "gcThreshold", repository.gcThreshold); if (repository.gcPeriod == settings.getInteger(Keys.git.defaultGarbageCollectionPeriod, 7)) { // use default from config config.unset(Constants.CONFIG_GITBLIT, null, "gcPeriod"); } else { config.setInt(Constants.CONFIG_GITBLIT, null, "gcPeriod", repository.gcPeriod); } if (repository.lastGC != null) { config.setString(Constants.CONFIG_GITBLIT, null, "lastGC", new SimpleDateFormat(Constants.ISO8601).format(repository.lastGC)); } if (repository.maxActivityCommits == settings.getInteger(Keys.web.maxActivityCommits, 0)) { // use default from config config.unset(Constants.CONFIG_GITBLIT, null, "maxActivityCommits"); } else { config.setInt(Constants.CONFIG_GITBLIT, null, "maxActivityCommits", repository.maxActivityCommits); } CommitMessageRenderer defaultRenderer = CommitMessageRenderer .fromName(settings.getString(Keys.web.commitMessageRenderer, null)); if (repository.commitMessageRenderer == null || repository.commitMessageRenderer == defaultRenderer) { // use default from config config.unset(Constants.CONFIG_GITBLIT, null, "commitMessageRenderer"); } else { // repository overrides default config.setString(Constants.CONFIG_GITBLIT, null, "commitMessageRenderer", repository.commitMessageRenderer.name()); } updateList(config, "federationSets", repository.federationSets); updateList(config, "preReceiveScript", repository.preReceiveScripts); updateList(config, "postReceiveScript", repository.postReceiveScripts); updateList(config, "mailingList", repository.mailingLists); updateList(config, "indexBranch", repository.indexedBranches); updateList(config, "metricAuthorExclusions", repository.metricAuthorExclusions); // User Defined Properties if (repository.customFields != null) { if (repository.customFields.size() == 0) { // clear section config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS); } else { for (Entry<String, String> property : repository.customFields.entrySet()) { // set field String key = property.getKey(); String value = property.getValue(); config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, key, value); } } } try { config.save(); } catch (IOException e) { logger.error("Failed to save repository config!", e); } }
From source file:com.gitblit.models.RepositoryModelTest.java
License:Apache License
@Before public void initializeConfiguration() throws Exception { Repository r = GitBlitSuite.getHelloworldRepository(); StoredConfig config = r.getConfig(); config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS); config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, "commitMessageRegEx", "\\d"); config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, "anotherProperty", "Hello"); config.save();// w w w. j a v a 2 s . c o m }
From source file:com.gitblit.models.RepositoryModelTest.java
License:Apache License
@After public void teardownConfiguration() throws Exception { Repository r = GitBlitSuite.getHelloworldRepository(); StoredConfig config = r.getConfig(); config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS); config.save();// w w w .java2 s . c o m }
From source file:com.gitblit.tickets.ITicketService.java
License:Apache License
/** * Renames a label.//from w w w . j a v a 2 s . c o m * * @param repository * @param oldName * @param newName * @param createdBy * @return true if the rename was successful * @since 1.4.0 */ public synchronized boolean renameLabel(RepositoryModel repository, String oldName, String newName, String createdBy) { if (StringUtils.isEmpty(newName)) { throw new IllegalArgumentException("new label can not be empty!"); } Repository db = null; try { db = repositoryManager.getRepository(repository.name); TicketLabel label = getLabel(repository, oldName); StoredConfig config = db.getConfig(); config.unsetSection(LABEL, oldName); config.setString(LABEL, newName, COLOR, label.color); config.save(); for (QueryResult qr : label.tickets) { Change change = new Change(createdBy); change.unlabel(oldName); change.label(newName); updateTicket(repository, qr.number, change); } return true; } catch (IOException e) { log.error("failed to rename label " + oldName + " in " + repository, e); } finally { if (db != null) { db.close(); } } return false; }
From source file:com.gitblit.tickets.ITicketService.java
License:Apache License
/** * Deletes a label./*from ww w . j ava2 s .c o m*/ * * @param repository * @param label * @param createdBy * @return true if the delete was successful * @since 1.4.0 */ public synchronized boolean deleteLabel(RepositoryModel repository, String label, String createdBy) { if (StringUtils.isEmpty(label)) { throw new IllegalArgumentException("label can not be empty!"); } Repository db = null; try { db = repositoryManager.getRepository(repository.name); StoredConfig config = db.getConfig(); config.unsetSection(LABEL, label); config.save(); return true; } catch (IOException e) { log.error("failed to delete label " + label + " in " + repository, e); } finally { if (db != null) { db.close(); } } return false; }
From source file:com.gitblit.tickets.ITicketService.java
License:Apache License
/** * Renames a milestone.//from w w w . ja va 2 s . c om * * @param repository * @param oldName * @param newName * @param createdBy * @param notifyOpenTickets * @return true if successful * @since 1.6.0 */ public synchronized boolean renameMilestone(RepositoryModel repository, String oldName, String newName, String createdBy, boolean notifyOpenTickets) { if (StringUtils.isEmpty(newName)) { throw new IllegalArgumentException("new milestone can not be empty!"); } Repository db = null; try { db = repositoryManager.getRepository(repository.name); TicketMilestone tm = getMilestone(repository, oldName); if (tm == null) { return false; } StoredConfig config = db.getConfig(); config.unsetSection(MILESTONE, oldName); config.setString(MILESTONE, newName, STATUS, tm.status.name()); config.setString(MILESTONE, newName, COLOR, tm.color); if (tm.due != null) { config.setString(MILESTONE, newName, DUE, new SimpleDateFormat(DUE_DATE_PATTERN).format(tm.due)); } config.save(); milestonesCache.remove(repository.name); TicketNotifier notifier = createNotifier(); for (QueryResult qr : tm.tickets) { Change change = new Change(createdBy); change.setField(Field.milestone, newName); TicketModel ticket = updateTicket(repository, qr.number, change); if (notifyOpenTickets && ticket.isOpen()) { notifier.queueMailing(ticket); } } if (notifyOpenTickets) { notifier.sendAll(); } return true; } catch (IOException e) { log.error("failed to rename milestone " + oldName + " in " + repository, e); } finally { if (db != null) { db.close(); } } return false; }
From source file:com.gitblit.tickets.ITicketService.java
License:Apache License
/** * Deletes a milestone./*from w w w . j av a 2 s.com*/ * * @param repository * @param milestone * @param createdBy * @param notifyOpenTickets * @return true if successful * @since 1.6.0 */ public synchronized boolean deleteMilestone(RepositoryModel repository, String milestone, String createdBy, boolean notifyOpenTickets) { if (StringUtils.isEmpty(milestone)) { throw new IllegalArgumentException("milestone can not be empty!"); } Repository db = null; try { TicketMilestone tm = getMilestone(repository, milestone); if (tm == null) { return false; } db = repositoryManager.getRepository(repository.name); StoredConfig config = db.getConfig(); config.unsetSection(MILESTONE, milestone); config.save(); milestonesCache.remove(repository.name); TicketNotifier notifier = createNotifier(); for (QueryResult qr : tm.tickets) { Change change = new Change(createdBy); change.setField(Field.milestone, ""); TicketModel ticket = updateTicket(repository, qr.number, change); if (notifyOpenTickets && ticket.isOpen()) { notifier.queueMailing(ticket); } } if (notifyOpenTickets) { notifier.sendAll(); } return true; } catch (IOException e) { log.error("failed to delete milestone " + milestone + " in " + repository, e); } finally { if (db != null) { db.close(); } } return false; }