Skip to content

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
Signed-off-by: Yauheni Khnykin <[email protected]>
  • Loading branch information
Hsilgos committed Dec 25, 2023
1 parent 64c1609 commit a27a153
Show file tree
Hide file tree
Showing 237 changed files with 4,597 additions and 3,931 deletions.
4 changes: 2 additions & 2 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ buildscript {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.13.0"
classpath "com.diffplug.spotless:spotless-plugin-gradle:5.10.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.21.0"
classpath "com.diffplug.spotless:spotless-plugin-gradle:6.22.0"

modules {
module("org.jetbrains.trove4j:trove4j") {
Expand All @@ -35,7 +35,7 @@ buildscript {
}
}
plugins {
id 'nebula.lint' version '16.9.0'
id 'nebula.lint' version '18.1.0'
}

allprojects {
Expand All @@ -61,12 +61,12 @@ allprojects {
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "17"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "17"
}
}

Expand Down
6 changes: 3 additions & 3 deletions functional-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"
classpath 'com.android.tools.build:gradle:8.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20"

def gluecodiumVersion = project.hasProperty('gluecodiumVersion')
? project.property('gluecodiumVersion').toString().trim() : '+'

classpath "com.here.gluecodium:gluecodium-gradle:${gluecodiumVersion}"
classpath 'com.diffplug.spotless:spotless-plugin-gradle:5.10.2'
classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.22.0'

modules {
module("org.jetbrains.trove4j:trove4j") {
Expand Down
2 changes: 2 additions & 0 deletions functional-tests/functional/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ android {
ndkVersion rootProject.ndkVersion
compileSdkVersion rootProject.compileSdkVersion

namespace 'com.here.gluecodium.test.functional'

defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
Expand Down
1 change: 1 addition & 0 deletions functional-tests/namerules/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def getCMakeCommonParameters() {
android {
ndkVersion rootProject.ndkVersion
compileSdkVersion rootProject.compileSdkVersion
namespace 'com.here.gluecodium.test.namerules'

defaultConfig {
minSdkVersion rootProject.minSdkVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,104 +35,116 @@ import org.gradle.api.plugins.JavaPluginConvention
import java.io.File
import javax.inject.Inject

class GluecodiumPlugin @Inject constructor(private val objectFactory: ObjectFactory) : Plugin<Project> {

override fun apply(project: Project) {
val gluecodiumExtension =
project.extensions.create(GLUECODIUM_EXTENSION_NAME, GluecodiumExtension::class.java)

val javaGenerator: String
if (project.pluginManager.hasPlugin("com.android.base")) {
javaGenerator = "android"
applyAndroid(project, gluecodiumExtension)
} else {
javaGenerator = "java"
applyJava(project, gluecodiumExtension)
}
class GluecodiumPlugin
@Inject
constructor(private val objectFactory: ObjectFactory) : Plugin<Project> {
override fun apply(project: Project) {
val gluecodiumExtension =
project.extensions.create(GLUECODIUM_EXTENSION_NAME, GluecodiumExtension::class.java)

val javaGenerator: String
if (project.pluginManager.hasPlugin("com.android.base")) {
javaGenerator = "android"
applyAndroid(project, gluecodiumExtension)
} else {
javaGenerator = "java"
applyJava(project, gluecodiumExtension)
}

project.tasks.register(GLUECODIUM_TASK_NAME, GluecodiumTask::class.java) {
it.description = "Processes Gluecodium IDL files"
it.javaGenerator = javaGenerator
propagateExtensionProperties(it, gluecodiumExtension)
project.tasks.register(GLUECODIUM_TASK_NAME, GluecodiumTask::class.java) {
it.description = "Processes Gluecodium IDL files"
it.javaGenerator = javaGenerator
propagateExtensionProperties(it, gluecodiumExtension)
}
}
}

private fun applyAndroid(project: Project, gluecodiumExtension: GluecodiumExtension) {
val androidExtension = project.extensions.getByName("android") as BaseExtension
private fun applyAndroid(
project: Project,
gluecodiumExtension: GluecodiumExtension,
) {
val androidExtension = project.extensions.getByName("android") as BaseExtension

val sourceSets = androidExtension.sourceSets
sourceSets.forEach { it.java.srcDir(gluecodiumExtension.outputDirectory) }
setDefaultGluecodiumSources(project, gluecodiumExtension, sourceSets.map { it.name })
val sourceSets = androidExtension.sourceSets
sourceSets.forEach { it.java.srcDir(gluecodiumExtension.outputDirectory) }
setDefaultGluecodiumSources(project, gluecodiumExtension, sourceSets.map { it.name })

project.afterEvaluate { injectGluecodiumTask(androidExtension) }
}

private fun applyJava(project: Project, gluecodiumExtension: GluecodiumExtension) {
project.pluginManager.apply(JavaPlugin::class.java)

val sourceSets = project.convention.getPlugin(JavaPluginConvention::class.java)
.sourceSets
.filterIsInstance<DefaultSourceSet>()
sourceSets.forEach { it.java.srcDir(gluecodiumExtension.outputDirectory) }
setDefaultGluecodiumSources(project, gluecodiumExtension, sourceSets.map { it.name })
project.afterEvaluate { injectGluecodiumTask(androidExtension) }
}

sourceSets.forEach { sourceSet ->
project.tasks.named(sourceSet.compileJavaTaskName) { compileTask ->
compileTask.dependsOn(GLUECODIUM_TASK_NAME)
private fun applyJava(
project: Project,
gluecodiumExtension: GluecodiumExtension,
) {
project.pluginManager.apply(JavaPlugin::class.java)

val sourceSets =
project.convention.getPlugin(JavaPluginConvention::class.java)
.sourceSets
.filterIsInstance<DefaultSourceSet>()
sourceSets.forEach { it.java.srcDir(gluecodiumExtension.outputDirectory) }
setDefaultGluecodiumSources(project, gluecodiumExtension, sourceSets.map { it.name })

sourceSets.forEach { sourceSet ->
project.tasks.named(sourceSet.compileJavaTaskName) { compileTask ->
compileTask.dependsOn(GLUECODIUM_TASK_NAME)
}
}
}
}

private fun setDefaultGluecodiumSources(
project: Project,
gluecodiumExtension: GluecodiumExtension,
sourceSetNames: List<String>
) {
val defaultSources = sourceSetNames.map { "${project.rootDir}/src/$it/$GLUECODIUM_DIR_NAME" }
gluecodiumExtension.source.convention(project.files(defaultSources).asFileTree)
gluecodiumExtension.outputDirectory.convention(
File("${project.buildDir}/generated-src/$GLUECODIUM_DIR_NAME")
)
}

private fun propagateExtensionProperties(task: GluecodiumTask, gluecodiumExtension: GluecodiumExtension) {
task.source(gluecodiumExtension.source)
task.outputDirectory.set(gluecodiumExtension.outputDirectory)
task.commonOutputDirectory.set(gluecodiumExtension.commonOutputDirectory)
task.auxiliarySource.set(gluecodiumExtension.auxiliarySource)
task.copyrightHeaderFile.set(gluecodiumExtension.copyrightHeaderFile)
task.javaPackage.set(gluecodiumExtension.javaPackage)
task.javaInternalPackage.set(gluecodiumExtension.javaInternalPackage)
task.javaNameRules.set(gluecodiumExtension.javaNameRules)
task.javaNonNullAnnotation.set(gluecodiumExtension.javaNonNullAnnotation)
task.javaNullableAnnotation.set(gluecodiumExtension.javaNullableAnnotation)
task.cppNamespace.set(gluecodiumExtension.cppNamespace)
task.cppInternalNamespace.set(gluecodiumExtension.cppInternalNamespace)
task.cppExportMacroName.set(gluecodiumExtension.cppExportMacroName)
task.cppNameRules.set(gluecodiumExtension.cppNameRules)
}
private fun setDefaultGluecodiumSources(
project: Project,
gluecodiumExtension: GluecodiumExtension,
sourceSetNames: List<String>,
) {
val defaultSources = sourceSetNames.map { "${project.rootDir}/src/$it/$GLUECODIUM_DIR_NAME" }
gluecodiumExtension.source.convention(project.files(defaultSources).asFileTree)
gluecodiumExtension.outputDirectory.convention(
File("${project.buildDir}/generated-src/$GLUECODIUM_DIR_NAME"),
)
}

private fun injectGluecodiumTask(androidExtension: BaseExtension) {
val variants = when (androidExtension) {
is AppExtension -> androidExtension.applicationVariants
is LibraryExtension -> androidExtension.libraryVariants
else -> emptyList<BaseVariant>()
private fun propagateExtensionProperties(
task: GluecodiumTask,
gluecodiumExtension: GluecodiumExtension,
) {
task.source(gluecodiumExtension.source)
task.outputDirectory.set(gluecodiumExtension.outputDirectory)
task.commonOutputDirectory.set(gluecodiumExtension.commonOutputDirectory)
task.auxiliarySource.set(gluecodiumExtension.auxiliarySource)
task.copyrightHeaderFile.set(gluecodiumExtension.copyrightHeaderFile)
task.javaPackage.set(gluecodiumExtension.javaPackage)
task.javaInternalPackage.set(gluecodiumExtension.javaInternalPackage)
task.javaNameRules.set(gluecodiumExtension.javaNameRules)
task.javaNonNullAnnotation.set(gluecodiumExtension.javaNonNullAnnotation)
task.javaNullableAnnotation.set(gluecodiumExtension.javaNullableAnnotation)
task.cppNamespace.set(gluecodiumExtension.cppNamespace)
task.cppInternalNamespace.set(gluecodiumExtension.cppInternalNamespace)
task.cppExportMacroName.set(gluecodiumExtension.cppExportMacroName)
task.cppNameRules.set(gluecodiumExtension.cppNameRules)
}
val testVariants =
variants.filterIsInstance<TestedVariant>().mapNotNull { it.testVariant }

val allVariants = variants + testVariants
for (variant in allVariants) {
val taskProviders = variant.externalNativeBuildProviders + variant.javaCompileProvider
for (taskProvider in taskProviders) {
taskProvider.configure { it.dependsOn(GLUECODIUM_TASK_NAME) }

private fun injectGluecodiumTask(androidExtension: BaseExtension) {
val variants =
when (androidExtension) {
is AppExtension -> androidExtension.applicationVariants
is LibraryExtension -> androidExtension.libraryVariants
else -> emptyList<BaseVariant>()
}
val testVariants =
variants.filterIsInstance<TestedVariant>().mapNotNull { it.testVariant }

val allVariants = variants + testVariants
for (variant in allVariants) {
val taskProviders = variant.externalNativeBuildProviders + variant.javaCompileProvider
for (taskProvider in taskProviders) {
taskProvider.configure { it.dependsOn(GLUECODIUM_TASK_NAME) }
}
}
}
}

companion object {
private const val GLUECODIUM_DIR_NAME = "gluecodium"
private const val GLUECODIUM_EXTENSION_NAME = "gluecodium"
private const val GLUECODIUM_TASK_NAME = "generateGluecodiumSources"
companion object {
private const val GLUECODIUM_DIR_NAME = "gluecodium"
private const val GLUECODIUM_EXTENSION_NAME = "gluecodium"
private const val GLUECODIUM_TASK_NAME = "generateGluecodiumSources"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ internal class GluecodiumRunner(
private val gluecodiumFactory: (GluecodiumOptions, GeneratorOptions) -> Gluecodium =
{ gluecodiumOptions: GluecodiumOptions, generatorOptions: GeneratorOptions ->
Gluecodium(gluecodiumOptions, generatorOptions)
}
},
) {
fun run(gluecodiumOptions: GluecodiumOptions, generatorOptions: GeneratorOptions) {
fun run(
gluecodiumOptions: GluecodiumOptions,
generatorOptions: GeneratorOptions,
) {
val executionResult = gluecodiumFactory(gluecodiumOptions, generatorOptions).execute()
if (!executionResult) {
throw GradleException("Gluecodium code generation failed. See log for details.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,18 @@ open class GluecodiumTask : SourceTask() {
logProperty("cppNamespace", cppNamespace)
logProperty("cppInternalNamespace", cppInternalNamespace)
logProperty(
"cppExportMacroName", cppExportMacroName,
DEFAULT_VALUE_STRING + " " + GeneratorOptions.DEFAULT_CPP_EXPORT_MACRO_NAME
"cppExportMacroName",
cppExportMacroName,
DEFAULT_VALUE_STRING + " " + GeneratorOptions.DEFAULT_CPP_EXPORT_MACRO_NAME,
)
logProperty("cppNameRules", cppNameRules, DEFAULT_VALUE_STRING)
}

private fun logProperty(optionName: String, property: Property<*>, defaultValue: String = "") {
private fun logProperty(
optionName: String,
property: Property<*>,
defaultValue: String = "",
) {
logger.debug(GLUECODIUM_OPTIONS_FORMAT, optionName, property.orNull ?: defaultValue)
}

Expand Down
6 changes: 3 additions & 3 deletions gluecodium/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ jacocoTestCoverageVerification {
}
jacocoTestReport {
reports {
csv.enabled true
html.enabled true
xml.enabled true
csv.required = true
html.required = true
xml.required = true

csv.destination file("${buildDir}/reports/coverage/coverageReport.csv")
html.destination file("${buildDir}/reports/coverage/html")
Expand Down
Loading

0 comments on commit a27a153

Please sign in to comment.