Search in sources :

Example 1 with DirectoryEntry

use of org.opensolaris.opengrok.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<FileExtra> extras) {
    if (extras == null) {
        return files.stream().map(f -> new DirectoryEntry(new File(dir, f))).collect(Collectors.toList());
    }
    Map<String, FileExtra> byName = indexExtraByName(extras);
    List<DirectoryEntry> result = new ArrayList<>(files.size());
    for (String file : files) {
        File fileobj = new File(dir, file);
        FileExtra extra = findExtra(byName, fileobj);
        DirectoryEntry entry = new DirectoryEntry(fileobj, extra);
        result.add(entry);
    }
    return result;
}
Also used : FileExtra(org.opensolaris.opengrok.search.FileExtra) List(java.util.List) Map(java.util.Map) DirectoryEntry(org.opensolaris.opengrok.search.DirectoryEntry) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) File(java.io.File) ArrayList(java.util.ArrayList) FileExtra(org.opensolaris.opengrok.search.FileExtra) ArrayList(java.util.ArrayList) DirectoryEntry(org.opensolaris.opengrok.search.DirectoryEntry) File(java.io.File)

Example 2 with DirectoryEntry

use of org.opensolaris.opengrok.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.
 *  Gets filtered by {@link IgnoredNames}.
 * @return a possible empty list of README files included in the written
 *  listing.
 * @throws org.opensolaris.opengrok.history.HistoryException when we cannot
 * get result from SCM
 *
 * @throws java.io.IOException when any I/O problem
 * @throws NullPointerException if a parameter except <var>files</var>
 *  is {@code null}
 */
public List<String> extraListTo(String contextPath, File dir, Writer out, String path, List<DirectoryEntry> entries) throws HistoryException, IOException {
    // TODO this belongs to a jsp, not here
    ArrayList<String> readMes = new ArrayList<>();
    int offset = -1;
    EftarFileReader.FNode parentFNode = null;
    if (desc != null) {
        parentFNode = desc.getNode(path);
        if (parentFNode != null) {
            offset = parentFNode.childOffset;
        }
    }
    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><tt>Description</tt></th>\n");
    }
    out.write("</tr>\n</thead>\n<tbody>\n");
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    IgnoredNames ignoredNames = env.getIgnoredNames();
    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 (ignoredNames.ignore(child)) {
                continue;
            }
            String filename = child.getName();
            if (filename.startsWith("README") || filename.endsWith("README") || filename.startsWith("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);
            printLoc(out, entry);
            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;
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) ArrayList(java.util.ArrayList) IgnoredNames(org.opensolaris.opengrok.index.IgnoredNames) DirectoryEntry(org.opensolaris.opengrok.search.DirectoryEntry) Date(java.util.Date) Format(java.text.Format) SimpleDateFormat(java.text.SimpleDateFormat) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File)

Aggregations

File (java.io.File)2 ArrayList (java.util.ArrayList)2 DirectoryEntry (org.opensolaris.opengrok.search.DirectoryEntry)2 Format (java.text.Format)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)1 IgnoredNames (org.opensolaris.opengrok.index.IgnoredNames)1 FileExtra (org.opensolaris.opengrok.search.FileExtra)1