All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.objectos.masche.maven.plugin.CreateSchemaMojo Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2015 Objectos, Fábrica de Software LTDA.
 *
 * 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 br.com.objectos.masche.maven.plugin;

import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import br.com.objectos.db.core.SqlException;
import br.com.objectos.schema.info.SqlMeta;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/**
 * @author [email protected] (Marcio Endo)
 */
@Mojo(name = "create-schema", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
public class CreateSchemaMojo extends AbstractMojo {

  @Parameter(required = true)
  Vendor vendor;

  @Parameter(required = true)
  String server;

  @Parameter(required = true)
  int port;

  @Parameter(required = true)
  String db;

  @Parameter(required = true)
  String user;

  @Parameter(required = true)
  String password;

  @Parameter(required = true, defaultValue = "${basedir}/src/main/java")
  File sourceDirectory;

  @Parameter(required = false)
  Set exclusionSet = new HashSet<>();

  @Parameter
  private boolean skip;

  @Override
  public void execute() throws MojoExecutionException, MojoFailureException {
    if (!skip) {
      try {
        execute0();
      } catch (ClassNotFoundException e) {
        throw new MojoExecutionException("Could not load JDBC driver. "
            + "Are you sure you defined the correct plugin dependency?", e);
      } catch (IOException e) {
        throw new MojoExecutionException("Could not create database", e);
      } catch (SqlException e) {
        throw new MojoExecutionException("Could not create database", e);
      }
    }
  }

  private void execute0() throws ClassNotFoundException, IOException, SqlException {
    vendor.loadDriver();
    SqlMeta.builder()
        .dialect(vendor.dialect())
        .server(server)
        .port(port)
        .db(db)
        .user(user)
        .password(password)
        .sourceDirectory(sourceDirectory)
        .exclusionSet(exclusionSet)
        .build()
        .generate();
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy