Skip to content

Commit 40669ec

Browse files
idodeclareVladimir Kotal
authored andcommitted
Fix #770 Fix #1351 : use PathAccepter in FileHistoryCache
- Extract path-based including/ignoring to configuration - Also, relocate Filter, IgnoredDirs, IgnoredFiles, IgnoredNames to configuration
1 parent 4f99ffa commit 40669ec

File tree

19 files changed

+243
-122
lines changed

19 files changed

+243
-122
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Configuration.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
import org.opengrok.indexer.authorization.AuthControlFlag;
6060
import org.opengrok.indexer.authorization.AuthorizationStack;
6161
import org.opengrok.indexer.history.RepositoryInfo;
62-
import org.opengrok.indexer.index.Filter;
63-
import org.opengrok.indexer.index.IgnoredNames;
6462
import org.opengrok.indexer.logger.LoggerFactory;
6563

6664

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/ConfigurationHelp.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2018-2019, Chris Fraire <cfraire@me.com>.
21+
* Copyright (c) 2018-2020, Chris Fraire <cfraire@me.com>.
2222
*/
2323

2424
package org.opengrok.indexer.configuration;
@@ -39,8 +39,6 @@
3939
import org.opengrok.indexer.authorization.AuthorizationPlugin;
4040
import org.opengrok.indexer.authorization.AuthorizationStack;
4141
import org.opengrok.indexer.history.RepositoryInfo;
42-
import org.opengrok.indexer.index.Filter;
43-
import org.opengrok.indexer.index.IgnoredNames;
4442
import org.opengrok.indexer.util.StringUtils;
4543

4644
/**

opengrok-indexer/src/main/java/org/opengrok/indexer/index/Filter.java renamed to opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Filter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
/*
2121
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2020, Chris Fraire <cfraire@me.com>.
2223
*/
2324

24-
package org.opengrok.indexer.index;
25+
package org.opengrok.indexer.configuration;
2526

2627
import java.io.File;
2728
import java.io.Serializable;

opengrok-indexer/src/main/java/org/opengrok/indexer/index/IgnoredDirs.java renamed to opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/IgnoredDirs.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
/*
2121
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2019, Chris Fraire <cfraire@me.com>.
22+
* Portions Copyright (c) 2019-2020, Chris Fraire <cfraire@me.com>.
2323
*/
24-
package org.opengrok.indexer.index;
24+
package org.opengrok.indexer.configuration;
2525

2626
import java.io.File;
2727

opengrok-indexer/src/main/java/org/opengrok/indexer/index/IgnoredFiles.java renamed to opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/IgnoredFiles.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
/*
2121
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2019, Chris Fraire <cfraire@me.com>.
22+
* Portions Copyright (c) 2019-2020, Chris Fraire <cfraire@me.com>.
2323
*/
24-
package org.opengrok.indexer.index;
24+
package org.opengrok.indexer.configuration;
2525

2626
import java.io.File;
2727

opengrok-indexer/src/main/java/org/opengrok/indexer/index/IgnoredNames.java renamed to opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/IgnoredNames.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
/*
2121
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2019, Chris Fraire <cfraire@me.com>.
22+
* Portions Copyright (c) 2019-2020, Chris Fraire <cfraire@me.com>.
2323
*/
24-
package org.opengrok.indexer.index;
24+
package org.opengrok.indexer.configuration;
2525

2626
import java.io.File;
2727
import java.io.Serializable;
@@ -60,6 +60,12 @@ public void setItems(List<String> item) {
6060
}
6161
}
6262

63+
/**
64+
* Adds the specified {@code pattern} if it follows the expected naming
65+
* convention (or else ignored).
66+
* @param pattern defined pattern starting either with {@code "f:"} for
67+
* ignore-file or with {@code "d:"} for an ignore-directory
68+
*/
6369
public void add(String pattern) {
6470
if (pattern.startsWith(FILE_PREFIX)) {
6571
ignoredFiles.add(pattern.substring(FILE_PREFIX.length()));
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
23+
*/
24+
25+
package org.opengrok.indexer.configuration;
26+
27+
import org.opengrok.indexer.logger.LoggerFactory;
28+
29+
import java.io.File;
30+
import java.util.logging.Level;
31+
import java.util.logging.Logger;
32+
33+
/**
34+
* Represents a gatekeeper that decides whether a particular file or directory
35+
* is acceptable for history or code analysis with respect to configuration of
36+
* ignored files and directories or of specified inclusive filtering.
37+
*/
38+
public class PathAccepter {
39+
40+
private static final Logger LOGGER = LoggerFactory.getLogger(PathAccepter.class);
41+
42+
private final IgnoredNames ignoredNames;
43+
private final Filter includedNames;
44+
45+
/**
46+
* Package-private to be initialized from the runtime environment.
47+
*/
48+
PathAccepter(IgnoredNames ignoredNames, Filter includedNames) {
49+
this.ignoredNames = ignoredNames;
50+
this.includedNames = includedNames;
51+
}
52+
53+
/**
54+
* Evaluates the specified {@code file} versus the runtime configuration of
55+
* ignored files and directories or of specified inclusive filtering, and
56+
* returns a value whether the {@code file} is to be accepted.
57+
* @param file a defined instance under the source root
58+
*/
59+
public boolean accept(File file) {
60+
if (!includedNames.isEmpty()
61+
&& // the filter should not affect directory names
62+
(!(file.isDirectory() || includedNames.match(file)))) {
63+
LOGGER.log(Level.FINER, "not including {0}", file.getAbsolutePath());
64+
return false;
65+
}
66+
67+
if (ignoredNames.ignore(file)) {
68+
LOGGER.log(Level.FINER, "ignoring {0}", file.getAbsolutePath());
69+
return false;
70+
}
71+
72+
return true;
73+
}
74+
}

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/RuntimeEnvironment.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@
6262
import org.opengrok.indexer.authorization.AuthorizationStack;
6363
import org.opengrok.indexer.history.HistoryGuru;
6464
import org.opengrok.indexer.history.RepositoryInfo;
65-
import org.opengrok.indexer.index.Filter;
66-
import org.opengrok.indexer.index.IgnoredNames;
6765
import org.opengrok.indexer.index.IndexDatabase;
6866
import org.opengrok.indexer.index.IndexerParallelizer;
6967
import org.opengrok.indexer.logger.LoggerFactory;
@@ -190,6 +188,13 @@ public IndexerParallelizer getIndexerParallelizer() {
190188
return lzIndexerParallelizer.get();
191189
}
192190

191+
/**
192+
* Gets an instance associated to this environment.
193+
*/
194+
public PathAccepter getPathAccepter() {
195+
return new PathAccepter(getIgnoredNames(), getIncludedNames());
196+
}
197+
193198
private String getCanonicalPath(String s) {
194199
if (s == null) {
195200
return null;
@@ -704,8 +709,7 @@ public void removeRepositories() {
704709
*/
705710
public void setRepositories(String... dir) {
706711
List<RepositoryInfo> repos = new ArrayList<>(HistoryGuru.getInstance().
707-
addRepositories(Arrays.stream(dir).map(File::new).toArray(File[]::new),
708-
getIgnoredNames()));
712+
addRepositories(Arrays.stream(dir).map(File::new).toArray(File[]::new)));
709713
setRepositories(repos);
710714
}
711715

0 commit comments

Comments
 (0)