Search in sources :

Example 1 with RuntimeEnvironment

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

the class AnalyzerGuru method writeXref.

/**
 * Write a browse-able version of the file.
 *
 * @param factory The analyzer factory for this file type
 * @param in The input stream containing the data
 * @param out Where to write the result
 * @param defs definitions for the source file, if available
 * @param annotation Annotation information for the file
 * @param project Project the file belongs to
 * @throws java.io.IOException If an error occurs while creating the output
 */
public static void writeXref(AnalyzerFactory factory, Reader in, Writer out, Definitions defs, Annotation annotation, Project project) throws IOException {
    Reader input = in;
    if (factory.getGenre() == AbstractAnalyzer.Genre.PLAIN) {
        // This is some kind of text file, so we need to expand tabs to
        // spaces to match the project's tab settings.
        input = ExpandTabsReader.wrap(in, project);
    }
    WriteXrefArgs args = new WriteXrefArgs(input, out);
    args.setDefs(defs);
    args.setAnnotation(annotation);
    args.setProject(project);
    AbstractAnalyzer analyzer = factory.getAnalyzer();
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    analyzer.setScopesEnabled(env.isScopesEnabled());
    analyzer.setFoldingEnabled(env.isFoldingEnabled());
    analyzer.writeXref(args);
}
Also used : RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) HistoryReader(org.opengrok.indexer.history.HistoryReader)

Example 2 with RuntimeEnvironment

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

the class MandocRunner method start.

/**
 * Starts a run of the mandoc binary to receive input from {@link #write}.
 * @throws IOException thrown if a read or write to the mandoc process
 * fails.
 * @throws MandocException if no mandoc binary is defined
 */
public void start() throws IOException, MandocException {
    destroy();
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    String binary = env.getMandoc();
    if (binary == null) {
        throw new MandocException("no mandoc binary is defined");
    }
    List<String> command = new ArrayList<>();
    command.add(binary);
    // do not use `more`
    command.add("-c");
    // explicitly set the output encoding
    command.add("-Kutf-8");
    // Produce HTML5, CSS1, and MathML output
    command.add("-Thtml");
    // HTML fragment only
    command.add("-Ofragment");
    // Override the default operating system name
    String oo = osOverride;
    if (oo != null) {
        command.add("-I");
        command.add("os=" + oo);
    }
    if (LOGGER.isLoggable(Level.FINER)) {
        StringBuilder sb = new StringBuilder();
        command.forEach(s -> sb.append(s).append(" "));
        String cmd = sb.toString();
        LOGGER.log(Level.FINER, "Executing mandoc command [{0}]", cmd);
    }
    ProcessBuilder processBuilder = new ProcessBuilder(command);
    Process starting = processBuilder.start();
    OutputStreamWriter inn = new OutputStreamWriter(starting.getOutputStream(), StandardCharsets.UTF_8);
    BufferedReader rdr = new BufferedReader(new InputStreamReader(starting.getInputStream(), StandardCharsets.UTF_8));
    InputStream errorStream = starting.getErrorStream();
    mandocIn = inn;
    mandocOut = rdr;
    mandoc = starting;
    errThread = new Thread(() -> {
        // implicitly capture `errorStream' for the InputStreamReader
        try (BufferedReader error = new BufferedReader(new InputStreamReader(errorStream, StandardCharsets.UTF_8))) {
            String s;
            while ((s = error.readLine()) != null) {
                LOGGER.log(Level.WARNING, "Error from mandoc: {0}", s);
            }
        } catch (IOException ex) {
        // ignore
        }
    });
    errThread.setDaemon(true);
    errThread.start();
}
Also used : RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter)

Example 3 with RuntimeEnvironment

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

the class CSharpAnalyzerFactoryTest method setUpClass.

@BeforeAll
public static void setUpClass() throws Exception {
    ctags = new Ctags();
    repository = new TestRepository();
    repository.create(CSharpAnalyzerFactoryTest.class.getClassLoader().getResource("sources"));
    CSharpAnalyzerFactory analFact = new CSharpAnalyzerFactory();
    analyzer = analFact.getAnalyzer();
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    if (env.validateUniversalCtags()) {
        analyzer.setCtags(new Ctags());
    }
}
Also used : TestRepository(org.opengrok.indexer.util.TestRepository) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Ctags(org.opengrok.indexer.analysis.Ctags) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with RuntimeEnvironment

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

