@Override public boolean hasRepository(String repositoryPath) { String uid = StringUtils.sha1(repositoryPath.replace("\\", "/")); EntityManager em = getEntityManager(); TypedQuery<Long> query = em.createNamedQuery("RepositoryDB.countByUid", Long.class); query.setParameter("uid", uid); return ((Long) query.getSingleResult() != 0); }
@Override public List<FileDB> getCommitedFiles(CommitDB commitDb) { commands.set(5, commitDb.getName()); processBuilder.command(commands); Process process = null; try { process = processBuilder.start(); BufferedReader buffer = new BufferedReader(new InputStreamReader(process.getInputStream())); String str = null; List<FileDB> files = new ArrayList<FileDB>(); buffer.readLine(); // skips the first line while ((str = buffer.readLine()) != null) { String parts[] = str.split( "\t"); // parts[0] - lines added, parts[1] - lines removed, parts[2] - file path int linesAdded = -1; int linesRemoved = -1; String path = repositoryPath + "/" + parts[2]; if (!parts[0].equals("-")) { linesAdded = Integer.parseInt(parts[0]); } if (!parts[1].equals("-")) { linesRemoved = Integer.parseInt(parts[1]); } FileDB fileDb = new FileDB(0, path, StringUtils.sha1(path)); FileXCommitDB fileXCommit = new FileXCommitDB( new FileXCommitPK(0, commitDb.getId()), linesAdded, linesRemoved, false); if (getData(commitDb.getName(), parts[2]) == null) { fileXCommit.setRemoved(true); } List<FileXCommitDB> filesXCommits = new ArrayList<FileXCommitDB>(1); filesXCommits.add(fileXCommit); fileDb.setFileXCommits(filesXCommits); files.add(fileDb); } buffer.close(); return files; } catch (IOException e) { throw new VisMinerAPIException(e.getMessage(), e); } }
@Override public List<String> getSnapshotFiles(String commitUid) { try { RevCommit lastCommit = revWalk.parseCommit(repository.resolve(commitUid)); treeWalk.reset(); treeWalk.addTree(lastCommit.getTree()); treeWalk.setRecursive(true); List<String> files = new ArrayList<String>(); while (treeWalk.next()) { String path = repositoryPath + "/" + treeWalk.getPathString(); files.add(StringUtils.sha1(path)); } return files; } catch (IOException e) { throw new VisMinerAPIException(e.getMessage(), e); } }
@Override public RepositoryDB findByPath(String path) { String uid = StringUtils.sha1(path.replace("\\", "/")); return findByUid(uid); }
// Generate unique id for software units private String generateUid(String repositoryPath, String parentName, String softwareUnitName) { String uid = repositoryPath + parentName + softwareUnitName; return StringUtils.sha1(uid); }