Skip to content

Feature/uhighlighter #2052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ information: Portions Copyright [yyyy] [name of copyright owner]
CDDL HEADER END

Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.

-->
<project name="OpenGrok" default="jar" basedir="." xmlns:jacoco="antlib:org.jacoco.ant"
Expand Down Expand Up @@ -507,6 +507,18 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
<available file="${lucene-analyzers-common.jar}" type="file" property="lucene-analyzers-common.jar.present">
<filepath refid="plainlib.search.path"/>
</available>
<available file="${lucene-highlighter.jar}" type="file" property="lucene-highlighter.jar.present">
<filepath refid="plainlib.search.path"/>
</available>
<available file="${lucene-join.jar}" type="file" property="lucene-join.jar.present">
<filepath refid="plainlib.search.path"/>
</available>
<available file="${lucene-memory.jar}" type="file" property="lucene-memory.jar.present">
<filepath refid="plainlib.search.path"/>
</available>
<available file="${lucene-queries.jar}" type="file" property="lucene-queries.jar.present">
<filepath refid="plainlib.search.path"/>
</available>
<available file="${lucene-queryparser.jar}" type="file" property="lucene-queryparser.jar.present">
<filepath refid="plainlib.search.path"/>
</available>
Expand All @@ -518,6 +530,10 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
<and>
<isset property="lucene-core.jar.present"/>
<isset property="lucene-analyzers-common.jar.present"/>
<isset property="lucene-highlighter.jar.present"/>
<isset property="lucene-join.jar.present"/>
<isset property="lucene-memory.jar.present"/>
<isset property="lucene-queries.jar.present"/>
<isset property="lucene-queryparser.jar.present"/>
<isset property="lucene-suggest.jar.present"/>
</and>
Expand All @@ -535,6 +551,14 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
dest="lib/${lucene-core.jar}" verbose="true" usetimestamp="true"/>
<get src="${mvn.repository}/org/apache/lucene/lucene-analyzers-common/${lucene.version}/${lucene-analyzers-common.jar}"
dest="lib/${lucene-analyzers-common.jar}" verbose="true" usetimestamp="true"/>
<get src="${mvn.repository}/org/apache/lucene/lucene-highlighter/${lucene.version}/${lucene-highlighter.jar}"
dest="lib/${lucene-highlighter.jar}" verbose="true" usetimestamp="true"/>
<get src="${mvn.repository}/org/apache/lucene/lucene-join/${lucene.version}/${lucene-join.jar}"
dest="lib/${lucene-join.jar}" verbose="true" usetimestamp="true"/>
<get src="${mvn.repository}/org/apache/lucene/lucene-memory/${lucene.version}/${lucene-memory.jar}"
dest="lib/${lucene-memory.jar}" verbose="true" usetimestamp="true"/>
<get src="${mvn.repository}/org/apache/lucene/lucene-queries/${lucene.version}/${lucene-queries.jar}"
dest="lib/${lucene-queries.jar}" verbose="true" usetimestamp="true"/>
<get src="${mvn.repository}/org/apache/lucene/lucene-queryparser/${lucene.version}/${lucene-queryparser.jar}"
dest="lib/${lucene-queryparser.jar}" verbose="true" usetimestamp="true"/>
<get src="${mvn.repository}/org/apache/lucene/lucene-suggest/${lucene.version}/${lucene-suggest.jar}"
Expand Down
4 changes: 2 additions & 2 deletions debian/ant.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DEB_JARS=JFlex.jar:ant-junit.jar:ant-nodeps.jar:junit4.jar:bcel.jar:swing-layout.jar:lucene-core.jar:lucene-spellchecker.jar:servlet-api.jar
WAR_JARS=bcel.jar:swing-layout.jar:lucene-core.jar:lucene-spellchecker.jar
DEB_JARS=JFlex.jar:ant-junit.jar:ant-nodeps.jar:junit4.jar:bcel.jar:swing-layout.jar:lucene-core.jar:lucene-highlighter.jar:lucene-join.jar:lucene-memory.jar:lucene-queries.jar:lucene-spellchecker.jar:servlet-api.jar
WAR_JARS=bcel.jar:swing-layout.jar:lucene-core.jar:lucene-highlighter.jar:lucene-join.jar:lucene-memory.jar:lucene-queries.jar:lucene-spellchecker.jar

