Skip to content

Commit 9368fce

Browse files
author
Vladimir Kotal
committed
Merge branch 'idodeclare-feature/dir-LOC-lines' into master
2 parents e779faa + 9effdf2 commit 9368fce

25 files changed

+915
-185
lines changed

dev/checkstyle/suppressions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Portions Copyright (c) 2018-2020, Chris Fraire <[email protected]>.
4444

4545
<suppress checks="FileLength" files="RuntimeEnvironment\.java" />
4646

47-
<suppress checks="MethodLength" files="Indexer\.java|AuthorizationFrameworkTest\.java" />
47+
<suppress checks="MethodLength" files="Indexer\.java|IndexDatabase\.java|AuthorizationFrameworkTest\.java" />
4848

4949
<suppress checks="JavadocStyle" files="MellonHeaderDecoder\.java|CustomSloppyPhraseScorer\.java|
5050
|PhrasePositions\.java|GitRepositoryTest\.java" />

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AbstractAnalyzer.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.lucene.analysis.TokenStream;
3434
import org.apache.lucene.document.Document;
3535
import org.opengrok.indexer.configuration.Project;
36+
import org.opengrok.indexer.index.NumLinesLOCAggregator;
3637

3738
/**
3839
* @author Chandan
@@ -44,6 +45,7 @@ public abstract class AbstractAnalyzer extends Analyzer {
4445
protected Supplier<JFlexTokenizer> symbolTokenizerFactory;
4546
protected Project project;
4647
protected Ctags ctags;
48+
protected NumLinesLOCAggregator countsAggregator;
4749
protected boolean scopesEnabled;
4850
protected boolean foldingEnabled;
4951

@@ -76,6 +78,10 @@ public void setCtags(Ctags ctags) {
7678
this.ctags = ctags;
7779
}
7880

81+
public void setCountsAggregator(NumLinesLOCAggregator countsAggregator) {
82+
this.countsAggregator = countsAggregator;
83+
}
84+
7985
public void setProject(Project project) {
8086
this.project = project;
8187
}
@@ -113,13 +119,15 @@ public abstract void analyze(Document doc, StreamSource src, Writer xrefOut)
113119
@Override
114120
protected abstract TokenStreamComponents createComponents(String fieldName);
115121

116-
protected abstract void addNumLines(Document doc, int value);
117-
118-
protected abstract void addLOC(Document doc, int value);
119-
120122
@Override
121123
protected abstract TokenStream normalize(String fieldName, TokenStream in);
122124

125+
/**
126+
* Subclasses must override to incorporate a determined number of lines and
127+
* lines-of-code (LOC).
128+
*/
129+
protected abstract void addNumLinesLOC(Document doc, NumLinesLOC counts);
130+
123131
/**
124132
* What kind of file is this?
125133
*/
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2020, Chris Fraire <[email protected]>.
22+
*/
23+
24+
package org.opengrok.indexer.analysis;
25+
26+
/**
27+
* Represents an API for an aggregation of {@link NumLinesLOC}.
28+
*/
29+
public interface AccumulatedNumLinesLOC {
30+
String getPath();
31+
long getNumLines();
32+
long getLOC();
33+
}

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/FileAnalyzer.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,16 @@ protected TokenStreamComponents createComponents(String fieldName) {
201201
}
202202

