use of org.apache.maven.reporting.MavenReportException in project camel by apache.
the class DocumentGeneratorMojo method getDocumentContext.
private VelocityContext getDocumentContext() throws MavenReportException {
final VelocityContext context = new VelocityContext();
context.put("helper", this);
// project GAV
context.put("groupId", project.getGroupId());
context.put("artifactId", project.getArtifactId());
context.put("version", project.getVersion());
// component URI format
// look for single API, no endpoint-prefix
@SuppressWarnings("unchecked") final Set<String> apiNames = new TreeSet<String>(collection.getApiNames());
context.put("apiNames", apiNames);
String suffix;
if (apiNames.size() == 1 && ((Set) apiNames).contains("")) {
suffix = "://endpoint?[options]";
} else {
suffix = "://endpoint-prefix/endpoint?[options]";
}
context.put("uriFormat", scheme + suffix);
// API helpers
final Map<String, ApiMethodHelper> apiHelpers = new TreeMap<String, ApiMethodHelper>();
for (Object element : collection.getApiHelpers().entrySet()) {
Map.Entry entry = (Map.Entry) element;
apiHelpers.put(((ApiName) entry.getKey()).getName(), (ApiMethodHelper) entry.getValue());
}
context.put("apiHelpers", apiHelpers);
// API methods and endpoint configurations
final Map<String, Class<? extends ApiMethod>> apiMethods = new TreeMap<String, Class<? extends ApiMethod>>();
final Map<String, Class<?>> apiConfigs = new TreeMap<String, Class<?>>();
for (Object element : collection.getApiMethods().entrySet()) {
Map.Entry entry = (Map.Entry) element;
final String name = ((ApiName) entry.getValue()).getName();
@SuppressWarnings("unchecked") Class<? extends ApiMethod> apiMethod = (Class<? extends ApiMethod>) entry.getKey();
apiMethods.put(name, apiMethod);
Class<?> configClass;
try {
configClass = getProjectClassLoader().loadClass(getEndpointConfigName(apiMethod));
} catch (ClassNotFoundException e) {
throw new MavenReportException(e.getMessage(), e);
} catch (MojoExecutionException e) {
throw new MavenReportException(e.getMessage(), e);
}
apiConfigs.put(name, configClass);
}
context.put("apiMethods", apiMethods);
context.put("apiConfigs", apiConfigs);
// API component properties
context.put("scheme", this.scheme);
context.put("componentName", this.componentName);
Class<?> configClass;
try {
configClass = getProjectClassLoader().loadClass(getComponentConfig());
} catch (ClassNotFoundException e) {
throw new MavenReportException(e.getMessage(), e);
} catch (MojoExecutionException e) {
throw new MavenReportException(e.getMessage(), e);
}
context.put("componentConfig", configClass);
// get declared and derived fields for component config
// use get/set methods instead of fields, since this class could inherit others, that have private fields
// so getDeclaredFields() won't work, like it does for generated endpoint config classes!!!
final Map<String, String> configFields = new TreeMap<String, String>();
do {
IntrospectionSupport.ClassInfo classInfo = IntrospectionSupport.cacheClass(configClass);
for (IntrospectionSupport.MethodInfo method : classInfo.methods) {
if (method.isSetter) {
configFields.put(method.getterOrSetterShorthandName, getCanonicalName(method.method.getParameterTypes()[0]));
}
}
configClass = configClass.getSuperclass();
} while (configClass != null && !configClass.equals(Object.class));
context.put("componentConfigFields", configFields);
return context;
}
use of org.apache.maven.reporting.MavenReportException in project camel by apache.
the class DocumentGeneratorMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
RenderingContext context = new RenderingContext(reportOutputDirectory, getOutputName() + ".html");
SiteRendererSink sink = new SiteRendererSink(context);
Locale locale = Locale.getDefault();
try {
generate(sink, locale);
} catch (MavenReportException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
use of org.apache.maven.reporting.MavenReportException in project camel by apache.
the class DocumentGeneratorMojo method loadApiCollection.
private void loadApiCollection() throws MavenReportException {
try {
final Class<?> collectionClass = getProjectClassLoader().loadClass(outPackage + "." + componentName + "ApiCollection");
final Method getCollection = collectionClass.getMethod("getCollection");
this.collection = (ApiCollection) getCollection.invoke(null);
} catch (ClassNotFoundException e) {
throw new MavenReportException(e.getMessage(), e);
} catch (NoSuchMethodException e) {
throw new MavenReportException(e.getMessage(), e);
} catch (InvocationTargetException e) {
throw new MavenReportException(e.getMessage(), e);
} catch (IllegalAccessException e) {
throw new MavenReportException(e.getMessage(), e);
} catch (MojoExecutionException e) {
throw new MavenReportException(e.getMessage(), e);
}
}
use of org.apache.maven.reporting.MavenReportException in project jewelcli by lexicalscope.
the class JewelCliReportMojo method interfaceClass.
private Class<?> interfaceClass(final ClassLoader classLoader) throws MavenReportException {
final String interfac3 = interfaces[0];
getLog().debug("generating command line interface report for " + interfac3);
try {
return classLoader.loadClass(interfac3);
} catch (final ClassNotFoundException e) {
throw new MavenReportException("Unable to load interface class " + interfac3, e);
}
}
use of org.apache.maven.reporting.MavenReportException in project jewelcli by lexicalscope.
the class JewelCliReportMojo method getClassLoader.
private ClassLoader getClassLoader() throws MavenReportException {
final List<URL> urls = new ArrayList<URL>();
try {
for (final Object object : project.getCompileClasspathElements()) {
final String path = (String) object;
final URL url = new File(path).toURL();
getLog().debug("adding classpath element " + url);
urls.add(url);
}
} catch (final MalformedURLException e) {
throw new MavenReportException("Unable to load command line interface class", e);
} catch (final DependencyResolutionRequiredException e) {
throw new MavenReportException("Unable to resolve dependencies of project", e);
}
return new URLClassLoader(urls.toArray(new URL[] {}), getClass().getClassLoader());
}
Aggregations