Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround + fixed generator/resolver of bean catalog in maven-plugin #6554

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading