Skip to content

Commit

Permalink
Apply spotless code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaprasadreddy committed May 7, 2023
1 parent 1e25a59 commit 384b327
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 44 deletions.
34 changes: 27 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version>
<spotless-maven-plugin.version>2.36.0</spotless-maven-plugin.version>
<maven-plugin-api.version>3.9.0</maven-plugin-api.version>
<maven-plugin-annotations.version>3.8.1</maven-plugin-annotations.version>
<maven-project.version>2.2.1</maven-project.version>
<maven-core.version>3.9.0</maven-core.version>
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
<maven-source-plugin.version>3.2.0</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.4.1</maven-javadoc-plugin.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
<maven-plugin-plugin.version>3.6.0</maven-plugin-plugin.version>
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
Expand Down Expand Up @@ -196,6 +197,29 @@
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless-maven-plugin.version}</version>
<configuration>
<java>
<importOrder />
<removeUnusedImports />
<palantirJavaFormat>
<version>2.30.0</version>
</palantirJavaFormat>
<formatAnnotations />
</java>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand All @@ -204,7 +228,7 @@
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
<goal>jar</goal>
</goals>
</execution>
</executions>
Expand All @@ -213,10 +237,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<inherited>true</inherited>
<configuration>
<source>${java.version}</source>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down
27 changes: 23 additions & 4 deletions src/main/java/com/sivalabs/jooq/codegen/DatabaseProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,37 @@
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.PostgreSQLContainer;

/**
* DatabaseProvider provides container instance for a given DatabaseType
*/
public class DatabaseProvider {

/**
* Default Postgres docker image
*/
public static final String POSTGRES_IMAGE = "postgres:15.2-alpine";
/**
* Default MySQL docker image
*/
public static final String MYSQL_IMAGE = "mysql:8.0.33";
/**
* Default MariaDB docker image
*/
public static final String MARIADB_IMAGE = "mariadb:10.11";

/**
* Instantiates a Docker container using Testcontainers for the given database type.
*/
static JdbcDatabaseContainer<?> getDatabaseContainer(DatabaseType dbType) {
switch (dbType) {
case POSTGRES: return new PostgreSQLContainer<>(POSTGRES_IMAGE);
case MYSQL: new MySQLContainer<>(MYSQL_IMAGE);
case MARIADB: new MariaDBContainer<>(MARIADB_IMAGE);
default: throw new RuntimeException("Unsupported DatabaseType");
case POSTGRES:
return new PostgreSQLContainer<>(POSTGRES_IMAGE);
case MYSQL:
new MySQLContainer<>(MYSQL_IMAGE);
case MARIADB:
new MariaDBContainer<>(MARIADB_IMAGE);
default:
throw new RuntimeException("Unsupported DatabaseType");
}
}
}
5 changes: 4 additions & 1 deletion src/main/java/com/sivalabs/jooq/codegen/DatabaseType.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.sivalabs.jooq.codegen;

/**
* Database Types supported by the plugin
*/
public enum DatabaseType {
POSTGRES,
MYSQL,
MARIADB
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.sivalabs.jooq.codegen;

import java.util.Properties;
import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.configuration.FluentConfiguration;

import java.util.Properties;

/**
* FlywayMigrationRunner executes the flyway migration scripts based on the given configuration properties.
*/
public class FlywayMigrationRunner {
private final FlywayProps flywayProps;

Expand All @@ -16,7 +18,7 @@ void run() {
FluentConfiguration configuration = new FluentConfiguration();
Properties properties = this.getFlywayConfig();
configuration.configuration(properties);
Flyway flyway = configuration.load();
Flyway flyway = configuration.load();
flyway.migrate();
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/sivalabs/jooq/codegen/FlywayProps.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.sivalabs.jooq.codegen;

/**
* Flyway configuration properties.
*/
public class FlywayProps {
private String jdbcUrl;
private String username;
Expand Down
50 changes: 21 additions & 29 deletions src/main/java/com/sivalabs/jooq/codegen/Plugin.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package com.sivalabs.jooq.codegen;

import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
Expand All @@ -10,25 +9,21 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;

import org.jooq.codegen.GenerationTool;
import org.jooq.meta.jaxb.Configuration;
import org.jooq.meta.jaxb.Jdbc;
import org.jooq.meta.jaxb.Target;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.jooq.codegen.GenerationTool;
import org.jooq.meta.jaxb.Configuration;
import org.jooq.meta.jaxb.Jdbc;
import org.jooq.meta.jaxb.Target;
import org.testcontainers.containers.JdbcDatabaseContainer;

@Mojo(
name = "generate",
defaultPhase = GENERATE_SOURCES,
requiresDependencyResolution = TEST,
threadSafe = true
)
/**
* Plugin entry point.
*/
@Mojo(name = "generate", defaultPhase = GENERATE_SOURCES, requiresDependencyResolution = TEST, threadSafe = true)
public class Plugin extends AbstractMojo {
@Parameter(property = "project", required = true, readonly = true)
private MavenProject project;
Expand Down Expand Up @@ -60,14 +55,14 @@ public void execute() throws MojoExecutionException {

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.");
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();
Expand All @@ -79,10 +74,10 @@ public void execute() throws MojoExecutionException {
String username;
String password;

if(this.jdbc == null ||
this.jdbc.getUrl() == null ||
this.jdbc.getUsername() == null ||
this.jdbc.getPassword() == null) {
if (this.jdbc == null
|| this.jdbc.getUrl() == null
|| this.jdbc.getUsername() == null
|| this.jdbc.getPassword() == null) {
container = DatabaseProvider.getDatabaseContainer(dbType);
container.start();

Expand Down Expand Up @@ -116,10 +111,7 @@ public void execute() throws MojoExecutionException {
generator.getTarget().setDirectory(DEFAULT_TARGET_DIRECTORY);
}

Jdbc jdbc = new Jdbc()
.withUrl(jdbcUrl)
.withUsername(username)
.withPassword(password);
Jdbc jdbc = new Jdbc().withUrl(jdbcUrl).withUsername(username).withPassword(password);

if (flyway.getLocations() != null && !flyway.getLocations().isEmpty()) {
FlywayMigrationRunner flywayRunner = new FlywayMigrationRunner(flyway);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/sivalabs/jooq/codegen/PluginProps.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.sivalabs.jooq.codegen;

/**
* Plugin configuration properties.
*/
public class PluginProps {
private DatabaseType dbType;
private FlywayProps flyway;
Expand Down

0 comments on commit 384b327

Please sign in to comment.