Package org.watermint.sourcecolon.org.opensolaris.opengrok.configuration

Examples of org.watermint.sourcecolon.org.opensolaris.opengrok.configuration.Configuration


            System.err.println(cmdOptions.getUsage());
            System.exit(1);
        }

        try {
            Configuration cfg = null;
            int cmd;

            // We need to read the configuration file first, since we
            // will try to overwrite options..
            while ((cmd = getOpts.getOpt()) != -1) {
                if (cmd == 'R') {
                    cfg = Configuration.read(new File(getOpts.getOptionArgument()));
                    break;
                }
            }

            if (cfg == null) {
                cfg = new Configuration();
            }

            // Now we can handle all the other options..
            getOpts.reset();
            while ((cmd = getOpts.getOpt()) != -1) {
                switch (cmd) {
                    case 'x':
                        createDict = true;
                        runIndex = false;
                        break;

                    case 'e':
                        cfg.setGenerateHtml(false);
                        break;
                    case 'P':
                        addProjects = true;
                        break;
                    case 'p':
                        defaultProject = getOpts.getOptionArgument();
                        break;
                    case 'c':
                        cfg.setCtags(getOpts.getOptionArgument());
                        break;
                    case 'w': {
                        String webapp = getOpts.getOptionArgument();
                        if (webapp.charAt(0) != '/' && !webapp.startsWith("http")) {
                            webapp = "/" + webapp;
                        }
                        if (webapp.endsWith("/")) {
                            cfg.setUrlPrefix(webapp + "s?");
                        } else {
                            cfg.setUrlPrefix(webapp + "/s?");
                        }
                    }
                    break;
                    case 'W':
                        configFilename = getOpts.getOptionArgument();
                        break;
                    case 'N':
                        allowedSymlinks.add(getOpts.getOptionArgument());
                        break;
                    case 'n':
                        runIndex = false;
                        break;
                    case 'v':
                        cfg.setVerbose(true);
                        break;
                    case 'C':
                        cfg.setPrintProgress(true);
                        break;

                    case 's': {
                        File sourceRoot = new File(getOpts.getOptionArgument());
                        if (!sourceRoot.isDirectory()) {
                            System.err.println("ERROR: Source root must be a directory");
                            System.exit(1);
                        }
                        cfg.setSourceRoot(sourceRoot.getCanonicalPath());
                        break;
                    }
                    case 'd': {
                        File dataRoot = new File(getOpts.getOptionArgument());
                        if (!dataRoot.exists() && !dataRoot.mkdirs()) {
                            System.err.println("ERROR: Cannot create data root");
                            System.exit(1);
                        }
                        if (!dataRoot.isDirectory()) {
                            System.err.println("ERROR: Data root must be a directory");
                            System.exit(1);
                        }
                        cfg.setDataRoot(dataRoot.getCanonicalPath());
                        break;
                    }
                    case 'i':
                        cfg.getIgnoredNames().add(getOpts.getOptionArgument());
                        break;
                    case 'I':
                        cfg.getIncludedNames().add(getOpts.getOptionArgument());
                        break;
                    case 'Q':
                        if (getOpts.getOptionArgument().equalsIgnoreCase(ON)) {
                            cfg.setQuickContextScan(true);
                        } else if (getOpts.getOptionArgument().equalsIgnoreCase(OFF)) {
                            cfg.setQuickContextScan(false);
                        } else {
                            System.err.println("ERROR: You should pass either \"on\" or \"off\" as argument to -Q");
                            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 'm': {
                        try {
                            cfg.setIndexWordLimit(Integer.parseInt(getOpts.getOptionArgument()));
                        } catch (NumberFormatException exp) {
                            System.err.println("ERROR: Failed to parse argument to \"-m\": " + exp.getMessage());
                            System.exit(1);
                        }
                        break;
                    }
                    case 'a':
                        if (getOpts.getOptionArgument().equalsIgnoreCase(ON)) {
                            cfg.setAllowLeadingWildcard(true);
                        } else if (getOpts.getOptionArgument().equalsIgnoreCase(OFF)) {
                            cfg.setAllowLeadingWildcard(false);
                        } else {
                            System.err.println("ERROR: You should pass either \"on\" or \"off\" as argument to -a");
                            System.err.println("       Ex: \"-a on\" will allow a search to start with a wildcard");
                            System.err.println("           \"-a off\" will disallow a search to start with a wildcard");
                            System.exit(1);
                        }

                        break;

                    case 'A': {
                        String[] arg = getOpts.getOptionArgument().split(":");
                        if (arg.length != 2) {
                            System.err.println("ERROR: You must specify: -A extension:class");
                            System.err.println("       Ex: -A foo:org.watermint.sourcecolon.org.opensolaris.opengrok.analysis.c.CAnalyzer");
                            System.err.println("           will use the C analyzer for all files ending with .foo");
                            System.err.println("       Ex: -A c:-");
                            System.err.println("           will disable the c-analyzer for for all files ending with .c");
                            System.exit(1);
                        }

                        arg[0] = arg[0].substring(arg[0].lastIndexOf('.') + 1).toUpperCase();
                        if (arg[1].equals("-")) {
                            AnalyzerGuru.addExtension(arg[0], null);
                            break;
                        }

                        try {
                            AnalyzerGuru.addExtension(
                                    arg[0],
                                    AnalyzerGuru.findFactory(arg[1]));
                        } catch (Exception e) {
                            log.log(Level.SEVERE, "Unable to use {0} as a FileAnalyzerFactory", arg[1]);
                            log.log(Level.SEVERE, "Stack: ", e.fillInStackTrace());
                            System.exit(1);
                        }
                    }
                    break;
                    case 'T':
                        try {
                            noThreads = Integer.parseInt(getOpts.getOptionArgument());
                        } catch (NumberFormatException exp) {
                            System.err.println("ERROR: Failed to parse argument to \"-T\": " + exp.getMessage());
                            System.exit(1);
                        }
                        break;
                    case 'l':
                        if (getOpts.getOptionArgument().equalsIgnoreCase(ON)) {
                            cfg.setUsingLuceneLocking(true);
                        } else if (getOpts.getOptionArgument().equalsIgnoreCase(OFF)) {
                            cfg.setUsingLuceneLocking(false);
                        } else {
                            System.err.println("ERROR: You should pass either \"on\" or \"off\" as argument to -l");
                            System.err.println("       Ex: \"-l on\" will enable locks in Lucene");
                            System.err.println("           \"-l off\" will disable locks in Lucene");
                        }
                        break;
                    case 'V':
                        System.out.println(Info.getFullVersion());
                        System.exit(0);
                        break;
                    case '?':
                        System.err.println(cmdOptions.getUsage());
                        System.exit(0);
                        break;
                    case 't':
                        try {
                            int tmp = Integer.parseInt(getOpts.getOptionArgument());
                            cfg.setTabSize(tmp);
                        } catch (NumberFormatException exp) {
                            System.err.println("ERROR: Failed to parse argument to \"-t\": " + exp.getMessage());
                            System.exit(1);
                        }
                        break;
                    default:
                        System.err.println("Internal Error - Unimplemented cmdline option: " + (char) cmd);
                        System.exit(1);
                }
            }

            int optind = getOpts.getOptionIndex();
            if (optind != -1) {
                while (optind < argv.length) {
                    subFiles.add(argv[optind]);
                    ++optind;
                }
            }

            //logging starts here
            if (cfg.isVerbose()) {
                String fn = LogManager.getLogManager().getProperty("java.util.logging.FileHandler.pattern");
                if (fn != null) {
                    System.out.println("Logging filehandler pattern: " + fn);
                }
            }

            // automatically allow symlinks that are directly in source root
            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);

            //Set updated configuration in RuntimeEnvironment
            RuntimeEnvironment env = RuntimeEnvironment.getInstance();
            env.setConfiguration(cfg);
View Full Code Here

TOP

Related Classes of org.watermint.sourcecolon.org.opensolaris.opengrok.configuration.Configuration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.