ShAnalyzer.java revision b310c0aeaec52a0246021104b8f52cbb31b68480
b9481bb7735c0335aa58f4749a989c2f07ab5f3bTimo Sirainen/*
b9481bb7735c0335aa58f4749a989c2f07ab5f3bTimo Sirainen * CDDL HEADER START
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen *
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen * The contents of this file are subject to the terms of the
34e7467e72d8a2e6b91ee6b2a50dd44570e12567Timo Sirainen * Common Development and Distribution License (the "License").
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen * You may not use this file except in compliance with the License.
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen *
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen * See LICENSE.txt included in this distribution for the specific
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen * language governing permissions and limitations under the License.
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen *
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen * When distributing Covered Code, include this CDDL HEADER in each
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen * file and include the License file at LICENSE.txt.
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen * If applicable, add the following below this CDDL HEADER, with the
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen * fields enclosed by brackets "[]" replaced with your own identifying
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen * information: Portions Copyright [yyyy] [name of copyright owner]
9d1526ac8bcec9aff3c3a32f092ee2f3da2760b7Timo Sirainen *
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen * CDDL HEADER END
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen */
9d1526ac8bcec9aff3c3a32f092ee2f3da2760b7Timo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen/*
9d1526ac8bcec9aff3c3a32f092ee2f3da2760b7Timo Sirainen * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenpackage org.opensolaris.opengrok.analysis.sh;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenimport java.io.IOException;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenimport java.io.Reader;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenimport java.io.StringReader;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenimport java.io.Writer;
b9481bb7735c0335aa58f4749a989c2f07ab5f3bTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenimport org.apache.lucene.analysis.TokenStream;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenimport org.apache.lucene.document.Document;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenimport org.apache.lucene.document.Field;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenimport org.opensolaris.opengrok.analysis.Definitions;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenimport org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
8dec8eab222cb7a0b4ef5e066cb1d7dac8a526d1Timo Sirainenimport org.opensolaris.opengrok.analysis.plain.PlainAnalyzer;
8dec8eab222cb7a0b4ef5e066cb1d7dac8a526d1Timo Sirainenimport org.opensolaris.opengrok.configuration.Project;
8dec8eab222cb7a0b4ef5e066cb1d7dac8a526d1Timo Sirainenimport org.opensolaris.opengrok.history.Annotation;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
8dec8eab222cb7a0b4ef5e066cb1d7dac8a526d1Timo Sirainen/**
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen * Analyzes Shell scripts/Conf files etc.,
* Created on September 21, 2005
*
* @author Chandan
*/
public class ShAnalyzer extends PlainAnalyzer {
/** Creates a new instance of ShAnalyzer */
ShSymbolTokenizer shref;
ShXref xref;
Reader dummy = new StringReader("");
protected ShAnalyzer(FileAnalyzerFactory factory) {
super(factory);
shref = new ShSymbolTokenizer(dummy);
xref = new ShXref(dummy);
}
@Override
public void analyze(Document doc, Reader in) throws IOException {
super.analyze(doc, in);
doc.add(new Field("refs", dummy));
}
@Override
public TokenStream overridableTokenStream(String fieldName, Reader reader) {
if("refs".equals(fieldName)) {
shref.reInit(super.content, super.len);
return shref;
}
return super.overridableTokenStream(fieldName, reader);
}
/**
* Write a cross referenced HTML file.
* @param out Writer to write HTML cross-reference
*/
@Override
public void writeXref(Writer out) throws IOException {
xref.reInit(content, len);
xref.project = project;
xref.setDefs(super.defs);
xref.write(out);
}
/**
* Write a cross referenced HTML file reads the source from in
* @param in Input source
* @param out Output xref writer
* @param defs definitions for the file (could be null)
* @param annotation annotation for the file (could be null)
*/
static void writeXref(Reader in, Writer out, Definitions defs, Annotation annotation, Project project) throws IOException {
ShXref xref = new ShXref(in);
xref.annotation = annotation;
xref.project = project;
xref.setDefs(defs);
xref.write(out);
}
}