use of org.apache.camel.maven.packaging.model.DataFormatModel in project camel by apache.
the class UpdateReadmeMojo method executeDataFormat.
private void executeDataFormat() throws MojoExecutionException, MojoFailureException {
// find the dataformat names
List<String> dataFormatNames = findDataFormatNames();
final Set<File> jsonFiles = new TreeSet<File>();
PackageHelper.findJsonFiles(buildDir, jsonFiles, new PackageHelper.CamelComponentsModelFilter());
// only if there is dataformat we should update the documentation files
if (!dataFormatNames.isEmpty()) {
getLog().debug("Found " + dataFormatNames.size() + " dataformats");
for (String dataFormatName : dataFormatNames) {
String json = loadDataFormatJson(jsonFiles, dataFormatName);
if (json != null) {
// special for some data formats
dataFormatName = asDataFormatName(dataFormatName);
File file = new File(docDir, dataFormatName + "-dataformat.adoc");
DataFormatModel model = generateDataFormatModel(dataFormatName, json);
String title = asDataFormatTitle(model.getName(), model.getTitle());
model.setTitle(title);
String docTitle = model.getTitle() + " DataFormat";
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());
String options = templateDataFormatOptions(model);
updated |= updateDataFormatOptions(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 dataformat doc file: " + file);
if (isFailFast()) {
throw new MojoExecutionException("Failed build due failFast=true");
}
}
}
}
}
}
use of org.apache.camel.maven.packaging.model.DataFormatModel in project camel by apache.
the class PrepareUserGuideMojo method generateDataFormatModel.
private DataFormatModel generateDataFormatModel(String json) {
List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("dataformat", json, false);
DataFormatModel dataFormat = new DataFormatModel();
dataFormat.setName(JSonSchemaHelper.getSafeValue("name", rows));
dataFormat.setTitle(JSonSchemaHelper.getSafeValue("title", rows));
dataFormat.setModelName(JSonSchemaHelper.getSafeValue("modelName", rows));
dataFormat.setDescription(JSonSchemaHelper.getSafeValue("description", rows));
dataFormat.setFirstVersion(JSonSchemaHelper.getSafeValue("firstVersion", rows));
dataFormat.setLabel(JSonSchemaHelper.getSafeValue("label", rows));
dataFormat.setDeprecated(JSonSchemaHelper.getSafeValue("deprecated", rows));
dataFormat.setJavaType(JSonSchemaHelper.getSafeValue("javaType", rows));
dataFormat.setGroupId(JSonSchemaHelper.getSafeValue("groupId", rows));
dataFormat.setArtifactId(JSonSchemaHelper.getSafeValue("artifactId", rows));
dataFormat.setVersion(JSonSchemaHelper.getSafeValue("version", rows));
return dataFormat;
}
use of org.apache.camel.maven.packaging.model.DataFormatModel in project camel by apache.
the class UpdateReadmeMojo method generateDataFormatModel.
private DataFormatModel generateDataFormatModel(String dataFormatName, String json) {
List<Map<String, String>> rows = parseJsonSchema("dataformat", json, false);
DataFormatModel dataFormat = new DataFormatModel();
dataFormat.setTitle(getSafeValue("title", rows));
dataFormat.setModelName(getSafeValue("modelName", rows));
dataFormat.setName(getSafeValue("name", rows));
dataFormat.setDescription(getSafeValue("description", rows));
dataFormat.setFirstVersion(getSafeValue("firstVersion", rows));
dataFormat.setLabel(getSafeValue("label", rows));
dataFormat.setDeprecated(getSafeValue("deprecated", rows));
dataFormat.setJavaType(getSafeValue("javaType", rows));
dataFormat.setGroupId(getSafeValue("groupId", rows));
dataFormat.setArtifactId(getSafeValue("artifactId", rows));
dataFormat.setVersion(getSafeValue("version", rows));
rows = parseJsonSchema("properties", json, true);
for (Map<String, String> row : rows) {
DataFormatOptionModel option = new DataFormatOptionModel();
option.setName(getSafeValue("name", row));
option.setDisplayName(getSafeValue("displayName", row));
option.setKind(getSafeValue("kind", row));
option.setType(getSafeValue("type", row));
option.setJavaType(getSafeValue("javaType", row));
option.setDeprecated(getSafeValue("deprecated", row));
option.setEnumValues(getSafeValue("enum", row));
option.setDefaultValue(getSafeValue("defaultValue", row));
option.setDescription(getSafeValue("description", row));
// special for bindy as we reuse one readme file
if (dataFormatName.startsWith("bindy") && option.getName().equals("type")) {
option.setDefaultValue("");
String doc = option.getDescription() + " The default value is either Csv or KeyValue depending on chosen dataformat.";
option.setDescription(doc);
}
// skip option named id
if ("id".equals(option.getName())) {
getLog().debug("Skipping option: " + option.getName());
} else {
dataFormat.addDataFormatOption(option);
}
}
return dataFormat;
}
use of org.apache.camel.maven.packaging.model.DataFormatModel in project camel by apache.
the class PrepareUserGuideMojo method executeDataFormats.
protected void executeDataFormats() throws MojoExecutionException, MojoFailureException {
Set<File> dataFormatFiles = new TreeSet<>();
if (dataFormatsDir != null && dataFormatsDir.isDirectory()) {
File[] files = dataFormatsDir.listFiles();
if (files != null) {
dataFormatFiles.addAll(Arrays.asList(files));
}
}
try {
List<DataFormatModel> models = new ArrayList<>();
for (File file : dataFormatFiles) {
String json = loadText(new FileInputStream(file));
DataFormatModel model = generateDataFormatModel(json);
models.add(model);
}
// sor the models
Collections.sort(models, new DataFormatComparator());
// the summary file has the TOC
File file = new File(userGuideDir, "SUMMARY.md");
// update data formats
StringBuilder dataFormats = new StringBuilder();
dataFormats.append("* Data Formats\n");
for (DataFormatModel model : models) {
String line = "\t* " + link(model) + "\n";
dataFormats.append(line);
}
boolean updated = updateDataFormats(file, dataFormats.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);
}
}
Aggregations