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

Update dependencies and remove dependency on org.reflections #11

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ description 'The core functionality of ADAM'
sourceCompatibility = 21

dependencies {
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.11.1'
api 'com.google.guava:guava:33.3.0-jre'
implementation group: 'org.reflections', name: 'reflections', version: '0.9.12'
api group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '5.10.0.202012080955-r'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.0'
testImplementation group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
api group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '7.0.0.202409031743-r'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.16'
implementation group: 'org.clapper', name: 'javautil', version: '3.2.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.1'
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '3.0'
}

apply from: "${rootProject.projectDir}/publish.gradle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ch.ergon.adam.core.db.interfaces.SchemaSource;
import ch.ergon.adam.core.db.interfaces.SourceAndSinkAdapter;
import ch.ergon.adam.core.db.interfaces.SqlExecutor;
import org.reflections.Reflections;
import ch.ergon.adam.core.reflection.ReflectionHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -37,8 +37,7 @@ private static synchronized void createInstance() {
}

private SourceAndSinkFactory() {
Reflections reflections = new Reflections("ch.ergon.adam");
Set<Class<? extends SourceAndSinkAdapter>> adapterTypes = reflections.getSubTypesOf(SourceAndSinkAdapter.class);
Set<Class<? extends SourceAndSinkAdapter>> adapterTypes = ReflectionHelper.findAllSubClasses("ch.ergon.adam", SourceAndSinkAdapter.class);
adapters = adapterTypes.stream().map(this::createAdapterInstance).filter(Objects::nonNull).collect(toList());
adapters.forEach(adapter -> {
logger.debug("New migration adapter registered [" + adapter.getClass().getName() + "]");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package ch.ergon.adam.core.filetree;

import org.reflections.Reflections;
import org.reflections.scanners.ResourcesScanner;
import ch.ergon.adam.core.reflection.ReflectionHelper;

import java.io.InputStream;
import java.util.List;
import java.util.Set;

import static java.util.stream.Collectors.toList;

public class ClasspathTraverser implements FileTreeTraverser {

private final Reflections reflections;
private final String path;

public ClasspathTraverser(String path) {
Expand All @@ -20,25 +17,16 @@ public ClasspathTraverser(String path) {
} else {
this.path = path + "/";
}
reflections = new Reflections(this.path, new ResourcesScanner());
}

@Override
public InputStream openFile(String fileName) {
Set<String> resources = reflections.getResources(name -> name.equals(fileName));
if (resources.isEmpty()) {
return null;
}
if (resources.size() > 1) {
throw new RuntimeException("Found multiple resources with name [" + fileName + "].");
}
String filePath = resources.iterator().next();
return getClass().getClassLoader().getResourceAsStream(filePath);
return ClassLoader.getSystemClassLoader().getResourceAsStream(path + fileName);
}

@Override
public List<String> getFileNames() {
return reflections.getResources(name -> true).stream()
return ReflectionHelper.findAllRessourcesForPath(path).stream()
.map(name -> name.replaceFirst(path, ""))
.sorted()
.collect(toList());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package ch.ergon.adam.core.reflection;

import com.google.common.reflect.ClassPath;

import java.lang.reflect.Modifier;
import java.util.*;

import static java.util.stream.Collectors.toSet;

public class ReflectionHelper {

public final static Map<String, Set<Class<?>>> classesByPackageCache = new HashMap<>();
public final static Map<String, Set<String>> resourcesByPathCache = new HashMap<>();


private static Set<Class<?>> findAllClassesForPackage(String packageName) {
if (!classesByPackageCache.containsKey(packageName)) {
try {
Set<Class<?>> classes = ClassPath.from(ClassLoader.getSystemClassLoader()).getAllClasses()
.stream()
.filter(c -> c.getPackageName().startsWith(packageName))
.map(ClassPath.ClassInfo::getName)
.map(ReflectionHelper::getClass)
.collect(toSet());
classesByPackageCache.put(packageName, classes);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

return classesByPackageCache.get(packageName);
}

public static Set<String> findAllRessourcesForPath(String path) {
if (!resourcesByPathCache.containsKey(path)) {
try {
Set<String> resources = ClassPath.from(ClassLoader.getSystemClassLoader()).getResources()
.stream()
.filter(r -> r.getResourceName().startsWith(path))
.map(ClassPath.ResourceInfo::getResourceName)
.collect(toSet());
resourcesByPathCache.put(path, resources);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

return resourcesByPathCache.get(path);
}

private static Class<?> getClass(String className) {
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

public static <T> Set<Class<? extends T>> findAllSubClasses(String packageName, Class<T> superClass) {
return findAllClassesForPackage(packageName).stream()
.filter(superClass::isAssignableFrom)
.filter(c -> !c.isInterface() && !Modifier.isAbstract(c.getModifiers()))
.map(c -> (Class<? extends T>)c)
.collect(toSet());
}
}
10 changes: 3 additions & 7 deletions gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'java-gradle-plugin'
id 'maven-publish'
id 'com.gradle.plugin-publish' version '0.15.0'
id 'com.gradle.plugin-publish' version '1.3.0'
id "ch.ergon.gradle.goodies.versioning"
}

Expand All @@ -17,20 +17,16 @@ dependencies {

apply from: "${rootProject.projectDir}/common.gradle"


pluginBundle {
gradlePlugin {
website = 'https://github.com/ergon/adam/'
vcsUrl = 'https://github.com/ergon/adam.git'
tags = ['database', 'schema', 'migration', 'postgresql', 'sqlite', 'jooq', 'ergon']
}

gradlePlugin {
plugins {
adamPlugin {
id = 'ch.ergon.adam'
displayName = 'ADAM Plugin'
description = 'Advanced DAtabase Migration to migrate database schema'
implementationClass = 'ch.ergon.adam.gradleplugin.AdamPlugin'
tags = ['database', 'schema', 'migration', 'postgresql', 'sqlite', 'jooq', 'ergon']
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion integration-test-db/src/main/resources/adam/target_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5
4
20 changes: 10 additions & 10 deletions integration-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@ repositories {
}

dependencies {
testImplementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.14.1'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
testImplementation 'org.apache.logging.log4j:log4j-slf4j2-impl:2.24.1'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.11.1'
testImplementation project(':core')
testImplementation project(':yml')
testImplementation project(':postgresql')
testImplementation project(':oracle')
testImplementation project(':sqlite')
testImplementation project(':integration-test-db')
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.1'
testImplementation group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
testImplementation("org.testcontainers:testcontainers:1.20.1")
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.1'
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '3.0'
testImplementation("org.testcontainers:testcontainers:1.20.2")
testImplementation("com.fasterxml.jackson.core:jackson-annotations") {
version {
strictly("2.12.2")
}
}
testImplementation("org.testcontainers:junit-jupiter:1.20.1")
testImplementation("org.testcontainers:postgresql:1.20.1")
testImplementation("org.postgresql:postgresql:42.7.1")
testImplementation("org.testcontainers:oracle-free:1.20.1")
testImplementation("org.testcontainers:junit-jupiter:1.20.2")
testImplementation("org.testcontainers:postgresql:1.20.2")
testImplementation("org.postgresql:postgresql:42.7.4")
testImplementation("org.testcontainers:oracle-free:1.20.2")
testImplementation('com.oracle.database.jdbc:ojdbc11:23.5.0.24.07')
testImplementation('org.jooq.pro:jooq:3.19.11')
}
Expand Down
2 changes: 1 addition & 1 deletion jooq/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description 'The jOOQ plugin for ADAM'
sourceCompatibility = 21

dependencies {
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.11.1'
api project(':core')
implementation group: 'org.jooq', name: 'jooq', version: '3.19.11'
}
Expand Down
2 changes: 1 addition & 1 deletion oracle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ description 'The Oracle plugin for ADAM'
sourceCompatibility = 21

dependencies {
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.11.1'
implementation project(':jooq')
implementation 'com.oracle.database.jdbc:ojdbc11:23.5.0.24.07'
implementation group: 'org.jooq.pro', name: 'jooq', version: '3.19.11'
Expand Down
4 changes: 2 additions & 2 deletions postgresql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ description 'The PostgreSQL plugin for ADAM'
sourceCompatibility = 21

dependencies {
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.11.1'
implementation project(':jooq')
implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.19'
implementation group: 'org.postgresql', name: 'postgresql', version: '42.7.4'
implementation group: 'org.jooq', name: 'jooq', version: '3.19.11'
}

Expand Down
4 changes: 2 additions & 2 deletions sqlite/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ description 'The SQLite plugin for ADAM'
sourceCompatibility = 21

dependencies {
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.11.1'
implementation project(':jooq')
implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.34.0'
implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.46.1.3'
implementation group: 'org.jooq', name: 'jooq', version: '3.19.11'
}

Expand Down
8 changes: 4 additions & 4 deletions yml/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ description 'The YML plugin for ADAM'
sourceCompatibility = 21

dependencies {
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.12.2'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.2'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.12.2'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.11.1'
implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.18.0'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.18.0'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.18.0'
implementation project(':core')
}

Expand Down
26 changes: 14 additions & 12 deletions yml/src/main/java/ch/ergon/adam/yml/YmlSink.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package ch.ergon.adam.yml;

import ch.ergon.adam.core.db.interfaces.SchemaSink;
import ch.ergon.adam.core.db.schema.*;
import ch.ergon.adam.yml.schema.*;
import ch.ergon.adam.core.db.interfaces.SchemaSink;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;

import java.io.File;
import java.io.IOException;
Expand All @@ -24,26 +24,28 @@ public class YmlSink implements SchemaSink {
private final File targetPath;
private final OutputStream outputStream;
private final ObjectMapper mapper;
private Set<Table> updatedTables = new HashSet<>();
private Set<Table> droppedTables = new HashSet<>();
private Set<View> updatedViews = new HashSet<>();
private Set<View> droppedViews = new HashSet<>();
private final Set<Table> updatedTables = new HashSet<>();
private final Set<Table> droppedTables = new HashSet<>();
private final Set<View> updatedViews = new HashSet<>();
private final Set<View> droppedViews = new HashSet<>();
private Schema targetSchema;

public YmlSink(File targetPath) {
this.targetPath = targetPath;
this.outputStream = null;
mapper = new ObjectMapper(new YAMLFactory());
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
mapper.setSerializationInclusion(NON_DEFAULT);
mapper = YAMLMapper.builder()
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
.serializationInclusion(NON_DEFAULT)
.build();
}

public YmlSink(OutputStream outputStream) {
this.targetPath = null;
this.outputStream = outputStream;
mapper = new ObjectMapper(new YAMLFactory());
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
mapper.setSerializationInclusion(NON_DEFAULT);
mapper = YAMLMapper.builder()
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
.serializationInclusion(NON_DEFAULT)
.build();
}

@Override
Expand Down
Loading