1515 */
1616package org .springframework .data .couchbase .repository .support ;
1717
18+ import static com .querydsl .apt .APTOptions .QUERYDSL_LOG_INFO ;
19+
1820import java .util .Collections ;
21+ import java .util .Set ;
1922
2023import javax .annotation .processing .RoundEnvironment ;
2124import javax .annotation .processing .SupportedAnnotationTypes ;
2225import javax .annotation .processing .SupportedSourceVersion ;
2326import javax .lang .model .SourceVersion ;
27+ import javax .lang .model .element .TypeElement ;
2428import javax .tools .Diagnostic ;
2529
2630import org .springframework .data .couchbase .core .mapping .Document ;
27- import org .springframework .lang .Nullable ;
2831
2932import com .querydsl .apt .AbstractQuerydslProcessor ;
3033import com .querydsl .apt .Configuration ;
@@ -49,9 +52,9 @@ public class CouchbaseAnnotationProcessor extends AbstractQuerydslProcessor {
4952 * @see com.querydsl.apt.AbstractQuerydslProcessor#createConfiguration(javax.annotation.processing.RoundEnvironment)
5053 */
5154 @ Override
52- protected Configuration createConfiguration (@ Nullable RoundEnvironment roundEnv ) {
55+ protected Configuration createConfiguration (/* @Nullable */ RoundEnvironment roundEnv ) {
5356
54- processingEnv .getMessager ().printMessage (Diagnostic .Kind .NOTE , "Running " + getClass ().getSimpleName ());
57+ processingEnv .getMessager ().printMessage (Diagnostic .Kind .NOTE , "Running override createConfiguration() " + getClass ().getSimpleName ());
5558
5659 DefaultConfiguration configuration = new DefaultConfiguration (processingEnv , roundEnv , Collections .emptySet (),
5760 QueryEntities .class , Document .class , QuerySupertype .class , QueryEmbeddable .class , QueryEmbedded .class ,
@@ -60,4 +63,52 @@ protected Configuration createConfiguration(@Nullable RoundEnvironment roundEnv)
6063
6164 return configuration ;
6265 }
66+
67+ @ Override
68+ public boolean process (Set <? extends TypeElement > annotations , RoundEnvironment roundEnv ) {
69+ setLogInfo ();
70+ logInfo ("Running override process() " + getClass ().getSimpleName () +" isOver: " +roundEnv .processingOver () +" annotations: " +annotations .size ());
71+
72+ if (roundEnv .processingOver () || annotations .size () == 0 ) {
73+ return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS ;
74+ }
75+
76+ if (roundEnv .getRootElements () == null || roundEnv .getRootElements ().isEmpty ()) {
77+ logInfo ("No sources to process" );
78+ return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS ;
79+ }
80+
81+ Configuration conf = createConfiguration (roundEnv );
82+ try {
83+ conf .getTypeMappings ();
84+ } catch (NoClassDefFoundError cnfe ){
85+ logWarn ( cnfe +" add a dependency on javax.inject:javax.inject to create querydsl classes" );
86+ return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS ;
87+ }
88+ return super .process (annotations , roundEnv );
89+
90+ }
91+
92+ private boolean shouldLogInfo ;
93+
94+ private void setLogInfo () {
95+ boolean hasProperty = processingEnv .getOptions ().containsKey (QUERYDSL_LOG_INFO );
96+ if (hasProperty ) {
97+ String val = processingEnv .getOptions ().get (QUERYDSL_LOG_INFO );
98+ shouldLogInfo = Boolean .parseBoolean (val );
99+ }
100+ }
101+
102+ private void logInfo (String message ) {
103+ if (shouldLogInfo ) {
104+ System .out .println ("[NOTE] " +message ); // maven compiler swallows messages to messager
105+ processingEnv .getMessager ().printMessage (Diagnostic .Kind .NOTE , message );
106+ }
107+ }
108+
109+ private void logWarn (String message ) {
110+ System .err .println ("[WARNING] " +message ); // maven compiler swallows messages to messager
111+ processingEnv .getMessager ().printMessage (Diagnostic .Kind .WARNING , message );
112+ }
63113}
114+
0 commit comments