in extensions/grpc/codegen/src/main/java/org/apache/camel/quarkus/grpc/codegen/CamelQuarkusGrpcCodegenProvider.java [282:328]
private void extractProtosFromArtifact(Path workDir, Collection<Path> protoFiles,
Set<String> protoDirectories, ResolvedDependency artifact, Collection<String> filesToInclude,
Collection<String> filesToExclude, boolean isDependency) throws CodeGenException {
try {
artifact.getContentTree(new PathFilter(filesToInclude, filesToExclude)).walk(
pathVisit -> {
Path path = pathVisit.getPath();
if (Files.isRegularFile(path) && path.getFileName().toString().endsWith(PROTO)) {
Path root = pathVisit.getRoot();
if (Files.isDirectory(root)) {
protoFiles.add(path);
protoDirectories.add(path.getParent().normalize().toAbsolutePath().toString());
} else { // archive
Path relativePath = path.getRoot().relativize(path);
Path protoUnzipDir = workDir
.resolve(HashUtil.sha1(root.normalize().toAbsolutePath().toString()))
.normalize().toAbsolutePath();
try {
Files.createDirectories(protoUnzipDir);
protoDirectories.add(protoUnzipDir.toString());
} catch (IOException e) {
throw new GrpcCodeGenException("Failed to create directory: " + protoUnzipDir, e);
}
Path outPath = protoUnzipDir;
for (Path part : relativePath) {
outPath = outPath.resolve(part.toString());
}
try {
Files.createDirectories(outPath.getParent());
if (isDependency) {
copySanitizedProtoFile(artifact, path, outPath);
} else {
Files.copy(path, outPath, StandardCopyOption.REPLACE_EXISTING);
}
protoFiles.add(outPath);
} catch (IOException e) {
throw new GrpcCodeGenException("Failed to extract proto file" + path + " to target: "
+ outPath, e);
}
}
}
});
} catch (GrpcCodeGenException e) {
throw new CodeGenException(e.getMessage(), e);
}
}