|
1 | 1 | package com.commercetools.sdk.plugins
|
2 | 2 |
|
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 |
7 | 7 | import com.google.common.base.CaseFormat
|
8 | 8 | import org.gradle.api.Plugin
|
9 | 9 | import org.gradle.api.Project
|
| 10 | +import shadow.javaparser.ast.body.MethodDeclaration |
10 | 11 | import java.io.File
|
11 | 12 | import java.io.IOException
|
12 | 13 | import java.io.Writer
|
@@ -263,22 +264,22 @@ class MigrationInfoPlugin : Plugin<Project> {
|
263 | 264 |
|
264 | 265 |
|
265 | 266 |
|
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 | + } |
282 | 283 |
|
283 | 284 | fun ClassOrInterfaceDeclaration.v2Class(v2BaseFolder: List<String>): String {
|
284 | 285 |
|
@@ -326,33 +327,33 @@ class MigrationInfoPlugin : Plugin<Project> {
|
326 | 327 | return v2Classes.joinToString(", ");
|
327 | 328 | }
|
328 | 329 |
|
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 | + } |
356 | 357 |
|
357 | 358 | fun ClassOrInterfaceDeclaration.v2CommandClassUsage(): String {
|
358 | 359 |
|
@@ -486,17 +487,18 @@ class MigrationInfoPlugin : Plugin<Project> {
|
486 | 487 | "io.sphere.sdk.projects.commands.updateactions.ChangeMessages" to "removed",
|
487 | 488 | )
|
488 | 489 |
|
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 | + } |
497 | 498 | }
|
498 | 499 |
|
499 | 500 | fun String.packageName(): String {
|
| 501 | + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, this) |
500 | 502 | if (this.isEmpty() or this.contains(".").not()) return ""
|
501 | 503 | val packageFolder = Paths.get(this.replace(".", "/"))
|
502 | 504 | return packageFolder.parent.toString().replace("/", ".");
|
|
0 commit comments