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);
}
}
});
}
}
}
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;
}
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&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("<br/>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=&refs=&path=");
out.write(project);
out.write("&hist="" + URIEncode(r) + """);
out.write("&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>");
}
}
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;
}
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);
}
}
Aggregations