Skip to content

Commit

Permalink
Merge pull request #30200 from geoand/#30190
Browse files Browse the repository at this point in the history
Ensure that Kotlin implementation of QuarkusApplication works properly
  • Loading branch information
geoand authored Jan 5, 2023
2 parents 39701e1 + d5fb7fc commit 0438237
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 @@ -419,25 +419,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 0438237

Please sign in to comment.