Skip to content

Commit b3a0212

Browse files
committed
Add plugin and test project
1 parent be63c5c commit b3a0212

File tree

364 files changed

+20041
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

364 files changed

+20041
-5
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
.gradle
2+
.kotlin
3+
.intellijPlatform
24

35
build
4-
.kotlin
56

67
.idea/*
7-
!.idea/codeStyles
8-
!.idea/runConfigurations
8+
!.idea/codeStyles/*
9+
!.idea/runConfigurations/*
910

1011
.DS_Store

build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
plugins {
2+
alias(libs.plugins.kotlin.jvm).apply(false)
3+
alias(libs.plugins.apollo).apply(false)
4+
}

gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
org.gradle.jvmargs=-Xmx8g
2+
3+
VERSION_NAME=4.3.1-SNAPSHOT

gradle/libs.versions.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[versions]
2+
kotlin-plugin = "2.1.21"
3+
intellij-platform = "2.6.0"
4+
apollo = "4.3.0"
5+
grammarkit = "2022.3.2.2"
6+
changelog = "2.2.1"
7+
sqlite-jdbc = "3.43.2.0"
8+
apollo-normalizedcache = "1.0.0-alpha.3"
9+
slf4j = "2.0.13"
10+
google-testparameterinjector = "1.11"
11+
12+
[plugins]
13+
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin-plugin" }
14+
intellij-platform = { id = "org.jetbrains.intellij.platform", version.ref = "intellij-platform" }
15+
apollo = { id = "com.apollographql.apollo", version.ref = "apollo" }
16+
grammarkit = { id = "org.jetbrains.grammarkit", version.ref = "grammarkit" }
17+
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
18+
19+
[libraries]
20+
apollo-annotations = { group = "com.apollographql.apollo", name = "apollo-annotations", version.ref = "apollo" }
21+
apollo-api = { group = "com.apollographql.apollo", name = "apollo-api", version.ref = "apollo" }
22+
apollo-runtime = { group = "com.apollographql.apollo", name = "apollo-runtime", version.ref = "apollo" }
23+
apollo-gradle-plugin-external = { group = "com.apollographql.apollo", name = "apollo-gradle-plugin-external", version.ref = "apollo" }
24+
apollo-ast = { group = "com.apollographql.apollo", name = "apollo-ast", version.ref = "apollo" }
25+
apollo-tooling = { group = "com.apollographql.apollo", name = "apollo-tooling", version.ref = "apollo" }
26+
apollo-normalized-cache-sqlite-classic = { group = "com.apollographql.apollo", name = "apollo-normalized-cache-sqlite", version.ref = "apollo" }
27+
apollo-normalized-cache-sqlite-new = { group = "com.apollographql.cache", name = "normalized-cache-sqlite", version.ref = "apollo-normalizedcache" }
28+
sqlite-jdbc = { group = "org.xerial", name = "sqlite-jdbc", version.ref = "sqlite-jdbc" }
29+
slf4j-simple = { group = "org.slf4j", name = "slf4j-simple", version.ref = "slf4j" }
30+
google-testparameterinjector = { group = "com.google.testparameterinjector", name = "test-parameter-injector", version.ref = "google-testparameterinjector" }

plugin/build.gradle.kts

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
2+
import org.gradle.api.tasks.testing.logging.TestLogEvent
3+
import org.jetbrains.changelog.markdownToHTML
4+
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
5+
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask.FailureLevel.INTERNAL_API_USAGES
6+
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask.FailureLevel.INVALID_PLUGIN
7+
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask.FailureLevel.PLUGIN_STRUCTURE_WARNINGS
8+
import java.net.URI
9+
import java.text.SimpleDateFormat
10+
import java.util.Date
11+
12+
fun properties(key: String) = project.findProperty(key).toString()
13+
14+
fun isSnapshotBuild() = System.getenv("IJ_PLUGIN_SNAPSHOT").toBoolean()
15+
16+
plugins {
17+
alias(libs.plugins.kotlin.jvm)
18+
alias(libs.plugins.intellij.platform)
19+
alias(libs.plugins.changelog)
20+
alias(libs.plugins.apollo)
21+
alias(libs.plugins.grammarkit)
22+
}
23+
24+
repositories {
25+
// mavenLocal()
26+
// maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
27+
// maven("https://storage.googleapis.com/apollo-previews/m2/")
28+
mavenCentral()
29+
30+
intellijPlatform {
31+
defaultRepositories()
32+
}
33+
}
34+
35+
group = properties("pluginGroup")
36+
37+
// Use the global version defined in the root project + dedicated suffix if building a snapshot from the CI
38+
version = properties("VERSION_NAME") + getSnapshotVersionSuffix()
39+
40+
fun getSnapshotVersionSuffix(): String {
41+
if (!isSnapshotBuild()) return ""
42+
return ".${SimpleDateFormat("YYYY-MM-dd").format(Date())}." + System.getenv("GITHUB_SHA").take(7)
43+
}
44+
45+
kotlin {
46+
jvmToolchain(21)
47+
}
48+
49+
// Copy specific dependencies to a directory visible to the unit tests.
50+
// See ApolloTestCase.kt.
51+
configurations {
52+
create("apolloDependencies")
53+
}
54+
dependencies {
55+
listOf(
56+
libs.apollo.annotations,
57+
libs.apollo.api,
58+
libs.apollo.runtime,
59+
).forEach {
60+
add("apolloDependencies", it)
61+
}
62+
}
63+
tasks.register<Copy>("copyApolloDependencies") {
64+
from(configurations.getByName("apolloDependencies"))
65+
into(layout.buildDirectory.asFile.get().resolve("apolloDependencies"))
66+
}
67+
68+
tasks {
69+
val runLocalIde by intellijPlatformTesting.runIde.registering {
70+
// Use a custom IJ/AS installation. Set this property in your local ~/.gradle/gradle.properties file.
71+
// (for AS, it should be something like '/Applications/Android Studio.app/Contents')
72+
// See https://plugins.jetbrains.com/docs/intellij/android-studio.html#configuring-the-plugin-gradle-build-script
73+
providers.gradleProperty("apolloIntellijPlugin.ideDir").orNull?.let {
74+
localPath.set(file(it))
75+
}
76+
77+
task {
78+
// Enables debug logging for the plugin
79+
systemProperty("idea.log.debug.categories", "Apollo")
80+
81+
// Disable hiding frequent exceptions in logs (annoying for debugging). See com.intellij.idea.IdeaLogger.
82+
systemProperty("idea.logger.exception.expiration.minutes", "0")
83+
84+
// Uncomment to disable internal mode - see https://plugins.jetbrains.com/docs/intellij/enabling-internal.html
85+
// systemProperty("idea.is.internal", "false")
86+
87+
// Enable K2 mode (can't be done in the UI in sandbox mode - see https://kotlin.github.io/analysis-api/testing-in-k2-locally.html)
88+
systemProperty("idea.kotlin.plugin.use.k2", "true")
89+
}
90+
}
91+
92+
withType<AbstractTestTask> {
93+
// Log tests
94+
testLogging {
95+
exceptionFormat = TestExceptionFormat.FULL
96+
events.add(TestLogEvent.PASSED)
97+
events.add(TestLogEvent.FAILED)
98+
showStandardStreams = true
99+
}
100+
dependsOn("copyApolloDependencies")
101+
dependsOn(":test-project:generateApolloSources")
102+
}
103+
104+
generateLexer {
105+
purgeOldFiles.set(true)
106+
sourceFile.set(file("src/main/grammars/ApolloGraphQLLexer.flex"))
107+
targetOutputDir.set(file("src/main/java/com/apollographql/ijplugin/psi"))
108+
}
109+
}
110+
111+
// Setup fake JDK for maven dependencies to work
112+
// See https://youtrack.jetbrains.com/issue/IJSDK-321
113+
val mockJdkRoot = layout.buildDirectory.asFile.get().resolve("mockJDK")
114+
tasks.register("downloadMockJdk") {
115+
val mockJdkRoot = mockJdkRoot
116+
doLast {
117+
val rtJar = mockJdkRoot.resolve("java/mockJDK-1.7/jre/lib/rt.jar")
118+
if (!rtJar.exists()) {
119+
rtJar.parentFile.mkdirs()
120+
rtJar.writeBytes(
121+
URI("https://github.com/JetBrains/intellij-community/raw/master/java/mockJDK-1.7/jre/lib/rt.jar").toURL()
122+
.openStream()
123+
.readBytes()
124+
)
125+
}
126+
}
127+
}
128+
129+
tasks.test.configure {
130+
// Setup fake JDK for maven dependencies to work
131+
// See https://jetbrains-platform.slack.com/archives/CPL5291JP/p1664105522154139 and https://youtrack.jetbrains.com/issue/IJSDK-321
132+
// Use a relative path to make build caching work
133+
dependsOn("downloadMockJdk")
134+
systemProperty("idea.home.path", mockJdkRoot.relativeTo(project.projectDir).path)
135+
136+
// Enable K2 mode - see https://kotlin.github.io/analysis-api/testing-in-k2-locally.html
137+
systemProperty("idea.kotlin.plugin.use.k2", "true")
138+
}
139+
140+
apollo {
141+
service("apolloDebugServer") {
142+
packageName.set("com.apollographql.ijplugin.apollodebugserver")
143+
introspection {
144+
endpointUrl.set("http://localhost:12200/")
145+
schemaFile.set(file("src/main/graphql/schema.graphqls"))
146+
}
147+
}
148+
}
149+
150+
dependencies {
151+
// IntelliJ Platform dependencies must be declared before the intellijPlatform block - see https://github.com/JetBrains/intellij-platform-gradle-plugin/issues/1784
152+
intellijPlatform {
153+
create(type = properties("platformType"), version = properties("platformVersion"))
154+
bundledPlugins(properties("platformBundledPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
155+
plugins(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
156+
// Use a specific version of the verifier
157+
// TODO: remove when https://youtrack.jetbrains.com/issue/MP-7366 is fixed
158+
pluginVerifier(version = "1.383")
159+
testFramework(TestFrameworkType.Plugin.Java)
160+
zipSigner()
161+
}
162+
163+
implementation(libs.apollo.gradle.plugin.external) {
164+
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core")
165+
}
166+
implementation(libs.apollo.ast)
167+
implementation(libs.apollo.tooling) {
168+
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core")
169+
}
170+
implementation(libs.apollo.normalized.cache.sqlite.classic)
171+
implementation(libs.sqlite.jdbc)
172+
implementation(libs.apollo.normalized.cache.sqlite.new) {
173+
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core")
174+
}
175+
implementation(libs.apollo.runtime) {
176+
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core")
177+
}
178+
runtimeOnly(libs.slf4j.simple)
179+
testImplementation(libs.google.testparameterinjector)
180+
181+
// Temporary workaround for https://github.com/JetBrains/intellij-platform-gradle-plugin/issues/1663
182+
// Should be fixed in platformVersion 2024.3.x
183+
testRuntimeOnly("org.opentest4j:opentest4j:1.3.0")
184+
}
185+
186+
// IntelliJ Platform Gradle Plugin configuration
187+
// See https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-extension.html#intellijPlatform-pluginConfiguration
188+
intellijPlatform {
189+
pluginConfiguration {
190+
id.set(properties("pluginId"))
191+
name.set(properties("pluginName"))
192+
version.set(project.version.toString())
193+
ideaVersion {
194+
sinceBuild = properties("pluginSinceBuild")
195+
// No untilBuild specified, the plugin wants to be compatible with all future versions
196+
untilBuild = provider { null }
197+
}
198+
// Extract the <!-- Plugin description --> section from README.md and provide it to the plugin's manifest
199+
description.set(
200+
projectDir.resolve("../README.md").readText().lines().run {
201+
val start = "<!-- Plugin description -->"
202+
val end = "<!-- Plugin description end -->"
203+
204+
if (!containsAll(listOf(start, end))) {
205+
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
206+
}
207+
subList(indexOf(start) + 1, indexOf(end))
208+
}.joinToString("\n").run { markdownToHTML(this) }
209+
)
210+
changeNotes.set(
211+
if (isSnapshotBuild()) {
212+
"Weekly snapshot builds contain the latest changes from the <code>main</code> branch."
213+
} else {
214+
"See the <a href=\"https://github.com/apollographql/apollo-kotlin/releases/tag/v${project.version}\">release notes</a>."
215+
}
216+
)
217+
}
218+
219+
signing {
220+
certificateChain.set(System.getenv("CERTIFICATE_CHAIN"))
221+
privateKey.set(System.getenv("PRIVATE_KEY"))
222+
password.set(System.getenv("PRIVATE_KEY_PASSWORD"))
223+
}
224+
225+
publishing {
226+
token.set(System.getenv("PUBLISH_TOKEN"))
227+
if (isSnapshotBuild()) {
228+
// Read more: https://plugins.jetbrains.com/docs/intellij/publishing-plugin.html#specifying-a-release-channel
229+
channels.set(listOf("snapshots"))
230+
}
231+
}
232+
233+
pluginVerification {
234+
ides {
235+
recommended()
236+
}
237+
failureLevel.set(
238+
setOf(
239+
// Temporarily disabled due to https://platform.jetbrains.com/t/plugin-verifier-fails-with-plugin-com-intellij-modules-json-not-declared-as-a-plugin-dependency/580
240+
// TODO: Uncomment when https://youtrack.jetbrains.com/issue/MP-7366 is fixed
241+
// COMPATIBILITY_PROBLEMS,
242+
INTERNAL_API_USAGES,
243+
INVALID_PLUGIN,
244+
PLUGIN_STRUCTURE_WARNINGS,
245+
)
246+
)
247+
}
248+
}

plugin/gradle.properties

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# IntelliJ Platform Artifacts Repositories
2+
# -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html
3+
pluginGroup=com.apollographql
4+
pluginName=Apollo GraphQL
5+
pluginId=com.apollographql.ijplugin
6+
pluginRepositoryUrl=https://github.com/apollographql/apollo-kotlin
7+
8+
9+
# XXX Do update the supported versions in the README.md, and in docs/source/testing/android-studio-plugin.mdx file when updating these values!
10+
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
11+
# for insight into build numbers and IntelliJ Platform versions.
12+
pluginSinceBuild=242
13+
# No untilBuild specified, the plugin wants to be compatible with all future versions
14+
# pluginUntilBuild=243.*
15+
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
16+
platformType=IU
17+
# Corresponds to AS Ladybug 2024.2.1 -> https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html
18+
# and https://developer.android.com/studio/archive (more up to date)
19+
# See also https://plugins.jetbrains.com/docs/intellij/android-studio.html
20+
platformVersion=2024.2.1
21+
22+
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
23+
platformBundledPlugins=com.intellij.java, org.jetbrains.kotlin, com.intellij.gradle, org.toml.lang
24+
# To find the version of a plugin relative to the platform version, see the plugin's page on the Marketplace,
25+
# e.g. for the GraphQL plugin: https://plugins.jetbrains.com/plugin/8097-graphql/versions/stable
26+
# Note: to run wih AS 2024.1.1, use org.jetbrains.android:241.14494.17
27+
platformPlugins=com.intellij.lang.jsgraphql:242.21829.3, org.jetbrains.android:242.21829.142

plugin/logback.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<configuration>
2+
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%kvp- %msg%n</pattern>
6+
</encoder>
7+
</appender>
8+
9+
<root level="INFO">
10+
<appender-ref ref="STDOUT" />
11+
</root>
12+
13+
</configuration>

0 commit comments

Comments
 (0)