use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareUserGuideMojo method executeLanguages.
protected void executeLanguages() throws MojoExecutionException, MojoFailureException {
Set<File> languageFiles = new TreeSet<>();
if (languagesDir != null && languagesDir.isDirectory()) {
File[] files = languagesDir.listFiles();
if (files != null) {
languageFiles.addAll(Arrays.asList(files));
}
}
try {
List<LanguageModel> models = new ArrayList<>();
for (File file : languageFiles) {
String json = loadText(new FileInputStream(file));
LanguageModel model = generateLanguageModel(json);
models.add(model);
}
// sor the models
Collections.sort(models, new LanguageComparator());
// the summary file has the TOC
File file = new File(userGuideDir, "SUMMARY.md");
// update languages
StringBuilder languages = new StringBuilder();
languages.append("* Expression Languages\n");
for (LanguageModel model : models) {
String line = "\t* " + link(model) + "\n";
languages.append(line);
}
boolean updated = updateLanguages(file, languages.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);
}
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class SpringBootAutoConfigurationMojo method writeAdditionalSpringMetaData.
private void writeAdditionalSpringMetaData(String prefix, String type, String name) throws MojoFailureException {
String fullQualifiedName = prefix + "." + type + "." + name + "." + "enabled";
String fileName = "META-INF/additional-spring-configuration-metadata.json";
File target = new File(SpringBootHelper.starterResourceDir(baseDir, project.getArtifactId()), fileName);
deleteFileOnMainArtifact(target);
try {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Map<String, Object> map = null;
List<Map<String, Object>> properties = null;
if (target.exists()) {
BufferedReader br = new BufferedReader(new FileReader(target));
map = gson.fromJson(br, Map.class);
properties = (List<Map<String, Object>>) map.get("properties");
if (properties != null && properties.stream().anyMatch(m -> fullQualifiedName.equals(m.get("name")))) {
getLog().debug("No changes to existing file: " + target);
return;
}
}
Map<String, Object> meta = new HashMap();
meta.put("name", fullQualifiedName);
meta.put("type", "java.lang.Boolean");
meta.put("defaultValue", true);
meta.put("description", "Enable " + name + " " + type);
if (properties == null) {
properties = new ArrayList<>(1);
}
if (map == null) {
map = new HashMap();
}
properties.add(meta);
map.put("properties", properties);
FileUtils.write(target, gson.toJson(map));
} 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 createComponentAutoConfigurationSource.
private void createComponentAutoConfigurationSource(String packageName, ComponentModel model, List<String> componentAliases, boolean hasOptions, String overrideComponentName) throws MojoFailureException {
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
int pos = model.getJavaType().lastIndexOf(".");
String name = model.getJavaType().substring(pos + 1);
name = name.replace("Component", "ComponentAutoConfiguration");
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("ComponentAutoConfiguration", "ComponentConfiguration");
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(model.getJavaType());
javaClass.addImport("org.apache.camel.CamelContext");
// add method for auto configure
String body = createComponentBody(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");
if (hasOptions) {
method.addParameter(configurationName, "configuration");
}
// Determine all the aliases
String[] springBeanAliases = componentAliases.stream().map(alias -> alias + "-component").toArray(size -> new String[size]);
method.addAnnotation(Lazy.class);
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.component", (overrideComponentName != null ? overrideComponentName : model.getScheme()).toLowerCase(Locale.US)));
sortImports(javaClass);
String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
writeSourceIfChanged(javaClass, fileName);
writeAdditionalSpringMetaData("camel", "component", (overrideComponentName != null ? overrideComponentName : model.getScheme()).toLowerCase(Locale.US));
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class SpringBootAutoConfigurationMojo method getProjectClassLoader.
protected ClassLoader getProjectClassLoader() throws MojoFailureException {
final List classpathElements;
try {
classpathElements = project.getTestClasspathElements();
} catch (org.apache.maven.artifact.DependencyResolutionRequiredException e) {
throw new MojoFailureException(e.getMessage(), e);
}
final URL[] urls = new URL[classpathElements.size()];
int i = 0;
for (Iterator it = classpathElements.iterator(); it.hasNext(); i++) {
try {
urls[i] = new File((String) it.next()).toURI().toURL();
} catch (MalformedURLException e) {
throw new MojoFailureException(e.getMessage(), e);
}
}
final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
return new URLClassLoader(urls, tccl != null ? tccl : getClass().getClassLoader());
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareCatalogMojo method executeArchetypes.
protected void executeArchetypes() throws MojoExecutionException, MojoFailureException {
getLog().info("Copying Archetype Catalog");
// find the generate catalog
File file = new File(archetypesDir, "target/classes/archetype-catalog.xml");
// make sure to create out dir
archetypesOutDir.mkdirs();
if (file.exists() && file.isFile()) {
File to = new File(archetypesOutDir, file.getName());
try {
copyFile(file, to);
} catch (IOException e) {
throw new MojoFailureException("Cannot copy file from " + file + " -> " + to, e);
}
}
}
Aggregations