WorkspaceScanner { public void fullScan(PropertyFileAcceptor acceptor, File baseDir, PropertyScanner scanner, ScanConfiguration config, IProgressMonitor monitor) { FileSet fs = createFileSet(config); fs.setDir(baseDir); SubMonitor subMon = SubMonitor.convert(monitor, "Scanning", 100); String masterLocale = config.getMasterLocale(); if (masterLocale != null && masterLocale.isEmpty()) masterLocale = null; if (baseDir.exists()) { DirectoryScanner ds = fs.getDirectoryScanner(new org.apache.tools.ant.Project()); subMon.worked(10); String[] files = ds.getIncludedFiles(); subMon.setWorkRemaining(files.length); for (String f : files) { checkCanceled(monitor); File file = new File(baseDir, f); if(scanner.isTemplate(file, config.getMasterLocale())) { subMon.subTask(f); acceptor.newMatch(file); subMon.worked(1); } } } if(monitor!=null) monitor.done(); } 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 testFullScan() { File baseDir = new File("src/test/resources/project/master"); WorkspaceScanner scanner = new WorkspaceScanner(); final List<String> filenames = new ArrayList<String>(); scanner.fullScan(new PropertyFileAcceptor() { @Override public void newMatch(File file) { filenames.add(file.getName()); } }, baseDir, new JavaPropertyScanner(), PropertiesFactory.eINSTANCE.createScanConfiguration(), new NullProgressMonitor()); int index = 0; assertEquals("messages.properties", filenames.get(index++)); assertEquals("messages2.properties", filenames.get(index++)); assertEquals("plugin.properties", filenames.get(index++)); assertEquals("messages.properties", filenames.get(index++)); assertEquals("wiki_example.properties", filenames.get(index++)); assertEquals(5, filenames.size()); }
@Test public void testFullScanWithFileExcude() { File baseDir = new File("src/test/resources/project/master"); ScanConfiguration configuration = PropertiesFactory.eINSTANCE.createScanConfiguration(); configuration.setExclude("**/wiki_examp*.properties"); WorkspaceScanner scanner = new WorkspaceScanner(); final List<String> filenames = new ArrayList<String>(); scanner.fullScan(new PropertyFileAcceptor() { @Override public void newMatch(File file) { filenames.add(file.getName()); } }, baseDir, new JavaPropertyScanner(), configuration, new NullProgressMonitor()); int index = 0; assertEquals("messages.properties", filenames.get(index++)); assertEquals("messages2.properties", filenames.get(index++)); assertEquals("plugin.properties", filenames.get(index++)); assertEquals("messages.properties", filenames.get(index++)); assertEquals(4, filenames.size()); }
@Test public void testFullScanWithMasterLocale() { File baseDir = new File("src/test/resources/project/master"); ScanConfiguration configuration = PropertiesFactory.eINSTANCE.createScanConfiguration(); configuration.setMasterLocale("en_CA"); WorkspaceScanner scanner = new WorkspaceScanner(); final List<String> filenames = new ArrayList<String>(); scanner.fullScan(new PropertyFileAcceptor() { @Override public void newMatch(File file) { filenames.add(file.getName()); } }, baseDir, new JavaPropertyScanner(), configuration, new NullProgressMonitor()); assertEquals(1, filenames.size()); int index = 0; assertEquals("messages_en_CA.properties", filenames.get(index++)); }