List of usage examples for org.eclipse.jgit.storage.file FileBasedConfig clear
@Override public void clear()
From source file:com.palantir.gerrit.gerritci.servlets.ConfigServlet.java
License:Apache License
@Override protected void doPut(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { if (currentUser.get().getCapabilities().canAdministrateServer() == false) { res.setStatus(403);//from w ww. j ava 2 s. c o m return; } /* * The actual parameters we send are encoded into a JSON object such * that they are contained in an object under the entry "f". The other * top-level keys seem to be useless. In addition, each key in the * parameters object has ":" prefixed to whatever it is the key is * actually named. Thus, by stripping the first character away from each * key, we arrive at a sane JSONObject of request parameters. Example: * {"b": [], "f": {":projectName": "name", ":verifyBranchRegex": * * ".*"}} */ JsonObject requestBody = (JsonObject) (new JsonParser()).parse(CharStreams.toString(req.getReader())); requestBody = requestBody.get("f").getAsJsonObject(); File confFile = new File(sitePaths.etc_dir, "gerrit-ci.config"); FileBasedConfig cfg = new FileBasedConfig(confFile, FS.DETECTED); try { cfg.load(); } catch (ConfigInvalidException e) { logger.error("Received PUT request. Error loading gerrit-ci.config file:", e); } cfg.clear(); for (Entry<String, JsonElement> entry : requestBody.entrySet()) { // substring(1) removes the ':' character that precedes each key in the requestBody cfg.setString("Settings", "Jenkins", entry.getKey().substring(1), entry.getValue().getAsString()); } cfg.save(); // the gerrit-ci.config file starts off with permissions -rw-rw-r-- cfg.getFile().setReadOnly(); // make unwritable by making file read only for everyone -r--r--r-- cfg.getFile().setReadable(false, false); // Make the file unreadable (readable=false and ownerOnly=false) cfg.getFile().setReadable(true, true); // Sets the file as readable for only the owner (readable=true and ownerOnly=true) -r-------- res.setStatus(200); res.setContentType("text/plain"); }
From source file:com.palantir.gerrit.gerritci.servlets.JobsServlet.java
License:Apache License
public static FileBasedConfig makeJobConfigFile(File etc_dir, String jobName, CurrentUser currentUser) { File confFile = new File(etc_dir, jobName + ".config"); FileBasedConfig cfg = new FileBasedConfig(confFile, FS.DETECTED); try {//from w w w . j a v a 2 s . com cfg.load(); } catch (ConfigInvalidException | IOException e) { logger.error("Received PUT request. Error loading project job file:", e); } cfg.clear(); cfg.setString("JobName", jobName, "UserUpdated", currentUser.getUserName()); return cfg; }