-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathDirectoryScannerTest.java
More file actions
618 lines (493 loc) · 23.4 KB
/
DirectoryScannerTest.java
File metadata and controls
618 lines (493 loc) · 23.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
package org.codehaus.plexus.util;
/*
* Copyright The Codehaus Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
/**
* Base class for testcases doing tests with files.
*
* @author Dan T. Tran
* @since 3.4.0
*/
class DirectoryScannerTest extends FileBasedTestCase {
private static final String testDir = getTestDirectory().getPath();
@BeforeEach
void setUp() {
try {
FileUtils.deleteDirectory(testDir);
} catch (IOException e) {
fail("Could not delete directory " + testDir);
}
}
@Test
void crossPlatformIncludesString() throws Exception {
DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(new File(getTestResourcesDir() + File.separator + "directory-scanner").getCanonicalFile());
String fs;
if (File.separatorChar == '/') {
fs = "\\";
} else {
fs = "/";
}
ds.setIncludes(new String[] {"foo" + fs});
ds.addDefaultExcludes();
ds.scan();
String[] files = ds.getIncludedFiles();
assertEquals(1, files.length);
}
@Test
void crossPlatformExcludesString() throws Exception {
DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(new File(getTestResourcesDir() + File.separator + "directory-scanner").getCanonicalFile());
ds.setIncludes(new String[] {"**"});
String fs;
if (File.separatorChar == '/') {
fs = "\\";
} else {
fs = "/";
}
ds.setExcludes(new String[] {"foo" + fs});
ds.addDefaultExcludes();
ds.scan();
String[] files = ds.getIncludedFiles();
assertEquals(0, files.length);
}
private String getTestResourcesDir() throws URISyntaxException {
ClassLoader cloader = Thread.currentThread().getContextClassLoader();
URL resource = cloader.getResource("test.txt");
if (resource == null) {
fail("Cannot locate test-resources directory containing 'test.txt' in the classloader.");
}
File file = new File(new URI(resource.toExternalForm()).normalize().getPath());
return file.getParent();
}
private void createTestFiles() throws IOException {
FileUtils.mkdir(testDir);
this.createFile(new File(testDir + "/scanner1.dat"), 0);
this.createFile(new File(testDir + "/scanner2.dat"), 0);
this.createFile(new File(testDir + "/scanner3.dat"), 0);
this.createFile(new File(testDir + "/scanner4.dat"), 0);
this.createFile(new File(testDir + "/scanner5.dat"), 0);
}
/**
* Check if 'src/test/resources/symlinks/src/sym*' test files (start with 'sym') exist and are symlinks.<br>
* On some OS (like Windows 10), the 'git clone' requires to be executed with admin permissions and the
* 'core.symlinks=true' git option.
*
* @return true If files here and symlinks, false otherwise
*/
private boolean checkTestFilesSymlinks() {
File symlinksDirectory = new File("src/test/resources/symlinks/src");
try {
List<String> symlinks =
FileUtils.getFileAndDirectoryNames(symlinksDirectory, "sym*", null, true, true, true, true);
if (symlinks.isEmpty()) {
throw new IOException("Symlinks files/directories are not present");
}
for (String symLink : symlinks) {
if (!Files.isSymbolicLink(Paths.get(symLink))) {
throw new IOException(String.format("Path is not a symlink: %s", symLink));
}
}
return true;
} catch (IOException e) {
System.err.printf(
"The unit test '%s.%s' will be skipped, reason: %s%n",
this.getClass().getSimpleName(), getTestMethodName(), e.getMessage());
System.out.printf("This test requires symlinks files in '%s' directory.%n", symlinksDirectory.getPath());
System.out.println("On some OS (like Windows 10), files are present only if the clone/checkout is done"
+ " in administrator mode, and correct (symlinks and not flat file/directory)"
+ " if symlinks option are used (for git: git clone -c core.symlinks=true [url])");
return false;
}
}
@Test
void general() throws Exception {
this.createTestFiles();
String includes = "scanner1.dat,scanner2.dat,scanner3.dat,scanner4.dat,scanner5.dat";
String excludes = "scanner1.dat,scanner2.dat";
List<File> fileNames = FileUtils.getFiles(new File(testDir), includes, excludes, false);
assertEquals(3, fileNames.size(), "Wrong number of results.");
assertTrue(fileNames.contains(new File("scanner3.dat")), "3 not found.");
assertTrue(fileNames.contains(new File("scanner4.dat")), "4 not found.");
assertTrue(fileNames.contains(new File("scanner5.dat")), "5 not found.");
}
@Test
void includesExcludesWithWhiteSpaces() throws Exception {
this.createTestFiles();
String includes = "scanner1.dat,\n \n,scanner2.dat \n\r, scanner3.dat\n, \tscanner4.dat,scanner5.dat\n,";
String excludes = "scanner1.dat,\n \n,scanner2.dat \n\r,,";
List<File> fileNames = FileUtils.getFiles(new File(testDir), includes, excludes, false);
assertEquals(3, fileNames.size(), "Wrong number of results.");
assertTrue(fileNames.contains(new File("scanner3.dat")), "3 not found.");
assertTrue(fileNames.contains(new File("scanner4.dat")), "4 not found.");
assertTrue(fileNames.contains(new File("scanner5.dat")), "5 not found.");
}
@Test
void followSymlinksFalse() {
assumeTrue(checkTestFilesSymlinks());
DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(new File("src/test/resources/symlinks/src/"));
ds.setFollowSymlinks(false);
ds.scan();
List<String> included = Arrays.asList(ds.getIncludedFiles());
assertAlwaysIncluded(included);
assertEquals(9, included.size());
List<String> includedDirs = Arrays.asList(ds.getIncludedDirectories());
assertTrue(includedDirs.contains("")); // w00t !
assertTrue(includedDirs.contains("aRegularDir"));
assertTrue(includedDirs.contains("symDir"));
assertTrue(includedDirs.contains("symLinkToDirOnTheOutside"));
assertTrue(includedDirs.contains("targetDir"));
assertEquals(5, includedDirs.size());
}
private void assertAlwaysIncluded(List<String> included) {
assertTrue(included.contains("aRegularDir" + File.separator + "aRegularFile.txt"));
assertTrue(included.contains("targetDir" + File.separator + "targetFile.txt"));
assertTrue(included.contains("fileR.txt"));
assertTrue(included.contains("fileW.txt"));
assertTrue(included.contains("fileX.txt"));
assertTrue(included.contains("symR"));
assertTrue(included.contains("symW"));
assertTrue(included.contains("symX"));
assertTrue(included.contains("symLinkToFileOnTheOutside"));
}
@Test
void followSymlinks() {
assumeTrue(checkTestFilesSymlinks());
DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(new File("src/test/resources/symlinks/src/"));
ds.setFollowSymlinks(true);
ds.scan();
List<String> included = Arrays.asList(ds.getIncludedFiles());
assertAlwaysIncluded(included);
assertTrue(included.contains("symDir" + File.separator + "targetFile.txt"));
assertTrue(included.contains("symLinkToDirOnTheOutside" + File.separator + "FileInDirOnTheOutside.txt"));
assertEquals(11, included.size());
List<String> includedDirs = Arrays.asList(ds.getIncludedDirectories());
assertTrue(includedDirs.contains("")); // w00t !
assertTrue(includedDirs.contains("aRegularDir"));
assertTrue(includedDirs.contains("symDir"));
assertTrue(includedDirs.contains("symLinkToDirOnTheOutside"));
assertTrue(includedDirs.contains("targetDir"));
assertEquals(5, includedDirs.size());
}
private void createTestDirectories() throws IOException {
FileUtils.mkdir(testDir + File.separator + "directoryTest");
FileUtils.mkdir(testDir + File.separator + "directoryTest" + File.separator + "testDir123");
FileUtils.mkdir(testDir + File.separator + "directoryTest" + File.separator + "test_dir_123");
FileUtils.mkdir(testDir + File.separator + "directoryTest" + File.separator + "test-dir-123");
this.createFile(
new File(testDir + File.separator + "directoryTest" + File.separator + "testDir123" + File.separator
+ "file1.dat"),
0);
this.createFile(
new File(testDir + File.separator + "directoryTest" + File.separator + "test_dir_123" + File.separator
+ "file1.dat"),
0);
this.createFile(
new File(testDir + File.separator + "directoryTest" + File.separator + "test-dir-123" + File.separator
+ "file1.dat"),
0);
}
@Test
void directoriesWithHyphens() throws Exception {
this.createTestDirectories();
DirectoryScanner ds = new DirectoryScanner();
String[] includes = {"**/*.dat"};
String[] excludes = {""};
ds.setIncludes(includes);
ds.setExcludes(excludes);
ds.setBasedir(new File(testDir + File.separator + "directoryTest"));
ds.setCaseSensitive(true);
ds.scan();
String[] files = ds.getIncludedFiles();
assertEquals(3, files.length, "Wrong number of results.");
}
@Test
void antExcludesOverrideIncludes() throws Exception {
printTestHeader();
File dir = new File(testDir, "regex-dir");
dir.mkdirs();
String[] excludedPaths = {"target/foo.txt"};
createFiles(dir, excludedPaths);
String[] includedPaths = {"src/main/resources/project/target/foo.txt"};
createFiles(dir, includedPaths);
DirectoryScanner ds = new DirectoryScanner();
String[] includes = {"**/target/*"};
String[] excludes = {"target/*"};
// This doesn't work, since excluded patterns refine included ones, meaning they operate on
// the list of paths that passed the included patterns, and can override them.
// String[] includes = {"**src/**/target/**/*" };
// String[] excludes = { "**/target/**/*" };
ds.setIncludes(includes);
ds.setExcludes(excludes);
ds.setBasedir(dir);
ds.scan();
assertInclusionsAndExclusions(ds.getIncludedFiles(), excludedPaths, includedPaths);
}
@Test
void antExcludesOverrideIncludesWithExplicitAntPrefix() throws Exception {
printTestHeader();
File dir = new File(testDir, "regex-dir");
dir.mkdirs();
String[] excludedPaths = {"target/foo.txt"};
createFiles(dir, excludedPaths);
String[] includedPaths = {"src/main/resources/project/target/foo.txt"};
createFiles(dir, includedPaths);
DirectoryScanner ds = new DirectoryScanner();
String[] includes = {SelectorUtils.ANT_HANDLER_PREFIX + "**/target/**/*" + SelectorUtils.PATTERN_HANDLER_SUFFIX
};
String[] excludes = {SelectorUtils.ANT_HANDLER_PREFIX + "target/**/*" + SelectorUtils.PATTERN_HANDLER_SUFFIX};
// This doesn't work, since excluded patterns refine included ones, meaning they operate on
// the list of paths that passed the included patterns, and can override them.
// String[] includes = {"**src/**/target/**/*" };
// String[] excludes = { "**/target/**/*" };
ds.setIncludes(includes);
ds.setExcludes(excludes);
ds.setBasedir(dir);
ds.scan();
assertInclusionsAndExclusions(ds.getIncludedFiles(), excludedPaths, includedPaths);
}
@Test
void regexIncludeWithExcludedPrefixDirs() throws Exception {
printTestHeader();
File dir = new File(testDir, "regex-dir");
dir.mkdirs();
String[] excludedPaths = {"src/main/foo.txt"};
createFiles(dir, excludedPaths);
String[] includedPaths = {"src/main/resources/project/target/foo.txt"};
createFiles(dir, includedPaths);
String regex = ".+/target.*";
DirectoryScanner ds = new DirectoryScanner();
String includeExpr = SelectorUtils.REGEX_HANDLER_PREFIX + regex + SelectorUtils.PATTERN_HANDLER_SUFFIX;
String[] includes = {includeExpr};
ds.setIncludes(includes);
ds.setBasedir(dir);
ds.scan();
assertInclusionsAndExclusions(ds.getIncludedFiles(), excludedPaths, includedPaths);
}
@Test
void regexExcludeWithNegativeLookahead() throws Exception {
printTestHeader();
File dir = new File(testDir, "regex-dir");
try {
FileUtils.deleteDirectory(dir);
} catch (IOException ignored) {
}
dir.mkdirs();
String[] excludedPaths = {"target/foo.txt"};
createFiles(dir, excludedPaths);
String[] includedPaths = {"src/main/resources/project/target/foo.txt"};
createFiles(dir, includedPaths);
String regex = "(?!.*src/).*target.*";
DirectoryScanner ds = new DirectoryScanner();
String excludeExpr = SelectorUtils.REGEX_HANDLER_PREFIX + regex + SelectorUtils.PATTERN_HANDLER_SUFFIX;
String[] excludes = {excludeExpr};
ds.setExcludes(excludes);
ds.setBasedir(dir);
ds.scan();
assertInclusionsAndExclusions(ds.getIncludedFiles(), excludedPaths, includedPaths);
}
@Test
void regexWithSlashInsideCharacterClass() throws Exception {
printTestHeader();
File dir = new File(testDir, "regex-dir");
try {
FileUtils.deleteDirectory(dir);
} catch (IOException ignored) {
}
dir.mkdirs();
String[] excludedPaths = {"target/foo.txt", "target/src/main/target/foo.txt"};
createFiles(dir, excludedPaths);
String[] includedPaths = {"module/src/main/target/foo.txt"};
createFiles(dir, includedPaths);
// NOTE: The portion "[^/]" is the interesting part of this pattern.
String regex = "(?!((?!target/)[^/]+/)*src/).*target.*";
DirectoryScanner ds = new DirectoryScanner();
String excludeExpr = SelectorUtils.REGEX_HANDLER_PREFIX + regex + SelectorUtils.PATTERN_HANDLER_SUFFIX;
String[] excludes = {excludeExpr};
ds.setExcludes(excludes);
ds.setBasedir(dir);
ds.scan();
assertInclusionsAndExclusions(ds.getIncludedFiles(), excludedPaths, includedPaths);
}
/**
* Test that the directory scanning does not enter into not matching directories.
*
* @see <a href="https://github.com/codehaus-plexus/plexus-utils/issues/63">Issue #63</a>
* @throws java.io.IOException if occurs an I/O error.
*/
@Test
void doNotScanUnnecesaryDirectories() throws Exception {
createTestDirectories();
// create additional directories 'anotherDir1', 'anotherDir2' and 'anotherDir3' with a 'file1.dat' file
FileUtils.mkdir(testDir + File.separator + "directoryTest" + File.separator + "testDir123" + File.separator
+ "anotherDir1");
FileUtils.mkdir(testDir + File.separator + "directoryTest" + File.separator + "test_dir_123" + File.separator
+ "anotherDir2");
FileUtils.mkdir(testDir + File.separator + "directoryTest" + File.separator + "test-dir-123" + File.separator
+ "anotherDir3");
this.createFile(
new File(testDir + File.separator + "directoryTest" + File.separator + "testDir123" + File.separator
+ "anotherDir1" + File.separator + "file1.dat"),
0);
this.createFile(
new File(testDir + File.separator + "directoryTest" + File.separator + "test_dir_123" + File.separator
+ "anotherDir2" + File.separator + "file1.dat"),
0);
this.createFile(
new File(testDir + File.separator + "directoryTest" + File.separator + "test-dir-123" + File.separator
+ "anotherDir3" + File.separator + "file1.dat"),
0);
String[] excludedPaths = {
"directoryTest" + File.separator + "testDir123" + File.separator + "anotherDir1" + File.separator
+ "file1.dat",
"directoryTest" + File.separator + "test_dir_123" + File.separator + "anotherDir2" + File.separator
+ "file1.dat",
"directoryTest" + File.separator + "test-dir-123" + File.separator + "anotherDir3" + File.separator
+ "file1.dat"
};
String[] includedPaths = {
"directoryTest" + File.separator + "testDir123" + File.separator + "file1.dat",
"directoryTest" + File.separator + "test_dir_123" + File.separator + "file1.dat",
"directoryTest" + File.separator + "test-dir-123" + File.separator + "file1.dat"
};
final Set<String> scannedDirSet = new HashSet<>();
DirectoryScanner ds = new DirectoryScanner() {
@Override
protected void scandir(File dir, String vpath, boolean fast) {
scannedDirSet.add(dir.getName());
super.scandir(dir, vpath, fast);
}
};
// one '*' matches only ONE directory level
String[] includes = {"directoryTest" + File.separator + "*" + File.separator + "file1.dat"};
ds.setIncludes(includes);
ds.setBasedir(new File(testDir));
ds.scan();
assertInclusionsAndExclusions(ds.getIncludedFiles(), excludedPaths, includedPaths);
Set<String> expectedScannedDirSet =
new HashSet<>(Arrays.asList("io", "directoryTest", "testDir123", "test_dir_123", "test-dir-123"));
assertEquals(expectedScannedDirSet, scannedDirSet);
}
@Test
void isSymbolicLink() throws Exception {
assumeTrue(checkTestFilesSymlinks());
final File directory = new File("src/test/resources/symlinks/src");
DirectoryScanner ds = new DirectoryScanner();
assertTrue(ds.isSymbolicLink(directory, "symR"));
assertTrue(ds.isSymbolicLink(directory, "symDir"));
assertFalse(ds.isSymbolicLink(directory, "fileR.txt"));
assertFalse(ds.isSymbolicLink(directory, "aRegularDir"));
}
@Test
void isParentSymbolicLink() throws Exception {
assumeTrue(checkTestFilesSymlinks());
final File directory = new File("src/test/resources/symlinks/src");
DirectoryScanner ds = new DirectoryScanner();
assertFalse(ds.isParentSymbolicLink(directory, "symR"));
assertFalse(ds.isParentSymbolicLink(directory, "symDir"));
assertFalse(ds.isParentSymbolicLink(directory, "fileR.txt"));
assertFalse(ds.isParentSymbolicLink(directory, "aRegularDir"));
assertFalse(ds.isParentSymbolicLink(new File(directory, "aRegularDir"), "aRegulatFile.txt"));
assertTrue(ds.isParentSymbolicLink(new File(directory, "symDir"), "targetFile.txt"));
assertTrue(
ds.isParentSymbolicLink(new File(directory, "symLinkToDirOnTheOutside"), "FileInDirOnTheOutside.txt"));
}
@Test
void defaultExcludes() throws Exception {
DirectoryScanner ds = new DirectoryScanner();
// work in src directory as target has filtering already applied with outdated default excludes
// (https://maven.apache.org/plugins/maven-resources-plugin/resources-mojo.html#addDefaultExcludes)
ds.setBasedir(new File("src/test/resources/directory-scanner-default-excludes").getCanonicalFile());
ds.addDefaultExcludes();
ds.scan();
assertInclusionsAndExclusions(
ds.getIncludedFiles(), new String[] {}, ".gitignore", ".gitattributes", ".cvsignore");
}
private void printTestHeader() {
StackTraceElement ste = new Throwable().getStackTrace()[1];
System.out.println("Test: " + ste.getMethodName());
}
private void assertInclusionsAndExclusions(String[] files, String[] excludedPaths, String... includedPaths) {
Arrays.sort(files);
System.out.println("Included files: ");
for (String file : files) {
System.out.println(file);
}
List<String> failedToExclude = new ArrayList<>();
for (String excludedPath : excludedPaths) {
String alt = excludedPath.replace('/', '\\');
System.out.println("Searching for exclusion as: " + excludedPath + "\nor: " + alt);
if (Arrays.binarySearch(files, excludedPath) > -1 || Arrays.binarySearch(files, alt) > -1) {
failedToExclude.add(excludedPath);
}
}
List<String> failedToInclude = new ArrayList<>();
for (String includedPath : includedPaths) {
String alt = includedPath.replace('/', '\\');
System.out.println("Searching for inclusion as: " + includedPath + "\nor: " + alt);
if (Arrays.binarySearch(files, includedPath) < 0 && Arrays.binarySearch(files, alt) < 0) {
failedToInclude.add(includedPath);
}
}
StringBuilder buffer = new StringBuilder();
if (!failedToExclude.isEmpty()) {
buffer.append("Should NOT have included:\n").append(StringUtils.join(failedToExclude.iterator(), "\n\t- "));
}
if (!failedToInclude.isEmpty()) {
if (buffer.length() > 0) {
buffer.append("\n\n");
}
buffer.append("Should have included:\n").append(StringUtils.join(failedToInclude.iterator(), "\n\t- "));
}
if (buffer.length() > 0) {
fail(buffer.toString());
}
}
private void createFiles(File dir, String... paths) throws IOException {
for (String path1 : paths) {
String path = path1.replace('/', File.separatorChar).replace('\\', File.separatorChar);
File file = new File(dir, path);
if (path.endsWith(File.separator)) {
file.mkdirs();
} else {
if (file.getParentFile() != null) {
file.getParentFile().mkdirs();
}
createFile(file, 0);
}
}
}
}