Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #13 from ursjoss/chore/maintenance
Browse files Browse the repository at this point in the history
Maintenance
  • Loading branch information
ayedo authored Jun 14, 2020
2 parents 988d4d7 + 251d6bd commit c69debc
Show file tree
Hide file tree
Showing 16 changed files with 261 additions and 168 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Check

on:
push:
branches:
- master
tags:
- '*'

pull_request:
branches:
- master

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v1

- name: Set up JDK 1.11
uses: actions/setup-java@v1
with:
java-version: 1.11

- name: Cache global .gradle folder
uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: global-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/*.kt*') }}
restore-keys: |
gradle-cache-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
- name: Check with Gradle
run: ./gradlew check
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Jooq-Modelator
==============

[![GitHub license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://raw.githubusercontent.com/ayedo/jooq-modelator/master/LICENSE)
[![Build Status](https://github.com/ayedo/jooq-modelator/workflows/Build/badge.svg)](https://github.com/ayedo/jooq-modelator/actions)

## Overview

This gradle plugin generates Jooq metamodel classes from Flyway & Liquibase migration files. It does so by running them against a dockerized database, and then running the Jooq generator against that database.
Expand Down Expand Up @@ -31,8 +34,8 @@ The plugin has been tested with Version 18.06.1-ce-mac73 (26764).

Two migration engines are supported:

- Flyway (version '6.0.1')
- Liquibase (version '3.8.0')
- Flyway (version '6.4.4')
- Liquibase (version '3.10.0')

__For Liquibase there are limitations:__

Expand Down
16 changes: 8 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.50'
id 'com.gradle.plugin-publish' version '0.10.1'
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
id 'com.gradle.plugin-publish' version '0.12.0'
}

apply plugin: 'java-gradle-plugin'
Expand All @@ -25,19 +25,19 @@ dependencies {
compile('org.jetbrains.kotlin:kotlin-stdlib-jdk8')
compile('net.jodah:failsafe:1.1.1')
compile('com.spotify:docker-client:8.16.0')
compile('org.flywaydb:flyway-core:6.0.1')
compile('org.liquibase:liquibase-core:3.8.0') {
compile('org.flywaydb:flyway-core:6.4.4')
compile('org.liquibase:liquibase-core:3.10.0') {
exclude group: 'ch.qos.logback', module: 'logback-classic'
}
compile('org.slf4j:slf4j-simple:1.7.28')
compile('org.slf4j:slf4j-api:1.7.30')

compile('javax.xml.bind:jaxb-api:2.3.1')
compile('com.sun.xml.bind:jaxb-core:2.3.0.1')
compile('javax.activation:activation:1.1.1')
compile('com.sun.xml.bind:jaxb-impl:2.3.2')
compile('com.sun.xml.bind:jaxb-impl:2.3.3')

testCompile('org.junit.jupiter:junit-jupiter-api:5.5.1')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.5.1')
testCompile('org.junit.jupiter:junit-jupiter-api:5.6.2')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.6.2')
}

pluginBundle {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
22 changes: 19 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
# Copyright 2015 the original author or authors.
#
# 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
#
# https://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.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down Expand Up @@ -109,8 +125,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
Expand Down
18 changes: 17 additions & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
Expand All @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ fun <T> DockerClient.useContainer(containerId: String, fn: () -> T) =

fun DockerClient.findLabeledContainers(key: String, value: String) =
this.listContainers(allContainers())
.filter({ container ->
.filter { container ->
container.labels()?.get(key) == value
})
}
3 changes: 2 additions & 1 deletion src/main/kotlin/ch/ayedo/jooqmodelator/core/HealthCheck.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ class FlywayDependentHealthChecker(databaseConfig: DatabaseConfig, healthCheckCo
withMaxDuration(maxDurationMs, MILLISECONDS)
}

@Suppress("RedundantLambdaArrow")
override fun waitForDatabase() {

net.jodah.failsafe.Failsafe.with<net.jodah.failsafe.RetryPolicy>(retryPolicy).run { ->
net.jodah.failsafe.Failsafe.with<RetryPolicy>(retryPolicy).run { _ ->

// for some reason 'use' does not work anymore
var connection: Connection? = null
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/ch/ayedo/jooqmodelator/core/Migration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection
import java.io.File
import java.nio.file.Path

@Suppress("SpellCheckingInspection")
interface Migrator {

/* deletes all objects in the database */
Expand Down Expand Up @@ -69,8 +70,8 @@ class LiquibaseMigrator(databaseConfig: DatabaseConfig, migrationsPaths: List<Pa
}

