Search in sources :

Example 46 with RuntimeEnvironment

use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class IndexDatabase method optimizeAll.

/**
     * Optimize all index databases
     *
     * @param executor An executor to run the job
     * @throws IOException if an error occurs
     */
static void optimizeAll(ExecutorService executor) throws IOException {
    List<IndexDatabase> dbs = new ArrayList<>();
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    if (env.hasProjects()) {
        for (Project project : env.getProjects()) {
            dbs.add(new IndexDatabase(project));
        }
    } else {
        dbs.add(new IndexDatabase());
    }
    for (IndexDatabase d : dbs) {
        final IndexDatabase db = d;
        if (db.isDirty()) {
            executor.submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        db.update();
                    } catch (Throwable e) {
                        LOGGER.log(Level.SEVERE, "Problem updating lucene index database: ", e);
                    }
                }
            });
        }
    }
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) ArrayList(java.util.ArrayList)

Example 47 with RuntimeEnvironment

use of org.opensolaris.opengrok.configuration.RuntimeEnvironment 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)

Example 48 with RuntimeEnvironment

use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class Util method readableLine.

public static void readableLine(int num, Writer out, Annotation annotation, String userPageLink, String userPageSuffix, String project, boolean skipNewline) throws IOException {
    // this method should go to JFlexXref
    String snum = String.valueOf(num);
    if (num > 1 && !skipNewline) {
        out.write("\n");
    }
    out.write(anchorClassStart);
    out.write(num % 10 == 0 ? "hl" : "l");
    out.write("\" name=\"");
    out.write(snum);
    out.write("\" href=\"#");
    out.write(snum);
    out.write(closeQuotedTag);
    out.write(snum);
    out.write(anchorEnd);
    if (annotation != null) {
        String r = annotation.getRevision(num);
        boolean enabled = annotation.isEnabled(num);
        out.write("<span class=\"blame\">");
        if (enabled) {
            out.write(anchorClassStart);
            out.write("r");
            if (annotation.getFileVersion(r) != 0) {
                /*
                        version number, 1 is the most recent
                        generates css classes version_color_n
                     */
                int versionNumber = Math.max(1, annotation.getFileVersionsCount() - annotation.getFileVersion(r) + 1);
                out.write(" version_color_" + versionNumber);
            }
            out.write("\" href=\"");
            out.write(URIEncode(annotation.getFilename()));
            out.write("?a=true&amp;r=");
            out.write(URIEncode(r));
            String msg = annotation.getDesc(r);
            out.write("\" title=\"");
            if (msg != null) {
                out.write(msg);
            }
            if (annotation.getFileVersion(r) != 0) {
                out.write("&lt;br/&gt;version: " + annotation.getFileVersion(r) + "/" + annotation.getRevisions().size());
            }
            out.write(closeQuotedTag);
        }
        StringBuilder buf = new StringBuilder();
        htmlize(r, buf);
        out.write(buf.toString());
        buf.setLength(0);
        if (enabled) {
            RuntimeEnvironment env = RuntimeEnvironment.getInstance();
            out.write(anchorEnd);
            // Write link to search the revision in current project.
            out.write(anchorClassStart);
            out.write("search\" href=\"" + env.getUrlPrefix());
            out.write("defs=&amp;refs=&amp;path=");
            out.write(project);
            out.write("&amp;hist=&quot;" + URIEncode(r) + "&quot;");
            out.write("&amp;type=\" title=\"Search history for this changeset");
            out.write(closeQuotedTag);
            out.write("S");
            out.write(anchorEnd);
        }
        String a = annotation.getAuthor(num);
        if (userPageLink == null) {
            out.write(HtmlConsts.SPAN_A);
            htmlize(a, buf);
            out.write(buf.toString());
            out.write(HtmlConsts.ZSPAN);
            buf.setLength(0);
        } else {
            out.write(anchorClassStart);
            out.write("a\" href=\"");
            out.write(userPageLink);
            out.write(URIEncode(a));
            if (userPageSuffix != null) {
                out.write(userPageSuffix);
            }
            out.write(closeQuotedTag);
            htmlize(a, buf);
            out.write(buf.toString());
            buf.setLength(0);
            out.write(anchorEnd);
        }
        out.write("</span>");
    }
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment)

Example 49 with RuntimeEnvironment

use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class MercurialRepository method getHistory.

