8000 [DROOLS-7608] EAP 7.4.15 VFS changes make drools PMML tests fail by tkobayas · Pull Request #25 · kiegroup/drools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[DROOLS-7608] EAP 7.4.15 VFS changes make drools PMML tests fail #25

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

Closed
wants to merge 1 commit into from
Closed
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 @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -464,14 +470,18 @@ 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();
}

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);
Comment on lines +481 to +484
Copy link
Author

Choose a reason for hiding this comment

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

You can confirm that VirtualFile.getPhysicalFile returns file path under deployment directory. (e.g. target/cargo/configurations/wildfly23x/tmp/vfs/deployment/deploymente0f78ed559baff33/kie-pmml-7.75.0-SNAPSHOT.jar-9458e4090f0fae31/contents/META-INF/kmodule.xml)

Actually, the kmodule.xml is created on the file path as a cache file. But what we want here is the kie-pmml-7.75.0-SNAPSHOT.jar which is under temp directory.

path = f.getPath();
} catch (Exception e) {
log.error( "Error when reading virtual file from " + url.toString(), e );
Expand All @@ -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);
Expand All @@ -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);
}
}
Comment on lines +515 to +535
Copy link
Author

Choose a reason for hiding this comment

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

This is the main part of the (temporary) fix. I was not able to find public methods to get the physical file (e.g. kie-server-integ-tests-drools/target/cargo/configurations/wildfly23x/tmp/vfs/temp/tempc483d0975993750a/content-c8ee66a0826ffc48/WEB-INF/lib/kie-pmml-7.75.0-SNAPSHOT.jar). So used setAccessible(true) for package-private methods.


log.info( "Virtual file physical path = " + path );
return path;
} catch (Exception e) {
Expand Down
0