/** * Creates a new instance of GroovyWorkspaceCompiler. * * @param targetDirectory the directory in which to put generated files * @param workspaceRoot the directory to compile * @param changedFilesRoot the directory in which to temporarily store incrementally changed files * @return the newly created GroovyWorkspaceCompiler */ @SuppressFBWarnings("PT_FINAL_TYPE_RETURN") public static GroovyWorkspaceCompiler of(Path targetDirectory, Path workspaceRoot, Path changedFilesRoot) { checkNotNull(targetDirectory, "targetDirectory must not be null"); checkNotNull(workspaceRoot, "workspaceRoot must not be null"); checkNotNull(changedFilesRoot, "changedFilesRoot must not be null"); checkArgument(targetDirectory.toFile().isDirectory(), "targetDirectory must be a directory"); checkArgument(workspaceRoot.toFile().isDirectory(), "workspaceRoot must be a directory"); checkArgument(changedFilesRoot.toFile().isDirectory(), "changedFilesRoot must be a directory"); CompilerConfiguration config = new CompilerConfiguration(); config.setTargetDirectory(targetDirectory.toFile()); GroovyWorkspaceCompiler workspaceCompiler = new GroovyWorkspaceCompiler(workspaceRoot, changedFilesRoot, config); workspaceCompiler.addAllSourcesToCompilationUnit(); return workspaceCompiler; }
private void resetCompilationUnit() { try { FileUtils.deleteDirectory(config.getTargetDirectory()); } catch (IOException e) { logger.error("Could not delete directory '" + config.getTargetDirectory().toString() + "'", e); throw new RuntimeException("Could not reset compiled files after changes. " + "Make sure you have permission to modify your target directory."); } if (!config.getTargetDirectory().mkdir()) { logger.error("Could not recreate target directory: '{}'", config.getTargetDirectory().getAbsolutePath()); throw new RuntimeException("Could not reset compiled files after changes. " + "User may not have permission to modify target directory."); } unit = new CompilationUnit(config); addAllSourcesToCompilationUnit(); }