protected List<CommitInfo> doHistory( Git git, String branch, String objectId, String path, int limit) { Repository r = git.getRepository(); CommitFinder finder = new CommitFinder(r); CommitListFilter block = new CommitListFilter(); if (Strings.isNotBlank(path)) { finder.setFilter(PathFilterUtils.and(path)); } finder.setFilter(block); if (limit > 0) { finder.setFilter(new CommitLimitFilter(100).setStop(true)); } if (Strings.isNotBlank(objectId)) { finder.findFrom(objectId); } else { if (Strings.isNotBlank(branch)) { RevCommit base = CommitUtils.getBase(r, branch); finder.findFrom(base); } else { finder.find(); } } List<RevCommit> commits = block.getCommits(); List<CommitInfo> results = new ArrayList<CommitInfo>(); for (RevCommit entry : commits) { CommitInfo commitInfo = createCommitInfo(entry); results.add(commitInfo); } return results; }
protected String doReadJsonChildContent( Git git, File rootDir, String branch, String path, String fileNameWildcard, String search) throws GitAPIException, IOException { checkoutBranch(git, branch); File file = getFile(rootDir, path); FileFilter filter = FileFilters.createFileFilter(fileNameWildcard); boolean first = true; StringBuilder buffer = new StringBuilder("{\n"); List<FileInfo> children = new ArrayList<FileInfo>(); if (file.isDirectory()) { if (file.exists()) { File[] files = file.listFiles(); for (File child : files) { if (!isIgnoreFile(child) && child.isFile()) { String text = IOHelper.readFully(child); if (!Strings.isNotBlank(search) || text.contains(search)) { if (first) { first = false; } else { buffer.append(",\n"); } buffer.append("\""); buffer.append(child.getName()); buffer.append("\": "); buffer.append(text); children.add(FileInfo.createFileInfo(rootDir, child)); } } } } } buffer.append("\n}"); return buffer.toString(); }
protected Class<?> tryFindClass(String className, String filter) { Class<?> aClass = null; if (Strings.isNotBlank(className) && classNameMatches(className, filter)) { try { aClass = findClass(className); } catch (Throwable e) { LOG.debug("Could not load class " + className + ". " + e, e); } } return aClass; }
/** * Returns the configuration directory; lazily attempting to create it if it does not yet exist */ public File getConfigDirectory() { String dirName = getConfigDir(); File answer = null; if (Strings.isNotBlank(dirName)) { answer = new File(dirName); } else { answer = new File(".hawtio"); } answer.mkdirs(); return answer; }
protected void processDirectoryClassNames( File directory, String packageName, Set<String> classes) { String[] fileNames = directory.list(); if (fileNames != null) { for (String fileName : fileNames) { String packagePrefix = Strings.isNotBlank(packageName) ? packageName + '.' : packageName; if (fileName.endsWith(".class")) { String className = packagePrefix + fileName.substring(0, fileName.length() - 6); classes.add(className); } File subdir = new File(directory, fileName); if (subdir.isDirectory()) { processDirectoryClassNames(subdir, packagePrefix + fileName, classes); } } } }
protected void processDirectory( File directory, String packageName, Set<Class<?>> classes, String filter, Integer limit) { String[] fileNames = directory.list(); if (fileNames != null) { for (String fileName : fileNames) { if (!withinLimit(limit, classes)) { return; } String className = null; String packagePrefix = Strings.isNotBlank(packageName) ? packageName + '.' : packageName; if (fileName.endsWith(".class")) { className = packagePrefix + fileName.substring(0, fileName.length() - 6); } Class<?> aClass = tryFindClass(className, filter); if (aClass != null) { classes.add(aClass); } File subdir = new File(directory, fileName); if (subdir.isDirectory()) { processDirectory(subdir, packagePrefix + fileName, classes, filter, limit); } } } }
protected String doDiff(Git git, String objectId, String baseObjectId, String path) { Repository r = git.getRepository(); /* RevCommit commit = JGitUtils.getCommit(r, objectId); ObjectId current; if (isNotBlank(objectId)) { current = BlobUtils.getId(r, objectId, blobPath); } else { current = CommitUtils.getHead(r).getId(); } ObjectId previous; if (isNotBlank(baseObjectId)) { previous = BlobUtils.getId(r, baseObjectId, blobPath); } else { RevCommit revCommit = CommitUtils.getCommit(r, current); RevCommit[] parents = revCommit.getParents(); if (parents.length == 0) { throw new IllegalArgumentException("No parent commits!"); } else { previous = parents[0]; } } Collection<Edit> changes = BlobUtils.diff(r, previous, current); // no idea how to format Collection<Edit> :) */ RevCommit commit; if (Strings.isNotBlank(objectId)) { commit = CommitUtils.getCommit(r, objectId); } else { commit = CommitUtils.getHead(r); } RevCommit baseCommit = null; if (Strings.isNotBlank(baseObjectId)) { baseCommit = CommitUtils.getCommit(r, baseObjectId); } ByteArrayOutputStream buffer = new ByteArrayOutputStream(); RawTextComparator cmp = RawTextComparator.DEFAULT; DiffFormatter formatter = new DiffFormatter(buffer); formatter.setRepository(r); formatter.setDiffComparator(cmp); formatter.setDetectRenames(true); RevTree commitTree = commit.getTree(); RevTree baseTree; try { if (baseCommit == null) { if (commit.getParentCount() > 0) { final RevWalk rw = new RevWalk(r); RevCommit parent = rw.parseCommit(commit.getParent(0).getId()); rw.dispose(); baseTree = parent.getTree(); } else { // FIXME initial commit. no parent?! baseTree = commitTree; } } else { baseTree = baseCommit.getTree(); } List<DiffEntry> diffEntries = formatter.scan(baseTree, commitTree); if (path != null && path.length() > 0) { for (DiffEntry diffEntry : diffEntries) { if (diffEntry.getNewPath().equalsIgnoreCase(path)) { formatter.format(diffEntry); break; } } } else { formatter.format(diffEntries); } formatter.flush(); return buffer.toString(); } catch (IOException e) { throw new RuntimeIOException(e); } }