Skip to content

Commit

Permalink
Release 1.4.1 (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs authored Jan 23, 2024
2 parents 435da9f + 78ab6ac commit 8e506cf
Show file tree
Hide file tree
Showing 38 changed files with 707 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/javadocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up JDK 15
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: adopt
java-version: 15
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up JDK 15
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: adopt
java-version: 15
- name: Build with Gradle
run: ./gradlew --build-cache build
- name: Test with Gradle
run: ./gradlew test
run: ./gradlew --build-cache test
- name: Publish to Maven Central
run: ./gradlew publish -PforceSign=true
env:
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up JDK 15
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: adopt
java-version: 15
- name: Build with Gradle
run: ./gradlew --build-cache build
- name: Test with Gradle
run: ./gradlew test
run: ./gradlew --build-cache test
11 changes: 8 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
java
`maven-publish`
`java-library`
id("de.chojo.publishdata") version "1.2.5"
id("de.chojo.publishdata") version "1.4.0"
alias(libs.plugins.spotless)
alias(libs.plugins.indra.core)
alias(libs.plugins.indra.publishing)
Expand All @@ -15,7 +15,7 @@ plugins {

publishData {
useEldoNexusRepos(false)
publishingVersion = "1.4.0"
publishingVersion = "1.4.1"
}

group = "de.chojo.sadu"
Expand Down Expand Up @@ -116,6 +116,11 @@ allprojects {
maven("https://eldonexus.de/repository/maven-proxies/")
}

publishData {
useEldoNexusRepos(false)
}


dependencies {
testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.10.1")
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", "5.10.1")
Expand Down Expand Up @@ -162,7 +167,7 @@ tasks {
register<Javadoc>("alljavadoc") {
applyJavaDocOptions(options)

destinationDir = file("${buildDir}/docs/javadoc")
destinationDir = file("${layout.buildDirectory}/docs/javadoc")
val projects = project.rootProject.allprojects.filter { p -> !p.name.contains("example") }
setSource(projects.map { p -> p.sourceSets.main.get().allJava })
classpath = files(projects.map { p -> p.sourceSets.main.get().compileClasspath })
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,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion sadu-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description = "SADU core module, containing common logic between modules."

dependencies {
api("org.slf4j", "slf4j-api", "2.0.9")
api(libs.slf4j.api)
api("org.jetbrains", "annotations", "24.1.0")
api("com.google.code.findbugs", "jsr305", "3.0.2")
}
3 changes: 3 additions & 0 deletions sadu-core/src/main/java/de/chojo/sadu/jdbc/JdbProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public String key() {
public String value() {
return URLEncoder.encode(String.valueOf(value), StandardCharsets.UTF_8);
}
public String valueRaw() {
return String.valueOf(value);
}

@Override
public boolean equals(Object o) {
Expand Down
17 changes: 17 additions & 0 deletions sadu-core/src/main/java/de/chojo/sadu/jdbc/JdbcConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.sql.Driver;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -120,6 +121,22 @@ protected String parameter() {
.collect(Collectors.joining("&"));
}

/**
* Removes the parameter from the parameter list
*
* @param key parameter key that should be removed
* @return the value associated with the key or null
*/
protected JdbProperty<?> removeParameter(String key) {
Optional<JdbProperty<?>> match = parameter.stream().filter(e -> e.key().equals(key)).findFirst();
match.ifPresent(v -> parameter.removeIf(e -> e.key().equals(key)));
return match.orElse(null);
}

protected Map<String, String> parameterRaw() {
return parameter.stream().collect(Collectors.toMap(JdbProperty::key, JdbProperty::value));
}

/**
* Get the jdbc url which combines the results of {@link #baseUrl()} and {@link #parameter()}
*
Expand Down
32 changes: 32 additions & 0 deletions sadu-core/src/main/java/de/chojo/sadu/jdbc/RemoteJdbcConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

package de.chojo.sadu.jdbc;

import org.jetbrains.annotations.ApiStatus;

import java.util.Optional;
import java.util.regex.Pattern;

/**
Expand Down Expand Up @@ -185,4 +188,33 @@ public T password(String password) {
public T user(String user) {
return addParameter("user", user);
}

/**
* Returns user credentials if the dataSourceCreator should set the credentials instead of jdbc url
*
* @return holding the credentials when they should be applied
*/
@ApiStatus.Internal
public Credentials userCredentials() {
return Credentials.EMPTY;
}

public static class Credentials {
public static final Credentials EMPTY = new Credentials(null,null);
private final JdbProperty<?> user;
private final JdbProperty<?> password;

public Credentials(JdbProperty<?> user, JdbProperty<?> password) {
this.user = user;
this.password = password;
}

public Optional<JdbProperty<?>> user() {
return Optional.ofNullable(user);
}

public Optional<JdbProperty<?>> password() {
return Optional.ofNullable(password);
}
}
}
18 changes: 18 additions & 0 deletions sadu-core/src/main/java/de/chojo/sadu/updater/SqlVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
* Class representing a version maintained by the SqlUpdaterBuilder
* <p>
Expand Down Expand Up @@ -85,4 +88,19 @@ public int compareTo(@NotNull SqlVersion o) {
}
return Integer.compare(patch, o.patch);
}

public static SqlVersion load() throws IOException {
return load(SqlVersion.class.getClassLoader());
}

public static SqlVersion load(ClassLoader classLoader) throws IOException {
var version = "";
try (var versionFile = classLoader.getResourceAsStream("database/version")) {
version = new String(versionFile.readAllBytes(), StandardCharsets.UTF_8).trim();
}

var ver = version.split("\\.");
return new SqlVersion(Integer.parseInt(ver[0]), Integer.parseInt(ver[1]));

}
}
19 changes: 17 additions & 2 deletions sadu-core/src/main/java/de/chojo/sadu/updater/UpdaterBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@

@ApiStatus.Internal
public interface UpdaterBuilder<T extends JdbcConfig<?>, S extends UpdaterBuilder<T, ?>> {
void setSource(DataSource source);
void setVersion(SqlVersion version);
/**
* Set the datasource that should be used
* @param source source
*/
S setSource(DataSource source);

/**
* Set the current db version that is expected
* @param version version
*/
S setVersion(SqlVersion version);

/**
* Set the Classloader that should be used to load resourced.
* @param classLoader classloader
*/
S withClassLoader(ClassLoader classLoader);
}
2 changes: 1 addition & 1 deletion sadu-datasource/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ dependencies {
api(project(":sadu-core"))

testImplementation(project(":sadu-sqlite"))
testImplementation("org.xerial:sqlite-jdbc:3.42.0.0")
testImplementation(testlibs.driver.sqlite)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
import de.chojo.sadu.databases.Database;
import de.chojo.sadu.datasource.stage.ConfigurationStage;
import de.chojo.sadu.datasource.stage.JdbcStage;
import de.chojo.sadu.jdbc.JdbProperty;
import de.chojo.sadu.jdbc.JdbcConfig;
import de.chojo.sadu.updater.UpdaterBuilder;
import de.chojo.sadu.jdbc.RemoteJdbcConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.CheckReturnValue;
import javax.sql.DataSource;
import java.util.Optional;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.function.Consumer;
Expand Down Expand Up @@ -59,10 +61,16 @@ public JdbcStage<T> configure(Consumer<T> builder) {
@CheckReturnValue
public ConfigurationStage create() {
loadDriverClass();
RemoteJdbcConfig.Credentials credentials = RemoteJdbcConfig.Credentials.EMPTY;
if (builder instanceof RemoteJdbcConfig) {
credentials = ((RemoteJdbcConfig)builder).userCredentials();
}
var jdbcUrl = builder.jdbcUrl();
log.info("Creating Hikari config using jdbc url: {}", jdbcUrl.replaceAll("password=.+?(&|$)", "password=******"));
hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl(jdbcUrl);
credentials.user().ifPresent(u -> hikariConfig.setUsername(u.valueRaw()));
credentials.password().ifPresent(u -> hikariConfig.setPassword(u.valueRaw()));
return this;
}

Expand Down
6 changes: 3 additions & 3 deletions sadu-examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ dependencies {
compileOnly(project(":"))

// database driver
compileOnly("org.xerial", "sqlite-jdbc", "3.42.0.0")
compileOnly("org.postgresql", "postgresql", "42.7.0")
compileOnly("org.mariadb.jdbc", "mariadb-java-client", "3.3.0")
compileOnly("org.xerial", "sqlite-jdbc", "3.45.0.0")
compileOnly("org.postgresql", "postgresql", "42.7.1")
compileOnly("org.mariadb.jdbc", "mariadb-java-client", "3.3.2")
compileOnly("mysql", "mysql-connector-java", "8.0.33")
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,6 @@ public <T> RowMapper<T> findOrWildcard(Class<T> clazz, ResultSetMetaData meta, M
if (mapper.isPresent()) {
return mapper.get();
}
throw MappingException.create(meta);
throw MappingException.create(clazz, meta);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ public MappingException(String message) {
}

public static MappingException create(ResultSetMetaData meta) throws SQLException {
return new MappingException("No mapper present for " + String.join(", ", Results.columnNames(meta)));
return new MappingException("No mapper present for %s of types %s".formatted(
String.join(", ", Results.columnNames(meta)),
String.join(", ", Results.columnTypes(meta)))
);
}

public static <T> MappingException create(Class<T> clazz, ResultSetMetaData meta) throws SQLException {
return new MappingException("No mapper present for columns %s of types %s to %s".formatted(
String.join(", ", Results.columnNames(meta)),
String.join(", ", Results.columnTypes(meta)),
clazz.getName())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,12 @@ public static Optional<Integer> getFirstColumnIndexOfType(ResultSetMetaData meta
}
return Optional.empty();
}

public static Set<String> columnTypes(ResultSetMetaData meta) throws SQLException {
Set<String> columns = new HashSet<>();
for (var i = 1; i <= meta.getColumnCount(); i++) {
columns.add("%s (%s)".formatted(meta.getColumnTypeName(i), meta.getColumnType(i)));
}
return columns;
}
}
5 changes: 4 additions & 1 deletion sadu-mariadb/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ description = "SADU module for interaction with a MariaDB database"
dependencies {
api(project(":sadu-updater"))

testImplementation("org.mariadb.jdbc", "mariadb-java-client", "3.3.0")
testImplementation(project(":sadu-queries"))
testImplementation(project(":sadu-datasource"))
testImplementation(testlibs.bundles.database.mariadb)
testImplementation(testlibs.slf4j.noop)
testImplementation(testlibs.bundles.junit)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

package de.chojo.sadu.jdbc;

import org.jetbrains.annotations.ApiStatus;

import java.util.Optional;

/**
* A builder to create a MariaDB jdbc url.
*/
Expand Down Expand Up @@ -173,6 +177,11 @@ protected String defaultDriverClass() {
return "org.mariadb.jdbc.Driver";
}

@Override
public Credentials userCredentials() {
return new Credentials(removeParameter("user"), removeParameter("password"));
}

/**
* Represents different SSL modes.
*/
Expand Down
Loading

0 comments on commit 8e506cf

Please sign in to comment.