@Test public void testMain() { System.out.println("Generate index by using command line options"); RuntimeEnvironment env = RuntimeEnvironment.getInstance(); String[] argv = {"-S", "-P", "-H", "-Q", "off", "-s", repository.getSourceRoot(), "-d", repository.getDataRoot(), "-v", "-c", env.getCtags()}; Indexer.main(argv); }
@SuppressWarnings("PMD.UseStringBufferForStringAppends") public static void main(String[] argv) { Statistics stats = new Statistics(); boolean update = true; Executor.registerErrorHandler(); ArrayList<String> subFiles = new ArrayList<>(); ArrayList<String> subFilesList = new ArrayList<>(); boolean createDict = false; try { argv = parseOptions(argv); disabledRepositories.addAll(cfg.getDisabledRepositories()); cfg.setDisabledRepositories(disabledRepositories); for (String repoName : disabledRepositories) { LOGGER.log(Level.FINEST, "Disabled {0}", repoName); } if (help) { exitWithHelp(); } checkConfiguration(); if (awaitProfiler) { pauseToAwaitProfiler(); } env = RuntimeEnvironment.getInstance(); List<Class<? extends Repository>> repositoryClasses = RepositoryFactory.getRepositoryClasses(); for (Class<? extends Repository> clazz : repositoryClasses) { try { Field f = clazz.getDeclaredField("CMD_PROPERTY_KEY"); Object key = f.get(null); if (key != null) { cfg.setRepoCmd(clazz.getCanonicalName(), System.getProperty(key.toString())); } } catch (Exception e) { } } if (verbose) { String fn = LoggerUtil.getFileHandlerPattern(); if (fn != null) { System.out.println("Logging filehandler pattern: " + fn); } } String file = cfg.getSourceRoot(); if (file != null) { File sourceRootFile = new File(file); File[] projectDirs = sourceRootFile.listFiles(); if (projectDirs != null) { for (File projectDir : projectDirs) { if (!projectDir.getCanonicalPath().equals(projectDir.getAbsolutePath())) { allowedSymlinks.add(projectDir.getAbsolutePath()); } } } } allowedSymlinks.addAll(cfg.getAllowedSymlinks()); cfg.setAllowedSymlinks(allowedSymlinks); canonicalRoots.addAll(cfg.getCanonicalRoots()); cfg.setCanonicalRoots(canonicalRoots); for (String arg : argv) { String path = Paths.get(cfg.getSourceRoot(), arg).toString(); subFilesList.add(path); } for (Entry<String, Project> entry : cfg.getProjects().entrySet()) { if (entry.getValue().getName() == null) { entry.getValue().setName(entry.getKey()); } } env.setConfiguration(cfg, subFilesList, CommandTimeoutType.INDEXER); if (checkIndexVersion) { if (cfg == null) { System.err.println("Need configuration to check index version (use -R)"); System.exit(1); } try { IndexVersion.check(subFilesList); } catch (IndexVersionException e) { System.err.printf("Index version check failed: %s\n", e); System.err.print("You might want to remove " + (subFilesList.size() > 0 ? "data for projects " + String.join(",", subFilesList) : "all data") + " under the DATA_ROOT and to reindex\n"); status = 1; System.exit(status); } } RepositoryFactory.initializeIgnoredNames(env); if (bareConfig) { getInstance().sendToConfigHost(env, webappURI); writeConfigToFile(env, configFilename); System.exit(0); } for (String path : subFilesList) { String srcPath = env.getSourceRootPath(); if (srcPath == null) { System.err.println("Error getting source root from environment. Exiting."); System.exit(1); } path = path.substring(srcPath.length()); if (env.hasProjects()) { Project project; if ((project = Project.getProject(path)) != null) { subFiles.add(path); List<RepositoryInfo> repoList = env.getProjectRepositoriesMap().get(project); if (repoList != null) { repositories.addAll(repoList. stream().map(RepositoryInfo::getDirectoryNameRelative).collect(Collectors.toSet())); } } else { System.err.println("The path " + path + " does not correspond to a project"); } } else { subFiles.add(path); } } if (!subFilesList.isEmpty() && subFiles.isEmpty()) { System.err.println("None of the paths were added, exiting"); System.exit(1); } if (addProjects && webappURI != null) { try { IndexerUtil.enableProjects(webappURI); } catch (Exception e) { LOGGER.log(Level.SEVERE, String.format("Couldn't notify the webapp on %s.", webappURI), e); System.err.println(String.format("Couldn't notify the webapp on %s: %s.", webappURI, e.getLocalizedMessage())); } } LOGGER.log(Level.INFO, "Indexer version {0} ({1}) running on Java {2}", new Object[]{Info.getVersion(), Info.getRevision(), System.getProperty("java.version")}); if (searchRepositories) { if (searchPaths.isEmpty()) { String[] dirs = env.getSourceRootFile(). list((f, name) -> f.isDirectory() && env.getPathAccepter().accept(f)); if (dirs != null) { searchPaths.addAll(Arrays.asList(dirs)); } } searchPaths = searchPaths.stream(). map(t -> Paths.get(env.getSourceRootPath(), t).toString()). collect(Collectors.toSet()); } getInstance().prepareIndexer(env, searchPaths, addProjects, createDict, runIndex, subFiles, new ArrayList<>(repositories)); env.setDefaultProjectsFromNames(defaultProjects); if (runIndex || (optimizedChanged && env.isOptimizeDatabase())) { IndexChangedListener progress = new DefaultIndexChangedListener(); getInstance().doIndexerExecution(update, subFiles, progress); } writeConfigToFile(env, configFilename); if (webappURI != null) { if (!subFiles.isEmpty()) { getInstance().refreshSearcherManagers(env, subFiles, webappURI); } else { getInstance().sendToConfigHost(env, webappURI); } } env.getIndexerParallelizer().bounce(); } catch (ParseException e) { System.err.println("** " + e.getMessage()); System.exit(1); } catch (IndexerException ex) { LOGGER.log(Level.SEVERE, "Exception running indexer", ex); System.err.println("Exception: " + ex.getLocalizedMessage()); System.err.println(optParser.getUsage()); System.exit(1); } catch (Throwable e) { LOGGER.log(Level.SEVERE, "Unexpected Exception", e); System.err.println("Exception: " + e.getLocalizedMessage()); System.exit(1); } finally { stats.report(LOGGER); } }
Indexer { @SuppressWarnings("PMD.UseStringBufferForStringAppends") public static void main(String[] argv) { Statistics stats = new Statistics(); boolean update = true; Executor.registerErrorHandler(); ArrayList<String> subFiles = new ArrayList<>(); ArrayList<String> subFilesList = new ArrayList<>(); boolean createDict = false; try { argv = parseOptions(argv); disabledRepositories.addAll(cfg.getDisabledRepositories()); cfg.setDisabledRepositories(disabledRepositories); for (String repoName : disabledRepositories) { LOGGER.log(Level.FINEST, "Disabled {0}", repoName); } if (help) { exitWithHelp(); } checkConfiguration(); if (awaitProfiler) { pauseToAwaitProfiler(); } env = RuntimeEnvironment.getInstance(); List<Class<? extends Repository>> repositoryClasses = RepositoryFactory.getRepositoryClasses(); for (Class<? extends Repository> clazz : repositoryClasses) { try { Field f = clazz.getDeclaredField("CMD_PROPERTY_KEY"); Object key = f.get(null); if (key != null) { cfg.setRepoCmd(clazz.getCanonicalName(), System.getProperty(key.toString())); } } catch (Exception e) { } } if (verbose) { String fn = LoggerUtil.getFileHandlerPattern(); if (fn != null) { System.out.println("Logging filehandler pattern: " + fn); } } String file = cfg.getSourceRoot(); if (file != null) { File sourceRootFile = new File(file); File[] projectDirs = sourceRootFile.listFiles(); if (projectDirs != null) { for (File projectDir : projectDirs) { if (!projectDir.getCanonicalPath().equals(projectDir.getAbsolutePath())) { allowedSymlinks.add(projectDir.getAbsolutePath()); } } } } allowedSymlinks.addAll(cfg.getAllowedSymlinks()); cfg.setAllowedSymlinks(allowedSymlinks); canonicalRoots.addAll(cfg.getCanonicalRoots()); cfg.setCanonicalRoots(canonicalRoots); for (String arg : argv) { String path = Paths.get(cfg.getSourceRoot(), arg).toString(); subFilesList.add(path); } for (Entry<String, Project> entry : cfg.getProjects().entrySet()) { if (entry.getValue().getName() == null) { entry.getValue().setName(entry.getKey()); } } env.setConfiguration(cfg, subFilesList, CommandTimeoutType.INDEXER); if (checkIndexVersion) { if (cfg == null) { System.err.println("Need configuration to check index version (use -R)"); System.exit(1); } try { IndexVersion.check(subFilesList); } catch (IndexVersionException e) { System.err.printf("Index version check failed: %s\n", e); System.err.print("You might want to remove " + (subFilesList.size() > 0 ? "data for projects " + String.join(",", subFilesList) : "all data") + " under the DATA_ROOT and to reindex\n"); status = 1; System.exit(status); } } RepositoryFactory.initializeIgnoredNames(env); if (bareConfig) { getInstance().sendToConfigHost(env, webappURI); writeConfigToFile(env, configFilename); System.exit(0); } for (String path : subFilesList) { String srcPath = env.getSourceRootPath(); if (srcPath == null) { System.err.println("Error getting source root from environment. Exiting."); System.exit(1); } path = path.substring(srcPath.length()); if (env.hasProjects()) { Project project; if ((project = Project.getProject(path)) != null) { subFiles.add(path); List<RepositoryInfo> repoList = env.getProjectRepositoriesMap().get(project); if (repoList != null) { repositories.addAll(repoList. stream().map(RepositoryInfo::getDirectoryNameRelative).collect(Collectors.toSet())); } } else { System.err.println("The path " + path + " does not correspond to a project"); } } else { subFiles.add(path); } } if (!subFilesList.isEmpty() && subFiles.isEmpty()) { System.err.println("None of the paths were added, exiting"); System.exit(1); } if (addProjects && webappURI != null) { try { IndexerUtil.enableProjects(webappURI); } catch (Exception e) { LOGGER.log(Level.SEVERE, String.format("Couldn't notify the webapp on %s.", webappURI), e); System.err.println(String.format("Couldn't notify the webapp on %s: %s.", webappURI, e.getLocalizedMessage())); } } LOGGER.log(Level.INFO, "Indexer version {0} ({1}) running on Java {2}", new Object[]{Info.getVersion(), Info.getRevision(), System.getProperty("java.version")}); if (searchRepositories) { if (searchPaths.isEmpty()) { String[] dirs = env.getSourceRootFile(). list((f, name) -> f.isDirectory() && env.getPathAccepter().accept(f)); if (dirs != null) { searchPaths.addAll(Arrays.asList(dirs)); } } searchPaths = searchPaths.stream(). map(t -> Paths.get(env.getSourceRootPath(), t).toString()). collect(Collectors.toSet()); } getInstance().prepareIndexer(env, searchPaths, addProjects, createDict, runIndex, subFiles, new ArrayList<>(repositories)); env.setDefaultProjectsFromNames(defaultProjects); if (runIndex || (optimizedChanged && env.isOptimizeDatabase())) { IndexChangedListener progress = new DefaultIndexChangedListener(); getInstance().doIndexerExecution(update, subFiles, progress); } writeConfigToFile(env, configFilename); if (webappURI != null) { if (!subFiles.isEmpty()) { getInstance().refreshSearcherManagers(env, subFiles, webappURI); } else { getInstance().sendToConfigHost(env, webappURI); } } env.getIndexerParallelizer().bounce(); } catch (ParseException e) { System.err.println("** " + e.getMessage()); System.exit(1); } catch (IndexerException ex) { LOGGER.log(Level.SEVERE, "Exception running indexer", ex); System.err.println("Exception: " + ex.getLocalizedMessage()); System.err.println(optParser.getUsage()); System.exit(1); } catch (Throwable e) { LOGGER.log(Level.SEVERE, "Unexpected Exception", e); System.err.println("Exception: " + e.getLocalizedMessage()); System.exit(1); } finally { stats.report(LOGGER); } } }
Indexer { @SuppressWarnings("PMD.UseStringBufferForStringAppends") public static void main(String[] argv) { Statistics stats = new Statistics(); boolean update = true; Executor.registerErrorHandler(); ArrayList<String> subFiles = new ArrayList<>(); ArrayList<String> subFilesList = new ArrayList<>(); boolean createDict = false; try { argv = parseOptions(argv); disabledRepositories.addAll(cfg.getDisabledRepositories()); cfg.setDisabledRepositories(disabledRepositories); for (String repoName : disabledRepositories) { LOGGER.log(Level.FINEST, "Disabled {0}", repoName); } if (help) { exitWithHelp(); } checkConfiguration(); if (awaitProfiler) { pauseToAwaitProfiler(); } env = RuntimeEnvironment.getInstance(); List<Class<? extends Repository>> repositoryClasses = RepositoryFactory.getRepositoryClasses(); for (Class<? extends Repository> clazz : repositoryClasses) { try { Field f = clazz.getDeclaredField("CMD_PROPERTY_KEY"); Object key = f.get(null); if (key != null) { cfg.setRepoCmd(clazz.getCanonicalName(), System.getProperty(key.toString())); } } catch (Exception e) { } } if (verbose) { String fn = LoggerUtil.getFileHandlerPattern(); if (fn != null) { System.out.println("Logging filehandler pattern: " + fn); } } String file = cfg.getSourceRoot(); if (file != null) { File sourceRootFile = new File(file); File[] projectDirs = sourceRootFile.listFiles(); if (projectDirs != null) { for (File projectDir : projectDirs) { if (!projectDir.getCanonicalPath().equals(projectDir.getAbsolutePath())) { allowedSymlinks.add(projectDir.getAbsolutePath()); } } } } allowedSymlinks.addAll(cfg.getAllowedSymlinks()); cfg.setAllowedSymlinks(allowedSymlinks); canonicalRoots.addAll(cfg.getCanonicalRoots()); cfg.setCanonicalRoots(canonicalRoots); for (String arg : argv) { String path = Paths.get(cfg.getSourceRoot(), arg).toString(); subFilesList.add(path); } for (Entry<String, Project> entry : cfg.getProjects().entrySet()) { if (entry.getValue().getName() == null) { entry.getValue().setName(entry.getKey()); } } env.setConfiguration(cfg, subFilesList, CommandTimeoutType.INDEXER); if (checkIndexVersion) { if (cfg == null) { System.err.println("Need configuration to check index version (use -R)"); System.exit(1); } try { IndexVersion.check(subFilesList); } catch (IndexVersionException e) { System.err.printf("Index version check failed: %s\n", e); System.err.print("You might want to remove " + (subFilesList.size() > 0 ? "data for projects " + String.join(",", subFilesList) : "all data") + " under the DATA_ROOT and to reindex\n"); status = 1; System.exit(status); } } RepositoryFactory.initializeIgnoredNames(env); if (bareConfig) { getInstance().sendToConfigHost(env, webappURI); writeConfigToFile(env, configFilename); System.exit(0); } for (String path : subFilesList) { String srcPath = env.getSourceRootPath(); if (srcPath == null) { System.err.println("Error getting source root from environment. Exiting."); System.exit(1); } path = path.substring(srcPath.length()); if (env.hasProjects()) { Project project; if ((project = Project.getProject(path)) != null) { subFiles.add(path); List<RepositoryInfo> repoList = env.getProjectRepositoriesMap().get(project); if (repoList != null) { repositories.addAll(repoList. stream().map(RepositoryInfo::getDirectoryNameRelative).collect(Collectors.toSet())); } } else { System.err.println("The path " + path + " does not correspond to a project"); } } else { subFiles.add(path); } } if (!subFilesList.isEmpty() && subFiles.isEmpty()) { System.err.println("None of the paths were added, exiting"); System.exit(1); } if (addProjects && webappURI != null) { try { IndexerUtil.enableProjects(webappURI); } catch (Exception e) { LOGGER.log(Level.SEVERE, String.format("Couldn't notify the webapp on %s.", webappURI), e); System.err.println(String.format("Couldn't notify the webapp on %s: %s.", webappURI, e.getLocalizedMessage())); } } LOGGER.log(Level.INFO, "Indexer version {0} ({1}) running on Java {2}", new Object[]{Info.getVersion(), Info.getRevision(), System.getProperty("java.version")}); if (searchRepositories) { if (searchPaths.isEmpty()) { String[] dirs = env.getSourceRootFile(). list((f, name) -> f.isDirectory() && env.getPathAccepter().accept(f)); if (dirs != null) { searchPaths.addAll(Arrays.asList(dirs)); } } searchPaths = searchPaths.stream(). map(t -> Paths.get(env.getSourceRootPath(), t).toString()). collect(Collectors.toSet()); } getInstance().prepareIndexer(env, searchPaths, addProjects, createDict, runIndex, subFiles, new ArrayList<>(repositories)); env.setDefaultProjectsFromNames(defaultProjects); if (runIndex || (optimizedChanged && env.isOptimizeDatabase())) { IndexChangedListener progress = new DefaultIndexChangedListener(); getInstance().doIndexerExecution(update, subFiles, progress); } writeConfigToFile(env, configFilename); if (webappURI != null) { if (!subFiles.isEmpty()) { getInstance().refreshSearcherManagers(env, subFiles, webappURI); } else { getInstance().sendToConfigHost(env, webappURI); } } env.getIndexerParallelizer().bounce(); } catch (ParseException e) { System.err.println("** " + e.getMessage()); System.exit(1); } catch (IndexerException ex) { LOGGER.log(Level.SEVERE, "Exception running indexer", ex); System.err.println("Exception: " + ex.getLocalizedMessage()); System.err.println(optParser.getUsage()); System.exit(1); } catch (Throwable e) { LOGGER.log(Level.SEVERE, "Unexpected Exception", e); System.err.println("Exception: " + e.getLocalizedMessage()); System.exit(1); } finally { stats.report(LOGGER); } } private  Indexer(); }
Indexer { @SuppressWarnings("PMD.UseStringBufferForStringAppends") public static void main(String[] argv) { Statistics stats = new Statistics(); boolean update = true; Executor.registerErrorHandler(); ArrayList<String> subFiles = new ArrayList<>(); ArrayList<String> subFilesList = new ArrayList<>(); boolean createDict = false; try { argv = parseOptions(argv); disabledRepositories.addAll(cfg.getDisabledRepositories()); cfg.setDisabledRepositories(disabledRepositories); for (String repoName : disabledRepositories) { LOGGER.log(Level.FINEST, "Disabled {0}", repoName); } if (help) { exitWithHelp(); } checkConfiguration(); if (awaitProfiler) { pauseToAwaitProfiler(); } env = RuntimeEnvironment.getInstance(); List<Class<? extends Repository>> repositoryClasses = RepositoryFactory.getRepositoryClasses(); for (Class<? extends Repository> clazz : repositoryClasses) { try { Field f = clazz.getDeclaredField("CMD_PROPERTY_KEY"); Object key = f.get(null); if (key != null) { cfg.setRepoCmd(clazz.getCanonicalName(), System.getProperty(key.toString())); } } catch (Exception e) { } } if (verbose) { String fn = LoggerUtil.getFileHandlerPattern(); if (fn != null) { System.out.println("Logging filehandler pattern: " + fn); } } String file = cfg.getSourceRoot(); if (file != null) { File sourceRootFile = new File(file); File[] projectDirs = sourceRootFile.listFiles(); if (projectDirs != null) { for (File projectDir : projectDirs) { if (!projectDir.getCanonicalPath().equals(projectDir.getAbsolutePath())) { allowedSymlinks.add(projectDir.getAbsolutePath()); } } } } allowedSymlinks.addAll(cfg.getAllowedSymlinks()); cfg.setAllowedSymlinks(allowedSymlinks); canonicalRoots.addAll(cfg.getCanonicalRoots()); cfg.setCanonicalRoots(canonicalRoots); for (String arg : argv) { String path = Paths.get(cfg.getSourceRoot(), arg).toString(); subFilesList.add(path); } for (Entry<String, Project> entry : cfg.getProjects().entrySet()) { if (entry.getValue().getName() == null) { entry.getValue().setName(entry.getKey()); } } env.setConfiguration(cfg, subFilesList, CommandTimeoutType.INDEXER); if (checkIndexVersion) { if (cfg == null) { System.err.println("Need configuration to check index version (use -R)"); System.exit(1); } try { IndexVersion.check(subFilesList); } catch (IndexVersionException e) { System.err.printf("Index version check failed: %s\n", e); System.err.print("You might want to remove " + (subFilesList.size() > 0 ? "data for projects " + String.join(",", subFilesList) : "all data") + " under the DATA_ROOT and to reindex\n"); status = 1; System.exit(status); } } RepositoryFactory.initializeIgnoredNames(env); if (bareConfig) { getInstance().sendToConfigHost(env, webappURI); writeConfigToFile(env, configFilename); System.exit(0); } for (String path : subFilesList) { String srcPath = env.getSourceRootPath(); if (srcPath == null) { System.err.println("Error getting source root from environment. Exiting."); System.exit(1); } path = path.substring(srcPath.length()); if (env.hasProjects()) { Project project; if ((project = Project.getProject(path)) != null) { subFiles.add(path); List<RepositoryInfo> repoList = env.getProjectRepositoriesMap().get(project); if (repoList != null) { repositories.addAll(repoList. stream().map(RepositoryInfo::getDirectoryNameRelative).collect(Collectors.toSet())); } } else { System.err.println("The path " + path + " does not correspond to a project"); } } else { subFiles.add(path); } } if (!subFilesList.isEmpty() && subFiles.isEmpty()) { System.err.println("None of the paths were added, exiting"); System.exit(1); } if (addProjects && webappURI != null) { try { IndexerUtil.enableProjects(webappURI); } catch (Exception e) { LOGGER.log(Level.SEVERE, String.format("Couldn't notify the webapp on %s.", webappURI), e); System.err.println(String.format("Couldn't notify the webapp on %s: %s.", webappURI, e.getLocalizedMessage())); } } LOGGER.log(Level.INFO, "Indexer version {0} ({1}) running on Java {2}", new Object[]{Info.getVersion(), Info.getRevision(), System.getProperty("java.version")}); if (searchRepositories) { if (searchPaths.isEmpty()) { String[] dirs = env.getSourceRootFile(). list((f, name) -> f.isDirectory() && env.getPathAccepter().accept(f)); if (dirs != null) { searchPaths.addAll(Arrays.asList(dirs)); } } searchPaths = searchPaths.stream(). map(t -> Paths.get(env.getSourceRootPath(), t).toString()). collect(Collectors.toSet()); } getInstance().prepareIndexer(env, searchPaths, addProjects, createDict, runIndex, subFiles, new ArrayList<>(repositories)); env.setDefaultProjectsFromNames(defaultProjects); if (runIndex || (optimizedChanged && env.isOptimizeDatabase())) { IndexChangedListener progress = new DefaultIndexChangedListener(); getInstance().doIndexerExecution(update, subFiles, progress); } writeConfigToFile(env, configFilename); if (webappURI != null) { if (!subFiles.isEmpty()) { getInstance().refreshSearcherManagers(env, subFiles, webappURI); } else { getInstance().sendToConfigHost(env, webappURI); } } env.getIndexerParallelizer().bounce(); } catch (ParseException e) { System.err.println("** " + e.getMessage()); System.exit(1); } catch (IndexerException ex) { LOGGER.log(Level.SEVERE, "Exception running indexer", ex); System.err.println("Exception: " + ex.getLocalizedMessage()); System.err.println(optParser.getUsage()); System.exit(1); } catch (Throwable e) { LOGGER.log(Level.SEVERE, "Unexpected Exception", e); System.err.println("Exception: " + e.getLocalizedMessage()); System.exit(1); } finally { stats.report(LOGGER); } } private  Indexer(); static Indexer getInstance(); @SuppressWarnings("PMD.UseStringBufferForStringAppends") static void main(String[] argv); static String[] parseOptions(String[] argv); static void writeConfigToFile(RuntimeEnvironment env, String filename); void prepareIndexer(RuntimeEnvironment env,
                               boolean searchRepositories,
                               boolean addProjects,
                               boolean createDict,
                               List<String> subFiles,
                               List<String> repositories); @SuppressWarnings("PMD.SimplifyStartsWith") void prepareIndexer(RuntimeEnvironment env,
            Set<String> searchPaths,
            boolean addProjects,
            boolean createDict,
            boolean createHistoryCache,
            List<String> subFiles,
            List<String> repositories); void doIndexerExecution(final boolean update, List<String> subFiles,
        IndexChangedListener progress); void refreshSearcherManagers(RuntimeEnvironment env, List<String> projects, String host); void sendToConfigHost(RuntimeEnvironment env, String host); }
