Example usage for org.eclipse.jgit.storage.file FileBasedConfig unset

List of usage examples for org.eclipse.jgit.storage.file FileBasedConfig unset

Introduction

In this page you can find the example usage for org.eclipse.jgit.storage.file FileBasedConfig unset.

Prototype

public void unset(final String section, final String subsection, final String name) 

Source Link

Document

Remove a configuration value.

Usage

From source file:com.google.gerrit.server.schema.Schema_57.java

License:Apache License

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
    SystemConfig sc = db.systemConfig().get(new SystemConfig.Key());
    Project.NameKey allProjects = sc.wildProjectName;

    FileBasedConfig cfg = new FileBasedConfig(site.gerrit_config, FS.DETECTED);
    boolean cfgDirty = false;
    try {//from  w  w w . j a  va  2  s .co  m
        cfg.load();
    } catch (ConfigInvalidException err) {
        throw new OrmException("Cannot read " + site.gerrit_config, err);
    } catch (IOException err) {
        throw new OrmException("Cannot read " + site.gerrit_config, err);
    }

    if (!allProjects.get().equals(AllProjectsNameProvider.DEFAULT)) {
        ui.message("Setting gerrit.allProjects = " + allProjects.get());
        cfg.setString("gerrit", null, "allProjects", allProjects.get());
        cfgDirty = true;
    }

    try {
        Repository git = mgr.openRepository(allProjects);
        try {
            MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allProjects, git);
            md.getCommitBuilder().setAuthor(serverUser);
            md.getCommitBuilder().setCommitter(serverUser);

            ProjectConfig config = ProjectConfig.read(md);
            AccessSection cap = config.getAccessSection(AccessSection.GLOBAL_CAPABILITIES, true);

            // Move the Administrators group reference to All-Projects.
            cap.getPermission(GlobalCapability.ADMINISTRATE_SERVER, true)
                    .add(new PermissionRule(config.resolve(db.accountGroups().get(sc.adminGroupId))));

            // Move the repository.*.createGroup to Create Project.
            String[] createGroupList = cfg.getStringList("repository", "*", "createGroup");

            // Prepare the account_group_includes query
            PreparedStatement stmt = ((JdbcSchema) db).getConnection()
                    .prepareStatement("SELECT * FROM account_group_includes WHERE group_id = ?");

            for (String name : createGroupList) {
                AccountGroup.NameKey key = new AccountGroup.NameKey(name);
                AccountGroupName groupName = db.accountGroupNames().get(key);
                if (groupName == null) {
                    continue;
                }

                AccountGroup group = db.accountGroups().get(groupName.getId());
                if (group == null) {
                    continue;
                }

                cap.getPermission(GlobalCapability.CREATE_PROJECT, true)
                        .add(new PermissionRule(config.resolve(group)));
            }
            if (createGroupList.length != 0) {
                ui.message("Moved repository.*.createGroup to 'Create Project' capability");
                cfg.unset("repository", "*", "createGroup");
                cfgDirty = true;
            }

            AccountGroup batch = db.accountGroups().get(sc.batchUsersGroupId);
            stmt.setInt(1, sc.batchUsersGroupId.get());
            if (batch != null && db.accountGroupMembers().byGroup(sc.batchUsersGroupId).toList().isEmpty()
                    && stmt.executeQuery().first() != false) {
                // If the batch user group is not used, delete it.
                //
                db.accountGroups().delete(Collections.singleton(batch));

                AccountGroupName name = db.accountGroupNames().get(batch.getNameKey());
                if (name != null) {
                    db.accountGroupNames().delete(Collections.singleton(name));
                }
            } else if (batch != null) {
                cap.getPermission(GlobalCapability.PRIORITY, true).getRule(config.resolve(batch), true)
                        .setAction(Action.BATCH);
            }

            md.setMessage("Upgrade to Gerrit Code Review schema 57\n");
            config.commit(md);
        } catch (SQLException err) {
            throw new OrmException("Cannot read account_group_includes", err);
        } finally {
            git.close();
        }
    } catch (ConfigInvalidException err) {
        throw new OrmException("Cannot read " + allProjects, err);
    } catch (IOException err) {
        throw new OrmException("Cannot update " + allProjects, err);
    }

    if (cfgDirty) {
        try {
            cfg.save();
        } catch (IOException err) {
            throw new OrmException("Cannot update " + site.gerrit_config, err);
        }
    }

    // We cannot set the columns to NULL, so use 0 and a DELETED tag.
    sc.adminGroupId = new AccountGroup.Id(0);
    sc.adminGroupUUID = new AccountGroup.UUID("DELETED");
    sc.anonymousGroupId = new AccountGroup.Id(0);
    sc.registeredGroupId = new AccountGroup.Id(0);
    sc.wildProjectName = new Project.NameKey("DELETED");
    sc.ownerGroupId = new AccountGroup.Id(0);
    sc.batchUsersGroupId = new AccountGroup.Id(0);
    sc.batchUsersGroupUUID = new AccountGroup.UUID("DELETED");
    sc.registerEmailPrivateKey = "DELETED";

    db.systemConfig().update(Collections.singleton(sc));
}

