Skip to content

Commit af9d138

Browse files
committed
[GR-64271]: Add default excludes for generating filelists.txt
PullRequest: graalpython/3767
2 parents e259198 + 99469b5 commit af9d138

File tree

1 file changed

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

1 file changed

+125
-11
lines changed

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

Lines changed: 125 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.io.FileWriter;
4545
import java.io.IOException;
4646
import java.nio.charset.StandardCharsets;
47+
import java.nio.file.FileSystems;
4748
import java.nio.file.Files;
4849
import java.nio.file.Path;
4950
import java.nio.file.Paths;
@@ -70,6 +71,107 @@
7071

7172
public final class VFSUtils {
7273

74+
/**
75+
* Patterns which should be excluded by default, like .gitignore or SCM files.
76+
* <ul>
77+
* <li>Misc: &#42;&#42;/&#42;~, &#42;&#42;/#&#42;#, &#42;&#42;/.#&#42;, &#42;&#42;/%&#42;%,
78+
* &#42;&#42;/._&#42;</li>
79+
* <li>CVS: &#42;&#42;/CVS, &#42;&#42;/CVS/&#42;&#42;, &#42;&#42;/.cvsignore</li>
80+
* <li>RCS: &#42;&#42;/RCS, &#42;&#42;/RCS/&#42;&#42;</li>
81+
* <li>SCCS: &#42;&#42;/SCCS, &#42;&#42;/SCCS/&#42;&#42;</li>
82+
* <li>VSSercer: &#42;&#42;/vssver.scc</li>
83+
* <li>MKS: &#42;&#42;/project.pj</li>
84+
* <li>SVN: &#42;&#42;/.svn, &#42;&#42;/.svn/&#42;&#42;</li>
85+
* <li>GNU: &#42;&#42;/.arch-ids, &#42;&#42;/.arch-ids/&#42;&#42;</li>
86+
* <li>Bazaar: &#42;&#42;/.bzr, &#42;&#42;/.bzr/&#42;&#42;</li>
87+
* <li>SurroundSCM: &#42;&#42;/.MySCMServerInfo</li>
88+
* <li>Mac: &#42;&#42;/.DS_Store</li>
89+
* <li>Serena Dimension: &#42;&#42;/.metadata, &#42;&#42;/.metadata/&#42;&#42;</li>
90+
* <li>Mercurial: &#42;&#42;/.hg, &#42;&#42;/.hg/&#42;&#42;</li>
91+
* <li>Git: &#42;&#42;/.git, &#42;&#42;/.git/&#42;&#42;, &#42;&#42;/.gitignore</li>
92+
* <li>Bitkeeper: &#42;&#42;/BitKeeper, &#42;&#42;/BitKeeper/&#42;&#42;, &#42;&#42;/ChangeSet,
93+
* &#42;&#42;/ChangeSet/&#42;&#42;</li>
94+
* <li>Darcs: &#42;&#42;/_darcs, &#42;&#42;/_darcs/&#42;&#42;, &#42;&#42;/.darcsrepo,
95+
* &#42;&#42;/.darcsrepo/&#42;&#42;&#42;&#42;/-darcs-backup&#42;, &#42;&#42;/.darcs-temp-mail
96+
* </ul>
97+
*
98+
*
99+
* The list is a copy of the one used in tools like the Maven JAR Plugin. @see <a href=
100+
* "https://codehaus-plexus.github.io/plexus-utils/apidocs/org/codehaus/plexus/util/AbstractScanner.html#DEFAULTEXCLUDES">DEFAULTEXCLUDES</a>
101+
*/
102+
private static final String[] DEFAULT_EXCLUDES = {
103+
// Miscellaneous typical temporary files
104+
"**/*~",
105+
"**/#*#",
106+
"**/.#*",
107+
"**/%*%",
108+
"**/._*",
109+
110+
// CVS
111+
"**/CVS",
112+
"**/CVS/**",
113+
"**/.cvsignore",
114+
115+
// RCS
116+
"**/RCS",
117+
"**/RCS/**",
118+
119+
// SCCS
120+
"**/SCCS",
121+
"**/SCCS/**",
122+
123+
// Visual SourceSafe
124+
"**/vssver.scc",
125+
126+
// MKS
127+
"**/project.pj",
128+
129+
// Subversion
130+
"**/.svn",
131+
"**/.svn/**",
132+
133+
// Arch
134+
"**/.arch-ids",
135+
"**/.arch-ids/**",
136+
137+
// Bazaar
138+
"**/.bzr",
139+
"**/.bzr/**",
140+
141+
// SurroundSCM
142+
"**/.MySCMServerInfo",
143+
144+
// Mac
145+
"**/.DS_Store",
146+
147+
// Serena Dimensions Version 10
148+
"**/.metadata",
149+
"**/.metadata/**",
150+
151+
// Mercurial
152+
"**/.hg",
153+
"**/.hg/**",
154+
155+
// git
156+
"**/.git",
157+
"**/.git/**",
158+
"**/.gitignore",
159+
160+
// BitKeeper
161+
"**/BitKeeper",
162+
"**/BitKeeper/**",
163+
"**/ChangeSet",
164+
"**/ChangeSet/**",
165+
166+
// darcs
167+
"**/_darcs",
168+
"**/_darcs/**",
169+
"**/.darcsrepo",
170+
"**/.darcsrepo/**",
171+
"**/-darcs-backup*",
172+
"**/.darcs-temp-mail"
173+
};
174+
73175
public static final String VFS_ROOT = "org.graalvm.python.vfs";
74176
public static final String VFS_VENV = "venv";
75177
public static final String VFS_FILESLIST = "fileslist.txt";
@@ -153,23 +255,35 @@ public static void generateVFSFilesList(Path resourcesRoot, Path vfs, Set<String
153255
}
154256
try (var s = Files.walk(vfs)) {
155257
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);
258+
if (!shouldPathBeExcluded(p)) {
259+
String entry = null;
260+
if (Files.isDirectory(p)) {
261+
String dirPath = makeDirPath(p.toAbsolutePath());
262+
entry = dirPath.substring(rootEndIdx);
263+
} else if (Files.isRegularFile(p)) {
264+
entry = p.toAbsolutePath().toString().substring(rootEndIdx);
265+
}
266+
if (entry != null) {
267+
entry = normalizeResourcePath(entry);
268+
if (!ret.add(entry) && duplicateHandler != null) {
269+
duplicateHandler.accept(entry);
270+
}
167271
}
168272
}
169273
});
170274
}
171275
}
172276

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

0 commit comments

Comments
 (0)