Search.java revision ff5eba819da0cf7964d884630fb13262ef12c505
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye * CDDL HEADER START
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye * The contents of this file are subject to the terms of the
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye * Common Development and Distribution License (the "License").
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye * You may not use this file except in compliance with the License.
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye * See LICENSE.txt included in this distribution for the specific
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye * language governing permissions and limitations under the License.
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye * When distributing Covered Code, include this CDDL HEADER in each
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye * file and include the License file at LICENSE.txt.
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye * If applicable, add the following below this CDDL HEADER, with the
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye * fields enclosed by brackets "[]" replaced with your own identifying
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye * information: Portions Copyright [yyyy] [name of copyright owner]
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye * CDDL HEADER END
fcb68bae47907ba23c545e379c81c3ee6e19f778Lubos Kosco * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
38115c792a2142d264ca2617b11962301f079c0aTrond Norbyeimport org.opensolaris.opengrok.configuration.RuntimeEnvironment;
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye * Search and list the matching files
5e0ccd8bb84a766f65680b4cc1e43b356d1d78b8Trond Norbye@SuppressWarnings({"PMD.AvoidPrintStackTrace", "PMD.SystemPrintln"})
4db6dbfe971f3c68c0945e5da3b6d5a3248054daTrond Norbye private final static String usage = "USAGE: Search -R <configuration.xml> [-d | -r | -p | -h | -f] 'query string' ..\n" +
a90c307564052f582357f820eadec4390e6a86c6Trond Norbye "\t -R <configuration.xml> Read configuration from the specified file\n" +
a90c307564052f582357f820eadec4390e6a86c6Trond Norbye "\t -d Symbol Definitions\n" +
a90c307564052f582357f820eadec4390e6a86c6Trond Norbye "\t -r Symbol References\n" +
a90c307564052f582357f820eadec4390e6a86c6Trond Norbye "\t -p Path\n" +
a90c307564052f582357f820eadec4390e6a86c6Trond Norbye "\t -h History\n" +
a90c307564052f582357f820eadec4390e6a86c6Trond Norbye "\t -f Full text";
9f5a7adefcd3e07345b92f0deb1ed1c30df6eec2Trond Norbye final List<Hit> results = new ArrayList<Hit>();
9f5a7adefcd3e07345b92f0deb1ed1c30df6eec2Trond Norbye @SuppressWarnings({"PMD.SwitchStmtsShouldHaveDefault"})
a90c307564052f582357f820eadec4390e6a86c6Trond Norbye protected boolean parseCmdLine(String[] argv) {
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye Getopt getopt = new Getopt(argv, "R:d:r:p:h:f:");
5e0ccd8bb84a766f65680b4cc1e43b356d1d78b8Trond Norbye return false;
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye RuntimeEnvironment.getInstance().readConfiguration(new File(getopt.getOptarg()));
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye System.err.println("Failed to read config file: ");
4db6dbfe971f3c68c0945e5da3b6d5a3248054daTrond Norbye return false;
4db6dbfe971f3c68c0945e5da3b6d5a3248054daTrond Norbye return true;
4db6dbfe971f3c68c0945e5da3b6d5a3248054daTrond Norbye protected boolean search() {
5e0ccd8bb84a766f65680b4cc1e43b356d1d78b8Trond Norbye if (RuntimeEnvironment.getInstance().getDataRootPath() == null) {
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye System.err.println("You must specify a configuration file");
5e0ccd8bb84a766f65680b4cc1e43b356d1d78b8Trond Norbye return false;
760369283613b2d5c2449cdc5b7a74e16d929750Trond Norbye if (engine == null || !engine.isValidQuery()) {
38115c792a2142d264ca2617b11962301f079c0aTrond Norbye System.err.println("You did not specify a valid query");
5e0ccd8bb84a766f65680b4cc1e43b356d1d78b8Trond Norbye return false;
5e0ccd8bb84a766f65680b4cc1e43b356d1d78b8Trond Norbye return true;
a90c307564052f582357f820eadec4390e6a86c6Trond Norbye protected void dumpResults() {
a90c307564052f582357f820eadec4390e6a86c6Trond Norbye System.err.println("Your search \"" + engine.getQuery() + "\" did not match any files.");
a90c307564052f582357f820eadec4390e6a86c6Trond Norbye String root = RuntimeEnvironment.getInstance().getSourceRootPath();
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco System.out.println("Printing results 1 - " + nhits +" of " + totalResults + " total matching documents collected.");
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco System.out.println(file.getAbsolutePath() + ":"+hit.getLineno()+" [" + hit.getLine() + "]");
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco System.out.println("Printed results 1 - " + nhits +" of " + totalResults + " total matching documents collected.");
ff5eba819da0cf7964d884630fb13262ef12c505Trond Norbye in = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
3aa0947feb67d3e8292d84776638be98dd97fdc3Lubos Kosco if (null == line || line.length() == 0 || line.charAt(0) == 'n') {
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco System.out.println(file.getAbsolutePath() + ":"+hit.getLineno()+" [" + hit.getLine() + "]");
5e0ccd8bb84a766f65680b4cc1e43b356d1d78b8Trond Norbye * usage Search index "query" prunepath
a90c307564052f582357f820eadec4390e6a86c6Trond Norbye * @param argv command line arguments
5e0ccd8bb84a766f65680b4cc1e43b356d1d78b8Trond Norbye boolean success = false;