From source file:com.googlesource.gerrit.plugins.emoticons.PutConfig.java

License:Apache License

@Override
public Response<?> apply(ConfigResource rsrc, Input input)
        throws IOException, ConfigInvalidException, UnprocessableEntityException {
    if (input == null) {
        input = new Input();
    }//from   w  w w . j  av a2s  .  c  o m
    FileBasedConfig cfg = new FileBasedConfig(sitePaths.gerrit_config.toFile(), FS.DETECTED);
    cfg.load();

    if (input.showEmoticons != null) {
        if (input.showEmoticons) {
            cfg.setBoolean("plugin", pluginName, "showEmoticons", input.showEmoticons);
        } else {
            cfg.unset("plugin", pluginName, "stage");
        }
    }

    cfg.save();
    cfgFactory.getFromGerritConfig(pluginName, true);
    return Response.none();
}

From source file:com.googlesource.gerrit.plugins.verifystatus.server.PutConfig.java

License:Apache License

@Override
public Response<?> apply(ConfigResource rsrc, Input input)
        throws IOException, ConfigInvalidException, UnprocessableEntityException {
    if (input == null) {
        input = new Input();
    }/*from   w ww  .  ja v  a2 s. com*/
    FileBasedConfig cfg = new FileBasedConfig(sitePaths.gerrit_config.toFile(), FS.DETECTED);
    cfg.load();

    if (input.showJobsPanel != null) {
        cfg.setBoolean("plugin", pluginName, "showJobsPanel", input.showJobsPanel);
    } else {
        cfg.unset("plugin", pluginName, "showJobsPanel");
    }
    if (input.showJobsDropDownPanel != null) {
        cfg.setBoolean("plugin", pluginName, "showJobsDropDownPanel", input.showJobsDropDownPanel);
    } else {
        cfg.unset("plugin", pluginName, "showJobsDropDownPanel");
    }
    if (input.showJobsSummaryPanel != null) {
        cfg.setBoolean("plugin", pluginName, "showJobsSummaryPanel", input.showJobsSummaryPanel);
    } else {
        cfg.unset("plugin", pluginName, "showJobsSummaryPanel");
    }

    cfg.save();
    cfgFactory.getFromGerritConfig(pluginName, true);
    return Response.none();
}

From source file:org.eclipse.orion.server.git.servlets.GitConfigHandlerV1.java

License:Open Source License

private boolean handleDelete(HttpServletRequest request, HttpServletResponse response, String path)
        throws CoreException, IOException, ServletException, ConfigInvalidException {
    Path p = new Path(path);
    if (p.segment(1).equals("clone") && p.segment(2).equals("file")) { //$NON-NLS-1$ //$NON-NLS-2$
        // expected path /gitapi/config/{key}/clone/file/{path}
        File gitDir = GitUtils.getGitDir(p.removeFirstSegments(2));
        FileBasedConfig config = getLocalConfig(gitDir);

        String key = p.segment(0);
        String[] keySegments = keyToSegments(key);
        if (keySegments == null)
            return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR,
                    HttpServletResponse.SC_BAD_REQUEST,
                    "Config entry key must be provided in the following form: section[.subsection].name",
                    null));/*from  w ww  .  ja v a 2  s. c  om*/

        // determine if config entry exist
        if (variableExist(config, keySegments)) {
            // delete
            config.unset(keySegments[0], keySegments[1], keySegments[2]);
            config.save();

            response.setStatus(HttpServletResponse.SC_OK);
        } else {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        }
        return true;
    }
    return false;
}

From source file:org.sonatype.m2e.egit.internal.EgitScmHandler.java

License:Open Source License

protected void fixAutoCRLF(File gitDirectory) throws IOException {
    // jgit does not have support for core.autocrlf but it sets the core.autocrlf=false in the local git
    // repository config (https://bugs.eclipse.org/bugs/show_bug.cgi?id=301775).
    // We need to unset it.
    FileRepository localRepository = new FileRepository(gitDirectory);
    try {/*from   w w w  .ja v a 2  s  .c o  m*/
        FileBasedConfig localConfig = localRepository.getConfig();
        localConfig.unset(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF);
        localConfig.save();
    } finally {
        localRepository.close();
    }
}