-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ApolloCompilerPluginProvider (#5865)
* Add logger and arguments * small tweak to the KDoc * improve migration guide * more KDoc * Update libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/ApolloCompilerPluginEnvironment.kt Co-authored-by: Benoit 'BoD' Lubek <BoD@JRAF.org> * Update libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/ApolloCompilerPluginEnvironment.kt Co-authored-by: Benoit 'BoD' Lubek <BoD@JRAF.org> * remove exception, messager and add comment --------- Co-authored-by: Benoit 'BoD' Lubek <BoD@JRAF.org>
- Loading branch information
1 parent
4e70750
commit 8efd9c1
Showing
23 changed files
with
340 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...ler/src/main/kotlin/com/apollographql/apollo3/compiler/ApolloCompilerPluginEnvironment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.apollographql.apollo3.compiler | ||
|
||
import com.apollographql.apollo3.annotations.ApolloExperimental | ||
|
||
/** | ||
* [ApolloCompilerPluginEnvironment] contains the environment where the Apollo compiler is run. | ||
*/ | ||
@ApolloExperimental | ||
class ApolloCompilerPluginEnvironment( | ||
/** | ||
* Arguments as passed from the Gradle plugin | ||
*/ | ||
val arguments: Map<String, Any?>, | ||
/** | ||
* A logger that can be used by the plugin. | ||
*/ | ||
val logger: ApolloCompilerPluginLogger, | ||
) |
16 changes: 16 additions & 0 deletions
16
...compiler/src/main/kotlin/com/apollographql/apollo3/compiler/ApolloCompilerPluginLogger.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.apollographql.apollo3.compiler | ||
|
||
import com.apollographql.apollo3.annotations.ApolloExperimental | ||
|
||
/** | ||
* [ApolloCompilerPluginLogger] allows logging from the context of the Apollo compiler. | ||
* | ||
* Typically, the Apollo compiler is run from an isolated classloader and cannot use the Gradle logging functions but can respect the logging level set by the user. | ||
*/ | ||
@ApolloExperimental | ||
interface ApolloCompilerPluginLogger { | ||
fun logging(message: String) | ||
fun info(message: String) | ||
fun warn(message: String) | ||
fun error(message: String) | ||
} |
17 changes: 17 additions & 0 deletions
17
...mpiler/src/main/kotlin/com/apollographql/apollo3/compiler/ApolloCompilerPluginProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.apollographql.apollo3.compiler | ||
|
||
import com.apollographql.apollo3.annotations.ApolloExperimental | ||
|
||
/** | ||
* [ApolloCompilerPluginProvider] is entry point for creating [ApolloCompilerPlugin]. | ||
* | ||
* [ApolloCompilerPluginProvider] is created by [java.util.ServiceLoader], make sure to include a matching `META-INF/services` resource. | ||
*/ | ||
@ApolloExperimental | ||
fun interface ApolloCompilerPluginProvider { | ||
/** | ||
* Creates the [ApolloCompilerPlugin] | ||
*/ | ||
fun create(environment: ApolloCompilerPluginEnvironment): ApolloCompilerPlugin | ||
} | ||
|
39 changes: 39 additions & 0 deletions
39
...src/main/kotlin/com/apollographql/apollo3/compiler/internal/GradleCompilerPluginLogger.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.apollographql.apollo3.compiler.internal | ||
|
||
import com.apollographql.apollo3.annotations.ApolloInternal | ||
import com.apollographql.apollo3.compiler.ApolloCompilerPluginLogger | ||
|
||
@ApolloInternal | ||
class GradleCompilerPluginLogger(val loglevel: Int) : ApolloCompilerPluginLogger { | ||
|
||
override fun logging(message: String) { | ||
if (loglevel <= LOGGING_LEVEL_LOGGING) | ||
println("v: [apollo] $message") | ||
} | ||
|
||
override fun info(message: String) { | ||
if (loglevel <= LOGGING_LEVEL_INFO) | ||
println("i: [apollo] $message") | ||
} | ||
|
||
override fun warn(message: String) { | ||
if (loglevel <= LOGGING_LEVEL_WARN) | ||
println("w: [apollo] $message") | ||
} | ||
|
||
override fun error(message: String) { | ||
if (loglevel <= LOGGING_LEVEL_ERROR) | ||
println("e: [apollo] $message") | ||
} | ||
|
||
companion object { | ||
/** | ||
* Matches Gradle LogLevel | ||
* See https://github.com/gradle/gradle/blob/71f42531a742bc263c61f1d0dc21bb6570cc817b/platforms/core-runtime/logging-api/src/main/java/org/gradle/api/logging/LogLevel.java#L21 | ||
*/ | ||
const val LOGGING_LEVEL_LOGGING = 0 | ||
const val LOGGING_LEVEL_INFO = 1 | ||
const val LOGGING_LEVEL_WARN = 3 | ||
const val LOGGING_LEVEL_ERROR = 5 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...le-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/api/CompilerPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.apollographql.apollo3.gradle.api | ||
|
||
import com.apollographql.apollo3.annotations.ApolloExperimental | ||
|
||
@ApolloExperimental | ||
interface CompilerPlugin { | ||
/** | ||
* Adds the given argument to the [com.apollographql.apollo3.compiler.ApolloCompilerPlugin]. | ||
* If two arguments are added with the same name, the second one overwrites the first one. | ||
* | ||
* @param name the name of the argument | ||
* @param value the value of the argument. One of: | ||
* - [String] | ||
* - [Int] | ||
* - [Double] | ||
* - [Boolean] | ||
* - [List] | ||
* - [Map] | ||
*/ | ||
fun argument(name: String, value: Any) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...rnal/src/main/kotlin/com/apollographql/apollo3/gradle/internal/ApolloTaskWithClasspath.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.apollographql.apollo3.gradle.internal | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.file.FileCollection | ||
import org.gradle.api.logging.LogLevel | ||
import org.gradle.api.provider.MapProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Classpath | ||
import org.gradle.api.tasks.Input | ||
|
||
abstract class ApolloTaskWithClasspath: DefaultTask() { | ||
@get:Classpath | ||
abstract val classpath: ConfigurableFileCollection | ||
|
||
@get:Input | ||
abstract val hasPlugin: Property<Boolean> | ||
|
||
@get:Input | ||
abstract val arguments: MapProperty<String, Any?> | ||
|
||
@get:Input | ||
abstract val logLevel: Property<LogLevel> | ||
|
||
class Options( | ||
val classpath: FileCollection, | ||
val hasPlugin: Boolean, | ||
val arguments: Map<String, Any?>, | ||
val logLevel: LogLevel | ||
) | ||
} |
Oops, something went wrong.