Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.StoredConfig


   * @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);
    }
    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);
    }
  }
View Full Code Here


   */
  private StoredConfig getRepositoryConfig(Repository r) {
    try {
      Field f = r.getClass().getDeclaredField("repoConfig");
      f.setAccessible(true);
      StoredConfig config = (StoredConfig) f.get(r);
      return config;
    } catch (Exception e) {
      logger.error("Failed to retrieve \"repoConfig\" via reflection", e);
    }
    return r.getConfig();
View Full Code Here

      // 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.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;
View Full Code Here

        // rename fork origins in their configs
        if (!ArrayUtils.isEmpty(repository.forks)) {
          for (String fork : repository.forks) {
            Repository rf = getRepository(fork);
            try {
              StoredConfig config = rf.getConfig();
              String origin = config.getString("remote", "origin", "url");
              origin = origin.replace(repositoryName, repository.name);
              config.setString("remote", "origin", "url", origin);
              config.setString(Constants.CONFIG_GITBLIT, null, "originRepository", repository.name);
              config.save();
            } catch (Exception e) {
              logger.error("Failed to update repository fork config for " + fork, e);
            }
            rf.close();
          }
View Full Code Here

          repairAttempted.add(repositoryName);
          JGitUtils.repairFetchSpecs(repository);
        }

        // find the first mirror remote - there should only be one
        StoredConfig rc = repository.getConfig();
        RemoteConfig mirror = null;
        List<RemoteConfig> configs = RemoteConfig.getAllRemoteConfigs(rc);
        for (RemoteConfig config : configs) {
          if (config.isMirror()) {
            mirror = config;
View Full Code Here

      try {
        // load repository config
        File gitDir = FileKey.resolve(new File(folder, repo), FS.DETECTED);
        Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
        StoredConfig config = repository.getConfig();
        config.load();

        Set<String> indexedBranches = new LinkedHashSet<String>();

        // add all local branches to index
        if (params.addAllLocalBranches) {
          List<RefModel> list = JGitUtils.getLocalBranches(repository, true, -1);
          for (RefModel refModel : list) {
            System.out.println(MessageFormat.format("adding [gitblit] indexBranch={0} for {1}", refModel.getName(), repo));
            indexedBranches.add(refModel.getName());
          }
        }
        else {
          // add only one branch to index ('default' if not specified)
          System.out.println(MessageFormat.format("adding [gitblit] indexBranch={0} for {1}", params.branch, repo));
          indexedBranches.add(params.branch);
        }

        String [] branches = config.getStringList("gitblit", null, "indexBranch");
        if (!ArrayUtils.isEmpty(branches)) {
          for (String branch : branches) {
            indexedBranches.add(branch);
          }
        }
        config.setStringList("gitblit", null, "indexBranch", new ArrayList<String>(indexedBranches));
        config.save();
        modCount++;
      } catch (Exception e) {
        System.err.println(repo);
        e.printStackTrace();
      }
View Full Code Here

  public synchronized TicketMilestone createMilestone(RepositoryModel repository, String milestone, String createdBy) {
    TicketMilestone ms = new TicketMilestone(milestone);
    Repository db = null;
    try {
      db = repositoryManager.getRepository(repository.name);
      StoredConfig config = db.getConfig();
      config.setString(MILESTONE, milestone, STATUS, ms.status.name());
      config.setString(MILESTONE, milestone, COLOR, ms.color);
      config.save();

      milestonesCache.remove(repository.name);
    } catch (IOException e) {
      log.error("failed to create milestone " + milestone + " in " + repository, e);
    } finally {
View Full Code Here

   */
  public synchronized boolean updateMilestone(RepositoryModel repository, TicketMilestone milestone, String createdBy) {
    Repository db = null;
    try {
      db = repositoryManager.getRepository(repository.name);
      StoredConfig config = db.getConfig();
      config.setString(MILESTONE, milestone.name, STATUS, milestone.status.name());
      config.setString(MILESTONE, milestone.name, COLOR, milestone.color);
      if (milestone.due != null) {
        config.setString(MILESTONE, milestone.name, DUE,
            new SimpleDateFormat(DUE_DATE_PATTERN).format(milestone.due));
      }
      config.save();

      milestonesCache.remove(repository.name);
      return true;
    } catch (IOException e) {
      log.error("failed to update milestone " + milestone + " in " + repository, e);
View Full Code Here

      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) {
View Full Code Here

      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) {
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.lib.StoredConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.