use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareCatalogKarafMojo method executeComponents.
protected void executeComponents(Set<String> features) 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 (!features.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();
Set<String> alternativeSchemes = new HashSet<>();
for (File file : jsonFiles) {
File to = new File(componentsOutDir, file.getName());
try {
copyFile(file, to);
} catch (IOException e) {
throw new MojoFailureException("Cannot copy file from " + file + " -> " + to, 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 PrepareCatalogKarafMojo method executeOthers.
protected void executeOthers(Set<String> features) throws MojoExecutionException, MojoFailureException {
getLog().info("Copying all Camel other json descriptors");
// lets use sorted set/maps
Set<File> jsonFiles = new TreeSet<File>();
Set<File> otherFiles = new TreeSet<File>();
// find all languages from the components directory
if (componentsDir != null && componentsDir.isDirectory()) {
File[] others = componentsDir.listFiles();
if (others != null) {
for (File dir : others) {
// the directory must be in the list of known features
if (!features.contains(dir.getName())) {
continue;
}
// (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());
}
}
}
}
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());
try {
copyFile(file, to);
} catch (IOException e) {
throw new MojoFailureException("Cannot copy file from " + file + " -> " + to, e);
}
}
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());
}
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 PrepareReadmeMojo method executeComponentsReadme.
protected void executeComponentsReadme(boolean coreOnly) 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, coreOnly);
// 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);
}
}
// sort the models
Collections.sort(models, new ComponentComparator());
// filter out unwanted components
List<ComponentModel> components = new ArrayList<>();
for (ComponentModel model : models) {
if (coreOnly) {
if ("camel-core".equals(model.getArtifactId())) {
// only include core components
components.add(model);
}
} else {
// we want to include everything in the big file (also from camel-core)
components.add(model);
}
}
// how many different artifacts
int count = components.stream().map(ComponentModel::getArtifactId).collect(toSet()).size();
// how many deprecated
long deprecated = components.stream().filter(c -> "true".equals(c.getDeprecated())).count();
// update the big readme file in the core/components dir
File file;
if (coreOnly) {
file = new File(readmeCoreDir, "readme.adoc");
} else {
file = new File(readmeComponentsDir, "readme.adoc");
}
// update regular components
boolean exists = file.exists();
String changed = templateComponents(components, count, deprecated);
boolean updated = updateComponents(file, changed);
if (updated) {
getLog().info("Updated readme.adoc file: " + file);
} else if (exists) {
getLog().debug("No changes to readme.adoc file: " + file);
} else {
getLog().warn("No readme.adoc file: " + file);
}
} catch (IOException e) {
throw new MojoFailureException("Error due " + e.getMessage(), e);
}
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareReadmeMojo method executeEipsReadme.
protected void executeEipsReadme() throws MojoExecutionException, MojoFailureException {
Set<File> eipFiles = new TreeSet<>();
if (eipsDir != null && eipsDir.isDirectory()) {
File[] files = eipsDir.listFiles();
if (files != null) {
eipFiles.addAll(Arrays.asList(files));
}
}
try {
List<EipModel> models = new ArrayList<>();
for (File file : eipFiles) {
String json = loadText(new FileInputStream(file));
EipModel model = generateEipModel(json);
// we only want actual EIPs from the models
if (model.getLabel().startsWith("eip")) {
models.add(model);
}
}
// re-order the EIPs so we have them in different categories
// sort the models
Collections.sort(models, new EipComparator());
// how many deprecated
long deprecated = models.stream().filter(EipModel::isDeprecated).count();
// update the big readme file in the core dir
File file = new File(readmeCoreDir, "readme-eip.adoc");
// update regular components
boolean exists = file.exists();
String changed = templateEips(models, deprecated);
boolean updated = updateEips(file, changed);
if (updated) {
getLog().info("Updated readme-eip.adoc file: " + file);
} else if (exists) {
getLog().debug("No changes to readme-eip.adoc file: " + file);
} else {
getLog().warn("No readme-eip.adoc file: " + file);
}
} catch (IOException e) {
throw new MojoFailureException("Error due " + e.getMessage(), e);
}
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareCatalogMojo method executeComponents.
protected Set<String> executeComponents() throws MojoExecutionException, MojoFailureException {
getLog().info("Copying all Camel component json descriptors");
// lets use sorted set/maps
Set<File> jsonFiles = new TreeSet<File>();
Set<File> duplicateJsonFiles = new TreeSet<File>();
Set<File> componentFiles = new TreeSet<File>();
Set<File> missingComponents = new TreeSet<File>();
Map<String, Set<String>> usedComponentLabels = new TreeMap<String, Set<String>>();
Set<String> usedOptionLabels = new TreeSet<String>();
Set<String> unlabeledOptions = new TreeSet<String>();
Set<File> missingFirstVersions = 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");
// special for these as they are in 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");
} else if ("camel-olingo2".equals(dir.getName())) {
target = new File(dir, "camel-olingo2-component/target/classes");
} else if ("camel-box".equals(dir.getName())) {
target = new File(dir, "camel-box-component/target/classes");
}
int before = componentFiles.size();
int before2 = jsonFiles.size();
findComponentFilesRecursive(target, jsonFiles, componentFiles, new CamelComponentsFileFilter());
int after = componentFiles.size();
int after2 = jsonFiles.size();
if (before != after && before2 == after2) {
missingComponents.add(dir);
}
}
}
}
}
if (coreDir != null && coreDir.isDirectory()) {
File target = new File(coreDir, "target/classes");
int before = componentFiles.size();
int before2 = jsonFiles.size();
findComponentFilesRecursive(target, jsonFiles, componentFiles, new CamelComponentsFileFilter());
int after = componentFiles.size();
int after2 = jsonFiles.size();
if (before != after && before2 == after2) {
missingComponents.add(coreDir);
}
}
getLog().info("Found " + componentFiles.size() + " component.properties files");
getLog().info("Found " + jsonFiles.size() + " component json files");
// make sure to create out dir
componentsOutDir.mkdirs();
Set<String> alternativeSchemes = new HashSet<>();
for (File file : jsonFiles) {
File to = new File(componentsOutDir, file.getName());
if (to.exists()) {
duplicateJsonFiles.add(to);
getLog().warn("Duplicate component 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 component label as we want the components 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> components = usedComponentLabels.get(s);
if (components == null) {
components = new TreeSet<String>();
usedComponentLabels.put(s, components);
}
components.add(name);
}
}
// check all the component options and grab the label(s) they use
List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("componentProperties", text, true);
for (Map<String, String> row : rows) {
String label = row.get("label");
if (label != null && !label.isEmpty()) {
String[] parts = label.split(",");
for (String part : parts) {
usedOptionLabels.add(part);
}
}
}
// check all the endpoint options and grab the label(s) they use
int unused = 0;
rows = JSonSchemaHelper.parseJsonSchema("properties", text, true);
for (Map<String, String> row : rows) {
String label = row.get("label");
if (label != null && !label.isEmpty()) {
String[] parts = label.split(",");
for (String part : parts) {
usedOptionLabels.add(part);
}
} else {
unused++;
}
}
if (unused >= UNUSED_LABELS_WARN) {
unlabeledOptions.add(name);
}
// remember alternative schemes
rows = JSonSchemaHelper.parseJsonSchema("component", text, false);
for (Map<String, String> row : rows) {
String alternativeScheme = row.get("alternativeSchemes");
if (alternativeScheme != null && !alternativeScheme.isEmpty()) {
String[] parts = alternativeScheme.split(",");
for (int i = 1; i < parts.length; i++) {
// skip first as that is the regular scheme
String part = parts[i];
alternativeSchemes.add(part);
}
}
}
// detect missing first version
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> componentNames = new LinkedHashSet<>();
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());
// remember component name
componentNames.add(name);
}
fos.close();
} catch (IOException e) {
throw new MojoFailureException("Error writing to file " + all);
}
printComponentsReport(jsonFiles, duplicateJsonFiles, missingComponents, usedComponentLabels, usedOptionLabels, unlabeledOptions, missingFirstVersions);
// filter out duplicate component names that are alternative scheme names
Set<String> answer = new LinkedHashSet<>();
for (String componentName : componentNames) {
if (!alternativeSchemes.contains(componentName)) {
answer.add(componentName);
}
}
return answer;
}
Aggregations