CompilationManager implements Closeable { public void rebuild() { try { Exception e = compileExecutor.submit(new Callable<Exception>() { @Override public Exception call() throws Exception { try { compileQueue.clear(); MoreFiles.delete(destination); destination.toFile().mkdirs(); final Collection<Path> sources = new ArrayList<>(); for (final Path sourceRoot : sourceRoots) { if (sourceRoot.toFile().exists()) { Files.walkFileTree(sourceRoot, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (isSource(file)) { sources.add(file); } else if (file.toFile().isFile()) { doCopyResource(SourcePath.valueOf(sourceRoot, sourceRoot.relativize(file))); } return FileVisitResult.CONTINUE; } }); } } compile(sources); return null; } catch (Exception e) { return e; } } }).get(compilationTimeout, TimeUnit.SECONDS); if (e != null) { throw new RuntimeException(e); } } catch (InterruptedException e) { throw new RuntimeException(e); } catch (ExecutionException e) { throw new RuntimeException(e); } catch (TimeoutException e) { throw new RuntimeException(e); } } CompilationManager(EventBus eventBus, Iterable<Path> sourceRoots, Path destination);  CompilationManager(EventBus eventBus, final Iterable<Path> sourceRoots, Path destination, CompilationSettings settings); EventBus getEventBus(); Path getDestination(); Iterable<Path> getSourceRoots(); Optional<Path> getClassFile(String className); void startAutoCompile(); void stopAutoCompile(); void awaitAutoCompile(); void incrementalCompile(); void rebuild(); void compileSources(final Path... sources); Collection<Diagnostic<?>> getLastDiagnostics(); HotReloadingClassLoader newHotReloadingClassLoader(String rootPackage, ImmutableSet<Class> coldClasses); boolean isCompiling(); @Override void close(); static final Predicate<Path> DEFAULT_CLASSPATH_RESOURCE_FILTER; static final CompilationSettings DEFAULT_SETTINGS; }
@Test public void should_copy_resources() throws Exception { CompilationManager compilationManager = new CompilationManager(eventBus, sourceRoots, destination); File resource = destination.resolve("restx/classloader/test_resource.txt").toFile(); assertThat(resource).doesNotExist(); prepareSource("restx/classloader/test_resource.txt"); compilationManager.rebuild(); assertThat(resource).exists(); assertThat(events).hasSize(1); assertThat(events.get(0)).isInstanceOf(ClasspathResourceEvent.class); }
@Test public void should_filter_resources() throws Exception { CompilationManager compilationManager = new CompilationManager(eventBus, sourceRoots, destination); File resource = destination.resolve("restx/classloader/test_resource.txt___jb_old___").toFile(); assertThat(resource).doesNotExist(); prepareSource("restx/classloader/test_resource.txt___jb_old___"); compilationManager.rebuild(); assertThat(resource).doesNotExist(); assertThat(events).isEmpty(); }