15
15
*/
16
16
package org .springframework .data .couchbase .repository .support ;
17
17
18
+ import static com .querydsl .apt .APTOptions .QUERYDSL_LOG_INFO ;
19
+
18
20
import java .util .Collections ;
21
+ import java .util .Set ;
19
22
20
23
import javax .annotation .processing .RoundEnvironment ;
21
24
import javax .annotation .processing .SupportedAnnotationTypes ;
22
25
import javax .annotation .processing .SupportedSourceVersion ;
23
26
import javax .lang .model .SourceVersion ;
27
+ import javax .lang .model .element .TypeElement ;
24
28
import javax .tools .Diagnostic ;
25
29
26
30
import org .springframework .data .couchbase .core .mapping .Document ;
27
- import org .springframework .lang .Nullable ;
28
31
29
32
import com .querydsl .apt .AbstractQuerydslProcessor ;
30
33
import com .querydsl .apt .Configuration ;
@@ -49,9 +52,9 @@ public class CouchbaseAnnotationProcessor extends AbstractQuerydslProcessor {
49
52
* @see com.querydsl.apt.AbstractQuerydslProcessor#createConfiguration(javax.annotation.processing.RoundEnvironment)
50
53
*/
51
54
@ Override
52
- protected Configuration createConfiguration (@ Nullable RoundEnvironment roundEnv ) {
55
+ protected Configuration createConfiguration (/* @Nullable */ RoundEnvironment roundEnv ) {
53
56
54
- processingEnv .getMessager ().printMessage (Diagnostic .Kind .NOTE , "Running " + getClass ().getSimpleName ());
57
+ processingEnv .getMessager ().printMessage (Diagnostic .Kind .NOTE , "Running override createConfiguration() " + getClass ().getSimpleName ());
55
58
56
59
DefaultConfiguration configuration = new DefaultConfiguration (processingEnv , roundEnv , Collections .emptySet (),
57
60
QueryEntities .class , Document .class , QuerySupertype .class , QueryEmbeddable .class , QueryEmbedded .class ,
@@ -60,4 +63,52 @@ protected Configuration createConfiguration(@Nullable RoundEnvironment roundEnv)
60
63
61
64
return configuration ;
62
65
}
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
+ }
63
113
}
114
+
0 commit comments