List of usage examples for org.eclipse.jgit.lib StoredConfig getInt
public int getInt(final String section, final String name, final int defaultValue)
From source file:com.gitblit.authority.GitblitAuthority.java
License:Apache License
private void setSizeAndPosition() { String sz = null;// w w w . j av a 2s. c o m String pos = null; try { StoredConfig config = getConfig(); sz = config.getString("ui", null, "size"); pos = config.getString("ui", null, "position"); defaultDuration = config.getInt("new", "duration", 365); } catch (Throwable t) { t.printStackTrace(); } // try to restore saved window size if (StringUtils.isEmpty(sz)) { setSize(900, 600); } else { String[] chunks = sz.split("x"); int width = Integer.parseInt(chunks[0]); int height = Integer.parseInt(chunks[1]); setSize(width, height); } // try to restore saved window position if (StringUtils.isEmpty(pos)) { setLocationRelativeTo(null); } else { String[] chunks = pos.split(","); int x = Integer.parseInt(chunks[0]); int y = Integer.parseInt(chunks[1]); setLocation(x, y); } }
From source file:com.pieceof8.gradle.snapshot.GitScmProvider.java
License:Apache License
/** {@inheritDoc} */ @Override/*from w w w. j ava 2s . c om*/ @SneakyThrows(IOException.class) public Commit getCommit() { if (repoDir == null) { throw new IllegalArgumentException("'repoDir' must not be null"); } FileRepositoryBuilder builder = new FileRepositoryBuilder(); @Cleanup Repository repo = builder.setGitDir(repoDir).readEnvironment().findGitDir().build(); StoredConfig conf = repo.getConfig(); int abbrev = Commit.ABBREV_LENGTH; if (conf != null) { abbrev = conf.getInt("core", "abbrev", abbrev); } val sdf = new SimpleDateFormat(extension.getDateFormat()); val HEAD = repo.getRef(Constants.HEAD); if (HEAD == null) { val msg = "Could not get HEAD Ref, the repository may be corrupt."; throw new RuntimeException(msg); } RevWalk revWalk = new RevWalk(repo); if (HEAD.getObjectId() == null) { val msg = "Could not find any commits from HEAD ref."; throw new RuntimeException(msg); } RevCommit commit = revWalk.parseCommit(HEAD.getObjectId()); revWalk.markStart(commit); try { // git commit time in sec and java datetime is in ms val commitTime = new Date(commit.getCommitTime() * 1000L); val ident = commit.getAuthorIdent(); return new Commit(sdf.format(new Date()), // build time conf.getString("user", null, "name"), conf.getString("user", null, "email"), repo.getBranch(), commit.getName(), sdf.format(commitTime), ident.getName(), ident.getEmailAddress(), commit.getFullMessage().trim()); } finally { revWalk.dispose(); } }
From source file:me.cmoz.gradle.snapshot.GitSCMCommand.java
License:Apache License
@Override @SneakyThrows(IOException.class) public Commit getLatestCommit(@NonNull final String dateFormat) { if (repoDir == null) { throw new IllegalStateException("'.git' folder could not be found."); }// w ww.jav a 2s . c om final FileRepositoryBuilder builder = new FileRepositoryBuilder(); final Repository repo = builder.setGitDir(repoDir).readEnvironment().build(); final StoredConfig conf = repo.getConfig(); int abbrev = Commit.ABBREV_LENGTH; if (conf != null) { abbrev = conf.getInt("core", "abbrev", abbrev); } final SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); final Ref HEAD = repo.getRef(Constants.HEAD); if (HEAD.getObjectId() == null) { throw new RuntimeException("Could not find any commits from HEAD ref."); } final RevWalk revWalk = new RevWalk(repo); if (HEAD.getObjectId() == null) { throw new RuntimeException("Could not find any commits from HEAD ref."); } final RevCommit revCommit = revWalk.parseCommit(HEAD.getObjectId()); revWalk.markStart(revCommit); try { // git commit time in sec and java datetime is in ms final Date commitTime = new Date(revCommit.getCommitTime() * 1000L); final PersonIdent ident = revCommit.getAuthorIdent(); final UserConfig userConf = conf.get(UserConfig.KEY); return Commit.builder().buildTime(sdf.format(new Date())).buildAuthorName(userConf.getAuthorName()) .buildAuthorEmail(userConf.getAuthorEmail()).branchName(repo.getBranch()) .commitId(revCommit.getName()).commitTime(sdf.format(commitTime)) .commitUserName(ident.getName()).commitUserEmail(ident.getEmailAddress()) .commitMessage(revCommit.getFullMessage().trim()).build(); } finally { revWalk.dispose(); repo.close(); } }