Skip to content

Commit

Permalink
Ensure that Kotlin implementation of QuarkusApplication works properly
Browse files Browse the repository at this point in the history
Fixes: quarkusio#30190

Follows up on: quarkusio#30058 (which incorrectly checked for QuarkusApplication
as a superclass)

(cherry picked from commit d5fb7fc)
  • Loading branch information
geoand authored and gsmet committed Jan 9, 2023
1 parent a566586 commit 3431537
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,25 +418,15 @@ public MainClassBuildItem mainClassBuildStep(BuildProducer<GeneratedClassBuildIt
}

private static String sanitizeMainClassName(ClassInfo mainClass, IndexView index) {
String className = mainClass.name().toString();
DotName mainClassDotName = mainClass.name();
String className = mainClassDotName.toString();
if (isKotlinClass(mainClass)) {
MethodInfo mainMethod = mainClass.method("main",
ArrayType.create(Type.create(DotName.createSimple(String.class.getName()), Type.Kind.CLASS), 1));
if (mainMethod == null) {
ClassInfo classToCheck = mainClass;
boolean hasQuarkusApplicationSuperClass = false;
while (classToCheck != null) {
DotName superName = classToCheck.superName();
if (superName.equals(QUARKUS_APPLICATION)) {
hasQuarkusApplicationSuperClass = true;
break;
}
if (superName.equals(OBJECT)) {
break;
}
classToCheck = index.getClassByName(superName);
}
if (!hasQuarkusApplicationSuperClass) {
boolean hasQuarkusApplicationInterface = index.getAllKnownImplementors(QUARKUS_APPLICATION).stream().map(
ClassInfo::name).anyMatch(d -> d.equals(mainClassDotName));
if (!hasQuarkusApplicationInterface) {
className += "Kt";
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.acme

import io.quarkus.runtime.Quarkus
import io.quarkus.runtime.QuarkusApplication
import io.quarkus.runtime.annotations.QuarkusMain

@QuarkusMain
class Main : QuarkusApplication {

@Throws(Exception::class)
override fun run(vararg args: String?): Int {
Quarkus.waitForExit()
return 0
}
}

0 comments on commit 3431537

Please sign in to comment.