Search in sources :

Example 1 with MavenReportException

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;
}
Also used : IntrospectionSupport(org.apache.camel.util.IntrospectionSupport) VelocityContext(org.apache.velocity.VelocityContext) ApiMethod(org.apache.camel.util.component.ApiMethod) TreeSet(java.util.TreeSet) ApiMethodHelper(org.apache.camel.util.component.ApiMethodHelper) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ApiName(org.apache.camel.util.component.ApiName) TreeMap(java.util.TreeMap) Map(java.util.Map) TreeMap(java.util.TreeMap) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 2 with MavenReportException

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);
    }
}
Also used : Locale(java.util.Locale) RenderingContext(org.apache.maven.doxia.siterenderer.RenderingContext) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SiteRendererSink(org.apache.maven.doxia.siterenderer.sink.SiteRendererSink) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 3 with MavenReportException

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Method(java.lang.reflect.Method) ApiMethod(org.apache.camel.util.component.ApiMethod) InvocationTargetException(java.lang.reflect.InvocationTargetException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 4 with MavenReportException

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);
    }
}
Also used : MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 5 with MavenReportException

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());
}
Also used : MalformedURLException(java.net.MalformedURLException) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) URLClassLoader(java.net.URLClassLoader) ArrayList(java.util.ArrayList) File(java.io.File) URL(java.net.URL) MavenReportException(org.apache.maven.reporting.MavenReportException)

Aggregations

MavenReportException (org.apache.maven.reporting.MavenReportException)48 File (java.io.File)23 IOException (java.io.IOException)23 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)14 ArrayList (java.util.ArrayList)10 Artifact (org.apache.maven.artifact.Artifact)7 FileOutputStream (java.io.FileOutputStream)6 Locale (java.util.Locale)6 BootclasspathArtifact (org.apache.maven.plugin.javadoc.options.BootclasspathArtifact)6 DocletArtifact (org.apache.maven.plugin.javadoc.options.DocletArtifact)6 JavadocPathArtifact (org.apache.maven.plugin.javadoc.options.JavadocPathArtifact)6 ResourcesArtifact (org.apache.maven.plugin.javadoc.options.ResourcesArtifact)6 TagletArtifact (org.apache.maven.plugin.javadoc.options.TagletArtifact)6 FileNotFoundException (java.io.FileNotFoundException)5 Writer (java.io.Writer)5 LinkedHashSet (java.util.LinkedHashSet)5 SiteRendererSink (org.apache.maven.doxia.siterenderer.sink.SiteRendererSink)5 OutputStreamWriter (java.io.OutputStreamWriter)4 MalformedURLException (java.net.MalformedURLException)3 HashMap (java.util.HashMap)3