|
9 | 9 |
|
10 | 10 | import java.io.File; |
11 | 11 | import java.io.FileNotFoundException; |
| 12 | +import java.net.URI; |
12 | 13 | import java.net.URISyntaxException; |
| 14 | +import java.net.URL; |
13 | 15 | import java.nio.file.Path; |
14 | 16 | import java.nio.file.Paths; |
15 | 17 | import java.util.List; |
16 | 18 | import java.util.Map; |
| 19 | +import java.util.Objects; |
17 | 20 | import java.util.Optional; |
18 | 21 | import java.util.stream.Collectors; |
19 | 22 |
|
@@ -760,15 +763,34 @@ private OpenApiClientGeneratorWrapper createGeneratorWrapper(String specFileName |
760 | 763 | } |
761 | 764 |
|
762 | 765 | private Path getOpenApiSpecPath(String specFileName) throws URISyntaxException { |
763 | | - return Path.of(requireNonNull(this.getClass().getResource(String.format("/openapi/%s", specFileName))).toURI()); |
| 766 | + URL url = this.getClass().getResource("/openapi/" + specFileName); |
| 767 | + Objects.requireNonNull(url, "Could not find /openapi/" + specFileName); |
| 768 | + |
| 769 | + URI uri; |
| 770 | + try { |
| 771 | + uri = url.toURI(); |
| 772 | + } catch (URISyntaxException e) { |
| 773 | + // this should never happen for a well-formed file URL |
| 774 | + throw new RuntimeException("Invalid URI for " + url, e); |
| 775 | + } |
| 776 | + |
| 777 | + return Paths.get(uri); |
764 | 778 | } |
765 | 779 |
|
766 | 780 | private Path getOpenApiTargetPath(Path openApiSpec) throws URISyntaxException { |
767 | 781 | return Paths.get(getTargetDir(), "openapi-gen"); |
768 | 782 | } |
769 | 783 |
|
770 | | - private String getTargetDir() throws URISyntaxException { |
771 | | - return Paths.get(requireNonNull(getClass().getResource("/")).toURI()).getParent().toString(); |
| 784 | + private String getTargetDir() { |
| 785 | + URL url = requireNonNull(getClass().getResource("/"), |
| 786 | + "Could not locate classpath root"); |
| 787 | + try { |
| 788 | + return Paths.get(url.toURI()) |
| 789 | + .getParent() |
| 790 | + .toString(); |
| 791 | + } catch (URISyntaxException e) { |
| 792 | + throw new RuntimeException("Invalid URI for " + url, e); |
| 793 | + } |
772 | 794 | } |
773 | 795 |
|
774 | 796 | private Optional<VariableDeclarator> findVariableByName(List<FieldDeclaration> fields, String name) { |
|
0 commit comments