[jboss-osgi-commits] JBoss-OSGI SVN: r101764 - in projects/jboss-osgi/projects/runtime/framework/trunk/src: test/java/org/jboss/test/osgi/bundle and 1 other directory.
jboss-osgi-commits at lists.jboss.org
jboss-osgi-commits at lists.jboss.org
Wed Mar 3 04:36:28 EST 2010
Author: thomas.diesler at jboss.com
Date: 2010-03-03 04:36:27 -0500 (Wed, 03 Mar 2010)
New Revision: 101764
Removed:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContext.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContextFactory.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/LazyVirtualFileHandler.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/bundle/
projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleVFSUnitTestCase.java
Log:
Remove framework/vfs
Deleted: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java 2010-03-03 09:27:37 UTC (rev 101763)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java 2010-03-03 09:36:27 UTC (rev 101764)
@@ -1,185 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.framework.vfs;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.plugins.context.AbstractVirtualFileHandler;
-import org.jboss.virtual.spi.VFSContext;
-import org.jboss.virtual.spi.VirtualFileHandler;
-import org.jboss.deployers.vfs.spi.structure.helpers.AbstractStructureDeployer;
-import org.osgi.framework.Bundle;
-
-/**
- * Bundle handler.
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-class BundleHandler extends AbstractVirtualFileHandler
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = 6650185906199900589L;
-
- private VirtualFile root; // bundle's root
- private VirtualFile file;
- private Bundle bundle;
-
- private volatile String relativePath;
- private volatile URI uri;
- private volatile VirtualFileHandler handler;
-
- public BundleHandler(VFSContext context, VirtualFile root, VirtualFile file, Bundle bundle) throws IOException
- {
- this(context, LazyVirtualFileHandler.create(file.getParent()), root, file, bundle);
- }
-
- private BundleHandler(VFSContext context, VirtualFileHandler parent, VirtualFile root, VirtualFile file, Bundle bundle) throws IOException
- {
- super(context, parent, file.getName());
- this.root = root;
- this.file = file;
- this.bundle = bundle;
- }
-
- protected VirtualFileHandler getHandler() throws IOException
- {
- if (handler == null)
- handler = LazyVirtualFileHandler.create(file);
-
- return handler;
- }
-
- protected String getRelativePath(boolean checkStart, boolean checkEnd)
- {
- if (relativePath == null)
- relativePath = AbstractStructureDeployer.getRelativePath(root, file);
-
- StringBuilder path = new StringBuilder(relativePath);
- if (checkStart && relativePath.startsWith("/") == false)
- path.insert(0, '/');
- if (checkEnd && relativePath.endsWith("/") == false)
- path.append('/');
-
- return path.toString();
- }
-
- protected VirtualFileHandler createChildHandler(VirtualFile child) throws IOException
- {
- return new BundleHandler(getVFSContext(), this, root, child, bundle);
- }
-
- public URI toURI() throws URISyntaxException
- {
- if (uri == null)
- uri = new URI("bundle", Long.toString(bundle.getBundleId()), getRelativePath(true, false), null);
-
- return uri;
- }
-
- public long getLastModified() throws IOException
- {
- return bundle.getLastModified();
- }
-
- public InputStream openStream() throws IOException
- {
- bundle.getResource(getRelativePath(false, false)); // permission check
-
- return file.openStream();
- }
-
- public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
- {
- bundle.findEntries(getRelativePath(false, false), null, false); // permission check
-
- List<VirtualFile> children = file.getChildren();
- if (children != null && children.isEmpty() == false)
- {
- List<VirtualFileHandler> handlers = new ArrayList<VirtualFileHandler>(children.size());
- for (VirtualFile child : children)
- {
- handlers.add(createChildHandler(child));
- }
- return handlers;
- }
- return Collections.emptyList();
- }
-
- public VirtualFileHandler getChild(String path) throws IOException
- {
- String fullPath = getRelativePath(false, true) + path;
- URL entry = bundle.getEntry(fullPath); // permission check
- if (entry == null)
- return null;
-
- VirtualFile child = file.getChild(path); // the child should exist, since entry does
- return createChildHandler(child);
- }
-
- //---------------------------------------------------------
-
- @Override
- protected URL toInternalVfsUrl() throws MalformedURLException, URISyntaxException
- {
- return toURI().toURL();
- }
-
- public long getSize() throws IOException
- {
- return file.getSize();
- }
-
- public boolean exists() throws IOException
- {
- return file.exists();
- }
-
- public boolean isLeaf() throws IOException
- {
- return file.isLeaf();
- }
-
- public boolean isHidden() throws IOException
- {
- return file.isHidden();
- }
-
- public boolean removeChild(String name) throws IOException
- {
- return getHandler().removeChild(name);
- }
-
- public boolean isNested() throws IOException
- {
- return VFSUtils.isNestedFile(file);
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContext.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContext.java 2010-03-03 09:27:37 UTC (rev 101763)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContext.java 2010-03-03 09:36:27 UTC (rev 101764)
@@ -1,126 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.framework.vfs;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URL;
-
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.osgi.framework.bundle.AbstractBundleState;
-import org.jboss.osgi.framework.bundle.AbstractDeployedBundleState;
-import org.jboss.osgi.framework.bundle.OSGiBundleManager;
-import org.jboss.osgi.framework.bundle.OSGiBundleState;
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.plugins.context.AbstractVFSContext;
-import org.jboss.virtual.spi.VirtualFileHandler;
-
-/**
- * Bundle vfs context.
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-public class BundleVFSContext extends AbstractVFSContext
-{
- private String name;
- private VirtualFileHandler root;
-
- public BundleVFSContext(URI rootURI, OSGiBundleManager manager) throws IOException
- {
- super(rootURI);
-
- name = parseName(rootURI);
-
- AbstractDeployedBundleState bundleState = getBundleState(rootURI, manager);
- String path = parsePath(rootURI);
- URL resource = bundleState.getEntry(path); // permission check
- if (resource == null)
- throw new IllegalArgumentException("No such resource: " + path + " in bundle: " + bundleState);
-
- DeploymentUnit unit = bundleState.getDeploymentUnit();
- if (unit instanceof VFSDeploymentUnit == false)
- throw new IllegalArgumentException("Cannot handle non VFS deployments: " + unit);
-
- VFSDeploymentUnit vdu = VFSDeploymentUnit.class.cast(unit);
- VirtualFile duRoot = vdu.getRoot();
- VirtualFile duFile = vdu.getFile(path); // should exist, resource != null
- root = new BundleHandler(this, duRoot, duFile, bundleState);
- }
-
- /**
- * Parse context name from uri.
- *
- * @param uri the uri
- * @return parsed context's name
- */
- protected String parseName(URI uri)
- {
- return uri.getHost();
- }
-
- /**
- * Parse resource path from uri.
- *
- * @param uri the uri
- * @return parsed resource path
- */
- protected String parsePath(URI uri)
- {
- String path = uri.getPath();
- if (path == null)
- path = "";
-
- return path;
- }
-
- /**
- * Get bundle state.
- *
- * @param uri the uri
- * @param manager the osgi manager
- * @return bundle state or exception if no such bundle exists
- */
- protected AbstractDeployedBundleState getBundleState(URI uri, OSGiBundleManager manager)
- {
- String host = uri.getHost();
- long id = Long.parseLong(host);
- if (id == 0)
- throw new IllegalArgumentException("Cannot handle system bundle, it's too abstract.");
-
- AbstractBundleState abs = manager.getBundleById(id);
- if (abs == null)
- throw new IllegalArgumentException("No such bundle: " + id);
-
- return OSGiBundleState.class.cast(abs); // should be able to cast, as it's not system
- }
-
- public String getName()
- {
- return name;
- }
-
- public VirtualFileHandler getRoot() throws IOException
- {
- return root;
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContextFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContextFactory.java 2010-03-03 09:27:37 UTC (rev 101763)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContextFactory.java 2010-03-03 09:36:27 UTC (rev 101764)
@@ -1,102 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.framework.vfs;
-
-import java.net.URL;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.io.IOException;
-
-import org.jboss.virtual.plugins.context.AbstractContextFactory;
-import org.jboss.virtual.spi.VFSContext;
-import org.jboss.virtual.spi.VFSContextFactoryLocator;
-import org.jboss.osgi.framework.bundle.OSGiBundleManager;
-
-/**
- * Bundle vfs context factory.
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-public class BundleVFSContextFactory extends AbstractContextFactory
-{
- static
- {
- init();
- }
-
- private static final String HANDLER_PKGS = "java.protocol.handler.pkgs";
- private OSGiBundleManager manager;
-
- public BundleVFSContextFactory(OSGiBundleManager manager)
- {
- super("bundle");
- if (manager == null)
- throw new IllegalArgumentException("Null manager");
- this.manager = manager;
- }
-
- public static void init()
- {
- String pkg = BundleVFSContextFactory.class.getPackage().getName();
- String pkgs = System.getProperty(HANDLER_PKGS);
-
- if (pkgs == null || pkgs.trim().length() == 0)
- {
- pkgs = pkg;
- System.setProperty(HANDLER_PKGS, pkgs);
- }
- else if (pkgs.contains(pkg) == false)
- {
- pkgs += ("|" + pkg);
- System.setProperty(HANDLER_PKGS, pkgs);
- }
- }
-
- public void start()
- {
- VFSContextFactoryLocator.registerFactory(this);
- }
-
- public void stop()
- {
- VFSContextFactoryLocator.unregisterFactory(this);
- }
-
- public VFSContext getVFS(URL rootURL) throws IOException
- {
- try
- {
- return getVFS(rootURL.toURI());
- }
- catch (URISyntaxException e)
- {
- IOException ioe = new IOException();
- ioe.initCause(e);
- throw ioe;
- }
- }
-
- public VFSContext getVFS(URI rootURI) throws IOException
- {
- return new BundleVFSContext(rootURI, manager);
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/LazyVirtualFileHandler.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/LazyVirtualFileHandler.java 2010-03-03 09:27:37 UTC (rev 101763)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/vfs/LazyVirtualFileHandler.java 2010-03-03 09:36:27 UTC (rev 101764)
@@ -1,105 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.framework.vfs;
-
-import java.io.IOException;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.security.AccessController;
-import java.security.PrivilegedExceptionAction;
-
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.spi.VirtualFileHandler;
-
-/**
- * Create a lazy VirtualFileHandler based off VirtualFile
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-class LazyVirtualFileHandler
-{
- private static final Method getHandler;
-
- static
- {
- try
- {
- PrivilegedExceptionAction<Method> action = new PrivilegedExceptionAction<Method>()
- {
- public Method run() throws Exception
- {
- Method method = VirtualFile.class.getDeclaredMethod("getHandler");
- method.setAccessible(true);
- return method;
- }
- };
- getHandler = AccessController.doPrivileged(action);
-
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Create a VFH proxy, delaying the actual reflect hack.
- *
- * @param file the VFH owner
- * @return VFH proxy
- * @throws IOException for any error
- */
- static VirtualFileHandler create(VirtualFile file) throws IOException
- {
- if (file == null)
- return null;
-
- ClassLoader cl = LazyVirtualFileHandler.class.getClassLoader();
- Object proxy = Proxy.newProxyInstance(cl, new Class<?>[]{VirtualFileHandler.class}, new ProxyHandler(file));
- return VirtualFileHandler.class.cast(proxy);
- }
-
- private static class ProxyHandler implements InvocationHandler
- {
- private VirtualFile file;
- private volatile VirtualFileHandler handler;
-
- private ProxyHandler(VirtualFile file)
- {
- this.file = file;
- }
-
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
- {
- return method.invoke(getHandler(), args);
- }
-
- private VirtualFileHandler getHandler() throws Exception
- {
- if (handler == null)
- handler = (VirtualFileHandler)getHandler.invoke(file);
-
- return handler;
- }
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleVFSUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleVFSUnitTestCase.java 2010-03-03 09:27:37 UTC (rev 101763)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleVFSUnitTestCase.java 2010-03-03 09:36:27 UTC (rev 101764)
@@ -1,233 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat Middleware LLC, and individual contributors
-* as indicated by the @author tags. See the copyright.txt file in the
-* distribution for a full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.osgi.bundle;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URL;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import junit.framework.Test;
-
-import org.jboss.osgi.framework.vfs.BundleVFSContextFactory;
-import org.jboss.test.osgi.FrameworkTest;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.VirtualFileFilter;
-import org.jboss.virtual.VirtualFileVisitor;
-import org.jboss.virtual.VisitorAttributes;
-import org.osgi.framework.Bundle;
-
-/**
- * BundleVFSUnitTestCase.
- *
- * TODO test security
- * TODO test fragments
- * @author <a href="ales.justin at jboss.org">Ales Justin</a>
- */
-public class BundleVFSUnitTestCase extends FrameworkTest
-{
- private BundleVFSContextFactory factory;
-
- public static Test suite()
- {
- return suite(BundleVFSUnitTestCase.class);
- }
-
- public BundleVFSUnitTestCase(String name)
- {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
-
- factory = new BundleVFSContextFactory(getBundleManager());
- factory.start();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- factory.stop();
- factory = null;
-
- super.tearDown();
- }
-
- public void testBasicOps() throws Exception
- {
- Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
- try
- {
- URI uri = createURI(bundle, null);
- assertBundleByURI(uri, 0, true, "root.xml");
-
- uri = createURI(bundle, "root.xml");
- assertBundleByURI(uri, 0, false, null);
-
- uri = createURI(bundle, "META-INF");
- assertBundleByURI(uri, -1, true, "MANIFEST.MF");
-
- uri = createURI(bundle, "META-INF/MANIFEST.MF");
- assertBundleByURI(uri, 0, false, null);
- }
- finally
- {
- uninstall(bundle);
- }
- }
-
- public void testBasicNavigation() throws Exception
- {
- Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
- try
- {
- URI uri = createURI(bundle, null);
- VirtualFile root = VFS.getRoot(uri);
- assertNotNull(root);
-
- VirtualFile metainf = root.getChild("META-INF");
- assertBundleByFile(metainf, -1, true, "MANIFEST.MF");
- List<VirtualFile> children = metainf.getChildren();
- assertTrue(children != null && children.size() == 1);
- assertEquals(root, metainf.getParent());
-
- VirtualFile manifest = metainf.getChild("MANIFEST.MF");
- assertBundleByFile(manifest, 0, false, null);
- }
- finally
- {
- uninstall(bundle);
- }
- }
-
- public void testVisitor() throws Exception
- {
- Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
- try
- {
- URI uri = createURI(bundle, null);
- VirtualFile root = VFS.getRoot(uri);
- assertNotNull(root);
-
- List<VirtualFile> children = root.getChildren(new VirtualFileFilter()
- {
- public boolean accepts(VirtualFile file)
- {
- return file.getPathName().contains("META-INF");
- }
- });
- assertTrue(children != null && children.size() == 1);
-
- children = root.getChildrenRecursively(new VirtualFileFilter()
- {
- public boolean accepts(VirtualFile file)
- {
- return file.getPathName().contains("META-INF");
- }
- });
- assertTrue(children != null && children.size() == 2);
-
- final AtomicInteger counter = new AtomicInteger(0);
- root.visit(new VirtualFileVisitor()
- {
- public VisitorAttributes getAttributes()
- {
- return VisitorAttributes.RECURSE_LEAVES_ONLY;
- }
-
- public void visit(VirtualFile file)
- {
- if (file.getName().equals("entry2.xml")) counter.incrementAndGet();
- }
- });
- assertEquals(2, counter.get());
- }
- finally
- {
- uninstall(bundle);
- }
- }
-
- protected URI createURI(Bundle bundle, String path) throws Exception
- {
- if (path == null)
- path = "";
- if (path != null && path.startsWith("/") == false)
- path = "/" + path;
-
- return new URI("bundle", Long.toString(bundle.getBundleId()), path, null);
- }
-
- protected void assertBundleByURI(URI uri, int available, boolean hasChildren, String path) throws Exception
- {
- VFS vfs = VFS.getVFS(uri);
- assertNotNull(vfs);
- VirtualFile file = vfs.getRoot();
- assertNotNull(file);
-
- URI bURI = file.toURI();
- assertEquals(uri, bURI);
- URL url = uri.toURL();
- assertEquals(url, file.toURL());
-
- assertBundleByFile(file, available, hasChildren, path);
-
- // check url
- file = VFS.getRoot(url);
- assertBundleByFile(file, available, hasChildren, path);
- }
-
- protected void assertBundleByFile(VirtualFile file, int available, boolean hasChildren, String path) throws IOException
- {
- long lastModified = file.getLastModified();
- assertTrue(lastModified >= 0);
-
- InputStream is = file.openStream();
- try
- {
- assertTrue(is.available() > available);
- }
- finally
- {
- is.close();
- }
-
- List<VirtualFile> children = file.getChildren();
- assertEquals(hasChildren, children != null && children.isEmpty() == false);
-
- String cp = path;
- if (cp == null)
- cp = "rubbish"; // :-)
-
- VirtualFile child = file.getChild(cp);
- assertEquals(path != null, child != null);
-
- if (child != null)
- assertEquals(file, child.getParent());
- }
-}
\ No newline at end of file
More information about the jboss-osgi-commits
mailing list