From e2f26d77a2d20693df62061cad24d40da38cc863 Mon Sep 17 00:00:00 2001 From: Andreas Keefer Date: Tue, 14 Nov 2023 00:10:53 +0100 Subject: [PATCH 1/5] prepare next release --- README.md | 8 ++++++-- elasticsearch-evolution-core/pom.xml | 2 +- pom.xml | 2 +- spring-boot-starter-elasticsearch-evolution/pom.xml | 2 +- tests/migration-scripts/pom.xml | 2 +- tests/pom.xml | 2 +- tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml | 2 +- tests/test-spring-boot-2.2/pom.xml | 2 +- tests/test-spring-boot-2.3/pom.xml | 2 +- tests/test-spring-boot-2.4/pom.xml | 2 +- tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml | 2 +- tests/test-spring-boot-2.6/pom.xml | 2 +- tests/test-spring-boot-2.7/pom.xml | 2 +- tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml | 2 +- tests/test-spring-boot-3.1/pom.xml | 2 +- 15 files changed, 20 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index ca279776..c01f35d8 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ First add the latest version of Elasticsearch-Evolution spring boot starter as a com.senacor.elasticsearch.evolution spring-boot-starter-elasticsearch-evolution - 0.4.2 + 0.4.3 ``` @@ -77,7 +77,7 @@ First add the latest version of Elasticsearch-Evolution core as a dependency: com.senacor.elasticsearch.evolution elasticsearch-evolution-core - 0.4.2 + 0.4.3 ``` @@ -291,6 +291,10 @@ ElasticsearchEvolution.configure() ## 6 changelog +### v0.4.4-SNAPSHOT + +- ... + ### v0.4.3 - support out of order migration execution. diff --git a/elasticsearch-evolution-core/pom.xml b/elasticsearch-evolution-core/pom.xml index 3a6f8ef7..0b4087d6 100644 --- a/elasticsearch-evolution-core/pom.xml +++ b/elasticsearch-evolution-core/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.4.3 + 0.4.4-SNAPSHOT ../ elasticsearch-evolution-core diff --git a/pom.xml b/pom.xml index 2d8f00ef..80ba9074 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.4.3 + 0.4.4-SNAPSHOT pom org.springframework.boot diff --git a/spring-boot-starter-elasticsearch-evolution/pom.xml b/spring-boot-starter-elasticsearch-evolution/pom.xml index 95585efb..2c67c00e 100644 --- a/spring-boot-starter-elasticsearch-evolution/pom.xml +++ b/spring-boot-starter-elasticsearch-evolution/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.4.3 + 0.4.4-SNAPSHOT ../ spring-boot-starter-elasticsearch-evolution diff --git a/tests/migration-scripts/pom.xml b/tests/migration-scripts/pom.xml index 2b46b5d0..e84b6b96 100644 --- a/tests/migration-scripts/pom.xml +++ b/tests/migration-scripts/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.senacor.elasticsearch.evolution migration-scripts - 0.4.3 + 0.4.4-SNAPSHOT jar containing migration files jar diff --git a/tests/pom.xml b/tests/pom.xml index 7a499afe..87fda920 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.4.3 + 0.4.4-SNAPSHOT ../ tests diff --git a/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml b/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml index af66ca41..daf95889 100644 --- a/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.1-scriptsInJarFile - 0.4.3 + 0.4.4-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.2/pom.xml b/tests/test-spring-boot-2.2/pom.xml index 137a209c..935dc550 100644 --- a/tests/test-spring-boot-2.2/pom.xml +++ b/tests/test-spring-boot-2.2/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.2 - 0.4.3 + 0.4.4-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.3/pom.xml b/tests/test-spring-boot-2.3/pom.xml index 44bc4e82..49615d0e 100644 --- a/tests/test-spring-boot-2.3/pom.xml +++ b/tests/test-spring-boot-2.3/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.3 - 0.4.3 + 0.4.4-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.4/pom.xml b/tests/test-spring-boot-2.4/pom.xml index cd99aa2a..066c89f2 100644 --- a/tests/test-spring-boot-2.4/pom.xml +++ b/tests/test-spring-boot-2.4/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.4 - 0.4.3 + 0.4.4-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml b/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml index d5337653..819a07ca 100644 --- a/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.5-scriptsInJarFile - 0.4.3 + 0.4.4-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.6/pom.xml b/tests/test-spring-boot-2.6/pom.xml index 1278176b..59fded25 100644 --- a/tests/test-spring-boot-2.6/pom.xml +++ b/tests/test-spring-boot-2.6/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.6 - 0.4.3 + 0.4.4-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.7/pom.xml b/tests/test-spring-boot-2.7/pom.xml index f0c652c6..11f83110 100644 --- a/tests/test-spring-boot-2.7/pom.xml +++ b/tests/test-spring-boot-2.7/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.7 - 0.4.3 + 0.4.4-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml index 9cf1bf06..85c67d39 100644 --- a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-3.0-scriptsInJarFile - 0.4.3 + 0.4.4-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-3.1/pom.xml b/tests/test-spring-boot-3.1/pom.xml index a3a0e6ae..c6046d9d 100644 --- a/tests/test-spring-boot-3.1/pom.xml +++ b/tests/test-spring-boot-3.1/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-3.1 - 0.4.3 + 0.4.4-SNAPSHOT Demo project for Spring Boot From b696920574bdb08cf99354066085443ebd652aba Mon Sep 17 00:00:00 2001 From: Andreas Keefer Date: Tue, 14 Nov 2023 15:12:13 +0100 Subject: [PATCH 2/5] #238 add spring boot configuration metadata --- elasticsearch-evolution-core/pom.xml | 5 +++ .../ElasticsearchEvolutionConfigTest.java | 36 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/elasticsearch-evolution-core/pom.xml b/elasticsearch-evolution-core/pom.xml index 0b4087d6..55b05cb1 100644 --- a/elasticsearch-evolution-core/pom.xml +++ b/elasticsearch-evolution-core/pom.xml @@ -22,6 +22,11 @@ spring-boot true + + org.springframework.boot + spring-boot-configuration-processor + true + diff --git a/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/api/config/ElasticsearchEvolutionConfigTest.java b/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/api/config/ElasticsearchEvolutionConfigTest.java index ff5d0916..e6c4dbdf 100644 --- a/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/api/config/ElasticsearchEvolutionConfigTest.java +++ b/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/api/config/ElasticsearchEvolutionConfigTest.java @@ -1,9 +1,21 @@ package com.senacor.elasticsearch.evolution.core.api.config; +import com.senacor.elasticsearch.evolution.core.internal.migration.input.MigrationScriptReaderImpl; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; - +import org.reflections.Reflections; +import org.reflections.scanners.Scanners; +import org.reflections.util.ClasspathHelper; +import org.reflections.util.ConfigurationBuilder; +import org.reflections.util.FilterBuilder; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -13,6 +25,28 @@ */ class ElasticsearchEvolutionConfigTest { + @Test + void springConfigurationMmetadataJson_should_have_been_generated_by_springBootConfigurationProcessor() { + final String metadataPath = "META-INF"; + Reflections reflections = new Reflections(new ConfigurationBuilder() + .setScanners(Scanners.Resources) + .filterInputsBy(new FilterBuilder().includePackage(metadataPath)) + .setUrls(ClasspathHelper.forPackage(metadataPath))); + final List springConfigMetadata = reflections.getResources("spring-configuration-metadata\\.json") + .stream() + .map(resource -> { + try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(MigrationScriptReaderImpl.getInputStream(resource), StandardCharsets.UTF_8))) { + return bufferedReader.lines() + .collect(Collectors.joining("\n")); + } catch (IOException e) { + throw new IllegalStateException("can't read spring-configuration-metadata.json from classpath: " + resource, e); + } + }).collect(Collectors.toList()); + + assertThat(springConfigMetadata) + .anySatisfy(metadataContent -> assertThat(metadataContent).contains(ElasticsearchEvolutionConfig.class.getName())); + } + @Nested class validate { From 81d42a826b4c6b94eeeab1b0b2540ee03ae92458 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Nov 2023 01:52:39 +0000 Subject: [PATCH 3/5] Bump org.testcontainers:elasticsearch from 1.19.1 to 1.19.2 Bumps [org.testcontainers:elasticsearch](https://github.com/testcontainers/testcontainers-java) from 1.19.1 to 1.19.2. - [Release notes](https://github.com/testcontainers/testcontainers-java/releases) - [Changelog](https://github.com/testcontainers/testcontainers-java/blob/main/CHANGELOG.md) - [Commits](https://github.com/testcontainers/testcontainers-java/compare/1.19.1...1.19.2) --- updated-dependencies: - dependency-name: org.testcontainers:elasticsearch dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml | 2 +- tests/test-spring-boot-2.2/pom.xml | 2 +- tests/test-spring-boot-2.3/pom.xml | 2 +- tests/test-spring-boot-2.4/pom.xml | 2 +- tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml | 2 +- tests/test-spring-boot-2.6/pom.xml | 2 +- tests/test-spring-boot-2.7/pom.xml | 2 +- tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml | 2 +- tests/test-spring-boot-3.1/pom.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 80ba9074..14b6ab33 100644 --- a/pom.xml +++ b/pom.xml @@ -103,7 +103,7 @@ 7.5.2 0.10.2 - 1.19.1 + 1.19.2 1.18.30 1.14.9 diff --git a/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml b/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml index daf95889..4130d4a7 100644 --- a/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml @@ -18,7 +18,7 @@ 2.15.0 7.5.2 - 1.19.1 + 1.19.2 diff --git a/tests/test-spring-boot-2.2/pom.xml b/tests/test-spring-boot-2.2/pom.xml index 935dc550..3e4ae5c0 100644 --- a/tests/test-spring-boot-2.2/pom.xml +++ b/tests/test-spring-boot-2.2/pom.xml @@ -18,7 +18,7 @@ 2.15.0 7.5.2 - 1.19.1 + 1.19.2 diff --git a/tests/test-spring-boot-2.3/pom.xml b/tests/test-spring-boot-2.3/pom.xml index 49615d0e..e3a8d1cd 100644 --- a/tests/test-spring-boot-2.3/pom.xml +++ b/tests/test-spring-boot-2.3/pom.xml @@ -18,7 +18,7 @@ 2.15.0 7.5.2 - 1.19.1 + 1.19.2 diff --git a/tests/test-spring-boot-2.4/pom.xml b/tests/test-spring-boot-2.4/pom.xml index 066c89f2..cf569a05 100644 --- a/tests/test-spring-boot-2.4/pom.xml +++ b/tests/test-spring-boot-2.4/pom.xml @@ -18,7 +18,7 @@ 2.15.0 7.5.2 - 1.19.1 + 1.19.2 diff --git a/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml b/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml index 819a07ca..3879cc28 100644 --- a/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml @@ -18,7 +18,7 @@ 2.15.0 7.5.2 - 1.19.1 + 1.19.2 diff --git a/tests/test-spring-boot-2.6/pom.xml b/tests/test-spring-boot-2.6/pom.xml index 59fded25..50ebd4a1 100644 --- a/tests/test-spring-boot-2.6/pom.xml +++ b/tests/test-spring-boot-2.6/pom.xml @@ -18,7 +18,7 @@ 2.15.0 7.5.2 - 1.19.1 + 1.19.2 diff --git a/tests/test-spring-boot-2.7/pom.xml b/tests/test-spring-boot-2.7/pom.xml index 11f83110..06b3bf5b 100644 --- a/tests/test-spring-boot-2.7/pom.xml +++ b/tests/test-spring-boot-2.7/pom.xml @@ -18,7 +18,7 @@ 2.15.0 7.5.2 - 1.19.1 + 1.19.2 diff --git a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml index 85c67d39..c0532b0f 100644 --- a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml @@ -18,7 +18,7 @@ 2.15.0 7.5.2 - 1.19.1 + 1.19.2 diff --git a/tests/test-spring-boot-3.1/pom.xml b/tests/test-spring-boot-3.1/pom.xml index c6046d9d..c021faef 100644 --- a/tests/test-spring-boot-3.1/pom.xml +++ b/tests/test-spring-boot-3.1/pom.xml @@ -18,7 +18,7 @@ 2.15.0 7.5.2 - 1.19.1 + 1.19.2 From 34b38f94e5ca5cd2d49556daa407ed9d0574e882 Mon Sep 17 00:00:00 2001 From: Andreas Keefer Date: Thu, 16 Nov 2023 00:18:37 +0100 Subject: [PATCH 4/5] replaces unmaintained org.reflections library with classgraph to scan the classpath for migration files. Fixes #239 --- README.md | 9 +- elasticsearch-evolution-core/pom.xml | 6 +- .../config/ElasticsearchEvolutionConfig.java | 11 +-- .../input/MigrationScriptReaderImpl.java | 97 +++++-------------- .../ElasticsearchEvolutionConfigTest.java | 39 +++----- .../input/MigrationScriptReaderImplTest.java | 30 +++++- pom.xml | 10 +- .../pom.xml | 2 +- tests/migration-scripts/pom.xml | 2 +- tests/pom.xml | 2 +- .../pom.xml | 2 +- tests/test-spring-boot-2.2/pom.xml | 2 +- tests/test-spring-boot-2.3/pom.xml | 2 +- tests/test-spring-boot-2.4/pom.xml | 2 +- .../pom.xml | 2 +- tests/test-spring-boot-2.6/pom.xml | 2 +- tests/test-spring-boot-2.7/pom.xml | 2 +- .../pom.xml | 2 +- tests/test-spring-boot-3.1/pom.xml | 2 +- 19 files changed, 95 insertions(+), 131 deletions(-) diff --git a/README.md b/README.md index c01f35d8..1c3053e6 100644 --- a/README.md +++ b/README.md @@ -291,9 +291,10 @@ ElasticsearchEvolution.configure() ## 6 changelog -### v0.4.4-SNAPSHOT +### v0.5.0-SNAPSHOT -- ... +- added spring boot configuration metadata [#240](https://github.com/senacor/elasticsearch-evolution/pull/240) +- replaces unmaintained [org.reflections](https://github.com/ronmamo/reflections) library with [classgraph](https://github.com/classgraph/classgraph) to scan the classpath for migration files. Fixes [#239](https://github.com/senacor/elasticsearch-evolution/issues/239) ### v0.4.3 @@ -304,6 +305,10 @@ ElasticsearchEvolution.configure() - added regression tests on JDK 21 - added regression tests for spring boot 3.1 - update org.reflections:reflections from 0.9.12 to 0.10.2 [#233](https://github.com/senacor/elasticsearch-evolution/pull/233) thanks @RiVogel +- **KNOWN ISSUES**: + - [#239](https://github.com/senacor/elasticsearch-evolution/issues/239): Migration files not found in Spring Boot jar + - Workaround 1: downgrade `org.reflections:reflections` to `0.10.1` + - Workaround 2: downgrade `elasticsearch-evolution` to `0.4.2` ### v0.4.2 diff --git a/elasticsearch-evolution-core/pom.xml b/elasticsearch-evolution-core/pom.xml index 55b05cb1..d993ff2a 100644 --- a/elasticsearch-evolution-core/pom.xml +++ b/elasticsearch-evolution-core/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.4.4-SNAPSHOT + 0.5.0-SNAPSHOT ../ elasticsearch-evolution-core @@ -50,8 +50,8 @@ - org.reflections - reflections + io.github.classgraph + classgraph diff --git a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/api/config/ElasticsearchEvolutionConfig.java b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/api/config/ElasticsearchEvolutionConfig.java index 10b242c2..7983add7 100644 --- a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/api/config/ElasticsearchEvolutionConfig.java +++ b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/api/config/ElasticsearchEvolutionConfig.java @@ -27,6 +27,9 @@ public class ElasticsearchEvolutionConfig { /** * Locations of migrations scripts. Supported is classpath:some/path and file:/some/path + * The location is scanned recursive. + * NOTE: all scripts in all locations / subdirectories will be flatted and only the version number will be used to + * order them. */ private List locations = new ArrayList<>( Collections.singletonList("classpath:es/migration")); @@ -283,14 +286,6 @@ public ElasticsearchEvolutionConfig setHistoryMaxQuerySize(int historyMaxQuerySi return this; } - /** - * @deprecated use {@link #isValidateOnMigrate()} instead - */ - @Deprecated - public boolean getValidateOnMigrate() { - return isValidateOnMigrate(); - } - public boolean isValidateOnMigrate() { return validateOnMigrate; } diff --git a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImpl.java b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImpl.java index acbf6e8e..3e633001 100644 --- a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImpl.java +++ b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImpl.java @@ -3,34 +3,26 @@ import com.senacor.elasticsearch.evolution.core.api.MigrationException; import com.senacor.elasticsearch.evolution.core.api.migration.MigrationScriptReader; import com.senacor.elasticsearch.evolution.core.internal.model.migration.RawMigrationScript; -import java.util.regex.Pattern; -import org.reflections.Reflections; -import org.reflections.scanners.Scanners; -import org.reflections.util.ClasspathHelper; -import org.reflections.util.ConfigurationBuilder; -import org.reflections.util.FilterBuilder; +import io.github.classgraph.ClassGraph; +import io.github.classgraph.ScanResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.BufferedReader; +import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.net.URI; import java.net.URISyntaxException; -import java.net.URL; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Collection; +import java.util.ArrayList; import java.util.List; -import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import static java.util.Collections.emptySet; - /** * @author Andreas Keefer */ @@ -137,35 +129,26 @@ private Stream readScriptsFromClassPath(String location) { // otherwise e.g. "...location_some_suffix" will also be found when search for "...location". location = location + "/"; } - final String locationWithoutPrefixAsPackageNotation = location.substring(CLASSPATH_PREFIX.length()) - .replace("/", "."); - - final Collection urls = ClasspathHelper.forPackage(locationWithoutPrefixAsPackageNotation); - final Set resources; - if (urls.isEmpty()) { - // https://github.com/senacor/elasticsearch-evolution/issues/27 - // when the package is empty or does not exist, Reflections can't find any URLs to scan for - resources = emptySet(); - } else { - Reflections reflections = new Reflections(new ConfigurationBuilder() - .setScanners(Scanners.Resources) - .filterInputsBy(new FilterBuilder().includePackage(locationWithoutPrefixAsPackageNotation)) - .setUrls(urls)); - resources = reflections.getResources(Pattern.compile(esMigrationPrefix + ".*")) - .stream() - .filter(path -> isValidFilename(Paths.get(path).getFileName().toString())) - .collect(Collectors.toSet()); - } - return resources.stream().flatMap(resource -> { - logger.debug("reading migration script '{}' from classpath...", resource); - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(getInputStream(resource), encoding))) { - Path p = Paths.get(resource); - return read(bufferedReader, p.getFileName().toString()); - } catch (IOException e) { - throw new MigrationException("can't read script from classpath: " + resource, e); - } - }); + final String locationWithoutPrefix = location.substring(CLASSPATH_PREFIX.length()); + + List res = new ArrayList<>(); + try (ScanResult scanResult = new ClassGraph() + .acceptPaths(locationWithoutPrefix) + .scan()) { + scanResult.getAllResources() + .filter(resource -> isValidFilename(Paths.get(resource.getPath()).getFileName().toString())) + .forEach(resource -> { + logger.debug("reading migration script '{}' from classpath...", resource); + try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(resource.load()), encoding))) { + Path p = Paths.get(resource.getPath()); + res.addAll(read(bufferedReader, p.getFileName().toString()).collect(Collectors.toList())); + } catch (IOException e) { + throw new MigrationException("can't read script from classpath: " + resource, e); + } + }); + } + return res.stream(); } private Stream read(BufferedReader reader, String filename) { @@ -178,46 +161,12 @@ private Stream read(BufferedReader reader, String filename) return Stream.of(new RawMigrationScript().setFileName(filename).setContent(content)); } - public static InputStream getInputStream(String path) { - ClassLoader classLoader = getDefaultClassLoader(); - if (classLoader != null) { - return classLoader.getResourceAsStream(path); - } else { - return ClassLoader.getSystemResourceAsStream(path); - } - } - private boolean hasValidSuffix(String path) { return this.esMigrationSuffixes .stream() .anyMatch(suffix -> path.toLowerCase().endsWith(suffix.toLowerCase())); } - static ClassLoader getDefaultClassLoader() { - ClassLoader cl = null; - try { - cl = Thread.currentThread().getContextClassLoader(); - logger.trace("getDefaultClassLoader - Thread.currentThread().getContextClassLoader()='{}'", cl); - } catch (Throwable ex) { - // Cannot access thread context ClassLoader - falling back... - } - if (cl == null) { - // No thread context class loader -> use class loader of this class. - cl = MigrationScriptReaderImpl.class.getClassLoader(); - logger.trace("getDefaultClassLoader - MigrationScriptReaderImpl.class.getClassLoader()='{}'", cl); - if (cl == null) { - // getClassLoader() returning null indicates the bootstrap ClassLoader - try { - cl = ClassLoader.getSystemClassLoader(); - logger.trace("getDefaultClassLoader - ClassLoader.getSystemClassLoader()='{}'", cl); - } catch (Throwable ex) { - // Cannot access system ClassLoader - oh well, maybe the caller can live with null... - } - } - } - return cl; - } - private boolean isValidFilename(String fileName) { return hasValidSuffix(fileName) && fileName.startsWith(this.esMigrationPrefix); diff --git a/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/api/config/ElasticsearchEvolutionConfigTest.java b/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/api/config/ElasticsearchEvolutionConfigTest.java index e6c4dbdf..f865b350 100644 --- a/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/api/config/ElasticsearchEvolutionConfigTest.java +++ b/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/api/config/ElasticsearchEvolutionConfigTest.java @@ -1,18 +1,11 @@ package com.senacor.elasticsearch.evolution.core.api.config; -import com.senacor.elasticsearch.evolution.core.internal.migration.input.MigrationScriptReaderImpl; +import io.github.classgraph.ClassGraph; +import io.github.classgraph.ScanResult; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.reflections.Reflections; -import org.reflections.scanners.Scanners; -import org.reflections.util.ClasspathHelper; -import org.reflections.util.ConfigurationBuilder; -import org.reflections.util.FilterBuilder; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -27,21 +20,19 @@ class ElasticsearchEvolutionConfigTest { @Test void springConfigurationMmetadataJson_should_have_been_generated_by_springBootConfigurationProcessor() { - final String metadataPath = "META-INF"; - Reflections reflections = new Reflections(new ConfigurationBuilder() - .setScanners(Scanners.Resources) - .filterInputsBy(new FilterBuilder().includePackage(metadataPath)) - .setUrls(ClasspathHelper.forPackage(metadataPath))); - final List springConfigMetadata = reflections.getResources("spring-configuration-metadata\\.json") - .stream() - .map(resource -> { - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(MigrationScriptReaderImpl.getInputStream(resource), StandardCharsets.UTF_8))) { - return bufferedReader.lines() - .collect(Collectors.joining("\n")); - } catch (IOException e) { - throw new IllegalStateException("can't read spring-configuration-metadata.json from classpath: " + resource, e); - } - }).collect(Collectors.toList()); + final List springConfigMetadata; + try (ScanResult scanResult = new ClassGraph().acceptPathsNonRecursive("META-INF/").scan()) { + springConfigMetadata = scanResult.getResourcesWithLeafName("spring-configuration-metadata.json") + .stream() + .map(resource -> { + try { + return resource.getContentAsString(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + }) + .collect(Collectors.toList()); + } assertThat(springConfigMetadata) .anySatisfy(metadataContent -> assertThat(metadataContent).contains(ElasticsearchEvolutionConfig.class.getName())); diff --git a/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImplTest.java b/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImplTest.java index 210a60ae..02e5d842 100644 --- a/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImplTest.java +++ b/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImplTest.java @@ -50,8 +50,10 @@ void inJarFile() { List res = reader.read(); - assertThat(res).hasSize(1); - assertThat(res.get(0).getFileName()).isEqualTo("MANIFEST.MF"); + assertThat(res).isNotEmpty() + .allSatisfy(rawMigrationScript -> assertThat(rawMigrationScript.getFileName()) + .as("fileName") + .isEqualTo("MANIFEST.MF")); } @Test @@ -248,11 +250,33 @@ void validPathButNoFiles() throws URISyntaxException { } private URL resolveURL(String path) { - ClassLoader classLoader = MigrationScriptReaderImpl.getDefaultClassLoader(); + ClassLoader classLoader = getDefaultClassLoader(); if (classLoader != null) { return classLoader.getResource(path); } else { return ClassLoader.getSystemResource(path); } } + + static ClassLoader getDefaultClassLoader() { + ClassLoader cl = null; + try { + cl = Thread.currentThread().getContextClassLoader(); + } catch (Throwable ex) { + // Cannot access thread context ClassLoader - falling back... + } + if (cl == null) { + // No thread context class loader -> use class loader of this class. + cl = MigrationScriptReaderImpl.class.getClassLoader(); + if (cl == null) { + // getClassLoader() returning null indicates the bootstrap ClassLoader + try { + cl = ClassLoader.getSystemClassLoader(); + } catch (Throwable ex) { + // Cannot access system ClassLoader - oh well, maybe the caller can live with null... + } + } + } + return cl; + } } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 14b6ab33..09e78b3a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.4.4-SNAPSHOT + 0.5.0-SNAPSHOT pom org.springframework.boot @@ -102,7 +102,7 @@ 2.15.0 7.5.2 - 0.10.2 + 4.8.164 1.19.2 1.18.30 @@ -112,9 +112,9 @@ - org.reflections - reflections - ${reflections.version} + io.github.classgraph + classgraph + ${classgraph.version} diff --git a/spring-boot-starter-elasticsearch-evolution/pom.xml b/spring-boot-starter-elasticsearch-evolution/pom.xml index 2c67c00e..d4a339c9 100644 --- a/spring-boot-starter-elasticsearch-evolution/pom.xml +++ b/spring-boot-starter-elasticsearch-evolution/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.4.4-SNAPSHOT + 0.5.0-SNAPSHOT ../ spring-boot-starter-elasticsearch-evolution diff --git a/tests/migration-scripts/pom.xml b/tests/migration-scripts/pom.xml index e84b6b96..1a13c814 100644 --- a/tests/migration-scripts/pom.xml +++ b/tests/migration-scripts/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.senacor.elasticsearch.evolution migration-scripts - 0.4.4-SNAPSHOT + 0.5.0-SNAPSHOT jar containing migration files jar diff --git a/tests/pom.xml b/tests/pom.xml index 87fda920..827437a3 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.4.4-SNAPSHOT + 0.5.0-SNAPSHOT ../ tests diff --git a/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml b/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml index 4130d4a7..0010b6a9 100644 --- a/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.1-scriptsInJarFile - 0.4.4-SNAPSHOT + 0.5.0-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.2/pom.xml b/tests/test-spring-boot-2.2/pom.xml index 3e4ae5c0..7ef64b9d 100644 --- a/tests/test-spring-boot-2.2/pom.xml +++ b/tests/test-spring-boot-2.2/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.2 - 0.4.4-SNAPSHOT + 0.5.0-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.3/pom.xml b/tests/test-spring-boot-2.3/pom.xml index e3a8d1cd..f95c7e0f 100644 --- a/tests/test-spring-boot-2.3/pom.xml +++ b/tests/test-spring-boot-2.3/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.3 - 0.4.4-SNAPSHOT + 0.5.0-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.4/pom.xml b/tests/test-spring-boot-2.4/pom.xml index cf569a05..a22a9f00 100644 --- a/tests/test-spring-boot-2.4/pom.xml +++ b/tests/test-spring-boot-2.4/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.4 - 0.4.4-SNAPSHOT + 0.5.0-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml b/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml index 3879cc28..344b2689 100644 --- a/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.5-scriptsInJarFile - 0.4.4-SNAPSHOT + 0.5.0-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.6/pom.xml b/tests/test-spring-boot-2.6/pom.xml index 50ebd4a1..a1cbbf19 100644 --- a/tests/test-spring-boot-2.6/pom.xml +++ b/tests/test-spring-boot-2.6/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.6 - 0.4.4-SNAPSHOT + 0.5.0-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.7/pom.xml b/tests/test-spring-boot-2.7/pom.xml index 06b3bf5b..7328636a 100644 --- a/tests/test-spring-boot-2.7/pom.xml +++ b/tests/test-spring-boot-2.7/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.7 - 0.4.4-SNAPSHOT + 0.5.0-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml index c0532b0f..0a1b5690 100644 --- a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-3.0-scriptsInJarFile - 0.4.4-SNAPSHOT + 0.5.0-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-3.1/pom.xml b/tests/test-spring-boot-3.1/pom.xml index c021faef..7237e3d7 100644 --- a/tests/test-spring-boot-3.1/pom.xml +++ b/tests/test-spring-boot-3.1/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-3.1 - 0.4.4-SNAPSHOT + 0.5.0-SNAPSHOT Demo project for Spring Boot From ec554bd5ad1bae6bba7e790062a3f108d65fcc4c Mon Sep 17 00:00:00 2001 From: Andreas Keefer Date: Thu, 16 Nov 2023 20:34:24 +0100 Subject: [PATCH 5/5] prepare 0.5.0 release --- README.md | 2 +- elasticsearch-evolution-core/pom.xml | 2 +- pom.xml | 2 +- spring-boot-starter-elasticsearch-evolution/pom.xml | 2 +- tests/migration-scripts/pom.xml | 2 +- tests/pom.xml | 2 +- tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml | 2 +- tests/test-spring-boot-2.2/pom.xml | 2 +- tests/test-spring-boot-2.3/pom.xml | 2 +- tests/test-spring-boot-2.4/pom.xml | 2 +- tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml | 2 +- tests/test-spring-boot-2.6/pom.xml | 2 +- tests/test-spring-boot-2.7/pom.xml | 2 +- tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml | 2 +- tests/test-spring-boot-3.1/pom.xml | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 1c3053e6..da035bbb 100644 --- a/README.md +++ b/README.md @@ -291,7 +291,7 @@ ElasticsearchEvolution.configure() ## 6 changelog -### v0.5.0-SNAPSHOT +### v0.5.0 - added spring boot configuration metadata [#240](https://github.com/senacor/elasticsearch-evolution/pull/240) - replaces unmaintained [org.reflections](https://github.com/ronmamo/reflections) library with [classgraph](https://github.com/classgraph/classgraph) to scan the classpath for migration files. Fixes [#239](https://github.com/senacor/elasticsearch-evolution/issues/239) diff --git a/elasticsearch-evolution-core/pom.xml b/elasticsearch-evolution-core/pom.xml index d993ff2a..87eec8c9 100644 --- a/elasticsearch-evolution-core/pom.xml +++ b/elasticsearch-evolution-core/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.5.0-SNAPSHOT + 0.5.0 ../ elasticsearch-evolution-core diff --git a/pom.xml b/pom.xml index 09e78b3a..2bb3f0af 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.5.0-SNAPSHOT + 0.5.0 pom org.springframework.boot diff --git a/spring-boot-starter-elasticsearch-evolution/pom.xml b/spring-boot-starter-elasticsearch-evolution/pom.xml index d4a339c9..36757190 100644 --- a/spring-boot-starter-elasticsearch-evolution/pom.xml +++ b/spring-boot-starter-elasticsearch-evolution/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.5.0-SNAPSHOT + 0.5.0 ../ spring-boot-starter-elasticsearch-evolution diff --git a/tests/migration-scripts/pom.xml b/tests/migration-scripts/pom.xml index 1a13c814..9ffe4976 100644 --- a/tests/migration-scripts/pom.xml +++ b/tests/migration-scripts/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.senacor.elasticsearch.evolution migration-scripts - 0.5.0-SNAPSHOT + 0.5.0 jar containing migration files jar diff --git a/tests/pom.xml b/tests/pom.xml index 827437a3..e8068468 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.5.0-SNAPSHOT + 0.5.0 ../ tests diff --git a/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml b/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml index 0010b6a9..309c8f6f 100644 --- a/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.1-scriptsInJarFile - 0.5.0-SNAPSHOT + 0.5.0 Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.2/pom.xml b/tests/test-spring-boot-2.2/pom.xml index 7ef64b9d..c5979bfd 100644 --- a/tests/test-spring-boot-2.2/pom.xml +++ b/tests/test-spring-boot-2.2/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.2 - 0.5.0-SNAPSHOT + 0.5.0 Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.3/pom.xml b/tests/test-spring-boot-2.3/pom.xml index f95c7e0f..17359092 100644 --- a/tests/test-spring-boot-2.3/pom.xml +++ b/tests/test-spring-boot-2.3/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.3 - 0.5.0-SNAPSHOT + 0.5.0 Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.4/pom.xml b/tests/test-spring-boot-2.4/pom.xml index a22a9f00..0ba7e8a3 100644 --- a/tests/test-spring-boot-2.4/pom.xml +++ b/tests/test-spring-boot-2.4/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.4 - 0.5.0-SNAPSHOT + 0.5.0 Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml b/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml index 344b2689..8fe784e4 100644 --- a/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.5-scriptsInJarFile - 0.5.0-SNAPSHOT + 0.5.0 Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.6/pom.xml b/tests/test-spring-boot-2.6/pom.xml index a1cbbf19..429cd3c4 100644 --- a/tests/test-spring-boot-2.6/pom.xml +++ b/tests/test-spring-boot-2.6/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.6 - 0.5.0-SNAPSHOT + 0.5.0 Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.7/pom.xml b/tests/test-spring-boot-2.7/pom.xml index 7328636a..70f2f4a0 100644 --- a/tests/test-spring-boot-2.7/pom.xml +++ b/tests/test-spring-boot-2.7/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.7 - 0.5.0-SNAPSHOT + 0.5.0 Demo project for Spring Boot diff --git a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml index 0a1b5690..100c9113 100644 --- a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-3.0-scriptsInJarFile - 0.5.0-SNAPSHOT + 0.5.0 Demo project for Spring Boot diff --git a/tests/test-spring-boot-3.1/pom.xml b/tests/test-spring-boot-3.1/pom.xml index 7237e3d7..630502ed 100644 --- a/tests/test-spring-boot-3.1/pom.xml +++ b/tests/test-spring-boot-3.1/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-3.1 - 0.5.0-SNAPSHOT + 0.5.0 Demo project for Spring Boot