Skip to content

Commit

Permalink
Allow primitive option types
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvisser committed Aug 17, 2023
1 parent a1fc7ab commit e376e86
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
31 changes: 30 additions & 1 deletion ret-cli/src/main/kotlin/io/rabobank/ret/plugins/PluginLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class PluginLoader(
command.options.forEach {
commandSpec.addOption(
OptionSpec.builder(it.names.toTypedArray())
.type(Class.forName(it.type))
.type(asType(it.type))
.completionCandidates(it.completionCandidates)
.build(),
)
Expand All @@ -82,4 +82,33 @@ class PluginLoader(
executionContext.repositoryName(),
executionContext.branchName(),
)

private companion object {
/**
* Return the java [java.lang.Class] object with the specified class name.
*
* This is an "extended" [java.lang.Class.forName] operation.
*
* + It is able to return Class objects for primitive types
* + Classes in name space `java.lang` do not need the fully qualified name
* + It does not throw a checked Exception
*
* @param className The class name, never `null`
*
* @throws IllegalArgumentException if no class can be loaded
*/
private fun asType(className: String): Class<*>? =
when (className) {
"boolean" -> Boolean::class.javaPrimitiveType
"byte" -> Byte::class.javaPrimitiveType
"short" -> Short::class.javaPrimitiveType
"int" -> Int::class.javaPrimitiveType
"long" -> Long::class.javaPrimitiveType
"float" -> Float::class.javaPrimitiveType
"double" -> Double::class.javaPrimitiveType
"char" -> Char::class.javaPrimitiveType
"void" -> Void.TYPE
else -> Class.forName(if (className.contains(".")) className else "java.lang.$className")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

public final class RetPlugin {

private RetPlugin(){
private RetPlugin() {

}

public static native long createIsolate();

public static native void invoke(long isolateId, String retContext);

public static native void initialize(long isolateId, String plugin);
}
4 changes: 0 additions & 4 deletions ret-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@
<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.quarkus.platform</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
Expand Down
7 changes: 2 additions & 5 deletions ret-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.github.rabobank</groupId>
Expand Down Expand Up @@ -87,10 +88,6 @@
<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.quarkus.platform</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
Expand Down

0 comments on commit e376e86

Please sign in to comment.