Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Improve Kotlin Binding Support #685

Merged
merged 7 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion Util/Xamarin.Kotlin.BindingSupport/build.cake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

var TARGET = Argument("t", Argument("target", "Default"));

var PACKAGE_VERSION = "0.2.0-preview";
var PACKAGE_VERSION = "0.3.0-preview";

Task("externals")
.Does(() =>
Expand Down
6 changes: 3 additions & 3 deletions Util/Xamarin.Kotlin.BindingSupport/native/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.41'
id 'org.jetbrains.kotlin.jvm' version '1.3.0'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note about the version numbers: As I update the version to the later ones, it struggles to find various members. So, I just dropped it all the way down. Not sure what is happening here, but it works now...

}

group 'xamarin.binding.kotlin'
Expand All @@ -17,8 +17,8 @@ dependencies {
compile 'com.github.ajalt:clikt:2.1.0'
compile 'xom:xom:1.3.2'
compile 'org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.1.0'
compile "org.jetbrains.kotlin:kotlin-stdlib:1.3.41"
compile "org.jetbrains.kotlin:kotlin-reflect:1.3.41"
compile "org.jetbrains.kotlin:kotlin-stdlib:1.3.0"
compile "org.jetbrains.kotlin:kotlin-reflect:1.3.0"
}

