use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareCatalogMojo method executeXmlSchemas.
protected void executeXmlSchemas() throws MojoExecutionException, MojoFailureException {
getLog().info("Copying Spring/Blueprint XML schemas");
schemasOutDir.mkdirs();
File file = new File(springSchemaDir, "camel-spring.xsd");
if (file.exists() && file.isFile()) {
File to = new File(schemasOutDir, file.getName());
try {
copyFile(file, to);
} catch (IOException e) {
throw new MojoFailureException("Cannot copy file from " + file + " -> " + to, e);
}
}
file = new File(blueprintSchemaDir, "camel-blueprint.xsd");
if (file.exists() && file.isFile()) {
File to = new File(schemasOutDir, file.getName());
try {
copyFile(file, to);
} catch (IOException e) {
throw new MojoFailureException("Cannot copy file from " + file + " -> " + to, e);
}
}
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class SpringBootAutoConfigurationMojo method writeSourceIfChanged.
private void writeSourceIfChanged(JavaClassSource source, String fileName) throws MojoFailureException {
File target = new File(SpringBootHelper.starterSrcDir(baseDir, project.getArtifactId()), fileName);
deleteFileOnMainArtifact(target);
try {
InputStream is = getClass().getClassLoader().getResourceAsStream("license-header-java.txt");
String header = loadText(is);
String code = sourceToString(source);
code = header + code;
getLog().debug("Source code generated:\n" + code);
if (target.exists()) {
String existing = FileUtils.readFileToString(target);
if (!code.equals(existing)) {
FileUtils.write(target, code, false);
getLog().info("Updated existing file: " + target);
} else {
getLog().debug("No changes to existing file: " + target);
}
} else {
FileUtils.write(target, code);
getLog().info("Created file: " + target);
}
} catch (Exception e) {
throw new MojoFailureException("IOError with file " + target, e);
}
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class SpringBootAutoConfigurationMojo method createLanguageAutoConfigurationSource.
private void createLanguageAutoConfigurationSource(String packageName, LanguageModel model, List<String> languageAliases, boolean hasOptions, String overrideLanguageName) throws MojoFailureException {
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
int pos = model.getJavaType().lastIndexOf(".");
String name = model.getJavaType().substring(pos + 1);
name = name.replace("Language", "LanguageAutoConfiguration");
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("LanguageAutoConfiguration", "LanguageConfiguration");
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");
String body = createLanguageBody(model.getShortJavaType(), hasOptions);
String methodName = "configure" + model.getShortJavaType();
MethodSource<JavaClassSource> method = javaClass.addMethod().setName(methodName).setPublic().setBody(body).setReturnType(model.getShortJavaType()).addThrows(Exception.class);
method.addParameter("CamelContext", "camelContext");
method.addParameter(configurationName, "configuration");
// Determine all the aliases
// adding the '-language' suffix to prevent collision with component names
String[] springBeanAliases = languageAliases.stream().map(alias -> alias + "-language").toArray(size -> new String[size]);
method.addAnnotation(Bean.class).setStringArrayValue("name", springBeanAliases);
method.addAnnotation(Scope.class).setStringValue("prototype");
method.addAnnotation(ConditionalOnClass.class).setLiteralValue("value", "CamelContext.class");
method.addAnnotation(ConditionalOnMissingBean.class).setLiteralValue("value", model.getShortJavaType() + ".class");
// Generate Condition
javaClass.addNestedType(createConditionType(javaClass, "camel.language", (overrideLanguageName != null ? overrideLanguageName : model.getName()).toLowerCase(Locale.US)));
sortImports(javaClass);
String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
writeSourceIfChanged(javaClass, fileName);
writeAdditionalSpringMetaData("camel", "language", (overrideLanguageName != null ? overrideLanguageName : model.getName()).toLowerCase(Locale.US));
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class SpringBootAutoConfigurationMojo method writeComponentSpringFactorySource.
private void writeComponentSpringFactorySource(String packageName, String name) throws MojoFailureException {
StringBuilder sb = new StringBuilder();
sb.append("org.springframework.boot.autoconfigure.EnableAutoConfiguration=\\\n");
String lineToAdd = packageName + "." + name + "\n";
sb.append(lineToAdd);
String fileName = "META-INF/spring.factories";
File target = new File(SpringBootHelper.starterResourceDir(baseDir, project.getArtifactId()), fileName);
deleteFileOnMainArtifact(target);
if (target.exists()) {
try {
// is the auto configuration already in the file
boolean found = false;
List<String> lines = FileUtils.readLines(target);
for (String line : lines) {
if (line.contains(name)) {
found = true;
break;
}
}
if (found) {
getLog().debug("No changes to existing file: " + target);
} else {
// find last non empty line, so we can add our new line after that
int lastLine = 0;
for (int i = lines.size() - 1; i >= 0; i--) {
String line = lines.get(i);
if (!line.trim().isEmpty()) {
// adjust existing line so its being continued
line = line + ",\\";
lines.set(i, line);
lastLine = i;
break;
}
}
lines.add(lastLine + 1, lineToAdd);
StringBuilder code = new StringBuilder();
for (String line : lines) {
code.append(line).append("\n");
}
// update
FileUtils.write(target, code.toString(), false);
getLog().info("Updated existing file: " + target);
}
} catch (Exception e) {
throw new MojoFailureException("IOError with file " + target, e);
}
} else {
// create new file
try {
InputStream is = getClass().getClassLoader().getResourceAsStream("license-header.txt");
String header = loadText(is);
String code = sb.toString();
// add empty new line after header
code = header + "\n" + code;
getLog().debug("Source code generated:\n" + code);
FileUtils.write(target, code);
getLog().info("Created file: " + target);
} catch (Exception e) {
throw new MojoFailureException("IOError with file " + target, e);
}
}
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareUserGuideMojo method executeOthers.
protected void executeOthers() throws MojoExecutionException, MojoFailureException {
Set<File> otherFiles = new TreeSet<>();
if (othersDir != null && othersDir.isDirectory()) {
File[] files = othersDir.listFiles();
if (files != null) {
otherFiles.addAll(Arrays.asList(files));
}
}
try {
List<OtherModel> models = new ArrayList<>();
for (File file : otherFiles) {
String json = loadText(new FileInputStream(file));
OtherModel model = generateOtherModel(json);
models.add(model);
}
// sor the models
Collections.sort(models, new OtherComparator());
// the summary file has the TOC
File file = new File(userGuideDir, "SUMMARY.md");
// update core components
StringBuilder other = new StringBuilder();
other.append("* Miscellaneous Components\n");
for (OtherModel model : models) {
String line = "\t* " + link(model) + "\n";
other.append(line);
}
boolean updated = updateOthers(file, other.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