/*
 * Copyright 2015 Tsukasa Kitachi
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package sbtjooq.codegen.tool;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;


public class GenerationTool {

    private static final Logger logger = LoggerFactory.getLogger(GenerationTool.class);

    private static final Class<?> delegateClass;
    private static final MethodHandle delegateMain;

    static {
        final Class<?> clazz = detectGenerationToolClass();
        delegateClass = clazz;
        delegateMain = getMainMethod(clazz);
    }

    private static Class<?> detectGenerationToolClass() {
        try {
            return Class.forName("org.jooq.codegen.GenerationTool");
        } catch (ClassNotFoundException e) {
            try {
                return Class.forName("org.jooq.util.GenerationTool");
            } catch (ClassNotFoundException suppressed) {
                e.addSuppressed(suppressed);
                throw new RuntimeException(e);
            }
        }
    }

    private static MethodHandle getMainMethod(Class<?> mainClass) {
        final MethodType mainType = MethodType.methodType(void.class, String[].class);
        try {
            return MethodHandles.publicLookup().findStatic(mainClass, "main", mainType);
        } catch (NoSuchMethodException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }


    private static void showRunningInfo() {
        final String vendor = System.getProperty("java.vendor");
        final String version = System.getProperty("java.version");
        logger.info("Running {} ({} Java {})", delegateClass.getName(), vendor, version);
    }

    private static void showJooqLogo() {
        try {
            Class.forName("org.jooq.impl.DefaultRenderContext");
        } catch (ClassNotFoundException ignored) {
        }
    }

    public void generate(String[] args) throws Throwable {
        //noinspection ConfusingArgumentToVarargsMethod
        delegateMain.invokeExact(args);
    }

    public static void main(String[] args) throws Throwable {
        showRunningInfo();
        showJooqLogo();
        new GenerationTool().generate(args);
    }

}

@@ -796,16 +796,57 @@
 dType;%0A%0A
+/**%0A * Wrapper of jOOQ GenerationTool%0A */
 %0Apublic 
@@ -2512,32 +2512,186 @@
        %7D%0A    %7D%0A%0A
+    /**%0A     * Invoke jOOQ GenerationTool%0A     * @param configurations configuration files%0A     * @throws Throwable thrown by jOOQ GenerationTool%0A     */%0A
     public void 
@@ -2700,35 +2700,45 @@
 nerate(String%5B%5D 
-arg
+configuration
 s) throws Throwa
@@ -2832,29 +2832,168 @@
 keExact(
-args);%0A    %7D%0A
+configurations);%0A    %7D%0A%0A    /**%0A     * Entry point%0A     * @param args configuration files%0A     * @throws Throwable thrown by jOOQ GenerationTool%0A     */
 %0A    pub

Add GenerationTool JavaDoc