Search in sources :

Example 1 with BaseEnvironmentProvider

use of org.talend.sdk.component.junit.environment.BaseEnvironmentProvider in project component-runtime by Talend.

the class Generator method generatedJUnitEnvironment.

private static void generatedJUnitEnvironment(final File generatedDir) throws MalformedURLException {
    final File file = new File(generatedDir, "generated_junit-environments.adoc");
    try (final PrintStream stream = new PrintStream(new WriteIfDifferentStream(file))) {
        stream.println("");
        stream.println("NOTE: the configuration is read from system properties, environment variables, ....");
        stream.println("");
        stream.println("[role=\"table-striped table-hover table-ordered\",options=\"header,autowidth\"]");
        stream.println("|====");
        stream.println("|Class|Name|Description");
        final File api = jarLocation(BaseEnvironmentProvider.class);
        final ClassLoader loader = Thread.currentThread().getContextClassLoader();
        final AnnotationFinder finder = new AnnotationFinder(api.isDirectory() ? new FileArchive(loader, api) : new JarArchive(loader, api.toURI().toURL()));
        finder.link().findSubclasses(BaseEnvironmentProvider.class).stream().filter(c -> !Modifier.isAbstract(c.getModifiers())).sorted(Comparator.comparing(Class::getName)).forEach(type -> {
            final BaseEnvironmentProvider environment;
            try {
                environment = BaseEnvironmentProvider.class.cast(type.getConstructor().newInstance());
            } catch (final InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
                throw new IllegalStateException(e);
            }
            stream.println("|" + type.getSimpleName() + "|" + environment.getName() + "|" + environment.getName() + " runner");
        });
        stream.println("|====");
        stream.println();
    }
}
Also used : PrintStream(java.io.PrintStream) BaseEnvironmentProvider(org.talend.sdk.component.junit.environment.BaseEnvironmentProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) JarArchive(org.apache.xbean.finder.archive.JarArchive) FileArchive(org.apache.xbean.finder.archive.FileArchive) File(java.io.File) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder)

Aggregations

File (java.io.File)1 PrintStream (java.io.PrintStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 AnnotationFinder (org.apache.xbean.finder.AnnotationFinder)1 FileArchive (org.apache.xbean.finder.archive.FileArchive)1 JarArchive (org.apache.xbean.finder.archive.JarArchive)1 BaseEnvironmentProvider (org.talend.sdk.component.junit.environment.BaseEnvironmentProvider)1