use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareCatalogMojo method executeDocuments.
protected void executeDocuments(Set<String> components, Set<String> dataformats, Set<String> languages, Set<String> others) throws MojoExecutionException, MojoFailureException {
getLog().info("Copying all Camel documents (ascii docs)");
// lets use sorted set/maps
Set<File> adocFiles = new TreeSet<File>();
Set<File> missingAdocFiles = new TreeSet<File>();
Set<File> duplicateAdocFiles = new TreeSet<File>();
// find all camel maven modules
if (componentsDir != null && componentsDir.isDirectory()) {
File[] componentFiles = componentsDir.listFiles();
if (componentFiles != null) {
for (File dir : componentFiles) {
if (dir.isDirectory() && !"target".equals(dir.getName()) && !dir.getName().startsWith(".") && !excludeDocumentDir(dir.getName())) {
File target = new File(dir, "src/main/docs");
// special for these as they are in sub dir
if ("camel-salesforce".equals(dir.getName())) {
target = new File(dir, "camel-salesforce-component/src/main/docs");
} else if ("camel-linkedin".equals(dir.getName())) {
target = new File(dir, "camel-linkedin-component/src/main/docs");
} else if ("camel-olingo2".equals(dir.getName())) {
target = new File(dir, "camel-olingo2-component/src/main/docs");
} else if ("camel-box".equals(dir.getName())) {
target = new File(dir, "camel-box-component/src/main/docs");
}
int before = adocFiles.size();
findAsciiDocFilesRecursive(target, adocFiles, new CamelAsciiDocFileFilter());
int after = adocFiles.size();
if (before == after) {
missingAdocFiles.add(dir);
}
}
}
}
}
if (coreDir != null && coreDir.isDirectory()) {
File target = new File(coreDir, "src/main/docs");
findAsciiDocFilesRecursive(target, adocFiles, new CamelAsciiDocFileFilter());
}
getLog().info("Found " + adocFiles.size() + " ascii document files");
// make sure to create out dir
documentsOutDir.mkdirs();
// use ascii doctor to convert the adoc files to html so we have documentation in this format as well
Asciidoctor asciidoctor = Asciidoctor.Factory.create();
int converted = 0;
for (File file : adocFiles) {
File to = new File(documentsOutDir, file.getName());
if (to.exists()) {
duplicateAdocFiles.add(to);
getLog().warn("Duplicate document name detected: " + to);
}
try {
copyFile(file, to);
} catch (IOException e) {
throw new MojoFailureException("Cannot copy file from " + file + " -> " + to, e);
}
// convert adoc to html as well
if (file.getName().endsWith(".adoc")) {
String newName = file.getName().substring(0, file.getName().length() - 5) + ".html";
File toHtml = new File(documentsOutDir, newName);
getLog().debug("Converting ascii document to html -> " + toHtml);
asciidoctor.convertFile(file, OptionsBuilder.options().toFile(toHtml));
converted++;
try {
// now fix the html file because we don't want to include certain lines
List<String> lines = FileUtils.readLines(toHtml);
List<String> output = new ArrayList<>();
for (String line : lines) {
// skip these lines
if (line.contains("% raw %") || line.contains("% endraw %")) {
continue;
}
output.add(line);
}
if (lines.size() != output.size()) {
FileUtils.writeLines(toHtml, output, false);
}
} catch (IOException e) {
// ignore
}
}
}
if (converted > 0) {
getLog().info("Converted " + converted + " ascii documents to HTML");
}
Set<String> docs = new LinkedHashSet<>();
File all = new File(documentsOutDir, "../docs.properties");
try {
FileOutputStream fos = new FileOutputStream(all, false);
String[] names = documentsOutDir.list();
List<String> documents = new ArrayList<String>();
// sort the names
for (String name : names) {
if (name.endsWith(".adoc")) {
// strip out .adoc from the name
String documentName = name.substring(0, name.length() - 5);
documents.add(documentName);
}
}
Collections.sort(documents);
for (String name : documents) {
fos.write(name.getBytes());
fos.write("\n".getBytes());
docs.add(name);
}
fos.close();
} catch (IOException e) {
throw new MojoFailureException("Error writing to file " + all);
}
printDocumentsReport(adocFiles, duplicateAdocFiles, missingAdocFiles);
// find out if we have documents for each component / dataformat / languages / others
printMissingDocumentsReport(docs, components, dataformats, languages, others);
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareCatalogMojo method executeLanguages.
protected Set<String> executeLanguages() throws MojoExecutionException, MojoFailureException {
getLog().info("Copying all Camel language json descriptors");
// lets use sorted set/maps
Set<File> jsonFiles = new TreeSet<File>();
Set<File> duplicateJsonFiles = new TreeSet<File>();
Set<File> languageFiles = new TreeSet<File>();
Map<String, Set<String>> usedLabels = new TreeMap<String, Set<String>>();
Set<File> missingFirstVersions = new TreeSet<File>();
// find all languages from the components directory
if (componentsDir != null && componentsDir.isDirectory()) {
File[] languages = componentsDir.listFiles();
if (languages != null) {
for (File dir : languages) {
// skip camel-spring-dm
if (dir.isDirectory() && "camel-spring-dm".equals(dir.getName())) {
continue;
}
if (dir.isDirectory() && !"target".equals(dir.getName())) {
File target = new File(dir, "target/classes");
findLanguageFilesRecursive(target, jsonFiles, languageFiles, new CamelLanguagesFileFilter());
}
}
}
}
if (coreDir != null && coreDir.isDirectory()) {
File target = new File(coreDir, "target/classes");
findLanguageFilesRecursive(target, jsonFiles, languageFiles, new CamelLanguagesFileFilter());
}
getLog().info("Found " + languageFiles.size() + " language.properties files");
getLog().info("Found " + jsonFiles.size() + " language json files");
// make sure to create out dir
languagesOutDir.mkdirs();
for (File file : jsonFiles) {
File to = new File(languagesOutDir, file.getName());
if (to.exists()) {
duplicateJsonFiles.add(to);
getLog().warn("Duplicate language name detected: " + to);
}
try {
copyFile(file, to);
} catch (IOException e) {
throw new MojoFailureException("Cannot copy file from " + file + " -> " + to, e);
}
// check if we have a label as we want the data format to include labels
try {
String text = loadText(new FileInputStream(file));
String name = asComponentName(file);
Matcher matcher = LABEL_PATTERN.matcher(text);
// grab the label, and remember it in the used labels
if (matcher.find()) {
String label = matcher.group(1);
String[] labels = label.split(",");
for (String s : labels) {
Set<String> languages = usedLabels.get(s);
if (languages == null) {
languages = new TreeSet<String>();
usedLabels.put(s, languages);
}
languages.add(name);
}
}
// detect missing first version
List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("language", text, false);
String firstVersion = null;
for (Map<String, String> row : rows) {
if (row.get("firstVersion") != null) {
firstVersion = row.get("firstVersion");
}
}
if (firstVersion == null) {
missingFirstVersions.add(file);
}
} catch (IOException e) {
// ignore
}
}
Set<String> answer = new LinkedHashSet<>();
File all = new File(languagesOutDir, "../languages.properties");
try {
FileOutputStream fos = new FileOutputStream(all, false);
String[] names = languagesOutDir.list();
List<String> languages = new ArrayList<String>();
// sort the names
for (String name : names) {
if (name.endsWith(".json")) {
// strip out .json from the name
String languageName = name.substring(0, name.length() - 5);
languages.add(languageName);
}
}
Collections.sort(languages);
for (String name : languages) {
fos.write(name.getBytes());
fos.write("\n".getBytes());
// remember language name
answer.add(name);
}
fos.close();
} catch (IOException e) {
throw new MojoFailureException("Error writing to file " + all);
}
printLanguagesReport(jsonFiles, duplicateJsonFiles, usedLabels, missingFirstVersions);
return answer;
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareCatalogMojo method executeOthers.
private Set<String> executeOthers() throws MojoFailureException {
getLog().info("Copying all Camel other json descriptors");
// lets use sorted set/maps
Set<File> jsonFiles = new TreeSet<File>();
Set<File> duplicateJsonFiles = new TreeSet<File>();
Set<File> otherFiles = new TreeSet<File>();
Map<String, Set<String>> usedLabels = new TreeMap<String, Set<String>>();
Set<File> missingFirstVersions = new TreeSet<File>();
// find all others from the components directory
if (componentsDir != null && componentsDir.isDirectory()) {
File[] others = componentsDir.listFiles();
if (others != null) {
for (File dir : others) {
// (camel-jetty is a placeholder, as camel-jetty9 is the actual component)
if ("camel-core-osgi".equals(dir.getName()) || "camel-core-xml".equals(dir.getName()) || "camel-box".equals(dir.getName()) || "camel-http-common".equals(dir.getName()) || "camel-jetty".equals(dir.getName()) || "camel-jetty-common".equals(dir.getName()) || "camel-linkedin".equals(dir.getName()) || "camel-olingo2".equals(dir.getName()) || "camel-salesforce".equals(dir.getName())) {
continue;
}
if (dir.isDirectory() && !"target".equals(dir.getName())) {
File target = new File(dir, "target/classes");
findOtherFilesRecursive(target, jsonFiles, otherFiles, new CamelOthersFileFilter());
}
}
}
}
// nothing in camel-core
getLog().info("Found " + otherFiles.size() + " other.properties files");
getLog().info("Found " + jsonFiles.size() + " other json files");
// make sure to create out dir
othersOutDir.mkdirs();
for (File file : jsonFiles) {
File to = new File(othersOutDir, file.getName());
if (to.exists()) {
duplicateJsonFiles.add(to);
getLog().warn("Duplicate other name detected: " + to);
}
try {
copyFile(file, to);
} catch (IOException e) {
throw new MojoFailureException("Cannot copy file from " + file + " -> " + to, e);
}
// check if we have a label as we want the other to include labels
try {
String text = loadText(new FileInputStream(file));
String name = asComponentName(file);
Matcher matcher = LABEL_PATTERN.matcher(text);
// grab the label, and remember it in the used labels
if (matcher.find()) {
String label = matcher.group(1);
String[] labels = label.split(",");
for (String s : labels) {
Set<String> others = usedLabels.get(s);
if (others == null) {
others = new TreeSet<String>();
usedLabels.put(s, others);
}
others.add(name);
}
}
// detect missing first version
List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("other", text, false);
String firstVersion = null;
for (Map<String, String> row : rows) {
if (row.get("firstVersion") != null) {
firstVersion = row.get("firstVersion");
}
}
if (firstVersion == null) {
missingFirstVersions.add(file);
}
} catch (IOException e) {
// ignore
}
}
Set<String> answer = new LinkedHashSet<>();
File all = new File(othersOutDir, "../others.properties");
try {
FileOutputStream fos = new FileOutputStream(all, false);
String[] names = othersOutDir.list();
List<String> others = new ArrayList<String>();
// sort the names
for (String name : names) {
if (name.endsWith(".json")) {
// strip out .json from the name
String otherName = name.substring(0, name.length() - 5);
others.add(otherName);
}
}
Collections.sort(others);
for (String name : others) {
fos.write(name.getBytes());
fos.write("\n".getBytes());
// remember other name
answer.add(name);
}
fos.close();
} catch (IOException e) {
throw new MojoFailureException("Error writing to file " + all);
}
printOthersReport(jsonFiles, duplicateJsonFiles, usedLabels, missingFirstVersions);
return answer;
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareCatalogSpringBootMojo method executeComponents.
protected void executeComponents(Set<String> starters) throws MojoExecutionException, MojoFailureException {
getLog().info("Copying all Camel component json descriptors");
// lets use sorted set/maps
Set<File> jsonFiles = new TreeSet<File>();
Set<File> componentFiles = new TreeSet<File>();
// find all json files in components and camel-core
if (componentsDir != null && componentsDir.isDirectory()) {
File[] components = componentsDir.listFiles();
if (components != null) {
for (File dir : components) {
// skip camel-spring-dm
if (dir.isDirectory() && "camel-spring-dm".equals(dir.getName())) {
continue;
}
if (dir.isDirectory() && !"target".equals(dir.getName())) {
File target = new File(dir, "target/classes");
// the directory must be in the list of known features
if (!starters.contains(dir.getName())) {
continue;
}
// special for camel-salesforce which is in a sub dir
if ("camel-salesforce".equals(dir.getName())) {
target = new File(dir, "camel-salesforce-component/target/classes");
} else if ("camel-linkedin".equals(dir.getName())) {
target = new File(dir, "camel-linkedin-component/target/classes");
}
findComponentFilesRecursive(target, jsonFiles, componentFiles, new CamelComponentsFileFilter());
}
}
}
}
if (coreDir != null && coreDir.isDirectory()) {
File target = new File(coreDir, "target/classes");
findComponentFilesRecursive(target, jsonFiles, componentFiles, new CamelComponentsFileFilter());
}
getLog().info("Found " + componentFiles.size() + " component.properties files");
getLog().info("Found " + jsonFiles.size() + " component json files");
// make sure to create out dir
componentsOutDir.mkdirs();
for (File file : jsonFiles) {
// for spring-boot we need to amend the json file to use -starter as the artifact-id
try {
String text = loadText(new FileInputStream(file));
text = ARTIFACT_PATTERN.matcher(text).replaceFirst("\"artifactId\": \"camel-$1-starter\"");
// write new json file
File to = new File(componentsOutDir, file.getName());
FileOutputStream fos = new FileOutputStream(to, false);
fos.write(text.getBytes());
fos.close();
} catch (IOException e) {
throw new MojoFailureException("Cannot write json file " + file, e);
}
}
File all = new File(componentsOutDir, "../components.properties");
try {
FileOutputStream fos = new FileOutputStream(all, false);
String[] names = componentsOutDir.list();
List<String> components = new ArrayList<String>();
// sort the names
for (String name : names) {
if (name.endsWith(".json")) {
// strip out .json from the name
String componentName = name.substring(0, name.length() - 5);
components.add(componentName);
}
}
Collections.sort(components);
for (String name : components) {
fos.write(name.getBytes());
fos.write("\n".getBytes());
}
fos.close();
} catch (IOException e) {
throw new MojoFailureException("Error writing to file " + all);
}
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareCatalogSpringBootMojo method executeDataFormats.
protected void executeDataFormats(Set<String> starters) throws MojoExecutionException, MojoFailureException {
getLog().info("Copying all Camel dataformat json descriptors");
// lets use sorted set/maps
Set<File> jsonFiles = new TreeSet<File>();
Set<File> dataFormatFiles = new TreeSet<File>();
// find all data formats from the components directory
if (componentsDir != null && componentsDir.isDirectory()) {
File[] dataFormats = componentsDir.listFiles();
if (dataFormats != null) {
for (File dir : dataFormats) {
if (dir.isDirectory() && !"target".equals(dir.getName())) {
// skip camel-spring-dm
if (dir.isDirectory() && "camel-spring-dm".equals(dir.getName())) {
continue;
}
// the directory must be in the list of known starters
if (!starters.contains(dir.getName())) {
continue;
}
File target = new File(dir, "target/classes");
findDataFormatFilesRecursive(target, jsonFiles, dataFormatFiles, new CamelDataFormatsFileFilter());
}
}
}
}
if (coreDir != null && coreDir.isDirectory()) {
File target = new File(coreDir, "target/classes");
findDataFormatFilesRecursive(target, jsonFiles, dataFormatFiles, new CamelDataFormatsFileFilter());
}
getLog().info("Found " + dataFormatFiles.size() + " dataformat.properties files");
getLog().info("Found " + jsonFiles.size() + " dataformat json files");
// make sure to create out dir
dataFormatsOutDir.mkdirs();
for (File file : jsonFiles) {
// for spring-boot we need to amend the json file to use -starter as the artifact-id
try {
String text = loadText(new FileInputStream(file));
text = ARTIFACT_PATTERN.matcher(text).replaceFirst("\"artifactId\": \"camel-$1-starter\"");
// write new json file
File to = new File(dataFormatsOutDir, file.getName());
FileOutputStream fos = new FileOutputStream(to, false);
fos.write(text.getBytes());
fos.close();
} catch (IOException e) {
throw new MojoFailureException("Cannot write json file " + file, e);
}
}
File all = new File(dataFormatsOutDir, "../dataformats.properties");
try {
FileOutputStream fos = new FileOutputStream(all, false);
String[] names = dataFormatsOutDir.list();
List<String> dataFormats = new ArrayList<String>();
// sort the names
for (String name : names) {
if (name.endsWith(".json")) {
// strip out .json from the name
String dataFormatName = name.substring(0, name.length() - 5);
dataFormats.add(dataFormatName);
}
}
Collections.sort(dataFormats);
for (String name : dataFormats) {
fos.write(name.getBytes());
fos.write("\n".getBytes());
}
fos.close();
} catch (IOException e) {
throw new MojoFailureException("Error writing to file " + all);
}
}
Aggregations