Skip to content

Commit b07173f

Browse files
committed
Clean up
Signed-off-by: Ricardo Zanini <[email protected]>
1 parent 11ccea7 commit b07173f

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiGeneratorCodeGenBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public boolean trigger(CodeGenContext context) throws CodeGenException {
5454
}
5555

5656
protected void generate(CodeGenContext context, final Path openApiFilePath, final Path outDir) {
57+
// TODO: do not generate with the output dir has generated files and the openapi file has the same checksum of the previous runz
5758
final OpenApiClientGeneratorWrapper generator = new OpenApiClientGeneratorWrapper(
5859
openApiFilePath.normalize(), outDir)
5960
.withCircuitBreakerConfiguration(CircuitBreakerConfigurationParser.parse(

deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiGeneratorStreamCodeGen.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.io.FileOutputStream;
44
import java.io.IOException;
5-
import java.io.InputStream;
65
import java.io.UncheckedIOException;
76
import java.nio.channels.Channels;
87
import java.nio.channels.ReadableByteChannel;
@@ -11,8 +10,6 @@
1110
import java.util.List;
1211
import java.util.ServiceLoader;
1312
import java.util.stream.Collectors;
14-
import java.util.zip.CRC32;
15-
import java.util.zip.CheckedInputStream;
1613

1714
import org.eclipse.microprofile.config.Config;
1815
import org.slf4j.Logger;
@@ -28,14 +25,16 @@ public class OpenApiGeneratorStreamCodeGen extends OpenApiGeneratorCodeGenBase {
2825
private static final Logger LOGGER = LoggerFactory.getLogger(OpenApiGeneratorStreamCodeGen.class);
2926

3027
private List<OpenApiSpecInputProvider> providers;
28+
private final ServiceLoader<OpenApiSpecInputProvider> loader;
3129

3230
public OpenApiGeneratorStreamCodeGen() {
33-
31+
loader = ServiceLoader.load(OpenApiSpecInputProvider.class);
3432
}
3533

3634
private void loadServices() {
37-
final ServiceLoader<OpenApiSpecInputProvider> loader = ServiceLoader.load(OpenApiSpecInputProvider.class);
35+
loader.reload();
3836
providers = loader.stream().map(ServiceLoader.Provider::get).collect(Collectors.toList());
37+
LOGGER.debug("Loaded {} OpenApiSpecInputProviders", providers);
3938
}
4039

4140
@Override
@@ -62,14 +61,15 @@ public boolean trigger(CodeGenContext context) throws CodeGenException {
6261

6362
for (final OpenApiSpecInputProvider provider : this.providers) {
6463
for (SpecInputModel inputModel : provider.read()) {
64+
LOGGER.debug("Processing OpenAPI spec input model {}", inputModel);
6565
if (inputModel == null) {
6666
throw new CodeGenException("SpecInputModel from provider " + provider + " is null");
6767
}
68-
// TODO: in the future, we can use the checksum to not generate the stub files again
6968
final Path openApiFilePath = Paths.get(outDir.toString(), inputModel.getFileName());
7069
try (ReadableByteChannel channel = Channels.newChannel(inputModel.getInputStream());
7170
FileOutputStream output = new FileOutputStream(openApiFilePath.toString())) {
7271
output.getChannel().transferFrom(channel, 0, Integer.MAX_VALUE);
72+
LOGGER.debug("Saved OpenAPI spec input model in {}", openApiFilePath);
7373
this.generate(context, openApiFilePath, outDir);
7474
generated = true;
7575
} catch (IOException e) {
@@ -81,21 +81,6 @@ public boolean trigger(CodeGenContext context) throws CodeGenException {
8181
return generated;
8282
}
8383

84-
private String generateChecksumCRC32(final InputStream is) {
85-
CheckedInputStream checkedInputStream = new CheckedInputStream(is, new CRC32());
86-
byte[] buffer = new byte[2048];
87-
while (true) {
88-
try {
89-
if (checkedInputStream.read(buffer, 0, buffer.length) < 0) {
90-
break;
91-
}
92-
} catch (IOException e) {
93-
throw new UncheckedIOException("Fail to calculate checksum for InputStream", e);
94-
}
95-
}
96-
return String.valueOf(checkedInputStream.getChecksum().getValue());
97-
}
98-
9984
@Override
10085
public boolean shouldRun(Path sourceDir, Config config) {
10186
this.loadServices();

0 commit comments

Comments
 (0)