Skip to content

Exclude javax.inject and CB AnnotationProcessor to exit gracefully w/o. #1934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<springdata.commons>3.3.0-SNAPSHOT</springdata.commons>
<java-module-name>spring.data.couchbase</java-module-name>
<hibernate.validator>7.0.1.Final</hibernate.validator>
<mysema.querydsl>3.7.4</mysema.querydsl>
<couchbase.encryption>3.1.0</couchbase.encryption>
<jodatime>2.10.13</jodatime>
<jackson-joda>2.13.4</jackson-joda>
Expand All @@ -49,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>
Expand Down Expand Up @@ -250,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>
Expand All @@ -273,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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -60,4 +63,52 @@ protected Configuration createConfiguration(@Nullable RoundEnvironment roundEnv)

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);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ void sampleScan() {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void testNestedOrCriteria() {
@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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
@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);
Expand Down
Loading