Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[incubator-kie-drools-5745] Compatibility issue with Spring-boot 3.2 #6064

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.drools.compiler.kie.builder.impl.event.KieServicesEventListerner;
import org.drools.compiler.kproject.models.KieModuleModelImpl;
import org.drools.util.IoUtils;
import org.drools.util.JarUtils;
import org.drools.util.PortablePath;
import org.drools.util.StringUtils;
import org.kie.api.KieServices;
Expand Down Expand Up @@ -410,6 +411,9 @@ public static String fixURLFromKProjectPath(URL url) {
urlPath = urlPath.substring( 0, urlPath.length() - 1 );
}

// Replace "/!BOOT-INF/" with "!/BOOT-INF/" to make it consistent with the actual path in the jar file
urlPath = JarUtils.replaceNestedPathForSpringBoot32(urlPath);

// remove any remaining protocols, normally only if it was a jar
int firstSlash = urlPath.indexOf( '/' );
colonIndex = firstSlash > 0 ? urlPath.lastIndexOf( ":", firstSlash ) : urlPath.lastIndexOf( ":" );
Expand Down
16 changes: 16 additions & 0 deletions drools-util/src/main/java/org/drools/util/JarUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class JarUtils {
private static final String SPRING_BOOT_PREFIX = "BOOT-INF/classes/"; // Actual path prefix in Spring Boot JAR
private static final String SPRING_BOOT_URL_PREFIX = "BOOT-INF/classes!/"; // Spring Boot adds "!" to resource url as a "nest" separator

private static final String SPRING_BOOT_NESTED_PREFIX_BEFORE_3_2 = "!/BOOT-INF/"; // Before Spring Boot 3.2
private static final String SPRING_BOOT_NESTED_PREFIX_AFTER_3_2 = "/!BOOT-INF/"; // Since Spring Boot 3.2

private JarUtils() {
// Avoid instantiating class
}
Expand All @@ -45,4 +48,17 @@ public static String normalizeSpringBootResourceUrlPath(String resourceUrlPath)
return resourceUrlPath;
}
}

/**
* Replace the new spring-boot nested path representation "/!BOOT-INF/" (introduced since 3.2) with the old "!/BOOT-INF/".
* Because the new path representation doesn't meet the path manipulation in the drools codebase.
* See https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2-Release-Notes#nested-jar-support
*/
public static String replaceNestedPathForSpringBoot32(String urlPath) {
if (urlPath.contains(SPRING_BOOT_NESTED_PREFIX_AFTER_3_2)) {
return urlPath.replace(SPRING_BOOT_NESTED_PREFIX_AFTER_3_2, SPRING_BOOT_NESTED_PREFIX_BEFORE_3_2);
} else {
return urlPath;
}
}
}
12 changes: 12 additions & 0 deletions drools-util/src/test/java/org/drools/util/JarUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,16 @@ public void normalizeSpringBootResourceUrlPath() {
String normalized = JarUtils.normalizeSpringBootResourceUrlPath("BOOT-INF/classes!/org/example/MyClass.class");
assertThat(normalized).isEqualTo("BOOT-INF/classes/org/example/MyClass.class");
}

@Test
public void replaceNestedPathForSpringBoot32_shouldNotAffectOldPath() {
String result = JarUtils.replaceNestedPathForSpringBoot32("/dir/myapp.jar!/BOOT-INF/lib/mykjar.jar");
assertThat(result).isEqualTo("/dir/myapp.jar!/BOOT-INF/lib/mykjar.jar");
}

@Test
public void replaceNestedPathForSpringBoot32_shouldReplaceNewPath() {
String result = JarUtils.replaceNestedPathForSpringBoot32("/dir/myapp.jar/!BOOT-INF/lib/mykjar.jar");
assertThat(result).isEqualTo("/dir/myapp.jar!/BOOT-INF/lib/mykjar.jar");
}
Comment on lines +33 to +43
Copy link
Contributor Author

@tkobayas tkobayas Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added simple unit tests only.

I have manually tested with spring boot 3.2.6 uber jar. https://github.com/tkobayas/kiegroup-examples/tree/master/Ex-spring-boot-3.2-demo-main . and confirmed that the issue is solved.

Adding such integration tests (actually build a uber jar and run it with ProcessBuilder) might be worth discussing.

}
Loading