203203
/**
204-
* Add a field to store document number of lines.
205-
* @param doc the target document
206-
* @param value the number of lines
204+
* Add fields to store document number-of-lines and lines-of-code (LOC).
207205
*/
208206
@Override
209-
protected void addNumLines(Document doc, int value) {
210-
doc.add(new StoredField(QueryBuilder.NUML, value));
211-
}
207+
protected void addNumLinesLOC(Document doc, NumLinesLOC counts) {
208+
doc.add(new StoredField(QueryBuilder.NUML, counts.getNumLines()));
209+
doc.add(new StoredField(QueryBuilder.LOC, counts.getLOC()));
212210

213-
/**
214-
* Add a field to store document lines-of-code.
215-
* @param doc the target document
216-
* @param value the loc
217-
*/
218-
@Override
219-
protected void addLOC(Document doc, int value) {
220-
doc.add(new StoredField(QueryBuilder.LOC, value));
211+
if (countsAggregator != null) {
212+
countsAggregator.register(counts);
213+
}
221214
}
222215

223216
private JFlexTokenizer createPlainSymbolTokenizer() {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2020, Chris Fraire <[email protected]>.
22+
*/
23+
24+
package org.opengrok.indexer.analysis;
25+
26+
/**
27+
* Represents an immutable data object that associates a file with its analyzed
28+
* number-of-lines and lines-of-code or with null values.
29+
*/
30+
public class NullableNumLinesLOC {
31+
private final String path;
32+
private final Long numLines;
33+
private final Long loc;
34+
35+
public NullableNumLinesLOC(String path, Long numLines, Long loc) {
36+
this.path = path;
37+
this.numLines = numLines;
38+
this.loc = loc;
39+
}
40+
41+
public String getPath() {
42+
return path;
43+
}
44+
45+
public Long getNumLines() {
46+
return numLines;
47+
}
48+
49+
public Long getLOC() {
50+
return loc;
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2020, Chris Fraire <[email protected]>.
22+
*/
23+
24+
package org.opengrok.indexer.analysis;
25+
26+
/**
27+
* Represents an immutable data object that associates a file with its analyzed
28+
* number-of-lines and lines-of-code.
29+
*/
30+
public class NumLinesLOC {
31+
private final String path;
32+
private final long numLines;
33+
private final long loc;
34+
35+
public NumLinesLOC(String path, long numLines, long loc) {
36+
this.path = path;
37+
this.numLines = numLines;
38+
this.loc = loc;
39+
}
40+
41+
public String getPath() {
42+
return path;
43+
}
44+
45+
public long getNumLines() {
46+
return numLines;
47+
}
48+
49+
public long getLOC() {
50+
return loc;
51+
}
52+
}

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/document/MandocAnalyzer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.opengrok.indexer.analysis.AbstractAnalyzer;
3131
import org.opengrok.indexer.analysis.AnalyzerFactory;
3232
import org.opengrok.indexer.analysis.JFlexTokenizer;
33+
import org.opengrok.indexer.analysis.NumLinesLOC;
3334
import org.opengrok.indexer.analysis.OGKTextField;
3435
import org.opengrok.indexer.analysis.StreamSource;
3536
import org.opengrok.indexer.analysis.TextAnalyzer;
@@ -88,8 +89,8 @@ public void analyze(Document doc, StreamSource src, Writer xrefOut)
8889
args.setProject(project);
8990
Xrefer xref = writeXref(args);
9091

91-
addNumLines(doc, xref.getLineNumber());
92-
addLOC(doc, xref.getLOC());
92+
String path = doc.get(QueryBuilder.PATH);
93+
addNumLinesLOC(doc, new NumLinesLOC(path, xref.getLineNumber(), xref.getLOC()));
9394
}
9495
}
9596
}

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/document/TroffAnalyzer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.opengrok.indexer.analysis.AbstractAnalyzer;
3131
import org.opengrok.indexer.analysis.AnalyzerFactory;
3232
import org.opengrok.indexer.analysis.JFlexTokenizer;
33+
import org.opengrok.indexer.analysis.NumLinesLOC;
3334
import org.opengrok.indexer.analysis.OGKTextField;
3435
import org.opengrok.indexer.analysis.StreamSource;
3536
import org.opengrok.indexer.analysis.TextAnalyzer;
@@ -87,8 +88,8 @@ public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOExc
8788
args.setProject(project);
8889
Xrefer xref = writeXref(args);
8990

90-
addNumLines(doc, xref.getLineNumber());
91-
addLOC(doc, xref.getLOC());
91+
String path = doc.get(QueryBuilder.PATH);
92+
addNumLinesLOC(doc, new NumLinesLOC(path, xref.getLineNumber(), xref.getLOC()));
9293
}
9394
}
9495
}

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/plain/PlainAnalyzer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.opengrok.indexer.analysis.ExpandTabsReader;
3737
import org.opengrok.indexer.analysis.JFlexTokenizer;
3838
import org.opengrok.indexer.analysis.JFlexXref;
39+
import org.opengrok.indexer.analysis.NumLinesLOC;
3940
import org.opengrok.indexer.analysis.OGKTextField;
4041
import org.opengrok.indexer.analysis.OGKTextVecField;
4142
import org.opengrok.indexer.analysis.Scopes;
@@ -157,8 +158,8 @@ public void analyze(Document doc, StreamSource src, Writer xrefOut)
157158
scopesSerialized));
158159
}
159160

160-
addNumLines(doc, xref.getLineNumber());
161-
addLOC(doc, xref.getLOC());
161+
String path = doc.get(QueryBuilder.PATH);
162+
addNumLinesLOC(doc, new NumLinesLOC(path, xref.getLineNumber(), xref.getLOC()));
162163
} finally {
163164
if (nullWriter != null) {
164165
nullWriter.close();

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/plain/XMLAnalyzer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017, 2019, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis.plain;
2525

@@ -29,6 +29,7 @@
2929
import org.apache.lucene.document.Document;
3030
import org.opengrok.indexer.analysis.AnalyzerFactory;
3131
import org.opengrok.indexer.analysis.JFlexXref;
32+
import org.opengrok.indexer.analysis.NumLinesLOC;
3233
import org.opengrok.indexer.analysis.OGKTextField;
3334
import org.opengrok.indexer.analysis.StreamSource;
3435
import org.opengrok.indexer.analysis.TextAnalyzer;
@@ -82,8 +83,8 @@ public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOExc
8283
args.setProject(project);
8384
Xrefer xref = writeXref(args);
8485

85-
addNumLines(doc, xref.getLineNumber());
86-
addLOC(doc, xref.getLOC());
86+
String path = doc.get(QueryBuilder.PATH);
87+
addNumLinesLOC(doc, new NumLinesLOC(path, xref.getLineNumber(), xref.getLOC()));
8788
}
8889
}
8990
}

0 commit comments

Comments
 (0)