diff --git a/.gitignore b/.gitignore index d4e5474..6395aac 100644 --- a/.gitignore +++ b/.gitignore @@ -13,9 +13,9 @@ hs_err_pid* # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # User-specific stuff -.idea/* -!.idea/codeStyles/ -!.idea/copyright/ +**/.idea/* +!**.idea/codeStyles/ +!**.idea/copyright/ local.properties diff --git a/build.gradle b/build.gradle index 0e54323..ab7dc01 100644 --- a/build.gradle +++ b/build.gradle @@ -20,8 +20,6 @@ buildscript { repositories { google() mavenCentral() - maven { url "https://kotlin.bintray.com/kotlinx" } - maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath libs.kotlinx.atomicfu.gradle @@ -36,82 +34,11 @@ allprojects { repositories { mavenCentral() google() - maven { url "https://kotlin.bintray.com/kotlinx" } - maven { url "https://plugins.gradle.org/m2/" } } tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { - kotlinOptions.allWarningsAsErrors = true - } -} - -void setupMultiplatformLibrary(Project project, Boolean shouldPublish = true) { - project.apply plugin: 'org.jetbrains.kotlin.multiplatform' - if (shouldPublish) { - project.apply from: '../publishing.gradle' - } - - project.group = GROUP - project.version = VERSION - - project.kotlin { - sourceSets { - commonTest { - dependencies { - implementation libs.kotlin.test - implementation libs.kotlin.test.annotations - } - } - } - } -} - -void setupAllTargetsWithDefaultSourceSets(Project project) { - setupIosTargets(project) - setupJvmTarget(project) - setupJsTarget(project) - - project.kotlin { - sourceSets { - jvmJsCommonMain.dependsOn commonMain - jvmJsCommonTest.dependsOn commonTest - - jvmMain.dependsOn jvmJsCommonMain - jvmTest.dependsOn jvmJsCommonTest - - jsMain.dependsOn jvmJsCommonMain - jsTest.dependsOn jvmJsCommonTest + kotlinOptions{ + allWarningsAsErrors = true } } -} - -private void setupIosTargets(Project project) { - project.kotlin { - targets.fromPreset(presets.iosX64, 'iosX64') - targets.fromPreset(presets.iosArm64, 'iosArm64') - } -} - -private void setupJvmTarget(Project project) { - project.kotlin { - targets.fromPreset(presets.jvm, 'jvm') - - sourceSets { - jvmMain { - dependencies { - - } - } - - jvmTest { - dependencies { - implementation libs.junit.junit - } - } - } - } -} - -private void setupJsTarget(Project project) { - project.apply plugin: JsPlugin } \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 35bf473..d1e4b55 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -22,35 +22,8 @@ repositories { mavenCentral() google() gradlePluginPortal() - maven { - url = uri(project.properties["careem_artifactory_url"] as String? ?: System.getenv("careem_artifactory_url")) - credentials { - username = project.properties["careem_artifactory_username"] as String? ?: System.getenv("careem_artifactory_username") - password = project.properties["careem_artifactory_api_key"] as String? ?: System.getenv("careem_artifactory_api_key") - } - content { - includeGroup("com.careem.mockingbird") - } - mavenContent { - releasesOnly() - } - } } dependencies { implementation(libs.kotlin.gradle) - implementation(libs.kotlin.reflectjvm) - implementation(libs.square.kotlinpoet) - implementation(libs.square.kotlinpoet.metadata) - implementation(libs.square.kotlinpoet.metadata.specs) - implementation(libs.kotlinx.metadatajvm) - implementation(libs.careem.mockingbird) // FIXME avoid this dep but use project dep instead -} - -kotlin { - // Add Deps to compilation, so it will become available in main project - sourceSets.getByName("main").kotlin.srcDirs( - "buildSrc/src/main/kotlin" - ) - println("ROOT:${rootProject.allprojects}") } diff --git a/mockingbird-compiler/build.gradle.kts b/mockingbird-compiler/build.gradle.kts index f6d19ac..6cf1b8d 100644 --- a/mockingbird-compiler/build.gradle.kts +++ b/mockingbird-compiler/build.gradle.kts @@ -20,6 +20,8 @@ plugins { `kotlin-dsl` } +apply(from = "../publishing.gradle") + gradlePlugin { plugins { register("mockingbird") { @@ -35,38 +37,17 @@ repositories { gradlePluginPortal() } -kotlin { - // Add Deps to compilation, so it will become available in main project - sourceSets.getByName("main").kotlin.srcDirs("buildSrc/src/main/kotlin") - println("ROOT:${rootProject.allprojects}") +tasks.withType().configureEach { + kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn" } dependencies { implementation(libs.kotlin.gradle) + implementation(libs.kotlin.reflectjvm) implementation(libs.square.kotlinpoet) implementation(libs.square.kotlinpoet.metadata) implementation(libs.square.kotlinpoet.metadata.specs) implementation(libs.kotlinx.metadatajvm) + implementation(project(":mockingbird")) } -//task pluginVersion { -// def outputDir = file("gen") -// -// inputs.property 'version', version -// outputs.dir outputDir -// -// doLast { -// def versionFile = file("$outputDir/com/squareup/sqldelight/Version.kt") -// versionFile.parentFile.mkdirs() -// versionFile.text = """// Generated file. Do not edit! -//package com.squareup.sqldelight -// -//val VERSION = "${project.version}" -//""" -// } -//} -// -//tasks.getByName('compileKotlin').dependsOn('pluginVersion') -// -//apply from: "$rootDir/gradle/gradle-mvn-push.gradle" - diff --git a/buildSrc/src/main/kotlin/MockingbirdPlugin.kt b/mockingbird-compiler/src/main/kotlin/com/careem/mockingbird/MockingbirdPlugin.kt similarity index 99% rename from buildSrc/src/main/kotlin/MockingbirdPlugin.kt rename to mockingbird-compiler/src/main/kotlin/com/careem/mockingbird/MockingbirdPlugin.kt index b777f2e..c24d3e5 100644 --- a/buildSrc/src/main/kotlin/MockingbirdPlugin.kt +++ b/mockingbird-compiler/src/main/kotlin/com/careem/mockingbird/MockingbirdPlugin.kt @@ -13,7 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package com.careem.mockingbird +import com.squareup.kotlinpoet.DelicateKotlinPoetApi import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.FunSpec import com.squareup.kotlinpoet.KModifier @@ -107,6 +109,8 @@ abstract class MockingbirdPlugin : Plugin { } } + + @OptIn(DelicateKotlinPoetApi::class) private fun generateMockClassFor(project: Project, kmClass: ImmutableKmClass) { val classToMock = Thread.currentThread().contextClassLoader.loadClass( kmClass.name.replace( @@ -124,6 +128,7 @@ abstract class MockingbirdPlugin : Plugin { // TODO fix package name println("Generating mocks for $simpleName") + val mockClassBuilder = TypeSpec.classBuilder("${simpleName}Mock") .addType(kmClass.buildMethodObject()) .addType(kmClass.buildArgObject()) diff --git a/buildSrc/src/main/kotlin/MockingbirdPluginExtension.kt b/mockingbird-compiler/src/main/kotlin/com/careem/mockingbird/MockingbirdPluginExtension.kt similarity index 86% rename from buildSrc/src/main/kotlin/MockingbirdPluginExtension.kt rename to mockingbird-compiler/src/main/kotlin/com/careem/mockingbird/MockingbirdPluginExtension.kt index a290486..1df6fef 100644 --- a/buildSrc/src/main/kotlin/MockingbirdPluginExtension.kt +++ b/mockingbird-compiler/src/main/kotlin/com/careem/mockingbird/MockingbirdPluginExtension.kt @@ -1,12 +1,3 @@ -import org.gradle.api.model.ObjectFactory -import org.gradle.api.provider.ListProperty -import org.gradle.kotlin.dsl.getValue -import org.gradle.kotlin.dsl.listProperty -import org.gradle.kotlin.dsl.property -import org.gradle.kotlin.dsl.provideDelegate -import org.gradle.kotlin.dsl.setValue -import kotlin.reflect.KProperty - /* * Copyright Careem, an Uber Technologies Inc. company * @@ -22,6 +13,16 @@ import kotlin.reflect.KProperty * See the License for the specific language governing permissions and * limitations under the License. */ +package com.careem.mockingbird + +import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.ListProperty +import org.gradle.kotlin.dsl.getValue +import org.gradle.kotlin.dsl.listProperty +import org.gradle.kotlin.dsl.property +import org.gradle.kotlin.dsl.provideDelegate +import org.gradle.kotlin.dsl.setValue +import kotlin.reflect.KProperty interface MockingbirdPluginExtension { var generateMocksFor: List @@ -39,7 +40,7 @@ internal class MockingbirdPluginExtensionImpl(objects: ObjectFactory) : Mockingb override var printLogs: Boolean by _printLogs // TODO implement this } -internal inline operator fun ListProperty.setValue(scope: Any, property: KProperty<*>, value: List) = +internal operator fun ListProperty.setValue(scope: Any, property: KProperty<*>, value: List) = set(value) -internal inline operator fun ListProperty.getValue(scope: Any, property: KProperty<*>): List = get() \ No newline at end of file +internal operator fun ListProperty.getValue(scope: Any, property: KProperty<*>): List = get() \ No newline at end of file diff --git a/mockingbird/build.gradle b/mockingbird/build.gradle index 9276ab9..a06ecc2 100644 --- a/mockingbird/build.gradle +++ b/mockingbird/build.gradle @@ -14,8 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -setupMultiplatformLibrary(project) -setupAllTargetsWithDefaultSourceSets(project) + +apply from: '../utils.gradle' + +setupMultiplatformLibrary(project, true) +setupAllTargetsWithDefaultSourceSets(project, true) kotlin { explicitApi() diff --git a/samples/.idea/codeStyles/Project.xml b/samples/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..4cd4110 --- /dev/null +++ b/samples/.idea/codeStyles/Project.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/.idea/codeStyles/codeStyleConfig.xml b/samples/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/samples/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/samples/build.gradle b/samples/build.gradle index 63a1b50..51e1006 100644 --- a/samples/build.gradle +++ b/samples/build.gradle @@ -15,15 +15,38 @@ * limitations under the License. */ -setupMultiplatformLibrary(project) -setupAllTargetsWithDefaultSourceSets(project) -apply plugin: MockingbirdPlugin +buildscript { + repositories { + google() + mavenCentral() + } + + dependencies { + classpath libs.kotlin.gradle + classpath "com.careem.mockingbird:mockingbird-compiler" + } +} + +allprojects { + repositories { + mavenCentral() + google() + } +} + +apply from: '../utils.gradle' + +setupMultiplatformLibrary(project, false) +setupAllTargetsWithDefaultSourceSets(project, false) // FIXME Js excluded here + +apply plugin: "com.careem.mockingbird" + kotlin { sourceSets { commonMain { dependencies { - implementation project(":mockingbird") + implementation "com.careem.mockingbird:mockingbird" implementation libs.touchlab.stately.isolate implementation kotlin('test') implementation kotlin('test-common') @@ -31,42 +54,16 @@ kotlin { } } - commonTest { - dependencies { - implementation project(":mockingbird") - implementation kotlin('test') - implementation kotlin('test-common') - implementation kotlin('test-annotations-common') - } - } - - jvmMain { - dependencies { - } - } - - jsMain { - dependencies { - } - } - - iosX64Main { - dependencies { - } - } - iosArm64Main { dependsOn iosX64Main } } } -mockingBird{ +mockingBird { generateMocksFor = [ 'com.careem.mockingbird.samples.PippoSample', 'com.careem.mockingbird.samples.Mock1' ] } - - diff --git a/samples/gradle.properties b/samples/gradle.properties new file mode 100644 index 0000000..3909171 --- /dev/null +++ b/samples/gradle.properties @@ -0,0 +1,25 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true + +# Kotlin +kotlin.code.style=official +kotlin.mpp.stability.nowarn=true + +kotlin.js.compiler=both \ No newline at end of file diff --git a/samples/gradle/wrapper/gradle-wrapper.jar b/samples/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e708b1c Binary files /dev/null and b/samples/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/gradle/wrapper/gradle-wrapper.properties b/samples/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..a0f7639 --- /dev/null +++ b/samples/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/samples/gradlew b/samples/gradlew new file mode 100755 index 0000000..4f906e0 --- /dev/null +++ b/samples/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# 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 +# +# https://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. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/samples/gradlew.bat b/samples/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/samples/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/samples/settings.gradle.kts b/samples/settings.gradle.kts new file mode 100644 index 0000000..c2bd38e --- /dev/null +++ b/samples/settings.gradle.kts @@ -0,0 +1,36 @@ +import org.gradle.initialization.DependenciesAccessors +import org.gradle.kotlin.dsl.support.serviceOf + +/** + * + * Copyright Careem, an Uber Technologies Inc. company + * + * 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. + */ + +enableFeaturePreview("VERSION_CATALOGS") + +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../versions.toml")) + } + } +} + +includeBuild("..") { + dependencySubstitution { + substitute(module("com.careem.mockingbird:mockingbird")).using(project(":mockingbird")) + substitute(module("com.careem.mockingbird:mockingbird-compiler")).using(project(":mockingbird-compiler")) + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index e7d3a3c..878d77e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -18,7 +18,6 @@ enableFeaturePreview("VERSION_CATALOGS") include(":mockingbird") -include(":samples") include(":mockingbird-compiler") dependencyResolutionManagement { diff --git a/utils.gradle b/utils.gradle new file mode 100644 index 0000000..484d684 --- /dev/null +++ b/utils.gradle @@ -0,0 +1,79 @@ + + +void setupMultiplatformLibrary(Project project, Boolean shouldPublish = true) { + project.apply plugin: 'org.jetbrains.kotlin.multiplatform' + if (shouldPublish) { + project.apply from: '../publishing.gradle' + project.group = GROUP + project.version = VERSION + } + + project.kotlin { + sourceSets { + commonTest { + dependencies { + implementation libs.kotlin.test + implementation libs.kotlin.test.annotations + } + } + } + } +} + +void setupAllTargetsWithDefaultSourceSets(Project project, Boolean includeJs = true) { + setupIosTargets(project) + setupJvmTarget(project) + if(includeJs){ + setupJsTarget(project) + } + + project.kotlin { + sourceSets { + jvmJsCommonMain.dependsOn commonMain + jvmJsCommonTest.dependsOn commonTest + + jvmMain.dependsOn jvmJsCommonMain + jvmTest.dependsOn jvmJsCommonTest + + if(includeJs){ + jsMain.dependsOn jvmJsCommonMain + jsTest.dependsOn jvmJsCommonTest + } + } + } +} + +private void setupIosTargets(Project project) { + project.kotlin { + targets.fromPreset(presets.iosX64, 'iosX64') + targets.fromPreset(presets.iosArm64, 'iosArm64') + } +} + +private void setupJvmTarget(Project project) { + project.kotlin { + targets.fromPreset(presets.jvm, 'jvm') + + sourceSets { + jvmMain { + dependencies { + + } + } + + jvmTest { + dependencies { + implementation libs.junit.junit + } + } + } + } +} + +private void setupJsTarget(Project project) { + project.apply plugin: JsPlugin +} + +ext.setupMultiplatformLibrary = { Project project, Boolean shouldPublish -> setupMultiplatformLibrary(project, shouldPublish) } +ext.setupAllTargetsWithDefaultSourceSets = { Project project, Boolean includeJs -> setupAllTargetsWithDefaultSourceSets(project, includeJs) } + diff --git a/versions.toml b/versions.toml index 61a8993..cc73f96 100644 --- a/versions.toml +++ b/versions.toml @@ -6,7 +6,6 @@ stately = "1.1.7-a1" atomicFu = "0.16.2" kotlinPoet = "1.9.0" kotlinxMetadata = "0.1.0" -mockingbird = "1.10.0" [libraries] jacoco-jacoco = { module = "org.jacoco:org.jacoco.core", version.ref = "jacoco" } @@ -21,7 +20,6 @@ square-kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinP square-kotlinpoet-metadata = { module = "com.squareup:kotlinpoet-metadata", version.ref = "kotlinPoet" } square-kotlinpoet-metadata-specs = { module = "com.squareup:kotlinpoet-metadata-specs", version.ref = "kotlinPoet" } kotlinx-metadatajvm = { module = "org.jetbrains.kotlinx:kotlinx-metadata-jvm", version.ref = "kotlinxMetadata" } -careem-mockingbird = { module = "com.careem.mockingbird:mockingbird", version.ref = "mockingbird" } kotlinx-atomicfu-gradle = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "atomicFu" } kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } \ No newline at end of file