You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pa...@apache.org on 2020/01/23 20:17:18 UTC

svn commit: r1873072 - in /felix/sandbox/pauls/connect: ./ src/main/java/org/apache/felix/framework/ src/main/java/org/apache/felix/framework/cache/ src/main/java/org/osgi/framework/ src/main/java/org/osgi/framework/connect/ src/main/java/org/osgi/fram...

Author: pauls
Date: Thu Jan 23 20:17:17 2020
New Revision: 1873072

URL: http://svn.apache.org/viewvc?rev=1873072&view=rev
Log:
Update to latest connect interfaces

Modified:
    felix/sandbox/pauls/connect/pom.xml
    felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/BundleImpl.java
    felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
    felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
    felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/Felix.java
    felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/FrameworkFactory.java
    felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
    felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/BundleCache.java
    felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/ConnectContentContent.java
    felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/ConnectRevision.java
    felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/JarContent.java
    felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/FrameworkUtil.java
    felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/connect/ConnectContent.java
    felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/connect/ConnectModule.java
    felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/connect/FrameworkUtilHelper.java
    felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/launch/Framework.java
    felix/sandbox/pauls/connect/src/main/resources/default.properties
    felix/sandbox/pauls/connect/src/test/java/org/apache/felix/framework/ConnectTest.java

Modified: felix/sandbox/pauls/connect/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/pom.xml?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/pom.xml (original)
+++ felix/sandbox/pauls/connect/pom.xml Thu Jan 23 20:17:17 2020
@@ -30,7 +30,7 @@
   <version>6.1.0-CONNECT</version>
   <properties>
     <dollar>$</dollar>
-    <felix.java.version>6</felix.java.version>
+    <felix.java.version>8</felix.java.version>
   </properties>
   <scm>
       <connection>scm:svn:http://svn.apache.org/repos/asf/felix/trunk/framework</connection>
@@ -89,7 +89,7 @@
               <excludes>
                   <exclude>src/main/appended-resources/**</exclude>
                   <exclude>src/**/packageinfo</exclude>
-                  <exclude>src/main/resources/META-INF/services/org.osgi.framework.launch.FrameworkFactory</exclude>
+                  <exclude>src/main/resources/META-INF/services/*</exclude>
                   <exclude>src/main/resources/org/apache/felix/framework/Felix.properties</exclude>
               </excludes>
             </configuration>
@@ -143,7 +143,7 @@
     <dependency>
         <groupId>org.ow2.asm</groupId>
         <artifactId>asm-all</artifactId>
-        <version>4.2</version>
+        <version>5.2</version>
         <scope>test</scope>
     </dependency>
     <dependency>

Modified: felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/BundleImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/BundleImpl.java?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/BundleImpl.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/BundleImpl.java Thu Jan 23 20:17:17 2020
@@ -1401,9 +1401,4 @@ class BundleImpl implements Bundle, Bund
     {
         return m_context;
     }
-
-    public ConnectModule getConnectModule()
-    {
-        return m_archive.getConnectModule();
-    }
 }

Modified: felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java Thu Jan 23 20:17:17 2020
@@ -151,11 +151,6 @@ public class BundleRevisionImpl implemen
         return m_declaredActivationPolicy;
     }
 
-    ConnectModule getConnectModule()
-    {
-        return m_bundle.getConnectModule();
-    }
-
     boolean isActivationTrigger(String pkgName)
     {
         if ((m_activationIncludes == null) && (m_activationExcludes == null))

Modified: felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/BundleWiringImpl.java?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/BundleWiringImpl.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/BundleWiringImpl.java Thu Jan 23 20:17:17 2020
@@ -18,6 +18,7 @@
  */
 package org.apache.felix.framework;
 
+import org.apache.felix.framework.cache.ConnectContentContent;
 import org.apache.felix.framework.cache.Content;
 import org.apache.felix.framework.capabilityset.SimpleFilter;
 import org.apache.felix.framework.resolver.ResourceNotFoundException;
@@ -37,6 +38,7 @@ import org.osgi.framework.Constants;
 import org.osgi.framework.FrameworkEvent;
 import org.osgi.framework.PackagePermission;
 import org.osgi.framework.ServiceReference;
+import org.osgi.framework.connect.ConnectContent;
 import org.osgi.framework.connect.ConnectModule;
 import org.osgi.framework.hooks.weaving.WeavingException;
 import org.osgi.framework.hooks.weaving.WeavingHook;
