Skip to content

Commit

Permalink
Fixed problems with KSP (#1173)
Browse files Browse the repository at this point in the history
Fixed #1154
Fixed #1288
  • Loading branch information
altro3 authored Nov 23, 2023
1 parent 6c4dbe0 commit 5da7705
Show file tree
Hide file tree
Showing 113 changed files with 2,743 additions and 327 deletions.
5 changes: 1 addition & 4 deletions docs-examples/example-groovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ repositories {

dependencies {

testAnnotationProcessor(mn.micronaut.inject.groovy)

testCompileOnly(mn.micronaut.inject.groovy)
testCompileOnly(libs.managed.swagger.annotations)
testCompileOnly(projects.micronautOpenapi)

testImplementation(mn.micronaut.http)
testImplementation projects.micronautOpenapi
testImplementation(mn.snakeyaml)
testImplementation(mnGroovy.micronaut.runtime.groovy)
testImplementation(mnValidation.validation)
Expand Down
3 changes: 2 additions & 1 deletion docs-examples/example-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ repositories {
dependencies {

testAnnotationProcessor(mn.micronaut.inject.java)
testAnnotationProcessor(projects.micronautOpenapi)

testCompileOnly(mn.micronaut.inject.java)
testCompileOnly projects.micronautOpenapiAnnotations

testImplementation(mn.micronaut.http)
testImplementation projects.micronautOpenapi
testImplementation(mn.snakeyaml)
testImplementation(mn.reactor)
testImplementation(mnValidation.validation)
Expand Down
20 changes: 9 additions & 11 deletions docs-examples/example-kotlin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.kapt)
alias(libs.plugins.kotlin.ksp)
alias(libs.plugins.kotlin.allopen)
}

Expand All @@ -9,11 +9,13 @@ repositories {
}

dependencies {
kapt projects.micronautOpenapi
kapt(mn.micronaut.inject.java)
kapt(mnValidation.micronaut.validation)

kaptTest(mn.micronaut.inject.java)
kspTest(mn.micronaut.inject.kotlin)
kspTest(mnValidation.micronaut.validation)
kspTest(projects.micronautOpenapi)

testCompileOnly projects.micronautOpenapiAnnotations
testCompileOnly(mn.micronaut.inject.kotlin)

testImplementation(mn.micronaut.http)
testImplementation(libs.managed.swagger.annotations)
Expand All @@ -24,16 +26,12 @@ dependencies {
testImplementation(libs.kotlin.reflect)
testImplementation(mnTest.micronaut.test.junit5)

testCompileOnly(mn.micronaut.inject.java)

testRuntimeOnly(libs.junit.jupiter.engine)
testRuntimeOnly(mnLogging.logback.classic)
}

kapt {
arguments {
arg("micronaut.openapi.project.dir", projectDir.toString())
}
ksp {
arg("micronaut.openapi.project.dir", projectDir.toString())
}

test {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ developers=Puneet Behl,Álvaro Sánchez-Mariscal,Iván López

org.gradle.caching=true
kotlin.stdlib.default.dependency=false
org.gradle.jvmargs=-Xmx1g -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8

# No matter which Java toolchain we use, the Kotlin Daemon is always invoked by the current JDK.
# Therefor to fix Kapt errors when running tests under Java 21, we need to open up some modules for the Kotlin Daemon.
Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ managed-freemarker = "2.3.32"
managed-pegdown = "1.6.0"

kotlin = "1.9.20"
ksp = "1.9.20-1.0.14"
jspecify = "0.3.0"
jdt-annotation = "2.2.700"
android-annotation = "1.7.0"
spotbugs-annotations = "4.8.1"
openapi-generator = "7.0.1"
openapi-generator = "7.1.0"
swagger-parser = "1.0.68"
swagger-parser-v3 = "2.1.19"
javaparser = "3.25.6"
Expand Down Expand Up @@ -83,5 +84,6 @@ swagger-parser-v3 = { module = "io.swagger.parser.v3:swagger-parser-v3", version

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
kotlin-allopen = { id = "org.jetbrains.kotlin.plugin.allopen", version.ref = "kotlin" }
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ public void visit(ExpImageNode node) {
String text = printChildrenToString(node);
LinkRenderer.Rendering imageRenderer = linkRenderer.render(node, text);
Node linkNode;
if ((linkNode = findParentNode(node, rootNode)) instanceof ExpLinkNode) {
printImageTagWithLink(imageRenderer, linkRenderer.render((ExpLinkNode) linkNode, null));
if ((linkNode = findParentNode(node, rootNode)) instanceof ExpLinkNode expLinkNode) {
printImageTagWithLink(imageRenderer, linkRenderer.render(expLinkNode, null));
} else {
printImageTag(linkRenderer.render(node, text));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public ExampleSerializer(JsonSerializer<Object> serializer) {

@Override
public void resolve(SerializerProvider serializerProvider) throws JsonMappingException {
if (defaultSerializer instanceof ResolvableSerializer) {
((ResolvableSerializer) defaultSerializer).resolve(serializerProvider);
if (defaultSerializer instanceof ResolvableSerializer resolvableSerializer) {
resolvableSerializer.resolve(serializerProvider);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public MediaTypeSerializer(JsonSerializer<Object> serializer) {

@Override
public void resolve(SerializerProvider serializerProvider) throws JsonMappingException {
if (defaultSerializer instanceof ResolvableSerializer) {
((ResolvableSerializer) defaultSerializer).resolve(serializerProvider);
if (defaultSerializer instanceof ResolvableSerializer resolvableSerializer) {
resolvableSerializer.resolve(serializerProvider);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public Schema31Serializer(JsonSerializer<Object> serializer) {

@Override
public void resolve(SerializerProvider serializerProvider) throws JsonMappingException {
if (defaultSerializer instanceof ResolvableSerializer) {
((ResolvableSerializer) defaultSerializer).resolve(serializerProvider);
if (defaultSerializer instanceof ResolvableSerializer resolvableSerializer) {
resolvableSerializer.resolve(serializerProvider);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public SchemaSerializer(JsonSerializer<Object> serializer) {

@Override
public void resolve(SerializerProvider serializerProvider) throws JsonMappingException {
if (defaultSerializer instanceof ResolvableSerializer) {
((ResolvableSerializer) defaultSerializer).resolve(serializerProvider);
if (defaultSerializer instanceof ResolvableSerializer resolvableSerializer) {
resolvableSerializer.resolve(serializerProvider);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,6 @@ public String getPackageName() {
return packageName;
}

@Override
public void setSerializationLibrary(final String serializationLibrary) {
try {
this.serializationLibrary = SerializationLibraryKind.valueOf(serializationLibrary).name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ class {{classname}}Test {
{{#model}}
{{^vendorExtensions.x-is-one-of-interface}}
{{^isEnum}}
val model: {{classname}}? = null
val model: {{classname}}? = null

{{/isEnum}}
/**
* Model tests for {{classname}}
*/
@Test
fun test{{classname}}() {
// TODO: test {{classname}}
}
/**
* Model tests for {{classname}}
*/
@Test
fun test{{classname}}() {
// TODO: test {{classname}}
}

{{#allVars}}
/**
* Test the property '{{name}}'
*/
@Test
fun {{name}}Test() {
// TODO: test {{name}}
}
/**
* Test the property '{{name}}'
*/
@Test
fun {{name}}Test() {
// TODO: test {{name}}
}

{{/allVars}}
{{/vendorExtensions.x-is-one-of-interface}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public ACTUAL containsWithNameAndAttributes(final String name, final Map<String,

private static boolean hasAttributes(final AnnotationExpr annotation, final Map<String, String> expectedAttributesToContains) {
final Map<String, String> actualAttributes;
if (annotation instanceof SingleMemberAnnotationExpr) {
if (annotation instanceof SingleMemberAnnotationExpr singleMemberAnnotationExpr) {
actualAttributes = ImmutableMap.of(
"value", ((SingleMemberAnnotationExpr) annotation).getMemberValue().toString()
"value", singleMemberAnnotationExpr.getMemberValue().toString()
);
} else if (annotation instanceof NormalAnnotationExpr) {
actualAttributes = ((NormalAnnotationExpr) annotation).getPairs().stream()
} else if (annotation instanceof NormalAnnotationExpr normalAnnotationExpr) {
actualAttributes = normalAnnotationExpr.getPairs().stream()
.collect(Collectors.toMap(NodeWithSimpleName::getNameAsString, pair -> pair.getValue().toString()));
} else if (annotation instanceof MarkerAnnotationExpr) {
actualAttributes = new HashMap<>();
Expand Down
3 changes: 3 additions & 0 deletions openapi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {
api(libs.managed.jsoup)

testImplementation(mn.micronaut.management)
testImplementation(mn.micronaut.inject.kotlin.test)
testImplementation(mn.micronaut.inject.groovy.test)
testImplementation(mn.micronaut.inject.java.test)
testImplementation(mn.micronaut.http.server)
Expand All @@ -46,4 +47,6 @@ configurations.configureEach {

test {
useJUnitPlatform()

maxHeapSize = "1024m"
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
* Changes the Retention Policy of the annotation to SOURCE.
*
* @param <T> The annotation type.
* @since 2.1
*
* @author croudet
* @since 2.1
*/
abstract class AbstractRetentionPolicyAnnotationTransformer<T extends Annotation> implements TypedAnnotationTransformer<T> {

private final Class<T> type;

/**
Expand All @@ -46,7 +48,7 @@ abstract class AbstractRetentionPolicyAnnotationTransformer<T extends Annotation
@Override
public List<AnnotationValue<?>> transform(AnnotationValue<T> annotation, VisitorContext context) {
return Collections.singletonList(
AnnotationValue.builder(annotation, RetentionPolicy.SOURCE).build());
AnnotationValue.builder(annotation, RetentionPolicy.SOURCE).build());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
/**
* Changes the Retention Policy of the annotation to SOURCE.
*
* @since 2.1
* @author croudet
* @since 2.1
*/
public class ApiResponseRetentionPolicyAnnotationTransformer extends AbstractRetentionPolicyAnnotationTransformer<ApiResponse> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
/**
* Changes the Retention Policy of the annotation to SOURCE.
*
* @since 2.1
* @author croudet
* @since 2.1
*/
public class ApiResponsesRetentionPolicyAnnotationTransformer extends AbstractRetentionPolicyAnnotationTransformer<ApiResponses> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
/**
* Changes the Retention Policy of the annotation to SOURCE.
*
* @since 2.1
* @author croudet
* @since 2.1
*/
public class ArraySchemaRetentionPolicyAnnotationTransformer extends AbstractRetentionPolicyAnnotationTransformer<ArraySchema> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
/**
* Changes the Retention Policy of the annotation to SOURCE.
*
* @since 2.1
* @author croudet
* @since 2.1
*/
public class CallbackRetentionPolicyAnnotationTransformer extends AbstractRetentionPolicyAnnotationTransformer<Callback> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
/**
* Changes the Retention Policy of the annotation to SOURCE.
*
* @since 2.1
* @author croudet
* @since 2.1
*/
public class CallbacksRetentionPolicyAnnotationTransformer extends AbstractRetentionPolicyAnnotationTransformer<Callbacks> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
/**
* Changes the Retention Policy of the annotation to SOURCE.
*
* @since 2.1
* @author croudet
* @since 2.1
*/
public class ContactRetentionPolicyAnnotationTransformer extends AbstractRetentionPolicyAnnotationTransformer<Contact> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
/**
* Changes the Retention Policy of the annotation to SOURCE.
*
* @since 2.1
* @author croudet
* @since 2.1
*/
public class ContentRetentionPolicyAnnotationTransformer extends AbstractRetentionPolicyAnnotationTransformer<Content> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
/**
* Changes the Retention Policy of the annotation to SOURCE.
*
* @since 2.1
* @author croudet
* @since 2.1
*/
public class DiscriminatorMappingRetentionPolicyAnnotationTransformer extends AbstractRetentionPolicyAnnotationTransformer<DiscriminatorMapping> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
/**
* Changes the Retention Policy of the annotation to SOURCE.
*
* @since 2.1
* @author croudet
* @since 2.1
*/
public class EncodingRetentionPolicyAnnotationTransformer extends AbstractRetentionPolicyAnnotationTransformer<Encoding> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
/**
* Changes the Retention Policy of the annotation to SOURCE.
*
* @since 2.1
* @author croudet
* @since 2.1
*/
public class ExampleObjectMappingRetentionPolicyAnnotationTransformer extends AbstractRetentionPolicyAnnotationTransformer<ExampleObject> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
/**
* Changes the Retention Policy of the annotation to SOURCE.
*
* @since 2.1
* @author croudet
* @since 2.1
*/
public class ExtensionPropertyRetentionPolicyAnnotationTransformer extends AbstractRetentionPolicyAnnotationTransformer<ExtensionProperty> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
/**
* Changes the Retention Policy of the annotation to SOURCE.
*
* @since 2.1
* @author croudet
* @since 2.1
*/
public class ExtensionRetentionPolicyAnnotationTransformer extends AbstractRetentionPolicyAnnotationTransformer<Extension> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
/**
* Changes the Retention Policy of the annotation to SOURCE.
*
* @since 2.1
* @author croudet
* @since 2.1
*/
public class ExtensionsRetentionPolicyAnnotationTransformer extends AbstractRetentionPolicyAnnotationTransformer<Extensions> {

Expand Down
Loading

0 comments on commit 5da7705

Please sign in to comment.