in tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PrepareCatalogQuarkusMojo.java [79:172]
public void execute() throws MojoExecutionException, MojoFailureException {
final Path catalogPath = catalogBaseDir.toPath().resolve(CqCatalog.CQ_CATALOG_DIR);
final Map<String, Set<String>> schemesByKind = new LinkedHashMap<>();
CqCatalog.kinds().forEach(kind -> schemesByKind.put(kind.name(), new TreeSet<>()));
final CqCatalog catalog = CqCatalog.findFirstFromClassPath();
if (extendClassPathCatalog) {
catalog.store(catalogBaseDir.toPath());
catalog.models().forEach(model -> schemesByKind.get(model.getKind()).add(model.getName()));
}
findExtensions()
.forEach(ext -> {
final String artifactIdBase = ext.getArtifactIdBase();
final Path schemaFile = ext
.getExtensionDir()
.resolve("component/src/generated/resources/org/apache/camel/component/"
+ artifactIdBase + "/" + artifactIdBase + ".json")
.toAbsolutePath().normalize();
if (Files.isRegularFile(schemaFile)) {
try {
final String schema = new String(Files.readAllBytes(schemaFile),
StandardCharsets.UTF_8);
final String capBase = artifactIdBase.substring(0, 1).toUpperCase()
+ artifactIdBase.substring(1);
getLog().debug("Adding an extra component " + artifactIdBase + " " +
"org.apache.camel.component." + artifactIdBase + "." + capBase + "Component " +
schema);
catalog.addComponent(artifactIdBase,
"org.apache.camel.component." + artifactIdBase + "." + capBase + "Component",
schema);
} catch (IOException e) {
throw new RuntimeException("Could not read " + schemaFile, e);
}
}
});
findExtensions()
.forEach(extPath -> {
final String artifactIdBase = extPath.getArtifactIdBase();
final List<ArtifactModel<?>> models = catalog.filterModels(artifactIdBase)
.collect(Collectors.toList());
final Path runtimePomXmlPath = extPath
.getExtensionDir().resolve("runtime/pom.xml")
.toAbsolutePath().normalize();
final CamelQuarkusExtension ext = CamelQuarkusExtension.read(runtimePomXmlPath);
final boolean nativeSupported = ext.isNativeSupported();
if (models.isEmpty()) {
final ArtifactModel<?> model;
final Kind extKind = ext.getKind();
if (extKind == Kind.component) {
model = new ComponentModel();
} else if (extKind == Kind.language) {
model = new LanguageModel();
} else if (extKind == Kind.dataformat) {
model = new DataFormatModel();
} else {
model = new OtherModel();
}
final String name = ext.getRuntimeArtifactId().replace("camel-quarkus-", "");
model.setName(name);
final String title = ext.getName().orElseThrow(() -> new RuntimeException(
"name is missing in " + ext.getRuntimePomXmlPath()));
model.setTitle(title);
model.setDescription(ext.getDescription().orElseThrow(() -> new RuntimeException(
"description is missing in " + ext.getRuntimePomXmlPath())));
model.setDeprecated(CqUtils.isDeprecated(title, models, ext.isDeprecated()));
model.setLabel(ext.getLabel().orElse("quarkus"));
update(model, ext, nativeSupported, quarkusVersion);
CqCatalog.serialize(catalogPath, model);
schemesByKind.get(model.getKind()).add(model.getName());
} else {
for (ArtifactModel<?> model : models) {
update(model, ext, nativeSupported, quarkusVersion);
CqCatalog.serialize(catalogPath, model);
schemesByKind.get(model.getKind()).add(model.getName());
}
}
});
CqCatalog.kinds().forEach(kind -> {
final Path newCatalog = catalogPath.resolve(kind.name() + "s.properties");
try {
Files.createDirectories(newCatalog.getParent());
Files.write(newCatalog,
schemesByKind.get(kind.name()).stream().collect(Collectors.joining("\n"))
.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new RuntimeException("Could not write to " + newCatalog);
}
});
}