tkobayas commented on code in PR #6587:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6587#discussion_r3232479281


##########
kie-memory-compiler/src/main/java/org/kie/memorycompiler/jdknative/NativeJavaCompiler.java:
##########
@@ -51,6 +52,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.jar.JarEntry;
+import java.util.jar.JarFile;

Review Comment:
   done



##########
kie-memory-compiler/src/test/java/org/kie/memorycompiler/jdknative/NativeJavaCompilerTest.java:
##########
@@ -40,15 +48,64 @@ public void simulateJreWithException() {
 
                
assertThatExceptionOfType(KieMemoryCompilerException.class).isThrownBy(() -> 
compiler.compile(null, null, null, null, null));
        }
-       
+
+       @Test
+       public void emptySourcesShouldSucceed() {
+               NativeJavaCompiler compiler = new NativeJavaCompiler();
+               CompilationResult result = compiler.compile(new String[0], 
null, null, null, compiler.createDefaultSettings());
+               assertThat(result.getErrors()).isEmpty();
+       }
+
+       /**
+        * Tests that NativeJavaCompiler can resolve classes from 
directory-based
+        * classpath entries (not JARs). This exercises the processDirectory() 
method
+        * which was added to fix kjar builds where kie-maven-plugin compiles 
DRL
+        * referencing Java classes from target/classes.
+        *
+        * The test compiles source that references CompilationResult (a class 
from
+        * this module's target/classes directory) using a URLClassLoader that 
includes
+        * target/classes as a directory URL — without setting any classpath on
+        * JavaCompilerSettings (simulating the classic DRL compilation path).
+        */
+       @Test
+       public void compileWithDirectoryClasspath() throws Exception {
+               // target/classes contains compiled classes from this module as 
a directory (not a JAR)
+               File targetClasses = new File("target/classes");
+               assertThat(targetClasses).isDirectory();
+
+               // Create a classloader with target/classes as a directory URL
+               URLClassLoader classLoader = new URLClassLoader(
+                               new URL[]{targetClasses.toURI().toURL()},
+                               ClassLoader.getPlatformClassLoader()
+               );
+
+               // Source that references CompilationResult from the 
directory-based classpath
+               String source =
+                               "package org.kie.memorycompiler.test;\n" +
+                               "import 
org.kie.memorycompiler.CompilationResult;\n" +
+                               "public class DirectoryClasspathTest {\n" +
+                               "    public boolean hasErrors(CompilationResult 
result) {\n" +
+                               "        return result.getErrors().length > 
0;\n" +
+                               "    }\n" +
+                               "}";
+
+               Map<String, byte[]> compiled = KieMemoryCompiler.compileNoLoad(
+                               
Map.of("org.kie.memorycompiler.test.DirectoryClasspathTest", source),
+                               classLoader
+               );
+
+               
assertThat(compiled).containsKey("org.kie.memorycompiler.test.DirectoryClasspathTest");
+               
assertThat(compiled.get("org.kie.memorycompiler.test.DirectoryClasspathTest")).isNotEmpty();

Review Comment:
   done



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