Skip to content

Commit

Permalink
fix: Camel K CRD file extraction fails
Browse files Browse the repository at this point in the history
  • Loading branch information
igarashitm committed Sep 8, 2023
1 parent 144a741 commit cb5a9c3
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,27 @@ private void processCRDs(Path inputDir, Index index) {
}

private void processCRDFile(Path file, Index index) {
var splitted = file.getFileName().toString().split("\\.");
if (splitted.length < 2) {
getLog().error(new Exception("Invalid file name: " + file.getFileName()));
var dotSplitted = file.getFileName().toString().split("\\.");
if (dotSplitted.length < 4
|| !"camel".equalsIgnoreCase(dotSplitted[0])
|| !"apache".equalsIgnoreCase(dotSplitted[1])
|| !"yaml".equalsIgnoreCase(dotSplitted[3])) {
getLog().error(new Exception(
"Invalid Camel K CRD file name, it is expected to be"
+ "'camel.apache.org_<CRD name>.yaml', but it was: "
+ file.getFileName()));
return;
}
var underscoreSplitted = dotSplitted[2].split("_");
if (underscoreSplitted.length < 2 || !"org".equals(underscoreSplitted[0])) {
getLog().error(new Exception(
"Invalid Camel K CRD file name, it is expected to be"
+ "'camel.apache.org_<CRD name>.yaml', but it was: "
+ file.getFileName()));
return;
}
var outputFileName = String.format(
"%s-%s-%s.json", CRD_SCHEMA, splitted[0], camelKCRDVersion);
"%s-%s-%s.json", CRD_SCHEMA, underscoreSplitted[1], camelKCRDVersion);
var output = outputDirectory.toPath().resolve(outputFileName);
try {
var crd = yamlMapper.readValue(file.toFile(), CustomResourceDefinition.class);
Expand Down

0 comments on commit cb5a9c3

Please sign in to comment.