IGNITE-17512 Fix File -> URI.
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java b/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java
index b1c9869..6297be2 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java
@@ -18,7 +18,6 @@
package org.apache.ignite.testframework.config;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
@@ -106,12 +105,11 @@
initTestProjectHome();
// Load default properties.
- File cfgFile = getTestConfigurationFile(null, TESTS_PROP_FILE);
+ URI cfgFile = getTestConfigurationFile(null, TESTS_PROP_FILE);
- assert cfgFile != null && cfgFile.exists();
- assert !cfgFile.isDirectory();
+ assert cfgFile != null;
- dfltProps = Collections.unmodifiableMap(loadFromFile(new HashMap<String, String>(), cfgFile));
+ dfltProps = Collections.unmodifiableMap(loadFromResource(new HashMap<>(), cfgFile));
if ("false".equals(System.getProperty("IGNITE_TEST_PROP_DISABLE_LOG4J", "false"))) {
String user = System.getProperty("user.name");
@@ -139,12 +137,12 @@
if (cfgFile == null)
cfgFile = DEFAULT_LOG4J_FILE;
- File log4jFile = getTestConfigurationFile(user, cfgFile);
+ URI log4jFile = getTestConfigurationFile(user, cfgFile);
if (log4jFile == null)
log4jFile = getTestConfigurationFile(null, cfgFile);
- Configurator.initialize(LoggerConfig.ROOT, log4jFile.getAbsolutePath());
+ Configurator.initialize(LoggerConfig.ROOT, GridTestProperties.class.getClassLoader(), log4jFile);
System.out.println("Configured log4j2 from: " + log4jFile);
}
@@ -155,13 +153,13 @@
}
/** */
- public static File findTestResource(String res) {
+ public static URI findTestResource(String res) {
URL resUrl = GridTestProperties.class.getResource(TEST_CONFIG_DIR + res);
if (resUrl == null)
return null;
- return new File(URI.create(resUrl.toExternalForm()));
+ return URI.create(resUrl.toExternalForm());
}
/**
@@ -284,10 +282,10 @@
* @return Loaded properties.
*/
private static Map<String, String> loadProperties(Map<String, String> props, String dir) {
- File cfg = getTestConfigurationFile(dir, TESTS_PROP_FILE);
+ URI cfg = getTestConfigurationFile(dir, TESTS_PROP_FILE);
if (cfg != null)
- loadFromFile(props, cfg);
+ loadFromResource(props, cfg);
return props;
}
@@ -297,7 +295,7 @@
* @param fileName File name.
* @return Configuration file for given user.
*/
- @Nullable private static File getTestConfigurationFile(@Nullable String user, String fileName) {
+ @Nullable private static URI getTestConfigurationFile(@Nullable String user, String fileName) {
String path = TESTS_CFG_PATH;
if (user != null)
@@ -310,7 +308,7 @@
if (file != null && file.exists()) {
assert !file.isDirectory();
- return file;
+ return file.toURI();
}
return user == null ? findTestResource(fileName) : null;
@@ -318,28 +316,25 @@
/**
* @param props Initial properties.
- * @param file Property file.
+ * @param resource File resource location.
* @return Loaded properties.
*/
- private static Map<String, String> loadFromFile(Map<String, String> props, File file) {
- try {
+ private static Map<String, String> loadFromResource(Map<String, String> props, URI resource) {
+ try (InputStream in = resource.toURL().openStream()) {
+ Properties fileProps = new Properties();
- try (InputStream in = new FileInputStream(file)) {
- Properties fileProps = new Properties();
+ fileProps.load(in);
- fileProps.load(in);
+ for (Entry<Object, Object> prop : fileProps.entrySet())
+ props.put((String)prop.getKey(), (String)prop.getValue());
- for (Entry<Object, Object> prop : fileProps.entrySet())
- props.put((String)prop.getKey(), (String)prop.getValue());
-
- for (Entry<String, String> prop : props.entrySet())
- prop.setValue(substituteProperties(prop.getValue()));
- }
+ for (Entry<String, String> prop : props.entrySet())
+ prop.setValue(substituteProperties(prop.getValue()));
}
catch (IOException e) {
e.printStackTrace();
- assert false : "Failed to load test configuration properties: " + file;
+ assert false : "Failed to load test configuration properties: " + resource;
}
return props;