@Override
History getHistory(File file, String sinceRevision) throws HistoryException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    // Note that the filtering of revisions based on sinceRevision is done
    // in the history log executor by passing appropriate options to
    // the 'hg' executable.
    // This is done only for directories since if getHistory() is used
    // for file, the file is renamed and its complete history is fetched
    // so no sinceRevision filter is needed.
    // See findOriginalName() code for more details.
    History result = new MercurialHistoryParser(this).parse(file, sinceRevision);
    // because we know it :-)
    if (env.isTagsEnabled()) {
        assignTagsInHistory(result);
    }
    return result;
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment)

Example 50 with RuntimeEnvironment

use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class MonotoneHistoryParser method processStream.

/**
 * Process the output from the hg log command and insert the HistoryEntries
 * into the history field.
 *
 * @param input The output from the process
 * @throws java.io.IOException If an error occurs while reading the stream
 */
@Override
public void processStream(InputStream input) throws IOException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    DateFormat df = repository.getDateFormat();
    BufferedReader in = new BufferedReader(new InputStreamReader(input));
    String s;
    HistoryEntry entry = null;
    int state = 0;
    while ((s = in.readLine()) != null) {
        s = s.trim();
        // the minimum amount for maximum compatibility between monotone versions.
        if (s.startsWith("-----------------------------------------------------------------")) {
            if (entry != null && state > 2) {
                entries.add(entry);
            }
            entry = new HistoryEntry();
            entry.setActive(true);
            state = 0;
            continue;
        }
        switch(state) {
            case 0:
                if (s.startsWith("Revision:")) {
                    String rev = s.substring("Revision:".length()).trim();
                    entry.setRevision(rev);
                    ++state;
                }
                break;
            case 1:
                if (s.startsWith("Author:")) {
                    entry.setAuthor(s.substring("Author:".length()).trim());
                    ++state;
                }
                break;
            case 2:
                if (s.startsWith("Date:")) {
                    Date date = new Date();
                    try {
                        date = df.parse(s.substring("date:".length()).trim());
                    } catch (ParseException pe) {
                        // 
                        throw new IOException("Could not parse date: " + s, pe);
                    }
                    entry.setDate(date);
                    ++state;
                }
                break;
            case 3:
                if (s.startsWith("Modified ") || s.startsWith("Added ") || s.startsWith("Deleted ")) {
                    ++state;
                } else if (s.equalsIgnoreCase("ChangeLog:")) {
                    state = 5;
                }
                break;
            case 4:
                if (s.startsWith("Modified ") || s.startsWith("Added ") || s.startsWith("Deleted ")) {
                // NOPMD
                /* swallow */
                } else if (s.equalsIgnoreCase("ChangeLog:")) {
                    state = 5;
                } else {
                    String[] files = s.split(" ");
                    for (String f : files) {
                        File file = new File(mydir, f);
                        try {
                            String path = env.getPathRelativeToSourceRoot(file);
                            entry.addFile(path.intern());
                        } catch (ForbiddenSymlinkException e) {
                            LOGGER.log(Level.FINER, e.getMessage());
                        // ignore
                        } catch (FileNotFoundException e) {
                        // NOPMD
                        // If the file is not located under the source root, ignore it
                        }
                    }
                }
                break;
            case 5:
                entry.appendMessage(s);
                break;
            default:
                LOGGER.warning("Unknown parser state: " + state);
                break;
        }
    }
    if (entry != null && state > 2) {
        entries.add(entry);
    }
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) InputStreamReader(java.io.InputStreamReader) ForbiddenSymlinkException(org.opensolaris.opengrok.util.ForbiddenSymlinkException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Date(java.util.Date) DateFormat(java.text.DateFormat) BufferedReader(java.io.BufferedReader) ParseException(java.text.ParseException) File(java.io.File)

Aggregations

RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)81 File (java.io.File)31 Project (org.opensolaris.opengrok.configuration.Project)27 IOException (java.io.IOException)23 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)17 TestRepository (org.opensolaris.opengrok.util.TestRepository)13 ForbiddenSymlinkException (org.opensolaris.opengrok.util.ForbiddenSymlinkException)12 BeforeClass (org.junit.BeforeClass)11 Ctags (org.opensolaris.opengrok.analysis.Ctags)6 BufferedReader (java.io.BufferedReader)5 FileNotFoundException (java.io.FileNotFoundException)5 InputStreamReader (java.io.InputStreamReader)5 ParseException (java.text.ParseException)5 DateFormat (java.text.DateFormat)4 Date (java.util.Date)4 RepositoryInfo (org.opensolaris.opengrok.history.RepositoryInfo)4 OutputStreamWriter (java.io.OutputStreamWriter)3 ConnectException (java.net.ConnectException)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3