Skip to content

Commit

Permalink
Workaround + fixed generator/resolver of bean catalog in maven-plugin (
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriOndrusek authored Sep 26, 2024
1 parent de68f20 commit bd3f81d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public CqCatalog(Path baseDir, Flavor flavor) {

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;
Expand Down Expand Up @@ -197,6 +198,8 @@ static void serialize(final Path catalogPath, ArtifactModel<?> model) {
switch (model.getKind()) {
case bean:
rawJson = JsonMapper.createParameterJsonSchema((PojoBeanModel) model);
//workaround
rawJson = rawJson.replace("model", "bean");
break;
case component:
rawJson = JsonMapper.createParameterJsonSchema((ComponentModel) model);
Expand Down Expand Up @@ -346,6 +349,7 @@ static class CqRuntimeProvider implements RuntimeProvider {
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;
Expand Down Expand Up @@ -438,6 +442,10 @@ protected String getOtherCatalog() {
return OTHER_CATALOG;
}

protected String getBeansCatalog() {
return BEANS_CATALOG;
}

protected String getCapabilitiesCatalog() {
return CAPABILITIES_CATALOG;
}
Expand Down Expand Up @@ -529,7 +537,7 @@ public List<String> findOtherNames() {
@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);
Expand Down Expand Up @@ -586,4 +594,20 @@ public void close() {
}
}

/**
* 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");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
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()
Expand Down

0 comments on commit bd3f81d

Please sign in to comment.