From 2f001ca696899444039a81a30bf3ae89800fc257 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 18 Mar 2015 14:29:19 +0300 Subject: [PATCH] Pack built-ins metadata to kotlin-runtime Maven artifact This fixes reflection usage against Maven's kotlin-reflect --- .../tools/kotlin-maven-plugin-test/pom.xml | 2 +- .../src/it/test-reflection/pom.xml | 75 +++++++++++++++++++ .../src/main/kotlin/main/main.kt | 43 +++++++++++ .../src/test/java/test/ReflectionTest.java | 28 +++++++ .../src/it/test-reflection/verify.bsh | 7 ++ libraries/tools/runtime/pom.xml | 15 +++- 6 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-reflection/pom.xml create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-reflection/src/main/kotlin/main/main.kt create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-reflection/src/test/java/test/ReflectionTest.java create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-reflection/verify.bsh diff --git a/libraries/tools/kotlin-maven-plugin-test/pom.xml b/libraries/tools/kotlin-maven-plugin-test/pom.xml index 07a1c534634..bf79fe0dbcd 100644 --- a/libraries/tools/kotlin-maven-plugin-test/pom.xml +++ b/libraries/tools/kotlin-maven-plugin-test/pom.xml @@ -20,7 +20,7 @@ org.jetbrains.kotlin - kotlin-runtime + kotlin-reflect ${project.version} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-reflection/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-reflection/pom.xml new file mode 100644 index 00000000000..bfd2865873d --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-reflection/pom.xml @@ -0,0 +1,75 @@ + + + 4.0.0 + + + org.jetbrains.kotlin + kotlin-project + 0.1-SNAPSHOT + ../../pom.xml + + + test-reflection + + + + junit + junit + 4.9 + + + org.jetbrains.kotlin + kotlin-reflect + ${project.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 + ${project.version} + + + compile + process-sources + + compile + + + + test-compile + process-test-sources + + test-compile + + + + + + + + \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-reflection/src/main/kotlin/main/main.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-reflection/src/main/kotlin/main/main.kt new file mode 100644 index 00000000000..c9fe7bd5e53 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-reflection/src/main/kotlin/main/main.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2010-2015 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 main + +fun topLevelFun() {} + +class A(val prop: String) + +val Int.extProp: Int get() = this + +fun box(): String { + val u = ::topLevelFun + u() + + fun localFun() {} + val l = ::localFun + l() + + val ext = Int::extProp + if (ext.get(42) != 42) return "Fail ext: ${ext[42]}" + + val a = A::class + if (a.properties.size() != 1) return "Fail: ${a.properties}" + + val p = A::prop + if (p.name != "prop") return "Fail name: ${p.name}" + + return p.get(A("OK")) +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-reflection/src/test/java/test/ReflectionTest.java b/libraries/tools/kotlin-maven-plugin-test/src/it/test-reflection/src/test/java/test/ReflectionTest.java new file mode 100644 index 00000000000..d4aa2907451 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-reflection/src/test/java/test/ReflectionTest.java @@ -0,0 +1,28 @@ +/* + * Copyright 2010-2015 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; + +import org.junit.Test; + +import static junit.framework.Assert.assertEquals; + +public class ReflectionTest { + @Test + public void testClasspath() { + assertEquals("OK", main.MainPackage.box()); + } +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-reflection/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/test-reflection/verify.bsh new file mode 100644 index 00000000000..c8879ea3ce6 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-reflection/verify.bsh @@ -0,0 +1,7 @@ +import java.io.*; +import java.net.*; + +File file = new File(basedir, "target/test-reflection-0.1-SNAPSHOT.jar"); +if (!file.exists() || !file.isFile()) { + throw new FileNotFoundException("Could not find generated JAR: " + file); +} diff --git a/libraries/tools/runtime/pom.xml b/libraries/tools/runtime/pom.xml index dbf820ad450..eebeebaefff 100644 --- a/libraries/tools/runtime/pom.xml +++ b/libraries/tools/runtime/pom.xml @@ -18,6 +18,19 @@ target/copied-sources + + + ${basedir}/../../../dist/builtins + + **/*.kotlin_* + + + kotlin/reflect/**/* + kotlin/internal/**/* + + + + org.apache.maven.plugins @@ -30,7 +43,7 @@ process-sources - +