JBPAPP-7491 , JBPAPP-7488 , HHH-6806 Add support for vfsfile and vfszip in JarVisitor

The method getVisitor(URL jarUrl, Filter[] filters, String entry) does not have conditionals for protocols vfs based,
like vfszip or vfsfile. It returns an InputStreamZippedJarVisitor implementation for both protocols. If it is a vfszip,
it will work, but will not not for vfsfile. The fix includes vfszip and vfsfile to JarVisitorFactory, so it can return
FileZippedJarVisitor (more efficient than InputStreamZippedJarVisitor) for vfszip and ExplodedJarVisitor for vfsfile
This commit is contained in:
Alessandro Lazarotti 2011-11-22 15:39:42 -02:00 committed by Emmanuel Bernard
parent 6c7379c38f
commit 3c11500618
2 changed files with 48 additions and 12 deletions

View File

@ -162,7 +162,7 @@ public class JarVisitorFactory {
if ( "jar".equals( protocol ) ) {
return new JarProtocolVisitor( jarUrl, filters, entry );
}
else if ( StringHelper.isEmpty( protocol ) || "file".equals( protocol ) ) {
else if ( StringHelper.isEmpty( protocol ) || "file".equals( protocol ) || "vfszip".equals( protocol ) || "vfsfile".equals( protocol ) ) {
File file;
try {
final String filePart = jarUrl.getFile();

View File

@ -23,15 +23,23 @@
*/
package org.hibernate.ejb.test.packaging;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.MappedSuperclass;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.net.URLStreamHandlerFactory;
import java.util.Set;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.MappedSuperclass;
import org.hibernate.ejb.packaging.ClassFilter;
import org.hibernate.ejb.packaging.Entry;
import org.hibernate.ejb.packaging.ExplodedJarVisitor;
@ -45,15 +53,8 @@ import org.hibernate.ejb.packaging.JarVisitorFactory;
import org.hibernate.ejb.packaging.PackageFilter;
import org.hibernate.ejb.test.pack.defaultpar.ApplicationServer;
import org.hibernate.ejb.test.pack.explodedpar.Carpet;
import org.junit.Test;
import org.hibernate.testing.TestForIssue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* @author Emmanuel Bernard
@ -221,6 +222,41 @@ public class JarVisitorTest extends PackagingTestCase {
}
}
@Test
@TestForIssue(jiraKey = "HHH-6806")
public void testJarVisitorFactory() throws Exception{
//setting URL to accept vfs based protocol
URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {
public URLStreamHandler createURLStreamHandler(String protocol) {
if("vfszip".equals(protocol) || "vfsfile".equals(protocol) )
return new URLStreamHandler() {
protected URLConnection openConnection(URL u)
throws IOException {
return null;
}
};
return null;
}
});
URL jarUrl = new URL ("file:./target/packages/defaultpar.par");
JarVisitor jarVisitor = JarVisitorFactory.getVisitor(jarUrl, getFilters(), null);
assertEquals(FileZippedJarVisitor.class.getName(), jarVisitor.getClass().getName());
jarUrl = new URL ("file:./target/packages/explodedpar");
jarVisitor = JarVisitorFactory.getVisitor(jarUrl, getFilters(), null);
assertEquals(ExplodedJarVisitor.class.getName(), jarVisitor.getClass().getName());
jarUrl = new URL ("vfszip:./target/packages/defaultpar.par");
jarVisitor = JarVisitorFactory.getVisitor(jarUrl, getFilters(), null);
assertEquals(FileZippedJarVisitor.class.getName(), jarVisitor.getClass().getName());
jarUrl = new URL ("vfsfile:./target/packages/explodedpar");
jarVisitor = JarVisitorFactory.getVisitor(jarUrl, getFilters(), null);
assertEquals(ExplodedJarVisitor.class.getName(), jarVisitor.getClass().getName());
}
@Test
@TestForIssue( jiraKey = "EJB-230" )
public void testDuplicateFilterExplodedJarExpected() throws Exception {