use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class WebappListener method checkIndex.
/**
* Checks the index(es). If projects are enabled then each project with invalid index
* is marked as not being indexed.
* @param env runtime environment
*/
private void checkIndex(RuntimeEnvironment env) {
if (env.isProjectsEnabled()) {
Map<String, Project> projects = env.getProjects();
File indexRoot = new File(env.getDataRootPath(), IndexDatabase.INDEX_DIR);
if (indexRoot.exists()) {
LOGGER.log(Level.FINE, "Checking indexes for all projects");
for (Map.Entry<String, Project> projectEntry : projects.entrySet()) {
try {
IndexCheck.checkDir(new File(indexRoot, projectEntry.getKey()));
} catch (Exception e) {
LOGGER.log(Level.WARNING, String.format("Project %s index check failed, marking as not indexed", projectEntry.getKey()), e);
projectEntry.getValue().setIndexed(false);
}
}
LOGGER.log(Level.FINE, "Index check for all projects done");
}
} else {
LOGGER.log(Level.FINE, "Checking index");
try {
IndexCheck.checkDir(new File(env.getDataRootPath(), IndexDatabase.INDEX_DIR));
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "index check failed", e);
}
LOGGER.log(Level.FINE, "Index check done");
}
}
use of org.opengrok.indexer.configuration.Project 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.Project in project OpenGrok by OpenGrok.
the class Indexer method addProjects.
private void addProjects(File[] files, Map<String, Project> projects) {
// Keep a copy of the old project list so that we can preserve
// the customization of existing projects.
Map<String, Project> oldProjects = new HashMap<>();
for (Project p : projects.values()) {
oldProjects.put(p.getName(), p);
}
projects.clear();
// Add a project for each top-level directory in source root.
for (File file : files) {
String name = file.getName();
String path = '/' + name;
if (oldProjects.containsKey(name)) {
// This is an existing object. Reuse the old project,
// possibly with customizations, instead of creating a
// new with default values.
Project p = oldProjects.get(name);
p.setPath(path);
p.setName(name);
p.completeWithDefaults();
projects.put(name, p);
} else if (!name.startsWith(".") && file.isDirectory()) {
// Found a new directory with no matching project, so
// create a new project with default properties.
projects.put(name, new Project(name, path));
}
}
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class Indexer method prepareIndexer.
/**
* Generate history cache and/or scan the repositories.
*
* This is the first phase of the indexing where history cache is being
* generated for repositories (at least for those which support getting
* history per directory).
*
* @param env runtime environment
* @param searchPaths list of paths in which to search for repositories
* @param addProjects if true, add projects
* @param createDict if true, create dictionary
* @param createHistoryCache create history cache flag
* @param subFiles list of directories
* @param repositories list of repositories
* @throws IndexerException indexer exception
* @throws IOException I/O exception
*/
public void prepareIndexer(RuntimeEnvironment env, Set<String> searchPaths, boolean addProjects, boolean createDict, boolean createHistoryCache, List<String> subFiles, List<String> repositories) throws IndexerException, IOException {
if (!env.validateUniversalCtags()) {
throw new IndexerException("Didn't find Universal Ctags");
}
// some project properties might be needed for that.
if (addProjects) {
File[] files = env.getSourceRootFile().listFiles();
Map<String, Project> projects = env.getProjects();
addProjects(files, projects);
}
if (!searchPaths.isEmpty()) {
LOGGER.log(Level.INFO, "Scanning for repositories in {0}...", searchPaths);
Statistics stats = new Statistics();
env.setRepositories(searchPaths.toArray(new String[0]));
stats.report(LOGGER, String.format("Done scanning for repositories, found %d repositories", env.getRepositories().size()), "indexer.repository.scan");
}
if (createHistoryCache) {
// Even if history is disabled globally, it can be enabled for some repositories.
if (repositories != null && !repositories.isEmpty()) {
LOGGER.log(Level.INFO, "Generating history cache for repositories: {0}", String.join(",", repositories));
HistoryGuru.getInstance().createCache(repositories);
} else {
LOGGER.log(Level.INFO, "Generating history cache for all repositories ...");
HistoryGuru.getInstance().createCache();
}
LOGGER.info("Done generating history cache");
}
if (createDict) {
IndexDatabase.listFrequentTokens(subFiles);
}
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class PluginClassLoaderTest method testTruePlugin.
@Test
public void testTruePlugin() {
PluginClassLoader instance = new PluginClassLoader(pluginDirectory);
Class<?> clazz = loadClass(instance, "opengrok.auth.plugin.TruePlugin");
IAuthorizationPlugin plugin = getNewInstance(clazz);
Group g = new Group("group1");
Project p = new Project("project1");
assertTrue(plugin.isAllowed(new DummyHttpServletRequest(), g));
assertTrue(plugin.isAllowed(new DummyHttpServletRequest(), p));
}
Aggregations