SamWithReceiver: Add general-purpose plugin and Gradle/Maven integrations
This commit is contained in:
committed by
Yan Zhulanow
parent
db3172a750
commit
d07fd52c43
+101
@@ -0,0 +1,101 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>test-sam-with-receiver-simple</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${kotlin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<goals> <goal>compile</goal> </goals>
|
||||
<configuration>
|
||||
<sourceDirs>
|
||||
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
|
||||
<sourceDir>${project.basedir}/src/main/java</sourceDir>
|
||||
</sourceDirs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
|
||||
<configuration>
|
||||
<compilerPlugins>
|
||||
<plugin>sam-with-receiver</plugin>
|
||||
</compilerPlugins>
|
||||
|
||||
<pluginOptions>
|
||||
<option>sam-with-receiver:annotation=lib.SamWithReceiver</option>
|
||||
</pluginOptions>
|
||||
</configuration>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-sam-with-receiver</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<executions>
|
||||
<!-- Replacing default-compile as it is treated specially by maven -->
|
||||
<execution>
|
||||
<id>default-compile</id>
|
||||
<phase>none</phase>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>java-compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals> <goal>compile</goal> </goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package lib;
|
||||
|
||||
@SamWithReceiver
|
||||
public interface Job {
|
||||
public void execute(String context, int other);
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package lib;
|
||||
|
||||
public interface JobWithoutReceiver {
|
||||
public void execute(String context, int other);
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package lib;
|
||||
|
||||
public class Manager {
|
||||
public void doJob(Job job) {}
|
||||
public void doJobWithoutReceiver(JobWithoutReceiver job) {}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package lib;
|
||||
|
||||
public @interface SamWithReceiver {}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package test
|
||||
|
||||
import lib.*
|
||||
|
||||
fun test() {
|
||||
val manager = Manager()
|
||||
manager.doJob { other -> println(this) }
|
||||
manager.doJobWithoutReceiver { context, other -> println(context) }
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import java.io.*;
|
||||
|
||||
File file = new File(basedir, "target/test-sam-with-receiver-simple-1.0-SNAPSHOT.jar");
|
||||
if (!file.exists() || !file.isFile()) {
|
||||
throw new FileNotFoundException("Could not find generated JAR: " + file);
|
||||
}
|
||||
Reference in New Issue
Block a user