From 135f311d81dcd016c50a9951858a5f202c2b8a00 Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Thu, 15 Feb 2024 18:54:49 +0900 Subject: [PATCH] [DROOLS-7608] EAP 7.4.15 VFS changes make drools PMML tests fail - WIP : ugly reflection --- .../kie/builder/impl/ClasspathKieProject.java | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/ClasspathKieProject.java b/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/ClasspathKieProject.java index b8ccd5a3dcb..ccdd5262557 100644 --- a/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/ClasspathKieProject.java +++ b/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/ClasspathKieProject.java @@ -25,8 +25,11 @@ import java.lang.ref.WeakReference; import java.lang.reflect.Method; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLDecoder; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; @@ -194,6 +197,7 @@ private static void fetchKModuleFromSpring(URL kModuleUrl) { } private static InternalKieModule fetchKModule(URL url, String fixedURL) { + log.info( "fetchKModule url=" + url + " fixedURL=" + fixedURL); if ( url.getPath().endsWith("-spring.xml")) { // the entire kmodule creation is happening in the kie-spring module, // hence we force a null return @@ -274,6 +278,7 @@ private static boolean isJarFile(String urlPathToAdd, String rootPath) { } private static String getPomPropertiesFromZipFile(String rootPath) { + log.info("getPomPropertiesFromZipFile : rootPath = " + rootPath); File actualZipFile = new File( rootPath ); if ( !actualZipFile.exists() ) { if (rootPath.indexOf(".jar!") > 0) { @@ -303,7 +308,7 @@ private static String getPomPropertiesFromZipFile(String rootPath) { } private static String getPomPropertiesFromZipStream(String rootPath) { - + log.info("getPomPropertiesFromZipStream : rootPath = " + rootPath); rootPath = rootPath.substring( rootPath.lastIndexOf( '!' ) + 1 ); // read jar file from uber-jar InputStream in = ClasspathKieProject.class.getResourceAsStream(rootPath); @@ -395,9 +400,10 @@ public static String fixURLFromKProjectPath(URL url) { urlType = urlPath.substring( 0, colonIndex ); } - urlPath = url.getPath(); + log.info("fixURLFromKProjectPath: url=" + urlPath); + if ( "jar".equals( urlType ) ) { // switch to using getPath() instead of toExternalForm() if ( urlPath.indexOf( '!' ) > 0 ) { @@ -464,6 +470,7 @@ private static String getPathForVFS(URL url) { log.warn( "Found virtual file " + url + " but org.jboss.vfs.VFS is not available on the classpath" ); } } + log.info("getPathForVFS: m=" + m + " m2=" + m2); if (m == null || m2 == null) { return url.getPath(); @@ -471,7 +478,10 @@ private static String getPathForVFS(URL url) { String path = null; try { + Object virtualFile = m2.invoke(null, url.toURI()); + log.info("virtualFile=" + virtualFile); File f = (File)m.invoke( m2.invoke(null, url.toURI()) ); + log.info("f=" + f); path = f.getPath(); } catch (Exception e) { log.error( "Error when reading virtual file from " + url.toString(), e ); @@ -489,6 +499,8 @@ private static String getPathForVFS(URL url) { int kModulePos = urlString.length() - ("/" + KieModuleModelImpl.KMODULE_JAR_PATH).length(); boolean isInJar = urlString.substring(kModulePos - 4, kModulePos).equals(".jar"); + log.info(" isInJar=" + isInJar + " kModulePos=" + kModulePos + " urlString=" + urlString + " path=" + path); + try { if (isInJar && path.contains("contents" + File.separator)) { String jarName = urlString.substring(0, kModulePos); @@ -500,6 +512,28 @@ private static String getPathForVFS(URL url) { path = path.substring( 0, path.length() - ("/" + KieModuleModelImpl.KMODULE_JAR_PATH).length() ); } + if (!Files.exists(Paths.get(path))) { + log.info("path : " + path + " --- does not exist"); + log.info("fallback for EAP 7.14.5"); + try { + Method m3 = Class.forName("org.jboss.vfs.VFS").getDeclaredMethod("getMount", Class.forName("org.jboss.vfs.VirtualFile")); + m3.setAccessible(true); + Method m4 = Class.forName("org.jboss.vfs.VFS$Mount").getDeclaredMethod("getFileSystem"); + m4.setAccessible(true); + Method m5 = Class.forName("org.jboss.vfs.spi.FileSystem").getMethod("getMountSource"); + + Object virtualFile = m2.invoke(null, url.toURI()); + Object mount = m3.invoke(null, virtualFile); + Object fileSystem = m4.invoke(mount); + log.info("fileSystem : " + fileSystem); + File mountSource = (File) m5.invoke(fileSystem); + log.info("mountSource : " + mountSource); + path = mountSource.getPath(); + } catch (Exception e) { + e.printStackTrace(System.out); + } + } + log.info( "Virtual file physical path = " + path ); return path; } catch (Exception e) {