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

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

Introduction

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

Prototype

public String toText() 

Source Link

Document

Get this configuration, formatted as a Git style text file.

Usage

From source file:com.collabnet.gerrit.SecureStoreJasypt.java

License:Apache License

private static void saveSecure(final FileBasedConfig sec) throws IOException {
    if (FileUtil.modified(sec)) {
        final byte[] out = Constants.encode(sec.toText());
        final File path = sec.getFile();
        final LockFile lf = new LockFile(path, FS.DETECTED);
        if (!lf.lock()) {
            throw new IOException("Cannot lock " + path);
        }//  w  w  w  . jav  a 2  s.c o m
        try {
            FileUtil.chmod(0600, new File(path.getParentFile(), path.getName() + ".lock"));
            lf.write(out);
            if (!lf.commit()) {
                throw new IOException("Cannot commit write to " + path);
            }
        } finally {
            lf.unlock();
        }
    }
}

From source file:com.google.gerrit.common.FileUtil.java

License:Apache License

public static boolean modified(FileBasedConfig cfg) throws IOException {
    byte[] curVers;
    try {//from ww w . j  a  v  a  2  s  .c o  m
        curVers = IO.readFully(cfg.getFile());
    } catch (FileNotFoundException notFound) {
        return true;
    }

    byte[] newVers = Constants.encode(cfg.toText());
    return !Arrays.equals(curVers, newVers);
}

From source file:com.google.gerrit.pgm.init.InitUtil.java

License:Apache License

static void saveSecure(final FileBasedConfig sec) throws IOException {
    if (modified(sec)) {
        final byte[] out = Constants.encode(sec.toText());
        final File path = sec.getFile();
        final LockFile lf = new LockFile(path, FS.DETECTED);
        if (!lf.lock()) {
            throw new IOException("Cannot lock " + path);
        }/*w  ww.j  a v a 2 s.co  m*/
        try {
            chmod(0600, new File(path.getParentFile(), path.getName() + ".lock"));
            lf.write(out);
            if (!lf.commit()) {
                throw new IOException("Cannot commit write to " + path);
            }
        } finally {
            lf.unlock();
        }
    }
}

From source file:com.google.gerrit.pgm.init.InitUtil.java

License:Apache License

private static boolean modified(FileBasedConfig cfg) throws IOException {
    byte[] curVers;
    try {//from   ww  w  .ja  v  a 2s . c  o m
        curVers = IO.readFully(cfg.getFile());
    } catch (FileNotFoundException notFound) {
        return true;
    }

    byte[] newVers = Constants.encode(cfg.toText());
    return !Arrays.equals(curVers, newVers);
}

From source file:com.googlesource.gerrit.plugins.secureconfig.SecureConfigStore.java

License:Apache License

private void saveSecure(final FileBasedConfig sec) throws IOException {
    if (FileUtil.modified(sec)) {
        final byte[] out = Constants.encode(sec.toText());
        final File path = sec.getFile();
        final LockFile lf = new LockFile(path);
        if (!lf.lock()) {
            throw new IOException("Cannot lock " + path);
        }/*from ww  w.j  a  v  a  2s. c o  m*/
        try {
            FileUtil.chmod(0600, new File(path.getParentFile(), path.getName() + ".lock"));
            lf.write(out);
            if (!lf.commit()) {
                throw new IOException("Cannot commit write to " + path);
            }
        } finally {
            lf.unlock();
        }
    }
}

From source file:com.palantir.gerrit.gerritci.servlets.JobsServlet.java

License:Apache License

public static ObjectId createGitFileId(Repository repository, FileBasedConfig jobConfig,
        ObjectInserter objectInserter, String jobName) throws UnsupportedEncodingException, IOException {
    ObjectId fileId = objectInserter.insert(Constants.OBJ_BLOB, jobConfig.toText().getBytes("utf-8"));
    objectInserter.flush();//from   w  w w .j  a  v a  2  s .  co m
    logger.info("Created blobId " + fileId + " for " + jobName);
    return fileId;
}

From source file:org.ms123.common.git.GitServiceImpl.java

License:Open Source License

public List getRepositories(@PName("flags") @POptional List<String> flags,
        @PName("all") @PDefaultBool(false) @POptional Boolean all) throws RpcException {
    System.out.println("getRepositories;" + flags + "/" + all);
    try {//from  w  ww . j  ava  2  s.co  m
        String gitSpace = System.getProperty("git.repos");
        File dir = new File(gitSpace);
        if (!dir.exists()) {
            throw new RpcException(ERROR_FROM_METHOD, 100, "GitService.gitSpace not exists");
        }
        List<Map> resList = new ArrayList<Map>();
        File[] chld = dir.listFiles();
        FS fs = FS.detect();
        for (int i = 0; i < chld.length; i++) {
            File file = chld[i];
            String fileName = file.getName();
            if (!all && hasStoreCfg(file) == false) {
                continue;
            }
            debug("\n---------------->" + fileName);
            Map map = new HashMap();
            if (flags != null && flags.contains("updateAvailable")) {
                Git gitObject = Git.open(new File(gitSpace, fileName));
                map.put("updateAvailable", updateAvailable(gitObject));
            }
            if (flags != null && flags.contains("isModified")) {
                Git gitObject = Git.open(new File(gitSpace, fileName));
                map.put("isModified", isModified(gitObject));
            }
            debug(fileName);
            FileBasedConfig fbc = new FileBasedConfig(new File(gitSpace + "/" + fileName + "/.git/config"), fs);
            fbc.load();
            debug("FBC:" + fbc);
            debug("FBC:" + fbc.getSections());
            debug("FBC:" + fbc.toText());
            String created = fbc.getString("sw", null, "created");
            SimpleDateFormat sdf = new SimpleDateFormat(m_datePattern, Locale.GERMAN);
            map.put("name", fileName);
            if (created != null) {
                map.put("created", sdf.parse(created).getTime());
            }
            resList.add(map);
        }
        return resList;
    } catch (Exception e) {
        if (e instanceof RpcException)
            throw (RpcException) e;
        throw new RpcException(ERROR_FROM_METHOD, INTERNAL_SERVER_ERROR, "GitService.getRepositories:", e);
    } finally {
    }
}