use of org.apache.camel.maven.packaging.model.ComponentModel in project camel by apache.
the class UpdateReadmeMojo method executeComponent.
private void executeComponent() throws MojoExecutionException, MojoFailureException {
// find the component names
List<String> componentNames = findComponentNames();
final Set<File> jsonFiles = new TreeSet<File>();
PackageHelper.findJsonFiles(buildDir, jsonFiles, new PackageHelper.CamelComponentsModelFilter());
// only if there is components we should update the documentation files
if (!componentNames.isEmpty()) {
getLog().debug("Found " + componentNames.size() + " components");
for (String componentName : componentNames) {
String json = loadComponentJson(jsonFiles, componentName);
if (json != null) {
// special for some components
componentName = asComponentName(componentName);
File file = new File(docDir, componentName + "-component.adoc");
ComponentModel model = generateComponentModel(componentName, json);
String title = asComponentTitle(model.getScheme(), model.getTitle());
model.setTitle(title);
// we only want the first scheme as the alternatives do not have their own readme file
if (!isEmpty(model.getAlternativeSchemes())) {
String first = model.getAlternativeSchemes().split(",")[0];
if (!model.getScheme().equals(first)) {
continue;
}
}
String docTitle = model.getTitle() + " Component";
boolean deprecated = "true".equals(model.getDeprecated());
if (deprecated) {
docTitle += " (deprecated)";
}
boolean exists = file.exists();
boolean updated;
updated = updateTitles(file, docTitle);
updated |= updateAvailableFrom(file, model.getFirstVersion());
// resolvePropertyPlaceholders is an option which only make sense to use if the component has other options
boolean hasOptions = model.getComponentOptions().stream().anyMatch(o -> !o.getName().equals("resolvePropertyPlaceholders"));
if (!hasOptions) {
model.getComponentOptions().clear();
}
String options = templateComponentOptions(model);
updated |= updateComponentOptions(file, options);
options = templateEndpointOptions(model);
updated |= updateEndpointOptions(file, options);
if (updated) {
getLog().info("Updated doc file: " + file);
} else if (exists) {
getLog().debug("No changes to doc file: " + file);
} else {
getLog().warn("No component doc file: " + file);
if (isFailFast()) {
throw new MojoExecutionException("Failed build due failFast=true");
}
}
}
}
}
}
use of org.apache.camel.maven.packaging.model.ComponentModel in project camel by apache.
the class PrepareReadmeMojo method generateComponentModel.
private ComponentModel generateComponentModel(String json, boolean coreOnly) {
List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("component", json, false);
ComponentModel component = new ComponentModel(coreOnly);
component.setScheme(JSonSchemaHelper.getSafeValue("scheme", rows));
component.setSyntax(JSonSchemaHelper.getSafeValue("syntax", rows));
component.setAlternativeSyntax(JSonSchemaHelper.getSafeValue("alternativeSyntax", rows));
component.setAlternativeSchemes(JSonSchemaHelper.getSafeValue("alternativeSchemes", rows));
component.setTitle(JSonSchemaHelper.getSafeValue("title", rows));
component.setDescription(JSonSchemaHelper.getSafeValue("description", rows));
component.setFirstVersion(JSonSchemaHelper.getSafeValue("firstVersion", rows));
component.setLabel(JSonSchemaHelper.getSafeValue("label", rows));
component.setDeprecated(JSonSchemaHelper.getSafeValue("deprecated", rows));
component.setConsumerOnly(JSonSchemaHelper.getSafeValue("consumerOnly", rows));
component.setProducerOnly(JSonSchemaHelper.getSafeValue("producerOnly", rows));
component.setJavaType(JSonSchemaHelper.getSafeValue("javaType", rows));
component.setGroupId(JSonSchemaHelper.getSafeValue("groupId", rows));
component.setArtifactId(JSonSchemaHelper.getSafeValue("artifactId", rows));
component.setVersion(JSonSchemaHelper.getSafeValue("version", rows));
return component;
}
use of org.apache.camel.maven.packaging.model.ComponentModel in project camel by apache.
the class PrepareUserGuideMojo method executeComponents.
protected void executeComponents() throws MojoExecutionException, MojoFailureException {
Set<File> componentFiles = new TreeSet<>();
if (componentsDir != null && componentsDir.isDirectory()) {
File[] files = componentsDir.listFiles();
if (files != null) {
componentFiles.addAll(Arrays.asList(files));
}
}
try {
List<ComponentModel> models = new ArrayList<>();
for (File file : componentFiles) {
String json = loadText(new FileInputStream(file));
ComponentModel model = generateComponentModel(json);
// filter out alternative schemas which reuses documentation
boolean add = true;
if (!model.getAlternativeSchemes().isEmpty()) {
String first = model.getAlternativeSchemes().split(",")[0];
if (!model.getScheme().equals(first)) {
add = false;
}
}
if (add) {
models.add(model);
}
}
// sor the models
Collections.sort(models, new ComponentComparator());
// the summary file has the TOC
File file = new File(userGuideDir, "SUMMARY.md");
// update core components
StringBuilder core = new StringBuilder();
core.append("* Core Components\n");
for (ComponentModel model : models) {
if (model.getLabel().contains("core")) {
String line = "\t* " + link(model) + "\n";
core.append(line);
}
}
boolean updated = updateCoreComponents(file, core.toString());
// update regular components
StringBuilder regular = new StringBuilder();
regular.append("* Components\n");
for (ComponentModel model : models) {
if (!model.getLabel().contains("core")) {
String line = "\t* " + link(model) + "\n";
regular.append(line);
}
}
updated |= updateComponents(file, regular.toString());
if (updated) {
getLog().info("Updated user guide file: " + file);
} else {
getLog().debug("No changes to user guide file: " + file);
}
} catch (IOException e) {
throw new MojoFailureException("Error due " + e.getMessage(), e);
}
}
use of org.apache.camel.maven.packaging.model.ComponentModel in project camel by apache.
the class UpdateReadmeMojo method generateComponentModel.
private ComponentModel generateComponentModel(String componentName, String json) {
List<Map<String, String>> rows = parseJsonSchema("component", json, false);
ComponentModel component = new ComponentModel(true);
component.setScheme(getSafeValue("scheme", rows));
component.setSyntax(getSafeValue("syntax", rows));
component.setAlternativeSyntax(getSafeValue("alternativeSyntax", rows));
component.setAlternativeSchemes(getSafeValue("alternativeSchemes", rows));
component.setTitle(getSafeValue("title", rows));
component.setDescription(getSafeValue("description", rows));
component.setFirstVersion(getSafeValue("firstVersion", rows));
component.setLabel(getSafeValue("label", rows));
component.setDeprecated(getSafeValue("deprecated", rows));
component.setConsumerOnly(getSafeValue("consumerOnly", rows));
component.setProducerOnly(getSafeValue("producerOnly", rows));
component.setJavaType(getSafeValue("javaType", rows));
component.setGroupId(getSafeValue("groupId", rows));
component.setArtifactId(getSafeValue("artifactId", rows));
component.setVersion(getSafeValue("version", rows));
String oldGroup = null;
rows = parseJsonSchema("componentProperties", json, true);
for (Map<String, String> row : rows) {
ComponentOptionModel option = new ComponentOptionModel();
option.setName(getSafeValue("name", row));
option.setDisplayName(getSafeValue("displayName", row));
option.setKind(getSafeValue("kind", row));
option.setGroup(getSafeValue("group", row));
option.setRequired(getSafeValue("required", row));
option.setType(getSafeValue("type", row));
option.setJavaType(getSafeValue("javaType", row));
option.setEnums(getSafeValue("enum", row));
option.setDeprecated(getSafeValue("deprecated", row));
option.setSecret(getSafeValue("secret", row));
option.setDefaultValue(getSafeValue("defaultValue", row));
option.setDescription(getSafeValue("description", row));
// lets put required in the description
if ("true".equals(option.getRequired())) {
String desc = "*Required* " + option.getDescription();
option.setDescription(desc);
}
component.addComponentOption(option);
// group separate between different options
if (oldGroup == null || !oldGroup.equals(option.getGroup())) {
option.setNewGroup(true);
}
oldGroup = option.getGroup();
}
oldGroup = null;
rows = parseJsonSchema("properties", json, true);
for (Map<String, String> row : rows) {
EndpointOptionModel option = new EndpointOptionModel();
option.setName(getSafeValue("name", row));
option.setDisplayName(getSafeValue("displayName", row));
option.setKind(getSafeValue("kind", row));
option.setGroup(getSafeValue("group", row));
option.setRequired(getSafeValue("required", row));
option.setType(getSafeValue("type", row));
option.setJavaType(getSafeValue("javaType", row));
option.setEnums(getSafeValue("enum", row));
option.setPrefix(getSafeValue("prefix", row));
option.setMultiValue(getSafeValue("multiValue", row));
option.setDeprecated(getSafeValue("deprecated", row));
option.setSecret(getSafeValue("secret", row));
option.setDefaultValue(getSafeValue("defaultValue", row));
option.setDescription(getSafeValue("description", row));
// lets put required in the description
if ("true".equals(option.getRequired())) {
String desc = "*Required* " + option.getDescription();
option.setDescription(desc);
}
// separate the options in path vs parameter so we can generate two different tables
if ("path".equals(option.getKind())) {
component.addEndpointPathOption(option);
} else {
component.addEndpointOption(option);
}
// group separate between different options
if (oldGroup == null || !oldGroup.equals(option.getGroup())) {
option.setNewGroup(true);
}
oldGroup = option.getGroup();
}
return component;
}
Aggregations