Skip to content

Commit

Permalink
[DROOLS-3181] fix VirtualFileSystem discovery after changes in eap 6.…
Browse files Browse the repository at this point in the history
…4.21 (apache#2118)
  • Loading branch information
mariofusco committed Oct 24, 2018
1 parent cc4e356 commit 2a36f67
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import org.appformer.maven.support.PomModel;
import org.drools.compiler.kie.builder.impl.event.KieModuleDiscovered;
import org.drools.compiler.kie.builder.impl.event.KieServicesEventListerner;
import org.drools.compiler.kproject.ReleaseIdImpl;
Expand All @@ -42,7 +45,6 @@
import org.kie.api.builder.KieRepository;
import org.kie.api.builder.ReleaseId;
import org.kie.api.builder.model.KieModuleModel;
import org.appformer.maven.support.PomModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -419,8 +421,7 @@ private static String getPathForVFS(URL url) {

String path = null;
try {
Object content = url.openConnection().getContent();
File f = (File)m.invoke(content);
File f = (File)m.invoke( findVirtualFile( url ) );
path = f.getPath();
} catch (Exception e) {
log.error( "Error when reading virtual file from " + url.toString(), e );
Expand Down Expand Up @@ -457,6 +458,20 @@ private static String getPathForVFS(URL url) {
return url.getPath();
}

private static Object findVirtualFile( URL url ) throws IOException {
URLConnection urlConnection = url.openConnection();
try {
if ( urlConnection.getClass().getName().equals( "org.jboss.vfs.protocol.VirtualFileURLConnection" ) ) {
Field f = urlConnection.getClass().getDeclaredField( "file" );
f.setAccessible( true );
return f.get( urlConnection );
}
} catch (NoSuchFieldException | IllegalAccessException e) {
// ignored
}
return urlConnection.getContent();
}

public InternalKieModule getKieModuleForKBase(String kBaseName) {
return this.kJarFromKBaseName.get( kBaseName );
}
Expand Down

0 comments on commit 2a36f67

Please sign in to comment.