use of org.opengrok.indexer.search.DirectoryEntry in project OpenGrok by OpenGrok.
the class FileExtraZipper method zip.
/**
* Merge the specified lists by looking up a possible entry in
* {@code extras} for every element in {@code files}.
* @param dir the files' directory
* @param files the file names
* @param extras some OpenGrok-analyzed extra metadata
* @return a list of the same size as {@code files}
*/
public List<DirectoryEntry> zip(File dir, List<String> files, List<NullableNumLinesLOC> extras) {
if (extras == null) {
return files.stream().map(f -> new DirectoryEntry(new File(dir, f))).collect(Collectors.toList());
}
Map<String, NullableNumLinesLOC> byName = indexExtraByName(extras);
List<DirectoryEntry> result = new ArrayList<>(files.size());
for (String file : files) {
File fileobj = new File(dir, file);
NullableNumLinesLOC extra = findExtra(byName, fileobj);
DirectoryEntry entry = new DirectoryEntry(fileobj, extra);
result.add(entry);
}
return result;
}
use of org.opengrok.indexer.search.DirectoryEntry in project OpenGrok by OpenGrok.
the class DirectoryListingTest method directoryListingWithEftarException.
@Test
public void directoryListingWithEftarException() throws IOException, HistoryException {
EftarFileReader mockReader = mock(EftarFileReader.class);
when(mockReader.getNode(anyString())).thenThrow(IOException.class);
DirectoryListing instance = new DirectoryListing(mockReader);
File file = new File(directory, "foo");
StringWriter mockWriter = spy(StringWriter.class);
instance.extraListTo("ctx", directory, mockWriter, directory.getPath(), Collections.singletonList(new DirectoryEntry(file)));
verify(mockWriter, atLeast(20)).write(anyString());
}
use of org.opengrok.indexer.search.DirectoryEntry in project OpenGrok by OpenGrok.
the class DirectoryListing method extraListTo.
/**
* Write a HTML-ized listing of the given directory to the given destination.
*
* @param contextPath path used for link prefixes
* @param dir the directory to list
* @param out write destination
* @param path virtual path of the directory (usually the path name of
* <var>dir</var> with the source root directory stripped off).
* @param entries basenames of potential children of the directory to list,
* but filtered by {@link PathAccepter}.
* @return a possible empty list of README files included in the written
* listing.
* @throws IOException when cannot write to the {@code out} parameter
* @throws HistoryException when failed to get last modified time for files in directory
*/
public List<String> extraListTo(String contextPath, File dir, Writer out, String path, List<DirectoryEntry> entries) throws IOException, HistoryException {
// TODO this belongs to a jsp, not here
ArrayList<String> readMes = new ArrayList<>();
int offset = -1;
EftarFileReader.FNode parentFNode = null;
if (desc != null) {
try {
parentFNode = desc.getNode(path);
} catch (IOException e) {
LOGGER.log(Level.WARNING, String.format("cannot get Eftar node for path ''%s''", path), e);
}
if (parentFNode != null) {
offset = parentFNode.getChildOffset();
}
}
out.write("<table id=\"dirlist\" class=\"tablesorter tablesorter-default\">\n");
out.write("<thead>\n");
out.write("<tr>\n");
out.write("<th class=\"sorter-false\"></th>\n");
out.write("<th>Name</th>\n");
out.write("<th class=\"sorter-false\"></th>\n");
out.write("<th class=\"sort-dates\">Date</th>\n");
out.write("<th class=\"sort-groksizes\">Size</th>\n");
out.write("<th>#Lines</th>\n");
out.write("<th>LOC</th>\n");
if (offset > 0) {
out.write("<th><samp>Description</samp></th>\n");
}
out.write("</tr>\n</thead>\n<tbody>\n");
PathAccepter pathAccepter = RuntimeEnvironment.getInstance().getPathAccepter();
Format dateFormatter = new SimpleDateFormat("dd-MMM-yyyy", Locale.getDefault());
// Print the '..' entry even for empty directories.
if (path.length() != 0) {
out.write("<tr><td><p class=\"'r'\"/></td><td>");
out.write("<b><a href=\"..\">..</a></b></td><td></td>");
printDateSize(out, dir.getParentFile(), null, dateFormatter);
out.write("</tr>\n");
}
Map<String, Date> modTimes = HistoryGuru.getInstance().getLastModifiedTimes(dir);
if (entries != null) {
for (DirectoryEntry entry : entries) {
File child = entry.getFile();
if (!pathAccepter.accept(child)) {
continue;
}
String filename = child.getName();
String filenameLower = filename.toLowerCase(Locale.ROOT);
if (filenameLower.startsWith("readme") || filenameLower.endsWith("readme")) {
readMes.add(filename);
}
boolean isDir = child.isDirectory();
out.write("<tr><td>");
out.write("<p class=\"");
out.write(isDir ? 'r' : 'p');
out.write("\"/>");
out.write("</td><td><a href=\"");
if (isDir) {
String longpath = getSimplifiedPath(child);
out.write(Util.uriEncodePath(longpath));
out.write("/\"><b>");
int idx;
if ((idx = longpath.lastIndexOf('/')) > 0) {
out.write("<span class=\"simplified-path\">");
out.write(longpath.substring(0, idx + 1));
out.write("</span>");
out.write(longpath.substring(idx + 1));
} else {
out.write(longpath);
}
out.write("</b></a>/");
} else {
out.write(Util.uriEncodePath(filename));
out.write("\">");
out.write(filename);
out.write("</a>");
}
out.write("</td>");
Util.writeHAD(out, contextPath, path + filename, isDir);
printDateSize(out, child, modTimes.get(filename), dateFormatter);
printNumlines(out, entry, isDir);
printLoc(out, entry, isDir);
if (offset > 0) {
String briefDesc = desc.getChildTag(parentFNode, filename);
if (briefDesc == null) {
out.write("<td/>");
} else {
out.write("<td>");
out.write(briefDesc);
out.write("</td>");
}
}
out.write("</tr>\n");
}
}
out.write("</tbody>\n</table>");
return readMes;
}
Aggregations