From df55e05a570d75158b69ba2e3937018baf7ae93f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=91=E6=88=9F?= Date: Fri, 15 May 2020 00:37:22 +0800 Subject: [PATCH] fit jdk 13 filter behavior --- .../testable/processor/TestableProcessor.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/alibaba/testable/processor/TestableProcessor.java b/src/main/java/com/alibaba/testable/processor/TestableProcessor.java index f387377..0badb84 100644 --- a/src/main/java/com/alibaba/testable/processor/TestableProcessor.java +++ b/src/main/java/com/alibaba/testable/processor/TestableProcessor.java @@ -7,6 +7,7 @@ import com.alibaba.testable.translator.TestableFieldTranslator; import com.alibaba.testable.util.ConstPool; import com.sun.tools.javac.tree.JCTree; +import javax.annotation.processing.FilerException; import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; import javax.annotation.processing.SupportedSourceVersion; @@ -47,13 +48,23 @@ public class TestableProcessor extends BaseProcessor { } private void createStaticNewClass() { + if (!isStaticNewClassExist()) { + try { + writeSourceFile(ConstPool.SN_PKG + "." + ConstPool.SN_CLS, new StaticNewClassGenerator().fetch()); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + private boolean isStaticNewClassExist() { try { FileObject staticNewClassFile = filter.getResource(SOURCE_OUTPUT, ConstPool.SN_PKG, ConstPool.SN_CLS + JAVA_POSTFIX); - if (!staticNewClassFile.getName().contains(GENERATED_TEST_SOURCES) && staticNewClassFile.getLastModified() == 0) { - writeSourceFile(ConstPool.SN_PKG + "." + ConstPool.SN_CLS, new StaticNewClassGenerator().fetch()); - } + return staticNewClassFile.getName().contains(GENERATED_TEST_SOURCES) || staticNewClassFile.getLastModified() > 0; + } catch (FilerException e) { + return true; } catch (IOException e) { - e.printStackTrace(); + return false; } }