From jboss-osgi-commits at lists.jboss.org Wed Mar 3 04:36:29 2010
Content-Type: multipart/mixed; boundary="===============8578468777728601545=="
MIME-Version: 1.0
From: jboss-osgi-commits at lists.jboss.org
To: jboss-osgi-commits at lists.jboss.org
Subject: [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.
Date: Wed, 03 Mar 2010 04:36:28 -0500
Message-ID: <201003030936.o239aSSO015995@svn01.web.mwc.hst.phx2.redhat.com>
--===============8578468777728601545==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Author: thomas.diesler(a)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/j=
boss/osgi/framework/vfs/BundleHandler.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/j=
boss/osgi/framework/vfs/BundleVFSContext.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/j=
boss/osgi/framework/vfs/BundleVFSContextFactory.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/j=
boss/osgi/framework/vfs/LazyVirtualFileHandler.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/j=
boss/osgi/framework/vfs/bundle/
projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/j=
boss/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
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- 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 10=
1763)
+++ 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 10=
1764)
@@ -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.AbstractStructureDepl=
oyer;
-import org.osgi.framework.Bundle;
-
-/**
- * Bundle handler.
- *
- * @author Ales Justin
- */
-class BundleHandler extends AbstractVirtualFileHandler
-{
- /** The serialVersionUID */
- private static final long serialVersionUID =3D 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, Vi=
rtualFile root, VirtualFile file, Bundle bundle) throws IOException
- {
- super(context, parent, file.getName());
- this.root =3D root;
- this.file =3D file;
- this.bundle =3D bundle;
- }
-
- protected VirtualFileHandler getHandler() throws IOException
- {
- if (handler =3D=3D null)
- handler =3D LazyVirtualFileHandler.create(file);
-
- return handler;
- }
-
- protected String getRelativePath(boolean checkStart, boolean checkEnd)
- {
- if (relativePath =3D=3D null)
- relativePath =3D AbstractStructureDeployer.getRelativePath(root, =
file);
- =
- StringBuilder path =3D new StringBuilder(relativePath);
- if (checkStart && relativePath.startsWith("/") =3D=3D false)
- path.insert(0, '/');
- if (checkEnd && relativePath.endsWith("/") =3D=3D false)
- path.append('/');
-
- return path.toString();
- }
-
- protected VirtualFileHandler createChildHandler(VirtualFile child) thro=
ws IOException
- {
- return new BundleHandler(getVFSContext(), this, root, child, bundle);
- }
-
- public URI toURI() throws URISyntaxException
- {
- if (uri =3D=3D null)
- uri =3D new URI("bundle", Long.toString(bundle.getBundleId()), ge=
tRelativePath(true, false), null);
-
- return uri;
- }
-
- public long getLastModified() throws IOException
- {
- return bundle.getLastModified();
- }
-
- public InputStream openStream() throws IOException
- {
- bundle.getResource(getRelativePath(false, false)); // permission che=
ck
- =
- return file.openStream();
- }
-
- public List getChildren(boolean ignoreErrors) throw=
s IOException
- {
- bundle.findEntries(getRelativePath(false, false), null, false); // p=
ermission check
-
- List children =3D file.getChildren();
- if (children !=3D null && children.isEmpty() =3D=3D false)
- {
- List handlers =3D new ArrayList(children.size());
- for (VirtualFile child : children)
- {
- handlers.add(createChildHandler(child));
- }
- return handlers;
- }
- return Collections.emptyList();
- }
-
- public VirtualFileHandler getChild(String path) throws IOException
- {
- String fullPath =3D getRelativePath(false, true) + path; =
- URL entry =3D bundle.getEntry(fullPath); // permission check
- if (entry =3D=3D null)
- return null;
-
- VirtualFile child =3D file.getChild(path); // the child should exist=
, since entry does
- return createChildHandler(child);
- }
-
- //---------------------------------------------------------
-
- @Override
- protected URL toInternalVfsUrl() throws MalformedURLException, URISynta=
xException
- {
- 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
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- 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 Ales Justin
- */
-public class BundleVFSContext extends AbstractVFSContext
-{
- private String name;
- private VirtualFileHandler root;
-
- public BundleVFSContext(URI rootURI, OSGiBundleManager manager) throws =
IOException
- {
- super(rootURI);
-
- name =3D parseName(rootURI);
-
- AbstractDeployedBundleState bundleState =3D getBundleState(rootURI, =
manager);
- String path =3D parsePath(rootURI);
- URL resource =3D bundleState.getEntry(path); // permission check
- if (resource =3D=3D null)
- throw new IllegalArgumentException("No such resource: " + path + =
" in bundle: " + bundleState);
-
- DeploymentUnit unit =3D bundleState.getDeploymentUnit();
- if (unit instanceof VFSDeploymentUnit =3D=3D false)
- throw new IllegalArgumentException("Cannot handle non VFS deploym=
ents: " + unit);
-
- VFSDeploymentUnit vdu =3D VFSDeploymentUnit.class.cast(unit);
- VirtualFile duRoot =3D vdu.getRoot();
- VirtualFile duFile =3D vdu.getFile(path); // should exist, resource =
!=3D null
- root =3D 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 =3D uri.getPath();
- if (path =3D=3D null)
- path =3D "";
-
- 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, OSGiBundl=
eManager manager)
- {
- String host =3D uri.getHost();
- long id =3D Long.parseLong(host);
- if (id =3D=3D 0)
- throw new IllegalArgumentException("Cannot handle system bundle, =
it's too abstract.");
-
- AbstractBundleState abs =3D manager.getBundleById(id);
- if (abs =3D=3D null)
- throw new IllegalArgumentException("No such bundle: " + id);
-
- return OSGiBundleState.class.cast(abs); // should be able to cast, a=
s 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
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/=
jboss/osgi/framework/vfs/BundleVFSContextFactory.java 2010-03-03 09:27:37 U=
TC (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 U=
TC (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 Ales Justin
- */
-public class BundleVFSContextFactory extends AbstractContextFactory
-{
- static
- {
- init();
- }
-
- private static final String HANDLER_PKGS =3D "java.protocol.handler.pkg=
s";
- private OSGiBundleManager manager;
-
- public BundleVFSContextFactory(OSGiBundleManager manager)
- {
- super("bundle");
- if (manager =3D=3D null)
- throw new IllegalArgumentException("Null manager");
- this.manager =3D manager;
- }
-
- public static void init()
- {
- String pkg =3D BundleVFSContextFactory.class.getPackage().getName();
- String pkgs =3D System.getProperty(HANDLER_PKGS);
-
- if (pkgs =3D=3D null || pkgs.trim().length() =3D=3D 0)
- {
- pkgs =3D pkg;
- System.setProperty(HANDLER_PKGS, pkgs);
- }
- else if (pkgs.contains(pkg) =3D=3D false)
- {
- pkgs +=3D ("|" + 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 =3D 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
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/=
jboss/osgi/framework/vfs/LazyVirtualFileHandler.java 2010-03-03 09:27:37 UT=
C (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 UT=
C (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 Ales Justin
- */
-class LazyVirtualFileHandler
-{
- private static final Method getHandler;
-
- static
- {
- try
- {
- PrivilegedExceptionAction action =3D new PrivilegedExcept=
ionAction()
- {
- public Method run() throws Exception
- {
- Method method =3D VirtualFile.class.getDeclaredMethod("getH=
andler");
- method.setAccessible(true);
- return method;
- }
- };
- getHandler =3D 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 =3D=3D null)
- return null;
-
- ClassLoader cl =3D LazyVirtualFileHandler.class.getClassLoader();
- Object proxy =3D Proxy.newProxyInstance(cl, new Class>[]{VirtualFi=
leHandler.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 =3D file;
- }
-
- public Object invoke(Object proxy, Method method, Object[] args) thr=
ows Throwable
- {
- return method.invoke(getHandler(), args);
- }
-
- private VirtualFileHandler getHandler() throws Exception
- {
- if (handler =3D=3D null)
- handler =3D (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
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- 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 Ales Justin
- */
-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 =3D new BundleVFSContextFactory(getBundleManager());
- factory.start();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- factory.stop();
- factory =3D null;
-
- super.tearDown();
- }
-
- public void testBasicOps() throws Exception
- {
- Bundle bundle =3D addBundle("/bundles/entries/", "entries-simple");
- try
- {
- URI uri =3D createURI(bundle, null);
- assertBundleByURI(uri, 0, true, "root.xml");
-
- uri =3D createURI(bundle, "root.xml");
- assertBundleByURI(uri, 0, false, null); =
-
- uri =3D createURI(bundle, "META-INF");
- assertBundleByURI(uri, -1, true, "MANIFEST.MF");
-
- uri =3D createURI(bundle, "META-INF/MANIFEST.MF");
- assertBundleByURI(uri, 0, false, null);
- }
- finally
- {
- uninstall(bundle);
- }
- }
-
- public void testBasicNavigation() throws Exception
- {
- Bundle bundle =3D addBundle("/bundles/entries/", "entries-simple");
- try
- {
- URI uri =3D createURI(bundle, null);
- VirtualFile root =3D VFS.getRoot(uri);
- assertNotNull(root);
-
- VirtualFile metainf =3D root.getChild("META-INF");
- assertBundleByFile(metainf, -1, true, "MANIFEST.MF");
- List children =3D metainf.getChildren();
- assertTrue(children !=3D null && children.size() =3D=3D 1);
- assertEquals(root, metainf.getParent());
-
- VirtualFile manifest =3D metainf.getChild("MANIFEST.MF");
- assertBundleByFile(manifest, 0, false, null);
- }
- finally
- {
- uninstall(bundle);
- }
- }
-
- public void testVisitor() throws Exception
- {
- Bundle bundle =3D addBundle("/bundles/entries/", "entries-simple");
- try
- {
- URI uri =3D createURI(bundle, null);
- VirtualFile root =3D VFS.getRoot(uri);
- assertNotNull(root);
-
- List children =3D root.getChildren(new VirtualFileFi=
lter()
- {
- public boolean accepts(VirtualFile file)
- {
- return file.getPathName().contains("META-INF");
- }
- });
- assertTrue(children !=3D null && children.size() =3D=3D 1);
-
- children =3D root.getChildrenRecursively(new VirtualFileFilter()
- {
- public boolean accepts(VirtualFile file)
- {
- return file.getPathName().contains("META-INF");
- }
- });
- assertTrue(children !=3D null && children.size() =3D=3D 2);
-
- final AtomicInteger counter =3D 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.incrementA=
ndGet();
- }
- });
- assertEquals(2, counter.get());
- }
- finally
- {
- uninstall(bundle);
- }
- }
-
- protected URI createURI(Bundle bundle, String path) throws Exception
- {
- if (path =3D=3D null)
- path =3D "";
- if (path !=3D null && path.startsWith("/") =3D=3D false)
- path =3D "/" + path;
- =
- return new URI("bundle", Long.toString(bundle.getBundleId()), path, =
null);
- }
-
- protected void assertBundleByURI(URI uri, int available, boolean hasChi=
ldren, String path) throws Exception
- {
- VFS vfs =3D VFS.getVFS(uri);
- assertNotNull(vfs);
- VirtualFile file =3D vfs.getRoot();
- assertNotNull(file);
-
- URI bURI =3D file.toURI();
- assertEquals(uri, bURI);
- URL url =3D uri.toURL();
- assertEquals(url, file.toURL());
-
- assertBundleByFile(file, available, hasChildren, path);
-
- // check url
- file =3D VFS.getRoot(url);
- assertBundleByFile(file, available, hasChildren, path);
- }
-
- protected void assertBundleByFile(VirtualFile file, int available, bool=
ean hasChildren, String path) throws IOException
- {
- long lastModified =3D file.getLastModified();
- assertTrue(lastModified >=3D 0);
-
- InputStream is =3D file.openStream();
- try
- {
- assertTrue(is.available() > available);
- }
- finally
- {
- is.close();
- }
-
- List children =3D file.getChildren();
- assertEquals(hasChildren, children !=3D null && children.isEmpty() =
=3D=3D false);
-
- String cp =3D path;
- if (cp =3D=3D null)
- cp =3D "rubbish"; // :-)
-
- VirtualFile child =3D file.getChild(cp);
- assertEquals(path !=3D null, child !=3D null);
-
- if (child !=3D null)
- assertEquals(file, child.getParent());
- }
-}
\ No newline at end of file
--===============8578468777728601545==--