file.reference.jrcs.jar=lib/jrcs.jar

Expand Down
12 changes: 12 additions & 0 deletions nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ manifest.custom.caller.allowable.codebase=
project.licensePath=./nbproject/licenseheader.txt
src.generatedsrc.dir=generatedsrc
file.reference.lucene-core.jar=lib/${lucene-core.jar}
file.reference.lucene-highlighter.jar=lib/${lucene-highlighter.jar}
file.reference.lucene-join.jar=lib/${lucene-join.jar}
file.reference.lucene-memory.jar=lib/${lucene-memory.jar}
file.reference.lucene-queries.jar=lib/${lucene-queries.jar}
dist.war=${dist.dir}/source.war
javac.target=1.8
build.generated.dir=${build.dir}/generated
Expand All @@ -19,6 +23,10 @@ run.classpath=\
${build.classes.dir}
lucene.version=7.2.1
lucene-core.jar=lucene-core-${lucene.version}.jar
lucene-highlighter.jar=lucene-highlighter-${lucene.version}.jar
lucene-join.jar=lucene-join-${lucene.version}.jar
lucene-memory.jar=lucene-memory-${lucene.version}.jar
lucene-queries.jar=lucene-queries-${lucene.version}.jar
file.reference.opengrok-dev-test=test
debug.test.classpath=${run.test.classpath}
jnlp.descriptor=application
Expand Down Expand Up @@ -78,6 +86,10 @@ javac.classpath=\
${file.reference.bcel.jar}:\
${file.reference.lucene-analyzers-common.jar}:\
${file.reference.lucene-core.jar}:\
${file.reference.lucene-highlighter.jar}:\
${file.reference.lucene-join.jar}:\
${file.reference.lucene-memory.jar}:\
${file.reference.lucene-queries.jar}:\
${file.reference.lucene-queryparser.jar}:\
${file.reference.lucene-suggest.jar}:\
${file.reference.servlet-api.jar}
Expand Down
18 changes: 17 additions & 1 deletion opengrok-indexer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ information: Portions Copyright [yyyy] [name of copyright owner]
CDDL HEADER END

Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy

Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down Expand Up @@ -476,6 +476,22 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-highlighter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-join</artifactId>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-memory</artifactId>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queries</artifactId>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
Expand Down
8 changes: 8 additions & 0 deletions opengrok-web-nbproject/nbproject/build-impl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,10 @@ exists or setup the property manually. For example like this:
<copyfiles files="${file.reference.bcel.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.lucene-core.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.lucene-analyzers-common.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.lucene-highlighter.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.lucene-join.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.lucene-memory.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.lucene-queries.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.lucene-queryparser.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.lucene-suggest.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.json-simple-1.1.1.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
Expand All @@ -1004,6 +1008,10 @@ exists or setup the property manually. For example like this:
<copyfiles files="${file.reference.bcel.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.lucene-core.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.lucene-analyzers-common.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.lucene-highlighter.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.lucene-join.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.lucene-memory.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.lucene-queries.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.lucene-queryparser.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.lucene-suggest.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.json-simple-1.1.1.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
Expand Down
12 changes: 12 additions & 0 deletions opengrok-web-nbproject/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.serve
lucene.version=7.2.1
lucene-core.jar=lucene-core-${lucene.version}.jar
lucene-analyzers-common.jar=lucene-analyzers-common-${lucene.version}.jar
lucene-highlighter.jar=lucene-highlighter-${lucene.version}.jar
lucene-join.jar=lucene-join-${lucene.version}.jar
lucene-memory.jar=lucene-memory-${lucene.version}.jar
lucene-queries.jar=lucene-queries-${lucene.version}.jar
lucene-queryparser.jar=lucene-queryparser-${lucene.version}.jar
lucene-suggest.jar=lucene-suggest-${lucene.version}.jar
file.reference.lucene-core.jar=../lib/${lucene-core.jar}
file.reference.lucene-analyzers-common.jar=../lib/${lucene-analyzers-common.jar}
file.reference.lucene-highlighter.jar=../lib/${lucene-highlighter.jar}
file.reference.lucene-join.jar=../lib/${lucene-join.jar}
file.reference.lucene-memory.jar=../lib/${lucene-memory.jar}
file.reference.lucene-queries.jar=../lib/${lucene-queries.jar}
file.reference.lucene-queryparser.jar=../lib/${lucene-queryparser.jar}
file.reference.lucene-suggest.jar=../lib/${lucene-suggest.jar}
file.reference.ant.jar=${ant.library.dir}/ant.jar
Expand All @@ -67,6 +75,10 @@ javac.classpath=\
${file.reference.bcel.jar}:\
${file.reference.lucene-core.jar}:\
${file.reference.lucene-analyzers-common.jar}:\
${file.reference.lucene-highlighter.jar}:\
${file.reference.lucene-join.jar}:\
${file.reference.lucene-memory.jar}:\
${file.reference.lucene-queries.jar}:\
${file.reference.lucene-queryparser.jar}:\
${file.reference.lucene-suggest.jar}:\
${file.reference.json-simple-1.1.1.jar}
Expand Down
16 changes: 16 additions & 0 deletions opengrok-web-nbproject/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@
<file>${file.reference.lucene-analyzers-common.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library dirs="200">
<file>${file.reference.lucene-highlighter.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library dirs="200">
<file>${file.reference.lucene-join.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library dirs="200">
<file>${file.reference.lucene-memory.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library dirs="200">
<file>${file.reference.lucene-queries.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library dirs="200">
<file>${file.reference.lucene-queryparser.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
Expand Down
21 changes: 21 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ information: Portions Copyright [yyyy] [name of copyright owner]
CDDL HEADER END

Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy

Portions Copyright (c) 2018, Chris Fraire <[email protected]>.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down Expand Up @@ -87,6 +88,26 @@ Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
<artifactId>lucene-analyzers-common</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-highlighter</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-join</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-memory</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queries</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
Expand Down
26 changes: 25 additions & 1 deletion src/org/opensolaris/opengrok/analysis/AnalyzerGuru.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy

* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
*/
package org.opensolaris.opengrok.analysis;

Expand Down Expand Up @@ -213,6 +213,13 @@ public class AnalyzerGuru {

private static final Map<String, String> fileTypeDescriptions = new TreeMap<>();

/**
* Maps from {@link FileAnalyzer#getFileTypeName()} to
* {@link FileAnalyzerFactory}
*/
private static final Map<String, FileAnalyzerFactory> FILETYPE_FACTORIES =
new HashMap<>();

/*
* If you write your own analyzer please register it here. The order is
* important for any factory that uses a FileAnalyzerFactory.Matcher
Expand Down Expand Up @@ -338,6 +345,9 @@ private static void registerAnalyzer(FileAnalyzerFactory factory) {
}
matchers.addAll(factory.getMatchers());
factories.add(factory);

FileAnalyzer fa = factory.getAnalyzer();
FILETYPE_FACTORIES.put(fa.getFileTypeName(), factory);
}

/**
Expand Down Expand Up @@ -385,6 +395,17 @@ public static FileAnalyzer getAnalyzer() {
return DEFAULT_ANALYZER_FACTORY.getAnalyzer();
}

/**
* Gets an analyzer for the specified {@code fileTypeName} if it accords
* with a known {@link FileAnalyzer#getFileTypeName()}.
* @param fileTypeName a defined name
* @return a defined instance if known or otherwise {@code null}
*/
public static FileAnalyzer getAnalyzer(String fileTypeName) {
FileAnalyzerFactory factory = FILETYPE_FACTORIES.get(fileTypeName);
return factory == null ? null : factory.getAnalyzer();
}

/**
* Get an analyzer suited to analyze a file. This function will reuse
* analyzers since they are costly.
Expand Down Expand Up @@ -531,6 +552,9 @@ public static void writeXref(FileAnalyzerFactory factory, Reader in,
args.setProject(project);

FileAnalyzer analyzer = factory.getAnalyzer();
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is because of testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing the new highlighter, I found that scopes were not working when looking at historical versions of files or when annotating a file — i.e. where this writeXref() is called by list.jsp instead of its using the stored .gz version.

analyzer.setScopesEnabled(env.isScopesEnabled());
analyzer.setFoldingEnabled(env.isFoldingEnabled());
analyzer.writeXref(args);
}

Expand Down
8 changes: 3 additions & 5 deletions src/org/opensolaris/opengrok/analysis/CtagsReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ private static String cutPattern(String tagLine, int startTab, int endTab) {
* Adds a tag to a {@code Definitions} instance.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy 2018

*/
private void addTag(Definitions defs, int lineno, String symbol,
String type, String text, String namespace, String signature,
int lineStart, int lineEnd) {
String type, String text, String namespace, String signature,
int lineStart, int lineEnd) {
// The strings are frequently repeated (a symbol can be used in
// multiple definitions, multiple definitions can have the same type,
// one line can contain multiple definitions). Intern them to minimize
Expand All @@ -397,9 +397,7 @@ private void addTag(Definitions defs, int lineno, String symbol,
* syntax.
* @return a defined instance
*/
private CpatIndex bestIndexOfTag(int lineno, String whole,
String str) {

private CpatIndex bestIndexOfTag(int lineno, String whole, String str) {
if (whole.length() < 1) {
return new CpatIndex(lineno, 0, 1, true);
}
Expand Down
72 changes: 72 additions & 0 deletions src/org/opensolaris/opengrok/analysis/OGKTextField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
* United States License. To view a copy of this license, visit
* http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to
* Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
*
* Copyright (c) 2012, https://stackoverflow.com/users/1270457/amas
* Copyright (c) 2012, https://stackoverflow.com/questions/11945728/how-to-use-termvector-lucene-4-0
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
*/

package org.opensolaris.opengrok.analysis;

import java.io.Reader;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.index.IndexOptions;

/**
* Represents an OpenGrok-customized tokenized text field to centralize settings
* across all the analyzers.
*/
public class OGKTextField extends Field {

/** Indexed, tokenized, not stored. */
public static final FieldType TYPE_NOT_STORED = new FieldType();

/** Indexed, tokenized, stored. */
public static final FieldType TYPE_STORED = new FieldType();

static {
TYPE_NOT_STORED.setIndexOptions(
IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
TYPE_NOT_STORED.setTokenized(true);
TYPE_NOT_STORED.freeze();

TYPE_STORED.setIndexOptions(
IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
TYPE_STORED.setTokenized(true);
TYPE_STORED.setStored(true);
TYPE_STORED.freeze();
}

/**
* Creates a new un-stored instance with {@link Reader} value.
*/
public OGKTextField(String name, Reader reader) {
super(name, reader, TYPE_NOT_STORED);
}

/**
* Creates a new instance with {@link Reader} value.
*/
public OGKTextField(String name, Reader reader, Store store) {
super(name, reader, store == Store.YES ? TYPE_STORED : TYPE_NOT_STORED);
}

/**
* Creates a new instance with {@code String} value.
*/
public OGKTextField(String name, String value, Store store) {
super(name, value, store == Store.YES ? TYPE_STORED : TYPE_NOT_STORED);
}

/**
* Creates a new un-stored instance with {@link TokenStream} value.
*/
public OGKTextField(String name, TokenStream stream) {
super(name, stream, TYPE_NOT_STORED);
}
}
Loading