diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ApolloCompilerPlugin.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ApolloCompilerPlugin.kt index b1c5c696653..ac9eea2ad2a 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ApolloCompilerPlugin.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ApolloCompilerPlugin.kt @@ -11,13 +11,6 @@ import com.apollographql.apollo.compiler.ir.IrOperations import com.apollographql.apollo.compiler.operationoutput.OperationDescriptor import com.apollographql.apollo.compiler.operationoutput.OperationId -@Deprecated( - "Use ApolloCompilerPlugin instead (don't forget to replace the META-INF.service file to `com.apollographql.apollo.compiler.ApolloCompilerPlugin`", - ReplaceWith("ApolloCompilerPlugin"), - DeprecationLevel.ERROR -) -typealias Plugin = ApolloCompilerPlugin - /** * [ApolloCompilerPlugin] allows to customize the behaviour of the Apollo Compiler. * diff --git a/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo/gradle/internal/serviceloader.kt b/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo/gradle/internal/serviceloader.kt index a892fe08391..51fcb72ab99 100644 --- a/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo/gradle/internal/serviceloader.kt +++ b/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo/gradle/internal/serviceloader.kt @@ -19,7 +19,7 @@ internal fun apolloCompilerPlugin( val plugin = plugins.singleOrNull() if (plugin != null) { - return plugin + error("Apollo: use ApolloCompilerPluginProvider instead of ApolloCompilerPlugin directly. ApolloCompilerPluginProvider allows arguments and logging") } val pluginProviders = ServiceLoader.load(ApolloCompilerPluginProvider::class.java).toList() diff --git a/libraries/apollo-gradle-plugin/testProjects/operationIdsWithIsolation/apollo-compiler-plugin/src/main/kotlin/apollo/plugin/MyPlugin.kt b/libraries/apollo-gradle-plugin/testProjects/operationIdsWithIsolation/apollo-compiler-plugin/src/main/kotlin/apollo/plugin/MyPlugin.kt index 099c0a64fe0..e9f44c4ea5e 100644 --- a/libraries/apollo-gradle-plugin/testProjects/operationIdsWithIsolation/apollo-compiler-plugin/src/main/kotlin/apollo/plugin/MyPlugin.kt +++ b/libraries/apollo-gradle-plugin/testProjects/operationIdsWithIsolation/apollo-compiler-plugin/src/main/kotlin/apollo/plugin/MyPlugin.kt @@ -1,7 +1,10 @@ package apollo.plugin +import com.apollographql.apollo.annotations.ApolloExperimental import com.apollographql.apollo.compiler.OperationOutputGenerator import com.apollographql.apollo.compiler.ApolloCompilerPlugin +import com.apollographql.apollo.compiler.ApolloCompilerPluginEnvironment +import com.apollographql.apollo.compiler.ApolloCompilerPluginProvider import com.apollographql.apollo.compiler.operationoutput.OperationDescriptor import com.apollographql.apollo.compiler.operationoutput.OperationId @@ -9,4 +12,12 @@ class MyPlugin: ApolloCompilerPlugin { override fun operationIds(descriptors: List): List? { return descriptors.map { OperationId("${it.name}CustomId", it.name) } } +} + +@OptIn(ApolloExperimental::class) +class MyPluginProvider: ApolloCompilerPluginProvider { + override fun create(environment: ApolloCompilerPluginEnvironment): ApolloCompilerPlugin { + return MyPlugin() + } + } \ No newline at end of file diff --git a/libraries/apollo-gradle-plugin/testProjects/operationIdsWithIsolation/apollo-compiler-plugin/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin b/libraries/apollo-gradle-plugin/testProjects/operationIdsWithIsolation/apollo-compiler-plugin/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin deleted file mode 100644 index a025c438265..00000000000 --- a/libraries/apollo-gradle-plugin/testProjects/operationIdsWithIsolation/apollo-compiler-plugin/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin +++ /dev/null @@ -1 +0,0 @@ -apollo.plugin.MyPlugin \ No newline at end of file diff --git a/libraries/apollo-gradle-plugin/testProjects/operationIdsWithIsolation/apollo-compiler-plugin/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider b/libraries/apollo-gradle-plugin/testProjects/operationIdsWithIsolation/apollo-compiler-plugin/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider new file mode 100644 index 00000000000..897e1663cd8 --- /dev/null +++ b/libraries/apollo-gradle-plugin/testProjects/operationIdsWithIsolation/apollo-compiler-plugin/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider @@ -0,0 +1 @@ +apollo.plugin.MyPluginProvider \ No newline at end of file diff --git a/tests/compiler-plugins/add-field/src/main/kotlin/hooks/TestPlugin.kt b/tests/compiler-plugins/add-field/src/main/kotlin/hooks/TestPlugin.kt index 546f2bff18b..801d7a23baa 100644 --- a/tests/compiler-plugins/add-field/src/main/kotlin/hooks/TestPlugin.kt +++ b/tests/compiler-plugins/add-field/src/main/kotlin/hooks/TestPlugin.kt @@ -13,6 +13,14 @@ import com.apollographql.apollo.ast.responseName import com.apollographql.apollo.ast.rootTypeDefinition import com.apollographql.apollo.compiler.DocumentTransform import com.apollographql.apollo.compiler.ApolloCompilerPlugin +import com.apollographql.apollo.compiler.ApolloCompilerPluginEnvironment +import com.apollographql.apollo.compiler.ApolloCompilerPluginProvider + +class TestPluginProvider: ApolloCompilerPluginProvider { + override fun create(environment: ApolloCompilerPluginEnvironment): ApolloCompilerPlugin { + return TestPlugin() + } +} class TestPlugin : ApolloCompilerPlugin { override fun documentTransform(): DocumentTransform { diff --git a/tests/compiler-plugins/add-field/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin b/tests/compiler-plugins/add-field/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin deleted file mode 100644 index f9d9be73fdf..00000000000 --- a/tests/compiler-plugins/add-field/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin +++ /dev/null @@ -1 +0,0 @@ -hooks.TestPlugin \ No newline at end of file diff --git a/tests/compiler-plugins/add-field/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider b/tests/compiler-plugins/add-field/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider new file mode 100644 index 00000000000..e169993db7e --- /dev/null +++ b/tests/compiler-plugins/add-field/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider @@ -0,0 +1 @@ +hooks.TestPluginProvider \ No newline at end of file diff --git a/tests/compiler-plugins/capitalize-enum-values/src/main/kotlin/hooks/TestPlugin.kt b/tests/compiler-plugins/capitalize-enum-values/src/main/kotlin/hooks/TestPlugin.kt index 5757ddcab93..538da4201fb 100644 --- a/tests/compiler-plugins/capitalize-enum-values/src/main/kotlin/hooks/TestPlugin.kt +++ b/tests/compiler-plugins/capitalize-enum-values/src/main/kotlin/hooks/TestPlugin.kt @@ -1,11 +1,19 @@ package hooks import com.apollographql.apollo.compiler.ApolloCompilerPlugin +import com.apollographql.apollo.compiler.ApolloCompilerPluginEnvironment +import com.apollographql.apollo.compiler.ApolloCompilerPluginProvider import com.apollographql.apollo.compiler.Transform import com.apollographql.apollo.compiler.codegen.kotlin.KotlinOutput import com.squareup.kotlinpoet.FunSpec import com.squareup.kotlinpoet.TypeSpec +class TestPluginProvider: ApolloCompilerPluginProvider { + override fun create(environment: ApolloCompilerPluginEnvironment): ApolloCompilerPlugin { + return TestPlugin() + } +} + class TestPlugin : ApolloCompilerPlugin { override fun kotlinOutputTransform(): Transform { return object : Transform { diff --git a/tests/compiler-plugins/capitalize-enum-values/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin b/tests/compiler-plugins/capitalize-enum-values/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin deleted file mode 100644 index f9d9be73fdf..00000000000 --- a/tests/compiler-plugins/capitalize-enum-values/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin +++ /dev/null @@ -1 +0,0 @@ -hooks.TestPlugin \ No newline at end of file diff --git a/tests/compiler-plugins/capitalize-enum-values/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider b/tests/compiler-plugins/capitalize-enum-values/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider new file mode 100644 index 00000000000..e169993db7e --- /dev/null +++ b/tests/compiler-plugins/capitalize-enum-values/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider @@ -0,0 +1 @@ +hooks.TestPluginProvider \ No newline at end of file diff --git a/tests/compiler-plugins/custom-flatten/src/main/kotlin/hooks/TestPlugin.kt b/tests/compiler-plugins/custom-flatten/src/main/kotlin/hooks/TestPlugin.kt index 8d963cb674e..2aac72ba2ca 100644 --- a/tests/compiler-plugins/custom-flatten/src/main/kotlin/hooks/TestPlugin.kt +++ b/tests/compiler-plugins/custom-flatten/src/main/kotlin/hooks/TestPlugin.kt @@ -1,9 +1,17 @@ package hooks import com.apollographql.apollo.compiler.ApolloCompilerPlugin +import com.apollographql.apollo.compiler.ApolloCompilerPluginEnvironment +import com.apollographql.apollo.compiler.ApolloCompilerPluginProvider import com.apollographql.apollo.compiler.Transform import com.apollographql.apollo.compiler.ir.IrOperations +class TestPluginProvider: ApolloCompilerPluginProvider { + override fun create(environment: ApolloCompilerPluginEnvironment): ApolloCompilerPlugin { + return TestPlugin() + } +} + class TestPlugin : ApolloCompilerPlugin { override fun irOperationsTransform(): Transform { return object : Transform { diff --git a/tests/compiler-plugins/custom-flatten/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin b/tests/compiler-plugins/custom-flatten/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin deleted file mode 100644 index f9d9be73fdf..00000000000 --- a/tests/compiler-plugins/custom-flatten/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin +++ /dev/null @@ -1 +0,0 @@ -hooks.TestPlugin \ No newline at end of file diff --git a/tests/compiler-plugins/custom-flatten/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider b/tests/compiler-plugins/custom-flatten/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider new file mode 100644 index 00000000000..e169993db7e --- /dev/null +++ b/tests/compiler-plugins/custom-flatten/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider @@ -0,0 +1 @@ +hooks.TestPluginProvider \ No newline at end of file diff --git a/tests/compiler-plugins/default-null-values/src/main/kotlin/hooks/TestPlugin.kt b/tests/compiler-plugins/default-null-values/src/main/kotlin/hooks/TestPlugin.kt index 4353817a442..153a88bae85 100644 --- a/tests/compiler-plugins/default-null-values/src/main/kotlin/hooks/TestPlugin.kt +++ b/tests/compiler-plugins/default-null-values/src/main/kotlin/hooks/TestPlugin.kt @@ -1,12 +1,20 @@ package hooks import com.apollographql.apollo.compiler.ApolloCompilerPlugin +import com.apollographql.apollo.compiler.ApolloCompilerPluginEnvironment +import com.apollographql.apollo.compiler.ApolloCompilerPluginProvider import com.apollographql.apollo.compiler.Transform import com.apollographql.apollo.compiler.codegen.kotlin.KotlinOutput import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.TypeSpec +class TestPluginProvider: ApolloCompilerPluginProvider { + override fun create(environment: ApolloCompilerPluginEnvironment): ApolloCompilerPlugin { + return TestPlugin() + } +} + class TestPlugin: ApolloCompilerPlugin { override fun kotlinOutputTransform(): Transform { return object : Transform { diff --git a/tests/compiler-plugins/default-null-values/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin b/tests/compiler-plugins/default-null-values/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin deleted file mode 100644 index f9d9be73fdf..00000000000 --- a/tests/compiler-plugins/default-null-values/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin +++ /dev/null @@ -1 +0,0 @@ -hooks.TestPlugin \ No newline at end of file diff --git a/tests/compiler-plugins/default-null-values/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider b/tests/compiler-plugins/default-null-values/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider new file mode 100644 index 00000000000..e169993db7e --- /dev/null +++ b/tests/compiler-plugins/default-null-values/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider @@ -0,0 +1 @@ +hooks.TestPluginProvider \ No newline at end of file diff --git a/tests/compiler-plugins/getters-and-setters/src/main/kotlin/hooks/TestPlugin.kt b/tests/compiler-plugins/getters-and-setters/src/main/kotlin/hooks/TestPlugin.kt index 0698915d284..fcff6972c85 100644 --- a/tests/compiler-plugins/getters-and-setters/src/main/kotlin/hooks/TestPlugin.kt +++ b/tests/compiler-plugins/getters-and-setters/src/main/kotlin/hooks/TestPlugin.kt @@ -1,6 +1,8 @@ package hooks import com.apollographql.apollo.compiler.ApolloCompilerPlugin +import com.apollographql.apollo.compiler.ApolloCompilerPluginEnvironment +import com.apollographql.apollo.compiler.ApolloCompilerPluginProvider import com.apollographql.apollo.compiler.Transform import com.apollographql.apollo.compiler.capitalizeFirstLetter import com.apollographql.apollo.compiler.codegen.java.JavaOutput @@ -8,6 +10,11 @@ import com.squareup.javapoet.JavaFile import com.squareup.javapoet.MethodSpec import javax.lang.model.element.Modifier +class TestPluginProvider: ApolloCompilerPluginProvider { + override fun create(environment: ApolloCompilerPluginEnvironment): ApolloCompilerPlugin { + return TestPlugin() + } +} class TestPlugin : ApolloCompilerPlugin { override fun javaOutputTransform(): Transform { return object : Transform { diff --git a/tests/compiler-plugins/getters-and-setters/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin b/tests/compiler-plugins/getters-and-setters/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin deleted file mode 100644 index f9d9be73fdf..00000000000 --- a/tests/compiler-plugins/getters-and-setters/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin +++ /dev/null @@ -1 +0,0 @@ -hooks.TestPlugin \ No newline at end of file diff --git a/tests/compiler-plugins/getters-and-setters/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider b/tests/compiler-plugins/getters-and-setters/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider new file mode 100644 index 00000000000..e169993db7e --- /dev/null +++ b/tests/compiler-plugins/getters-and-setters/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider @@ -0,0 +1 @@ +hooks.TestPluginProvider \ No newline at end of file diff --git a/tests/compiler-plugins/typename-interface/src/main/kotlin/hooks/TestPlugin.kt b/tests/compiler-plugins/typename-interface/src/main/kotlin/hooks/TestPlugin.kt index 1bd39120ca8..b37f6bbf9e0 100644 --- a/tests/compiler-plugins/typename-interface/src/main/kotlin/hooks/TestPlugin.kt +++ b/tests/compiler-plugins/typename-interface/src/main/kotlin/hooks/TestPlugin.kt @@ -1,12 +1,20 @@ package hooks import com.apollographql.apollo.compiler.ApolloCompilerPlugin +import com.apollographql.apollo.compiler.ApolloCompilerPluginEnvironment +import com.apollographql.apollo.compiler.ApolloCompilerPluginProvider import com.apollographql.apollo.compiler.Transform import com.apollographql.apollo.compiler.codegen.kotlin.KotlinOutput import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.TypeSpec +class TestPluginProvider: ApolloCompilerPluginProvider { + override fun create(environment: ApolloCompilerPluginEnvironment): ApolloCompilerPlugin { + return TestPlugin() + } +} + class TestPlugin : ApolloCompilerPlugin { private val interfaceName = "hooks.typenameinterface.HasTypeName" diff --git a/tests/compiler-plugins/typename-interface/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin b/tests/compiler-plugins/typename-interface/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin deleted file mode 100644 index f9d9be73fdf..00000000000 --- a/tests/compiler-plugins/typename-interface/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin +++ /dev/null @@ -1 +0,0 @@ -hooks.TestPlugin \ No newline at end of file diff --git a/tests/compiler-plugins/typename-interface/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider b/tests/compiler-plugins/typename-interface/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider new file mode 100644 index 00000000000..e169993db7e --- /dev/null +++ b/tests/compiler-plugins/typename-interface/src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider @@ -0,0 +1 @@ +hooks.TestPluginProvider \ No newline at end of file