diff --git a/libraries/examples/annotation-processor-example/pom.xml b/libraries/examples/annotation-processor-example/pom.xml index 21bfd8ae5a2..324fb3ba6f9 100644 --- a/libraries/examples/annotation-processor-example/pom.xml +++ b/libraries/examples/annotation-processor-example/pom.xml @@ -26,7 +26,6 @@ org.jetbrains.kotlin kotlin-stdlib ${project.version} - provided diff --git a/libraries/examples/annotation-processor-example/src/main/kotlin/example/ExampleAnnotationProcessor.kt b/libraries/examples/annotation-processor-example/src/main/kotlin/example/ExampleAnnotationProcessor.kt index e1e85cf75ed..99a387e2c39 100644 --- a/libraries/examples/annotation-processor-example/src/main/kotlin/example/ExampleAnnotationProcessor.kt +++ b/libraries/examples/annotation-processor-example/src/main/kotlin/example/ExampleAnnotationProcessor.kt @@ -45,7 +45,7 @@ class ExampleAnnotationProcessor : AbstractProcessor() { val simpleName = element.simpleName.toString() val generatedJavaClassName = generatedFilePrefix.capitalize() + simpleName.capitalize() + generatedFileSuffix - filer.createSourceFile(generatedJavaClassName).openWriter().use { with(it) { + filer.createSourceFile(packageName + '.' + generatedJavaClassName).openWriter().use { with(it) { appendln("package $packageName;") appendln("public final class $generatedJavaClassName {}") }} diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt index a858679fc91..00bf19f3f0c 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt @@ -72,8 +72,14 @@ abstract class BaseGradleIT { val androidHome: File? = null, val androidGradlePluginVersion: String? = null) - open inner class Project(val projectName: String, val wrapperVersion: String, val minLogLevel: LogLevel = LogLevel.DEBUG) { - open val resourcesRoot = File(resourcesRootFile, "testProject/$projectName") + open inner class Project( + val projectName: String, + val wrapperVersion: String, + directoryPrefix: String? = null, + val minLogLevel: LogLevel = LogLevel.DEBUG + ) { + val resourceDirName = if (directoryPrefix != null) "$directoryPrefix/$projectName" else projectName + open val resourcesRoot = File(resourcesRootFile, "testProject/$resourceDirName") val projectDir = File(workingDir.canonicalFile, projectName) open fun setupWorkingDir() { diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseIncrementalGradleIT.kt b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseIncrementalGradleIT.kt index 4b220b5cbd7..4d5d4c68f46 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseIncrementalGradleIT.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseIncrementalGradleIT.kt @@ -10,7 +10,7 @@ import kotlin.test.assertEquals abstract class BaseIncrementalGradleIT : BaseGradleIT() { - inner class JpsTestProject(val buildLogFinder: BuildLogFinder, val resourcesBase: File, val relPath: String, wrapperVersion: String = "2.10", minLogLevel: LogLevel = LogLevel.DEBUG) : Project(File(relPath).name, wrapperVersion, minLogLevel) { + inner class JpsTestProject(val buildLogFinder: BuildLogFinder, val resourcesBase: File, val relPath: String, wrapperVersion: String = "2.10", minLogLevel: LogLevel = LogLevel.DEBUG) : Project(File(relPath).name, wrapperVersion, null, minLogLevel) { override val resourcesRoot = File(resourcesBase, relPath) val mapWorkingToOriginalFile = hashMapOf() diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/Kapt2IT.kt b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/Kapt2IT.kt new file mode 100644 index 00000000000..30b77a862c2 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/Kapt2IT.kt @@ -0,0 +1,142 @@ +/* + * 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.gradle + +import org.junit.Test +import java.io.File +import java.io.FileFilter + +class Kapt2IT: BaseGradleIT() { + companion object { + private const val GRADLE_VERSION = "2.10" + private const val ANDROID_GRADLE_PLUGIN_VERSION = "1.5.+" + } + + private fun androidBuildOptions() = + BuildOptions(withDaemon = true, + androidHome = File("../../../dependencies/android-sdk-for-tests"), + androidGradlePluginVersion = ANDROID_GRADLE_PLUGIN_VERSION) + + override fun defaultBuildOptions(): BuildOptions = + super.defaultBuildOptions().copy(withDaemon = true) + + private fun CompiledProject.assertKaptSuccessful() { + assertContains("Kapt: Annotation processing complete, 0 errors, 0 warnings") + } + + @Test + fun testSimple() { + val project = Project("simple", GRADLE_VERSION, directoryPrefix = "kapt2") + + project.build("build") { + assertSuccessful() + assertKaptSuccessful() + assertContains(":compileKotlin") + assertContains(":compileJava") + assertFileExists("build/generated/source/kapt2/main/example/TestClassGenerated.java") + assertFileExists("build/classes/main/example/TestClass.class") + assertFileExists("build/classes/main/example/TestClassGenerated.class") + assertFileExists("build/classes/main/example/SourceAnnotatedTestClassGenerated.class") + assertFileExists("build/classes/main/example/BinaryAnnotatedTestClassGenerated.class") + assertFileExists("build/classes/main/example/RuntimeAnnotatedTestClassGenerated.class") + assertContains("example.JavaTest PASSED") + } + + project.build("build") { + assertSuccessful() + assertContains(":compileKotlin UP-TO-DATE") + assertContains(":compileJava UP-TO-DATE") + } + } + + @Test + fun testInheritedAnnotations() { + Project("inheritedAnnotations", GRADLE_VERSION, directoryPrefix = "kapt2").build("build") { + assertSuccessful() + assertKaptSuccessful() + assertFileExists("build/generated/source/kapt2/main/example/TestClassGenerated.java") + assertFileExists("build/generated/source/kapt2/main/example/AncestorClassGenerated.java") + assertFileExists("build/classes/main/example/TestClassGenerated.class") + assertFileExists("build/classes/main/example/AncestorClassGenerated.class") + } + } + + @Test + fun testButterKnife() { + val project = Project("android-butterknife", GRADLE_VERSION, directoryPrefix = "kapt2") + val options = androidBuildOptions() + + project.build("assembleRelease", options = options) { + assertSuccessful() + assertKaptSuccessful() + assertFileExists("app/build/generated/source/kapt2/release/org/example/kotlin/butterknife/SimpleActivity\$\$ViewBinder.java") + assertFileExists("app/build/intermediates/classes/release/org/example/kotlin/butterknife/SimpleActivity\$\$ViewBinder.class") + assertFileExists("app/build/intermediates/classes/release/org/example/kotlin/butterknife/SimpleAdapter\$ViewHolder.class") + } + + project.build("assembleRelease", options = options) { + assertSuccessful() + assertContains(":compileReleaseKotlin UP-TO-DATE") + assertContains(":compileReleaseJavaWithJavac UP-TO-DATE") + } + } + + @Test + fun testDagger() { + val project = Project("android-dagger", GRADLE_VERSION, directoryPrefix = "kapt2") + val options = androidBuildOptions() + + project.build("assembleRelease", options = options) { + assertSuccessful() + assertKaptSuccessful() + assertFileExists("app/build/generated/source/kapt2/release/com/example/dagger/kotlin/DaggerApplicationComponent.java") + assertFileExists("app/build/generated/source/kapt2/release/com/example/dagger/kotlin/ui/HomeActivity_MembersInjector.java") + assertFileExists("app/build/intermediates/classes/release/com/example/dagger/kotlin/DaggerApplicationComponent.class") + assertFileExists("app/build/intermediates/classes/release/com/example/dagger/kotlin/AndroidModule.class") + } + } + + @Test + fun testDbFlow() { + val project = Project("android-dbflow", GRADLE_VERSION, directoryPrefix = "kapt2") + val options = androidBuildOptions() + + project.build("assembleRelease", options = options) { + assertSuccessful() + assertKaptSuccessful() + assertFileExists("app/build/generated/source/kapt2/release/com/raizlabs/android/dbflow/config/GeneratedDatabaseHolder.java") + assertFileExists("app/build/generated/source/kapt2/release/com/raizlabs/android/dbflow/config/AppDatabaseapp_Database.java") + assertFileExists("app/build/generated/source/kapt2/release/mobi/porquenao/poc/kotlin/core/Item_Table.java") + assertFileExists("app/build/generated/source/kapt2/release/mobi/porquenao/poc/kotlin/core/Item_Adapter.java") + } + } + + @Test + fun testRealm() { + val project = Project("android-realm", GRADLE_VERSION, directoryPrefix = "kapt2") + val options = androidBuildOptions() + + project.build("assembleRelease", options = options) { + assertSuccessful() + assertKaptSuccessful() + assertFileExists("build/generated/source/kapt2/release/io/realm/CatRealmProxy.java") + assertFileExists("build/generated/source/kapt2/release/io/realm/CatRealmProxyInterface.java") + assertFileExists("build/generated/source/kapt2/release/io/realm/DefaultRealmModule.java") + assertFileExists("build/generated/source/kapt2/release/io/realm/DefaultRealmModuleMediator.java") + } + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/KaptIT.kt b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/KaptIT.kt index 1af3c993f89..1a57da8d82e 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/KaptIT.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/KaptIT.kt @@ -24,7 +24,7 @@ class KaptIT: BaseGradleIT() { assertContains(":compileKotlin") assertContains(":compileJava") assertFileExists("build/tmp/kapt/main/wrappers/annotations.main.txt") - assertFileExists("build/generated/source/kapt/main/TestClassGenerated.java") + assertFileExists("build/generated/source/kapt/main/example/TestClassGenerated.java") assertFileExists("build/classes/main/example/TestClass.class") assertFileExists("build/classes/main/example/TestClassGenerated.class") assertNoSuchFile("build/classes/main/example/SourceAnnotatedTestClassGenerated.class") @@ -162,8 +162,8 @@ class KaptIT: BaseGradleIT() { fun testInheritedAnnotations() { Project("kaptInheritedAnnotations", GRADLE_VERSION).build("build") { assertSuccessful() - assertFileExists("build/generated/source/kapt/main/TestClassGenerated.java") - assertFileExists("build/generated/source/kapt/main/AncestorClassGenerated.java") + assertFileExists("build/generated/source/kapt/main/example/TestClassGenerated.java") + assertFileExists("build/generated/source/kapt/main/example/AncestorClassGenerated.java") assertFileExists("build/classes/main/example/TestClassGenerated.class") assertFileExists("build/classes/main/example/AncestorClassGenerated.class") } diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/build.gradle b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/build.gradle new file mode 100644 index 00000000000..7618cfd15fa --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/build.gradle @@ -0,0 +1,37 @@ +apply plugin: 'android-sdk-manager' +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-kapt' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.1" + + defaultConfig { + applicationId "org.example.kotlin.butterknife" + minSdkVersion 15 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + + compile 'com.android.support:appcompat-v7:23.3.0' + compile 'com.jakewharton:butterknife:8.0.1' + kapt 'com.jakewharton:butterknife-compiler:8.0.1' + compile "org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT" +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/proguard-rules.pro b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/proguard-rules.pro new file mode 100644 index 00000000000..2193714bb6b --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/yan/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/src/main/AndroidManifest.xml b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..1861dbb21b2 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/src/main/java/org/example/kotlin/butterknife/SimpleActivity.kt b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/src/main/java/org/example/kotlin/butterknife/SimpleActivity.kt new file mode 100644 index 00000000000..99dfae1ccb9 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/src/main/java/org/example/kotlin/butterknife/SimpleActivity.kt @@ -0,0 +1,84 @@ +package org.example.kotlin.butterknife + +import android.app.Activity +import android.os.Bundle +import android.view.View +import android.view.animation.AlphaAnimation +import android.widget.Button +import android.widget.ListView +import android.widget.TextView +import android.widget.Toast + +import android.widget.Toast.LENGTH_SHORT +import butterknife.* + +class SimpleActivity : Activity() { + + @BindView(R.id.title) + lateinit var title: TextView + + @BindView(R.id.subtitle) + lateinit var subtitle: TextView + + @BindView(R.id.hello) + lateinit var hello: Button + + @BindView(R.id.list_of_things) + lateinit var listOfThings: ListView + + @BindView(R.id.footer) + lateinit var footer: TextView + + @BindViews(R.id.title, R.id.subtitle, R.id.hello) + lateinit var headerViews: MutableList + + @JvmField + @BindColor(R.color.blue) + var titleTextColor: Int = 0 + + private lateinit var adapter: SimpleAdapter + + @OnClick(R.id.hello) + fun sayHello() { + Toast.makeText(this, "Hello, views!", LENGTH_SHORT).show() + ButterKnife.apply(headerViews.toList(), ALPHA_FADE) + } + + @OnLongClick(R.id.hello) + fun sayGetOffMe(): Boolean { + Toast.makeText(this, "Let go of me!", LENGTH_SHORT).show() + return true + } + + @OnItemClick(R.id.list_of_things) + fun onItemClick(position: Int) { + Toast.makeText(this, "You clicked: " + adapter.getItem(position), LENGTH_SHORT).show() + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.simple_activity) + ButterKnife.bind(this) + + title.text = "Butter Knife" + subtitle.text = "Field and method binding for Android views." + footer.text = "by Jake Wharton" + hello.text = "Say Hello" + + title.setTextColor(titleTextColor) + + adapter = SimpleAdapter(this) + listOfThings.adapter = adapter + } + + companion object { + private val ALPHA_FADE = ButterKnife.Action { view, index -> + with (AlphaAnimation(0f, 1f)) { + fillBefore = true + duration = 500 + startOffset = (index * 100).toLong() + view.startAnimation(this) + } + } + } +} diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/src/main/java/org/example/kotlin/butterknife/SimpleAdapter.kt b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/src/main/java/org/example/kotlin/butterknife/SimpleAdapter.kt new file mode 100644 index 00000000000..37dd5b37531 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/src/main/java/org/example/kotlin/butterknife/SimpleAdapter.kt @@ -0,0 +1,57 @@ +package org.example.kotlin.butterknife + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.BaseAdapter +import android.widget.TextView +import butterknife.ButterKnife +import butterknife.BindView + +class SimpleAdapter(context: Context) : BaseAdapter() { + + private val inflater = LayoutInflater.from(context) + + override fun getCount() = CONTENTS.size + override fun getItem(position: Int) = CONTENTS[position] + override fun getItemId(position: Int) = position.toLong() + + override fun getView(position: Int, v: View?, parent: ViewGroup): View { + var view = v + val holder: ViewHolder + if (view != null) { + holder = view.tag as ViewHolder + } else { + view = inflater.inflate(R.layout.simple_list_item, parent, false) + holder = ViewHolder(view) + view!!.tag = holder + } + + val word = getItem(position) + holder.word.text = "Word: $word" + holder.length.text = "Length: ${word.length}" + holder.position.text = "Position: $position" + + return view + } + + class ViewHolder(view: View) { + @BindView(R.id.word) + lateinit var word: TextView + + @BindView(R.id.length) + lateinit var length: TextView + + @BindView(R.id.position) + lateinit var position: TextView + + init { + ButterKnife.bind(this, view) + } + } + + companion object { + private val CONTENTS = "The quick brown fox jumps over the lazy dog".split(" ") + } +} diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/src/main/java/org/example/kotlin/butterknife/SimpleApp.kt b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/src/main/java/org/example/kotlin/butterknife/SimpleApp.kt new file mode 100644 index 00000000000..a603ab880ee --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/src/main/java/org/example/kotlin/butterknife/SimpleApp.kt @@ -0,0 +1,11 @@ +package org.example.kotlin.butterknife + +import android.app.Application +import butterknife.ButterKnife + +class SimpleApp : Application() { + override fun onCreate() { + super.onCreate() + ButterKnife.setDebug(BuildConfig.DEBUG) + } +} diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/src/main/res/layout/simple_activity.xml b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/src/main/res/layout/simple_activity.xml new file mode 100644 index 00000000000..f214de7841f --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kapt2/android-butterknife/app/src/main/res/layout/simple_activity.xml @@ -0,0 +1,44 @@ + + + + + +