Indexer.java revision 222c232d357e358bf67bd0685b8331b71bb56f97
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*
* Portions Copyright 2011 Jens Elkner.
*/
/**
* Creates and updates an inverted source index as well as generates Xref, file
* stats etc., if specified in the options
*/
public final class Indexer {
/* tunables for -r (history for remote repositories) */
private static final String DERBY_EMBEDDED_DRIVER
= "org.apache.derby.jdbc.EmbeddedDriver";
private static final String DERBY_CLIENT_DRIVER
= "org.apache.derby.jdbc.ClientDriver";
public static Indexer getInstance() {
return index;
}
private static void A_usage() {
}
/**
* Program entry point
*
* @param argv argument vector
*/
@SuppressWarnings("PMD.UseStringBufferForStringAppends")
boolean runIndex = true;
boolean update = true;
boolean optimizedChanged = false;
} else {
boolean searchRepositories = false;
boolean addProjects = false;
boolean refreshHistory = false;
boolean listFiles = false;
boolean listRepos = false;
boolean createDict = false;
// Parse command line options:
try {
} catch (ParseException ex) {
}
try {
int cmd;
// We need to read the configuration file first, since we
// will try to overwrite options..
if (cmd == 'R') {
break;
}
}
cfg = new Configuration();
}
// Now we can handle all the other options..
switch (cmd) {
case 'A': {
boolean prefix = false;
A_usage();
}
prefix = true;
} else {
A_usage();
}
if (prefix) {
} else {
}
break;
}
if (prefix) {
try {
arg[0],
} catch (Exception e) {
}
} else {
try {
arg[0],
} catch (Exception e) {
}
}
}
break;
case 'a':
cfg.setAllowLeadingWildcard(true);
cfg.setAllowLeadingWildcard(false);
} else {
}
break;
case 'B':
break;
case 'C':
cfg.setPrintProgress(true);
break;
case 'c':
break;
case 'D':
cfg.setHistoryCacheInDB(true);
break;
case 'd': {
}
if (!dataRoot.isDirectory()) {
}
break;
}
case 'e':
cfg.setGenerateHtml(false);
break;
case 'G':
cfg.setTagsEnabled(true);
break;
case 'H':
refreshHistory = true;
break;
case 'h':
break;
case 'I':
break;
case 'i':
break;
case 'j':
// Should be a full class name, but we also accept
// the shorthands "client" and "embedded". Expand
// the shorthands here.
switch (databaseDriver) {
case "client":
break;
case "embedded":
break;
}
break;
case 'K':
listRepos = true;
break;
case 'k':
break;
case 'L':
break;
case 'l':
cfg.setUsingLuceneLocking(true);
cfg.setUsingLuceneLocking(false);
} else {
}
break;
case 'm': {
try {
} catch (NumberFormatException exp) {
}
break;
}
case 'N':
break;
case 'n':
runIndex = false;
break;
case 'O': {
cfg.setOptimizeDatabase(true);
cfg.setOptimizeDatabase(false);
} else {
}
optimizedChanged = true;
}
break;
}
case 'o':
+ "' not found for the -o option");
}
+ "options for ctags: " + CTagsExtraOptionsFile);
break;
case 'P':
addProjects = true;
break;
case 'p':
break;
case 'Q':
cfg.setQuickContextScan(true);
cfg.setQuickContextScan(false);
} else {
System.err.println(" Ex: \"-Q on\" will just scan a \"chunk\" of the file and insert \"[..all..]\"");
System.err.println(" \"-Q off\" will try to build a more accurate list by reading the complete file.");
}
break;
case 'q':
cfg.setVerbose(false);
break;
case 'R':
// already handled
break;
case 'r':
} else {
System.err.println("ERROR: You should pass either \"on\" or \"off\" or \"uionly\" as argument to -r");
+ "only for repositories which allow getting history for directories");
}
break;
case 'S':
searchRepositories = true;
break;
case 's': {
if (!sourceRoot.isDirectory()) {
}
break;
}
case 'T':
try {
} catch (NumberFormatException exp) {
+ exp.getMessage());
}
break;
case 't':
try {
} catch (NumberFormatException exp) {
+ exp.getMessage());
}
break;
case 'U':
break;
case 'u':
break;
case 'V':
break;
case 'v':
cfg.setVerbose(true);
break;
case 'W':
break;
case 'w': {
}
} else {
}
}
break;
case 'X':
break;
case 'z':
try {
} catch (NumberFormatException exp) {
+ exp.getMessage());
}
break;
case '?':
break;
default:
}
}
try {
}
} catch (Exception e) {
// don't care
}
}
//logging starts here
}
}
if (cfg.isHistoryCacheInDB()) {
// The default database driver is Derby's client driver.
if (databaseDriver == null) {
}
// The default URL depends on the database driver.
if (databaseURL == null) {
} else {
}
}
}
// automatically allow symlinks that are directly in source root
if (projectDirs != null) {
}
}
}
}
// Assemble the unprocessed command line arguments (possibly
// a list of paths). This will be used to perform more fine
// grained checking in invalidateRepositories().
if (optind != -1) {
}
}
// Set updated configuration in RuntimeEnvironment.
/*
* Add paths to directories under source root. If projects
* are enabled the path should correspond to a project because
* project path is necessary to correctly set index directory
* (otherwise the index files will end up in index data root
* directory and not per project data root directory).
* For the check we need to have 'env' already set.
*/
if (env.hasProjects()) {
// The paths need to correspond to a project.
} else {
+ " does not correspond to a project");
}
} else {
}
}
}
// Issue a warning when JDBC is used with renamed file handling.
// This causes heavy slowdown when used with JavaDB (issue #774).
+ "handling is on - possible performance degradation");
}
// Get history first.
return;
}
// And now index it all.
progress);
}
// Finally send new configuration to the web application.
} catch (IndexerException ex) {
} catch (Throwable e) {
} finally {
}
}
}
/*
* 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).
*
* PMD wants us to use length() > 0 && charAt(0) instead of startsWith()
* for performance. We prefer clarity over performance here, so silence it.
*/
@SuppressWarnings("PMD.SimplifyStartsWith")
boolean searchRepositories,
boolean addProjects,
boolean refreshHistory,
boolean listFiles,
boolean createDict,
throw new IndexerException("ERROR: Please specify a DATA ROOT path");
}
throw new IndexerException("ERROR: please specify a SRC_ROOT with option -s !");
}
throw new IndexerException("Didn't find Exuberant Ctags");
}
throw new IndexerException("Internal error, zapCache shouldn't be null");
}
if (listRepoPaths) {
return;
}
}
}
boolean all = false;
all = true;
break;
}
}
}
if (all) {
}
}
try {
} catch (HistoryException e) {
}
}
return;
}
}
if (addProjects) {
// Keep a copy of the old project list so that we can preserve
// the customization of existing projects.
}
// Add a project for each top-level directory in source root.
// This is an existing object. Reuse the old project,
// possibly with customizations, instead of creating a
// new with default values.
// Found a new directory with no matching project, so
// create a new project with default properties.
p.setDescription(name);
}
}
// The projects should be sorted...
int ret;
} else {
}
return ret;
}
});
}
if (defaultProject != null) {
env.setDefaultProject(p);
break;
}
}
}
if (configFilename != null) {
}
if (refreshHistory) {
}
if (listFiles) {
}
if (createDict) {
}
}
/*
* This is the second phase of the indexer which generates Lucene index
* by passing source code files through Exuberant ctags, generating xrefs
* and storing data from the source files in the index (along with history,
* if any).
*/
throws IOException {
if (update) {
} else if (env.isOptimizeDatabase()) {
}
} else {
} else {
db = new IndexDatabase();
} else {
}
if (idx != -1) {
}
if (idx == -1) {
}
} else {
}
}
}
public void run() {
try {
if (update) {
} else if (optimize) {
}
} catch (Throwable e) {
+ " index", e);
}
}
});
}
}
while (!executor.isTerminated()) {
try {
// Wait forever
} catch (InterruptedException exp) {
}
}
try {
// It can happen that history index is not done in prepareIndexer()
// but via db.update() above in which case we must make sure the
// thread pool for renamed file handling is destroyed.
} catch (InterruptedException ex) {
"destroying of renamed thread pool failed", ex);
}
}
if (configHost != null) {
try {
}
} else {
}
}
}
}
private Indexer() {
}
}