Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] AspectJ issue with Kotlin

That looks like you are binary weaving. Let me present a few questions/things-to-explore. You said "aspectj weaving is not working for us.":
- are you getting weave-info messages saying advice is applying but it isn't?
- are you not even getting weave-info messages?
- are you using elaborate point cut patterns?  Have you tried a 'javap -private' on the kotlin classes, do the methods look like you expect in that code or has kotlin somehow renamed them and the point cuts would no longer match without adjustment?
- have you tried a looser point cut (execution(* *(..))) for example - does that match and work?

Andy

On Thu, 25 Jul 2019 at 23:50, Hitesh Das <hiteshdasmnnit@xxxxxxxxx> wrote:
Hi Andy,
PFA the gradle script we are using.

final def log = project.logger
final def variants = project.android.applicationVariants

variants.all { variant ->
    try {

        /*variant.outputs.all { output ->
            def newPath = outputFileName.replace(".apk", "-${variant.versionName}.${variant.versionCode}.apk")
            outputFileName = new File(outputFileName, newPath)


            def fullName = ""
            output.name.tokenize('-').eachWithIndex { token, index ->
                fullName = fullName + (index == 0 ? token : token.capitalize())
            }

            println("Full Name : "+fullName+"\n")
            //println("output file name : "+outputFileName)
            println("build path : "+project.buildDir.path)
        }*/

        println("TimeLogger Trying to weave the class '${variant.buildType.name}'.")

        if (!variant.buildType.isDebuggable()) {
            println("TimeLogger Skipping non-debuggable build type '${variant.buildType.name}'.")
            return
        }



        JavaCompile javaCompile = variant.javaCompile
        javaCompile.doLast {
            String[] args = ["-showWeaveInfo",
                             "-1.5",
                             "-inpath", javaCompile.destinationDir.toString(),
                             "-aspectpath", javaCompiler.classpath.asFileTree.filter {
                !it.canonicalPath.contains("transforms")
            }.asPath,
                             "-d", javaCompile.destinationDir.toString(),
                             "-classpath", javaCompile.classpath.asPath,
                             "-bootclasspath", project.android.bootClasspath.join(File.pathSeparator)]

            String[] kotlinArgs = ["-showWeaveInfo",
                                   "-1.5",
                                   "-inpath", project.buildDir.path + "/tmp/kotlin-classes/"+"<debugFolderName>",
                                   "-aspectpath", javaCompiler.classpath.asFileTree.filter {
                !it.canonicalPath.contains("transforms")
            }.asPath,
                                   "-d", project.buildDir.path + "/tmp/kotlin-classes/
"+"<debugFolderName>",
                                   "-classpath", javaCompile.classpath.asPath,
                                   "-bootclasspath", project.android.bootClasspath.join(
                    File.pathSeparator)]



            MessageHandler handler = new MessageHandler(true)
            new Main().run(kotlinArgs, handler)
            new Main().run(args, handler)


            for (IMessage message : handler.getMessages(null, true)) {
                switch (message.getKind()) {
                    case IMessage.ABORT:
                    case IMessage.ERROR:
                    case IMessage.FAIL:
                        log.error message.message, message.thrown
                        break
                    case IMessage.WARNING:
                        log.warn message.message, message.thrown
                        break
                    case IMessage.INFO:
                        log.info message.message, message.thrown
                        break
                    case IMessage.DEBUG:
                        log.debug message.message, message.thrown
                        break
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace()
        println("TimeLogger Exception: " + e.getMessage())
    }

}


On Thu, Jul 25, 2019 at 8:59 PM Andy Clement <andrew.clement@xxxxxxxxx> wrote:
How are you applying AspectJ to the kotlin classes? Are you doing simple post compile time weaving? (feeding your kotlin compiled classes into the AspectJ compiler for binary weaving). I would have expected this to work but I haven't looked at whether they generate something unusual. If you had a sample app I'll take a look at exactly why it is misbehaving.

cheers,
Andy

On Thu, 25 Jul 2019 at 02:07, Hitesh Das <hiteshdasmnnit@xxxxxxxxx> wrote:

Hi All,

I am an Android Developer and is using AOP to profile methods in our current java project. So far AOP with aspectj was working like charm and was serving our purpose.
Now we are migrating the project to Kotlin and aspectj weaving is not working for us.

We searched through a lot of forums but none of the solutions seems working. This is blocking us.

Solutions we tried 
1. Making the kotlin classes open
2. Providing kotlin class path and executing the main method twice once with java classpath and another with Kotlin class path.

None of them is working.

Any guidance to this would be of great help.



--
Regards
Hitesh Das
+91-9015225032

Planet: Earth 

_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/aspectj-dev
_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/aspectj-dev


--
Regards
Hitesh Das
+91-9015225032

Planet: Earth 

_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/aspectj-dev

Back to the top