use of org.opensolaris.opengrok.index.IgnoredNames in project OpenGrok by OpenGrok.
the class DirectoryListing method listTo.
/**
* Write a htmlized 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 opengrok source directory stripped off).
* @param files 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> listTo(String contextPath, File dir, Writer out, String path, List<String> files) 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");
if (offset > 0) {
out.write("<th><tt>Description</tt></th>\n");
}
out.write("</tr>\n</thead>\n<tbody>\n");
IgnoredNames ignoredNames = RuntimeEnvironment.getInstance().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 (files != null) {
for (String file : files) {
if (ignoredNames.ignore(file)) {
continue;
}
File child = new File(dir, file);
if (ignoredNames.ignore(child)) {
continue;
}
if (file.startsWith("README") || file.endsWith("README") || file.startsWith("readme")) {
readMes.add(file);
}
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(file));
out.write("\">");
out.write(file);
out.write("</a>");
}
out.write("</td>");
Util.writeHAD(out, contextPath, path + file, isDir);
printDateSize(out, child, modTimes.get(file), dateFormatter);
if (offset > 0) {
String briefDesc = desc.getChildTag(parentFNode, file);
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.index.IgnoredNames in project OpenGrok by OpenGrok.
the class DirectoryListing method getSimplifiedPath.
/**
* Traverse directory until subdirectory with more than one item
* (other than directory) or end of path is reached.
* @param dir directory to traverse
* @return string representing path with empty directories or the name of the directory
*/
private static String getSimplifiedPath(File dir) {
String[] files = dir.list();
// Permissions can prevent getting list of items in the directory.
if (files == null)
return dir.getName();
if (files.length == 1) {
File entry = new File(dir, files[0]);
IgnoredNames ignoredNames = RuntimeEnvironment.getInstance().getIgnoredNames();
if (!ignoredNames.ignore(entry) && entry.isDirectory()) {
return (dir.getName() + "/" + getSimplifiedPath(entry));
}
}
return dir.getName();
}
use of org.opensolaris.opengrok.index.IgnoredNames 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.index.IgnoredNames in project OpenGrok by OpenGrok.
the class ConfigurationHelp method getSampleValue.
private static Object getSampleValue(Method setter, Object defaultValue) {
Class paramType = setter.getParameterTypes()[0];
Type genType = setter.getGenericParameterTypes()[0];
if (setter.getName().equals("setBugPattern")) {
return "Sample Bug \\#(\\d+)";
} else if (setter.getName().equals("setReviewPattern")) {
return "Sample Issue \\#(\\d+)";
} else if (paramType == String.class) {
return "user-specified-value";
} else if (paramType == int.class) {
return 1 + (int) defaultValue;
} else if (paramType == short.class) {
return (short) (1 + (short) defaultValue);
} else if (paramType == boolean.class) {
if (defaultValue == null)
return null;
return !(boolean) defaultValue;
} else if (paramType == double.class) {
return 1 + (double) defaultValue;
} else if (paramType == List.class) {
return getSampleListValue(genType);
} else if (paramType == Map.class) {
return getSampleMapValue(genType);
} else if (paramType == Set.class) {
return getSampleSetValue(genType);
} else if (paramType == AuthorizationStack.class) {
AuthorizationStack astck = new AuthorizationStack(AuthControlFlag.REQUIRED, "user-specified-value");
astck.add(new AuthorizationPlugin(AuthControlFlag.REQUISITE, "user-specified-value"));
return astck;
} else if (paramType == Filter.class) {
Filter flt = new Filter();
flt.add("user-specified-(patterns)*");
flt.add("user-specified-filename");
flt.add("user/specified/path");
return flt;
} else if (paramType == IgnoredNames.class) {
IgnoredNames inm = new IgnoredNames();
inm.add("f:user-specified-value");
inm.add("d:user-specified-value");
return inm;
} else if (paramType.isEnum()) {
for (Object value : paramType.getEnumConstants()) {
if (!value.equals(defaultValue))
return value;
}
return null;
} else {
throw new UnsupportedOperationException("getSampleValue() for " + paramType + ", " + genType);
}
}
use of org.opensolaris.opengrok.index.IgnoredNames in project OpenGrok by OpenGrok.
the class FileUtilities method getAllFiles.
public static void getAllFiles(File root, List<File> files, boolean directories) {
assertNotNull(files);
if (directories) {
files.add(root);
}
IgnoredNames ignore = RuntimeEnvironment.getInstance().getIgnoredNames();
for (File f : root.listFiles()) {
if (!ignore.ignore(f)) {
if (f.isDirectory()) {
getAllFiles(f, files, directories);
} else {
files.add(f);
}
}
}
}
Aggregations