compileKotlin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class ProcessXmlCommand : CliktCommand(name = "KotlinBindingSupport") {
val outputFile: File? by option("-o", "--output", help = "path to the output transform file")
.file(fileOkay = true, folderOkay = false)

val ignoreFile: File? by option("-i", "--ignore", help = "path to the ignore file")
.file(fileOkay = true, folderOkay = false)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't actually thing this is needed anymore since it is working properly with a lower Kotlin version, but just in case.


val companions: Processor.CompanionProcessing by option("--companions", help = "indicate how to handle companions")
.choice(
"default" to Processor.CompanionProcessing.Default,
Expand All @@ -32,7 +35,7 @@ class ProcessXmlCommand : CliktCommand(name = "KotlinBindingSupport") {
.flag(default = false)

override fun run() {
val proc = Processor(xmlFile, jarFiles, outputFile)
val proc = Processor(xmlFile, jarFiles, outputFile, ignoreFile)
proc.verbose = verbose
proc.companions = companions
proc.process()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import java.lang.reflect.Constructor
import java.lang.reflect.Executable
import java.lang.reflect.Field
import java.lang.reflect.Method
import java.net.URL
import java.net.URLClassLoader
import kotlin.reflect.KFunction
import kotlin.reflect.KVisibility
import kotlin.reflect.jvm.kotlinFunction
import kotlin.reflect.jvm.kotlinProperty

class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?, ignoreFile: File?) {

private fun expressionClasses() =
"/api/package/*[local-name()='class' or local-name()='interface']"
Expand Down Expand Up @@ -48,6 +47,8 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
private val outputFile: File?
private val xtransformsdoc: Document

private val ignored: List<String>

init {
val urls = jarFiles.map { file -> file.toURI().toURL() }
loader = URLClassLoader(urls.toTypedArray())
Expand All @@ -57,6 +58,12 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {

xtransformsdoc = Document(Element("metadata"))
this.outputFile = outputFile

if (ignoreFile != null) {
ignored = ignoreFile.readLines()
} else {
ignored = emptyList()
}
}

fun process() {
Expand Down Expand Up @@ -196,13 +203,13 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {

// remove the members that are not meant to be used
processMembers(xclass, "constructor") {
shouldRemoveMember(it, jclass.declaredConstructors)
shouldRemoveMember(it, jclass.declaredConstructors + jclass.constructors)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still a required change because several members are not found for some reason. It works now, so...

}
processMembers(xclass, "method") {
shouldRemoveMember(it, jclass.declaredMethods)
shouldRemoveMember(it, jclass.declaredMethods + jclass.methods)
}
processMembers(xclass, "field") {
shouldRemoveField(it, jclass.declaredFields)
shouldRemoveField(it, jclass.declaredFields + jclass.fields)
}
}

Expand Down Expand Up @@ -253,6 +260,12 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {

logVerbose("Checking the class \"${xpackage}.${xname}\"...")

// make sure we haven't been told to ignore this
if (ignored.contains("${xpackage}.${xname}")) {
logVerbose("Ignoring class \"${xpackage}.${xname}\" because it was found in the ignore file...")
return ProcessResult.Ignore
}

// before we check anything, make sure that the parent class is visible
var lastPeriod = xname.lastIndexOf(".")
while (lastPeriod != -1) {
Expand Down Expand Up @@ -319,6 +332,12 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
val xtype = xmember.localName
val xfullname = "${xpackage}.${xclassname}.${xname}"

// make sure we haven't been told to ignore this
if (ignored.contains(xfullname)) {
logVerbose("Ignoring member \"${xfullname}\" because it was found in the ignore file...")
return ProcessResult.Ignore
}

// before doing any complex checks, make sure it is not an invalid member
if (invalidKeywords.any { check -> check(xname) })
return ProcessResult.RemoveGenerated
Expand Down Expand Up @@ -410,6 +429,12 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
val xtype = xmember.getAttributeValue("type")
val xfullname = "${xpackage}.${xclassname}.${xname}"

// make sure we haven't been told to ignore this
if (ignored.contains(xfullname)) {
logVerbose("Ignoring field \"${xfullname}\" because it was found in the ignore file...")
return ProcessResult.Ignore
}

// before doing any complex checks, make sure it is not an invalid member
if (invalidKeywords.any { check -> check(xname) }) {
return ProcessResult.RemoveGenerated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@
<PropertyGroup>
<KotlinBindingSupportJar Condition="'$(KotlinBindingSupportJar)' == ''">$(MSBuildThisFileDirectory)binding-support-1.0.jar</KotlinBindingSupportJar>
<KotlinBindingSupportExtraArgs Condition="'$(KotlinBindingSupportExtraArgs)' == ''"></KotlinBindingSupportExtraArgs>
<KotlinBindingSupportIgnorePath Condition="'$(KotlinBindingSupportIgnorePath)' == ''"></KotlinBindingSupportIgnorePath>
<KotlinBindingSupportOutputPath Condition="'$(KotlinBindingSupportOutputPath)' == ''">$(IntermediateOutputPath)\KotlinBindingSupport.generated.xml</KotlinBindingSupportOutputPath>
</PropertyGroup>

<!-- private properties -->
<PropertyGroup>
<_KotlinBindingJavaPath Condition="'$(_KotlinBindingJavaPath)' == '' and '$(OS)' == 'Unix'">$(JavaSdkDirectory)\bin\java</_KotlinBindingJavaPath>
<_KotlinBindingJavaPath Condition="'$(_KotlinBindingJavaPath)' == '' and '$(OS)' != 'Unix'">$(JavaSdkDirectory)\bin\java.exe</_KotlinBindingJavaPath>
<_KotlinBindingSupportIgnore Condition="'$(KotlinBindingSupportIgnorePath)' != ''">--ignore &quot;$(KotlinBindingSupportIgnorePath)&quot;</_KotlinBindingSupportIgnore>
</PropertyGroup>

<ItemGroup>
<_KotlinBindingReferenceJar Include="@(EmbeddedJar);@(InputJar)" />
<_KotlinBindingReferenceJar Include="@(EmbeddedReferenceJar);@(ReferenceJar);@(_AdditionalJavaLibraryReferences)" />
</ItemGroup>

<Exec Command="&quot;$(_KotlinBindingJavaPath)&quot; -jar &quot;$(KotlinBindingSupportJar)&quot; --xml &quot;$(ApiOutputFile)&quot; --jar &quot;@(_KotlinBindingReferenceJar, '&quot; --jar &quot;')&quot; --output &quot;$(KotlinBindingSupportOutputPath)&quot; $(KotlinBindingSupportExtraArgs)" />
<Exec Command="&quot;$(_KotlinBindingJavaPath)&quot; -jar &quot;$(KotlinBindingSupportJar)&quot; --xml &quot;$(ApiOutputFile)&quot; --jar &quot;@(_KotlinBindingReferenceJar, '&quot; --jar &quot;')&quot; --output &quot;$(KotlinBindingSupportOutputPath)&quot; $(_KotlinBindingSupportIgnore) $(KotlinBindingSupportExtraArgs)" />

<ItemGroup>
<!-- insert the generated transform at the beginning -->
Expand Down