The following document contains the results of PMD's CPD 4.3.
File | Line |
---|---|
cn/shenyanchao/ut/AstGenerator.java | 48 |
cn/shenyanchao/ut/DebugMain.java | 53 |
public void execute() throws MojoExecutionException, MojoFailureException { getLog().info(sourceDir); getLog().info(testDir); File sourceDirectory = new File(sourceDir); makeDirIfNotExist(sourceDirectory); File testDirectory = new File(testDir); makeDirIfNotExist(testDirectory); Iterator<File> fileItr = FileUtils.iterateFiles(sourceDirectory, new JavaFileFilter(), TrueFileFilter.INSTANCE); while (fileItr.hasNext()) { File javaFile = fileItr.next(); getLog().info("start process file:" + javaFile.getAbsolutePath()); //process java file if (ClassTools.isNeedTest(javaFile, sourceEncode)) { convertJavaFile2Test(javaFile); } } } /** * if dir not exist,create it * * @param dir */ private void makeDirIfNotExist(File dir) { if (!dir.isDirectory()) { getLog().error(dir.getAbsolutePath() + "is not a directory!"); } if (!dir.exists()) { boolean success = false; while (!success) { success = dir.mkdirs(); } } } /** * @param javaFile */ private void convertJavaFile2Test(File javaFile) { CompilationUnit sourceCU = JavaParserFactory.getCompilationUnit(javaFile, sourceEncode); CompilationUnit testCU = null; String testJavaFileName = JavaParserUtils.findTestJavaFileName(sourceCU, javaFile, testDir); boolean testExist = FileChecker.isTestJavaClassExist(new File(testJavaFileName)); if (!testExist) { CommandInvoker invoker = new CommandInvoker(new NewTestCommand(new NewTestReceiver(sourceCU, javaFile))); testCU = invoker.action(); } else if (testExist) { CompilationUnit existTestCU = JavaParserFactory.getCompilationUnit(new File(testJavaFileName), sourceEncode); CommandInvoker invoker = new CommandInvoker(new ExistTestCommand(new ExistTestReceiver(sourceCU, javaFile, existTestCU, new File(testJavaFileName)))); testCU = invoker.action(); } if (null != testCU) { //写入测试代码文件 TestWriter.writeJavaTest(testJavaFileName, testCU.toString(), sourceEncode); } } |