Skip to content

Commit addbaaa

Browse files
author
Vladimir Kotal
committed
Merge pull request #935 from vladak/ignorednames
split ignoredNames into list for files and directories
2 parents f89c180 + 2bd934c commit addbaaa

File tree

6 files changed

+246
-65
lines changed

6 files changed

+246
-65
lines changed

src/org/opensolaris/opengrok/history/HistoryGuru.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ private void addRepositories(File[] files, Collection<RepositoryInfo> repos,
316316
}
317317

318318
/**
319-
* recursivelly search for repositories with a depth limit
319+
* recursively search for repositories with a depth limit
320320
* @param files list of files to check if they contain a repo
321321
* @param repos list of found repos
322322
* @param ignoredNames what files to ignore

src/org/opensolaris/opengrok/index/CommandLineOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public CommandLineOptions() {
8484
options.add(new Option('H', null, "Generate history cache for all repositories"));
8585
options.add(new Option('h', "/path/to/repository", "just generate history cache for the specified repos (absolute path from source root)"));
8686
options.add(new Option('I', "pattern", "Only files matching this pattern will be examined (supports wildcards, example: -I *.java -I *.c)"));
87-
options.add(new Option('i', "pattern", "Ignore the named files or directories (supports wildcards, example: -i *.so -i *.dll)"));
87+
options.add(new Option('i', "pattern", "Ignore the named files (prefix with 'f:') or directories (prefix with 'd:') (supports wildcards, example: -i *.so -i *.dll)"));
8888
options.add(new Option('j', "class", "Name of the JDBC driver class used by the history cache. Can use one of the shorthands \"client\" (org.apache.derby.jdbc.ClientDriver) or \"embedded\" (org.apache.derby.jdbc.EmbeddedDriver). Default: \"client\""));
8989
options.add(new Option('k', "/path/to/repository", "Kill the history cache for the given repository and exit. Use '*' to delete the cache for all repositories."));
9090
options.add(new Option('K', null, "List all repository pathes and exit."));
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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) 2015, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opensolaris.opengrok.index;
24+
25+
import java.io.File;
26+
27+
/**
28+
* This class maintains a list of directory names, SRC_ROOT
29+
* relative file paths (like "usr/src/uts"), and glob
30+
* patterns (like .make.*) which opengrok should ignore.
31+
*
32+
* @author Chandan
33+
*/
34+
public final class IgnoredDirs extends Filter {
35+
private static final String[] defaultPatternsDirs = {
36+
"SCCS",
37+
"CVS",
38+
"RCS",
39+
// Teamware
40+
"Codemgr_wsdata",
41+
"deleted_files",
42+
"CVSROOT",
43+
".svn",
44+
".git",
45+
".hg",
46+
".razor",
47+
".bzr",
48+
};
49+
50+
public IgnoredDirs() {
51+
super();
52+
addDefaultPatterns();
53+
}
54+
55+
/**
56+
* Should the file be ignored or not?
57+
* @param file the file to check
58+
* @return true if this file should be ignored, false otherwise
59+
*/
60+
public boolean ignore(File file) {
61+
return match(file) && file.isDirectory();
62+
}
63+
64+
/**
65+
* Should the file be ignored or not?
66+
* @param name the name of the file to check
67+
* @return true if this pathname should be ignored, false otherwise
68+
*/
69+
public boolean ignore(String name) {
70+
return match(name);
71+
}
72+
73+
private void addDefaultPatterns() {
74+
for (String s : defaultPatternsDirs) {
75+
add(s);
76+
}
77+
}
78+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opensolaris.opengrok.index;
24+
25+
import java.io.File;
26+
27+
/**
28+
* This class maintains a list of file names (like "cscope.out"), SRC_ROOT
29+
* relative file paths (like "usr/src/uts" or "usr/src/Makefile"), and glob
30+
* patterns (like .make.*) which opengrok should ignore.
31+
*
32+
* @author Chandan
33+
*/
34+
public final class IgnoredFiles extends Filter {
35+
private static final String[] defaultPatternsFiles = {
36+
"cscope.in.out",
37+
"cscope.out.po",
38+
"cscope.out.in",
39+
"cscope.po.out",
40+
"cscope.po.in",
41+
"cscope.files",
42+
"cscope.out",
43+
// CVS
44+
".cvsignore",
45+
".repo",
46+
".hgtags",
47+
".p4config",
48+
"*~",
49+
".make.*",
50+
".del-*",
51+
"_MTN",
52+
// File Extensions for Visual Studio and Mono Projects
53+
".vspscc",
54+
".suo",
55+
".vssscc",
56+
".user",
57+
".ncb",
58+
".gpState",
59+
".snc",
60+
".sln",
61+
".vsmdi",
62+
".dll",
63+
".opengrok_skip_history",
64+
};
65+
66+
public IgnoredFiles() {
67+
super();
68+
addDefaultPatterns();
69+
}
70+
71+
/**
72+
* Should the file be ignored or not?
73+
* @param file the file to check
74+
* @return true if this file should be ignored, false otherwise
75+
*/
76+
public boolean ignore(File file) {
77+
return match(file) && file.isFile();
78+
}
79+
80+
/**
81+
* Should the file be ignored or not?
82+
* @param name the name of the file to check
83+
* @return true if this pathname should be ignored, false otherwise
84+
*/
85+
public boolean ignore(String name) {
86+
return match(name);
87+
}
88+
89+
private void addDefaultPatterns() {
90+
for (String s : defaultPatternsFiles) {
91+
add(s);
92+
}
93+
}
94+
}

src/org/opensolaris/opengrok/index/IgnoredNames.java

Lines changed: 48 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -18,76 +18,66 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opensolaris.opengrok.index;
2424

2525
import java.io.File;
26+
import java.util.ArrayList;
27+
import java.util.List;
28+
import org.opensolaris.opengrok.index.IgnoredDirs;
29+
import org.opensolaris.opengrok.index.IgnoredFiles;
30+
2631

2732
/**
28-
* This class maintains a list of file names (like "cscope.out"), SRC_ROOT
29-
* relative file paths (like "usr/src/uts" or "usr/src/Makefile"), and glob
30-
* patterns (like .make.*) which opengrok should ignore.
31-
*
32-
* @author Chandan
33+
* wrapper class for IgnoredFiles and IgnoredDirs
34+
*
35+
* @author Vladimir Kotal
3336
*/
34-
public final class IgnoredNames extends Filter {
35-
private static final String[] defaultPatterns = {
36-
"SCCS",
37-
"CVS",
38-
"RCS",
39-
"cscope.in.out",
40-
"cscope.out.po",
41-
"cscope.out.in",
42-
"cscope.po.out",
43-
"cscope.po.in",
44-
"cscope.files",
45-
"cscope.out",
46-
"Codemgr_wsdata",
47-
".cvsignore",
48-
"CVSROOT",
49-
// tags are leftover from the time when ctags did not run daemonized
50-
// "TAGS",
51-
// "tags",
52-
".svn",
53-
".git",
54-
".repo",
55-
".hg",
56-
".hgtags",
57-
".bzr",
58-
".p4config",
59-
".razor",
60-
"*~",
61-
"deleted_files",
62-
".make.*",
63-
".del-*",
64-
"_MTN",
65-
// File Extensions for Visual Studio and Mono Projects
66-
".vspscc",
67-
".suo",
68-
".vssscc",
69-
".user",
70-
".ncb",
71-
".gpState",
72-
".snc",
73-
".sln",
74-
".vsmdi",
75-
".dll",
76-
".opengrok_skip_history",
77-
};
37+
public class IgnoredNames {
38+
private IgnoredFiles ignoredFiles;
39+
private IgnoredDirs ignoredDirs;
7840

7941
public IgnoredNames() {
80-
super();
81-
addDefaultPatterns();
42+
ignoredFiles = new IgnoredFiles();
43+
ignoredDirs = new IgnoredDirs();
44+
}
45+
46+
public List<String> getItems() {
47+
List<String> twoLists = new ArrayList<>();
48+
twoLists.addAll(ignoredFiles.getItems());
49+
twoLists.addAll(ignoredDirs.getItems());
50+
return twoLists;
8251
}
8352

53+
public void add(String pattern) {
54+
if (pattern.startsWith("f:")) {
55+
ignoredFiles.add(pattern.substring(2));
56+
} else if (pattern.startsWith("d:")) {
57+
ignoredDirs.add(pattern.substring(2));
58+
} else {
59+
// backward compatibility
60+
ignoredFiles.add(pattern);
61+
}
62+
}
63+
64+
public void setItems(List<String> item) {
65+
clear();
66+
for (String s : item) {
67+
add(s);
68+
}
69+
}
70+
8471
/**
8572
* Should the file be ignored or not?
8673
* @param file the file to check
8774
* @return true if this file should be ignored, false otherwise
8875
*/
8976
public boolean ignore(File file) {
90-
return match(file);
77+
if (file.isFile())
78+
return ignoredFiles.match(file);
79+
else
80+
return ignoredDirs.match(file);
9181
}
9282

9383
/**
@@ -96,12 +86,11 @@ public boolean ignore(File file) {
9686
* @return true if this pathname should be ignored, false otherwise
9787
*/
9888
public boolean ignore(String name) {
99-
return match(name);
89+
return ignoredFiles.match(name) || ignoredDirs.match(name);
10090
}
101-
102-
private void addDefaultPatterns() {
103-
for (String s : defaultPatterns) {
104-
add(s);
105-
}
91+
92+
public void clear() {
93+
ignoredFiles.clear();
94+
ignoredDirs.clear();
10695
}
10796
}

test/org/opensolaris/opengrok/index/IgnoredNamesTest.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323

2424
package org.opensolaris.opengrok.index;
@@ -28,16 +28,30 @@
2828
import java.util.List;
2929
import org.junit.Test;
3030
import static org.junit.Assert.*;
31+
import org.junit.BeforeClass;
32+
import org.opensolaris.opengrok.analysis.Ctags;
33+
import org.opensolaris.opengrok.analysis.c.CAnalyzerFactoryTest;
34+
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
35+
import org.opensolaris.opengrok.util.TestRepository;
3136

3237
/**
3338
*
3439
* @author Trond Norbye
3540
*/
3641
public class IgnoredNamesTest {
42+
private static TestRepository repository;
43+
44+
@BeforeClass
45+
public static void setUpClass() throws Exception {
46+
repository = new TestRepository();
47+
repository.create(CAnalyzerFactoryTest.class.getResourceAsStream(
48+
"/org/opensolaris/opengrok/index/source.zip"));
49+
}
50+
3751
@Test
3852
public void testIgnoredPatterns() {
3953
IgnoredNames instance = new IgnoredNames();
40-
54+
4155
List<String> names = instance.getItems();
4256
assertNotNull(names);
4357

@@ -67,10 +81,12 @@ public void testIgnoredPatterns() {
6781
assertTrue(instance.ignore(".o"));
6882
assertFalse(instance.ignore("foo.oo"));
6983

70-
instance.add("Makefile");
84+
instance.add("f:Makefile");
7185
names = instance.getItems();
7286
assertEquals(2, names.size());
73-
assertTrue(instance.ignore(new File("Makefile")));
87+
assertTrue(instance.ignore(new File(repository.getSourceRoot() +
88+
"/c/Makefile")));
89+
7490
assertFalse(instance.ignore("main.c"));
7591

7692
instance.add("o*o?.a?c*");
@@ -79,6 +95,10 @@ public void testIgnoredPatterns() {
7995
assertFalse(instance.ignore("opengrok.ac"));
8096
assertFalse(instance.ignore("grok.abcd"));
8197

98+
instance.add("d:haskell");
99+
assertTrue(instance.ignore(new File(repository.getSourceRoot() +
100+
"/haskell")));
101+
82102
instance.clear();
83103
names = instance.getItems();
84104
assertEquals(0, names.size());

0 commit comments

Comments
 (0)