Skip to content

Commit

Permalink
add base plugin
Browse files Browse the repository at this point in the history
code style fixes
package moved
  • Loading branch information
m-raab committed Sep 12, 2019
1 parent 5dd11b0 commit dc845ae
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 47 deletions.
13 changes: 8 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,30 @@ description = "Intershop Commerce Management Build Plugin"

version = scm.version.version

val pluginIdICMPlugin = "com.intershop.gradle.icm"
val pluginIdICMTestPlugin = "com.intershop.gradle.icm.ishunittest"

repositories {
mavenCentral()
}

gradlePlugin {
plugins {
create("icmPlugin") {
id = pluginIdICMPlugin
id = "com.intershop.gradle.icm"
implementationClass = "com.intershop.gradle.icm.ICMBuildPlugin"
displayName = project.name
description = project.description
}
create("icmTestPlugin") {
id = pluginIdICMTestPlugin
id = "com.intershop.gradle.icm.ishunittest"
implementationClass = "com.intershop.gradle.icm.ICMTestPlugin"
displayName = "icm-test-plugin"
description = "This plugin should be applied to test projects with ishunit tests"
}
create("icmBaseProjectPlugin") {
id = "com.intershop.gradle.icm.ishbuild"
implementationClass = "com.intershop.gradle.icm.ICMBaselugin"
displayName = "icm-base-plugin"
description = "This plugin should be applied to the original Intershop Commerce Management base product project"
}
}
}

Expand Down
90 changes: 90 additions & 0 deletions src/main/kotlin/com/intershop/gradle/icm/ICMBasePlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright 2019 Intershop Communications AG.
*
* 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.intershop.gradle.icm

import com.intershop.gradle.icm.extension.IntershopExtension
import com.intershop.gradle.icm.utils.OsCheck
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.tasks.Copy
import java.io.File

