Skip to content

Commit a44c74f

Browse files
authored
Merge pull request #11 from ergon/update_deps
Update dependencies and remove dependency on org.reflections
2 parents 91b1211 + 4a2974b commit a44c74f

File tree

13 files changed

+115
-64
lines changed

13 files changed

+115
-64
lines changed

core/build.gradle

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ description 'The core functionality of ADAM'
99
sourceCompatibility = 21
1010

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

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

core/src/main/java/ch/ergon/adam/core/db/SourceAndSinkFactory.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import ch.ergon.adam.core.db.interfaces.SchemaSource;
55
import ch.ergon.adam.core.db.interfaces.SourceAndSinkAdapter;
66
import ch.ergon.adam.core.db.interfaces.SqlExecutor;
7-
import org.reflections.Reflections;
7+
import ch.ergon.adam.core.reflection.ReflectionHelper;
88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
1010

@@ -37,8 +37,7 @@ private static synchronized void createInstance() {
3737
}
3838

3939
private SourceAndSinkFactory() {
40-
Reflections reflections = new Reflections("ch.ergon.adam");
41-
Set<Class<? extends SourceAndSinkAdapter>> adapterTypes = reflections.getSubTypesOf(SourceAndSinkAdapter.class);
40+
Set<Class<? extends SourceAndSinkAdapter>> adapterTypes = ReflectionHelper.findAllSubClasses("ch.ergon.adam", SourceAndSinkAdapter.class);
4241
adapters = adapterTypes.stream().map(this::createAdapterInstance).filter(Objects::nonNull).collect(toList());
4342
adapters.forEach(adapter -> {
4443
logger.debug("New migration adapter registered [" + adapter.getClass().getName() + "]");

core/src/main/java/ch/ergon/adam/core/filetree/ClasspathTraverser.java

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package ch.ergon.adam.core.filetree;
22

3-
import org.reflections.Reflections;
4-
import org.reflections.scanners.ResourcesScanner;
3+
import ch.ergon.adam.core.reflection.ReflectionHelper;
54

65
import java.io.InputStream;
76
import java.util.List;
8-
import java.util.Set;
97

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

1210
public class ClasspathTraverser implements FileTreeTraverser {
1311

14-
private final Reflections reflections;
1512
private final String path;
1613

1714
public ClasspathTraverser(String path) {
@@ -20,25 +17,16 @@ public ClasspathTraverser(String path) {
2017
} else {
2118
this.path = path + "/";
2219
}
23-
reflections = new Reflections(this.path, new ResourcesScanner());
2420
}
2521

2622
@Override
2723
public InputStream openFile(String fileName) {
28-
Set<String> resources = reflections.getResources(name -> name.equals(fileName));
29-
if (resources.isEmpty()) {
30-
return null;
31-
}
32-
if (resources.size() > 1) {
33-
throw new RuntimeException("Found multiple resources with name [" + fileName + "].");
34-
}
35-
String filePath = resources.iterator().next();
36-
return getClass().getClassLoader().getResourceAsStream(filePath);
24+
return ClassLoader.getSystemClassLoader().getResourceAsStream(path + fileName);
3725
}
3826

3927
@Override
4028
public List<String> getFileNames() {
41-
return reflections.getResources(name -> true).stream()
29+
return ReflectionHelper.findAllRessourcesForPath(path).stream()
4230
.map(name -> name.replaceFirst(path, ""))
4331
.sorted()
4432
.collect(toList());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package ch.ergon.adam.core.reflection;
2+
3+
import com.google.common.reflect.ClassPath;
4+
5+
import java.lang.reflect.Modifier;
6+
import java.util.*;
7+
8+
import static java.util.stream.Collectors.toSet;
9+
10+
public class ReflectionHelper {
11+
12+
public final static Map<String, Set<Class<?>>> classesByPackageCache = new HashMap<>();
13+
public final static Map<String, Set<String>> resourcesByPathCache = new HashMap<>();
14+
15+
16+
private static Set<Class<?>> findAllClassesForPackage(String packageName) {
17+
if (!classesByPackageCache.containsKey(packageName)) {
18+
try {
19+
Set<Class<?>> classes = ClassPath.from(ClassLoader.getSystemClassLoader()).getAllClasses()
20+
.stream()
21+
.filter(c -> c.getPackageName().startsWith(packageName))
22+
.map(ClassPath.ClassInfo::getName)
23+
.map(ReflectionHelper::getClass)
24+
.collect(toSet());
25+
classesByPackageCache.put(packageName, classes);
26+
} catch (Exception e) {
27+
throw new RuntimeException(e);
28+
}
29+
}
30+
31+
return classesByPackageCache.get(packageName);
32+
}
33+
34+
public static Set<String> findAllRessourcesForPath(String path) {
35+
if (!resourcesByPathCache.containsKey(path)) {
36+
try {
37+
Set<String> resources = ClassPath.from(ClassLoader.getSystemClassLoader()).getResources()
38+
.stream()
39+
.filter(r -> r.getResourceName().startsWith(path))
40+
.map(ClassPath.ResourceInfo::getResourceName)
41+
.collect(toSet());
42+
resourcesByPathCache.put(path, resources);
43+
} catch (Exception e) {
44+
throw new RuntimeException(e);
45+
}
46+
}
47+
48+
return resourcesByPathCache.get(path);
49+
}
50+
51+
private static Class<?> getClass(String className) {
52+
try {
53+
return Class.forName(className);
54+
} catch (ClassNotFoundException e) {
55+
throw new RuntimeException(e);
56+
}
57+
}
58+
59+
public static <T> Set<Class<? extends T>> findAllSubClasses(String packageName, Class<T> superClass) {
60+
return findAllClassesForPackage(packageName).stream()
61+
.filter(superClass::isAssignableFrom)
62+
.filter(c -> !c.isInterface() && !Modifier.isAbstract(c.getModifiers()))
63+
.map(c -> (Class<? extends T>)c)
64+
.collect(toSet());
65+
}
66+
}

gradle-plugin/build.gradle

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id 'java-gradle-plugin'
33
id 'maven-publish'
4-
id 'com.gradle.plugin-publish' version '0.15.0'
4+
id 'com.gradle.plugin-publish' version '1.3.0'
55
id "ch.ergon.gradle.goodies.versioning"
66
}
77

@@ -17,20 +17,16 @@ dependencies {
1717

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

20-
21-
pluginBundle {
20+
gradlePlugin {
2221
website = 'https://github.com/ergon/adam/'
2322
vcsUrl = 'https://github.com/ergon/adam.git'
24-
tags = ['database', 'schema', 'migration', 'postgresql', 'sqlite', 'jooq', 'ergon']
25-
}
26-
27-
gradlePlugin {
2823
plugins {
2924
adamPlugin {
3025
id = 'ch.ergon.adam'
3126
displayName = 'ADAM Plugin'
3227
description = 'Advanced DAtabase Migration to migrate database schema'
3328
implementationClass = 'ch.ergon.adam.gradleplugin.AdamPlugin'
29+
tags = ['database', 'schema', 'migration', 'postgresql', 'sqlite', 'jooq', 'ergon']
3430
}
3531
}
3632
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5
1+
4

integration-test/build.gradle

+10-10
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,27 @@ repositories {
2222
}
2323

2424
dependencies {
25-
testImplementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.14.1'
26-
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
25+
testImplementation 'org.apache.logging.log4j:log4j-slf4j2-impl:2.24.1'
26+
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.11.1'
2727
testImplementation project(':core')
2828
testImplementation project(':yml')
2929
testImplementation project(':postgresql')
3030
testImplementation project(':oracle')
3131
testImplementation project(':sqlite')
3232
testImplementation project(':integration-test-db')
33-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1'
34-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.1'
35-
testImplementation group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
36-
testImplementation("org.testcontainers:testcontainers:1.20.1")
33+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.1'
34+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.1'
35+
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '3.0'
36+
testImplementation("org.testcontainers:testcontainers:1.20.2")
3737
testImplementation("com.fasterxml.jackson.core:jackson-annotations") {
3838
version {
3939
strictly("2.12.2")
4040
}
4141
}
42-
testImplementation("org.testcontainers:junit-jupiter:1.20.1")
43-
testImplementation("org.testcontainers:postgresql:1.20.1")
44-
testImplementation("org.postgresql:postgresql:42.7.1")
45-
testImplementation("org.testcontainers:oracle-free:1.20.1")
42+
testImplementation("org.testcontainers:junit-jupiter:1.20.2")
43+
testImplementation("org.testcontainers:postgresql:1.20.2")
44+
testImplementation("org.postgresql:postgresql:42.7.4")
45+
testImplementation("org.testcontainers:oracle-free:1.20.2")
4646
testImplementation('com.oracle.database.jdbc:ojdbc11:23.5.0.24.07')
4747
testImplementation('org.jooq.pro:jooq:3.19.11')
4848
}

jooq/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description 'The jOOQ plugin for ADAM'
99
sourceCompatibility = 21
1010

1111
dependencies {
12-
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
12+
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.11.1'
1313
api project(':core')
1414
implementation group: 'org.jooq', name: 'jooq', version: '3.19.11'
1515
}

oracle/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ description 'The Oracle plugin for ADAM'
2323
sourceCompatibility = 21
2424

2525
dependencies {
26-
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
26+
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.11.1'
2727
implementation project(':jooq')
2828
implementation 'com.oracle.database.jdbc:ojdbc11:23.5.0.24.07'
2929
implementation group: 'org.jooq.pro', name: 'jooq', version: '3.19.11'

postgresql/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ description 'The PostgreSQL plugin for ADAM'
99
sourceCompatibility = 21
1010

1111
dependencies {
12-
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
12+
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.11.1'
1313
implementation project(':jooq')
14-
implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.19'
14+
implementation group: 'org.postgresql', name: 'postgresql', version: '42.7.4'
1515
implementation group: 'org.jooq', name: 'jooq', version: '3.19.11'
1616
}
1717

sqlite/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ description 'The SQLite plugin for ADAM'
99
sourceCompatibility = 21
1010

1111
dependencies {
12-
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
12+
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.11.1'
1313
implementation project(':jooq')
14-
implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.34.0'
14+
implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.46.1.3'
1515
implementation group: 'org.jooq', name: 'jooq', version: '3.19.11'
1616
}
1717

yml/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ description 'The YML plugin for ADAM'
99
sourceCompatibility = 21
1010

1111
dependencies {
12-
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
13-
implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.12.2'
14-
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.2'
15-
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.12.2'
12+
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.11.1'
13+
implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.18.0'
14+
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.18.0'
15+
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.18.0'
1616
implementation project(':core')
1717
}
1818

yml/src/main/java/ch/ergon/adam/yml/YmlSink.java

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package ch.ergon.adam.yml;
22

3+
import ch.ergon.adam.core.db.interfaces.SchemaSink;
34
import ch.ergon.adam.core.db.schema.*;
45
import ch.ergon.adam.yml.schema.*;
5-
import ch.ergon.adam.core.db.interfaces.SchemaSink;
66
import com.fasterxml.jackson.databind.MapperFeature;
77
import com.fasterxml.jackson.databind.ObjectMapper;
8-
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
8+
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
99

1010
import java.io.File;
1111
import java.io.IOException;
@@ -24,26 +24,28 @@ public class YmlSink implements SchemaSink {
2424
private final File targetPath;
2525
private final OutputStream outputStream;
2626
private final ObjectMapper mapper;
27-
private Set<Table> updatedTables = new HashSet<>();
28-
private Set<Table> droppedTables = new HashSet<>();
29-
private Set<View> updatedViews = new HashSet<>();
30-
private Set<View> droppedViews = new HashSet<>();
27+
private final Set<Table> updatedTables = new HashSet<>();
28+
private final Set<Table> droppedTables = new HashSet<>();
29+
private final Set<View> updatedViews = new HashSet<>();
30+
private final Set<View> droppedViews = new HashSet<>();
3131
private Schema targetSchema;
3232

3333
public YmlSink(File targetPath) {
3434
this.targetPath = targetPath;
3535
this.outputStream = null;
36-
mapper = new ObjectMapper(new YAMLFactory());
37-
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
38-
mapper.setSerializationInclusion(NON_DEFAULT);
36+
mapper = YAMLMapper.builder()
37+
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
38+
.serializationInclusion(NON_DEFAULT)
39+
.build();
3940
}
4041

4142
public YmlSink(OutputStream outputStream) {
4243
this.targetPath = null;
4344
this.outputStream = outputStream;
44-
mapper = new ObjectMapper(new YAMLFactory());
45-
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
46-
mapper.setSerializationInclusion(NON_DEFAULT);
45+
mapper = YAMLMapper.builder()
46+
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
47+
.serializationInclusion(NON_DEFAULT)
48+
.build();
4749
}
4850

4951
@Override

0 commit comments

Comments
 (0)