Skip to content

Commit 3dc183f

Browse files
committed
Add default excludes for generating filelists.txt
1 parent 6a78dd1 commit 3dc183f

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;
@@ -70,6 +72,104 @@
7072

7173
public final class VFSUtils {
7274

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

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

0 commit comments

Comments
 (0)