Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.4.1 #152

Merged
merged 20 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b958cc9
Fix error in mariadb on encoded password (#134)
rainbowdashlabs Nov 23, 2023
96f1e00
Bump version to 1.4.1
rainbowdashlabs Nov 23, 2023
e2e1c1e
Fix mariadb mapper implementation (#135)
rainbowdashlabs Nov 23, 2023
71974a4
fix(deps): update dependency org.xerial:sqlite-jdbc to v3.43.0.0 (#120)
renovate[bot] Nov 23, 2023
5300692
chore(deps): update plugin com.diffplug.spotless to v6.23.0
renovate[bot] Nov 27, 2023
9f4d5fe
chore(deps): update plugin com.diffplug.spotless to v6.23.1
renovate[bot] Nov 29, 2023
7fa1d64
chore(deps): update dependency gradle to v8.5
renovate[bot] Nov 29, 2023
0abbf03
chore(deps): update plugin com.diffplug.spotless to v6.23.2
renovate[bot] Nov 30, 2023
bc596b5
chore(deps): update actions/setup-java action to v4
renovate[bot] Nov 30, 2023
3560c24
chore(deps): update plugin com.diffplug.spotless to v6.23.3
renovate[bot] Dec 4, 2023
a16f1ab
fix(deps): update dependency org.postgresql:postgresql to v42.7.1
renovate[bot] Dec 10, 2023
bdd9bbc
fix(deps): update slf4j monorepo to v2.0.11 (#146)
renovate[bot] Jan 23, 2024
4e30701
fix(deps): update dependency org.mariadb.jdbc:mariadb-java-client to …
renovate[bot] Jan 23, 2024
4f2364a
Allow to inject classloader (#147)
rainbowdashlabs Jan 23, 2024
1c94c99
chore(deps): update plugin com.diffplug.spotless to v6.25.0
renovate[bot] Jan 23, 2024
68f7560
fix(deps): update dependency org.xerial:sqlite-jdbc to v3.45.0.0 (#136)
renovate[bot] Jan 23, 2024
21b9b69
chore(deps): update plugin org.gradle.toolchains.foojay-resolver-conv…
renovate[bot] Jan 23, 2024
02fb4c5
fix(deps): update dependency com.mysql:mysql-connector-j to v8.3.0 (#…
renovate[bot] Jan 23, 2024
2a6322e
chore(deps): update plugin de.chojo.publishdata to v1.4.0
renovate[bot] Jan 23, 2024
78ab6ac
Define repos everywhere
rainbowdashlabs Jan 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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