diff --git a/build.gradle.kts b/build.gradle.kts index 6acecd1..071bb76 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -71,9 +71,6 @@ 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() } @@ -81,17 +78,23 @@ repositories { 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" + } } } diff --git a/src/main/kotlin/com/intershop/gradle/icm/ICMBasePlugin.kt b/src/main/kotlin/com/intershop/gradle/icm/ICMBasePlugin.kt new file mode 100644 index 0000000..83c03e6 --- /dev/null +++ b/src/main/kotlin/com/intershop/gradle/icm/ICMBasePlugin.kt @@ -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 { + + 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") ) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/intershop/gradle/icm/ICMBuildPlugin.kt b/src/main/kotlin/com/intershop/gradle/icm/ICMBuildPlugin.kt index 9f9cace..a53e836 100644 --- a/src/main/kotlin/com/intershop/gradle/icm/ICMBuildPlugin.kt +++ b/src/main/kotlin/com/intershop/gradle/icm/ICMBuildPlugin.kt @@ -45,12 +45,9 @@ class ICMBuildPlugin : Plugin { 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 @@ -65,9 +62,6 @@ class ICMBuildPlugin : Plugin { val icmserver = configurations.maybeCreate("icmserver") icmserver.setTransitive(false) - configurations.maybeCreate("runtimeLib") - configurations.maybeCreate("dockerRuntimeLib") - configureCreateServerInfoPropertiesTask(project, extension) rootProject.subprojects.forEach { prj -> @@ -87,11 +81,11 @@ class ICMBuildPlugin : Plugin { 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) } diff --git a/src/main/kotlin/com/intershop/gradle/icm/ICMTestPlugin.kt b/src/main/kotlin/com/intershop/gradle/icm/ICMTestPlugin.kt index 604bdbc..9826098 100644 --- a/src/main/kotlin/com/intershop/gradle/icm/ICMTestPlugin.kt +++ b/src/main/kotlin/com/intershop/gradle/icm/ICMTestPlugin.kt @@ -25,6 +25,8 @@ class ICMTestPlugin : Plugin { override fun apply(project: Project) { with(project) { + logger.info( "ICM test plugin will be initialized" ) + tasks.maybeCreate("ishUnitTest", ISHUnitTest::class.java) } diff --git a/src/main/kotlin/com/intershop/gradle/icm/extension/BaseConfiguration.kt b/src/main/kotlin/com/intershop/gradle/icm/extension/BaseConfiguration.kt new file mode 100644 index 0000000..db9c995 --- /dev/null +++ b/src/main/kotlin/com/intershop/gradle/icm/extension/BaseConfiguration.kt @@ -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 = project.objects.property(String::class.java) + private val runtimeVersionProperty: Property = 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 + get() = runtimeModuleProperty + + /** + * Runtime module of ICM base project. + */ + var runtimeModule by runtimeModuleProperty + + /** + * Runtime module property provider of ICM base project. + */ + val runtimeVersionProvider: Provider + get() = runtimeVersionProperty + + /** + * Runtime module of ICM base project. + */ + var runtimeVersion by runtimeVersionProperty +} \ No newline at end of file diff --git a/src/main/kotlin/com/intershop/gradle/icm/extension/IntershopExtension.kt b/src/main/kotlin/com/intershop/gradle/icm/extension/IntershopExtension.kt index 3e09837..d8d0ab3 100644 --- a/src/main/kotlin/com/intershop/gradle/icm/extension/IntershopExtension.kt +++ b/src/main/kotlin/com/intershop/gradle/icm/extension/IntershopExtension.kt @@ -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. @@ -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. @@ -53,4 +52,23 @@ open class IntershopExtension(var project: Project) { fun projectInfo(action: Action) { 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) { + 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) { + action.execute(baseConfig) + } } diff --git a/src/main/kotlin/com/intershop/gradle/icm/extension/ProjectInfo.kt b/src/main/kotlin/com/intershop/gradle/icm/extension/ProjectInfo.kt index fe4dd78..a1b4415 100644 --- a/src/main/kotlin/com/intershop/gradle/icm/extension/ProjectInfo.kt +++ b/src/main/kotlin/com/intershop/gradle/icm/extension/ProjectInfo.kt @@ -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 Property.setValue(receiver: Any?, property: KProperty<*>, value: T) = set(value) -/** - * Add a get function to a String property. - */ -operator fun Property.getValue(receiver: Any?, property: KProperty<*>): T = get() /** * Extension for server info properties. @@ -41,11 +33,6 @@ open class ProjectInfo(project: Project) { private val copyrightFromProperty: Property = project.objects.property(String::class.java) private val organizationProperty: Property = 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") diff --git a/src/main/kotlin/com/intershop/gradle/icm/tasks/CopyThirdpartyLibs.kt b/src/main/kotlin/com/intershop/gradle/icm/tasks/CopyThirdpartyLibs.kt index fa19e30..1d9a308 100644 --- a/src/main/kotlin/com/intershop/gradle/icm/tasks/CopyThirdpartyLibs.kt +++ b/src/main/kotlin/com/intershop/gradle/icm/tasks/CopyThirdpartyLibs.kt @@ -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' diff --git a/src/main/kotlin/com/intershop/gradle/icm/tasks/CreateServerInfoProperties.kt b/src/main/kotlin/com/intershop/gradle/icm/tasks/CreateServerInfoProperties.kt index c067fb0..c0ffe9f 100644 --- a/src/main/kotlin/com/intershop/gradle/icm/tasks/CreateServerInfoProperties.kt +++ b/src/main/kotlin/com/intershop/gradle/icm/tasks/CreateServerInfoProperties.kt @@ -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. diff --git a/src/main/kotlin/com/intershop/gradle/icm/tasks/WriteCartridgeClasspath.kt b/src/main/kotlin/com/intershop/gradle/icm/tasks/WriteCartridgeClasspath.kt index 51f17cf..dc8f1f5 100644 --- a/src/main/kotlin/com/intershop/gradle/icm/tasks/WriteCartridgeClasspath.kt +++ b/src/main/kotlin/com/intershop/gradle/icm/tasks/WriteCartridgeClasspath.kt @@ -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 diff --git a/src/main/kotlin/com/intershop/gradle/icm/tasks/WriteCartridgeDescriptor.kt b/src/main/kotlin/com/intershop/gradle/icm/tasks/WriteCartridgeDescriptor.kt index ed0fc41..e81943a 100644 --- a/src/main/kotlin/com/intershop/gradle/icm/tasks/WriteCartridgeDescriptor.kt +++ b/src/main/kotlin/com/intershop/gradle/icm/tasks/WriteCartridgeDescriptor.kt @@ -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 diff --git a/src/main/kotlin/com/intershop/gradle/icm/utils/OsCheck.kt b/src/main/kotlin/com/intershop/gradle/icm/utils/OsCheck.kt new file mode 100644 index 0000000..2118950 --- /dev/null +++ b/src/main/kotlin/com/intershop/gradle/icm/utils/OsCheck.kt @@ -0,0 +1,53 @@ +/* + * 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.utils + +import java.util.Locale + +object OsCheck { + + /** + * types of Operating Systems + */ + enum class OSType { + Windows, MacOS, Linux, Other + } + + private lateinit var detectedOS: OSType + + /** + * detect the operating system from the os.name System property and cache + * the result + * + * @returns - the operating system detected + */ + init { + val OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH) + if (OS.indexOf("mac") >= 0 || OS.indexOf("darwin") >= 0) { + detectedOS = OSType.MacOS + } else if (OS.indexOf("win") >= 0) { + detectedOS = OSType.Windows + } else if (OS.indexOf("nux") >= 0) { + detectedOS = OSType.Linux + } else { + detectedOS = OSType.Other + } + } + + fun getDetectedOS() = detectedOS +} \ No newline at end of file diff --git a/src/main/kotlin/com/intershop/gradle/icm/Utils.kt b/src/main/kotlin/com/intershop/gradle/icm/utils/Utils.kt similarity index 97% rename from src/main/kotlin/com/intershop/gradle/icm/Utils.kt rename to src/main/kotlin/com/intershop/gradle/icm/utils/Utils.kt index 2ca3df9..a412f75 100644 --- a/src/main/kotlin/com/intershop/gradle/icm/Utils.kt +++ b/src/main/kotlin/com/intershop/gradle/icm/utils/Utils.kt @@ -15,7 +15,7 @@ * */ -package com.intershop.gradle.icm +package com.intershop.gradle.icm.utils import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.Property