22
33import javax .annotation .processing .AbstractProcessor ;
44import javax .annotation .processing .FilerException ;
5+ import javax .annotation .processing .FilerException ;
56import javax .annotation .processing .ProcessingEnvironment ;
67import javax .annotation .processing .RoundEnvironment ;
78import javax .lang .model .SourceVersion ;
@@ -20,6 +21,8 @@ public class Processor extends AbstractProcessor implements Constants {
2021 private static final String KAPT_KOTLIN_GENERATED_OPTION = "kapt.kotlin.generated" ;
2122
2223 private ProcessingContext processingContext ;
24+ private SimpleModuleInfoWriter moduleWriter ;
25+ private boolean initModuleWriter ;
2326
2427 public Processor () {
2528 }
@@ -60,6 +63,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
6063 int count = processEntities (roundEnv );
6164 processOthers (roundEnv );
6265 final int loaded = processingContext .complete ();
66+ initModuleInfoBean ();
6367 if (roundEnv .processingOver ()) {
6468 writeModuleInfoBean ();
6569 }
@@ -96,11 +100,27 @@ private void processOthers(RoundEnvironment roundEnv, TypeElement otherType) {
96100 }
97101 }
98102
99- private void writeModuleInfoBean () {
103+ private void initModuleInfoBean () {
100104 try {
101- new SimpleModuleInfoWriter (processingContext ).write ();
105+ if (!initModuleWriter ) {
106+ moduleWriter = new SimpleModuleInfoWriter (processingContext );
107+ }
102108 } catch (FilerException e ) {
103- processingContext .logWarn (null , "FilerException trying to write EntityClassRegister: " + e );
109+ processingContext .logWarn (null , "FilerException trying to write EntityClassRegister error: " + e );
110+ } catch (Throwable e ) {
111+ processingContext .logError (null , "Failed to initialise EntityClassRegister error:" + e + " stack:" + Arrays .toString (e .getStackTrace ()));
112+ } finally {
113+ initModuleWriter = true ;
114+ }
115+ }
116+
117+ private void writeModuleInfoBean () {
118+ try {
119+ if (moduleWriter == null ) {
120+ processingContext .logNote (null , "EntityClassRegister skipped" );
121+ } else {
122+ moduleWriter .write ();
123+ }
104124 } catch (Throwable e ) {
105125 processingContext .logError (null , "Failed to write EntityClassRegister error:" + e + " stack:" + Arrays .toString (e .getStackTrace ()));
106126 }
0 commit comments