Skip to content

Commit db81e7a

Browse files
committed
Exclude javax.inject and CouchbaseAnnotationProcessor to exit gracefully without. (#1934)
CouchbaseAnnotationProcessor will provide a warning and skip generation if javax.inject is not present.
1 parent 7251e1c commit db81e7a

File tree

5 files changed

+98
-32
lines changed

5 files changed

+98
-32
lines changed

pom.xml

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
<springdata.commons>3.1.11-SNAPSHOT</springdata.commons>
2424
<java-module-name>spring.data.couchbase</java-module-name>
2525
<hibernate.validator>7.0.1.Final</hibernate.validator>
26-
<apt>1.1.3</apt>
27-
<querydsl>5.0.0</querydsl>
2826
<couchbase.encryption>3.1.0</couchbase.encryption>
2927
<jodatime>2.10.13</jodatime>
3028
<jackson-joda>2.13.4</jackson-joda>
@@ -50,6 +48,19 @@
5048
<artifactId>querydsl-apt</artifactId>
5149
<version>${querydsl}</version>
5250
<classifier>jakarta</classifier>
51+
<exclusions>
52+
<exclusion>
53+
<groupId>javax.inject</groupId>
54+
<artifactId>javax.inject</artifactId>
55+
</exclusion>
56+
</exclusions>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>javax.inject</groupId>
61+
<artifactId>javax.inject</artifactId>
62+
<version>1</version>
63+
<scope>test</scope>
5364
</dependency>
5465

5566
<dependency>
@@ -248,6 +259,33 @@
248259

249260
<build>
250261
<plugins>
262+
<plugin>
263+
<groupId>org.apache.maven.plugins</groupId>
264+
<artifactId>maven-compiler-plugin</artifactId>
265+
<configuration>
266+
<proc>none</proc>
267+
</configuration>
268+
<executions>
269+
<execution>
270+
<id>test-annotation-processing</id>
271+
<phase>generate-test-sources</phase>
272+
<goals>
273+
<goal>testCompile</goal>
274+
</goals>
275+
<configuration>
276+
<proc>only</proc>
277+
<annotationProcessors>
278+
<annotationProcessor>org.springframework.data.couchbase.repository.support.CouchbaseAnnotationProcessor</annotationProcessor>
279+
</annotationProcessors>
280+
<generatedTestSourcesDirectory>target/generated-test-sources</generatedTestSourcesDirectory>
281+
<compilerArgs>
282+
<arg>-Aquerydsl.logInfo=true</arg>
283+
</compilerArgs>
284+
</configuration>
285+
</execution>
286+
</executions>
287+
</plugin>
288+
251289
<plugin>
252290
<groupId>org.apache.maven.plugins</groupId>
253291
<artifactId>maven-surefire-plugin</artifactId>
@@ -291,30 +329,7 @@
291329
<groupId>org.asciidoctor</groupId>
292330
<artifactId>asciidoctor-maven-plugin</artifactId>
293331
</plugin>
294-
<plugin>
295-
<groupId>com.mysema.maven</groupId>
296-
<artifactId>apt-maven-plugin</artifactId>
297-
<version>${apt}</version>
298-
<dependencies>
299-
<dependency>
300-
<groupId>com.querydsl</groupId>
301-
<artifactId>querydsl-apt</artifactId>
302-
<version>${querydsl}</version>
303-
</dependency>
304-
</dependencies>
305-
<executions>
306-
<execution>
307-
<phase>generate-test-sources</phase>
308-
<goals>
309-
<goal>test-process</goal>
310-
</goals>
311-
<configuration>
312-
<outputDirectory>target/generated-test-sources</outputDirectory>
313-
<processor>org.springframework.data.couchbase.repository.support.CouchbaseAnnotationProcessor</processor>
314-
</configuration>
315-
</execution>
316-
</executions>
317-
</plugin>
332+
318333
</plugins>
319334
</build>
320335

src/main/java/org/springframework/data/couchbase/repository/support/CouchbaseAnnotationProcessor.java

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@
1515
*/
1616
package org.springframework.data.couchbase.repository.support;
1717

18+
import static com.querydsl.apt.APTOptions.QUERYDSL_LOG_INFO;
19+
1820
import java.util.Collections;
21+
import java.util.Set;
1922

2023
import javax.annotation.processing.RoundEnvironment;
2124
import javax.annotation.processing.SupportedAnnotationTypes;
2225
import javax.annotation.processing.SupportedSourceVersion;
2326
import javax.lang.model.SourceVersion;
27+
import javax.lang.model.element.TypeElement;
2428
import javax.tools.Diagnostic;
2529

2630
import org.springframework.data.couchbase.core.mapping.Document;
27-
import org.springframework.lang.Nullable;
2831

2932
import com.querydsl.apt.AbstractQuerydslProcessor;
3033
import 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+

src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateKeyValueIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ void sampleScan() {
13291329
MutationToken mt = couchbaseTemplate.getCouchbaseClientFactory().getDefaultCollection()
13301330
.upsert(id, JsonObject.create().put("id", id)).mutationToken().get();
13311331
Stream<User> users = couchbaseTemplate.rangeScan(User.class).consistentWith(MutationState.from(mt))
1332-
/*.withSort(ScanSort.ASCENDING)*/.samplingScan(5l, null);
1332+
/*.withSort(ScanSort.ASCENDING)*/.samplingScan(5l, (Long)null);
13331333
List<User> usersList = users.toList();
13341334
assertEquals(5, usersList.size(), "number in sample");
13351335
for (User u : usersList) {

src/test/java/org/springframework/data/couchbase/core/query/QueryCriteriaTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void testNestedOrCriteria() {
9090
@Test
9191
void testNestedNotIn() {
9292
QueryCriteria c = where(i("name")).is("Bubba").or(where(i("age")).gt(12).and(i("country")).is("Austria"))
93-
.and(where(i("state")).notIn(new String[] { "Alabama", "Florida" }));
93+
.and(where(i("state")).notIn( "Alabama", "Florida" ));
9494
JsonArray parameters = JsonArray.create();
9595
assertEquals(" ( (`name` = $1) or (`age` > $2 and `country` = $3)) and (not( (`state` in $4) ))",
9696
c.export(new int[1], parameters, null));

src/test/java/org/springframework/data/couchbase/domain/BigAirlineRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
@Repository
3232
public interface BigAirlineRepository extends CouchbaseRepository<BigAirline, String>,
33-
QuerydslPredicateExecutor<BigAirline>, DynamicProxyable<BigAirlineRepository> {
33+
DynamicProxyable<BigAirlineRepository> {
3434

3535
@Query("#{#n1ql.selectEntity} where #{#n1ql.filter} and (name = $1)")
3636
List<Airline> getByName(@Param("airline_name") String airlineName);

0 commit comments

Comments
 (0)