WorkspaceScanner { public void partialScan(PropertyFileAcceptor acceptor, File baseDir, PropertyScanner scanner, ScanConfiguration config, File singleFile) { Project antProject = new org.apache.tools.ant.Project(); FileSet fs = createFileSet(config); String[] excludes = fs.mergeExcludes(antProject); if(excludes!=null) { for (String exclude : excludes) { if(SelectorUtils.match(normalizePattern(exclude), singleFile.getPath())) return; } } String[] includes = fs.mergeIncludes(antProject); if(includes==null) return; for (String include : includes) { if(SelectorUtils.match(normalizePattern(include), singleFile.getPath())) { if (baseDir.exists()) { acceptor.newMatch(singleFile); } break; } } } WorkspaceScanner(); void fullScan(PropertyFileAcceptor acceptor, File baseDir, PropertyScanner scanner, ScanConfiguration config, IProgressMonitor monitor); void partialScan(PropertyFileAcceptor acceptor, File baseDir, PropertyScanner scanner, ScanConfiguration config, File singleFile); boolean partialScan(File baseDir, PropertyScanner scanner, ScanConfiguration config, File singleFile);  }
@Test public void testPartialScan() throws Exception { File baseDir = new File("src/test/resources/project/master"); WorkspaceScanner scanner = new WorkspaceScanner(); final List<String> filenames = new ArrayList<String>(); scanner.partialScan(new PropertyFileAcceptor() { @Override public void newMatch(File file) { filenames.add(file.getName()); } }, baseDir, new JavaPropertyScanner(), PropertiesFactory.eINSTANCE.createScanConfiguration(), new File("src/test/resources/project/master/org/jabylon/properties/util/autotranslate/messages.properties")); int index = 0; assertEquals(1, filenames.size()); assertEquals("messages.properties", filenames.get(index++)); }
@Test public void testPartialScanWithComplicatedInclude() { File baseDir = new File("src/test/resources/project/master"); ScanConfiguration scanConfig = PropertiesFactory.eINSTANCE.createScanConfiguration(); scanConfig.setInclude("**/jabylon/properties/util/autotranslate/*.properties"); WorkspaceScanner scanner = new WorkspaceScanner(); final List<String> filenames = new ArrayList<String>(); scanner.partialScan(new PropertyFileAcceptor() { @Override public void newMatch(File file) { filenames.add(file.getName()); } }, baseDir, new JavaPropertyScanner(), scanConfig, new File("src/test/resources/project/master/org/jabylon/properties/util/autotranslate/messages.properties")); int index = 0; assertEquals(1, filenames.size()); assertEquals("messages.properties", filenames.get(index++)); }
@Test public void testPartialScanWithExclude() { File baseDir = new File("src/test/resources/project/master"); ScanConfiguration scanConfig = PropertiesFactory.eINSTANCE.createScanConfiguration(); scanConfig.setExclude("**/jabylon/properties/util/autotranslate/*.properties"); WorkspaceScanner scanner = new WorkspaceScanner(); final List<String> filenames = new ArrayList<String>(); scanner.partialScan(new PropertyFileAcceptor() { @Override public void newMatch(File file) { filenames.add(file.getName()); } }, baseDir, new JavaPropertyScanner(), scanConfig, new File("src/test/resources/project/master/org/jabylon/properties/util/autotranslate/messages.properties")); assertEquals(0, filenames.size()); }