Skip to content

Commit 937b23d

Browse files
committed
fix exportSignatures plugin
1 parent 35df01a commit 937b23d

25 files changed

+209
-126
lines changed

build.gradle

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ plugins {
1919

2020
id "me.champeau.jmh" version "0.6.8"
2121
id "jacoco"
22+
23+
id "versioning"
24+
id "srcinfo"
2225
}
2326

2427
import java.text.SimpleDateFormat
@@ -87,6 +90,10 @@ subprojects { project ->
8790
apply from: "$rootDir/gradle-scripts/subproject-dependencies.gradle"
8891
apply from: "$rootDir/gradle-scripts/subproject-config.gradle"
8992

93+
if (project.file("build.gradle").exists()) {
94+
apply from: "$rootDir/gradle-scripts/subproject-srcinfo-plugin.gradle"
95+
}
96+
9097
group='com.commercetools.sdk'
9198

9299
version = globalVersion

buildSrc/build.gradle

-19
This file was deleted.

buildSrc/src/main/resources/META-INF/gradle-plugins/srcinfo.properties

-1
This file was deleted.

buildSrc/src/main/resources/META-INF/gradle-plugins/versioning.properties

-1
This file was deleted.

commercetools/internal-docs/src/main/java/com/commercetools/docs/meta/MigrationModelClassMapping.java

+8
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@
265265
* <td>{@link com.commercetools.api.models.cart.CartChangeTaxRoundingModeAction}</td>
266266
* </tr>
267267
* <tr>
268+
* <td>{@link io.sphere.sdk.carts.commands.updateactions.FreezeCart}</td>
269+
* <td>{@link com.commercetools.api.models.cart.CartFreezeCartAction}</td>
270+
* </tr>
271+
* <tr>
268272
* <td>{@link io.sphere.sdk.carts.commands.updateactions.Recalculate}</td>
269273
* <td>{@link com.commercetools.api.models.cart.CartRecalculateAction}</td>
270274
* </tr>
@@ -441,6 +445,10 @@
441445
* <td>{@link com.commercetools.api.models.cart.CartSetShippingRateInputAction}</td>
442446
* </tr>
443447
* <tr>
448+
* <td>{@link io.sphere.sdk.carts.commands.updateactions.UnfreezeCart}</td>
449+
* <td>{@link com.commercetools.api.models.cart.CartUnfreezeCartAction}</td>
450+
* </tr>
451+
* <tr>
444452
* <td>{@link io.sphere.sdk.carts.commands.updateactions.UpdateItemShippingAddress}</td>
445453
* <td>{@link com.commercetools.api.models.cart.CartUpdateItemShippingAddressAction}</td>
446454
* </tr>

common-plugins/build.gradle

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
plugins {
2+
id 'java-gradle-plugin'
3+
id 'idea'
4+
id 'org.jetbrains.kotlin.jvm' version "2.0.0"
5+
}
6+
7+
repositories {
8+
mavenCentral()
9+
}
10+
11+
java {
12+
toolchain {
13+
languageVersion = JavaLanguageVersion.of(11)
14+
}
15+
}
16+
17+
group = 'com.commercetools.sdk.plugins'
18+
version = '1.0'
19+
20+
gradlePlugin {
21+
plugins.register('srcinfo-plugin') {
22+
id = 'srcinfo'
23+
implementationClass = 'com.commercetools.sdk.plugins.SrcInfoPlugin'
24+
}
25+
plugins.register("versioning-plugin") {
26+
id = 'versioning'
27+
implementationClass = 'com.commercetools.sdk.plugins.VersioningPlugin'
28+
}
29+
}
30+
31+
dependencies {
32+
implementation project(path: ':javaparser', configuration: 'shadow')
33+
implementation "com.google.code.gson:gson:2.11.0"
34+
implementation 'com.squareup:javapoet:1.13.0'
35+
implementation 'com.google.guava:guava:33.3.1-jre'
36+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
plugins {
2+
id 'java'
3+
id 'com.github.johnrengelman.shadow' version '7.1.2'
4+
}
5+
6+
group = 'com.commercetools.sdk.plugins'
7+
version = '1.0'
8+
9+
repositories {
10+
mavenCentral()
11+
}
12+
13+
shadowJar {
14+
relocate 'com.github.javaparser', 'shadow.javaparser'
15+
}
16+
17+
dependencies {
18+
implementation 'com.github.javaparser:javaparser-core:3.26.2'
19+
}

common-plugins/settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include("javaparser")

buildSrc/src/main/kotlin/com/commercetools/sdk/plugins/GraphQLTask.kt renamed to common-plugins/src/main/kotlin/com/commercetools/sdk/plugins/GraphQLTask.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.commercetools.sdk.plugins
22

3-
import com.github.javaparser.StaticJavaParser
4-
import com.github.javaparser.ast.CompilationUnit
5-
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration
6-
import com.github.javaparser.ast.body.ConstructorDeclaration
7-
import com.github.javaparser.ast.body.MethodDeclaration
8-
import com.github.javaparser.ast.body.TypeDeclaration
3+
import shadow.javaparser.StaticJavaParser
4+
import shadow.javaparser.ast.CompilationUnit
5+
import shadow.javaparser.ast.body.ClassOrInterfaceDeclaration
6+
import shadow.javaparser.ast.body.ConstructorDeclaration
7+
import shadow.javaparser.ast.body.MethodDeclaration
8+
import shadow.javaparser.ast.body.TypeDeclaration
99
import com.squareup.javapoet.*
1010
import org.gradle.api.DefaultTask
1111
import org.gradle.api.plugins.JavaPluginExtension

buildSrc/src/main/kotlin/com/commercetools/sdk/plugins/MigrationInfoPlugin.kt renamed to common-plugins/src/main/kotlin/com/commercetools/sdk/plugins/MigrationInfoPlugin.kt

+57-55
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.commercetools.sdk.plugins
22

3-
import com.github.javaparser.StaticJavaParser
4-
import com.github.javaparser.ast.CompilationUnit
5-
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration
6-
import com.github.javaparser.ast.body.TypeDeclaration
3+
import shadow.javaparser.StaticJavaParser
4+
import shadow.javaparser.ast.CompilationUnit
5+
import shadow.javaparser.ast.body.ClassOrInterfaceDeclaration
6+
import shadow.javaparser.ast.body.TypeDeclaration
77
import com.google.common.base.CaseFormat
88
import org.gradle.api.Plugin
99
import org.gradle.api.Project
10+
import shadow.javaparser.ast.body.MethodDeclaration
1011
import java.io.File
1112
import java.io.IOException
1213
import java.io.Writer
@@ -263,22 +264,22 @@ class MigrationInfoPlugin : Plugin<Project> {
263264

264265

265266

266-
// fun classInfo(file: File, info: ClassOrInterfaceDeclaration, hash: String): List<Pair<String, Map<String, String>>> {
267-
// return info.methods.map { methodInfo ->
268-
// "${info.fullyQualifiedName.get()}#${methodInfo.signature}" to mapOf(
269-
// "type" to "method",
270-
// "gitHash" to hash,
271-
// "methodName" to methodInfo.name.toString(),
272-
// "simpleName" to "${info.name}#${methodInfo.name}",
273-
// "name" to "${info.fullyQualifiedName.get()}#${methodInfo.name}",
274-
// "file" to file.toString(),
275-
// "start" to methodInfo.begin.get().line.toString(),
276-
// "end" to methodInfo.end.get().line.toString(),
277-
// "srcUrl" to "https://github.com/commercetools/commercetools-sdk-java-v2/blob/${hash}/${file}#L${methodInfo.begin.get().line}-L${methodInfo.end.get().line}",
278-
// "sdkV1Method" to methodInfo.methodBody()
279-
// )
280-
// }
281-
// }
267+
fun classInfo(file: File, info: ClassOrInterfaceDeclaration, hash: String): List<Pair<String, Map<String, String>>> {
268+
return info.methods.map { methodInfo ->
269+
"${info.fullyQualifiedName.get()}#${methodInfo.signature}" to mapOf(
270+
"type" to "method",
271+
"gitHash" to hash,
272+
"methodName" to methodInfo.name.toString(),
273+
"simpleName" to "${info.name}#${methodInfo.name}",
274+
"name" to "${info.fullyQualifiedName.get()}#${methodInfo.name}",
275+
"file" to file.toString(),
276+
"start" to methodInfo.begin.get().line.toString(),
277+
"end" to methodInfo.end.get().line.toString(),
278+
"srcUrl" to "https://github.com/commercetools/commercetools-sdk-java-v2/blob/${hash}/${file}#L${methodInfo.begin.get().line}-L${methodInfo.end.get().line}",
279+
"sdkV1Method" to methodInfo.methodBody()
280+
)
281+
}
282+
}
282283

283284
fun ClassOrInterfaceDeclaration.v2Class(v2BaseFolder: List<String>): String {
284285

@@ -326,33 +327,33 @@ class MigrationInfoPlugin : Plugin<Project> {
326327
return v2Classes.joinToString(", ");
327328
}
328329

329-
// fun ClassOrInterfaceDeclaration.v1CreateCommandClassUsage(): Pair<String, String> {
330-
//
331-
// if (commandClassUsageV1Mapping.containsKey(this.fullyQualifiedName.get())) {
332-
// return commandClassUsageV1Mapping.get(this.fullyQualifiedName.get()) ?: Pair("", "")
333-
// }
334-
// val v1PackageName = this.fullyQualifiedName.map { it.replace("." + this.name.toString(), "") }.get()
335-
// val v1ModelPackageName = v1PackageName.replace(".commands", "");
336-
//
337-
// return this.getMethodsByName("of").map { "$v1ModelPackageName.${it.parameters.filter { it.nameAsString.contains("draft", true) }.map { it.typeAsString }.firstOrNull() ?: "" }" to "of(${it.parameters.joinToString(",") { it.typeAsString }})" }.first()
338-
// }
339-
//
340-
// fun ClassOrInterfaceDeclaration.v1UpdateCommandClassUsage(): Pair<String, String> {
341-
//
342-
// if (commandClassUsageV1Mapping.containsKey(this.fullyQualifiedName.get())) {
343-
// return commandClassUsageV1Mapping.get(this.fullyQualifiedName.get()) ?: Pair("", "")
344-
// }
345-
//
346-
// return this.getMethodsByName("of").filter { it.parameters.any { it.typeAsString.startsWith("UpdateAction") } }.map { "" to "of(${it.parameters.joinToString(",") { it.typeAsString.split("<").first() + if (it.isVarArgs) "..." else "" }})" }.first()
347-
// }
348-
//
349-
// fun ClassOrInterfaceDeclaration.v1DeleteCommandClassUsage(): Pair<String, String> {
350-
//
351-
// if (commandClassUsageV1Mapping.containsKey(this.fullyQualifiedName.get())) {
352-
// return commandClassUsageV1Mapping.get(this.fullyQualifiedName.get()) ?: Pair("", "")
353-
// }
354-
// return this.getMethodsByName("of").filter { it.parameters.any { it.typeAsString.startsWith("Versioned") } }.map { "" to "of(${it.parameters.joinToString(",") { it.typeAsString.split("<").first() }})" }.firstOrNull() ?: Pair("", "")
355-
// }
330+
fun ClassOrInterfaceDeclaration.v1CreateCommandClassUsage(): Pair<String, String> {
331+
332+
if (commandClassUsageV1Mapping.containsKey(this.fullyQualifiedName.get())) {
333+
return commandClassUsageV1Mapping.get(this.fullyQualifiedName.get()) ?: Pair("", "")
334+
}
335+
val v1PackageName = this.fullyQualifiedName.map { it.replace("." + this.name.toString(), "") }.get()
336+
val v1ModelPackageName = v1PackageName.replace(".commands", "");
337+
338+
return this.getMethodsByName("of").map { "$v1ModelPackageName.${it.parameters.filter { it.nameAsString.contains("draft", true) }.map { it.typeAsString }.firstOrNull() ?: "" }" to "of(${it.parameters.joinToString(",") { it.typeAsString }})" }.first()
339+
}
340+
341+
fun ClassOrInterfaceDeclaration.v1UpdateCommandClassUsage(): Pair<String, String> {
342+
343+
if (commandClassUsageV1Mapping.containsKey(this.fullyQualifiedName.get())) {
344+
return commandClassUsageV1Mapping.get(this.fullyQualifiedName.get()) ?: Pair("", "")
345+
}
346+
347+
return this.getMethodsByName("of").filter { it.parameters.any { it.typeAsString.startsWith("UpdateAction") } }.map { "" to "of(${it.parameters.joinToString(",") { it.typeAsString.split("<").first() + if (it.isVarArgs) "..." else "" }})" }.first()
348+
}
349+
350+
fun ClassOrInterfaceDeclaration.v1DeleteCommandClassUsage(): Pair<String, String> {
351+
352+
if (commandClassUsageV1Mapping.containsKey(this.fullyQualifiedName.get())) {
353+
return commandClassUsageV1Mapping.get(this.fullyQualifiedName.get()) ?: Pair("", "")
354+
}
355+
return this.getMethodsByName("of").filter { it.parameters.any { it.typeAsString.startsWith("Versioned") } }.map { "" to "of(${it.parameters.joinToString(",") { it.typeAsString.split("<").first() }})" }.firstOrNull() ?: Pair("", "")
356+
}
356357

357358
fun ClassOrInterfaceDeclaration.v2CommandClassUsage(): String {
358359

@@ -486,17 +487,18 @@ class MigrationInfoPlugin : Plugin<Project> {
486487
"io.sphere.sdk.projects.commands.updateactions.ChangeMessages" to "removed",
487488
)
488489

489-
// fun MethodDeclaration.methodBody(): String {
490-
// val methodBody = this.body
491-
// if (!methodBody.isPresent) {
492-
// return ""
493-
// }
494-
// val bodyRange = methodBody.get().tokenRange.get().toString()
495-
// return bodyRange.substring(1, bodyRange.length - 1).trimIndent()
496-
// }
490+
fun MethodDeclaration.methodBody(): String {
491+
val methodBody = this.body
492+
if (!methodBody.isPresent) {
493+
return ""
494+
}
495+
val bodyRange = methodBody.get().tokenRange.get().toString()
496+
return bodyRange.substring(1, bodyRange.length - 1).trimIndent()
497+
}
497498
}
498499

499500
fun String.packageName(): String {
501+
CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, this)
500502
if (this.isEmpty() or this.contains(".").not()) return ""
501503
val packageFolder = Paths.get(this.replace(".", "/"))
502504
return packageFolder.parent.toString().replace("/", ".");

buildSrc/src/main/kotlin/com/commercetools/sdk/plugins/SrcInfoPlugin.kt renamed to common-plugins/src/main/kotlin/com/commercetools/sdk/plugins/SrcInfoPlugin.kt

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package com.commercetools.sdk.plugins;
22

3-
import com.github.javaparser.StaticJavaParser
4-
import com.github.javaparser.ast.CompilationUnit
5-
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration
6-
import com.github.javaparser.ast.body.MethodDeclaration
7-
import com.github.javaparser.ast.body.TypeDeclaration
8-
import com.github.javaparser.ast.expr.NormalAnnotationExpr
3+
import shadow.javaparser.ParserConfiguration.LanguageLevel
4+
import shadow.javaparser.ast.CompilationUnit
5+
import shadow.javaparser.ast.body.ClassOrInterfaceDeclaration
6+
import shadow.javaparser.ast.body.MethodDeclaration
7+
import shadow.javaparser.ast.body.TypeDeclaration
8+
import shadow.javaparser.ast.expr.NormalAnnotationExpr
99
import com.google.gson.stream.JsonWriter
1010
import org.gradle.api.Plugin
1111
import org.gradle.api.Project
12+
import shadow.javaparser.JavaParser
13+
import shadow.javaparser.ParserConfiguration
1214
import java.io.File
1315
import java.io.IOException
1416
import java.io.Writer
@@ -32,11 +34,14 @@ class SrcInfoPlugin : Plugin<Project> {
3234
private fun createExportTask(project: Project) {
3335
val extension = project.extensions.create("srcInfo", SrcInfoPluginExtension::class.java)
3436
val exportTask = project.task("exportSignatures")
37+
val parserConfiguration = ParserConfiguration()
38+
parserConfiguration.languageLevel = LanguageLevel.JAVA_17
39+
val javaParser = JavaParser(parserConfiguration)
3540
exportTask.group = "documentation"
3641
exportTask.doLast {
3742
val outputFolder = extension.outputFolder.map { o -> Paths.get(o) }.getOrElse(project.buildDir.resolve("src-info").toPath())
3843
val docsUrnOnly = extension.docsUrnOnly.getOrElse(false)
39-
outputFolder.toFile().mkdir()
44+
outputFolder.toFile().mkdirs()
4045
val javaFiles = project.fileTree(mapOf("dir" to extension.baseFolder.getOrElse("src"), "include" to "**/*.java")).files
4146
val fileWriter: Writer = Files.newBufferedWriter(outputFolder.resolve(project.name + ".json"))
4247
val writer = JsonWriter(fileWriter)
@@ -46,7 +51,7 @@ class SrcInfoPlugin : Plugin<Project> {
4651
writer.beginObject()
4752
javaFiles.forEach { file ->
4853
run {
49-
javaFileInfo(file, project, hash, extension.includePackages.orNull, docsUrnOnly).forEach { entry ->
54+
javaFileInfo(javaParser, file, project, hash, extension.includePackages.orNull, docsUrnOnly).forEach { entry ->
5055
run {
5156
writer.name(entry.key)
5257
writer.beginObject()
@@ -65,8 +70,9 @@ class SrcInfoPlugin : Plugin<Project> {
6570
}
6671
}
6772

68-
private fun javaFileInfo(file: File, project: Project, hash: String, includePackages: List<String>?, docsUrnOnly: Boolean): Map<String, Map<String, String>> {
69-
val parse: CompilationUnit = StaticJavaParser.parse(file)
73+
private fun javaFileInfo(javaParser: JavaParser, file: File, project: Project, hash: String, includePackages: List<String>?, docsUrnOnly: Boolean): Map<String, Map<String, String>> {
74+
val parse: CompilationUnit = javaParser.parse(file).result.get()
75+
7076
val relativeFile = file.relativeTo(project.rootDir)
7177
if (includePackages != null && includePackages.firstOrNull { s: String -> parse.packageDeclaration.get().nameAsString.startsWith(s) } == null) {
7278
return emptyMap()

gradle-scripts/subproject-config.gradle

-8
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ ext {
6060
buildInfoPackage = "io.vrap.rmf.base.client"
6161
}
6262

63-
srcInfo {
64-
includePackages = [
65-
"example",
66-
"commercetools"
67-
]
68-
docsUrnOnly = true
69-
}
70-
7163
tasks.register('integrationTest', Test) {
7264
description = "Runs integration tests."
7365
group = "verification"

gradle-scripts/subproject-plugins.gradle

-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@ apply plugin: 'idea'
22

33
apply plugin: 'java'
44
apply plugin: 'java-library' // needed to make sure that transitive deps have 'compile' scope
5-
6-
apply plugin: 'srcinfo'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apply plugin: 'srcinfo'
2+
3+
srcInfo {
4+
includePackages = [
5+
"example",
6+
"commercetools"
7+
]
8+
docsUrnOnly = true
9+
}

gradle/wrapper/gradle-wrapper.jar

-17.7 KB
Binary file not shown.
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
44
networkTimeout=10000
5+
validateDistributionUrl=true
56
zipStoreBase=GRADLE_USER_HOME
67
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)