@@ -728,10 +730,9 @@ public class BundleWiringImpl implements
         // is not disposed.
         if (!m_isDisposed && (m_classLoader == null))
         {
-            ConnectModule connectModule = m_revision.getConnectModule();
-            if (connectModule != null)
+            if (m_revision.getContent() instanceof ConnectContentContent)
             {
-                m_classLoader = connectModule.getClassLoader();
+                m_classLoader = ((ConnectContentContent) m_revision.getContent()).getClassLoader();
             }
 
             if (m_classLoader == null)

Modified: felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/Felix.java?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/Felix.java Thu Jan 23 20:17:17 2020
@@ -58,7 +58,7 @@ import org.osgi.framework.ServicePermiss
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.Version;
-import org.osgi.framework.connect.ConnectFactory;
+import org.osgi.framework.connect.ConnectFramework;
 import org.osgi.framework.launch.Framework;
 import org.osgi.framework.namespace.HostNamespace;
 import org.osgi.framework.startlevel.FrameworkStartLevel;
@@ -214,7 +214,7 @@ public class Felix extends BundleImpl im
     // Do we need to consult the default java security policy if no security provider is present?
     private volatile boolean m_securityDefaultPolicy;
 
-    private volatile ConnectFactory m_connectFactory;
+    private final ConnectFramework m_connectFramework;
 
     /**
      * <p>
@@ -354,6 +354,11 @@ public class Felix extends BundleImpl im
     **/
     public Felix(Map configMap)
     {
+        this(configMap, null);
+    }
+
+    public Felix(Map configMap, ConnectFramework connectFramework)
+    {
         super();
         // Copy the configuration properties; convert keys to strings.
         m_configMutableMap = new StringMap();
@@ -463,6 +468,8 @@ public class Felix extends BundleImpl im
         m_fwkWiring = new FrameworkWiringImpl(this, m_registry);
         // Create framework start level object.
         m_fwkStartLevel = new FrameworkStartLevelImpl(this, m_registry);
+
+        m_connectFramework = connectFramework;
     }
 
     Logger getLogger()
@@ -637,24 +644,18 @@ public class Felix extends BundleImpl im
         return true;
     }
 
-
     @Override
     public void init() throws BundleException
     {
-        init((FrameworkListener[]) null);
+        init(null);
     }
+
     /**
      * @see org.osgi.framework.launch.Framework#init(org.osgi.framework.FrameworkListener[])
      */
     @Override
     public void init(final FrameworkListener... listeners) throws BundleException
     {
-        init(null, null);
-    }
-
-    @Override
-    public void init(final ConnectFactory connectFactory, FrameworkListener... listeners) throws BundleException
-    {
         // The system bundle can only be initialized if it currently isn't started.
         acquireBundleLock(this,
             Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE);
@@ -692,8 +693,6 @@ public class Felix extends BundleImpl im
                     }
                 }
 
-                m_connectFactory = connectFactory;
-
                 // Generate a framework UUID.
                 // Spec says we get a new UUID for each invocation of init().
                 m_configMutableMap.put(
@@ -785,7 +784,6 @@ public class Felix extends BundleImpl im
                         "Unresolved constraint in System Bundle:"
                         + ex.getUnresolvedRequirements());
                 }
-
                 // Reload the cached bundles before creating and starting the
                 // system bundle, since we want all cached bundles to be reloaded
                 // when we activate the system bundle and any subsequent system
