Skip to content

Commit 077589e

Browse files
authored
Add example project and notebook (#62)
Add an example project and Jupyter notebook doing the same analysis as the existing example script. Should come up with a better demo analysis, but most good ones aren't simple enough to be a demo.
1 parent c24cf34 commit 077589e

File tree

56 files changed

+1483
-229
lines changed

Some content is hidden

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

56 files changed

+1483
-229
lines changed

.github/workflows/pr.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
uses: ./.github/actions/build
4444
with:
4545
args: 'openApiGenerate'
46-
- run: mv ./build/generated/openapi-generator ./pr-ref-api
46+
- run: mv ./library/build/generated/openapi-generator ./pr-ref-api
4747
- name: Checkout base ref
4848
uses: actions/checkout@v3
4949
with:
@@ -53,7 +53,7 @@ jobs:
5353
uses: ./.github/actions/build
5454
with:
5555
args: '-p ./base-ref-checkout openApiGenerate'
56-
- run: mv ./base-ref-checkout/build/generated/openapi-generator ./base-ref-api
56+
- run: mv ./base-ref-checkout/library/build/generated/openapi-generator ./base-ref-api
5757
- name: Diff generated APIs
5858
run: |
5959
echo -e '### Generated API diff\n\n```diff' > comment.md
@@ -79,7 +79,7 @@ jobs:
7979
with:
8080
dry_run: true
8181

82-
dry-run-check-new-api-spec:
83-
uses: ./.github/workflows/check-new-api-spec.yml
82+
dry-run-update-api-spec:
83+
uses: ./.github/workflows/update-api-spec.yml
8484
with:
8585
dry_run: true

.github/workflows/publish-javadoc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
with:
3333
args: 'dokkaHtml'
3434
artifact-name: 'docs'
35-
path-to-upload: "build/dokka/html/**/*"
35+
path-to-upload: "library/build/dokka/html/**/*"
3636

3737
publish-javadoc:
3838
needs: [build-javadoc]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name: 'Check for new API spec version'
1+
name: 'Update API spec'
22

33
on:
44
schedule:
5-
- cron: '0 6 * * 1'
5+
- cron: '0 6 * * *'
66
workflow_dispatch:
77
inputs:
88
dry_run:
@@ -22,7 +22,7 @@ defaults:
2222

2323
jobs:
2424

25-
check-new-api-spec:
25+
update-api-spec:
2626
runs-on: ubuntu-latest
2727
steps:
2828
- name: 'Checkout'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: 'Update Gradle Wrapper'
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "0 6 * * *"
7+
8+
jobs:
9+
10+
update-gradle-wrapper:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Update Gradle Wrapper
15+
uses: gradle-update/update-gradle-wrapper-action@v1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ build
66
!.github/actions/build
77
!*/src/**/build
88
!*/*/src/**/build
9+
.ipynb_checkpoints
910

1011
__pycache__
1112

build.gradle.kts

Lines changed: 9 additions & 219 deletions
Original file line numberDiff line numberDiff line change
@@ -1,225 +1,15 @@
1-
@file:Suppress("UnstableApiUsage")
2-
3-
import java.net.URL
4-
import org.jetbrains.dokka.DokkaConfiguration.Visibility.PUBLIC
5-
import org.jetbrains.dokka.gradle.DokkaTask
6-
71
plugins {
8-
id("org.jetbrains.kotlin.jvm") version "1.8.21"
9-
id("org.jetbrains.dokka") version "1.8.10"
10-
id("org.openapi.generator") version "6.5.0"
11-
`java-library`
12-
`java-test-fixtures`
13-
`maven-publish`
14-
}
15-
16-
group = "com.github.gabrielfeo"
17-
val repoUrl = "https://github.com/gabrielfeo/gradle-enterprise-api-kotlin"
18-
19-
val localSpecPath = providers.gradleProperty("localSpecPath")
20-
val remoteSpecUrl = providers.gradleProperty("remoteSpecUrl").orElse(
21-
providers.gradleProperty("gradle.enterprise.version").map { geVersion ->
22-
val specName = "gradle-enterprise-$geVersion-api.yaml"
23-
"https://docs.gradle.com/enterprise/api-manual/ref/$specName"
24-
}
25-
)
26-
27-
val downloadApiSpec by tasks.registering {
28-
onlyIf { !localSpecPath.isPresent() }
29-
val spec = resources.text.fromUri(remoteSpecUrl)
30-
val specName = remoteSpecUrl.map { it.substringAfterLast('/') }
31-
val outFile = project.layout.buildDirectory.file(specName)
32-
inputs.property("Spec URL", remoteSpecUrl)
33-
outputs.file(outFile)
34-
doLast {
35-
logger.info("Downloaded API spec from ${remoteSpecUrl.get()}")
36-
spec.asFile().renameTo(outFile.get().asFile)
37-
}
38-
}
39-
40-
openApiGenerate {
41-
generatorName.set("kotlin")
42-
val spec = when {
43-
localSpecPath.isPresent() -> localSpecPath.map { File(it).absolutePath }
44-
else -> downloadApiSpec.map { it.outputs.files.first().absolutePath }
45-
}
46-
inputSpec.set(spec)
47-
val generateDir = project.layout.buildDirectory.file("generated/openapi-generator")
48-
outputDir.set(generateDir.map { it.asFile.absolutePath })
49-
val ignoreFile = project.layout.projectDirectory.file(".openapi-generator-ignore")
50-
ignoreFileOverride.set(ignoreFile.asFile.absolutePath)
51-
apiPackage.set("com.gabrielfeo.gradle.enterprise.api")
52-
modelPackage.set("com.gabrielfeo.gradle.enterprise.api.model")
53-
packageName.set("com.gabrielfeo.gradle.enterprise.api.internal")
54-
invokerPackage.set("com.gabrielfeo.gradle.enterprise.api.internal")
55-
additionalProperties.put("library", "jvm-retrofit2")
56-
additionalProperties.put("useCoroutines", true)
57-
}
58-
59-
tasks.openApiGenerate.configure {
60-
doFirst {
61-
logger.info("Using API spec ${inputSpec.get()}")
62-
}
63-
// Replace Response<X> with X in every method return type of GradleEnterpriseApi.kt
64-
doLast {
65-
val apiFile = File(
66-
outputDir.get(),
67-
"src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/GradleEnterpriseApi.kt",
68-
)
69-
ant.withGroovyBuilder {
70-
"replaceregexp"(
71-
"file" to apiFile,
72-
"match" to ": Response<(.*?)>$",
73-
"replace" to """: \1""",
74-
"flags" to "gm",
75-
)
76-
}
77-
}
78-
// Add @JvmSuppressWildcards to avoid square/retrofit#3275
79-
doLast {
80-
val apiFile = File(
81-
outputDir.get(),
82-
"src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/GradleEnterpriseApi.kt",
83-
)
84-
ant.withGroovyBuilder {
85-
"replaceregexp"(
86-
"file" to apiFile,
87-
"match" to "interface GradleEnterpriseApi",
88-
"replace" to """
89-
@JvmSuppressWildcards
90-
interface GradleEnterpriseApi
91-
""".trimIndent(),
92-
"flags" to "m",
93-
)
94-
}
95-
}
96-
// Workaround for properties generated with `arrayListOf(null,null)` as default value
97-
doLast {
98-
val srcDir = File(outputDir.get(), "src/main/kotlin")
99-
ant.withGroovyBuilder {
100-
"replaceregexp"(
101-
"match" to """arrayListOf\(null,null\)""",
102-
"replace" to """emptyList()""",
103-
"flags" to "gm",
104-
) {
105-
"fileset"(
106-
"dir" to srcDir
107-
)
108-
}
109-
}
110-
}
111-
// Workaround for missing imports of exploded queries
112-
doLast {
113-
val srcDir = File(outputDir.get(), "src/main/kotlin")
114-
val modelPackage = openApiGenerate.modelPackage.get()
115-
val modelPackagePattern = modelPackage.replace(".", "\\.")
116-
ant.withGroovyBuilder {
117-
"replaceregexp"(
118-
"match" to """(?:import $modelPackagePattern.[.\w]+\s)+""",
119-
"replace" to "import $modelPackage.*\n",
120-
"flags" to "m",
121-
) {
122-
"fileset"(
123-
"dir" to srcDir
124-
)
125-
}
126-
}
127-
}
2+
id("org.jetbrains.kotlin.jvm") version "1.8.21" apply false
3+
id("org.jetbrains.dokka") version "1.8.10" apply false
4+
id("org.openapi.generator") version "6.5.0" apply false
1285
}
1296

130-
sourceSets {
131-
main {
132-
java {
133-
srcDir(tasks.openApiGenerate)
134-
}
135-
}
136-
}
137-
138-
java {
139-
withSourcesJar()
140-
withJavadocJar()
141-
toolchain {
142-
languageVersion.set(JavaLanguageVersion.of(8))
143-
}
144-
}
145-
146-
components.getByName<AdhocComponentWithVariants>("java").apply {
147-
withVariantsFromConfiguration(configurations["testFixturesApiElements"]) { skip() }
148-
withVariantsFromConfiguration(configurations["testFixturesRuntimeElements"]) { skip() }
149-
}
150-
151-
tasks.withType<DokkaTask>().configureEach {
152-
dokkaSourceSets.all {
153-
sourceLink {
154-
localDirectory.set(file("src/main/kotlin"))
155-
remoteUrl.set(URL("$repoUrl/blob/$version/src/main/kotlin"))
156-
remoteLineSuffix.set("#L")
157-
}
158-
jdkVersion.set(8)
159-
suppressGeneratedFiles.set(false)
160-
documentedVisibilities.set(setOf(PUBLIC))
161-
perPackageOption {
162-
matchingRegex.set(""".*\.internal.*""")
163-
suppress.set(true)
164-
}
165-
externalDocumentationLink("https://kotlinlang.org/api/kotlinx.coroutines/")
166-
externalDocumentationLink("https://square.github.io/okhttp/4.x/okhttp/")
167-
externalDocumentationLink("https://square.github.io/retrofit/2.x/retrofit/")
168-
externalDocumentationLink("https://square.github.io/moshi/1.x/moshi/")
169-
externalDocumentationLink("https://square.github.io/moshi/1.x/moshi-kotlin/")
170-
}
171-
}
172-
173-
tasks.named<Jar>("javadocJar") {
174-
from(tasks.dokkaHtml)
175-
}
176-
177-
publishing {
178-
publications {
179-
create<MavenPublication>("library") {
180-
artifactId = "gradle-enterprise-api-kotlin"
181-
from(components["java"])
182-
}
183-
}
184-
}
185-
186-
testing {
187-
suites {
188-
getByName<JvmTestSuite>("test") {
189-
dependencies {
190-
implementation("com.squareup.okhttp3:mockwebserver:4.11.0")
191-
implementation("com.squareup.okio:okio:3.3.0")
192-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1")
193-
}
194-
}
195-
register<JvmTestSuite>("integrationTest") {
196-
dependencies {
197-
implementation(project())
198-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1")
199-
}
200-
}
201-
withType<JvmTestSuite> {
202-
useKotlinTest()
203-
}
204-
}
205-
}
206-
207-
java {
208-
consistentResolution {
209-
useRuntimeClasspathVersions()
210-
}
211-
}
7+
val group by project.properties
8+
val artifact by project.properties
2129

213-
dependencies {
214-
constraints {
215-
implementation("com.squareup.okio:okio:3.3.0")
10+
project(":examples:example-project:app").configurations.configureEach {
11+
resolutionStrategy.dependencySubstitution {
12+
substitute(module("$group:$artifact"))
13+
.using(project(":library"))
21614
}
217-
api("com.squareup.moshi:moshi:1.15.0")
218-
implementation("com.squareup.moshi:moshi-kotlin:1.15.0")
219-
api("com.squareup.okhttp3:okhttp:4.11.0")
220-
implementation("com.squareup.okhttp3:logging-interceptor:4.11.0")
221-
api("com.squareup.retrofit2:retrofit:2.9.0")
222-
implementation("com.squareup.retrofit2:converter-moshi:2.9.0")
223-
implementation("com.squareup.retrofit2:converter-scalars:2.9.0")
224-
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
22515
}

0 commit comments

Comments
 (0)