Author: thomas.diesler(a)jboss.com
Date: 2010-03-11 06:27:39 -0500 (Thu, 11 Mar 2010)
New Revision: 102276
Added:
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/vfs21/
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/vfs21/SimpleVFS21Test.java
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/vfs21/bundle/
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/vfs21/bundle/SimpleActivator.java
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/resources/
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/resources/simple/
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/resources/simple/META-INF/
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/resources/simple/META-INF/MANIFEST.MF
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/osgi/
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/osgi/vfs30/
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/osgi/vfs30/SimpleVFS30Test.java
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/osgi/vfs30/bundle/
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/osgi/vfs30/bundle/SimpleActivator.java
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/resources/
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/resources/simple/
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/resources/simple/META-INF/
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/resources/simple/META-INF/MANIFEST.MF
Modified:
projects/jboss-osgi/projects/vfs/trunk/api/pom.xml
projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/VFSUtils.java
projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/VirtualFile.java
projects/jboss-osgi/projects/vfs/trunk/vfs21/.classpath
projects/jboss-osgi/projects/vfs/trunk/vfs21/pom.xml
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VirtualFileAdaptor21.java
projects/jboss-osgi/projects/vfs/trunk/vfs30/.classpath
projects/jboss-osgi/projects/vfs/trunk/vfs30/pom.xml
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java
Log:
Add getFileURL() and test coverage
Modified: projects/jboss-osgi/projects/vfs/trunk/api/pom.xml
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/api/pom.xml 2010-03-11 11:17:32 UTC (rev
102275)
+++ projects/jboss-osgi/projects/vfs/trunk/api/pom.xml 2010-03-11 11:27:39 UTC (rev
102276)
@@ -28,17 +28,4 @@
<version>1.0.0-SNAPSHOT</version>
</parent>
- <!-- Properties -->
- <properties>
- <version.osgi>4.2.0</version.osgi>
- </properties>
-
- <!-- Dependencies -->
- <dependencies>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>${version.osgi}</version>
- </dependency>
- </dependencies>
</project>
Modified:
projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/VFSUtils.java
===================================================================
---
projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/VFSUtils.java 2010-03-11
11:17:32 UTC (rev 102275)
+++
projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/VFSUtils.java 2010-03-11
11:27:39 UTC (rev 102276)
@@ -24,6 +24,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
@@ -61,7 +62,7 @@
}
}
- public static void copyStream(InputStream is, FileOutputStream os) throws IOException
+ public static void copyStream(InputStream is, OutputStream os) throws IOException
{
if (is == null)
throw new IllegalArgumentException("input stream is null");
Modified:
projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/VirtualFile.java
===================================================================
---
projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/VirtualFile.java 2010-03-11
11:17:32 UTC (rev 102275)
+++
projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/VirtualFile.java 2010-03-11
11:27:39 UTC (rev 102276)
@@ -24,7 +24,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
-import java.net.URISyntaxException;
import java.net.URL;
import java.util.Enumeration;
import java.util.List;
@@ -74,16 +73,22 @@
boolean isDirectory() throws IOException;
/**
- * Get the VF URL (file://root/org/jboss/X.java)
+ * Get the VF URL (vfs:/root/org/jboss/X.java)
*
* @return the full URL to the VF in the VFS.
* @throws MalformedURLException if a url cannot be parsed
- * @throws URISyntaxException if a uri cannot be parsed
- * @throws IllegalStateException if the file is closed
+ * @throws IOException for any problem accessing the virtual file system
*/
- URL toURL() throws MalformedURLException, URISyntaxException;
+ URL toURL() throws IOException;
/**
+ * Get the file URL used for the mount.
+ *
+ * @return The source file URL or null if this is not the root.
+ */
+ URL getFileURL() throws IOException;
+
+ /**
* Get the parent
*
* @return the parent or null if there is no parent
Modified: projects/jboss-osgi/projects/vfs/trunk/vfs21/.classpath
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs21/.classpath 2010-03-11 11:17:32 UTC (rev
102275)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs21/.classpath 2010-03-11 11:27:39 UTC (rev
102276)
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" output="target/test-classes"
path="src/test/java"/>
+ <classpathentry kind="src" output="target/test-classes"
path="src/test/resources"/>
<classpathentry kind="con"
path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
Modified: projects/jboss-osgi/projects/vfs/trunk/vfs21/pom.xml
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs21/pom.xml 2010-03-11 11:17:32 UTC (rev
102275)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs21/pom.xml 2010-03-11 11:27:39 UTC (rev
102276)
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- ====================================================================== -->
-<!-- -->
-<!-- JBoss, the OpenSource J2EE webOS -->
-<!-- -->
-<!-- Distributable under LGPL license. -->
-<!-- See terms of license at
http://www.gnu.org. -->
-<!-- -->
-<!-- ====================================================================== -->
+ <!-- ====================================================================== -->
+ <!-- -->
+ <!-- JBoss, the OpenSource J2EE webOS -->
+ <!-- -->
+ <!-- Distributable under LGPL license. -->
+ <!-- See terms of license at
http://www.gnu.org. -->
+ <!-- -->
+ <!-- ====================================================================== -->
<!-- $Id: pom.xml -1 $ -->
@@ -30,7 +30,9 @@
<!-- Properties -->
<properties>
+ <version.jboss.shrinkwrap>1.0.0-SNAPSHOT</version.jboss.shrinkwrap>
<version.jboss.vfs>2.1.3.SP1</version.jboss.vfs>
+ <version.osgi>4.2.0</version.osgi>
</properties>
<!-- Dependencies -->
@@ -45,5 +47,23 @@
<artifactId>jboss-vfs</artifactId>
<version>${version.jboss.vfs}</version>
</dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${version.osgi}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-impl-base</artifactId>
+ <version>${version.jboss.shrinkwrap}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Modified:
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VirtualFileAdaptor21.java
===================================================================
---
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VirtualFileAdaptor21.java 2010-03-11
11:17:32 UTC (rev 102275)
+++
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VirtualFileAdaptor21.java 2010-03-11
11:27:39 UTC (rev 102276)
@@ -21,9 +21,10 @@
*/
package org.jboss.osgi.vfs21;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
@@ -45,13 +46,13 @@
private org.jboss.virtual.VirtualFile root;
private org.jboss.virtual.VirtualFile delegate;
- VirtualFileAdaptor21(org.jboss.virtual.VirtualFile root, org.jboss.virtual.VirtualFile
delegate)
+ VirtualFileAdaptor21(org.jboss.virtual.VirtualFile root, org.jboss.virtual.VirtualFile
delegate)
{
if (root == null)
throw new IllegalStateException("Null root");
if (delegate == null)
throw new IllegalStateException("Null delegate");
-
+
this.delegate = delegate;
this.root = root;
}
@@ -91,13 +92,37 @@
return delegate.isLeaf() == false;
}
- public URL toURL() throws MalformedURLException, URISyntaxException
+ public URL toURL() throws IOException
{
- return delegate.toURL();
+ try
+ {
+ return delegate.toURL();
+ }
+ catch (URISyntaxException ex)
+ {
+ throw new IOException(ex);
+ }
}
- public void close()
+ public URL getFileURL() throws IOException
{
+ if (root != delegate)
+ return null;
+
+ try
+ {
+ URI uri = VFSUtils.getCompatibleURI(root);
+ String path = VFSUtils.stripProtocol(uri);
+ return new File(path).toURI().toURL();
+ }
+ catch (Exception ex)
+ {
+ throw new IOException(ex);
+ }
+ }
+
+ public void close()
+ {
delegate.close();
}
@@ -129,7 +154,7 @@
{
if (path == null)
throw new IllegalArgumentException("Null path");
-
+
if (pattern == null)
pattern = "*";
@@ -147,14 +172,14 @@
{
if (path == null)
throw new IllegalArgumentException("Null path");
-
+
if (path.startsWith("/"))
path = path.substring(1);
-
+
org.jboss.virtual.VirtualFile child = delegate.getChild(path);
if (child == null)
return null;
-
+
return new VFSEntryPathsEnumeration(delegate, child);
}
Added:
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/vfs21/SimpleVFS21Test.java
===================================================================
---
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/vfs21/SimpleVFS21Test.java
(rev 0)
+++
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/vfs21/SimpleVFS21Test.java 2010-03-11
11:27:39 UTC (rev 102276)
@@ -0,0 +1,182 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.vfs21;
+
+//$Id: SimpleTestCase.java 102173 2010-03-09 21:16:59Z thomas.diesler(a)jboss.com $
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.jboss.osgi.vfs.AbstractVFS;
+import org.jboss.osgi.vfs.VFSUtils;
+import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.Asset;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.test.osgi.vfs21.bundle.SimpleActivator;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+
+/**
+ * A test that verifies the VFS21 abstraction.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 11-Mar-2010
+ */
+public class SimpleVFS21Test
+{
+ private static VirtualFile virtualFile;
+ private static int fileLength;
+
+ @BeforeClass
+ public static void beforeClass() throws IOException
+ {
+ JavaArchive archive = Archives.create("example-simple.jar",
JavaArchive.class);
+ archive.addClass(SimpleActivator.class);
+ Asset asset = new Asset()
+ {
+ public InputStream openStream()
+ {
+ String path = "/simple/" + JarFile.MANIFEST_NAME;
+ try
+ {
+ URL manifest = getClass().getResource(path);
+ return manifest.openStream();
+ }
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Cannot open stream for: " +
path, ex);
+ }
+ }
+ };
+ archive.add(asset, JarFile.MANIFEST_NAME);
+
+ // Convert archive to file URL
+ ZipExporter exporter = archive.as(ZipExporter.class);
+ File target = File.createTempFile("archive_", ".jar");
+ exporter.exportZip(target, true);
+ target.deleteOnExit();
+
+ FileInputStream fis = new FileInputStream(target);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ VFSUtils.copyStream(fis, baos);
+ fileLength = baos.toByteArray().length;
+
+ virtualFile = AbstractVFS.getRoot(target.toURI().toURL());
+ }
+
+ @Test
+ public void testManifestAccess() throws Exception
+ {
+ VirtualFile child = virtualFile.getChild(JarFile.MANIFEST_NAME);
+ assertNotNull("Manifest not null", child);
+
+ Manifest manifest = new Manifest();
+ manifest.read(child.openStream());
+ Attributes attributes = manifest.getMainAttributes();
+ String symbolicName = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
+ assertEquals("example-simple", symbolicName);
+ }
+
+ @Test
+ public void testManifestURLAccess() throws Exception
+ {
+ VirtualFile child = virtualFile.getChild(JarFile.MANIFEST_NAME);
+ assertNotNull("Manifest not null", child);
+
+ URL childURL = child.toURL();
+ URLConnection con = childURL.openConnection();
+ con.connect();
+ InputStream is = con.getInputStream();
+
+ Manifest manifest = new Manifest();
+ manifest.read(is);
+ Attributes attributes = manifest.getMainAttributes();
+ String symbolicName = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
+ assertEquals("example-simple", symbolicName);
+ }
+
+ @Test
+ public void testGetEntryPaths() throws Exception
+ {
+ Set<String> actual = new HashSet<String>();
+ Enumeration<String> en = virtualFile.getEntryPaths("/");
+ while(en.hasMoreElements())
+ actual.add(en.nextElement());
+
+ Set<String> expected = new HashSet<String>();
+ expected.add("org/");
+ expected.add("org/jboss/");
+ expected.add("org/jboss/test/");
+ expected.add("org/jboss/test/osgi/");
+ expected.add("org/jboss/test/osgi/vfs21/");
+ expected.add("org/jboss/test/osgi/vfs21/bundle/");
+ expected.add("org/jboss/test/osgi/vfs21/bundle/SimpleActivator.class");
+ expected.add("META-INF/");
+ expected.add("META-INF/MANIFEST.MF");
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testFindEntries() throws Exception
+ {
+ Set<String> actual = new HashSet<String>();
+ Enumeration<URL> en = virtualFile.findEntries("/", null, true);
+ while(en.hasMoreElements())
+ actual.add(en.nextElement().toExternalForm());
+
+ Set<String> expected = new HashSet<String>();
+ expected.add(virtualFile.toURL() +
"org/jboss/test/osgi/vfs21/bundle/SimpleActivator.class");
+ expected.add(virtualFile.toURL() + "META-INF/MANIFEST.MF");
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testURLStreamAccess() throws Exception
+ {
+ URL fileURL = virtualFile.getFileURL();
+ URLConnection con = fileURL.openConnection();
+ con.connect();
+ InputStream is = con.getInputStream();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ VFSUtils.copyStream(is, baos);
+ int actualLength = baos.toByteArray().length;
+ assertEquals(fileLength, actualLength);
+ }
+}
\ No newline at end of file
Added:
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/vfs21/bundle/SimpleActivator.java
===================================================================
---
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/vfs21/bundle/SimpleActivator.java
(rev 0)
+++
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/vfs21/bundle/SimpleActivator.java 2010-03-11
11:27:39 UTC (rev 102276)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.vfs21.bundle;
+
+//$Id: SimpleActivator.java 101150 2010-02-19 10:50:46Z thomas.diesler(a)jboss.com $
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * A simple BundleActivator
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 24-Apr-2009
+ */
+public class SimpleActivator implements BundleActivator
+{
+ public void start(BundleContext context)
+ {
+ }
+
+ public void stop(BundleContext context)
+ {
+ }
+}
\ No newline at end of file
Added:
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/resources/simple/META-INF/MANIFEST.MF
===================================================================
---
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/resources/simple/META-INF/MANIFEST.MF
(rev 0)
+++
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/resources/simple/META-INF/MANIFEST.MF 2010-03-11
11:27:39 UTC (rev 102276)
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: example-simple
+Bundle-Activator: org.jboss.test.osgi.vfs21.bundle.SimpleActivator
+Import-Package: org.osgi.framework
Modified: projects/jboss-osgi/projects/vfs/trunk/vfs30/.classpath
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs30/.classpath 2010-03-11 11:17:32 UTC (rev
102275)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/.classpath 2010-03-11 11:27:39 UTC (rev
102276)
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" output="target/test-classes"
path="src/test/java"/>
+ <classpathentry kind="src" output="target/test-classes"
path="src/test/resources"/>
<classpathentry kind="con"
path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
Modified: projects/jboss-osgi/projects/vfs/trunk/vfs30/pom.xml
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs30/pom.xml 2010-03-11 11:17:32 UTC (rev
102275)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/pom.xml 2010-03-11 11:27:39 UTC (rev
102276)
@@ -30,7 +30,9 @@
<!-- Properties -->
<properties>
+ <version.jboss.shrinkwrap>1.0.0-SNAPSHOT</version.jboss.shrinkwrap>
<version.jboss.vfs>3.0.0-SNAPSHOT</version.jboss.vfs>
+ <version.osgi>4.2.0</version.osgi>
</properties>
<!-- Dependencies -->
@@ -45,5 +47,23 @@
<artifactId>jboss-vfs</artifactId>
<version>${version.jboss.vfs}</version>
</dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${version.osgi}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-impl-base</artifactId>
+ <version>${version.jboss.shrinkwrap}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Modified:
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java
===================================================================
---
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java 2010-03-11
11:17:32 UTC (rev 102275)
+++
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java 2010-03-11
11:27:39 UTC (rev 102276)
@@ -27,7 +27,9 @@
import org.jboss.osgi.vfs.VFSAdaptor;
import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.vfs.util.automount.Automounter;
+import org.jboss.vfs.TempFileProvider;
+import org.jboss.vfs.VFS;
+import org.jboss.vfs.spi.MountHandle;
/**
* An adaptor to the jboss-vfs-3.0.x VFS.
@@ -49,9 +51,10 @@
throw new IOException(ex);
}
- Automounter.mount(root);
+ TempFileProvider tmp = TempFileProvider.create("osgiroot", null);
+ MountHandle mountHandle = VFS.mountZip(root, root, tmp);
- return new VirtualFileAdaptor30(root);
+ return new VirtualFileAdaptor30(root, mountHandle);
}
public VirtualFile adapt(Object virtualFile)
Modified:
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java
===================================================================
---
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java 2010-03-11
11:17:32 UTC (rev 102275)
+++
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java 2010-03-11
11:27:39 UTC (rev 102276)
@@ -21,10 +21,9 @@
*/
package org.jboss.osgi.vfs30;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
@@ -32,7 +31,8 @@
import java.util.List;
import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.vfs.util.automount.Automounter;
+import org.jboss.vfs.VFSUtils;
+import org.jboss.vfs.spi.MountHandle;
/**
* An adaptor to the jboss-vfs-3.0.x VirtualFile.
@@ -43,7 +43,14 @@
class VirtualFileAdaptor30 implements VirtualFile
{
private org.jboss.vfs.VirtualFile delegate;
+ private MountHandle mountHandle;
+ VirtualFileAdaptor30(org.jboss.vfs.VirtualFile root, MountHandle mountHandle)
+ {
+ this(root);
+ this.mountHandle = mountHandle;
+ }
+
VirtualFileAdaptor30(org.jboss.vfs.VirtualFile delegate)
{
if (delegate == null)
@@ -76,11 +83,21 @@
return delegate.isDirectory();
}
- public URL toURL() throws MalformedURLException, URISyntaxException
+ public URL toURL() throws IOException
{
- return delegate.toURL();
+ URL url = delegate.toURL();
+ return url;
}
+ public URL getFileURL() throws IOException
+ {
+ if (mountHandle == null)
+ return null;
+
+ File mountSource = mountHandle.getMountSource();
+ return mountSource.toURI().toURL();
+ }
+
public VirtualFile getParent()
{
org.jboss.vfs.VirtualFile parent = delegate.getParent();
@@ -145,8 +162,8 @@
public void close()
{
- if (Automounter.isMounted(delegate))
- Automounter.cleanup(delegate);
+ if (mountHandle != null)
+ VFSUtils.safeClose(mountHandle);
}
@Override
Added:
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/osgi/vfs30/SimpleVFS30Test.java
===================================================================
---
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/osgi/vfs30/SimpleVFS30Test.java
(rev 0)
+++
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/osgi/vfs30/SimpleVFS30Test.java 2010-03-11
11:27:39 UTC (rev 102276)
@@ -0,0 +1,182 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.vfs30;
+
+//$Id: SimpleTestCase.java 102173 2010-03-09 21:16:59Z thomas.diesler(a)jboss.com $
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.jboss.osgi.vfs.AbstractVFS;
+import org.jboss.osgi.vfs.VFSUtils;
+import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.Asset;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.test.osgi.vfs30.bundle.SimpleActivator;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+
+/**
+ * A test that verifies the VFS30 abstraction.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 11-Mar-2010
+ */
+public class SimpleVFS30Test
+{
+ private static VirtualFile virtualFile;
+ private static int fileLength;
+
+ @BeforeClass
+ public static void beforeClass() throws IOException
+ {
+ JavaArchive archive = Archives.create("example-simple.jar",
JavaArchive.class);
+ archive.addClass(SimpleActivator.class);
+ Asset asset = new Asset()
+ {
+ public InputStream openStream()
+ {
+ String path = "/simple/" + JarFile.MANIFEST_NAME;
+ try
+ {
+ URL manifest = getClass().getResource(path);
+ return manifest.openStream();
+ }
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Cannot open stream for: " +
path, ex);
+ }
+ }
+ };
+ archive.add(asset, JarFile.MANIFEST_NAME);
+
+ // Convert archive to file URL
+ ZipExporter exporter = archive.as(ZipExporter.class);
+ File target = File.createTempFile("archive_", ".jar");
+ exporter.exportZip(target, true);
+ target.deleteOnExit();
+
+ FileInputStream fis = new FileInputStream(target);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ VFSUtils.copyStream(fis, baos);
+ fileLength = baos.toByteArray().length;
+
+ virtualFile = AbstractVFS.getRoot(target.toURI().toURL());
+ }
+
+ @Test
+ public void testManifestAccess() throws Exception
+ {
+ VirtualFile child = virtualFile.getChild(JarFile.MANIFEST_NAME);
+ assertNotNull("Manifest not null", child);
+
+ Manifest manifest = new Manifest();
+ manifest.read(child.openStream());
+ Attributes attributes = manifest.getMainAttributes();
+ String symbolicName = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
+ assertEquals("example-simple", symbolicName);
+ }
+
+ @Test
+ public void testManifestURLAccess() throws Exception
+ {
+ VirtualFile child = virtualFile.getChild(JarFile.MANIFEST_NAME);
+ assertNotNull("Manifest not null", child);
+
+ URL childURL = child.toURL();
+ URLConnection con = childURL.openConnection();
+ con.connect();
+ InputStream is = con.getInputStream();
+
+ Manifest manifest = new Manifest();
+ manifest.read(is);
+ Attributes attributes = manifest.getMainAttributes();
+ String symbolicName = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
+ assertEquals("example-simple", symbolicName);
+ }
+
+ @Test
+ public void testGetEntryPaths() throws Exception
+ {
+ Set<String> actual = new HashSet<String>();
+ Enumeration<String> en = virtualFile.getEntryPaths("/");
+ while(en.hasMoreElements())
+ actual.add(en.nextElement());
+
+ Set<String> expected = new HashSet<String>();
+ expected.add("org/");
+ expected.add("org/jboss/");
+ expected.add("org/jboss/test/");
+ expected.add("org/jboss/test/osgi/");
+ expected.add("org/jboss/test/osgi/vfs30/");
+ expected.add("org/jboss/test/osgi/vfs30/bundle/");
+ expected.add("org/jboss/test/osgi/vfs30/bundle/SimpleActivator.class");
+ expected.add("META-INF/");
+ expected.add("META-INF/MANIFEST.MF");
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testFindEntries() throws Exception
+ {
+ Set<String> actual = new HashSet<String>();
+ Enumeration<URL> en = virtualFile.findEntries("/", null, true);
+ while(en.hasMoreElements())
+ actual.add(en.nextElement().toExternalForm());
+
+ Set<String> expected = new HashSet<String>();
+ expected.add(virtualFile.toURL() +
"org/jboss/test/osgi/vfs30/bundle/SimpleActivator.class");
+ expected.add(virtualFile.toURL() + "META-INF/MANIFEST.MF");
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testURLStreamAccess() throws Exception
+ {
+ URL fileURL = virtualFile.getFileURL();
+ URLConnection con = fileURL.openConnection();
+ con.connect();
+ InputStream is = con.getInputStream();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ VFSUtils.copyStream(is, baos);
+ int actualLength = baos.toByteArray().length;
+ assertEquals(fileLength, actualLength);
+ }
+}
\ No newline at end of file
Added:
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/osgi/vfs30/bundle/SimpleActivator.java
===================================================================
---
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/osgi/vfs30/bundle/SimpleActivator.java
(rev 0)
+++
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/osgi/vfs30/bundle/SimpleActivator.java 2010-03-11
11:27:39 UTC (rev 102276)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.vfs30.bundle;
+
+//$Id: SimpleActivator.java 101150 2010-02-19 10:50:46Z thomas.diesler(a)jboss.com $
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * A simple BundleActivator
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 24-Apr-2009
+ */
+public class SimpleActivator implements BundleActivator
+{
+ public void start(BundleContext context)
+ {
+ }
+
+ public void stop(BundleContext context)
+ {
+ }
+}
\ No newline at end of file
Added:
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/resources/simple/META-INF/MANIFEST.MF
===================================================================
---
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/resources/simple/META-INF/MANIFEST.MF
(rev 0)
+++
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/resources/simple/META-INF/MANIFEST.MF 2010-03-11
11:27:39 UTC (rev 102276)
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: example-simple
+Bundle-Activator: org.jboss.test.osgi.vfs30.bundle.SimpleActivator
+Import-Package: org.osgi.framework