Copilot commented on code in PR #6310:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6310#discussion_r2084535997


##########
drools-util/src/main/java/org/drools/util/FileUtils.java:
##########
@@ -59,6 +62,38 @@ public static File getFile(String fileName) {
         return toReturn;
     }
 
+    /**
+     * Retrieve the <code>File</code> from jars
+     *
+     * @param fileName
+     * @return
+     */
+    public static File getFileFromDependency(String fileName) throws 
IOException {
+        URL jarUrl =
+                
Collections.list(Thread.currentThread().getContextClassLoader().getResources(fileName))
+                        .stream()
+                        .filter(url -> url.getProtocol().equals("jar"))
+                        .findFirst()
+                        .orElseThrow(() -> new RuntimeException("Failed to 
retrieve jar containing " + fileName));
+        String jarFileName = jarUrl.getFile();
+        String jarPath = jarFileName.substring(jarFileName.lastIndexOf(":") + 
1,
+                                               jarFileName.lastIndexOf("!"));
+        System.out.println(jarPath);
+        final JarFile jarFile = new JarFile(new File(jarPath));
+        System.out.println(jarFile);
+        String foundFile = Collections.list(jarFile.entries())
+                .stream()
+                .filter(entry -> entry.getName().equals(fileName) && 
!entry.isDirectory())
+                .map(ZipEntry::getName)
+                .findFirst()
+                .orElseThrow(() -> new RuntimeException("Failed to find file " 
+ fileName));
+        System.out.println(foundFile);
+        URL r = 
Thread.currentThread().getContextClassLoader().getResource(foundFile);
+        System.out.println(r);

Review Comment:
   Consider replacing System.out.println with a proper logging framework (e.g., 
using Logger) for consistency and better log management.
   ```suggestion
           logger.info("Jar path: " + jarPath);
           final JarFile jarFile = new JarFile(new File(jarPath));
           logger.info("Jar file: " + jarFile);
           String foundFile = Collections.list(jarFile.entries())
                   .stream()
                   .filter(entry -> entry.getName().equals(fileName) && 
!entry.isDirectory())
                   .map(ZipEntry::getName)
                   .findFirst()
                   .orElseThrow(() -> new RuntimeException("Failed to find file 
" + fileName));
           logger.info("Found file: " + foundFile);
           URL r = 
Thread.currentThread().getContextClassLoader().getResource(foundFile);
           logger.info("Resource URL: " + r);
   ```



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to