Lines 46-59
Link Here
|
46 |
import java.io.File; |
46 |
import java.io.File; |
47 |
import java.io.IOException; |
47 |
import java.io.IOException; |
48 |
import java.net.URL; |
48 |
import java.net.URL; |
|
|
49 |
import java.util.ArrayList; |
49 |
import java.util.Arrays; |
50 |
import java.util.Arrays; |
50 |
import java.util.Collection; |
51 |
import java.util.Collection; |
|
|
52 |
import java.util.Collections; |
51 |
import java.util.EnumSet; |
53 |
import java.util.EnumSet; |
52 |
import java.util.HashMap; |
54 |
import java.util.HashMap; |
53 |
import java.util.HashSet; |
55 |
import java.util.List; |
54 |
import java.util.Map; |
56 |
import java.util.Map; |
55 |
import java.util.Set; |
|
|
56 |
import java.util.regex.Pattern; |
57 |
import java.util.regex.Pattern; |
|
|
58 |
import static junit.framework.Assert.assertNull; |
57 |
import org.netbeans.api.java.classpath.ClassPath; |
59 |
import org.netbeans.api.java.classpath.ClassPath; |
58 |
import org.netbeans.junit.NbTestCase; |
60 |
import org.netbeans.junit.NbTestCase; |
59 |
import org.netbeans.modules.parsing.spi.indexing.Indexable; |
61 |
import org.netbeans.modules.parsing.spi.indexing.Indexable; |
Lines 303-319
Link Here
|
303 |
"folder2/data3.txt"); |
305 |
"folder2/data3.txt"); |
304 |
} |
306 |
} |
305 |
|
307 |
|
|
|
308 |
public void testDuplicateResults1() throws IOException { |
309 |
File root = new File(getWorkDir(), "src"); |
310 |
String [] paths = new String [] { |
311 |
"org/pckg1/file1.txt", |
312 |
"org/pckg1/pckg2/file1.txt", |
313 |
"org/pckg1/pckg2/file2.txt", |
314 |
}; |
315 |
|
316 |
populateFolderStructure(root, paths); |
317 |
|
318 |
FileObject rootFO = FileUtil.toFileObject(root); |
319 |
FileObjectCrawler crawler = new FileObjectCrawler(rootFO, new FileObject[] {rootFO.getFileObject("org/pckg1/pckg2/file1.txt"), rootFO.getFileObject("org/pckg1/pckg2")}, EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, CR, SuspendSupport.NOP); |
320 |
assertCollectedFiles("Wrong files collected", crawler.getResources(), new String[] {"org/pckg1/pckg2/file1.txt", "org/pckg1/pckg2/file2.txt"}); |
321 |
} |
322 |
|
323 |
public void testDuplicateResults2() throws IOException { |
324 |
File root = new File(getWorkDir(), "src"); |
325 |
String [] paths = new String [] { |
326 |
"org/pckg1/file1.txt", |
327 |
"org/pckg1/pckg2/file1.txt", |
328 |
"org/pckg1/pckg2/file2.txt", |
329 |
}; |
330 |
|
331 |
populateFolderStructure(root, paths); |
332 |
|
333 |
FileObject rootFO = FileUtil.toFileObject(root); |
334 |
FileObjectCrawler crawler = new FileObjectCrawler(rootFO, new FileObject[] {rootFO.getFileObject("org/pckg1/pckg2/file1.txt"), rootFO.getFileObject("org/pckg1/pckg2/file2.txt")}, EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, CR, SuspendSupport.NOP); |
335 |
assertCollectedFiles("Wrong files collected", crawler.getResources(), new String[] {"org/pckg1/pckg2/file1.txt", "org/pckg1/pckg2/file2.txt"}); |
336 |
} |
337 |
|
306 |
protected void assertCollectedFiles(String message, Collection<Indexable> resources, String... expectedPaths) throws IOException { |
338 |
protected void assertCollectedFiles(String message, Collection<Indexable> resources, String... expectedPaths) throws IOException { |
307 |
Set<String> collectedPaths = new HashSet<String>(); |
339 |
List<String> collectedPaths = new ArrayList<String>(); |
308 |
for(Indexable ii : resources) { |
340 |
for(Indexable ii : resources) { |
309 |
collectedPaths.add(ii.getRelativePath()); |
341 |
collectedPaths.add(ii.getRelativePath()); |
310 |
} |
342 |
} |
311 |
Set<String> expectedPathsFiltered = new HashSet<String>(); |
343 |
List<String> expectedPathsFiltered = new ArrayList<String>(); |
312 |
for(String path : expectedPaths) { |
344 |
for(String path : expectedPaths) { |
313 |
if (!path.endsWith("/")) { // crawler only collects files |
345 |
if (!path.endsWith("/")) { // crawler only collects files |
314 |
expectedPathsFiltered.add(path); |
346 |
expectedPathsFiltered.add(path); |
315 |
} |
347 |
} |
316 |
} |
348 |
} |
|
|
349 |
Collections.sort(collectedPaths); |
350 |
Collections.sort(expectedPathsFiltered); |
317 |
assertEquals(message, expectedPathsFiltered, collectedPaths); |
351 |
assertEquals(message, expectedPathsFiltered, collectedPaths); |
318 |
} |
352 |
} |
319 |
|
353 |
|