From 52bbbc1815c5fdc60b2c09a871180bf8fc36ad3e Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Fri, 5 May 2017 13:56:25 +0700 Subject: [PATCH] gradle-plugin: Specify compiler version in project properties This patch allows gradle-plugin user to specify a compiler version via project properties. The default version is 0.2. It also updates samples to use this new version of gradle plugin. --- samples/csvparser/build.gradle | 2 +- samples/gitchurn/build.gradle | 2 +- samples/libcurl/build.gradle | 2 +- samples/opengl/build.gradle | 2 +- samples/socket/build.gradle | 2 +- samples/tetris/build.gradle | 2 +- tools/gradle-plugin/build.gradle | 11 ++++--- .../src/main/kotlin/CompilerDownloadTask.kt | 24 ++++++++++++--- .../src/main/kotlin/KonanCompilerConfig.kt | 16 ++++++++++ .../src/main/kotlin/KonanCompilerTask.kt | 19 ++++++++++++ .../src/main/kotlin/KonanInteropConfig.kt | 16 ++++++++++ .../src/main/kotlin/KonanInteropTask.kt | 18 ++++++++++++ .../src/main/kotlin/KonanPlugin.kt | 29 ++++++++++++++++--- .../META-INF/gradle-plugins/konan.properties | 1 - 14 files changed, 125 insertions(+), 21 deletions(-) diff --git a/samples/csvparser/build.gradle b/samples/csvparser/build.gradle index 3b6f236e655..f68e47d9399 100644 --- a/samples/csvparser/build.gradle +++ b/samples/csvparser/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.1" + classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.2" } } diff --git a/samples/gitchurn/build.gradle b/samples/gitchurn/build.gradle index 1dd8c53fc0b..db120f1da70 100644 --- a/samples/gitchurn/build.gradle +++ b/samples/gitchurn/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.1" + classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.2" } } diff --git a/samples/libcurl/build.gradle b/samples/libcurl/build.gradle index 07ebb6bfc2b..73c1a0baceb 100644 --- a/samples/libcurl/build.gradle +++ b/samples/libcurl/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.1" + classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.2" } } diff --git a/samples/opengl/build.gradle b/samples/opengl/build.gradle index b61731ea928..096b845aa0c 100644 --- a/samples/opengl/build.gradle +++ b/samples/opengl/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.1" + classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.2" } } diff --git a/samples/socket/build.gradle b/samples/socket/build.gradle index 8128d7bc6f9..ad47b9f3d27 100644 --- a/samples/socket/build.gradle +++ b/samples/socket/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.1" + classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.2" } } diff --git a/samples/tetris/build.gradle b/samples/tetris/build.gradle index 1fc653f4c94..e9ae9347c56 100644 --- a/samples/tetris/build.gradle +++ b/samples/tetris/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.1" + classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.2" } } diff --git a/tools/gradle-plugin/build.gradle b/tools/gradle-plugin/build.gradle index 6b2f4c5d6e8..d06f85abc21 100644 --- a/tools/gradle-plugin/build.gradle +++ b/tools/gradle-plugin/build.gradle @@ -68,7 +68,7 @@ publishing { artifact jar groupId 'org.jetbrains.kotlin' artifactId 'kotlin-native-gradle-plugin' - version '0.1' + version '0.2' pom.withXml { XmlProvider xml -> def stdlibDep = xml.asNode().appendNode("dependencies").appendNode("dependency") stdlibDep.appendNode("groupId", "org.jetbrains.kotlin") @@ -87,12 +87,11 @@ bintray { repo = 'kotlin-native-dependencies' name = 'kotlin-native-gradle-plugin' userOrg = 'jetbrains' - // TODO: Specify license and github path - //licenses = ['Apache-2.0'] - //vcsUrl = 'https://github.com/...' + licenses = ['Apache-2.0'] + vcsUrl = 'https://github.com/JetBrains/kotlin-native' version { - name = '0.1' - desc = 'Kotlin Native Gradle plugin 0.1' + name = '0.2' + desc = 'Kotlin Native Gradle plugin 0.2' } publish = true // project.hasProperty("publish") override = project.hasProperty("override") diff --git a/tools/gradle-plugin/src/main/kotlin/CompilerDownloadTask.kt b/tools/gradle-plugin/src/main/kotlin/CompilerDownloadTask.kt index 8d1ac58f93f..e76989dbb20 100644 --- a/tools/gradle-plugin/src/main/kotlin/CompilerDownloadTask.kt +++ b/tools/gradle-plugin/src/main/kotlin/CompilerDownloadTask.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2017 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.plugin import org.gradle.api.DefaultTask @@ -11,7 +27,6 @@ open class CompilerDownloadTask: DefaultTask() { internal companion object { internal const val DOWNLOAD_URL = "http://download.jetbrains.com/kotlin/native" - internal val KONAN_NAME = "kotlin-native-${simpleOsName()}-${KonanPlugin.KONAN_VERSION}" private val KONAN_PARENT_DIR = "${System.getProperty("user.home")}/.konan" internal fun simpleOsName(): String { @@ -32,9 +47,10 @@ open class CompilerDownloadTask: DefaultTask() { return } try { - logger.info("Downloading Kotlin Native compiler from $DOWNLOAD_URL into $KONAN_PARENT_DIR") - DependencyDownloader(File(KONAN_PARENT_DIR), DOWNLOAD_URL, listOf(KONAN_NAME)).run() - project.extensions.extraProperties.set(KonanPlugin.KONAN_HOME_PROPERTY_NAME, "$KONAN_PARENT_DIR/$KONAN_NAME") + val konanCompiler = "kotlin-native-${simpleOsName()}-${project.konanVersion}" + logger.info("Downloading Kotlin Native compiler from $DOWNLOAD_URL/$konanCompiler into $KONAN_PARENT_DIR") + DependencyDownloader(File(KONAN_PARENT_DIR), DOWNLOAD_URL, listOf(konanCompiler)).run() + project.extensions.extraProperties.set(KonanPlugin.KONAN_HOME_PROPERTY_NAME, "$KONAN_PARENT_DIR/$konanCompiler") } catch (e: RuntimeException) { throw GradleScriptException("Cannot download Kotlin Native compiler", e) } diff --git a/tools/gradle-plugin/src/main/kotlin/KonanCompilerConfig.kt b/tools/gradle-plugin/src/main/kotlin/KonanCompilerConfig.kt index 0d1d2d6f94d..e7259c49e20 100644 --- a/tools/gradle-plugin/src/main/kotlin/KonanCompilerConfig.kt +++ b/tools/gradle-plugin/src/main/kotlin/KonanCompilerConfig.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2017 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.plugin import org.gradle.api.Named diff --git a/tools/gradle-plugin/src/main/kotlin/KonanCompilerTask.kt b/tools/gradle-plugin/src/main/kotlin/KonanCompilerTask.kt index a4be7207658..5c4ba8e93f8 100644 --- a/tools/gradle-plugin/src/main/kotlin/KonanCompilerTask.kt +++ b/tools/gradle-plugin/src/main/kotlin/KonanCompilerTask.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2017 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.plugin import org.gradle.api.DefaultTask @@ -63,6 +79,9 @@ open class KonanCompileTask: DefaultTask() { @Optional @Input var apiVersion : String? = null internal set + // TODO: Is there a better way to rerun tasks when the compiler version changes? + @Input val konanVersion = project.konanVersion + // Task action ------------------------------------------------------------ protected fun buildArgs() = mutableListOf().apply { diff --git a/tools/gradle-plugin/src/main/kotlin/KonanInteropConfig.kt b/tools/gradle-plugin/src/main/kotlin/KonanInteropConfig.kt index cfde3a1e383..7cfeac29671 100644 --- a/tools/gradle-plugin/src/main/kotlin/KonanInteropConfig.kt +++ b/tools/gradle-plugin/src/main/kotlin/KonanInteropConfig.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2017 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.plugin import org.gradle.api.Named diff --git a/tools/gradle-plugin/src/main/kotlin/KonanInteropTask.kt b/tools/gradle-plugin/src/main/kotlin/KonanInteropTask.kt index c78058b0ba0..44cc105f98c 100644 --- a/tools/gradle-plugin/src/main/kotlin/KonanInteropTask.kt +++ b/tools/gradle-plugin/src/main/kotlin/KonanInteropTask.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2017 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.plugin import org.gradle.api.DefaultTask @@ -51,6 +67,8 @@ open class KonanInteropTask: DefaultTask() { @InputFiles val headers = mutableSetOf() @InputFiles val linkFiles = mutableSetOf() + @Input val konanVersion = project.konanVersion + @TaskAction fun exec() { project.javaexec { diff --git a/tools/gradle-plugin/src/main/kotlin/KonanPlugin.kt b/tools/gradle-plugin/src/main/kotlin/KonanPlugin.kt index a7bbf30387c..1d437e1a650 100644 --- a/tools/gradle-plugin/src/main/kotlin/KonanPlugin.kt +++ b/tools/gradle-plugin/src/main/kotlin/KonanPlugin.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2017 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.plugin import org.gradle.api.DefaultTask @@ -11,7 +27,8 @@ import org.gradle.internal.reflect.Instantiator /** * We use the follwing properties: - * kotlin.native.home - directory where compiler is located (aka dist in konan project output) + * konan.home - directory where compiler is located (aka dist in konan project output). + * konan.version - a konan compiler version for downloading. */ // konanHome extension is set by downloadKonanCompiler task. @@ -33,6 +50,9 @@ internal val Project.konanInteropContainer: KonanInteropContainer internal val Project.konanCompilerDownloadTask get() = tasks.getByName(KonanPlugin.KONAN_DOWNLOAD_TASK_NAME) +internal val Project.konanVersion + get() = findProperty(KonanPlugin.KONAN_VERSION_PROPERTY_NAME) as String? ?: KonanPlugin.DEFAULT_KONAN_VERSION + class KonanArtifactsContainer(val project: ProjectInternal): AbstractNamedDomainObjectContainer( KonanCompilerConfig::class.java, project.gradle.services.get(Instantiator::class.java)) { @@ -91,11 +111,12 @@ class KonanPlugin: Plugin { companion object { internal const val COMPILER_EXTENSION_NAME = "konanArtifacts" internal const val INTEROP_EXTENSION_NAME = "konanInterop" - internal const val KONAN_HOME_PROPERTY_NAME = "konan.home" internal const val KONAN_DOWNLOAD_TASK_NAME = "downloadKonanCompiler" - // TODO: Move in config. - internal const val KONAN_VERSION = "0.1" + internal const val KONAN_HOME_PROPERTY_NAME = "konan.home" + internal const val KONAN_VERSION_PROPERTY_NAME = "konan.version" + + internal const val DEFAULT_KONAN_VERSION = "0.2" } /** diff --git a/tools/gradle-plugin/src/main/resources/META-INF/gradle-plugins/konan.properties b/tools/gradle-plugin/src/main/resources/META-INF/gradle-plugins/konan.properties index 368d15f832e..7275083968d 100644 --- a/tools/gradle-plugin/src/main/resources/META-INF/gradle-plugins/konan.properties +++ b/tools/gradle-plugin/src/main/resources/META-INF/gradle-plugins/konan.properties @@ -1,2 +1 @@ -# TODO: find a good name for the plugin implementation-class=org.jetbrains.kotlin.gradle.plugin.KonanPlugin \ No newline at end of file