ImmutableBeanGenerator { public static void scanAndGenerate(File directory, File generatedSourceDirectory) { for (File file : directory.listFiles()) { if (file.isDirectory()) { scanAndGenerate(file, generatedSourceDirectory); } else if (file.getName().endsWith(".java")) { try { String code = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); if (code.contains(GenerateImmutable.class.getName())) { generate(code, generatedSourceDirectory); } } catch (IOException e) { throw new RuntimeException(e); } } } }  static void generate(String code, File generatedSource); static Generated generate(String code); static void scanAndGenerate(File directory, File generatedSourceDirectory);  }
@Test public void testScanAndGenerate() { ImmutableBeanGenerator.scanAndGenerate(new File("src/test/java"), new File("target/gen")); assertTrue(new File("target/gen/com/github/davidmoten/bean/immutable/Example.java").exists()); }