Skip to content
Permalink
Browse files

Gradle: Gather common Kotlin DSL extension functions in the buildSrc …

…project

Signed-off-by: Sebastian Schuberth <sebastian.schuberth@here.com>
  • Loading branch information...
sschuberth committed Apr 17, 2019
1 parent dc1db48 commit 71c38fc1819e0668eefead0ab696c54fbc5a149f
Showing with 83 additions and 52 deletions.
  1. +1 −1 .gitignore
  2. +2 −19 build.gradle.kts
  3. +22 −0 buildSrc/build.gradle.kts
  4. +54 −0 buildSrc/src/main/kotlin/IdeaExtKotlinDsl.kt
  5. +2 −16 model/build.gradle.kts
  6. +2 −16 spdx-utils/build.gradle.kts
@@ -1,4 +1,4 @@
/.gradle/
.gradle/
.idea/
build/
out/
@@ -1,17 +1,14 @@
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask

import com.here.ort.gradle.*

import io.gitlab.arturbosch.detekt.detekt

import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.plugins.ide.idea.model.IdeaModel
import org.gradle.plugins.ide.idea.model.IdeaProject

import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.gradle.ext.DefaultRunConfigurationContainer
import org.jetbrains.gradle.ext.JUnit
import org.jetbrains.gradle.ext.ProjectSettings
import org.jetbrains.gradle.ext.RunConfiguration
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet

@@ -34,20 +31,6 @@ plugins {
id("org.jetbrains.gradle.plugin.idea-ext")
}

// The following extension functions add the missing Kotlin DSL syntactic sugar for configuring the idea-ext plugin.

fun Project.idea(block: IdeaModel.() -> Unit) =
(this as ExtensionAware).extensions.configure("idea", block)

fun IdeaProject.settings(block: ProjectSettings.() -> Unit) =
(this@settings as ExtensionAware).extensions.configure(block)

fun ProjectSettings.runConfigurations(block: DefaultRunConfigurationContainer.() -> Unit) =
(this@runConfigurations as ExtensionAware).extensions.configure("runConfigurations", block)

inline fun <reified T: RunConfiguration> DefaultRunConfigurationContainer.defaults(noinline block: T.() -> Unit) =
defaults(T::class.java, block)

idea {
project {
settings {
@@ -0,0 +1,22 @@
import java.io.FileInputStream
import java.util.Properties

// Get the root project's properties as extras.
FileInputStream("${rootDir.parentFile}/gradle.properties").use {
Properties().apply { load(it) }.forEach {
extra[it.key.toString()] = it.value.toString()
}
}

plugins {
`kotlin-dsl`
}

repositories {
jcenter()
maven("https://plugins.gradle.org/m2/")
}

dependencies {
compile("gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext:${extra["ideaExtPluginVersion"]}")
}
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2017-2019 HERE Europe B.V.
* Copyright (C) 2010-2019 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.
*
* SPDX-License-Identifier: Apache-2.0
* License-Filename: LICENSE
*/

package com.here.ort.gradle

import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.plugins.ide.idea.model.IdeaModel
import org.gradle.plugins.ide.idea.model.IdeaProject

import org.jetbrains.gradle.ext.DefaultRunConfigurationContainer
import org.jetbrains.gradle.ext.ProjectSettings
import org.jetbrains.gradle.ext.RunConfiguration
import org.jetbrains.gradle.ext.TaskTriggersConfig

// The following extension functions add the missing Kotlin DSL syntactic sugar for nicely configuring the idea-ext
// plugin.

// The code is derived from the one at [1] which is Copyright 2010-2019 JetBrains s.r.o. and governed under the
// Apache 2.0 license.
//
// [1] https://github.com/JetBrains/kotlin/blob/27fd64ed4276f907079f41920fda3c4a6d530b2a/buildSrc/src/main/kotlin/ideaExtKotlinDsl.kt

fun Project.idea(block: IdeaModel.() -> Unit) =
(this as ExtensionAware).extensions.configure("idea", block)

fun IdeaProject.settings(block: ProjectSettings.() -> Unit) =
(this@settings as ExtensionAware).extensions.configure("settings", block)

fun ProjectSettings.taskTriggers(block: TaskTriggersConfig.() -> Unit) =
(this@taskTriggers as ExtensionAware).extensions.configure("taskTriggers", block)

fun ProjectSettings.runConfigurations(block: DefaultRunConfigurationContainer.() -> Unit) =
(this@runConfigurations as ExtensionAware).extensions.configure("runConfigurations", block)

inline fun <reified T: RunConfiguration> DefaultRunConfigurationContainer.defaults(noinline block: T.() -> Unit) =
defaults(T::class.java, block)
@@ -1,10 +1,7 @@
import org.ajoberstar.grgit.Grgit
import com.here.ort.gradle.*

import org.gradle.plugins.ide.idea.model.IdeaModel
import org.gradle.plugins.ide.idea.model.IdeaProject
import org.ajoberstar.grgit.Grgit

import org.jetbrains.gradle.ext.ProjectSettings
import org.jetbrains.gradle.ext.TaskTriggersConfig
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile

val jacksonVersion: String by project
@@ -53,17 +50,6 @@ tasks.withType(KotlinCompile::class) {
dependsOn(generateVersionResource)
}

// The following extension functions add the missing Kotlin DSL syntactic sugar for configuring the idea-ext plugin.

fun Project.idea(block: IdeaModel.() -> Unit) =
(this as ExtensionAware).extensions.configure("idea", block)

fun IdeaProject.settings(block: ProjectSettings.() -> Unit) =
(this@settings as ExtensionAware).extensions.configure(block)

fun ProjectSettings.taskTriggers(block: TaskTriggersConfig.() -> Unit) =
(this@taskTriggers as ExtensionAware).extensions.configure("taskTriggers", block)

rootProject.idea {
project {
settings {
@@ -1,12 +1,9 @@
import at.bxm.gradleplugins.svntools.tasks.SvnExport

import groovy.json.JsonSlurper
import com.here.ort.gradle.*

import org.gradle.plugins.ide.idea.model.IdeaModel
import org.gradle.plugins.ide.idea.model.IdeaProject
import groovy.json.JsonSlurper

import org.jetbrains.gradle.ext.ProjectSettings
import org.jetbrains.gradle.ext.TaskTriggersConfig
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile

import java.io.FileFilter
@@ -35,17 +32,6 @@ tasks.withType(KotlinCompile::class) {
dependsOn(generateGrammarSource)
}

// The following extension functions add the missing Kotlin DSL syntactic sugar for configuring the idea-ext plugin.

fun Project.idea(block: IdeaModel.() -> Unit) =
(this as ExtensionAware).extensions.configure("idea", block)

fun IdeaProject.settings(block: ProjectSettings.() -> Unit) =
(this@settings as ExtensionAware).extensions.configure(block)

fun ProjectSettings.taskTriggers(block: TaskTriggersConfig.() -> Unit) =
(this@taskTriggers as ExtensionAware).extensions.configure("taskTriggers", block)

rootProject.idea {
project {
settings {

0 comments on commit 71c38fc

Please sign in to comment.
You can’t perform that action at this time.