List of usage examples for org.eclipse.jgit.lib StoredConfig getNames
public Set<String> getNames(String section, String subsection)
From source file:com.gitblit.GitBlit.java
License:Apache License
/** * Create a repository model from the configuration and repository data. * /*w w w. j a va2s . co m*/ * @param repositoryName * @return a repositoryModel or null if the repository does not exist */ private RepositoryModel loadRepositoryModel(String repositoryName) { Repository r = getRepository(repositoryName); if (r == null) { return null; } RepositoryModel model = new RepositoryModel(); model.name = repositoryName; model.hasCommits = JGitUtils.hasCommits(r); model.lastChange = JGitUtils.getLastChange(r); model.isBare = r.isBare(); if (repositoryName.indexOf('/') == -1) { model.projectPath = ""; } else { model.projectPath = repositoryName.substring(0, repositoryName.indexOf('/')); } StoredConfig config = r.getConfig(); boolean hasOrigin = !StringUtils.isEmpty(config.getString("remote", "origin", "url")); if (config != null) { model.description = getConfig(config, "description", ""); model.owner = getConfig(config, "owner", ""); model.useTickets = getConfig(config, "useTickets", false); model.useDocs = getConfig(config, "useDocs", false); model.allowForks = getConfig(config, "allowForks", true); model.accessRestriction = AccessRestrictionType.fromName(getConfig(config, "accessRestriction", settings.getString(Keys.git.defaultAccessRestriction, null))); model.authorizationControl = AuthorizationControl.fromName(getConfig(config, "authorizationControl", settings.getString(Keys.git.defaultAuthorizationControl, null))); model.showRemoteBranches = getConfig(config, "showRemoteBranches", hasOrigin); model.isFrozen = getConfig(config, "isFrozen", false); model.showReadme = getConfig(config, "showReadme", false); model.skipSizeCalculation = getConfig(config, "skipSizeCalculation", false); model.skipSummaryMetrics = getConfig(config, "skipSummaryMetrics", false); model.federationStrategy = FederationStrategy.fromName(getConfig(config, "federationStrategy", null)); model.federationSets = new ArrayList<String>( Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "federationSets"))); model.isFederated = getConfig(config, "isFederated", false); model.origin = config.getString("remote", "origin", "url"); model.preReceiveScripts = new ArrayList<String>( Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "preReceiveScript"))); model.postReceiveScripts = new ArrayList<String>( Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "postReceiveScript"))); model.mailingLists = new ArrayList<String>( Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "mailingList"))); model.indexedBranches = new ArrayList<String>( Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "indexBranch"))); // Custom defined properties model.customFields = new LinkedHashMap<String, String>(); for (String aProperty : config.getNames(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS)) { model.customFields.put(aProperty, config.getString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, aProperty)); } } model.HEAD = JGitUtils.getHEADRef(r); model.availableRefs = JGitUtils.getAvailableHeadTargets(r); r.close(); if (model.origin != null && model.origin.startsWith("file://")) { // repository was cloned locally... perhaps as a fork try { File folder = new File(new URI(model.origin)); String originRepo = com.gitblit.utils.FileUtils.getRelativePath(getRepositoriesFolder(), folder); if (!StringUtils.isEmpty(originRepo)) { // ensure origin still exists File repoFolder = new File(getRepositoriesFolder(), originRepo); if (repoFolder.exists()) { model.originRepository = originRepo; } } } catch (URISyntaxException e) { logger.error("Failed to determine fork for " + model, e); } } return model; }
From source file:com.gitblit.manager.RepositoryManager.java
License:Apache License
/** * Create a repository model from the configuration and repository data. * * @param repositoryName//www .j a v a 2s. c o m * @return a repositoryModel or null if the repository does not exist */ private RepositoryModel loadRepositoryModel(String repositoryName) { Repository r = getRepository(repositoryName); if (r == null) { return null; } RepositoryModel model = new RepositoryModel(); model.isBare = r.isBare(); File basePath = getRepositoriesFolder(); if (model.isBare) { model.name = com.gitblit.utils.FileUtils.getRelativePath(basePath, r.getDirectory()); } else { model.name = com.gitblit.utils.FileUtils.getRelativePath(basePath, r.getDirectory().getParentFile()); } if (StringUtils.isEmpty(model.name)) { // Repository is NOT located relative to the base folder because it // is symlinked. Use the provided repository name. model.name = repositoryName; } model.projectPath = StringUtils.getFirstPathElement(repositoryName); StoredConfig config = r.getConfig(); boolean hasOrigin = false; if (config != null) { // Initialize description from description file hasOrigin = !StringUtils.isEmpty(config.getString("remote", "origin", "url")); if (getConfig(config, "description", null) == null) { File descFile = new File(r.getDirectory(), "description"); if (descFile.exists()) { String desc = com.gitblit.utils.FileUtils.readContent(descFile, System.getProperty("line.separator")); if (!desc.toLowerCase().startsWith("unnamed repository")) { config.setString(Constants.CONFIG_GITBLIT, null, "description", desc); } } } model.description = getConfig(config, "description", ""); model.originRepository = getConfig(config, "originRepository", null); model.addOwners(ArrayUtils.fromString(getConfig(config, "owner", ""))); model.acceptNewPatchsets = getConfig(config, "acceptNewPatchsets", true); model.acceptNewTickets = getConfig(config, "acceptNewTickets", true); model.requireApproval = getConfig(config, "requireApproval", settings.getBoolean(Keys.tickets.requireApproval, false)); model.mergeTo = getConfig(config, "mergeTo", null); model.mergeType = MergeType .fromName(getConfig(config, "mergeType", settings.getString(Keys.tickets.mergeType, null))); model.useIncrementalPushTags = getConfig(config, "useIncrementalPushTags", false); model.incrementalPushTagPrefix = getConfig(config, "incrementalPushTagPrefix", null); model.allowForks = getConfig(config, "allowForks", true); model.accessRestriction = AccessRestrictionType.fromName(getConfig(config, "accessRestriction", settings.getString(Keys.git.defaultAccessRestriction, "PUSH"))); model.authorizationControl = AuthorizationControl.fromName(getConfig(config, "authorizationControl", settings.getString(Keys.git.defaultAuthorizationControl, null))); model.verifyCommitter = getConfig(config, "verifyCommitter", false); model.showRemoteBranches = getConfig(config, "showRemoteBranches", hasOrigin); model.isFrozen = getConfig(config, "isFrozen", false); model.skipSizeCalculation = getConfig(config, "skipSizeCalculation", false); model.skipSummaryMetrics = getConfig(config, "skipSummaryMetrics", false); model.commitMessageRenderer = CommitMessageRenderer.fromName(getConfig(config, "commitMessageRenderer", settings.getString(Keys.web.commitMessageRenderer, null))); model.federationStrategy = FederationStrategy.fromName(getConfig(config, "federationStrategy", null)); model.federationSets = new ArrayList<String>( Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "federationSets"))); model.isFederated = getConfig(config, "isFederated", false); model.gcThreshold = getConfig(config, "gcThreshold", settings.getString(Keys.git.defaultGarbageCollectionThreshold, "500KB")); model.gcPeriod = getConfig(config, "gcPeriod", settings.getInteger(Keys.git.defaultGarbageCollectionPeriod, 7)); try { model.lastGC = new SimpleDateFormat(Constants.ISO8601) .parse(getConfig(config, "lastGC", "1970-01-01'T'00:00:00Z")); } catch (Exception e) { model.lastGC = new Date(0); } model.maxActivityCommits = getConfig(config, "maxActivityCommits", settings.getInteger(Keys.web.maxActivityCommits, 0)); model.origin = config.getString("remote", "origin", "url"); if (model.origin != null) { model.origin = model.origin.replace('\\', '/'); model.isMirror = config.getBoolean("remote", "origin", "mirror", false); } model.preReceiveScripts = new ArrayList<String>( Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "preReceiveScript"))); model.postReceiveScripts = new ArrayList<String>( Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "postReceiveScript"))); model.mailingLists = new ArrayList<String>( Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "mailingList"))); model.indexedBranches = new ArrayList<String>( Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "indexBranch"))); model.metricAuthorExclusions = new ArrayList<String>( Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "metricAuthorExclusions"))); // Custom defined properties model.customFields = new LinkedHashMap<String, String>(); for (String aProperty : config.getNames(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS)) { model.customFields.put(aProperty, config.getString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, aProperty)); } } model.HEAD = JGitUtils.getHEADRef(r); if (StringUtils.isEmpty(model.mergeTo)) { model.mergeTo = model.HEAD; } model.availableRefs = JGitUtils.getAvailableHeadTargets(r); model.sparkleshareId = JGitUtils.getSparkleshareId(r); model.hasCommits = JGitUtils.hasCommits(r); updateLastChangeFields(r, model); r.close(); if (StringUtils.isEmpty(model.originRepository) && model.origin != null && model.origin.startsWith("file://")) { // repository was cloned locally... perhaps as a fork try { File folder = new File(new URI(model.origin)); String originRepo = com.gitblit.utils.FileUtils.getRelativePath(getRepositoriesFolder(), folder); if (!StringUtils.isEmpty(originRepo)) { // ensure origin still exists File repoFolder = new File(getRepositoriesFolder(), originRepo); if (repoFolder.exists()) { model.originRepository = originRepo.toLowerCase(); // persist the fork origin updateConfiguration(r, model); } } } catch (URISyntaxException e) { logger.error("Failed to determine fork for " + model, e); } } return model; }
From source file:com.microsoft.gittf.core.config.ChangesetCommitMap.java
License:Open Source License
private static void copyConfigurationEntries(StoredConfig source, FileBasedConfig target) { Set<String> downloadedChangesetEntries = source.getNames(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.COMMIT_SUBSECTION); for (String changesetEntry : downloadedChangesetEntries) { String commitHash = source.getString(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.COMMIT_SUBSECTION, changesetEntry); target.setString(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.COMMIT_SUBSECTION, changesetEntry, commitHash); }/* w ww.j av a 2s.c o m*/ Set<String> createdCommitEntries = source.getNames(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.CHANGESET_SUBSECTION); for (String commitEntry : createdCommitEntries) { int changesetId = source.getInt(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.CHANGESET_SUBSECTION, commitEntry, -1); target.setInt(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.CHANGESET_SUBSECTION, commitEntry, changesetId); } source.unsetSection(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.CHANGESET_SUBSECTION); source.unsetSection(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.COMMIT_SUBSECTION); try { target.save(); source.save(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.eclipse.che.git.impl.jgit.JGitConfigImpl.java
License:Open Source License
@Override public List<String> getList() throws GitException { List<String> results = new ArrayList<>(); // Iterate all sections and subsections, printing all values StoredConfig config = repository.getConfig(); for (String section : config.getSections()) { for (String subsection : config.getSubsections(section)) { Set<String> names = config.getNames(section, subsection); addConfigValues(section, subsection, names, results); }//ww w. j a v a 2 s. com Set<String> names = config.getNames(section); addConfigValues(section, null, names, results); } return results; }