sashapolo commented on code in PR #1794:
URL: https://github.com/apache/ignite-3/pull/1794#discussion_r1137044484


##########
modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/IgniteTestUtils.java:
##########
@@ -826,4 +830,41 @@ public static void runRace(long timeoutMillis, 
RunnableX... actions) {
             throw assertionError;
         }
     }
+
+    /**
+     * Returns a file system path for a resource name.
+     *
+     * @param cls A class.
+     * @param resourceName A resource name.
+     * @return A file system path matching the path component of the resource 
URL.
+     */
+    public static <T> String getResourcePath(Class<T> cls, String 
resourceName) {
+        return getResourcePath(cls.getClassLoader().getResource(resourceName));
+    }
+
+    /**
+     * Converts an URL gotten from classloader to proper file system path.

Review Comment:
   ```suggestion
        * Converts a URL to a file system path.
   ```



##########
modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/IgniteTestUtils.java:
##########
@@ -826,4 +830,41 @@ public static void runRace(long timeoutMillis, 
RunnableX... actions) {
             throw assertionError;
         }
     }
+
+    /**
+     * Returns a file system path for a resource name.
+     *
+     * @param cls A class.
+     * @param resourceName A resource name.
+     * @return A file system path matching the path component of the resource 
URL.
+     */
+    public static <T> String getResourcePath(Class<T> cls, String 
resourceName) {
+        return getResourcePath(cls.getClassLoader().getResource(resourceName));
+    }
+
+    /**
+     * Converts an URL gotten from classloader to proper file system path.
+     *
+     * @param url A resource URL.
+     * @return A file system path matching the path component of the resource 
URL.
+     */
+    public static String getResourcePath(URL url) {
+        try {
+            Objects.requireNonNull(url);

Review Comment:
   I think this check is redundant



##########
modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/IgniteTestUtils.java:
##########
@@ -826,4 +830,41 @@ public static void runRace(long timeoutMillis, 
RunnableX... actions) {
             throw assertionError;
         }
     }
+
+    /**
+     * Returns a file system path for a resource name.
+     *
+     * @param cls A class.
+     * @param resourceName A resource name.
+     * @return A file system path matching the path component of the resource 
URL.
+     */
+    public static <T> String getResourcePath(Class<T> cls, String 
resourceName) {

Review Comment:
   ```suggestion
       public static String getResourcePath(Class<?> cls, String resourceName) {
   ```



##########
modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/IgniteTestUtils.java:
##########
@@ -826,4 +830,41 @@ public static void runRace(long timeoutMillis, 
RunnableX... actions) {
             throw assertionError;
         }
     }
+
+    /**
+     * Returns a file system path for a resource name.
+     *
+     * @param cls A class.
+     * @param resourceName A resource name.
+     * @return A file system path matching the path component of the resource 
URL.
+     */
+    public static <T> String getResourcePath(Class<T> cls, String 
resourceName) {
+        return getResourcePath(cls.getClassLoader().getResource(resourceName));
+    }
+
+    /**
+     * Converts an URL gotten from classloader to proper file system path.
+     *
+     * @param url A resource URL.
+     * @return A file system path matching the path component of the resource 
URL.
+     */
+    public static String getResourcePath(URL url) {
+        try {
+            Objects.requireNonNull(url);
+            // Properly extract file system path from the "file:" URL
+            return Path.of(url.toURI()).toString();
+        } catch (URISyntaxException e) {
+            throw new RuntimeException(e); // Shouldn't happen since URL is 
obtained from the class loader
+        }
+    }
+
+    /**
+     * Adds escape characters before backslashes in a path (on Windows), e.g. 
for the HOCON config parser.

Review Comment:
   Can you please provide an example, how this method will transform a given 
string?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to