Indexer { @SuppressWarnings("PMD.UseStringBufferForStringAppends") public static void main(String[] argv) { Statistics stats = new Statistics(); boolean update = true; Executor.registerErrorHandler(); ArrayList<String> subFiles = new ArrayList<>(); ArrayList<String> subFilesList = new ArrayList<>(); boolean createDict = false; try { argv = parseOptions(argv); disabledRepositories.addAll(cfg.getDisabledRepositories()); cfg.setDisabledRepositories(disabledRepositories); for (String repoName : disabledRepositories) { LOGGER.log(Level.FINEST, "Disabled {0}", repoName); } if (help) { exitWithHelp(); } checkConfiguration(); if (awaitProfiler) { pauseToAwaitProfiler(); } env = RuntimeEnvironment.getInstance(); List<Class<? extends Repository>> repositoryClasses = RepositoryFactory.getRepositoryClasses(); for (Class<? extends Repository> clazz : repositoryClasses) { try { Field f = clazz.getDeclaredField("CMD_PROPERTY_KEY"); Object key = f.get(null); if (key != null) { cfg.setRepoCmd(clazz.getCanonicalName(), System.getProperty(key.toString())); } } catch (Exception e) { } } if (verbose) { String fn = LoggerUtil.getFileHandlerPattern(); if (fn != null) { System.out.println("Logging filehandler pattern: " + fn); } } String file = cfg.getSourceRoot(); if (file != null) { File sourceRootFile = new File(file); File[] projectDirs = sourceRootFile.listFiles(); if (projectDirs != null) { for (File projectDir : projectDirs) { if (!projectDir.getCanonicalPath().equals(projectDir.getAbsolutePath())) { allowedSymlinks.add(projectDir.getAbsolutePath()); } } } } allowedSymlinks.addAll(cfg.getAllowedSymlinks()); cfg.setAllowedSymlinks(allowedSymlinks); canonicalRoots.addAll(cfg.getCanonicalRoots()); cfg.setCanonicalRoots(canonicalRoots); for (String arg : argv) { String path = Paths.get(cfg.getSourceRoot(), arg).toString(); subFilesList.add(path); } for (Entry<String, Project> entry : cfg.getProjects().entrySet()) { if (entry.getValue().getName() == null) { entry.getValue().setName(entry.getKey()); } } env.setConfiguration(cfg, subFilesList, CommandTimeoutType.INDEXER); if (checkIndexVersion) { if (cfg == null) { System.err.println("Need configuration to check index version (use -R)"); System.exit(1); } try { IndexVersion.check(subFilesList); } catch (IndexVersionException e) { System.err.printf("Index version check failed: %s\n", e); System.err.print("You might want to remove " + (subFilesList.size() > 0 ? "data for projects " + String.join(",", subFilesList) : "all data") + " under the DATA_ROOT and to reindex\n"); status = 1; System.exit(status); } } RepositoryFactory.initializeIgnoredNames(env); if (bareConfig) { getInstance().sendToConfigHost(env, webappURI); writeConfigToFile(env, configFilename); System.exit(0); } for (String path : subFilesList) { String srcPath = env.getSourceRootPath(); if (srcPath == null) { System.err.println("Error getting source root from environment. Exiting."); System.exit(1); } path = path.substring(srcPath.length()); if (env.hasProjects()) { Project project; if ((project = Project.getProject(path)) != null) { subFiles.add(path); List<RepositoryInfo> repoList = env.getProjectRepositoriesMap().get(project); if (repoList != null) { repositories.addAll(repoList. stream().map(RepositoryInfo::getDirectoryNameRelative).collect(Collectors.toSet())); } } else { System.err.println("The path " + path + " does not correspond to a project"); } } else { subFiles.add(path); } } if (!subFilesList.isEmpty() && subFiles.isEmpty()) { System.err.println("None of the paths were added, exiting"); System.exit(1); } if (addProjects && webappURI != null) { try { IndexerUtil.enableProjects(webappURI); } catch (Exception e) { LOGGER.log(Level.SEVERE, String.format("Couldn't notify the webapp on %s.", webappURI), e); System.err.println(String.format("Couldn't notify the webapp on %s: %s.", webappURI, e.getLocalizedMessage())); } } LOGGER.log(Level.INFO, "Indexer version {0} ({1}) running on Java {2}", new Object[]{Info.getVersion(), Info.getRevision(), System.getProperty("java.version")}); if (searchRepositories) { if (searchPaths.isEmpty()) { String[] dirs = env.getSourceRootFile(). list((f, name) -> f.isDirectory() && env.getPathAccepter().accept(f)); if (dirs != null) { searchPaths.addAll(Arrays.asList(dirs)); } } searchPaths = searchPaths.stream(). map(t -> Paths.get(env.getSourceRootPath(), t).toString()). collect(Collectors.toSet()); } getInstance().prepareIndexer(env, searchPaths, addProjects, createDict, runIndex, subFiles, new ArrayList<>(repositories)); env.setDefaultProjectsFromNames(defaultProjects); if (runIndex || (optimizedChanged && env.isOptimizeDatabase())) { IndexChangedListener progress = new DefaultIndexChangedListener(); getInstance().doIndexerExecution(update, subFiles, progress); } writeConfigToFile(env, configFilename); if (webappURI != null) { if (!subFiles.isEmpty()) { getInstance().refreshSearcherManagers(env, subFiles, webappURI); } else { getInstance().sendToConfigHost(env, webappURI); } } env.getIndexerParallelizer().bounce(); } catch (ParseException e) { System.err.println("** " + e.getMessage()); System.exit(1); } catch (IndexerException ex) { LOGGER.log(Level.SEVERE, "Exception running indexer", ex); System.err.println("Exception: " + ex.getLocalizedMessage()); System.err.println(optParser.getUsage()); System.exit(1); } catch (Throwable e) { LOGGER.log(Level.SEVERE, "Unexpected Exception", e); System.err.println("Exception: " + e.getLocalizedMessage()); System.exit(1); } finally { stats.report(LOGGER); } } private  Indexer(); static Indexer getInstance(); @SuppressWarnings("PMD.UseStringBufferForStringAppends") static void main(String[] argv); static String[] parseOptions(String[] argv); static void writeConfigToFile(RuntimeEnvironment env, String filename); void prepareIndexer(RuntimeEnvironment env,
                               boolean searchRepositories,
                               boolean addProjects,
                               boolean createDict,
                               List<String> subFiles,
                               List<String> repositories); @SuppressWarnings("PMD.SimplifyStartsWith") void prepareIndexer(RuntimeEnvironment env,
            Set<String> searchPaths,
            boolean addProjects,
            boolean createDict,
            boolean createHistoryCache,
            List<String> subFiles,
            List<String> repositories); void doIndexerExecution(final boolean update, List<String> subFiles,
        IndexChangedListener progress); void refreshSearcherManagers(RuntimeEnvironment env, List<String> projects, String host); void sendToConfigHost(RuntimeEnvironment env, String host); static final char PATH_SEPARATOR; static final String PATH_SEPARATOR_STRING; }