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);
}
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();
}
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());
}
}
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("&");
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("<br/>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("&");
out.write(QueryParameters.REFS_SEARCH_PARAM_EQ);
out.write("&");
out.write(QueryParameters.PATH_SEARCH_PARAM_EQ);
out.write(project);
out.write("&");
out.write(QueryParameters.HIST_SEARCH_PARAM_EQ);
out.write(""");
out.write(uriEncode(r));
out.write(""&");
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>");
}
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()));
}
Aggregations