Add Gradle plugin to project
This commit is contained in:
+9
-11
@@ -1,19 +1,17 @@
|
|||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "1.3.60" apply false
|
kotlin("jvm") version "1.3.60" apply false
|
||||||
id("org.jetbrains.dokka") version "0.10.0" apply false
|
id("org.jetbrains.dokka") version "0.10.0" apply false
|
||||||
id("nebula.release") version "13.1.1"
|
id("com.gradle.plugin-publish") version "0.10.1" apply false
|
||||||
}
|
}
|
||||||
|
|
||||||
val release = tasks.findByPath(":release")
|
|
||||||
release?.finalizedBy(project.getTasksByName("publish", true))
|
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = "com.bnorm.power"
|
group = "com.bnorm.power"
|
||||||
|
version = "0.1.0-SNAPSHOT"
|
||||||
}
|
}
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
kotlin.code.style=official
|
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("java-gradle-plugin")
|
||||||
|
kotlin("jvm")
|
||||||
|
kotlin("kapt")
|
||||||
|
|
||||||
|
id("com.gradle.plugin-publish")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(kotlin("stdlib"))
|
||||||
|
implementation(kotlin("gradle-plugin-api"))
|
||||||
|
|
||||||
|
kapt("com.google.auto.service:auto-service:1.0-rc6")
|
||||||
|
compileOnly("com.google.auto.service:auto-service-annotations:1.0-rc6")
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginBundle {
|
||||||
|
website = "https://github.com/bnorm/kotlin-power-assert"
|
||||||
|
vcsUrl = "https://github.com/bnorm/kotlin-power-assert.git"
|
||||||
|
tags = listOf("kotlin", "power-assert")
|
||||||
|
}
|
||||||
|
|
||||||
|
gradlePlugin {
|
||||||
|
plugins {
|
||||||
|
create("kotlinPowerAssert") {
|
||||||
|
id = "com.bnorm.power.kotlin-power-assert"
|
||||||
|
displayName = "Kotlin Power Assertion Plugin"
|
||||||
|
description = "Kotlin Compiler Plugin to add power to your assertions"
|
||||||
|
implementationClass = "com.bnorm.power.PowerAssertGradlePlugin"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType<KotlinCompile> {
|
||||||
|
kotlinOptions.jvmTarget = "1.8"
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register("publish") {
|
||||||
|
dependsOn("publishPlugins")
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Brian Norman
|
||||||
|
*
|
||||||
|
* 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 com.bnorm.power
|
||||||
|
|
||||||
|
open class PowerAssertGradleExtension {
|
||||||
|
var enabled: Boolean = true
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Brian Norman
|
||||||
|
*
|
||||||
|
* 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 com.bnorm.power
|
||||||
|
|
||||||
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Project
|
||||||
|
|
||||||
|
class PowerAssertGradlePlugin : Plugin<Project> {
|
||||||
|
override fun apply(project: Project): Unit = with(project) {
|
||||||
|
extensions.create("kotlinPowerAssert", PowerAssertGradleExtension::class.java)
|
||||||
|
}
|
||||||
|
}
|
||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Brian Norman
|
||||||
|
*
|
||||||
|
* 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 com.bnorm.power
|
||||||
|
|
||||||
|
import com.google.auto.service.AutoService
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.tasks.compile.AbstractCompile
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
|
||||||
|
|
||||||
|
@AutoService(KotlinGradleSubplugin::class)
|
||||||
|
class PowerAssertGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
|
||||||
|
|
||||||
|
override fun getCompilerPluginId(): String = "com.bnorm.kotlin-power-assert"
|
||||||
|
|
||||||
|
override fun isApplicable(project: Project, task: AbstractCompile): Boolean =
|
||||||
|
project.plugins.hasPlugin(PowerAssertGradlePlugin::class.java)
|
||||||
|
|
||||||
|
|
||||||
|
override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact(
|
||||||
|
groupId = "com.bnorm.power",
|
||||||
|
artifactId = "kotlin-power-assert",
|
||||||
|
version = "0.1.0-SNAPSHOT"
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun apply(
|
||||||
|
project: Project,
|
||||||
|
kotlinCompile: AbstractCompile,
|
||||||
|
javaCompile: AbstractCompile?,
|
||||||
|
variantData: Any?,
|
||||||
|
androidProjectHandler: Any?,
|
||||||
|
kotlinCompilation: KotlinCompilation<KotlinCommonOptions>?
|
||||||
|
): List<SubpluginOption> {
|
||||||
|
val extension = project.extensions.findByType(PowerAssertGradleExtension::class.java)
|
||||||
|
?: PowerAssertGradleExtension()
|
||||||
|
|
||||||
|
return listOf(
|
||||||
|
SubpluginOption(key = "enabled", value = extension.enabled.toString())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,7 +49,7 @@ tasks.register("dokkaJar", Jar::class) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
signing {
|
signing {
|
||||||
setRequired(provider { gradle.taskGraph.hasTask("release") })
|
setRequired(provider { gradle.taskGraph.hasTask("publish") })
|
||||||
sign(publishing.publications)
|
sign(publishing.publications)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
|
|||||||
import org.jetbrains.kotlin.ir.expressions.IrGetValue
|
import org.jetbrains.kotlin.ir.expressions.IrGetValue
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrStringConcatenationImpl
|
|
||||||
import org.jetbrains.kotlin.ir.types.getClass
|
import org.jetbrains.kotlin.ir.types.getClass
|
||||||
import org.jetbrains.kotlin.ir.util.functions
|
import org.jetbrains.kotlin.ir.util.functions
|
||||||
import org.jetbrains.kotlin.ir.util.getPackageFragment
|
import org.jetbrains.kotlin.ir.util.getPackageFragment
|
||||||
@@ -74,6 +73,7 @@ class PowerAssertCallTransformer(
|
|||||||
private lateinit var file: IrFile
|
private lateinit var file: IrFile
|
||||||
private lateinit var fileSource: String
|
private lateinit var fileSource: String
|
||||||
|
|
||||||
|
// TODO this is the only thing keeping this project from being multiplatform
|
||||||
private val constructor = this@PowerAssertCallTransformer.context.ir.symbols.assertionErrorConstructor
|
private val constructor = this@PowerAssertCallTransformer.context.ir.symbols.assertionErrorConstructor
|
||||||
|
|
||||||
override fun lower(irFile: IrFile) {
|
override fun lower(irFile: IrFile) {
|
||||||
@@ -138,7 +138,7 @@ class PowerAssertCallTransformer(
|
|||||||
require(assertCondition is IrGetValue)
|
require(assertCondition is IrGetValue)
|
||||||
|
|
||||||
// print(buildString {
|
// print(buildString {
|
||||||
// append(callSource).newline()
|
// append(callSource).appendln()
|
||||||
// val sorted = stack.sortedBy { it.indentation }
|
// val sorted = stack.sortedBy { it.indentation }
|
||||||
//
|
//
|
||||||
// val indentations = sorted.map { it.indentation }
|
// val indentations = sorted.map { it.indentation }
|
||||||
@@ -149,7 +149,7 @@ class PowerAssertCallTransformer(
|
|||||||
// }
|
// }
|
||||||
// last = i
|
// last = i
|
||||||
// }
|
// }
|
||||||
// newline()
|
// appendln()
|
||||||
//
|
//
|
||||||
// for (tmp in sorted.asReversed()) {
|
// for (tmp in sorted.asReversed()) {
|
||||||
//
|
//
|
||||||
@@ -163,7 +163,7 @@ class PowerAssertCallTransformer(
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// indent(tmp.indentation - last - 1)
|
// indent(tmp.indentation - last - 1)
|
||||||
// append(tmp.source).newline()
|
// append(tmp.source).appendln()
|
||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
|
|
||||||
@@ -190,8 +190,8 @@ class PowerAssertCallTransformer(
|
|||||||
val indentations = sorted.map { it.indentation }
|
val indentations = sorted.map { it.indentation }
|
||||||
|
|
||||||
addArgument(irString(buildString {
|
addArgument(irString(buildString {
|
||||||
newline()
|
appendln()
|
||||||
append(callSource).newline()
|
append(callSource).appendln()
|
||||||
var last = -1
|
var last = -1
|
||||||
for (i in indentations) {
|
for (i in indentations) {
|
||||||
if (i > last) {
|
if (i > last) {
|
||||||
@@ -205,7 +205,7 @@ class PowerAssertCallTransformer(
|
|||||||
for (tmp in sorted.asReversed()) {
|
for (tmp in sorted.asReversed()) {
|
||||||
addArgument(irString(buildString {
|
addArgument(irString(buildString {
|
||||||
var last = -1
|
var last = -1
|
||||||
newline()
|
appendln()
|
||||||
for (i in indentations) {
|
for (i in indentations) {
|
||||||
if (i == tmp.indentation) break
|
if (i == tmp.indentation) break
|
||||||
if (i > last) {
|
if (i > last) {
|
||||||
@@ -233,12 +233,4 @@ fun IrFile.info(expression: IrElement): SourceRangeInfo {
|
|||||||
return fileEntry.getSourceRangeInfo(expression.startOffset, expression.endOffset)
|
return fileEntry.getSourceRangeInfo(expression.startOffset, expression.endOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun StringBuilder.indent(indentation: Int) = apply {
|
fun StringBuilder.indent(indentation: Int): StringBuilder = append(" ".repeat(indentation))
|
||||||
repeat(indentation) {
|
|
||||||
append(" ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun StringBuilder.newline() = apply {
|
|
||||||
append("\n")
|
|
||||||
}
|
|
||||||
|
|||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Brian Norman
|
||||||
|
*
|
||||||
|
* 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 com.bnorm.power
|
||||||
|
|
||||||
|
import com.google.auto.service.AutoService
|
||||||
|
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
|
||||||
|
import org.jetbrains.kotlin.compiler.plugin.CliOption
|
||||||
|
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
|
||||||
|
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||||
|
|
||||||
|
@AutoService(CommandLineProcessor::class)
|
||||||
|
class PowerAssertCommandLineProcessor : CommandLineProcessor {
|
||||||
|
override val pluginId: String = "com.bnorm.kotlin-power-assert"
|
||||||
|
|
||||||
|
override val pluginOptions: Collection<CliOption> = listOf(
|
||||||
|
CliOption(
|
||||||
|
optionName = "enabled",
|
||||||
|
valueDescription = "<true|false>",
|
||||||
|
description = "whether to enable the kotlin-power-assert plugin or not"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun processOption(
|
||||||
|
option: AbstractCliOption,
|
||||||
|
value: String,
|
||||||
|
configuration: CompilerConfiguration
|
||||||
|
) {
|
||||||
|
return when (option.optionName) {
|
||||||
|
"enabled" -> configuration.put(KEY_ENABLED, value.toBoolean())
|
||||||
|
else -> error("Unexpected config option ${option.optionName}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,9 @@ import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
|
|||||||
import org.jetbrains.kotlin.com.intellij.mock.MockProject
|
import org.jetbrains.kotlin.com.intellij.mock.MockProject
|
||||||
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||||
|
import org.jetbrains.kotlin.config.CompilerConfigurationKey
|
||||||
|
|
||||||
|
val KEY_ENABLED = CompilerConfigurationKey<Boolean>("whether the plugin is enabled")
|
||||||
|
|
||||||
@AutoService(ComponentRegistrar::class)
|
@AutoService(ComponentRegistrar::class)
|
||||||
class PowerAssertComponentRegistrar : ComponentRegistrar {
|
class PowerAssertComponentRegistrar : ComponentRegistrar {
|
||||||
@@ -28,6 +31,9 @@ class PowerAssertComponentRegistrar : ComponentRegistrar {
|
|||||||
project: MockProject,
|
project: MockProject,
|
||||||
configuration: CompilerConfiguration
|
configuration: CompilerConfiguration
|
||||||
) {
|
) {
|
||||||
|
if (configuration[KEY_ENABLED] == false) {
|
||||||
|
return
|
||||||
|
}
|
||||||
IrGenerationExtension.registerExtension(project, PowerAssertIrGenerationExtension())
|
IrGenerationExtension.registerExtension(project, PowerAssertIrGenerationExtension())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
rootProject.name = "kotlin-power-assert"
|
rootProject.name = "kotlin-power-assert"
|
||||||
|
|
||||||
include(":kotlin-power-assert")
|
include(":kotlin-power-assert")
|
||||||
|
include(":kotlin-power-assert-gradle")
|
||||||
|
|||||||
Reference in New Issue
Block a user