Search in sources :

Example 1 with Configuration

use of org.jooq.meta.jaxb.Configuration in project jOOQ by jOOQ.

the class Plugin method read.

private void read(String file) {
    getLog().info("Reading external configuration: " + file);
    File f = new File(file);
    if (!f.isAbsolute())
        f = new File(project.getBasedir(), file);
    try (FileInputStream in = new FileInputStream(f)) {
        Configuration configuration = GenerationTool.load(in);
        logging = MiniJAXB.append(logging, configuration.getLogging());
        onError = MiniJAXB.append(onError, configuration.getOnError());
        jdbc = MiniJAXB.append(jdbc, configuration.getJdbc());
        generator = MiniJAXB.append(generator, configuration.getGenerator());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Configuration(org.jooq.meta.jaxb.Configuration) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 2 with Configuration

use of org.jooq.meta.jaxb.Configuration in project jOOQ by jOOQ.

the class Plugin method execute.

@Override
public void execute() throws MojoExecutionException {
    if (skip) {
        getLog().info("Skipping jOOQ code generation");
        return;
    }
    if (configurationFiles != null && !configurationFiles.isEmpty())
        for (String file : configurationFiles) read(file);
    else if (configurationFile != null)
        read(configurationFile);
    // correctly at this point. We'll log them all here.
    if (generator == null) {
        getLog().error("Incorrect configuration of jOOQ code generation tool");
        getLog().error("\n" + "The jOOQ-codegen-maven module's generator configuration is not set up correctly.\n" + "This can have a variety of reasons, among which:\n" + "- Your pom.xml's <configuration> contains invalid XML according to " + XSD_CODEGEN + "\n" + "- There is a version or artifact mismatch between your pom.xml and your commandline");
        throw new MojoExecutionException("Incorrect configuration of jOOQ code generation tool. See error above for details.");
    }
    ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
    URLClassLoader pluginClassLoader = getClassLoader();
    try {
        // [#2886] Add the surrounding project's dependencies to the current classloader
        Thread.currentThread().setContextClassLoader(pluginClassLoader);
        // [#9727] The Maven basedir may be overridden by explicit configuration
        String actualBasedir = basedir == null ? project.getBasedir().getAbsolutePath() : basedir;
        // [#5881] Target is allowed to be null
        if (generator.getTarget() == null)
            generator.setTarget(new Target());
        if (generator.getTarget().getDirectory() == null)
            generator.getTarget().setDirectory(DEFAULT_TARGET_DIRECTORY);
        Configuration configuration = new Configuration();
        configuration.setLogging(logging);
        configuration.setOnError(onError);
        configuration.setJdbc(jdbc);
        configuration.setGenerator(generator);
        configuration.setBasedir(actualBasedir);
        if (getLog().isDebugEnabled())
            getLog().debug("Using this configuration:\n" + configuration);
        GenerationTool.generate(configuration);
    } catch (Exception ex) {
        throw new MojoExecutionException("Error running jOOQ code generation tool", ex);
    } finally {
        // [#2886] Restore old class loader
        Thread.currentThread().setContextClassLoader(oldCL);
        // [#7630] Close URLClassLoader to help free resources
        try {
            pluginClassLoader.close();
        }// Catch all possible errors to avoid suppressing the original exception
         catch (Throwable e) {
            getLog().error("Couldn't close the classloader.", e);
        }
    }
    project.addCompileSourceRoot(generator.getTarget().getDirectory());
}
Also used : Target(org.jooq.meta.jaxb.Target) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Configuration(org.jooq.meta.jaxb.Configuration) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 3 with Configuration

use of org.jooq.meta.jaxb.Configuration in project jOOQ by jOOQ.

the class GenerationTool method main.

public static void main(String[] args) throws Exception {
    JooqLogger.initSimpleFormatter();
    String[] files;
    if (args.length > 0) {
        files = args;
    } else {
        String property = System.getProperty("jooq.codegen.configurationFile");
        if (property != null) {
            files = new String[] { property };
        } else {
            log.error("Usage : GenerationTool <configuration-file>");
            System.exit(-1);
            return;
        }
    }
    for (String file : files) {
        InputStream in = GenerationTool.class.getResourceAsStream(file);
        try {
            // to some users who were unaware that this file is loaded from the classpath
            if (in == null && !file.startsWith("/"))
                in = GenerationTool.class.getResourceAsStream("/" + file);
            // [#3668] Also check the local file system for configuration files
            if (in == null && new File(file).exists())
                in = new FileInputStream(file);
            if (in == null) {
                log.error("Cannot find " + file + " on classpath, or in directory " + new File(".").getCanonicalPath());
                log.error("-----------");
                log.error("Please be sure it is located");
                log.error("  - on the classpath and qualified as a classpath location.");
                log.error("  - in the local directory or at a global path in the file system.");
                System.exit(-1);
                return;
            }
            // [#10463] Make sure logging threshold is set, in this special case
            Configuration configuration = load(in);
            setGlobalLoggingThreshold(configuration);
            log.info("Initialising properties", file);
            generate(configuration);
        } catch (Exception e) {
            log.error("Error in file: " + file + ". Error : " + e.getMessage(), e);
            System.exit(-1);
            return;
        } finally {
            if (in != null)
                in.close();
        }
    }
}
Also used : Configuration(org.jooq.meta.jaxb.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) StringUtils.defaultString(org.jooq.tools.StringUtils.defaultString) File(java.io.File) FileInputStream(java.io.FileInputStream) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 4 with Configuration

use of org.jooq.meta.jaxb.Configuration in project textdb by TextDB.

the class RunCodegen method main.

public static void main(String[] args) throws Exception {
    Path jooqXmlPath = Paths.get("core").resolve("conf").resolve("jooq-conf.xml");
    Configuration jooqConfig = GenerationTool.load(Files.newInputStream(jooqXmlPath));
    Path jdbcConfPath = Paths.get("core").resolve("conf").resolve("jdbc.conf");
    Config jdbcConfig = ConfigFactory.parseFile(jdbcConfPath.toFile());
    Jdbc jooqJdbcConfig = new Jdbc();
    jooqJdbcConfig.setDriver(jdbcConfig.getString("jdbc.driver"));
    jooqJdbcConfig.setUrl(jdbcConfig.getString("jdbc.url"));
    jooqJdbcConfig.setUsername(jdbcConfig.getString("jdbc.username"));
    jooqJdbcConfig.setPassword(jdbcConfig.getString("jdbc.password"));
    jooqConfig.setJdbc(jooqJdbcConfig);
    GenerationTool.generate(jooqConfig);
}
Also used : Path(java.nio.file.Path) Configuration(org.jooq.meta.jaxb.Configuration) Config(com.typesafe.config.Config) Jdbc(org.jooq.meta.jaxb.Jdbc)

Example 5 with Configuration

use of org.jooq.meta.jaxb.Configuration in project textdb by TextDB.

the class RunCodegen method main.

public static void main(String[] args) throws Exception {
    Path jooqXmlPath = Utils.getTexeraHomePath().resolve("conf").resolve("jooq-conf.xml");
    Configuration jooqConfig = GenerationTool.load(Files.newInputStream(jooqXmlPath));
    Path jdbcConfPath = Utils.getTexeraHomePath().resolve("conf").resolve("jdbc.conf");
    Config jdbcConfig = ConfigFactory.parseFile(jdbcConfPath.toFile());
    Jdbc jooqJdbcConfig = new Jdbc();
    jooqJdbcConfig.setDriver(jdbcConfig.getString("jdbc.driver"));
    jooqJdbcConfig.setUrl(jdbcConfig.getString("jdbc.url"));
    jooqJdbcConfig.setUsername(jdbcConfig.getString("jdbc.username"));
    jooqJdbcConfig.setPassword(jdbcConfig.getString("jdbc.password"));
    jooqConfig.setJdbc(jooqJdbcConfig);
    GenerationTool.generate(jooqConfig);
}
Also used : Path(java.nio.file.Path) Configuration(org.jooq.meta.jaxb.Configuration) Config(com.typesafe.config.Config) Jdbc(org.jooq.meta.jaxb.Jdbc)

Aggregations

Configuration (org.jooq.meta.jaxb.Configuration)5 IOException (java.io.IOException)3 Config (com.typesafe.config.Config)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 Path (java.nio.file.Path)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 Jdbc (org.jooq.meta.jaxb.Jdbc)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 URLClassLoader (java.net.URLClassLoader)1 SQLException (java.sql.SQLException)1 Target (org.jooq.meta.jaxb.Target)1 StringUtils.defaultString (org.jooq.tools.StringUtils.defaultString)1