diff --git a/config-test/pom.xml b/config-test/pom.xml index 9da9ec2db8f..41747d48493 100644 --- a/config-test/pom.xml +++ b/config-test/pom.xml @@ -59,10 +59,6 @@ - - org.reflections - reflections - junit junit diff --git a/config-test/src/main/java/com/powsybl/config/test/TestPlatformConfigProvider.java b/config-test/src/main/java/com/powsybl/config/test/TestPlatformConfigProvider.java index b125dc1e4b4..ada10671915 100644 --- a/config-test/src/main/java/com/powsybl/config/test/TestPlatformConfigProvider.java +++ b/config-test/src/main/java/com/powsybl/config/test/TestPlatformConfigProvider.java @@ -9,23 +9,23 @@ import com.google.auto.service.AutoService; import com.google.common.jimfs.Configuration; import com.google.common.jimfs.Jimfs; - import com.powsybl.commons.config.ModuleConfigRepository; import com.powsybl.commons.config.PlatformConfig; import com.powsybl.commons.config.PlatformConfigProvider; -import org.reflections.Reflections; -import org.reflections.util.ClasspathHelper; -import org.reflections.vfs.Vfs; +import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; +import java.io.InputStream; import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Set; +import java.util.Collections; +import java.util.List; /** * Provides a PlatformConfig reading config from the classpath only. @@ -42,6 +42,7 @@ public class TestPlatformConfigProvider implements PlatformConfigProvider { private static final String NAME = "test"; + private static final String FILELIST_PATH = "filelist.txt"; //Using a static for the FileSystem to show that it is a singleton //and won't be closed until the jvm is shut down. private static final FileSystem JIMFS = Jimfs.newFileSystem(Configuration.unix()); @@ -57,22 +58,26 @@ public String getName() { @Override public PlatformConfig getPlatformConfig() { - // ForManifest enriches the default static and context classloaders with - // additional jars from the Class-Path attribute. - // Needed for maven surefire in manifest-only jar mode (the default) but doesn't - // hurt for other cases. Not sure why it is not the default. - Reflections reflections = new Reflections(ClasspathHelper.forManifest(), new ResourcesScanner()); - String thisPackagePath = TestPlatformConfigProvider.class.getPackage().getName().replace('.', '/'); - Set resources = reflections.getResources(s -> s.startsWith(thisPackagePath)); + InputStream resourceList = TestPlatformConfigProvider.class.getResourceAsStream(FILELIST_PATH); + List resources; + if (resourceList != null) { + try { + resources = IOUtils.readLines(resourceList, StandardCharsets.UTF_8); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } else { + resources = Collections.emptyList(); + } + Path cfgDir; try { cfgDir = Files.createDirectories(JIMFS.getPath(CONFIG_DIR).toAbsolutePath()); - ClassLoader classLoader = TestPlatformConfigProvider.class.getClassLoader(); for (String resource : resources) { // The resources have relative paths (no leading slash) with full package path. - Path dest = cfgDir.resolve(resource.substring(resource.lastIndexOf('/') + 1)); + Path dest = cfgDir.resolve(resource); LOGGER.info("Copying classpath resource: {} -> {}", resource, dest); - Files.copy(classLoader.getResourceAsStream(resource), dest); + Files.copy(TestPlatformConfigProvider.class.getResourceAsStream(resource), dest); } } catch (IOException e) { throw new UncheckedIOException("Failed to initialize test config", e); @@ -81,23 +86,4 @@ public PlatformConfig getPlatformConfig() { return new PlatformConfig(repository, cfgDir); } - // This class must be named ResourceScanner because the getSimpleName is used by - // reflections.getResources - @SuppressWarnings("squid:S2176") - private static class ResourcesScanner extends org.reflections.scanners.ResourcesScanner { - - // To have the full path in the key to filter by directory. - @Override - public Object scan(Vfs.File file, Object classObject) { - getStore().put(file.getRelativePath(), file.getRelativePath()); - return classObject; - } - - // To fix https://github.com/ronmamo/reflections/issues/102 - @Override - public boolean acceptResult(final String fqn) { - return false; - } - } - } diff --git a/config-test/src/test/resources/com/powsybl/config/test/filelist.txt b/config-test/src/test/resources/com/powsybl/config/test/filelist.txt new file mode 100644 index 00000000000..ce6ba0ebbe4 --- /dev/null +++ b/config-test/src/test/resources/com/powsybl/config/test/filelist.txt @@ -0,0 +1,2 @@ +config.yml +other.txt diff --git a/pom.xml b/pom.xml index 4a3bf008bfb..65c2f675187 100644 --- a/pom.xml +++ b/pom.xml @@ -141,7 +141,6 @@ 3.0.0 1.0.1 1.1 - 0.9.11 0.9.0 2.9.7 4.12 @@ -583,11 +582,6 @@ jimfs ${jimfs.version} - - org.reflections - reflections - ${reflections.version} - com.google.protobuf protobuf-java