use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class Results method prettyPrint.
/**
* Prints out results in html form. The following search helper fields are
* required to be properly initialized: <ul>
* <li>{@link SearchHelper#dataRoot}</li>
* <li>{@link SearchHelper#contextPath}</li>
* <li>{@link SearchHelper#searcher}</li> <li>{@link SearchHelper#hits}</li>
* <li>{@link SearchHelper#historyContext} (ignored if {@code null})</li>
* <li>{@link SearchHelper#sourceContext} (ignored if {@code null})</li>
* <li>{@link SearchHelper#summarizer} (if sourceContext is not
* {@code null})</li> <li>{@link SearchHelper#sourceRoot} (if
* sourceContext or historyContext is not {@code null})</li> </ul>
*
* @param out write destination
* @param sh search helper which has all required fields set
* @param start index of the first hit to print
* @param end index of the last hit to print
* @throws HistoryException history exception
* @throws IOException I/O exception
* @throws ClassNotFoundException class not found
*/
public static void prettyPrint(Writer out, SearchHelper sh, int start, long end) throws HistoryException, IOException, ClassNotFoundException {
Project p;
String contextPath = sh.getContextPath();
String ctxE = Util.uriEncodePath(contextPath);
String xrefPrefix = contextPath + Prefix.XREF_P;
String morePrefix = contextPath + Prefix.MORE_P;
String xrefPrefixE = ctxE + Prefix.XREF_P;
File xrefDataDir = new File(sh.getDataRoot(), Prefix.XREF_P.toString());
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
boolean evenRow = true;
out.write("<tbody class=\"search-result\">");
for (Map.Entry<String, ArrayList<Integer>> entry : createMap(sh.getSearcher(), sh.getHits(), start, end).entrySet()) {
String parent = entry.getKey();
out.write("<tr class=\"dir\"><td colspan=\"3\"><a href=\"");
out.write(xrefPrefixE);
out.write(Util.uriEncodePath(parent));
out.write("/\">");
out.write(htmlize(parent));
out.write("/</a>");
if (sh.getDesc() != null) {
out.write(" - <i>");
out.write(sh.getDesc().get(parent));
out.write("</i>");
}
p = Project.getProject(parent);
String messages = MessagesUtils.messagesToJson(p, MESSAGES_MAIN_PAGE_TAG);
if (p != null && !messages.isEmpty()) {
out.write(" <a href=\"" + xrefPrefix + "/" + p.getName() + "\">");
out.write("<span class=\"note-" + MessagesUtils.getMessageLevel(p.getName(), MESSAGES_MAIN_PAGE_TAG) + " important-note important-note-rounded\" data-messages='" + messages + "'>!</span>");
out.write("</a>");
}
int tabSize = sh.getTabSize(p);
PrintPlainFinalArgs fargs = new PrintPlainFinalArgs(out, sh, env, xrefPrefix, tabSize, morePrefix);
out.write("</td></tr>");
for (int docId : entry.getValue()) {
Document doc = sh.getSearcher().doc(docId);
String rpath = doc.get(QueryBuilder.PATH);
String rpathE = Util.uriEncodePath(rpath);
if (evenRow) {
out.write("<tr class=\"search-result-even-row\">");
} else {
out.write("<tr>");
}
evenRow = !evenRow;
Util.writeHAD(out, sh.getContextPath(), rpathE, false);
out.write("<td class=\"f\"><a href=\"");
out.write(xrefPrefixE);
out.write(rpathE);
out.write("\"");
if (env.isLastEditedDisplayMode()) {
printLastEditedDate(out, doc);
}
out.write(">");
out.write(htmlize(rpath.substring(rpath.lastIndexOf('/') + 1)));
out.write("</a>");
out.write("</td><td><code class=\"con\">");
if (sh.getSourceContext() != null) {
AbstractAnalyzer.Genre genre = AbstractAnalyzer.Genre.get(doc.get(QueryBuilder.T));
Summarizer summarizer = sh.getSummarizer();
if (AbstractAnalyzer.Genre.XREFABLE == genre && summarizer != null) {
String xtags = getTags(xrefDataDir, rpath, env.isCompressXref());
// FIXME use Highlighter from lucene contrib here,
// instead of summarizer, we'd also get rid of
// apache lucene in whole source ...
out.write(summarizer.getSummary(xtags).toString());
} else if (AbstractAnalyzer.Genre.HTML == genre && summarizer != null) {
String htags = getTags(sh.getSourceRoot(), rpath, false);
out.write(summarizer.getSummary(htags).toString());
} else if (genre == AbstractAnalyzer.Genre.PLAIN) {
printPlain(fargs, doc, docId, rpath);
}
}
HistoryContext historyContext = sh.getHistoryContext();
if (historyContext != null) {
historyContext.getContext(new File(sh.getSourceRoot(), rpath), rpath, out, sh.getContextPath());
}
out.write("</code></td></tr>\n");
}
}
out.write("</tbody>");
}
use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class AuthorizationEntityTest method testForGroupsAndForProjectsDiscovery.
@ParameterizedTest
@MethodSource("parameters")
public void testForGroupsAndForProjectsDiscovery(Function<Void, AuthorizationEntity> authEntityFactory) {
Group g1, g2, g3;
AuthorizationEntity authEntity;
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
env.setProjectsEnabled(true);
env.getProjects().put("project 1", new Project("project 1"));
env.getProjects().put("project 2", new Project("project 2"));
env.getProjects().put("project 3", new Project("project 3"));
env.getProjects().put("project 4", new Project("project 4"));
env.getProjects().put("project 5", new Project("project 5"));
env.getProjects().put("project 6", new Project("project 6"));
env.getProjects().put("project 7", new Project("project 7"));
env.getProjects().put("project 8", new Project("project 8"));
env.getProjects().put("project 9", new Project("project 9"));
/**
* Structure<br>
* <pre>
* G1 + P1
* + P2
* + P3
* + G2
* + P4
* + P5
* + P6
* + P7
* G3 + P8
* + P9
* </pre>
*/
g1 = new Group();
g1.setName("group 1");
g1.addProject(env.getProjects().get("project 1"));
g1.addProject(env.getProjects().get("project 2"));
g1.addProject(env.getProjects().get("project 3"));
env.getGroups().add(g1);
g2 = new Group();
g2.setName("group 2");
g2.addProject(env.getProjects().get("project 4"));
g2.addProject(env.getProjects().get("project 5"));
g2.addProject(env.getProjects().get("project 6"));
g2.addProject(env.getProjects().get("project 7"));
g1.addGroup(g2);
env.getGroups().add(g2);
g3 = new Group();
g3.setName("group 3");
g3.addProject(env.getProjects().get("project 8"));
g3.addProject(env.getProjects().get("project 9"));
env.getGroups().add(g3);
// add g1 and all descendants their projects
authEntity = authEntityFactory.apply(null);
authEntity.setForGroups(new TreeSet<>());
authEntity.setForGroups("group 1");
authEntity.load(new TreeMap<>());
assertEquals(new TreeSet<>(Arrays.asList("group 1", "group 2")), authEntity.forGroups());
assertEquals(new TreeSet<>(Arrays.asList("project 1", "project 2", "project 3", "project 4", "project 5", "project 6", "project 7")), authEntity.forProjects());
// add group2, its parent g1 and g2 projects
authEntity = authEntityFactory.apply(null);
authEntity.setForGroups(new TreeSet<>());
authEntity.setForGroups("group 2");
authEntity.load(new TreeMap<>());
assertEquals(new TreeSet<>(Arrays.asList("group 1", "group 2")), authEntity.forGroups());
assertEquals(new TreeSet<>(Arrays.asList("project 4", "project 5", "project 6", "project 7")), authEntity.forProjects());
// add only g3 and its projects
authEntity = authEntityFactory.apply(null);
authEntity.setForGroups(new TreeSet<>());
authEntity.setForGroups("group 3");
authEntity.load(new TreeMap<>());
assertEquals(new TreeSet<>(Collections.singletonList("group 3")), authEntity.forGroups());
assertEquals(new TreeSet<>(Arrays.asList("project 8", "project 9")), authEntity.forProjects());
}
use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class AuthorizationEntityTest method setUp.
@BeforeEach
public void setUp() {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
envGroups = env.getGroups();
envProjects = env.getProjects();
env.setGroups(new TreeSet<>());
env.setProjects(new TreeMap<>());
}
use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class AuthorizationEntityTest method testForGroupsAndForProjectsDiscoveryInvalidProjectInGroup.
/**
* Listed projects in the group don't exist.
*/
@ParameterizedTest
@MethodSource("parameters")
public void testForGroupsAndForProjectsDiscoveryInvalidProjectInGroup(Function<Void, AuthorizationEntity> authEntityFactory) {
AuthorizationEntity authEntity = authEntityFactory.apply(null);
authEntity.setForGroups(new TreeSet<>(Arrays.asList("group 1", "group 2")));
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
Group g1 = new Group();
g1.setName("group 1");
g1.addProject(new Project("project 1"));
g1.addProject(new Project("project 2"));
g1.addProject(new Project("project 3"));
env.getGroups().add(g1);
authEntity.load(new TreeMap<>());
assertEquals(new TreeSet<>(Collections.singletonList("group 1")), authEntity.forGroups());
assertEquals(new TreeSet<>(), authEntity.forProjects());
}
use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class MessagesUtils method getMessageLevel.
/**
* @param tags message tags
* @return name of highest cssClass of messages present in the system or null.
*/
public static String getMessageLevel(String... tags) {
Set<MessagesContainer.AcceptedMessage> messages;
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
messages = Arrays.stream(tags).map(env::getMessages).flatMap(Collection::stream).collect(Collectors.toSet());
return getHighestMessageLevel(messages);
}
Aggregations