Noarg: Add a kotlin-noarg Gradle plugin
This commit is contained in:
committed by
Yan Zhulanow
parent
e626b121ad
commit
be26246a3e
@@ -102,6 +102,7 @@
|
|||||||
<module>tools/kotlin-annotation-processing</module>
|
<module>tools/kotlin-annotation-processing</module>
|
||||||
<module>tools/kotlin-allopen</module>
|
<module>tools/kotlin-allopen</module>
|
||||||
<module>tools/kotlin-maven-allopen</module>
|
<module>tools/kotlin-maven-allopen</module>
|
||||||
|
<module>tools/kotlin-noarg</module>
|
||||||
|
|
||||||
<module>tools/kotlin-gradle-plugin</module>
|
<module>tools/kotlin-gradle-plugin</module>
|
||||||
<module>tools/kotlin-gradle-plugin-api</module>
|
<module>tools/kotlin-gradle-plugin-api</module>
|
||||||
|
|||||||
+13
@@ -144,4 +144,17 @@ class SimpleKotlinGradleIT : BaseGradleIT() {
|
|||||||
"public final method()V")
|
"public final method()V")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testKotlinJpaPlugin() {
|
||||||
|
Project("noArgJpa", GRADLE_VERSION).build("build") {
|
||||||
|
assertSuccessful()
|
||||||
|
|
||||||
|
val classesDir = File(project.projectDir, "build/classes/main")
|
||||||
|
val testClass = File(classesDir, "test/Test.class")
|
||||||
|
assertTrue(testClass.exists())
|
||||||
|
|
||||||
|
checkBytecodeContains(testClass, "public <init>()V")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: "kotlin"
|
||||||
|
apply plugin: "kotlin-jpa"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main.kotlin.srcDir 'src'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
}
|
||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file was copied from the javax.persistence :
|
||||||
|
* https://github.com/eclipse/javax.persistence/blob/master/src/javax/persistence/Entity.java
|
||||||
|
*/
|
||||||
|
package javax.persistence;
|
||||||
|
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import static java.lang.annotation.ElementType.TYPE;
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies that the class is an entity. This annotation is applied to the
|
||||||
|
* entity class.
|
||||||
|
*
|
||||||
|
* @since Java Persistence 1.0
|
||||||
|
*/
|
||||||
|
@Documented
|
||||||
|
@Target(TYPE)
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
public @interface Entity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (Optional) The entity name. Defaults to the unqualified
|
||||||
|
* name of the entity class. This name is used to refer to the
|
||||||
|
* entity in queries. The name must not be a reserved literal
|
||||||
|
* in the Java Persistence query language.
|
||||||
|
*/
|
||||||
|
String name() default "";
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
@javax.persistence.Entity
|
||||||
|
class Test(a: String, b: Int)
|
||||||
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>
|
||||||
|
<noarg.src>${basedir}/../../../plugins/noarg/noarg-cli/src</noarg.src>
|
||||||
|
<noarg.gradle.plugin.src>${basedir}/src/main/kotlin</noarg.gradle.plugin.src>
|
||||||
|
<noarg.gradle.plugin.resources>${basedir}/src/main/resources</noarg.gradle.plugin.resources>
|
||||||
|
<noarg.target-src>${basedir}/target/src/main/kotlin</noarg.target-src>
|
||||||
|
<noarg.target-resources>${basedir}/target/resource</noarg.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-noarg</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>1.6</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>${noarg.target-src}</sourceDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${noarg.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>${noarg.target-src}</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource><directory>${noarg.src}</directory></resource>
|
||||||
|
<resource><directory>${noarg.gradle.plugin.src}</directory></resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>copy-resources</id>
|
||||||
|
<phase>validate</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${noarg.target-resources}/META-INF</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource><directory>${noarg.src}/META-INF</directory></resource>
|
||||||
|
<resource><directory>${noarg.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>${noarg.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>${noarg.target-src}</sourceDir>
|
||||||
|
</sourceDirs>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* 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.noarg.gradle
|
||||||
|
|
||||||
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Project
|
||||||
|
|
||||||
|
class KotlinJpaSubplugin : Plugin<Project> {
|
||||||
|
override fun apply(project: Project) {
|
||||||
|
project.plugins.apply(NoArgGradleSubplugin::class.java)
|
||||||
|
val noArgExtension = NoArgGradleSubplugin.getNoArgExtension(project)
|
||||||
|
noArgExtension.annotation("javax.persistence.Entity")
|
||||||
|
}
|
||||||
|
}
|
||||||
+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.noarg.gradle
|
||||||
|
|
||||||
|
open class NoArgExtension {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
+86
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* 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.noarg.gradle
|
||||||
|
|
||||||
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.internal.AbstractTask
|
||||||
|
import org.gradle.api.internal.ConventionTask
|
||||||
|
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 NoArgGradleSubplugin : Plugin<Project> {
|
||||||
|
companion object {
|
||||||
|
fun isEnabled(project: Project) = project.plugins.findPlugin(NoArgGradleSubplugin::class.java) != null
|
||||||
|
|
||||||
|
fun getNoArgExtension(project: Project): NoArgExtension {
|
||||||
|
return project.extensions.getByType(NoArgExtension::class.java)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun apply(project: Project) {
|
||||||
|
val noArgExtension = project.extensions.create("noArg", NoArgExtension::class.java)
|
||||||
|
|
||||||
|
project.afterEvaluate {
|
||||||
|
val fqNamesAsString = noArgExtension.myAnnotations.joinToString(",")
|
||||||
|
project.extensions.extraProperties.set("kotlinNoArgAnnotations", fqNamesAsString)
|
||||||
|
|
||||||
|
open class TaskForAllOpen : AbstractTask()
|
||||||
|
project.tasks.add(project.tasks.create("noArgDataStorageTask", TaskForAllOpen::class.java).apply {
|
||||||
|
isEnabled = false
|
||||||
|
description = "Supported no-arg annotations: " + fqNamesAsString
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class NoArgKotlinGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
|
||||||
|
companion object {
|
||||||
|
val NOARG_GROUP_NAME = "org.jetbrains.kotlin"
|
||||||
|
val NOARG_ARTIFACT_NAME = "kotlin-noarg"
|
||||||
|
|
||||||
|
private 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 (!NoArgGradleSubplugin.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-noarg"
|
||||||
|
override fun getGroupName() = "org.jetbrains.kotlin"
|
||||||
|
override fun getPluginName() = "org.jetbrains.kotlin.noarg"
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
implementation-class=org.jetbrains.kotlin.noarg.gradle.KotlinJpaSubplugin
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
implementation-class=org.jetbrains.kotlin.noarg.gradle.NoArgGradleSubplugin
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
org.jetbrains.kotlin.noarg.gradle.NoArgKotlinGradleSubplugin
|
||||||
Reference in New Issue
Block a user