Search in sources :

Example 6 with TextReport

use of net.sourceforge.pmd.benchmark.TextReport in project Gargoyle by callakrsos.

the class PMDCheckedListComposite method simpleFilePmd.

/**
	 * 파일 1개를 대상으로 PMD 체크하기 위한 처리.
	 *
	 * @작성자 : KYJ
	 * @작성일 : 2016. 10. 13.
	 * @param file
	 */
protected void simpleFilePmd(File file) {
    try {
        String sourceCode = Files.toString(this.sourceFile, Charset.forName("UTF-8"));
        GargoylePMDParameters params = new GargoylePMDParameters();
        params.setSourceFileName(file.getAbsolutePath());
        params.setSourceText(sourceCode);
        if (!FileUtil.isJavaFile(file)) {
            String fileExtension = FileUtil.getFileExtension(file);
            try {
                Field declaredField = GargoylePMDParameters.class.getDeclaredField("language");
                if (declaredField != null) {
                    declaredField.setAccessible(true);
                    declaredField.set(params, fileExtension);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        // transformParametersIntoConfiguration(params);
        long start = System.nanoTime();
        doPMD.doPMD(transformParametersIntoConfiguration(params), reportListenerProperty.get(), violationCountingListener.get());
        long end = System.nanoTime();
        Benchmarker.mark(Benchmark.TotalPMD, end - start, 0);
        TextReport report = new TextReport();
        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
            report.generate(Benchmarker.values(), new PrintStream(out));
            out.flush();
            LOGGER.debug(out.toString("UTF-8"));
        }
        updateStatus(sourceCode);
    } catch (IOException e) {
        LOGGER.error(ValueUtil.toString(e));
    }
}
Also used : Field(java.lang.reflect.Field) PrintStream(java.io.PrintStream) GargoylePMDParameters(com.kyj.fx.voeditor.visual.framework.pmd.GargoylePMDParameters) TextReport(net.sourceforge.pmd.benchmark.TextReport) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)6 PrintStream (java.io.PrintStream)6 TextReport (net.sourceforge.pmd.benchmark.TextReport)6 GargoylePMDParameters (com.kyj.fx.voeditor.visual.framework.pmd.GargoylePMDParameters)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Field (java.lang.reflect.Field)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 PMDCheckedListComposite (com.kyj.fx.voeditor.visual.component.pmd.PMDCheckedListComposite)1 CloseableParent (com.kyj.fx.voeditor.visual.main.layout.CloseableParent)1 SharedMemory (com.kyj.fx.voeditor.visual.momory.SharedMemory)1 FxUtil (com.kyj.fx.voeditor.visual.util.FxUtil)1 ValueUtil (com.kyj.fx.voeditor.visual.util.ValueUtil)1 FileNotFoundException (java.io.FileNotFoundException)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 ActionEvent (javafx.event.ActionEvent)1 EventHandler (javafx.event.EventHandler)1 Menu (javafx.scene.control.Menu)1 MenuItem (javafx.scene.control.MenuItem)1