Skip to end of metadata
Go to start of metadata

Plugin Information

No information for the plugin 'scala-hello-world' is available. It may have been removed from distribution.

Hello World Plugin built in Scala

Introduction

This plugin is a proof of concept for building plugins in Scala. It reimplements the standard hello world plugin

There is a Java shim but the main functionality is Scala.

The plugin is built with gradle

./gradlew server

Techie Detail

The main techie detail is to apply Java compile annotation processing to Scala code. This is the sezpoz annotation processing which creates a file of plugin descriptors.

The bit in gradle is this

task annotate(dependsOn:compileScala, type: Exec)  {

    if (logging.level >= LogLevel.INFO) {
        args '-verbose'
    }

    doFirst{
        args '-proc:only'
        args '-d'
        args compileJava.destinationDir
        args '-classpath'
        args compileJava.classpath.getAsPath() + java.io.File.pathSeparatorChar + compileJava.destinationDir

        if (logging.level >= LogLevel.INFO) {
            args '-verbose'
        }

        fileTree(compileScala.destinationDir).each { File file ->
            if(file.path.contains('META-INF')) {
                return
            }
            if(!file.path.endsWith('class')) {
                return
            }
            args file.path.minus(compileScala.destinationDir).minus('.class').substring(1).replaceAll(File.separator,'.')
        }
    }

    executable "javac"
}

compileScala.doLast {annotate.execute()}

This will iterate all the class files built from scala and run the preprocessors on them. This is complicated as class files must have the `.class` removed 

The scala gradle plugin is also used.

Improvements

* split the java and scala pieces

* write some tests

* the java shim splits out the scala functions to separate functions as the java paramaterizing didn't fit the scala parameterizing

* make the code more functional