use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareCatalogMojo method executeModel.
protected void executeModel() throws MojoExecutionException, MojoFailureException {
getLog().info("================================================================================");
getLog().info("Copying all Camel model json descriptors");
// lets use sorted set/maps
Set<File> jsonFiles = new TreeSet<File>();
Set<File> duplicateJsonFiles = new TreeSet<File>();
Set<File> missingLabels = new TreeSet<File>();
Set<File> missingJavaDoc = new TreeSet<File>();
Map<String, Set<String>> usedLabels = new TreeMap<String, Set<String>>();
// find all json files in camel-core
if (coreDir != null && coreDir.isDirectory()) {
File target = new File(coreDir, "target/classes/org/apache/camel/model");
PackageHelper.findJsonFiles(target, jsonFiles, new PackageHelper.CamelComponentsModelFilter());
}
// find all json files in camel-spring
if (springDir != null && springDir.isDirectory()) {
File target = new File(springDir, "target/classes/org/apache/camel/spring");
PackageHelper.findJsonFiles(target, jsonFiles, new PackageHelper.CamelComponentsModelFilter());
File target2 = new File(springDir, "target/classes/org/apache/camel/core/xml");
PackageHelper.findJsonFiles(target2, jsonFiles, new PackageHelper.CamelComponentsModelFilter());
}
getLog().info("Found " + jsonFiles.size() + " model json files");
// make sure to create out dir
modelsOutDir.mkdirs();
for (File file : jsonFiles) {
File to = new File(modelsOutDir, file.getName());
if (to.exists()) {
duplicateJsonFiles.add(to);
getLog().warn("Duplicate model name detected: " + to);
}
try {
copyFile(file, to);
} catch (IOException e) {
throw new MojoFailureException("Cannot copy file from " + file + " -> " + to, e);
}
try {
// check if we have a label as we want the eip to include labels
String text = loadText(new FileInputStream(file));
// just do a basic label check
if (text.contains("\"label\": \"\"")) {
missingLabels.add(file);
} else {
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> models = usedLabels.get(s);
if (models == null) {
models = new TreeSet<String>();
usedLabels.put(s, models);
}
models.add(name);
}
}
}
// check all the properties if they have description
List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("properties", text, true);
for (Map<String, String> row : rows) {
String name = row.get("name");
// skip checking these as they have no documentation
if ("outputs".equals(name) || "transforms".equals(name)) {
continue;
}
String doc = row.get("description");
if (doc == null || doc.isEmpty()) {
missingJavaDoc.add(file);
break;
}
}
} catch (IOException e) {
// ignore
}
}
File all = new File(modelsOutDir, "../models.properties");
try {
FileOutputStream fos = new FileOutputStream(all, false);
String[] names = modelsOutDir.list();
List<String> models = new ArrayList<String>();
// sort the names
for (String name : names) {
if (name.endsWith(".json")) {
// strip out .json from the name
String modelName = name.substring(0, name.length() - 5);
models.add(modelName);
}
}
Collections.sort(models);
for (String name : models) {
fos.write(name.getBytes());
fos.write("\n".getBytes());
}
fos.close();
} catch (IOException e) {
throw new MojoFailureException("Error writing to file " + all);
}
printModelsReport(jsonFiles, duplicateJsonFiles, missingLabels, usedLabels, missingJavaDoc);
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareCatalogMojo method executeDataFormats.
protected Set<String> executeDataFormats() throws MojoExecutionException, MojoFailureException {
getLog().info("Copying all Camel dataformat json descriptors");
// lets use sorted set/maps
Set<File> jsonFiles = new TreeSet<File>();
Set<File> duplicateJsonFiles = new TreeSet<File>();
Set<File> dataFormatFiles = new TreeSet<File>();
Map<String, Set<String>> usedLabels = new TreeMap<String, Set<String>>();
Set<File> missingFirstVersions = 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())) {
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) {
File to = new File(dataFormatsOutDir, file.getName());
if (to.exists()) {
duplicateJsonFiles.add(to);
getLog().warn("Duplicate dataformat 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> dataFormats = usedLabels.get(s);
if (dataFormats == null) {
dataFormats = new TreeSet<String>();
usedLabels.put(s, dataFormats);
}
dataFormats.add(name);
}
}
// detect missing first version
List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("dataformat", 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(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());
// remember dataformat name
answer.add(name);
}
fos.close();
} catch (IOException e) {
throw new MojoFailureException("Error writing to file " + all);
}
printDataFormatsReport(jsonFiles, duplicateJsonFiles, usedLabels, missingFirstVersions);
return answer;
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class EipDocumentationEnricherMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (pathToModelDir == null) {
throw new MojoExecutionException("pathToModelDir parameter must not be null");
}
validateExists(inputCamelSchemaFile, "inputCamelSchemaFile");
validateIsFile(inputCamelSchemaFile, "inputCamelSchemaFile");
validateExists(camelCoreDir, "camelCoreDir");
validateExists(camelCoreXmlDir, "camelCoreXmlDir");
validateExists(camelSpringDir, "camelSpringDir");
validateIsDirectory(camelCoreDir, "camelCoreDir");
validateIsDirectory(camelCoreXmlDir, "camelCoreXmlDir");
validateIsDirectory(camelSpringDir, "camelSpringDir");
try {
runPlugin();
} catch (Exception e) {
throw new MojoExecutionException("Error during plugin execution", e);
}
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class SpringBootStarterMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (!isStarterAllowed()) {
getLog().info("Spring-Boot-Starter: starter not allowed for module " + project.getArtifactId() + ": skipping.");
return;
}
try {
// create the starter directory
File starterDir = starterDir();
getLog().info("Spring-Boot-Starter: starter dir for the component is: " + starterDir.getAbsolutePath());
if (!starterDir.exists()) {
starterDir.mkdirs();
}
// create the base pom.xml
Document pom = createBasePom();
// Apply changes to the starter pom
fixExcludedDependencies(pom);
fixAdditionalDependencies(pom);
fixAdditionalRepositories(pom);
// Write the starter pom
File pomFile = new File(starterDir, "pom.xml");
writeXmlFormatted(pom, pomFile);
// write LICENSE, USAGE and spring.provides files
writeStaticFiles();
writeSpringProvides();
// synchronized all starters with their parent pom 'modules' section
synchronizeParentPom();
} catch (Exception e) {
throw new MojoFailureException("Unable to create starter", e);
}
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class SpringBootAutoConfigurationMojo method createDataFormatAutoConfigurationSource.
private void createDataFormatAutoConfigurationSource(String packageName, DataFormatModel model, List<String> dataFormatAliases, boolean hasOptions, String overrideDataFormatName) throws MojoFailureException {
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
int pos = model.getJavaType().lastIndexOf(".");
String name = model.getJavaType().substring(pos + 1);
name = name.replace("DataFormat", "DataFormatAutoConfiguration");
javaClass.setPackage(packageName).setName(name);
String doc = "Generated by camel-package-maven-plugin - do not edit this file!";
javaClass.getJavaDoc().setFullText(doc);
javaClass.addAnnotation(Configuration.class);
javaClass.addAnnotation(ConditionalOnBean.class).setStringValue("type", "org.apache.camel.spring.boot.CamelAutoConfiguration");
javaClass.addAnnotation(Conditional.class).setLiteralValue(name + ".Condition.class");
javaClass.addAnnotation(AutoConfigureAfter.class).setStringValue("name", "org.apache.camel.spring.boot.CamelAutoConfiguration");
String configurationName = name.replace("DataFormatAutoConfiguration", "DataFormatConfiguration");
if (hasOptions) {
AnnotationSource<JavaClassSource> ann = javaClass.addAnnotation(EnableConfigurationProperties.class);
ann.setLiteralValue("value", configurationName + ".class");
javaClass.addImport("java.util.HashMap");
javaClass.addImport("java.util.Map");
javaClass.addImport("org.apache.camel.util.IntrospectionSupport");
}
javaClass.addImport("org.apache.camel.CamelContextAware");
javaClass.addImport(model.getJavaType());
javaClass.addImport("org.apache.camel.CamelContext");
javaClass.addImport("org.apache.camel.RuntimeCamelException");
javaClass.addImport("org.apache.camel.spi.DataFormat");
javaClass.addImport("org.apache.camel.spi.DataFormatFactory");
String body = createDataFormatBody(model.getShortJavaType(), hasOptions);
String methodName = "configure" + model.getShortJavaType() + "Factory";
MethodSource<JavaClassSource> method = javaClass.addMethod().setName(methodName).setPublic().setBody(body).setReturnType("org.apache.camel.spi.DataFormatFactory");
method.addParameter("CamelContext", "camelContext").setFinal(true);
if (hasOptions) {
method.addParameter(configurationName, "configuration").setFinal(true);
}
// Determine all the aliases
// adding the '-dataformat' suffix to prevent collision with component names
String[] springBeanAliases = dataFormatAliases.stream().map(alias -> alias + "-dataformat-factory").toArray(size -> new String[size]);
method.addAnnotation(Bean.class).setStringArrayValue("name", springBeanAliases);
method.addAnnotation(ConditionalOnClass.class).setLiteralValue("value", "CamelContext.class");
method.addAnnotation(ConditionalOnMissingBean.class).setLiteralValue("value", model.getShortJavaType() + ".class");
// Generate Condition
javaClass.addNestedType(createConditionType(javaClass, "camel.dataformat", (overrideDataFormatName != null ? overrideDataFormatName : model.getName()).toLowerCase(Locale.US)));
sortImports(javaClass);
String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
writeSourceIfChanged(javaClass, fileName);
writeAdditionalSpringMetaData("camel", "dataformat", (overrideDataFormatName != null ? overrideDataFormatName : model.getName()).toLowerCase(Locale.US));
}
Aggregations