the class Util method writeAnnotation.

private static void writeAnnotation(int num, Writer out, Annotation annotation, String userPageLink, String userPageSuffix, String project) throws IOException {
    String r = annotation.getRevision(num);
    boolean enabled = annotation.isEnabled(num);
    out.write("<span class=\"blame\">");
    if (enabled) {
        out.write(anchorClassStart);
        out.write("r");
        out.write("\" style=\"background-color: ");
        out.write(annotation.getColors().getOrDefault(r, "inherit"));
        out.write("\" href=\"");
        out.write(uriEncode(annotation.getFilename()));
        out.write("?");
        out.write(QueryParameters.ANNOTATION_PARAM_EQ_TRUE);
        out.write("&amp;");
        out.write(QueryParameters.REVISION_PARAM_EQ);
        out.write(uriEncode(r));
        String msg = annotation.getDesc(r);
        out.write("\" title=\"");
        if (msg != null) {
            out.write(Util.encode(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();
    final boolean most_recent_revision = annotation.getFileVersion(r) == annotation.getRevisions().size();
    // print an asterisk for the most recent revision
    if (most_recent_revision) {
        buf.append("<span class=\"most_recent_revision\">");
        buf.append('*');
    }
    htmlize(r, buf);
    if (most_recent_revision) {
        // recent revision span
        buf.append("</span>");
    }
    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(QueryParameters.DEFS_SEARCH_PARAM_EQ);
        out.write("&amp;");
        out.write(QueryParameters.REFS_SEARCH_PARAM_EQ);
        out.write("&amp;");
        out.write(QueryParameters.PATH_SEARCH_PARAM_EQ);
        out.write(project);
        out.write("&amp;");
        out.write(QueryParameters.HIST_SEARCH_PARAM_EQ);
        out.write("&quot;");
        out.write(uriEncode(r));
        out.write("&quot;&amp;");
        out.write(QueryParameters.TYPE_SEARCH_PARAM_EQ);
        out.write("\" title=\"Search history for this revision");
        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.opengrok.indexer.configuration.RuntimeEnvironment)

Example 5 with RuntimeEnvironment

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

the class SearchEngineTest method setUpClass.

@BeforeAll
public static void setUpClass() throws Exception {
    repository = new TestRepository();
    repository.create(HistoryGuru.class.getResource("/repositories"));
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    RepositoryFactory.initializeIgnoredNames(env);
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    env.setHistoryEnabled(false);
    Indexer.getInstance().prepareIndexer(env, true, true, false, null, null);
    env.setDefaultProjectsFromNames(new TreeSet<>(Collections.singletonList("/c")));
    Indexer.getInstance().doIndexerExecution(true, null, null);
    configFile = File.createTempFile("configuration", ".xml");
    env.writeConfiguration(configFile);
    RuntimeEnvironment.getInstance().readConfiguration(new File(configFile.getAbsolutePath()));
}
Also used : TestRepository(org.opengrok.indexer.util.TestRepository) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) HistoryGuru(org.opengrok.indexer.history.HistoryGuru) File(java.io.File) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)81 File (java.io.File)26 Project (org.opengrok.indexer.configuration.Project)24 Test (org.junit.jupiter.api.Test)22 IOException (java.io.IOException)18 BeforeAll (org.junit.jupiter.api.BeforeAll)13 ArrayList (java.util.ArrayList)12 TestRepository (org.opengrok.indexer.util.TestRepository)12 Path (java.nio.file.Path)8 ForbiddenSymlinkException (org.opengrok.indexer.util.ForbiddenSymlinkException)8 Document (org.apache.lucene.document.Document)6 Ctags (org.opengrok.indexer.analysis.Ctags)6 Executor (org.opengrok.indexer.util.Executor)6 BufferedReader (java.io.BufferedReader)5 FileNotFoundException (java.io.FileNotFoundException)5 InputStreamReader (java.io.InputStreamReader)5 EnabledForRepository (org.opengrok.indexer.condition.EnabledForRepository)5 HistoryGuru (org.opengrok.indexer.history.HistoryGuru)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)4