From a22e5d446b5e9b7063aec5685c8da88327e91410 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Thu, 1 Dec 2016 22:54:03 +0300 Subject: [PATCH] NoArg: Add Maven plugin --- libraries/pom.xml | 1 + libraries/tools/kotlin-maven-noarg/pom.xml | 131 ++++++++++++++++++ .../main/kotlin/NoArgMavenPluginExtensions.kt | 60 ++++++++ .../src/it/test-noarg-jpa/pom.xml | 84 +++++++++++ .../it/test-noarg-jpa/src/main/kotlin/test.kt | 22 +++ .../src/test/java/test/NoArgSimpleTest.java | 30 ++++ .../src/it/test-noarg-jpa/verify.bsh | 6 + .../src/it/test-noarg-simple/pom.xml | 88 ++++++++++++ .../test-noarg-simple/src/main/kotlin/test.kt | 22 +++ .../src/test/java/test/NoArgSimpleTest.java | 29 ++++ .../src/it/test-noarg-simple/verify.bsh | 6 + 11 files changed, 479 insertions(+) create mode 100755 libraries/tools/kotlin-maven-noarg/pom.xml create mode 100644 libraries/tools/kotlin-maven-noarg/src/main/kotlin/NoArgMavenPluginExtensions.kt create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-jpa/pom.xml create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-jpa/src/main/kotlin/test.kt create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-jpa/src/test/java/test/NoArgSimpleTest.java create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-jpa/verify.bsh create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-simple/pom.xml create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-simple/src/main/kotlin/test.kt create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-simple/src/test/java/test/NoArgSimpleTest.java create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-simple/verify.bsh diff --git a/libraries/pom.xml b/libraries/pom.xml index 0a6b58e90b6..1909abec532 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -103,6 +103,7 @@ tools/kotlin-allopen tools/kotlin-maven-allopen tools/kotlin-noarg + tools/kotlin-maven-noarg tools/kotlin-gradle-plugin tools/kotlin-gradle-plugin-api diff --git a/libraries/tools/kotlin-maven-noarg/pom.xml b/libraries/tools/kotlin-maven-noarg/pom.xml new file mode 100755 index 00000000000..2fc29ea603b --- /dev/null +++ b/libraries/tools/kotlin-maven-noarg/pom.xml @@ -0,0 +1,131 @@ + + + + 4.0.0 + + 3.0.5 + ${basedir}/../../../plugins/noarg/noarg-cli/src + ${basedir}/src/main/kotlin + ${basedir}/src/main/resources + ${basedir}/target/src/main/kotlin + ${basedir}/target/resource + + + + org.jetbrains.kotlin + kotlin-project + 1.1-SNAPSHOT + ../../pom.xml + + + kotlin-maven-noarg + jar + + All-open plugin for Maven + + + + jetbrains-utils + http://repository.jetbrains.com/utils + + + + + + org.jetbrains.kotlin + kotlin-stdlib + ${project.version} + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${project.version} + provided + + + + + ${noarg.target-src} + + + ${noarg.target-resources} + + + + + + maven-resources-plugin + 3.0.0 + + + copy-sources + validate + + copy-resources + + + ${noarg.target-src} + + ${noarg.src} + ${noarg.maven.plugin.src} + + + + + copy-resources + validate + + copy-resources + + + ${noarg.target-resources}/META-INF + + ${noarg.src}/META-INF + ${noarg.maven.plugin.resources}/META-INF + + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${project.version} + + + + compile + compile + compile + + + ${noarg.target-src} + + + + + + + org.codehaus.plexus + plexus-component-metadata + 1.7.1 + + + process-classes + + generate-metadata + + + + process-test-classes + + generate-test-metadata + + + + + + + diff --git a/libraries/tools/kotlin-maven-noarg/src/main/kotlin/NoArgMavenPluginExtensions.kt b/libraries/tools/kotlin-maven-noarg/src/main/kotlin/NoArgMavenPluginExtensions.kt new file mode 100644 index 00000000000..c9e108dffbc --- /dev/null +++ b/libraries/tools/kotlin-maven-noarg/src/main/kotlin/NoArgMavenPluginExtensions.kt @@ -0,0 +1,60 @@ +/* + * 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.test + +import org.apache.maven.plugin.* +import org.apache.maven.project.* +import org.codehaus.plexus.component.annotations.* +import org.codehaus.plexus.logging.* +import org.jetbrains.kotlin.maven.* + +val NOARG_COMPILER_PLUGIN_ID = "org.jetbrains.kotlin.noarg" + +@Component(role = KotlinMavenPluginExtension::class, hint = "no-arg") +class KotlinNoArgMavenPluginExtension : KotlinMavenPluginExtension { + @Requirement + lateinit var logger: Logger + + override fun getCompilerPluginId() = NOARG_COMPILER_PLUGIN_ID + + override fun isApplicable(project: MavenProject, execution: MojoExecution) = true + + override fun getPluginOptions(project: MavenProject, execution: MojoExecution): List { + logger.debug("Loaded Maven plugin " + javaClass.name) + return emptyList() + } +} + +@Component(role = KotlinMavenPluginExtension::class, hint = "jpa") +class KotlinJpaMavenPluginExtension : KotlinMavenPluginExtension { + private companion object { + val ANNOTATIONS_ARG_NAME = "annotation" + val JPA_ANNOTATIONS = listOf("javax.persistence.Entity") + } + + override fun getCompilerPluginId() = NOARG_COMPILER_PLUGIN_ID + + @Requirement + lateinit var logger: Logger + + override fun isApplicable(project: MavenProject, execution: MojoExecution) = true + + override fun getPluginOptions(project: MavenProject, execution: MojoExecution): List { + logger.debug("Loaded Maven plugin " + javaClass.name) + return JPA_ANNOTATIONS.map { PluginOption(NOARG_COMPILER_PLUGIN_ID, ANNOTATIONS_ARG_NAME, it) } + } +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-jpa/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-jpa/pom.xml new file mode 100644 index 00000000000..0ba70c88cad --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-jpa/pom.xml @@ -0,0 +1,84 @@ + + + 4.0.0 + + org.jetbrains.kotlin + test-noarg-jpa + 1.0-SNAPSHOT + + + + junit + junit + 4.9 + + + org.jetbrains.kotlin + kotlin-runtime + ${kotlin.version} + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-source-plugin + 2.1.2 + + + + + ${project.basedir}/src/main/kotlin + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + compile + process-sources + + compile + + + + test-compile + process-test-sources + + test-compile + + + + + + + jpa + + + + + + org.jetbrains.kotlin + kotlin-maven-noarg + ${kotlin.version} + + + + + + + \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-jpa/src/main/kotlin/test.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-jpa/src/main/kotlin/test.kt new file mode 100644 index 00000000000..33188f92381 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-jpa/src/main/kotlin/test.kt @@ -0,0 +1,22 @@ +/* + * 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 javax.persistence + +annotation class Entity + +@Entity +class NoArgClass(val a: String) \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-jpa/src/test/java/test/NoArgSimpleTest.java b/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-jpa/src/test/java/test/NoArgSimpleTest.java new file mode 100644 index 00000000000..b2950ba35e6 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-jpa/src/test/java/test/NoArgSimpleTest.java @@ -0,0 +1,30 @@ +/* + * 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 test; + +import org.junit.Test; + +import static junit.framework.Assert.assertEquals; +import java.lang.reflect.Modifier; +import javax.persistence.NoArgClass; + +public class NoArgSimpleTest { + @Test + public void greeting() { + assertEquals(2, NoArgClass.class.getDeclaredConstructors().length); + } +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-jpa/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-jpa/verify.bsh new file mode 100644 index 00000000000..e31932aa2a1 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-jpa/verify.bsh @@ -0,0 +1,6 @@ +import java.io.*; + +File file = new File(basedir, "target/test-noarg-jpa-1.0-SNAPSHOT.jar"); +if (!file.exists() || !file.isFile()) { + throw new FileNotFoundException("Could not find generated JAR: " + file); +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-simple/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-simple/pom.xml new file mode 100644 index 00000000000..2327af3c3c5 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-simple/pom.xml @@ -0,0 +1,88 @@ + + + 4.0.0 + + org.jetbrains.kotlin + test-noarg-simple + 1.0-SNAPSHOT + + + + junit + junit + 4.9 + + + org.jetbrains.kotlin + kotlin-runtime + ${kotlin.version} + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-source-plugin + 2.1.2 + + + + + ${project.basedir}/src/main/kotlin + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + compile + process-sources + + compile + + + + test-compile + process-test-sources + + test-compile + + + + + + + no-arg + + + + + + + + + + org.jetbrains.kotlin + kotlin-maven-noarg + ${kotlin.version} + + + + + + + \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-simple/src/main/kotlin/test.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-simple/src/main/kotlin/test.kt new file mode 100644 index 00000000000..99c2d46ceef --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-simple/src/main/kotlin/test.kt @@ -0,0 +1,22 @@ +/* + * 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 test + +annotation class NoArg + +@NoArg +class NoArgClass(val a: String) \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-simple/src/test/java/test/NoArgSimpleTest.java b/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-simple/src/test/java/test/NoArgSimpleTest.java new file mode 100644 index 00000000000..167f74a9bd5 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-simple/src/test/java/test/NoArgSimpleTest.java @@ -0,0 +1,29 @@ +/* + * 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 test; + +import org.junit.Test; + +import static junit.framework.Assert.assertEquals; +import java.lang.reflect.Modifier; + +public class NoArgSimpleTest { + @Test + public void greeting() { + assertEquals(2, NoArgClass.class.getDeclaredConstructors().length); + } +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-simple/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-simple/verify.bsh new file mode 100644 index 00000000000..8197bf3ebc1 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-noarg-simple/verify.bsh @@ -0,0 +1,6 @@ +import java.io.*; + +File file = new File(basedir, "target/test-noarg-simple-1.0-SNAPSHOT.jar"); +if (!file.exists() || !file.isFile()) { + throw new FileNotFoundException("Could not find generated JAR: " + file); +}