This is an automated email from the ASF dual-hosted git repository.
tjwatson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-atomos.git
The following commit(s) were added to refs/heads/master by this push:
new e675f42 Allow public access to ConnectContent via the AtomosContent
interface
new 2b935d0 Merge pull request #4 from sebratton/expose-getConnectContent
e675f42 is described below
commit e675f42fbb075be4b2544724da729cd4231e888d
Author: Samuel E Bratton <[email protected]>
AuthorDate: Tue Mar 3 15:40:48 2020 -0600
Allow public access to ConnectContent via the AtomosContent interface
---
.../impl/runtime/base/AtomosRuntimeBase.java | 3 ++-
.../apache/felix/atomos/runtime/AtomosContent.java | 11 +++++++++++
.../felix/atomos/runtime/AtomosRuntimeTest.java | 22 ++++++++++++++++++++++
3 files changed, 35 insertions(+), 1 deletion(-)
diff --git
a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosRuntimeBase.java
b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosRuntimeBase.java
index 63c962c..a73a8d8 100644
---
a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosRuntimeBase.java
+++
b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosRuntimeBase.java
@@ -1032,7 +1032,8 @@ public abstract class AtomosRuntimeBase implements
AtomosRuntime, SynchronousBun
protected abstract Object getKey();
- ConnectContent getConnectContent()
+ @Override
+ public ConnectContent getConnectContent()
{
debug("Getting connect content for %s", this);
return content;
diff --git
a/atomos.runtime/src/main/java/org/apache/felix/atomos/runtime/AtomosContent.java
b/atomos.runtime/src/main/java/org/apache/felix/atomos/runtime/AtomosContent.java
index 9929fc6..2e7aa22 100644
---
a/atomos.runtime/src/main/java/org/apache/felix/atomos/runtime/AtomosContent.java
+++
b/atomos.runtime/src/main/java/org/apache/felix/atomos/runtime/AtomosContent.java
@@ -19,6 +19,7 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Version;
+import org.osgi.framework.connect.ConnectContent;
/**
* Atomos Content provides information about content discovered
@@ -99,6 +100,16 @@ public interface AtomosContent extends
Comparable<AtomosContent>
*/
Bundle install(String prefix) throws BundleException;
+ /**
+ * Prefer {@link #getBundle() getBundle()} to this call to avoid
concurrency issues if there is any possibility
+ * that an OSGI framework is active and managing the associated content.
If the ConnectContent is not managed by
+ * a framework, {@link #getBundle() getBundle()} will return null and this
method can be called as a way to access
+ * the associated content. The caller is responsible for opening and
closing the ConnectContent as appropriate.
+ *
+ * @return ConnectContent associated with this Atomos content.
+ */
+ ConnectContent getConnectContent();
+
/**
* Returns the connected bundle location for this Atomos content or {@code
null} if
* no bundle location is connected for this content. A {@code non-null}
value is
diff --git
a/atomos.runtime/src/test/java/org/apache/felix/atomos/runtime/AtomosRuntimeTest.java
b/atomos.runtime/src/test/java/org/apache/felix/atomos/runtime/AtomosRuntimeTest.java
index aa3bed2..4b43d2e 100644
---
a/atomos.runtime/src/test/java/org/apache/felix/atomos/runtime/AtomosRuntimeTest.java
+++
b/atomos.runtime/src/test/java/org/apache/felix/atomos/runtime/AtomosRuntimeTest.java
@@ -174,6 +174,28 @@ public class AtomosRuntimeTest
failConnect(javaBase, javaXML, bc, runtime);
}
+ @Test
+ void testGetConnectContent(@TempDir Path storage) throws BundleException,
IOException {
+ AtomosRuntime runtime = AtomosRuntime.newAtomosRuntime();
+ Map<String, String> config = Map.of( //
+ Constants.FRAMEWORK_STORAGE, storage.toFile().getAbsolutePath());
+ testFramework = AtomosLauncher.newFramework(config, runtime);
+ testFramework.start();
+
+ AtomosContent atomosContent;
+ atomosContent =
runtime.getConnectedContent(Constants.SYSTEM_BUNDLE_LOCATION);
+ assertNotNull(atomosContent, "Could not get AtomosContent for System
Bundle");
+ assertEquals(atomosContent.getConnectContent(),
+
runtime.getModuleConnector().connect(atomosContent.getConnectLocation()).get().getContent(),
+ "AtomosContent.getConnectContent did not match
ConnectModule.getConnectedContent");
+
+ atomosContent =
runtime.getBootLayer().findAtomosContent("java.base").get();
+ assertNotNull(atomosContent, "Could not get AtomosContent for
java.base");
+ assertEquals(atomosContent.getConnectContent(),
+
runtime.getModuleConnector().connect(atomosContent.getConnectLocation()).get().getContent(),
+ "AtomosContent.getConnectContent did not match
ConnectModule.getConnectedContent");
+ }
+
private void failConnect(AtomosContent c1, AtomosContent c2, BundleContext
bc,
AtomosRuntime runtime) throws BundleException
{