|
44 | 44 | import java.io.FileWriter;
|
45 | 45 | import java.io.IOException;
|
46 | 46 | import java.nio.charset.StandardCharsets;
|
| 47 | +import java.nio.file.FileSystems; |
47 | 48 | import java.nio.file.Files;
|
48 | 49 | import java.nio.file.Path;
|
49 | 50 | import java.nio.file.Paths;
|
|
70 | 71 |
|
71 | 72 | public final class VFSUtils {
|
72 | 73 |
|
| 74 | + /** |
| 75 | + * Patterns which should be excluded by default, like .gitignore or SCM files. |
| 76 | + * <ul> |
| 77 | + * <li>Misc: **/*~, **/#*#, **/.#*, **/%*%, |
| 78 | + * **/._*</li> |
| 79 | + * <li>CVS: **/CVS, **/CVS/**, **/.cvsignore</li> |
| 80 | + * <li>RCS: **/RCS, **/RCS/**</li> |
| 81 | + * <li>SCCS: **/SCCS, **/SCCS/**</li> |
| 82 | + * <li>VSSercer: **/vssver.scc</li> |
| 83 | + * <li>MKS: **/project.pj</li> |
| 84 | + * <li>SVN: **/.svn, **/.svn/**</li> |
| 85 | + * <li>GNU: **/.arch-ids, **/.arch-ids/**</li> |
| 86 | + * <li>Bazaar: **/.bzr, **/.bzr/**</li> |
| 87 | + * <li>SurroundSCM: **/.MySCMServerInfo</li> |
| 88 | + * <li>Mac: **/.DS_Store</li> |
| 89 | + * <li>Serena Dimension: **/.metadata, **/.metadata/**</li> |
| 90 | + * <li>Mercurial: **/.hg, **/.hg/**</li> |
| 91 | + * <li>Git: **/.git, **/.git/**, **/.gitignore</li> |
| 92 | + * <li>Bitkeeper: **/BitKeeper, **/BitKeeper/**, **/ChangeSet, |
| 93 | + * **/ChangeSet/**</li> |
| 94 | + * <li>Darcs: **/_darcs, **/_darcs/**, **/.darcsrepo, |
| 95 | + * **/.darcsrepo/****/-darcs-backup*, **/.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 | + |
73 | 175 | public static final String VFS_ROOT = "org.graalvm.python.vfs";
|
74 | 176 | public static final String VFS_VENV = "venv";
|
75 | 177 | public static final String VFS_FILESLIST = "fileslist.txt";
|
@@ -153,23 +255,35 @@ public static void generateVFSFilesList(Path resourcesRoot, Path vfs, Set<String
|
153 | 255 | }
|
154 | 256 | try (var s = Files.walk(vfs)) {
|
155 | 257 | 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 | + } |
167 | 271 | }
|
168 | 272 | }
|
169 | 273 | });
|
170 | 274 | }
|
171 | 275 | }
|
172 | 276 |
|
| 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 | + |
173 | 287 | private static String makeDirPath(Path p) {
|
174 | 288 | String ret = p.toString();
|
175 | 289 | if (!ret.endsWith(File.separator)) {
|
|
0 commit comments