class ICMBasePlugin : Plugin<Project> {

private lateinit var runtimeLibConfiguration: Configuration

override fun apply(project: Project) {
with(project) {
if(project.rootProject == this) {
logger.info("ICM base project plugin will be initialized")

val extension = extensions.findByType(
IntershopExtension::class.java
) ?: extensions.create(
IntershopExtension.INTERSHOP_EXTENSION_NAME, IntershopExtension::class.java, this
)

addRuntimeDependencies(project, extension)


tasks.maybeCreate("installRuntimeLib", Copy::class.java).apply {
from(runtimeLibConfiguration)

rename("(.*).dll", "ish-runtime.dll")
rename("(.*).so", "libish-runtime.so")
rename("(.*).dylib", "libish-runtime.dylib")
rename("(.*).setpgid", "setpgid")

into(File(project.buildDir, "runtime-lib"))
}
}
}
}

private fun addRuntimeDependencies(project: Project, extension: IntershopExtension) {
val dependencyBase = "${extension.baseConfig.runtimeModule}:${extension.baseConfig.runtimeVersion}"
val dependencyHandler = project.dependencies

runtimeLibConfiguration = project.configurations.maybeCreate("runtimeLib")
.setTransitive(false)
.setDescription("Configuration for native runtime library")
.defaultDependencies {


if(OsCheck.getDetectedOS() == OsCheck.OSType.MacOS) {
it.add( dependencyHandler.create("${dependencyBase}:darwin@dylib") )
it.add( dependencyHandler.create("${dependencyBase}:darwin@setpgid") )
}
if(OsCheck.getDetectedOS() == OsCheck.OSType.Linux) {
it.add( dependencyHandler.create("${dependencyBase}:linux@so") )
it.add( dependencyHandler.create("${dependencyBase}:linux@setpgid") )
}
if(OsCheck.getDetectedOS() == OsCheck.OSType.Windows) {
it.add( dependencyHandler.create("${dependencyBase}:win32@dll") )
}
}

project.configurations.maybeCreate("dockerRuntimeLib")
.setTransitive(false)
.setDescription("Configuration for native runtime library used with Docker")
.defaultDependencies {
it.add( dependencyHandler.create("${dependencyBase}:darwin@dylib") )
it.add( dependencyHandler.create("${dependencyBase}:darwin@setpgid") )
}
}
}
16 changes: 5 additions & 11 deletions src/main/kotlin/com/intershop/gradle/icm/ICMBuildPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ class ICMBuildPlugin : Plugin<Project> {

override fun apply(project: Project) {
with(project) {
if(project.rootProject == project) {
logger.info(
"ICM build plugin adds extension {} to {}",
IntershopExtension.INTERSHOP_EXTENSION_NAME,
name
)
if(project.rootProject == this) {

logger.info( "ICM build plugin will be initialized" )

val extension = extensions.findByType(
IntershopExtension::class.java
Expand All @@ -65,9 +62,6 @@ class ICMBuildPlugin : Plugin<Project> {
val icmserver = configurations.maybeCreate("icmserver")
icmserver.setTransitive(false)

configurations.maybeCreate("runtimeLib")
configurations.maybeCreate("dockerRuntimeLib")

configureCreateServerInfoPropertiesTask(project, extension)

rootProject.subprojects.forEach { prj ->
Expand All @@ -87,11 +81,11 @@ class ICMBuildPlugin : Plugin<Project> {
cartridgeRuntime.setTransitive(true)

prj.tasks.maybeCreate("copyThirdpartyLibs", CopyThirdpartyLibs::class.java)
var descriptorTask = prj.tasks.maybeCreate("writeCartridgeDescriptor",
prj.tasks.maybeCreate("writeCartridgeDescriptor",
WriteCartridgeDescriptor::class.java).apply {
dependsOn(cartridge, cartridgeRuntime)
}
var classpathTask = prj.tasks.maybeCreate("writeCartridgeClasspath",
prj.tasks.maybeCreate("writeCartridgeClasspath",
WriteCartridgeClasspath::class.java).apply {
dependsOn(cartridgeRuntime, runtime)
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/com/intershop/gradle/icm/ICMTestPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ICMTestPlugin : Plugin<Project> {

override fun apply(project: Project) {
with(project) {
logger.info( "ICM test plugin will be initialized" )

tasks.maybeCreate("ishUnitTest", ISHUnitTest::class.java)

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2019 Intershop Communications AG.
*
* 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.intershop.gradle.icm.extension

import com.intershop.gradle.icm.utils.getValue
import com.intershop.gradle.icm.utils.setValue
import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider

class BaseConfiguration(project: Project) {

private val runtimeModuleProperty: Property<String> = project.objects.property(String::class.java)
private val runtimeVersionProperty: Property<String> = project.objects.property(String::class.java)

init {
runtimeModuleProperty.set("com.intershop.platform.lib:runtime-lib")
runtimeVersionProperty.set("1.0.0")
}

/**
* Runtime module property provider of ICM base project.
*/
val runtimeModuleProvider: Provider<String>
get() = runtimeModuleProperty

/**
* Runtime module of ICM base project.
*/
var runtimeModule by runtimeModuleProperty

/**
* Runtime module property provider of ICM base project.
*/
val runtimeVersionProvider: Provider<String>
get() = runtimeVersionProperty

/**
* Runtime module of ICM base project.
*/
var runtimeVersion by runtimeVersionProperty
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ package com.intershop.gradle.icm.extension

import groovy.lang.Closure
import org.gradle.api.Action
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.util.ConfigureUtil

/**
* Extension for ICM properties.
Expand All @@ -30,10 +28,11 @@ open class IntershopExtension(var project: Project) {
companion object {
// names for the plugin
const val INTERSHOP_EXTENSION_NAME = "intershop"
const val INTERSHOP_GROUP_NAME = "Intershop Commerce Management build plugin"
const val INTERSHOP_GROUP_NAME = "Intershop Commerce Management Plugins"
}

val projectInfo: ProjectInfo = ProjectInfo(project)
val baseConfig: BaseConfiguration = BaseConfiguration(project)

/**
* Configures the project information configuration.
Expand All @@ -53,4 +52,23 @@ open class IntershopExtension(var project: Project) {
fun projectInfo(action: Action<in ProjectInfo>) {
action.execute(projectInfo)
}

/**
* Configures the base project of Intershop Commerce Management.
*
* @param closure closure with base project configuration of Intershop Commerce Management
*/
@Suppress("unused")
fun baseConfig(closure: Closure<Any>) {
project.configure(baseConfig, closure)
}

/**
* Configures the base project of Intershop Commerce Management.
*
* @param action action with base project configuration of Intershop Commerce Management
*/
fun baseConfig(action: Action<in BaseConfiguration>) {
action.execute(baseConfig)
}
}
17 changes: 2 additions & 15 deletions src/main/kotlin/com/intershop/gradle/icm/extension/ProjectInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,11 @@
*/
package com.intershop.gradle.icm.extension

import com.intershop.gradle.icm.utils.getValue
import com.intershop.gradle.icm.utils.setValue
import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import kotlin.reflect.KProperty

/**
* Add a set function to a String property.
*/
operator fun <T> Property<T>.setValue(receiver: Any?, property: KProperty<*>, value: T) = set(value)
/**
* Add a get function to a String property.
*/
operator fun <T> Property<T>.getValue(receiver: Any?, property: KProperty<*>): T = get()

/**
* Extension for server info properties.
Expand All @@ -41,11 +33,6 @@ open class ProjectInfo(project: Project) {
private val copyrightFromProperty: Property<String> = project.objects.property(String::class.java)
private val organizationProperty: Property<String> = project.objects.property(String::class.java)

companion object {
// name of the extension
const val EXTENSION_NAME = "icmProjectinfo"
}

init {
productIDProperty.set("ICM")
productNameProperty.set("Intershop Commerce Management 7")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.internal.component.external.model.DefaultModuleComponentArtifactIdentifier
import java.io.File
import java.util.stream.Collectors
import java.util.stream.Stream

/**
* CopyThirdpartyLibs Gradle task 'copyThirdpartyLibs'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import java.io.File
import java.io.IOException
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import com.intershop.gradle.icm.setValue
import com.intershop.gradle.icm.getValue
import com.intershop.gradle.icm.utils.setValue
import com.intershop.gradle.icm.utils.getValue

/**
* Task for the creation of server info properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,17 @@
package com.intershop.gradle.icm.tasks

import com.intershop.gradle.icm.ICMBuildPlugin
import com.intershop.gradle.icm.getValue
import com.intershop.gradle.icm.setValue
import com.intershop.gradle.icm.utils.getValue
import com.intershop.gradle.icm.utils.setValue
import org.gradle.api.DefaultTask
import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
import org.gradle.api.file.FileCollection
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Classpath
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.TaskAction
import java.io.File

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package com.intershop.gradle.icm.tasks

import com.intershop.gradle.icm.ICMBuildPlugin
import com.intershop.gradle.icm.getValue
import com.intershop.gradle.icm.setValue
import com.intershop.gradle.icm.utils.getValue
import com.intershop.gradle.icm.utils.setValue
import groovy.util.XmlSlurper
import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
Expand Down
Loading

0 comments on commit dc845ae

Please sign in to comment.