val changeLogFiles = migrationsPaths
.map({ path -> path.toFile() })
.flatMap({ file: File -> file.listFiles({ pathName -> pathName.nameWithoutExtension == "databaseChangeLog" }).toList() })
.map { path -> path.toFile() }
.flatMap { file: File -> file.listFiles { pathName -> pathName.nameWithoutExtension == "databaseChangeLog" }?.toList() ?: emptyList() }

if (changeLogFiles.isEmpty()) {
throw IllegalStateException("Cannot find liquibase changelog file. It must be named 'databaseChangeLog'.")
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/ch/ayedo/jooqmodelator/core/Modelator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ch.ayedo.jooqmodelator.core.configuration.DatabaseConfig
import com.spotify.docker.client.DefaultDockerClient
import org.slf4j.LoggerFactory

@Suppress("SpellCheckingInspection")
class Modelator(configuration: Configuration) {

private val log = LoggerFactory.getLogger(Modelator::class.java)
Expand Down Expand Up @@ -39,7 +40,7 @@ class Modelator(configuration: Configuration) {
log.warn("More than one container with tag ${dockerConfig.labelKey}=$tag has been found. " +
"Using the one which was most recently created")
}
existingContainers.sortedBy({ it.created() }).map({ it.id() }).first()
existingContainers.sortedBy { it.created() }.map { it.id() }.first()
}

docker.useContainer(containerId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum class MigrationEngine {
LIQUIBASE
}

@Suppress("SpellCheckingInspection")
data class DockerConfig(val tag: String,
val labelKey: String = "ch.ayedo.jooqmodelator",
val env: List<String>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.ayedo.jooqmodelator.gradle


@Suppress("SpellCheckingInspection")
open class JooqModelatorExtension {

var jooqVersion: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import java.nio.file.Paths


@Suppress("SpellCheckingInspection")
open class JooqModelatorPlugin : Plugin<Project> {

override fun apply(project: Project) {
Expand All @@ -16,7 +16,7 @@ open class JooqModelatorPlugin : Plugin<Project> {

modelatorRuntime.description = "Add JDBC drivers or generator extensions here."

project.afterEvaluate({
project.afterEvaluate {

val config = project.extensions.findByType(JooqModelatorExtension::class.java)!!

Expand All @@ -29,9 +29,9 @@ open class JooqModelatorPlugin : Plugin<Project> {
?: throw IncompletePluginConfigurationException("path to the jOOQ generator configuration (jooqConfigPath)"))

jooqOutputPath = Paths.get(config.jooqOutputPath
?: throw IncompletePluginConfigurationException("path to the output directory (jooqOutputDirectory)"))
?: throw IncompletePluginConfigurationException("path to the output directory (jooqOutputPath)"))

migrationsPaths = config.migrationsPaths?.map({ strPath -> Paths.get(strPath) })
migrationsPaths = config.migrationsPaths?.map { strPath -> Paths.get(strPath) }
?: throw IncompletePluginConfigurationException("path to the migration files (migrationsPaths)")

dockerLabelKey = config.labelKey
Expand Down Expand Up @@ -63,7 +63,7 @@ open class JooqModelatorPlugin : Plugin<Project> {
for (migrationPath in task.migrationsPaths) {
task.inputs.dir(migrationPath)
}
})
}


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import ch.ayedo.jooqmodelator.core.configuration.PortMapping
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import java.net.URL
import java.net.URLClassLoader
import java.nio.file.Path


@Suppress("SpellCheckingInspection")
open class JooqModelatorTask : DefaultTask() {

@InputFile
Expand All @@ -25,6 +27,7 @@ open class JooqModelatorTask : DefaultTask() {
@OutputDirectory
lateinit var jooqOutputPath: Path

@InputFiles
lateinit var migrationsPaths: List<Path>

@Input
Expand Down
Loading

0 comments on commit c69debc

Please sign in to comment.