@Test(expected = CompiledJavaccFileOperationException.class) public void copyCustomAstClassToTargetDirectoryFails() throws Exception { PowerMockito.mockStatic(FileUtils.class, Answers.CALLS_REAL_METHODS.get()); doThrow(new IOException()).when(FileUtils.class); FileUtils.copyFile(any(File.class), any(File.class)); File file = new File(outputDirectory, "FileWithCorrespondingCustomAstClass.java"); CompiledJavaccFile compiledJavaccFile = new CompiledJavaccFile(file, outputDirectory, customAstClassesDirectory, targetDirectory, logger); compiledJavaccFile.copyCustomAstClassToTargetDirectory(customAstClassesDirectory); }
public void copyCustomAstClassToTargetDirectory(FileTree sourceTree) { logger.info("Not copying compiled file {} from {} to {} because it is overridden by the custom AST class {}", compiledJavaccFile, outputDirectory, targetDirectory, getCustomAstClassInputFile(sourceTree)); String packagePath = getPackageName(compiledJavaccFile).replaceAll("\\.", Matcher.quoteReplacement(File.separator)); File destination = new File(targetDirectory.getAbsolutePath() + File.separator + packagePath, compiledJavaccFile.getName()); logger.info("Copying custom AST class [{}] to [{}]", getCustomAstClassInputFile(sourceTree), destination); try { FileUtils.copyFile(getCustomAstClassInputFile(sourceTree), destination); } catch (IOException e) { String errorMessage = String.format("Could not copy %s to %s", getCustomAstClassInputFile(sourceTree), targetDirectory); throw new CompiledJavaccFileOperationException(errorMessage, e); } }
CompiledJavaccFile { public void copyCustomAstClassToTargetDirectory(FileTree sourceTree) { logger.info("Not copying compiled file {} from {} to {} because it is overridden by the custom AST class {}", compiledJavaccFile, outputDirectory, targetDirectory, getCustomAstClassInputFile(sourceTree)); String packagePath = getPackageName(compiledJavaccFile).replaceAll("\\.", Matcher.quoteReplacement(File.separator)); File destination = new File(targetDirectory.getAbsolutePath() + File.separator + packagePath, compiledJavaccFile.getName()); logger.info("Copying custom AST class [{}] to [{}]", getCustomAstClassInputFile(sourceTree), destination); try { FileUtils.copyFile(getCustomAstClassInputFile(sourceTree), destination); } catch (IOException e) { String errorMessage = String.format("Could not copy %s to %s", getCustomAstClassInputFile(sourceTree), targetDirectory); throw new CompiledJavaccFileOperationException(errorMessage, e); } } }
CompiledJavaccFile { public void copyCustomAstClassToTargetDirectory(FileTree sourceTree) { logger.info("Not copying compiled file {} from {} to {} because it is overridden by the custom AST class {}", compiledJavaccFile, outputDirectory, targetDirectory, getCustomAstClassInputFile(sourceTree)); String packagePath = getPackageName(compiledJavaccFile).replaceAll("\\.", Matcher.quoteReplacement(File.separator)); File destination = new File(targetDirectory.getAbsolutePath() + File.separator + packagePath, compiledJavaccFile.getName()); logger.info("Copying custom AST class [{}] to [{}]", getCustomAstClassInputFile(sourceTree), destination); try { FileUtils.copyFile(getCustomAstClassInputFile(sourceTree), destination); } catch (IOException e) { String errorMessage = String.format("Could not copy %s to %s", getCustomAstClassInputFile(sourceTree), targetDirectory); throw new CompiledJavaccFileOperationException(errorMessage, e); } } CompiledJavaccFile(File file, File outputDirectory, FileTree customAstClassesDirectory, File targetDirectory, Logger logger); }
CompiledJavaccFile { public void copyCustomAstClassToTargetDirectory(FileTree sourceTree) { logger.info("Not copying compiled file {} from {} to {} because it is overridden by the custom AST class {}", compiledJavaccFile, outputDirectory, targetDirectory, getCustomAstClassInputFile(sourceTree)); String packagePath = getPackageName(compiledJavaccFile).replaceAll("\\.", Matcher.quoteReplacement(File.separator)); File destination = new File(targetDirectory.getAbsolutePath() + File.separator + packagePath, compiledJavaccFile.getName()); logger.info("Copying custom AST class [{}] to [{}]", getCustomAstClassInputFile(sourceTree), destination); try { FileUtils.copyFile(getCustomAstClassInputFile(sourceTree), destination); } catch (IOException e) { String errorMessage = String.format("Could not copy %s to %s", getCustomAstClassInputFile(sourceTree), targetDirectory); throw new CompiledJavaccFileOperationException(errorMessage, e); } } CompiledJavaccFile(File file, File outputDirectory, FileTree customAstClassesDirectory, File targetDirectory, Logger logger); boolean customAstClassExists(); boolean customAstClassExists(FileTree fileTree); void copyCompiledFileToTargetDirectory(); void copyCustomAstClassToTargetDirectory(FileTree sourceTree); void ignoreCompiledFileAndUseCustomAstClassFromJavaSourceTree(FileTree javaSourceTree); @Override String toString(); }
CompiledJavaccFile { public void copyCustomAstClassToTargetDirectory(FileTree sourceTree) { logger.info("Not copying compiled file {} from {} to {} because it is overridden by the custom AST class {}", compiledJavaccFile, outputDirectory, targetDirectory, getCustomAstClassInputFile(sourceTree)); String packagePath = getPackageName(compiledJavaccFile).replaceAll("\\.", Matcher.quoteReplacement(File.separator)); File destination = new File(targetDirectory.getAbsolutePath() + File.separator + packagePath, compiledJavaccFile.getName()); logger.info("Copying custom AST class [{}] to [{}]", getCustomAstClassInputFile(sourceTree), destination); try { FileUtils.copyFile(getCustomAstClassInputFile(sourceTree), destination); } catch (IOException e) { String errorMessage = String.format("Could not copy %s to %s", getCustomAstClassInputFile(sourceTree), targetDirectory); throw new CompiledJavaccFileOperationException(errorMessage, e); } } CompiledJavaccFile(File file, File outputDirectory, FileTree customAstClassesDirectory, File targetDirectory, Logger logger); boolean customAstClassExists(); boolean customAstClassExists(FileTree fileTree); void copyCompiledFileToTargetDirectory(); void copyCustomAstClassToTargetDirectory(FileTree sourceTree); void ignoreCompiledFileAndUseCustomAstClassFromJavaSourceTree(FileTree javaSourceTree); @Override String toString();  }