Exclude javax.inject and CouchbaseAnnotationProcessor to exit gracefully without. (#1934)
CouchbaseAnnotationProcessor will provide a warning and skip generation if javax.inject is not present.
This commit is contained in:
committed by
mikereiche
parent
bccab34cc3
commit
e65e53e294
23
pom.xml
23
pom.xml
@@ -48,6 +48,19 @@
|
||||
<artifactId>querydsl-apt</artifactId>
|
||||
<version>${querydsl}</version>
|
||||
<classifier>jakarta</classifier>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject</artifactId>
|
||||
<version>1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -249,13 +262,6 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.querydsl</groupId>
|
||||
<artifactId>querydsl-apt</artifactId>
|
||||
<version>${querydsl}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<configuration>
|
||||
<proc>none</proc>
|
||||
</configuration>
|
||||
@@ -272,6 +278,9 @@
|
||||
<annotationProcessor>org.springframework.data.couchbase.repository.support.CouchbaseAnnotationProcessor</annotationProcessor>
|
||||
</annotationProcessors>
|
||||
<generatedTestSourcesDirectory>target/generated-test-sources</generatedTestSourcesDirectory>
|
||||
<compilerArgs>
|
||||
<arg>-Aquerydsl.logInfo=true</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
|
||||
@@ -15,16 +15,19 @@
|
||||
*/
|
||||
package org.springframework.data.couchbase.repository.support;
|
||||
|
||||
import static com.querydsl.apt.APTOptions.QUERYDSL_LOG_INFO;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.processing.RoundEnvironment;
|
||||
import javax.annotation.processing.SupportedAnnotationTypes;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.tools.Diagnostic;
|
||||
|
||||
import org.springframework.data.couchbase.core.mapping.Document;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import com.querydsl.apt.AbstractQuerydslProcessor;
|
||||
import com.querydsl.apt.Configuration;
|
||||
@@ -49,9 +52,9 @@ public class CouchbaseAnnotationProcessor extends AbstractQuerydslProcessor {
|
||||
* @see com.querydsl.apt.AbstractQuerydslProcessor#createConfiguration(javax.annotation.processing.RoundEnvironment)
|
||||
*/
|
||||
@Override
|
||||
protected Configuration createConfiguration(@Nullable RoundEnvironment roundEnv) {
|
||||
protected Configuration createConfiguration(/*@Nullable */RoundEnvironment roundEnv) {
|
||||
|
||||
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Running " + getClass().getSimpleName());
|
||||
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Running override createConfiguration() " + getClass().getSimpleName());
|
||||
|
||||
DefaultConfiguration configuration = new DefaultConfiguration(processingEnv, roundEnv, Collections.emptySet(),
|
||||
QueryEntities.class, Document.class, QuerySupertype.class, QueryEmbeddable.class, QueryEmbedded.class,
|
||||
@@ -60,4 +63,52 @@ public class CouchbaseAnnotationProcessor extends AbstractQuerydslProcessor {
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
setLogInfo();
|
||||
logInfo("Running override process() " + getClass().getSimpleName() +" isOver: "+roundEnv.processingOver() +" annotations: "+annotations.size());
|
||||
|
||||
if (roundEnv.processingOver() || annotations.size() == 0) {
|
||||
return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
|
||||
}
|
||||
|
||||
if (roundEnv.getRootElements() == null || roundEnv.getRootElements().isEmpty()) {
|
||||
logInfo("No sources to process");
|
||||
return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
|
||||
}
|
||||
|
||||
Configuration conf = createConfiguration(roundEnv);
|
||||
try {
|
||||
conf.getTypeMappings();
|
||||
} catch (NoClassDefFoundError cnfe ){
|
||||
logWarn( cnfe +" add a dependency on javax.inject:javax.inject to create querydsl classes");
|
||||
return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
|
||||
}
|
||||
return super.process(annotations, roundEnv);
|
||||
|
||||
}
|
||||
|
||||
private boolean shouldLogInfo;
|
||||
|
||||
private void setLogInfo() {
|
||||
boolean hasProperty = processingEnv.getOptions().containsKey(QUERYDSL_LOG_INFO);
|
||||
if (hasProperty) {
|
||||
String val = processingEnv.getOptions().get(QUERYDSL_LOG_INFO);
|
||||
shouldLogInfo = Boolean.parseBoolean(val);
|
||||
}
|
||||
}
|
||||
|
||||
private void logInfo(String message) {
|
||||
if (shouldLogInfo) {
|
||||
System.out.println("[NOTE] "+message); // maven compiler swallows messages to messager
|
||||
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, message);
|
||||
}
|
||||
}
|
||||
|
||||
private void logWarn(String message) {
|
||||
System.err.println("[WARNING] "+message); // maven compiler swallows messages to messager
|
||||
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1329,7 +1329,7 @@ class CouchbaseTemplateKeyValueIntegrationTests extends JavaIntegrationTests {
|
||||
MutationToken mt = couchbaseTemplate.getCouchbaseClientFactory().getDefaultCollection()
|
||||
.upsert(id, JsonObject.create().put("id", id)).mutationToken().get();
|
||||
Stream<User> users = couchbaseTemplate.rangeScan(User.class).consistentWith(MutationState.from(mt))
|
||||
/*.withSort(ScanSort.ASCENDING)*/.samplingScan(5l, null);
|
||||
/*.withSort(ScanSort.ASCENDING)*/.samplingScan(5l, (Long)null);
|
||||
List<User> usersList = users.toList();
|
||||
assertEquals(5, usersList.size(), "number in sample");
|
||||
for (User u : usersList) {
|
||||
|
||||
@@ -90,7 +90,7 @@ class QueryCriteriaTests {
|
||||
@Test
|
||||
void testNestedNotIn() {
|
||||
QueryCriteria c = where(i("name")).is("Bubba").or(where(i("age")).gt(12).and(i("country")).is("Austria"))
|
||||
.and(where(i("state")).notIn(new String[] { "Alabama", "Florida" }));
|
||||
.and(where(i("state")).notIn( "Alabama", "Florida" ));
|
||||
JsonArray parameters = JsonArray.create();
|
||||
assertEquals(" ( (`name` = $1) or (`age` > $2 and `country` = $3)) and (not( (`state` in $4) ))",
|
||||
c.export(new int[1], parameters, null));
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.stereotype.Repository;
|
||||
*/
|
||||
@Repository
|
||||
public interface BigAirlineRepository extends CouchbaseRepository<BigAirline, String>,
|
||||
QuerydslPredicateExecutor<BigAirline>, DynamicProxyable<BigAirlineRepository> {
|
||||
DynamicProxyable<BigAirlineRepository> {
|
||||
|
||||
@Query("#{#n1ql.selectEntity} where #{#n1ql.filter} and (name = $1)")
|
||||
List<Airline> getByName(@Param("airline_name") String airlineName);
|
||||
|
||||
Reference in New Issue
Block a user