This is an automated email from the ASF dual-hosted git repository.

zhfeng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/main by this push:
     new bd3f81d7d5 Workaround + fixed generator/resolver of bean catalog in 
maven-plugin (#6554)
bd3f81d7d5 is described below

commit bd3f81d7d50a545843aeb179f5e529b32b92b158
Author: JiriOndrusek <ondrusek.j...@gmail.com>
AuthorDate: Fri Sep 27 01:48:13 2024 +0200

    Workaround + fixed generator/resolver of bean catalog in maven-plugin 
(#6554)
---
 .../org/apache/camel/quarkus/maven/CqCatalog.java  | 28 ++++++++++++++++++++--
 .../quarkus/maven/PrepareCatalogQuarkusMojo.java   |  2 +-
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git 
a/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqCatalog.java
 
b/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqCatalog.java
index 415c2c465a..613c885de4 100644
--- 
a/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqCatalog.java
+++ 
b/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqCatalog.java
@@ -120,7 +120,8 @@ public class CqCatalog {
 
     public CqCatalog(Flavor flavor, Function<String, InputStream> 
resourceLocator) {
         this.flavor = flavor;
-        final DefaultCamelCatalog c = new DefaultCamelCatalog(true);
+        // workaround for catalog `beans/*.json`, see comment on 
BeansWorkaroundCustomCatalog for more information
+        final DefaultCamelCatalog c = new BeansWorkaroundCustomCatalog(true);
         c.setRuntimeProvider(flavor.createRuntimeProvider(c));
         c.setVersionManager(new CqVersionManager(c, resourceLocator));
         this.catalog = c;
@@ -197,6 +198,8 @@ public class CqCatalog {
         switch (model.getKind()) {
         case bean:
             rawJson = JsonMapper.createParameterJsonSchema((PojoBeanModel) 
model);
+            //workaround
+            rawJson = rawJson.replace("model", "bean");
             break;
         case component:
             rawJson = JsonMapper.createParameterJsonSchema((ComponentModel) 
model);
@@ -346,6 +349,7 @@ public class CqCatalog {
         private static final String LANGUAGE_CATALOG = CQ_CATALOG_DIR + 
"/languages.properties";
         private static final String TRANSFORMER_CATALOG = CQ_CATALOG_DIR + 
"/transformers.properties";
         private static final String OTHER_CATALOG = CQ_CATALOG_DIR + 
"/others.properties";
+        private static final String BEANS_CATALOG = CQ_CATALOG_DIR + 
"/beans.properties";
         private static final String CAPABILITIES_CATALOG = 
"org/apache/camel/catalog/capabilities.properties";
 
         private CamelCatalog camelCatalog;
@@ -438,6 +442,10 @@ public class CqCatalog {
             return OTHER_CATALOG;
         }
 
+        protected String getBeansCatalog() {
+            return BEANS_CATALOG;
+        }
+
         protected String getCapabilitiesCatalog() {
             return CAPABILITIES_CATALOG;
         }
@@ -529,7 +537,7 @@ public class CqCatalog {
         @Override
         public List<String> findBeansNames() {
             List<String> names = new ArrayList<>();
-            InputStream is = 
getCamelCatalog().getVersionManager().getResourceAsStream(getPojoBeanJSonSchemaDirectory());
+            InputStream is = 
getCamelCatalog().getVersionManager().getResourceAsStream(getBeansCatalog());
             if (is != null) {
                 try {
                     CatalogHelper.loadLines(is, names);
@@ -586,4 +594,20 @@ public class CqCatalog {
         }
     }
 
+    /**
+     * Prior https://github.com/apache/camel/pull/15708, the catalog files 
from `beans/*json` might have contained
+     * attribute `model` instead of `bean`. This custom catalog is fixing the 
json, to be parsable by Camel
+     * tooling.
+     */
+    public static class BeansWorkaroundCustomCatalog extends 
DefaultCamelCatalog {
+        public BeansWorkaroundCustomCatalog(boolean caching) {
+            super(caching);
+        }
+
+        @Override
+        public String pojoBeanJSonSchema(String name) {
+            return 
getJSonSchemaResolver().getPojoBeanJSonSchema(name).replace("model", "bean");
+        }
+    }
+
 }
diff --git 
a/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PrepareCatalogQuarkusMojo.java
 
b/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PrepareCatalogQuarkusMojo.java
index 74a853567d..22726478d9 100644
--- 
a/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PrepareCatalogQuarkusMojo.java
+++ 
b/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PrepareCatalogQuarkusMojo.java
@@ -88,7 +88,7 @@ public class PrepareCatalogQuarkusMojo extends 
AbstractExtensionListMojo {
         final CqCatalog catalog = CqCatalog.findFirstFromClassPath();
         if (extendClassPathCatalog) {
             catalog.store(catalogBaseDir.toPath());
-            catalog.models().forEach(model -> 
schemesByKind.get(model.getKind()).add(model.getName()));
+            catalog.models().forEach(model -> 
schemesByKind.get(model.getKind().name()).add(model.getName()));
         }
 
         findExtensions()

Reply via email to