use of org.apache.maven.plugin.MojoExecutionException 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.maven.plugin.MojoExecutionException in project camel by apache.
the class UpdateReadmeMojo method templateComponentOptions.
private String templateComponentOptions(ComponentModel model) throws MojoExecutionException {
try {
String template = loadText(UpdateReadmeMojo.class.getClassLoader().getResourceAsStream("component-options.mvel"));
String out = (String) TemplateRuntime.eval(template, model);
return out;
} catch (Exception e) {
throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project camel by apache.
the class UpdateReadmeMojo method updateTitles.
private boolean updateTitles(File file, String title) throws MojoExecutionException {
if (!file.exists()) {
return false;
}
boolean updated = false;
try {
List<String> newLines = new ArrayList<>();
String text = loadText(new FileInputStream(file));
String[] lines = text.split("\n");
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
if (i == 0) {
// first line is the title to make the text less noisy we use level 2
String newLine = "## " + title;
newLines.add(newLine);
updated = !line.equals(newLine);
continue;
}
// use single line headers with # as level instead of the cumbersome adoc weird style
if (line.startsWith("^^^") || line.startsWith("~~~") || line.startsWith("+++")) {
String level = line.startsWith("+++") ? "####" : "###";
// transform legacy heading into new style
int idx = newLines.size() - 1;
String prev = newLines.get(idx);
newLines.set(idx, level + " " + prev);
// okay if 2nd-prev line is a [[title]] we need to remove that too
// so we have nice clean sub titles
idx = newLines.size() - 2;
if (idx >= 0) {
prev = newLines.get(idx);
if (prev.startsWith("[[")) {
// remove
newLines.remove(idx);
}
}
updated = true;
} else {
// okay normal text so just add it
newLines.add(line);
}
}
if (updated) {
// build the new updated text
String newText = newLines.stream().collect(Collectors.joining("\n"));
writeText(file, newText);
}
} catch (Exception e) {
throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e);
}
return updated;
}
use of org.apache.maven.plugin.MojoExecutionException in project camel by apache.
the class UpdateReadmeMojo method templateEipOptions.
private String templateEipOptions(EipModel model) throws MojoExecutionException {
try {
String template = loadText(UpdateReadmeMojo.class.getClassLoader().getResourceAsStream("eip-options.mvel"));
String out = (String) TemplateRuntime.eval(template, model);
return out;
} catch (Exception e) {
throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project camel by apache.
the class UpdateReadmeMojo method updateEipOptions.
private boolean updateEipOptions(File file, String changed) throws MojoExecutionException {
if (!file.exists()) {
return false;
}
try {
String text = loadText(new FileInputStream(file));
String existing = StringHelper.between(text, "// eip options: START", "// eip options: END");
if (existing != null) {
// remove leading line breaks etc
existing = existing.trim();
changed = changed.trim();
if (existing.equals(changed)) {
return false;
} else {
String before = StringHelper.before(text, "// eip options: START");
String after = StringHelper.after(text, "// eip options: END");
text = before + "// eip options: START\n" + changed + "\n// eip options: END" + after;
writeText(file, text);
return true;
}
} else {
getLog().warn("Cannot find markers in file " + file);
getLog().warn("Add the following markers");
getLog().warn("\t// eip options: START");
getLog().warn("\t// eip options: END");
if (isFailFast()) {
throw new MojoExecutionException("Failed build due failFast=true");
}
return false;
}
} catch (Exception e) {
throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e);
}
}
Aggregations