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(); }
/** Reads the file contents from the currently checked out branch */ protected FileContents doRead(Git git, File rootDir, String branch, String pathOrEmpty) throws IOException, GitAPIException { checkoutBranch(git, branch); String path = Strings.isBlank(pathOrEmpty) ? "/" : pathOrEmpty; File file = getFile(rootDir, path); if (file.isFile()) { String contents = IOHelper.readFully(file); return new FileContents(false, contents, null); } else { List<FileInfo> children = new ArrayList<FileInfo>(); if (file.exists()) { File[] files = file.listFiles(); for (File child : files) { if (!isIgnoreFile(child)) { children.add(FileInfo.createFileInfo(rootDir, child)); } } } return new FileContents(file.isDirectory(), null, children); } }