Allopen: Add allopen Gradle subplugin
This commit is contained in:
committed by
Yan Zhulanow
parent
f57df272ac
commit
ed7c38fb96
@@ -100,6 +100,7 @@
|
||||
<module>tools/kotlin-js-tests</module>
|
||||
<module>tools/kotlin-js-tests-junit</module>
|
||||
<module>tools/kotlin-annotation-processing</module>
|
||||
<module>tools/kotlin-allopen</module>
|
||||
|
||||
<module>tools/kotlin-gradle-plugin</module>
|
||||
<module>tools/kotlin-gradle-plugin-api</module>
|
||||
|
||||
Executable
+148
@@ -0,0 +1,148 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.version>3.0.4</maven.version>
|
||||
<allopen.src>${basedir}/../../../plugins/allopen/src</allopen.src>
|
||||
<allopen.gradle.plugin.src>${basedir}/src/main/kotlin</allopen.gradle.plugin.src>
|
||||
<allopen.gradle.plugin.resources>${basedir}/src/main/resources</allopen.gradle.plugin.resources>
|
||||
<allopen.target-src>${basedir}/target/src/main/kotlin</allopen.target-src>
|
||||
<allopen.target-resources>${basedir}/target/resource</allopen.target-resources>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-project</artifactId>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>kotlin-allopen</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<description>All-open plugin for Gradle</description>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jetbrains-utils</id>
|
||||
<url>http://repository.jetbrains.com/utils</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-compiler-embeddable</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-gradle-plugin-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>gradle-api</artifactId>
|
||||
<version>2.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>${allopen.target-src}</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${allopen.target-resources}</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-sources</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${allopen.target-src}</outputDirectory>
|
||||
<resources>
|
||||
<resource><directory>${allopen.src}</directory></resource>
|
||||
<resource><directory>${allopen.gradle.plugin.src}</directory></resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>copy-resources</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${allopen.target-resources}/META-INF</outputDirectory>
|
||||
<resources>
|
||||
<resource><directory>${allopen.src}/META-INF</directory></resource>
|
||||
<resource><directory>${allopen.gradle.plugin.resources}/META-INF</directory></resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.google.code.maven-replacer-plugin</groupId>
|
||||
<artifactId>replacer</artifactId>
|
||||
<version>1.5.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>replace</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>${allopen.target-src}/**</include>
|
||||
</includes>
|
||||
<replacements>
|
||||
<replacement>
|
||||
<token>com\.intellij</token>
|
||||
<value>org.jetbrains.kotlin.com.intellij</value>
|
||||
</replacement>
|
||||
</replacements>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${project.version}</version>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals> <goal>compile</goal> </goals>
|
||||
<configuration>
|
||||
<sourceDirs>
|
||||
<sourceDir>${allopen.target-src}</sourceDir>
|
||||
</sourceDirs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.allopen.gradle
|
||||
|
||||
open class AllOpenExtension {
|
||||
internal val myAnnotations = mutableListOf<String>()
|
||||
|
||||
open fun annotation(fqName: String) {
|
||||
myAnnotations.add(fqName)
|
||||
}
|
||||
|
||||
open fun annotations(fqNames: List<String>) {
|
||||
myAnnotations.addAll(fqNames)
|
||||
}
|
||||
|
||||
open fun annotations(vararg fqNames: String) {
|
||||
myAnnotations.addAll(fqNames)
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.allopen.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.SourceSet
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin
|
||||
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
|
||||
|
||||
class AllOpenGradleSubplugin : Plugin<Project> {
|
||||
companion object {
|
||||
fun isEnabled(project: Project) = project.plugins.findPlugin(AllOpenGradleSubplugin::class.java) != null
|
||||
|
||||
fun getAllOpenExtension(project: Project): AllOpenExtension {
|
||||
return project.extensions.getByType(AllOpenExtension::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
override fun apply(project: Project) {
|
||||
project.extensions.create("allOpen", AllOpenExtension::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
class AllOpenKotlinGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
|
||||
private companion object {
|
||||
val ANNOTATIONS_ARG_NAME = "annotation"
|
||||
}
|
||||
|
||||
override fun isApplicable(project: Project, task: AbstractCompile) = AllOpenGradleSubplugin.isEnabled(project)
|
||||
|
||||
override fun apply(
|
||||
project: Project,
|
||||
kotlinCompile: AbstractCompile,
|
||||
javaCompile: AbstractCompile,
|
||||
variantData: Any?,
|
||||
javaSourceSet: SourceSet?
|
||||
): List<SubpluginOption> {
|
||||
if (!AllOpenGradleSubplugin.isEnabled(project)) return emptyList()
|
||||
|
||||
val allOpenExtension = project.extensions.findByType(AllOpenExtension::class.java) ?: return emptyList()
|
||||
|
||||
val options = mutableListOf<SubpluginOption>()
|
||||
|
||||
for (anno in allOpenExtension.myAnnotations) {
|
||||
options += SubpluginOption(ANNOTATIONS_ARG_NAME, anno)
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
override fun getArtifactName() = "kotlin-allopen"
|
||||
override fun getGroupName() = "org.jetbrains.kotlin"
|
||||
override fun getPluginName() = "org.jetbrains.kotlin.allopen"
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.allopen.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
|
||||
class SpringGradleSubplugin : Plugin<Project> {
|
||||
override fun apply(project: Project) {
|
||||
project.plugins.apply(AllOpenGradleSubplugin::class.java)
|
||||
val allOpenExtension = AllOpenGradleSubplugin.getAllOpenExtension(project)
|
||||
allOpenExtension.annotations("org.springframework.stereotype.Component",
|
||||
"org.springframework.transaction.annotation.Transactional",
|
||||
"org.springframework.scheduling.annotation.Async",
|
||||
"org.springframework.cache.annotation.Cacheable")
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
implementation-class=org.jetbrains.kotlin.allopen.gradle.AllOpenGradleSubplugin
|
||||
+1
@@ -0,0 +1 @@
|
||||
implementation-class=org.jetbrains.kotlin.allopen.gradle.SpringGradleSubplugin
|
||||
+1
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.allopen.gradle.AllOpenKotlinGradleSubplugin
|
||||
@@ -45,6 +45,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-allopen</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-gradle-subplugin-example</artifactId>
|
||||
|
||||
+45
@@ -1,6 +1,9 @@
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.jetbrains.kotlin.gradle.util.checkBytecodeContains
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class SimpleKotlinGradleIT : BaseGradleIT() {
|
||||
|
||||
@@ -99,4 +102,46 @@ class SimpleKotlinGradleIT : BaseGradleIT() {
|
||||
assertContains("GreeterTest PASSED")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAllOpenPlugin() {
|
||||
Project("allOpenSimple", GRADLE_VERSION).build("build") {
|
||||
assertSuccessful()
|
||||
|
||||
val classesDir = File(project.projectDir, "build/classes/main")
|
||||
val openClass = File(classesDir, "test/OpenClass.class")
|
||||
val closedClass = File(classesDir, "test/ClosedClass.class")
|
||||
assertTrue(openClass.exists())
|
||||
assertTrue(closedClass.exists())
|
||||
|
||||
checkBytecodeContains(openClass,
|
||||
"public class test/OpenClass {",
|
||||
"public method()V")
|
||||
|
||||
checkBytecodeContains(closedClass,
|
||||
"public final class test/ClosedClass {",
|
||||
"public final method()V")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testKotlinSpringPlugin() {
|
||||
Project("allOpenSpring", GRADLE_VERSION).build("build") {
|
||||
assertSuccessful()
|
||||
|
||||
val classesDir = File(project.projectDir, "build/classes/main")
|
||||
val openClass = File(classesDir, "test/OpenClass.class")
|
||||
val closedClass = File(classesDir, "test/ClosedClass.class")
|
||||
assertTrue(openClass.exists())
|
||||
assertTrue(closedClass.exists())
|
||||
|
||||
checkBytecodeContains(openClass,
|
||||
"public class test/OpenClass {",
|
||||
"public method()V")
|
||||
|
||||
checkBytecodeContains(closedClass,
|
||||
"public final class test/ClosedClass {",
|
||||
"public final method()V")
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: "kotlin"
|
||||
apply plugin: "kotlin-allopen"
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.kotlin.srcDir 'src'
|
||||
}
|
||||
|
||||
allOpen {
|
||||
annotation("lib.AllOpen")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package lib
|
||||
|
||||
annotation class AllOpen
|
||||
|
||||
annotation class AllClose
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package test
|
||||
|
||||
import lib.*
|
||||
|
||||
@AllOpen
|
||||
class OpenClass {
|
||||
fun method() {}
|
||||
}
|
||||
|
||||
@AllClose // effectively does nothing
|
||||
class ClosedClass {
|
||||
fun method() {}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: "kotlin"
|
||||
apply plugin: "kotlin-spring"
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.kotlin.srcDir 'src'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* This file was copied from the spring framework:
|
||||
* https://github.com/spring-projects/spring-framework
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.stereotype;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Indicates that an annotated class is a "component".
|
||||
* Such classes are considered as candidates for auto-detection
|
||||
* when using annotation-based configuration and classpath scanning.
|
||||
*
|
||||
* <p>Other class-level annotations may be considered as identifying
|
||||
* a component as well, typically a special kind of component:
|
||||
* e.g. the {@link Repository @Repository} annotation or AspectJ's
|
||||
* {@link org.aspectj.lang.annotation.Aspect @Aspect} annotation.
|
||||
*
|
||||
* @ author Mark Fisher
|
||||
* @since 2.5
|
||||
* @see Repository
|
||||
* @see Service
|
||||
* @see Controller
|
||||
* @see org.springframework.context.annotation.ClassPathBeanDefinitionScanner
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Indexed
|
||||
public @interface Component {
|
||||
|
||||
/**
|
||||
* The value may indicate a suggestion for a logical component name,
|
||||
* to be turned into a Spring bean in case of an autodetected component.
|
||||
* @return the suggested component name, if any
|
||||
*/
|
||||
String value() default "";
|
||||
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package test
|
||||
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
class OpenClass {
|
||||
fun method() {}
|
||||
}
|
||||
|
||||
class ClosedClass {
|
||||
fun method() {}
|
||||
}
|
||||
+4
@@ -13,6 +13,10 @@ fun classFileBytecodeString(classFile: File): String {
|
||||
return out.toString()
|
||||
}
|
||||
|
||||
fun checkBytecodeContains(classFile: File, vararg strings: String) {
|
||||
checkBytecodeContains(classFile, strings.toList())
|
||||
}
|
||||
|
||||
fun checkBytecodeContains(classFile: File, strings: Iterable<String>) {
|
||||
val bytecode = classFileBytecodeString(classFile)
|
||||
for (string in strings) {
|
||||
|
||||
Reference in New Issue
Block a user