ShAnalyzer.java revision 73b36d5a6848ae9189f4f9e35a68947e89b1fe80
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen/*
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * CDDL HEADER START
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * The contents of this file are subject to the terms of the
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * Common Development and Distribution License (the "License").
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * You may not use this file except in compliance with the License.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * See LICENSE.txt included in this distribution for the specific
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * language governing permissions and limitations under the License.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * When distributing Covered Code, include this CDDL HEADER in each
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * file and include the License file at LICENSE.txt.
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen * If applicable, add the following below this CDDL HEADER, with the
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * fields enclosed by brackets "[]" replaced with your own identifying
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * information: Portions Copyright [yyyy] [name of copyright owner]
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * CDDL HEADER END
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
ae46f6ba5bb9eee8900254d3042e89d490023be0Timo Sirainen/*
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * Use is subject to license terms.
3f3ad16ff74d694796d22501250a9a29997c0729Timo Sirainen */
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen/*
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * ident "%Z%%M% %I% %E% SMI"
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen */
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainenpackage org.opensolaris.opengrok.analysis.sh;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenimport org.apache.lucene.document.*;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenimport org.apache.lucene.analysis.*;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenimport java.io.*;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenimport org.opensolaris.opengrok.analysis.FileAnalyzer;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenimport org.opensolaris.opengrok.analysis.plain.*;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenimport org.opensolaris.opengrok.history.Annotation;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen/**
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen * Analyzes Shell scripts/Conf files etc.,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * Created on September 21, 2005
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * @author Chandan
db693bf6fcae96d834567f1782257517b7207655Timo Sirainen */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenpublic class ShAnalyzer extends PlainAnalyzer {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /** Creates a new instance of ShAnalyzer */
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen ShSymbolTokenizer shref;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen ShXref xref;
5801ce4da7d807ab85d02051ece5969e7175eebaTimo Sirainen Reader dummy = new StringReader("");
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen public static String[] suffixes = {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen "SH",
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen "KSH",
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen "CSH",
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen "BASH",
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen "TCL",
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen "TK",
db693bf6fcae96d834567f1782257517b7207655Timo Sirainen "PERL",
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen "RUBY",
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen "PM",
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen "RB",
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen "PY",
5801ce4da7d807ab85d02051ece5969e7175eebaTimo Sirainen "PL",
5801ce4da7d807ab85d02051ece5969e7175eebaTimo Sirainen "P5",
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen "AWK",
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen "MAKEFILE",
5801ce4da7d807ab85d02051ece5969e7175eebaTimo Sirainen "GMK",
db693bf6fcae96d834567f1782257517b7207655Timo Sirainen "CONF",
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen "COM",
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen "SPEC",
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen "FLG",
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen "XCL" // message
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen };
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public static String[] magics = {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen "#!",
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen "##",
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen "#\n#"
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen };
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public ShAnalyzer() {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen super();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen shref = new ShSymbolTokenizer(dummy);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen xref = new ShXref(dummy);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public void analyze(Document doc, InputStream in) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen super.analyze(doc, in);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen doc.add(Field.Text("refs", dummy));
db693bf6fcae96d834567f1782257517b7207655Timo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen public TokenStream tokenStream(String fieldName, Reader reader) {
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen if("refs".equals(fieldName)) {
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen shref.reInit(super.content, super.len);
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen return shref;
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen }
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen return super.tokenStream(fieldName, reader);
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen }
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen /**
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen * Write a cross referenced HTML file.
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen * @param out Writer to write HTML cross-reference
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen */
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen public void writeXref(Writer out) throws IOException {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen xref.reInit(content, len);
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen xref.setDefs(super.defs);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen xref.write(out);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen //lines = xref.getLine();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /**
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * Write a cross referenced HTML file reads the source from in
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * @param in Input source
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * @param out Output xref writer
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * @param annotation annotation for the file (could be null)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public static void writeXref(InputStream in, Writer out,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen Annotation annotation) throws IOException {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen ShXref xref = new ShXref(in);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen xref.annotation = annotation;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen xref.write(out);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen}
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen