Skip to content

Commit 9c3b032

Browse files
[GR-64272] Backport to 24.2:: Add default excludes for generating filelists.txt
PullRequest: graalpython/3773
2 parents 07d524a + 6877b76 commit 9c3b032

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;
@@ -64,6 +65,107 @@
6465

6566
public final class VFSUtils {
6667

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

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

0 commit comments

Comments
 (0)