@@ -795,7 +793,13 @@ public class Felix extends BundleImpl im
                 // First get cached bundle identifiers.
                 try
                 {
-                    archives = m_cache.getArchives(m_connectFactory);
+
+                    if (m_connectFramework != null)
+                    {
+                        m_connectFramework.initialize(m_cache.getSystemBundleDataFile(""), (Map) m_configMap);
+                        m_connectFramework.createBundleActivator().ifPresent(m_activatorList::add);
+                    }
+                    archives = m_cache.getArchives(m_connectFramework);
                 }
                 catch (Exception ex)
                 {
@@ -3235,7 +3239,7 @@ public class Felix extends BundleImpl im
                 try
                 {
                     // Add the bundle to the cache.
-                    ba = m_cache.create(id, getInitialBundleStartLevel(), location, is, m_connectFactory);
+                    ba = m_cache.create(id, getInitialBundleStartLevel(), location, is, m_connectFramework);
                 }
                 catch (Exception ex)
                 {

Modified: felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/FrameworkFactory.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/FrameworkFactory.java?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/FrameworkFactory.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/FrameworkFactory.java Thu Jan 23 20:17:17 2020
@@ -19,12 +19,20 @@
 package org.apache.felix.framework;
 
 import java.util.Map;
+
+import org.osgi.framework.connect.ConnectFramework;
 import org.osgi.framework.launch.Framework;
 
-public class FrameworkFactory implements org.osgi.framework.launch.FrameworkFactory
+public class FrameworkFactory implements org.osgi.framework.launch.FrameworkFactory, org.osgi.framework.connect.ConnectFrameworkFactory
 {
     public Framework newFramework(Map configuration)
     {
         return new Felix(configuration);
     }
+
+    @Override
+    public Framework newFramework(Map<String, String> configuration, ConnectFramework connectFramework)
+    {
+        return new Felix(configuration, connectFramework);
+    }
 }
\ No newline at end of file

Modified: felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/BundleArchive.java?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/BundleArchive.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/BundleArchive.java Thu Jan 23 20:17:17 2020
@@ -21,13 +21,15 @@ package org.apache.felix.framework.cache
 import java.io.*;
 
 import java.util.Map;
+import java.util.Optional;
 import java.util.SortedMap;
 import java.util.TreeMap;
 import org.apache.felix.framework.Logger;
 import org.apache.felix.framework.util.WeakZipFileFactory;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
-import org.osgi.framework.connect.ConnectFactory;
+import org.osgi.framework.connect.ConnectFramework;
 import org.osgi.framework.connect.ConnectModule;
 
 /**
@@ -125,7 +127,7 @@ public class BundleArchive
      * @param is input stream from which to read the bundle content.
      * @throws Exception if any error occurs.
     **/
-    public BundleArchive(Logger logger, Map configMap, WeakZipFileFactory zipFactory, ConnectFactory
+    public BundleArchive(Logger logger, Map configMap, WeakZipFileFactory zipFactory, ConnectFramework
         connectFactory,
         File archiveRootDir, long id, int startLevel, String location, InputStream is)
         throws Exception
@@ -146,14 +148,16 @@ public class BundleArchive
         m_lastModified = System.currentTimeMillis();
         m_refreshCount = 0;
 
-        if (connectFactory != null && connectFactory.handles(m_originalLocation))
-        {
-            m_module = connectFactory.getModule(m_originalLocation);
-        }
-        else
-        {
-            m_module = null;
-        }
+        m_module = Optional.ofNullable(connectFactory).flatMap(factory -> {
+            try
+            {
+                return connectFactory.getModule(m_originalLocation);
+            }
+            catch (BundleException e)
+            {
+                throw new IllegalStateException(e);
+            }
+        }).orElse(null);
 
         // Save state.
         initialize();
@@ -174,7 +178,7 @@ public class BundleArchive
      * @param configMap configMap for BundleArchive
      * @throws Exception if any error occurs.
     **/
-    public BundleArchive(Logger logger, Map configMap, WeakZipFileFactory zipFactory, ConnectFactory connectFactory,
+    public BundleArchive(Logger logger, Map configMap, WeakZipFileFactory zipFactory, ConnectFramework connectFactory,
         File archiveRootDir)
         throws Exception
     {
@@ -226,24 +230,21 @@ public class BundleArchive
         m_revisions.remove(currentRevNum);
 
         String location = getRevisionLocation(currentRevNum);
-        if (connectFactory != null && connectFactory.handles(location))
-        {
-            m_module = connectFactory.getModule(location);
-        }
-        else
-        {
-            m_module = null;
-        }
+        m_module = Optional.ofNullable(connectFactory).flatMap(factory -> {
+            try
+            {
+                return connectFactory.getModule(location);
+            }
+            catch (BundleException e)
+            {
+                throw new IllegalStateException(e);
+            }
+        }).orElse(null);
 
         // Add the revision object for the most recent revision.
         reviseInternal(true, currentRevNum, location, null);
     }
 
-    public ConnectModule getConnectModule()
-    {
-        return m_module;
-    }
-
     /**
      * <p>
      * Returns the bundle identifier associated with this archive.

Modified: felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/BundleCache.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/BundleCache.java?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/BundleCache.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/BundleCache.java Thu Jan 23 20:17:17 2020
@@ -22,8 +22,7 @@ import org.apache.felix.framework.Logger
 import org.apache.felix.framework.util.SecureAction;
 import org.apache.felix.framework.util.WeakZipFileFactory;
 import org.osgi.framework.Constants;
-import org.osgi.framework.connect.ConnectFactory;
-import org.osgi.framework.connect.ConnectModule;
+import org.osgi.framework.connect.ConnectFramework;
 
 import java.io.File;
 import java.io.FileOutputStream;
@@ -400,7 +399,7 @@ public class BundleCache
         deleteDirectoryTree(cacheDir);
     }
 
-    public BundleArchive[] getArchives(ConnectFactory connectFactory)
+    public BundleArchive[] getArchives(ConnectFramework connectFactory)
         throws Exception
     {
         // Get buffer size value.
@@ -449,7 +448,7 @@ public class BundleCache
             archiveList.toArray(new BundleArchive[archiveList.size()]);
     }
 
-    public BundleArchive create(long id, int startLevel, String location, InputStream is, ConnectFactory connectFactory)
+    public BundleArchive create(long id, int startLevel, String location, InputStream is, ConnectFramework connectFactory)
         throws Exception
     {
         File cacheDir = determineCacheDir(m_configMap);

Modified: felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/ConnectContentContent.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/ConnectContentContent.java?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/ConnectContentContent.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/ConnectContentContent.java Thu Jan 23 20:17:17 2020
@@ -22,11 +22,13 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Enumeration;
+import java.util.Iterator;
 
 import org.osgi.framework.connect.ConnectContent;
 
 public class ConnectContentContent implements Content
 {
+
     private final ConnectContent m_content;
 
     public ConnectContentContent(ConnectContent content)
@@ -37,29 +39,42 @@ public class ConnectContentContent imple
     @Override
     public void close()
     {
-        // TODO: close it?
-    }
-
-    @Override
-    public boolean hasEntry(String name)
-    {
         try
         {
-            return m_content.hasEntry(name);
+            m_content.close();
         }
         catch (IOException e)
         {
             e.printStackTrace();
-            return false;
         }
     }
 
     @Override
+    public boolean hasEntry(String name)
+    {
+        return m_content.getEntry(name).isPresent();
+    }
+
+    @Override
     public Enumeration<String> getEntries()
     {
         try
         {
-            return m_content.getEntries();
+            Iterator<String> entries = m_content.getEntries().iterator();
+            return new Enumeration<String>()
+            {
+                @Override
+                public boolean hasMoreElements()
+                {
+                    return entries.hasNext();
+                }
+
+                @Override
+                public String nextElement()
+                {
+                    return entries.next();
+                }
+            };
         }
         catch (IOException e)
         {
@@ -73,7 +88,7 @@ public class ConnectContentContent imple
     {
         try
         {
-            return m_content.getEntryAsBytes(name);
+            return m_content.getEntry(name).get().getBytes();
         }
         catch (Exception e)
         {
@@ -88,7 +103,7 @@ public class ConnectContentContent imple
     {
         try
         {
-            return m_content.getEntryAsStream(name);
+            return m_content.getEntry(name).get().getInputStream();
         }
         catch (Exception iae)
         {
@@ -97,46 +112,28 @@ public class ConnectContentContent imple
         }
     }
 
+    public ClassLoader getClassLoader() {
+        return m_content.getClassLoader().orElse(null);
+    }
+
     @Override
     public Content getEntryAsContent(String name)
     {
-        try
-        {
-            // TODO: handle null case
-            return new ConnectContentContent(m_content.getEntryAsContent(name));
-        }
-        catch (Exception ex)
-        {
-            ex.printStackTrace();
-            return null;
-        }
+        // TODO: Connect
+        return null;
     }
 
     @Override
-    public String getEntryAsNativeLibrary(String name)
+    public String getEntryAsNativeLibrary(String entryName)
     {
-        try
-        {
-            return m_content.getEntryAsNativeLibrary(name);
-        }
-        catch (IOException e)
-        {
-            // TODO: log this or something
-            e.printStackTrace();
-            return null;
-        }
+        // TODO: Connect
+        return null;
     }
 
     @Override
     public URL getEntryAsURL(String name)
     {
-        try
-        {
-            return m_content.getEntryAsURL(name);
-        }
-        catch (Exception ex)
-        {
-            return null;
-        }
+        // TODO: Connect
+        return null;
     }
 }

Modified: felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/ConnectRevision.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/ConnectRevision.java?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/ConnectRevision.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/ConnectRevision.java Thu Jan 23 20:17:17 2020
@@ -21,20 +21,23 @@ package org.apache.felix.framework.cache
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
+import java.io.UncheckedIOException;
 import java.util.Map;
+import java.util.Optional;
 
 import org.apache.felix.framework.Logger;
 import org.apache.felix.framework.util.StringMap;
+import org.osgi.framework.connect.ConnectContent;
 import org.osgi.framework.connect.ConnectModule;
 
 public class ConnectRevision extends BundleArchiveRevision
 {
-    private final ConnectModule m_module;
+    private final ConnectContent m_module;
 
     public ConnectRevision(Logger logger, Map configMap, File revisionRootDir, String location, ConnectModule module) throws Exception
     {
         super(logger, configMap, revisionRootDir, location);
-        m_module = module;
+        m_module = module.getContent();
         // If the revision directory exists, then we don't
         // need to initialize since it has already been done.
         if (BundleCache.getSecureAction().fileExists(getRevisionRootDir()))
@@ -56,22 +59,22 @@ public class ConnectRevision extends Bun
     @Override
     public Map<String, Object> getManifestHeader() throws Exception
     {
-        Map headers = m_module.getHeaders();
-        if (headers == null)
-        {
-            if (m_module.getContent().hasEntry("META-INF/MANIFEST.MF"))
-            {
-                byte[] manifest = m_module.getContent().getEntryAsBytes("META-INF/MANIFEST.MF");
-                headers = BundleCache.getMainAttributes(new StringMap(), new ByteArrayInputStream(manifest), manifest.length);
-            }
-        }
-        return headers;
+        return (Map) m_module.getHeaders().orElseGet(() -> m_module.getEntry("META-INF/MANIFEST.MF").flatMap(entry -> {
+                try
+                {
+                    return Optional.of((Map<String, String>) (Map) BundleCache.getMainAttributes(new StringMap(), entry.getInputStream(), entry.getContentLength()));
+                }
+                catch (Exception e)
+                {
+                    throw new IllegalStateException(e);
+                }
+            }).orElse(null));
     }
 
     @Override
     public Content getContent() throws Exception
     {
-        return new ConnectContentContent(m_module.getContent());
+        return new ConnectContentContent(m_module);
     }
 
     @Override

Modified: felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/JarContent.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/JarContent.java?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/JarContent.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/cache/JarContent.java Thu Jan 23 20:17:17 2020
@@ -398,7 +398,7 @@ public class JarContent implements Conte
         return m_file;
     }
 
-    private static class DevNullRunnable implements Runnable
+    static class DevNullRunnable implements Runnable
     {
         private final InputStream m_in;
 

Modified: felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/FrameworkUtil.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/FrameworkUtil.java?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/FrameworkUtil.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/FrameworkUtil.java Thu Jan 23 20:17:17 2020
@@ -26,11 +26,13 @@ import java.security.PrivilegedAction;
 import java.util.AbstractMap;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.ServiceLoader;
 import java.util.Set;
 
@@ -197,35 +199,67 @@ public class FrameworkUtil {
 	}
 
 	/**
-	 * Return a {@code Bundle} for the specified bundle class. The returned
-	 * {@code Bundle} is the bundle associated with the bundle class loader
-	 * which defined the specified class.
-	 * 
-	 * @param classFromBundle A class defined by a bundle class loader.
+	 * Return a {@code Bundle} for the specified bundle class loader.
+	 *
+	 * @param bundleClassLoader A bundle class loader.
+	 * @return An Optional containing {@code Bundle} for the specified bundle
+	 *         class loader or an empty Optional if the specified class loader
+	 *         is not associated with a specific bundle.
+	 * @since 1.10
+	 */
+	public static Optional<Bundle> getBundle(ClassLoader bundleClassLoader) {
+		return Optional
+			.ofNullable((bundleClassLoader instanceof BundleReference)
+				? ((BundleReference) bundleClassLoader).getBundle()
+				: null);
+	}
+
+	/**
+	 * Return a {@code Bundle} for the specified bundle class.
+	 *
+	 * @param classFromBundle A class defined by a bundle.
 	 * @return A {@code Bundle} for the specified bundle class or {@code null}
-	 *         if the specified class was not defined by a bundle class loader.
+	 *         if the specified class was not defined by a bundle.
 	 * @since 1.5
 	 */
-	public static Bundle getBundle(final Class<?> classFromBundle) {
+	public static Bundle getBundle(Class< ? > classFromBundle) {
 		// We use doPriv since the caller may not have permission
 		// to call getClassLoader.
-		Object cl = AccessController.doPrivileged(new PrivilegedAction<Object>() {
-			@Override
-			public Object run() {
-				return classFromBundle.getClassLoader();
-			}
-		});
+		Optional<ClassLoader> cl = Optional
+			.ofNullable(AccessController.doPrivileged(
+				(PrivilegedAction<ClassLoader>) () -> classFromBundle
+					.getClassLoader()));
+
+		return cl.flatMap(FrameworkUtil::getBundle)
+			.orElseGet(() -> helpers.stream()
+				.map(helper -> helper.getBundle(classFromBundle))
+				.filter(Optional::isPresent)
+				.map(Optional::get)
+				.findFirst()
+				.orElse(null));
+	}
 
-		if (cl instanceof BundleReference) {
-			return ((BundleReference) cl).getBundle();
-		}
-		else {
-			Iterator<FrameworkUtilHelper> iter = ServiceLoader.load(FrameworkUtilHelper.class).iterator();
-			if (iter.hasNext()) {
-				return iter.next().getBundle(classFromBundle);
+	private final static List<FrameworkUtilHelper> helpers;
+	static {
+		List<FrameworkUtilHelper> l = new ArrayList<>();
+		try {
+			ServiceLoader<FrameworkUtilHelper> helperLoader = AccessController
+				.doPrivileged(
+					(PrivilegedAction<ServiceLoader<FrameworkUtilHelper>>) () -> ServiceLoader
+						.load(FrameworkUtilHelper.class,
+							FrameworkUtilHelper.class
+								.getClassLoader()));
+			helperLoader.forEach(l::add);
+		} catch (Throwable error) {
+			// try hard not to fail static <clinit>
+			try {
+				Thread t = Thread.currentThread();
+				t.getUncaughtExceptionHandler().uncaughtException(t, error);
+			} catch (Throwable ignored) {
+				// we ignore this
 			}
 		}
-		return null;
+		helpers = Collections.unmodifiableList(l);
 	}
 
 	/**

Modified: felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/connect/ConnectContent.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/connect/ConnectContent.java?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/connect/ConnectContent.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/connect/ConnectContent.java Thu Jan 23 20:17:17 2020
@@ -1,58 +1,195 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
+ * Copyright (c) OSGi Alliance (2019). All Rights Reserved.
  *
- *   http://www.apache.org/licenses/LICENSE-2.0
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 package org.osgi.framework.connect;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URL;
-import java.util.Enumeration;
+import java.util.Map;
+import java.util.Optional;
 
-public interface ConnectContent
-{
-    boolean hasEntry(String name) throws IOException;
-
-    Enumeration<String> getEntries() throws IOException;
-
-    /**
-     * @throws IllegalArgumentException if no such entry
-     */
-    byte[] getEntryAsBytes(String name) throws IllegalArgumentException, IOException;
-
-    /**
-     * @throws IllegalArgumentException if no such entry
-     */
-    InputStream getEntryAsStream(String name) throws IllegalArgumentException, IOException;
-
-    /**
-     * @return null if framework should handle
-     * @throws IllegalArgumentException if no such entry
-     */
-    ConnectContent getEntryAsContent(String name) throws IllegalArgumentException, IOException;
-
-    /**
-     * @return null if framework should handle
-     * @throws IllegalArgumentException if no such entry
-     */
-    String getEntryAsNativeLibrary(String name) throws IllegalArgumentException, IOException;
-
-    /**
-     * @throws IllegalArgumentException if no such entry
-     */
-    URL getEntryAsURL(String name) throws IllegalArgumentException, IOException;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.framework.wiring.BundleRevisions;
+
+/**
+ * A connect content provides a {@link Framework framework} access to the
+ * content of a connect {@link ConnectModule module}. A framework may
+ * {@link #open() open} and {@link #close() close} the content for a connect
+ * module multiple times while the connect content is in use by the framework
+ * instance. The framework must close the connect content once the connect
+ * content is no longer used as the content of a current bundle revision or an
+ * in use bundle revision.
+ * 
+ * @see BundleRevisions
+ * @ThreadSafe
+ * @author $Id: ce8ae5d57f40d8cca91e06184cd732c3c0953f6a $
+ */
+public interface ConnectContent {
+	/**
+	 * The {@code osgi.identity}
+	 * {@link IdentityNamespace#CAPABILITY_TAGS_ATTRIBUTE tags} attribute value
+	 * used by the framework to tag connect bundle revisions.
+	 */
+	public static final String TAG_OSGI_CONNECT = "osgi.connect";
+
+	/**
+	 * Returns this connect content Manifest headers and values. The
+	 * {@link Optional#empty() empty} value is returned if the framework should
+	 * handle parsing the Manifest of the content itself.
+	 * 
+	 * @return This connect content Manifest headers and values.
+	 * @throws IllegalStateException if the connect content has been closed
+	 */
+	Optional<Map<String,String>> getHeaders();
+
+	/**
+	 * Returns an iterable with all the entry names available in this
+	 * ConnectContent
+	 * 
+	 * @return the entry names
+	 * @throws IOException if an error occurs reading the ConnectContent
+	 * @throws IllegalStateException if the connect content has been closed
+	 */
+	Iterable<String> getEntries() throws IOException;
+
+	/**
+	 * Returns the connect entry for the specified path name in this content.
+	 * The {@link Optional#empty() empty} value is returned if an entry with the
+	 * specified path name does not exist. The path must not start with a
+	 * &quot;/&quot; and is relative to the root of this content.
+	 * 
+	 * @param path the path name of the entry
+	 * @return the connect entry, or {@link Optional#empty() empty} if not
+	 *         found.
+	 * @throws IllegalStateException if the connect content has been closed
+	 */
+	Optional<ConnectEntry> getEntry(String path);
+
+	/**
+	 * Returns a class loader for this connect content. The
+	 * {@link Optional#empty() empty} value is returned if the framework should
+	 * handle creating a class loader for the bundle revision associated with
+	 * this connect content.
+	 * <p>
+	 * This method is called by the framework for {@link Bundle#RESOLVED
+	 * resolved} bundles only and will be called at most once while a bundle is
+	 * resolved. If a bundle associated with a connect module is refreshed and
+	 * resolved again the framework will ask the content for the class loader
+	 * again. This allows for a connect content to reuse or create a new class
+	 * loader each time the bundle revision is resolved.
+	 * 
+	 * @return a class loader for the module.
+	 */
+	Optional<ClassLoader> getClassLoader();
+
+	/**
+	 * Opens this connect content. The framework will open the content when it
+	 * needs to access the content for a bundle revision associated with the
+	 * connect content. The framework may lazily open the content until the
+	 * first request is made to access the bundle revision content.
+	 * 
+	 * @return a reference to this object
+	 * @throws IOException if an error occurred opening the content
+	 */
+	ConnectContent open() throws IOException;
+
+	/**
+	 * Closes this connect content.
+	 * 
+	 * @return a reference to this object
+	 * @throws IOException if an error occurred closing the connect content
+	 */
+	ConnectContent close() throws IOException;
+
+	/**
+	 * Represents the entry of a connect module
+	 */
+	public interface ConnectEntry {
+		/**
+		 * Returns the path name of the entry
+		 * 
+		 * @return the path name of the entry
+		 */
+		String getName();
+
+		/**
+		 * Returns the size of the entry. The value {@code -1} is returned if
+		 * the content length is not known.
+		 * 
+		 * @return the size of the entry, or {@code -1} if the content length is
+		 *         not known.
+		 */
+		public long getContentLength();
+
+		/**
+		 * Returns the last modification time of the entry
+		 * 
+		 * @return the last modification time of the entry
+		 */
+		public long getLastModified();
+
+		/**
+		 * Returns the content of the entry as a byte array.
+		 * 
+		 * @return the content bytes
+		 * @throws IOException if an error occurs reading the content
+		 */
+		default byte[] getBytes() throws IOException {
+			long longLength = getContentLength();
+			if (longLength > Integer.MAX_VALUE - 8) {
+				throw new IOException(
+						"Entry is to big to fit into a byte[]: " + getName());
+			}
+
+			try (InputStream in = getInputStream()) {
+				int length = (int) longLength;
+				if (length > 0) {
+					int bytesread = 0;
+					byte[] result = new byte[length];
+					int readcount = 0;
+					while (bytesread < length) {
+						readcount = in.read(result, bytesread,
+								length - bytesread);
+						bytesread += readcount;
+						if (readcount <= 0) {
+							break;
+						}
+					}
+					return result;
+				} else {
+					ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+					int nRead;
+					byte[] data = new byte[1024];
+					while ((nRead = in.read(data, 0, data.length)) > 0) {
+						buffer.write(data, 0, nRead);
+					}
+					buffer.flush();
+					return buffer.toByteArray();
+				}
+			}
+		}
+
+		/**
+		 * Returns the content of the entry as an input stream.
+		 * 
+		 * @return the content input stream
+		 * @throws IOException if an error occurs reading the content
+		 */
+		InputStream getInputStream() throws IOException;
+	}
 }

Modified: felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/connect/ConnectModule.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/connect/ConnectModule.java?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/connect/ConnectModule.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/connect/ConnectModule.java Thu Jan 23 20:17:17 2020
@@ -1,43 +1,42 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
+ * Copyright (c) OSGi Alliance (2019). All Rights Reserved.
  *
- *   http://www.apache.org/licenses/LICENSE-2.0
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 package org.osgi.framework.connect;
 
 import java.io.IOException;
-import java.util.Map;
-
-public interface ConnectModule
-{
-    /**
-     *
-     * @return the content
-     */
-    ConnectContent getContent() throws IOException;
 
-    /**
-     *
-     * @return null if framework should handle
-     */
-    ClassLoader getClassLoader();
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.wiring.BundleRevision;
 
-    /**
-     *
-     * @return null if framework should handle
-     */
-    Map<String, String> getHeaders();
+/**
+ * A connect module instance is used by a {@link Framework framework} to load
+ * content for a bundle revision installed in the framework.
+ * 
+ * @ThreadSafe
+ * @author $Id: 394a6872eb27589cc914095457cf3f4d7d82f6bf $
+ */
+public interface ConnectModule {
+	/**
+	 * Returns the current content of this connect module. The framework will
+	 * get the content when it needs to access the content for the current
+	 * {@link BundleRevision bundle revision} associated with this connect
+	 * module. The framework may lazily open the content until the first request
+	 * is made to access the bundle content.
+	 * 
+	 * @return the current content of this connect module
+	 * @throws IOException if an error occurred getting the content
+	 */
+	ConnectContent getContent() throws IOException;
 }

Modified: felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/connect/FrameworkUtilHelper.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/connect/FrameworkUtilHelper.java?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/connect/FrameworkUtilHelper.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/connect/FrameworkUtilHelper.java Thu Jan 23 20:17:17 2020
@@ -1,26 +1,43 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
+ * Copyright (c) OSGi Alliance (2019). All Rights Reserved.
  *
- *   http://www.apache.org/licenses/LICENSE-2.0
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
+
 package org.osgi.framework.connect;
 
+import java.util.Optional;
+
 import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
 
-public interface FrameworkUtilHelper
-{
-    Bundle getBundle(Class clazz);
+/**
+ * A helper for the {@link FrameworkUtil} class. This helper provides
+ * alternative implementations for methods on {@link FrameworkUtil}.
+ */
+public interface FrameworkUtilHelper {
+	/**
+	 * Return a {@code Bundle} associated with the specified class.
+	 * <p>
+	 * This helper method is called by {@link FrameworkUtil#getBundle(Class)} if
+	 * the standard implementation of {@code FrameworkUtil} cannot find the
+	 * bundle.
+	 * 
+	 * @param classFromBundle A class associated with a bundle
+	 * @return An Optional containing a {@code Bundle} for the specified class
+	 *         or an empty Optional if the specified class is not from a bundle.
+	 */
+	default Optional<Bundle> getBundle(Class< ? > classFromBundle) {
+		return Optional.empty();
+	}
 }

Modified: felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/launch/Framework.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/launch/Framework.java?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/launch/Framework.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/osgi/framework/launch/Framework.java Thu Jan 23 20:17:17 2020
@@ -25,7 +25,6 @@ import org.osgi.framework.BundleExceptio
 import org.osgi.framework.Constants;
 import org.osgi.framework.FrameworkEvent;
 import org.osgi.framework.FrameworkListener;
-import org.osgi.framework.connect.ConnectFactory;
 
 /**
  * A Framework instance. A Framework is also known as a System Bundle.
@@ -107,8 +106,6 @@ public interface Framework extends Bundl
 	 */
 	void init(FrameworkListener... listeners) throws BundleException;
 
-	void init(ConnectFactory connectFactory, FrameworkListener... listeners) throws BundleException;
-
 	/**
 	 * Wait until this Framework has completely stopped. The {@code stop} and
 	 * {@code update} methods on a Framework performs an asynchronous stop of

Modified: felix/sandbox/pauls/connect/src/main/resources/default.properties
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/resources/default.properties?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/resources/default.properties (original)
+++ felix/sandbox/pauls/connect/src/main/resources/default.properties Thu Jan 23 20:17:17 2020
@@ -100,7 +100,7 @@ ee-1.6=JavaSE-1.6,J2SE-1.5,J2SE-1.4,J2SE
 
 # Default packages exported by system bundle.
 org.osgi.framework.system.packages=\
- org.osgi.framework;version="1.9", \
+ org.osgi.framework;version="1.10", \
  org.osgi.framework.dto;version="1.8";uses:="org.osgi.dto", \
  org.osgi.framework.hooks.bundle;version="1.1";uses:="org.osgi.framework", \
  org.osgi.framework.hooks.resolver;version="1.0";uses:="org.osgi.framework.wiring", \
@@ -119,7 +119,8 @@ org.osgi.framework.system.packages=\
  org.osgi.service.url;version="1.0", \
  org.osgi.service.resolver;version="1.1";uses:="org.osgi.resource", \
  org.osgi.util.tracker;version="1.5.2";uses:="org.osgi.framework", \
- org.osgi.dto;version="1.1" \
+ org.osgi.dto;version="1.1", \
+ org.osgi.framework.connect;version="1.0.0" \
  ${dollar}{jre-${dollar}{felix.detect.java.specification.version}} \
  ${dollar}{jre-${dollar}{felix.detect.jpms}}
 
@@ -374,4 +375,4 @@ jre-1.8= \
  java.util.function;version="${dollar}{felix.detect.java.version}", \
  java.util.stream;version="${dollar}{felix.detect.java.version}", \
  javax.crypto;uses:="javax.crypto.spec,javax.security.auth";version="${dollar}{felix.detect.java.version}", \
- javax.lang.model;uses:="javax.lang.model.element";version="${dollar}{felix.detect.java.version}"
\ No newline at end of file
+ javax.lang.model;uses:="javax.lang.model.element";version="${dollar}{felix.detect.java.version}"

Modified: felix/sandbox/pauls/connect/src/test/java/org/apache/felix/framework/ConnectTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/test/java/org/apache/felix/framework/ConnectTest.java?rev=1873072&r1=1873071&r2=1873072&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/test/java/org/apache/felix/framework/ConnectTest.java (original)
+++ felix/sandbox/pauls/connect/src/test/java/org/apache/felix/framework/ConnectTest.java Thu Jan 23 20:17:17 2020
@@ -23,12 +23,10 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URL;
 import java.util.Arrays;
-import java.util.Collections;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
@@ -36,15 +34,17 @@ import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
 import java.util.zip.ZipEntry;
 
+
 import junit.framework.TestCase;
 import org.apache.felix.framework.util.StringMap;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
 import org.osgi.framework.Constants;
 import org.osgi.framework.FrameworkEvent;
 import org.osgi.framework.FrameworkListener;
 import org.osgi.framework.Version;
 import org.osgi.framework.connect.ConnectContent;
-import org.osgi.framework.connect.ConnectFactory;
+import org.osgi.framework.connect.ConnectFramework;
 import org.osgi.framework.connect.ConnectModule;
 import org.osgi.framework.launch.Framework;
 import org.osgi.framework.namespace.PackageNamespace;
@@ -67,23 +67,22 @@ public class ConnectTest extends TestCas
 
 
         FrameworkFactory factory = new FrameworkFactory();
-        Framework framework = factory.newFramework(params);
-
+        Framework framework = null;
         try
         {
             final AtomicReference<String> version = new AtomicReference<String>("1.0.0");
-            ConnectFactory connectFactory = new ConnectFactory()
+            ConnectFramework connectFactory = new ConnectFramework()
             {
                 @Override
-                public boolean handles(String location)
+                public ConnectFramework initialize(File storage, Map<String, String> configuration)
                 {
-                    return "connect:foo".equals(location);
+                    return null;
                 }
 
                 @Override
-                public ConnectModule getModule(String location) throws IllegalStateException
+                public Optional<ConnectModule> getModule(String location) throws IllegalStateException
                 {
-                    return new ConnectModule()
+                    return location.startsWith("connect:foo") ? Optional.of(new ConnectModule()
                     {
                         @Override
                         public ConnectContent getContent() throws IOException
@@ -91,69 +90,88 @@ public class ConnectTest extends TestCas
                             return new ConnectContent()
                             {
                                 @Override
-                                public boolean hasEntry(String name)
+                                public Optional<ConnectEntry> getEntry(String name)
                                 {
-                                    return "foo.txt".equals(name);
-                                }
 
-                                @Override
-                                public Enumeration<String> getEntries()
-                                {
-                                    return Collections.enumeration(Arrays.asList("foo.txt"));
+                                    return "foo.txt".equals(name) ? Optional.of(
+                                        new ConnectEntry()
+                                        {
+                                            @Override
+                                            public String getName()
+                                            {
+                                                return name;
+                                            }
+
+                                            @Override
+                                            public long getContentLength()
+                                            {
+                                                return 0;
+                                            }
+
+                                            @Override
+                                            public long getLastModified()
+                                            {
+                                                return 0;
+                                            }
+
+                                            @Override
+                                            public InputStream getInputStream() throws IOException
+                                            {
+                                                return null;
+                                            }
+                                        }
+                                    ) : Optional.empty();
                                 }
 
                                 @Override
-                                public byte[] getEntryAsBytes(String name) throws IllegalArgumentException, IOException
+                                public Iterable<String> getEntries()
                                 {
-                                    throw new IllegalArgumentException();
+                                    return Arrays.asList("foo.txt");
                                 }
 
                                 @Override
-                                public InputStream getEntryAsStream(String name) throws IllegalArgumentException, IOException
+                                public Optional<ClassLoader> getClassLoader()
                                 {
-                                    throw new IllegalArgumentException();
+                                    return Optional.of(getClass().getClassLoader());
                                 }
 
                                 @Override
-                                public ConnectContent getEntryAsContent(String name) throws IllegalArgumentException
+                                public ConnectContent open() throws IOException
                                 {
-                                    throw new IllegalArgumentException();
+                                    return null;
                                 }
 
                                 @Override
-                                public String getEntryAsNativeLibrary(String name) throws IllegalArgumentException, IOException
+                                public ConnectContent close() throws IOException
                                 {
-                                    throw new IllegalArgumentException();
+                                    return null;
                                 }
 
                                 @Override
-                                public URL getEntryAsURL(String name) throws IllegalArgumentException
+                                public Optional<Map<String, String>> getHeaders()
                                 {
-                                    throw new IllegalArgumentException();
+                                    Map<String, String> headers = new HashMap<String, String>();
+                                    headers.put(Constants.BUNDLE_MANIFESTVERSION, "2");
+                                    headers.put(Constants.BUNDLE_SYMBOLICNAME, "connect.foo");
+                                    headers.put(Constants.BUNDLE_VERSION, version.get());
+                                    headers.put(Constants.EXPORT_PACKAGE, ConnectTest.class.getPackage().getName());
+                                    return Optional.of(headers);
                                 }
                             };
                         }
 
-                        @Override
-                        public ClassLoader getClassLoader()
-                        {
-                            return getClass().getClassLoader();
-                        }
 
-                        @Override
-                        public Map<String, String> getHeaders()
-                        {
-                            Map<String, String> headers = new HashMap<String, String>();
-                            headers.put(Constants.BUNDLE_MANIFESTVERSION, "2");
-                            headers.put(Constants.BUNDLE_SYMBOLICNAME, "connect.foo");
-                            headers.put(Constants.BUNDLE_VERSION, version.get());
-                            headers.put(Constants.EXPORT_PACKAGE, ConnectTest.class.getPackage().getName());
-                            return headers;
-                        }
-                    };
+                    }) : Optional.empty();
+                }
+
+                @Override
+                public Optional<BundleActivator> createBundleActivator()
+                {
+                    return Optional.empty();
                 }
             };
-            framework.init(connectFactory);
+
+            framework = factory.newFramework(params, connectFactory);
 
             framework.start();
             Bundle b = framework.getBundleContext().installBundle("connect:foo");
@@ -167,8 +185,7 @@ public class ConnectTest extends TestCas
 
             framework.stop();
             framework.waitForStop(1000);
-            framework = factory.newFramework(params);
-            framework.init(connectFactory);
+            framework = factory.newFramework(params, connectFactory);
             framework.start();
 
             b = framework.getBundleContext().getBundle("connect:foo");