|
37 | 37 | import java.util.Map;
|
38 | 38 | import java.util.Scanner;
|
39 | 39 | import java.util.Set;
|
| 40 | +import java.util.StringJoiner; |
40 | 41 | import java.util.TreeMap;
|
41 | 42 | import java.util.concurrent.locks.ReentrantLock;
|
42 | 43 | import java.util.prefs.BackingStoreException;
|
@@ -352,7 +353,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
|
352 | 353 | Scan the paths of all the operations, computing the longest common prefix. Then compute and set the path suffix
|
353 | 354 | for each operation.
|
354 | 355 | */
|
355 |
| - String commonPathPrefixForApi = StringUtils.getCommonPrefix(objs.getOperations().getOperation() |
| 356 | + String commonPathPrefixForApi = commonPathPrefix(objs.getOperations().getOperation() |
356 | 357 | .stream()
|
357 | 358 | .map(op -> op.path)
|
358 | 359 | .map(path -> path.charAt(0) != '/' ? "/" + path : path )
|
@@ -450,6 +451,46 @@ protected String rootJavaEEPackage() {
|
450 | 451 | return rootJavaEEPackage;
|
451 | 452 | }
|
452 | 453 |
|
| 454 | + static String commonPathPrefix(String[] paths) { |
| 455 | + |
| 456 | + if (paths.length == 0) { |
| 457 | + return "/"; |
| 458 | + } |
| 459 | + |
| 460 | + // Start out with the first path as the longest common prefix. The eventual longest common |
| 461 | + // prefix can be no longer than the first path, so as we check other paths we simply |
| 462 | + // revise the number of matching segments we have. |
| 463 | + String[] commonSegments = stripAnyLeadingSlash(paths[0]).split("/"); |
| 464 | + int commonSegmentsCount = commonSegments.length; |
| 465 | + |
| 466 | + // Examine the remaining paths. |
| 467 | + for (int i = 1; i < paths.length; i++) { |
| 468 | + String[] segments = stripAnyLeadingSlash(paths[i]).split("/"); |
| 469 | + |
| 470 | + // Check each segment of this next path against the common segments we have so far. |
| 471 | + int segmentIndex = 0; |
| 472 | + while (segmentIndex < Math.min(commonSegmentsCount, segments.length) |
| 473 | + && commonSegments[segmentIndex].equals(segments[segmentIndex])) { |
| 474 | + segmentIndex++; |
| 475 | + } |
| 476 | + commonSegmentsCount = segmentIndex; |
| 477 | + if (commonSegmentsCount == 0) { |
| 478 | + break; |
| 479 | + } |
| 480 | + } |
| 481 | + StringJoiner commonPath = new StringJoiner("/", "/", ""); |
| 482 | + commonPath.setEmptyValue("/"); |
| 483 | + |
| 484 | + for (int i = 0; i < commonSegmentsCount; i++) { |
| 485 | + commonPath.add(commonSegments[i]); |
| 486 | + } |
| 487 | + return commonPath.toString(); |
| 488 | + } |
| 489 | + |
| 490 | + private static String stripAnyLeadingSlash(String path) { |
| 491 | + return path.startsWith("/") ? path.substring(1) : path; |
| 492 | + } |
| 493 | + |
453 | 494 | /**
|
454 | 495 | * Prepares a map of predefined HTTP status code constants.
|
455 | 496 | * <p>
|
@@ -716,9 +757,9 @@ static class VersionUtil {
|
716 | 757 |
|
717 | 758 | private static final String DEFAULT_VERSIONS = "<data>\n" +
|
718 | 759 | " <archetypes>\n" +
|
719 |
| - " <version>2.6.5</version>\n" + |
720 |
| - " <version>3.2.7</version>\n" + |
721 |
| - " <version>4.0.9</version>\n" + |
| 760 | + " <version>2.6.10</version>\n" + |
| 761 | + " <version>3.2.11</version>\n" + |
| 762 | + " <version>4.1.4</version>\n" + |
722 | 763 | " </archetypes>\n" +
|
723 | 764 | "</data>";
|
724 | 765 |
|
|
0 commit comments