Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.StoredConfig


        throw new RuntimeException(e);
      }

      GitConfigSharedRepository sharedRepository = new GitConfigSharedRepository(shared);
      if (sharedRepository.isShared()) {
        StoredConfig config = repo.getConfig();
        config.setString("core", null, "sharedRepository", sharedRepository.getValue());
        config.setBoolean("receive", null, "denyNonFastforwards", true);
        config.save();

        if (! JnaUtils.isWindows()) {
          Iterator<File> iter = org.apache.commons.io.FileUtils.iterateFilesAndDirs(repo.getDirectory(),
              TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
          // Adjust permissions on file/directory
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

   * @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

      users.clear();
      cookies.clear();
      teams.clear();

      try {
        StoredConfig config = new FileBasedConfig(realmFile, FS.detect());
        config.load();
        Set<String> usernames = config.getSubsections(USER);
        for (String username : usernames) {
          UserModel user = new UserModel(username.toLowerCase());
          user.password = config.getString(USER, username, PASSWORD);
          user.displayName = config.getString(USER, username, DISPLAYNAME);
          user.emailAddress = config.getString(USER, username, EMAILADDRESS);
          user.accountType = AccountType.fromString(config.getString(USER, username, ACCOUNTTYPE));
          if (Constants.EXTERNAL_ACCOUNT.equals(user.password) && user.accountType.isLocal()) {
            user.accountType = AccountType.EXTERNAL;
          }
          user.disabled = config.getBoolean(USER, username, DISABLED, false);
          user.organizationalUnit = config.getString(USER, username, ORGANIZATIONALUNIT);
          user.organization = config.getString(USER, username, ORGANIZATION);
          user.locality = config.getString(USER, username, LOCALITY);
          user.stateProvince = config.getString(USER, username, STATEPROVINCE);
          user.countryCode = config.getString(USER, username, COUNTRYCODE);
          user.cookie = config.getString(USER, username, COOKIE);
          user.getPreferences().locale = config.getString(USER, username, LOCALE);
          if (StringUtils.isEmpty(user.cookie) && !StringUtils.isEmpty(user.password)) {
            user.cookie = StringUtils.getSHA1(user.username + user.password);
          }

          // user roles
          Set<String> roles = new HashSet<String>(Arrays.asList(config.getStringList(
              USER, username, ROLE)));
          user.canAdmin = roles.contains(Constants.ADMIN_ROLE);
          user.canFork = roles.contains(Constants.FORK_ROLE);
          user.canCreate = roles.contains(Constants.CREATE_ROLE);
          user.excludeFromFederation = roles.contains(Constants.NOT_FEDERATED_ROLE);

          // repository memberships
          if (!user.canAdmin) {
            // non-admin, read permissions
            Set<String> repositories = new HashSet<String>(Arrays.asList(config
                .getStringList(USER, username, REPOSITORY)));
            for (String repository : repositories) {
              user.addRepositoryPermission(repository);
            }
          }

          // starred repositories
          Set<String> starred = new HashSet<String>(Arrays.asList(config
              .getStringList(USER, username, STARRED)));
          for (String repository : starred) {
            UserRepositoryPreferences prefs = user.getPreferences().getRepositoryPreferences(repository);
            prefs.starred = true;
          }

          // update cache
          users.put(user.username, user);
          if (!StringUtils.isEmpty(user.cookie)) {
            cookies.put(user.cookie, user);
          }
        }

        // load the teams
        Set<String> teamnames = config.getSubsections(TEAM);
        for (String teamname : teamnames) {
          TeamModel team = new TeamModel(teamname);
          Set<String> roles = new HashSet<String>(Arrays.asList(config.getStringList(
              TEAM, teamname, ROLE)));
          team.canAdmin = roles.contains(Constants.ADMIN_ROLE);
          team.canFork = roles.contains(Constants.FORK_ROLE);
          team.canCreate = roles.contains(Constants.CREATE_ROLE);
          team.accountType = AccountType.fromString(config.getString(TEAM, teamname, ACCOUNTTYPE));

          if (!team.canAdmin) {
            // non-admin team, read permissions
            team.addRepositoryPermissions(Arrays.asList(config.getStringList(TEAM, teamname,
                REPOSITORY)));
          }
          team.addUsers(Arrays.asList(config.getStringList(TEAM, teamname, USER)));
          team.addMailingLists(Arrays.asList(config.getStringList(TEAM, teamname,
              MAILINGLIST)));
          team.preReceiveScripts.addAll(Arrays.asList(config.getStringList(TEAM,
              teamname, PRERECEIVE)));
          team.postReceiveScripts.addAll(Arrays.asList(config.getStringList(TEAM,
              teamname, POSTRECEIVE)));

          teams.put(team.name.toLowerCase(), team);

          // set the teams on the users
View Full Code Here

    }

    public static Git addRemote(ProductInstance product, String key, String remoteName, Git git) throws IOException
    {
        StoredConfig config = git.getRepository().getConfig();
        config.setString("remote", remoteName, "url", getGitRepositoryUrl(product, key));
        config.setString("remote", remoteName, "fetch", "+refs/heads/*:refs/remotes/origin/*");
        config.save();
        return git;
    }
View Full Code Here

     *
     * @param gitRepoCtx RepositoryContext instance of the tenant
     */
    private void handleInvalidConfigurationError (RepositoryContext gitRepoCtx) {

        StoredConfig storedConfig = gitRepoCtx.getLocalRepo().getConfig();
        boolean modifiedConfig = false;
        if(storedConfig != null) {

            if(storedConfig.getString("branch", "master", "remote") == null ||
                    storedConfig.getString("branch", "master", "remote").isEmpty()) {

                storedConfig.setString("branch", "master", "remote", "origin");
                modifiedConfig = true;
            }

            if(storedConfig.getString("branch", "master", "merge") == null ||
                    storedConfig.getString("branch", "master", "merge").isEmpty()) {

                storedConfig.setString("branch", "master", "merge", "refs/heads/master");
                modifiedConfig = true;
            }

            if(modifiedConfig) {
                try {
                    storedConfig.save();
                   // storedConfig.load();

                } catch (IOException e) {
                    log.error("Error saving git configuration file in local repo at " + gitRepoCtx.getGitLocalRepoPath(), e);
                    e.printStackTrace();
View Full Code Here

   */
  private synchronized void write() throws IOException {
    // Write a temporary copy of the users file
    File realmFileCopy = new File(realmFile.getAbsolutePath() + ".tmp");

    StoredConfig config = new FileBasedConfig(realmFileCopy, FS.detect());

    // write users
    for (UserModel model : users.values()) {
      if (!StringUtils.isEmpty(model.password)) {
        config.setString(USER, model.username, PASSWORD, model.password);
      }
      if (!StringUtils.isEmpty(model.cookie)) {
        config.setString(USER, model.username, COOKIE, model.cookie);
      }
      if (!StringUtils.isEmpty(model.displayName)) {
        config.setString(USER, model.username, DISPLAYNAME, model.displayName);
      }
      if (!StringUtils.isEmpty(model.emailAddress)) {
        config.setString(USER, model.username, EMAILADDRESS, model.emailAddress);
      }
      if (model.accountType != null) {
        config.setString(USER, model.username, ACCOUNTTYPE, model.accountType.name());
      }
      if (!StringUtils.isEmpty(model.organizationalUnit)) {
        config.setString(USER, model.username, ORGANIZATIONALUNIT, model.organizationalUnit);
      }
      if (!StringUtils.isEmpty(model.organization)) {
        config.setString(USER, model.username, ORGANIZATION, model.organization);
      }
      if (!StringUtils.isEmpty(model.locality)) {
        config.setString(USER, model.username, LOCALITY, model.locality);
      }
      if (!StringUtils.isEmpty(model.stateProvince)) {
        config.setString(USER, model.username, STATEPROVINCE, model.stateProvince);
      }
      if (!StringUtils.isEmpty(model.countryCode)) {
        config.setString(USER, model.username, COUNTRYCODE, model.countryCode);
      }
      if (model.disabled) {
        config.setBoolean(USER, model.username, DISABLED, true);
      }
      if (model.getPreferences() != null) {
        Locale locale = model.getPreferences().getLocale();
        if (locale != null) {
          String val;
          if (StringUtils.isEmpty(locale.getCountry())) {
            val = locale.getLanguage();
          } else {
            val = locale.getLanguage() + "_" + locale.getCountry();
          }
          config.setString(USER, model.username, LOCALE, val);
        }

        config.setBoolean(USER, model.username, EMAILONMYTICKETCHANGES, model.getPreferences().isEmailMeOnMyTicketChanges());

        if (model.getPreferences().getTransport() != null) {
          config.setString(USER, model.username, TRANSPORT, model.getPreferences().getTransport().name());
        }
      }

      // user roles
      List<String> roles = new ArrayList<String>();
      if (model.canAdmin) {
        roles.add(Constants.ADMIN_ROLE);
      }
      if (model.canFork) {
        roles.add(Constants.FORK_ROLE);
      }
      if (model.canCreate) {
        roles.add(Constants.CREATE_ROLE);
      }
      if (model.excludeFromFederation) {
        roles.add(Constants.NOT_FEDERATED_ROLE);
      }
      if (roles.size() == 0) {
        // we do this to ensure that user record with no password
        // is written.  otherwise, StoredConfig optimizes that account
        // away. :(
        roles.add(Constants.NO_ROLE);
      }
      config.setStringList(USER, model.username, ROLE, roles);

      // discrete repository permissions
      if (model.permissions != null && !model.canAdmin) {
        List<String> permissions = new ArrayList<String>();
        for (Map.Entry<String, AccessPermission> entry : model.permissions.entrySet()) {
          if (entry.getValue().exceeds(AccessPermission.NONE)) {
            permissions.add(entry.getValue().asRole(entry.getKey()));
          }
        }
        config.setStringList(USER, model.username, REPOSITORY, permissions);
      }

      // user preferences
      if (model.getPreferences() != null) {
        List<String> starred =  model.getPreferences().getStarredRepositories();
        if (starred.size() > 0) {
          config.setStringList(USER, model.username, STARRED, starred);
        }
      }
    }

    // write teams
    for (TeamModel model : teams.values()) {
      // team roles
      List<String> roles = new ArrayList<String>();
      if (model.canAdmin) {
        roles.add(Constants.ADMIN_ROLE);
      }
      if (model.canFork) {
        roles.add(Constants.FORK_ROLE);
      }
      if (model.canCreate) {
        roles.add(Constants.CREATE_ROLE);
      }
      if (roles.size() == 0) {
        // we do this to ensure that team record is written.
        // Otherwise, StoredConfig might optimizes that record away.
        roles.add(Constants.NO_ROLE);
      }
      config.setStringList(TEAM, model.name, ROLE, roles);
      if (model.accountType != null) {
        config.setString(TEAM, model.name, ACCOUNTTYPE, model.accountType.name());
      }

      if (!model.canAdmin) {
        // write team permission for non-admin teams
        if (model.permissions == null) {
          // null check on "final" repositories because JSON-sourced TeamModel
          // can have a null repositories object
          if (!ArrayUtils.isEmpty(model.repositories)) {
            config.setStringList(TEAM, model.name, REPOSITORY, new ArrayList<String>(
                model.repositories));
          }
        } else {
          // discrete repository permissions
          List<String> permissions = new ArrayList<String>();
          for (Map.Entry<String, AccessPermission> entry : model.permissions.entrySet()) {
            if (entry.getValue().exceeds(AccessPermission.NONE)) {
              // code:repository (e.g. RW+:~james/myrepo.git
              permissions.add(entry.getValue().asRole(entry.getKey()));
            }
          }
          config.setStringList(TEAM, model.name, REPOSITORY, permissions);
        }
      }

      // null check on "final" users because JSON-sourced TeamModel
      // can have a null users object
      if (!ArrayUtils.isEmpty(model.users)) {
        config.setStringList(TEAM, model.name, USER, new ArrayList<String>(model.users));
      }

      // null check on "final" mailing lists because JSON-sourced
      // TeamModel can have a null users object
      if (!ArrayUtils.isEmpty(model.mailingLists)) {
        config.setStringList(TEAM, model.name, MAILINGLIST, new ArrayList<String>(
            model.mailingLists));
      }

      // null check on "final" preReceiveScripts because JSON-sourced
      // TeamModel can have a null preReceiveScripts object
      if (!ArrayUtils.isEmpty(model.preReceiveScripts)) {
        config.setStringList(TEAM, model.name, PRERECEIVE, model.preReceiveScripts);
      }

      // null check on "final" postReceiveScripts because JSON-sourced
      // TeamModel can have a null postReceiveScripts object
      if (!ArrayUtils.isEmpty(model.postReceiveScripts)) {
        config.setStringList(TEAM, model.name, POSTRECEIVE, model.postReceiveScripts);
      }
    }

    config.save();
    // manually set the forceReload flag because not all JVMs support real
    // millisecond resolution of lastModified. (issue-55)
    forceReload = true;

    // If the write is successful, delete the current file and rename
View Full Code Here

      users.clear();
      cookies.clear();
      teams.clear();

      try {
        StoredConfig config = new FileBasedConfig(realmFile, FS.detect());
        config.load();
        Set<String> usernames = config.getSubsections(USER);
        for (String username : usernames) {
          UserModel user = new UserModel(username.toLowerCase());
          user.password = config.getString(USER, username, PASSWORD);
          user.displayName = config.getString(USER, username, DISPLAYNAME);
          user.emailAddress = config.getString(USER, username, EMAILADDRESS);
          user.accountType = AccountType.fromString(config.getString(USER, username, ACCOUNTTYPE));
          if (Constants.EXTERNAL_ACCOUNT.equals(user.password) && user.accountType.isLocal()) {
            user.accountType = AccountType.EXTERNAL;
          }
          user.disabled = config.getBoolean(USER, username, DISABLED, false);
          user.organizationalUnit = config.getString(USER, username, ORGANIZATIONALUNIT);
          user.organization = config.getString(USER, username, ORGANIZATION);
          user.locality = config.getString(USER, username, LOCALITY);
          user.stateProvince = config.getString(USER, username, STATEPROVINCE);
          user.countryCode = config.getString(USER, username, COUNTRYCODE);
          user.cookie = config.getString(USER, username, COOKIE);
          if (StringUtils.isEmpty(user.cookie) && !StringUtils.isEmpty(user.password)) {
            user.cookie = StringUtils.getSHA1(user.username + user.password);
          }

          // preferences
          user.getPreferences().setLocale(config.getString(USER, username, LOCALE));
          user.getPreferences().setEmailMeOnMyTicketChanges(config.getBoolean(USER, username, EMAILONMYTICKETCHANGES, true));
          user.getPreferences().setTransport(Transport.fromString(config.getString(USER, username, TRANSPORT)));

          // user roles
          Set<String> roles = new HashSet<String>(Arrays.asList(config.getStringList(
              USER, username, ROLE)));
          user.canAdmin = roles.contains(Constants.ADMIN_ROLE);
          user.canFork = roles.contains(Constants.FORK_ROLE);
          user.canCreate = roles.contains(Constants.CREATE_ROLE);
          user.excludeFromFederation = roles.contains(Constants.NOT_FEDERATED_ROLE);

          // repository memberships
          if (!user.canAdmin) {
            // non-admin, read permissions
            Set<String> repositories = new HashSet<String>(Arrays.asList(config
                .getStringList(USER, username, REPOSITORY)));
            for (String repository : repositories) {
              user.addRepositoryPermission(repository);
            }
          }

          // starred repositories
          Set<String> starred = new HashSet<String>(Arrays.asList(config
              .getStringList(USER, username, STARRED)));
          for (String repository : starred) {
            UserRepositoryPreferences prefs = user.getPreferences().getRepositoryPreferences(repository);
            prefs.starred = true;
          }

          // update cache
          users.put(user.username, user);
          if (!StringUtils.isEmpty(user.cookie)) {
            cookies.put(user.cookie, user);
          }
        }

        // load the teams
        Set<String> teamnames = config.getSubsections(TEAM);
        for (String teamname : teamnames) {
          TeamModel team = new TeamModel(teamname);
          Set<String> roles = new HashSet<String>(Arrays.asList(config.getStringList(
              TEAM, teamname, ROLE)));
          team.canAdmin = roles.contains(Constants.ADMIN_ROLE);
          team.canFork = roles.contains(Constants.FORK_ROLE);
          team.canCreate = roles.contains(Constants.CREATE_ROLE);
          team.accountType = AccountType.fromString(config.getString(TEAM, teamname, ACCOUNTTYPE));

          if (!team.canAdmin) {
            // non-admin team, read permissions
            team.addRepositoryPermissions(Arrays.asList(config.getStringList(TEAM, teamname,
                REPOSITORY)));
          }
          team.addUsers(Arrays.asList(config.getStringList(TEAM, teamname, USER)));
          team.addMailingLists(Arrays.asList(config.getStringList(TEAM, teamname,
              MAILINGLIST)));
          team.preReceiveScripts.addAll(Arrays.asList(config.getStringList(TEAM,
              teamname, PRERECEIVE)));
          team.postReceiveScripts.addAll(Arrays.asList(config.getStringList(TEAM,
              teamname, POSTRECEIVE)));

          teams.put(team.name.toLowerCase(), team);

          // set the teams on the users
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.