Skip to content

Commit 9209769

Browse files
horakivoelkorchi
authored andcommitted
Add default excludes for generating filelists.txt
(cherry picked from commit 3dc183f)
1 parent 7d19644 commit 9209769

File tree

1 file changed

+123
-11
lines changed
  • graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs

1 file changed

+123
-11
lines changed

graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java

Lines changed: 123 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import java.io.FileWriter;
4545
import java.io.IOException;
4646
import java.nio.charset.StandardCharsets;
47+
import java.nio.file.FileSystem;
48+
import java.nio.file.FileSystems;
4749
import java.nio.file.Files;
4850
import java.nio.file.Path;
4951
import java.nio.file.Paths;
@@ -64,6 +66,104 @@
6466

6567
public final class VFSUtils {
6668

69+
/**
70+
* Patterns which should be excluded by default, like .gitignore or SCM files
71+
* <ul>
72+
* <li>Misc: &#42;&#42;/&#42;~, &#42;&#42;/#&#42;#, &#42;&#42;/.#&#42;, &#42;&#42;/%&#42;%,
73+
* &#42;&#42;/._&#42;</li>
74+
* <li>CVS: &#42;&#42;/CVS, &#42;&#42;/CVS/&#42;&#42;, &#42;&#42;/.cvsignore</li>
75+
* <li>RCS: &#42;&#42;/RCS, &#42;&#42;/RCS/&#42;&#42;</li>
76+
* <li>SCCS: &#42;&#42;/SCCS, &#42;&#42;/SCCS/&#42;&#42;</li>
77+
* <li>VSSercer: &#42;&#42;/vssver.scc</li>
78+
* <li>MKS: &#42;&#42;/project.pj</li>
79+
* <li>SVN: &#42;&#42;/.svn, &#42;&#42;/.svn/&#42;&#42;</li>
80+
* <li>GNU: &#42;&#42;/.arch-ids, &#42;&#42;/.arch-ids/&#42;&#42;</li>
81+
* <li>Bazaar: &#42;&#42;/.bzr, &#42;&#42;/.bzr/&#42;&#42;</li>
82+
* <li>SurroundSCM: &#42;&#42;/.MySCMServerInfo</li>
83+
* <li>Mac: &#42;&#42;/.DS_Store</li>
84+
* <li>Serena Dimension: &#42;&#42;/.metadata, &#42;&#42;/.metadata/&#42;&#42;</li>
85+
* <li>Mercurial: &#42;&#42;/.hg, &#42;&#42;/.hg/&#42;&#42;</li>
86+
* <li>Git: &#42;&#42;/.git, &#42;&#42;/.git/&#42;&#42;, &#42;&#42;/.gitignore</li>
87+
* <li>Bitkeeper: &#42;&#42;/BitKeeper, &#42;&#42;/BitKeeper/&#42;&#42;, &#42;&#42;/ChangeSet,
88+
* &#42;&#42;/ChangeSet/&#42;&#42;</li>
89+
* <li>Darcs: &#42;&#42;/_darcs, &#42;&#42;/_darcs/&#42;&#42;, &#42;&#42;/.darcsrepo,
90+
* &#42;&#42;/.darcsrepo/&#42;&#42;&#42;&#42;/-darcs-backup&#42;, &#42;&#42;/.darcs-temp-mail
91+
* </ul>
92+
*
93+
*/
94+
private static final String[] DEFAULT_EXCLUDES = {
95+
// Miscellaneous typical temporary files
96+
"**/*~",
97+
"**/#*#",
98+
"**/.#*",
99+
"**/%*%",
100+
"**/._*",
101+
102+
// CVS
103+
"**/CVS",
104+
"**/CVS/**",
105+
"**/.cvsignore",
106+
107+
// RCS
108+
"**/RCS",
109+
"**/RCS/**",
110+
111+
// SCCS
112+
"**/SCCS",
113+
"**/SCCS/**",
114+
115+
// Visual SourceSafe
116+
"**/vssver.scc",
117+
118+
// MKS
119+
"**/project.pj",
120+
121+
// Subversion
122+
"**/.svn",
123+
"**/.svn/**",
124+
125+
// Arch
126+
"**/.arch-ids",
127+
"**/.arch-ids/**",
128+
129+
// Bazaar
130+
"**/.bzr",
131+
"**/.bzr/**",
132+
133+
// SurroundSCM
134+
"**/.MySCMServerInfo",
135+
136+
// Mac
137+
"**/.DS_Store",
138+
139+
// Serena Dimensions Version 10
140+
"**/.metadata",
141+
"**/.metadata/**",
142+
143+
// Mercurial
144+
"**/.hg",
145+
"**/.hg/**",
146+
147+
// git
148+
"**/.git",
149+
"**/.git/**",
150+
"**/.gitignore",
151+
152+
// BitKeeper
153+
"**/BitKeeper",
154+
"**/BitKeeper/**",
155+
"**/ChangeSet",
156+
"**/ChangeSet/**",
157+
158+
// darcs
159+
"**/_darcs",
160+
"**/_darcs/**",
161+
"**/.darcsrepo",
162+
"**/.darcsrepo/**",
163+
"**/-darcs-backup*",
164+
"**/.darcs-temp-mail"
165+
};
166+
67167
public static final String VFS_ROOT = "org.graalvm.python.vfs";
68168
public static final String VFS_VENV = "venv";
69169
public static final String VFS_FILESLIST = "fileslist.txt";
@@ -152,23 +252,35 @@ public static void generateVFSFilesList(Path resourcesRoot, Path vfs, Set<String
152252
}
153253
try (var s = Files.walk(vfs)) {
154254
s.forEach(p -> {
155-
String entry = null;
156-
if (Files.isDirectory(p)) {
157-
String dirPath = makeDirPath(p.toAbsolutePath());
158-
entry = dirPath.substring(rootEndIdx);
159-
} else if (Files.isRegularFile(p)) {
160-
entry = p.toAbsolutePath().toString().substring(rootEndIdx);
161-
}
162-
if (entry != null) {
163-
entry = normalizeResourcePath(entry);
164-
if (!ret.add(entry) && duplicateHandler != null) {
165-
duplicateHandler.accept(entry);
255+
if (!shouldPathBeExcluded(p)) {
256+
String entry = null;
257+
if (Files.isDirectory(p)) {
258+
String dirPath = makeDirPath(p.toAbsolutePath());
259+
entry = dirPath.substring(rootEndIdx);
260+
} else if (Files.isRegularFile(p)) {
261+
entry = p.toAbsolutePath().toString().substring(rootEndIdx);
262+
}
263+
if (entry != null) {
264+
entry = normalizeResourcePath(entry);
265+
if (!ret.add(entry) && duplicateHandler != null) {
266+
duplicateHandler.accept(entry);
267+
}
166268
}
167269
}
168270
});
169271
}
170272
}
171273

274+
private static boolean shouldPathBeExcluded(Path path) {
275+
for (String glob : DEFAULT_EXCLUDES) {
276+
var matcher = FileSystems.getDefault().getPathMatcher("glob:" + glob);
277+
if (matcher.matches(path)) {
278+
return true;
279+
}
280+
}
281+
return false;
282+
}
283+
172284
private static String makeDirPath(Path p) {
173285
String ret = p.toString();
174286
if (!ret.endsWith(File.separator)) {

0 commit comments

Comments
 (0)