void camelBits()

in tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CheckExtensionPagesMojo.java [108:152]


    void camelBits(Path docsBasePath) {
        final CqCatalog cqCatalog = new CqCatalog(catalogBaseDir.toPath(), Flavor.camelQuarkus);

        final Path referenceDir = docsBasePath.resolve("modules/ROOT/examples");
        try (GavCqCatalog camelCatalog = GavCqCatalog.open(Paths.get(localRepository), Flavor.camel, camelVersion)) {

            CqCatalog.kinds().forEach(kind -> {
                final Set<String> cqNames = cqCatalog.models(kind)
                        .filter(CqCatalog::isFirstScheme)
                        .map(CqCatalog::toCamelDocsModel)
                        .map(ArtifactModel::getName)
                        .collect(Collectors.toSet());
                final Set<String> camelNames = camelCatalog.models(kind)
                        .filter(CqCatalog::isFirstScheme)
                        .map(CqCatalog::toCamelDocsModel)
                        .map(ArtifactModel::getName)
                        .collect(Collectors.toSet());

                final Path kindDir = referenceDir.resolve(CqUtils.kindPlural(kind));
                try {
                    Files.createDirectories(kindDir);
                } catch (IOException e) {
                    throw new RuntimeException("Could not create " + kindDir, e);
                }
                try (Stream<Path> kindFiles = Files.list(kindDir)) {
                    kindFiles.forEach(kindFile -> {
                        final String artifactIdBase = YML_ENDING_PATTERN.matcher(kindFile.getFileName().toString())
                                .replaceAll("");
                        if (cqNames.contains(artifactIdBase)) {
                            /* Nothing to do, this should have been done by UpdateExtensionDocPageMojo */
                        } else {
                            try {
                                Files.delete(kindFile);
                            } catch (IOException e) {
                                throw new RuntimeException("Could not delete " + kindFile, e);
                            }
                        }
                    });
                } catch (IOException e) {
                    throw new RuntimeException("Could not list " + kindDir, e);
                }
            });
        }

    }