You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2019/05/20 11:50:59 UTC
[karaf] branch master updated: [KARAF-6234] Deal with unavalaible
metatype service when registering command
This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf.git
The following commit(s) were added to refs/heads/master by this push:
new 191cf01 [KARAF-6234] Deal with unavalaible metatype service when registering command
new c827346 Merge pull request #847 from jbonofre/KARAF-6234
191cf01 is described below
commit 191cf01e9945d2b4a105600bf177f7bc23885e95
Author: Jean-Baptiste Onofré <jb...@apache.org>
AuthorDate: Mon May 20 10:38:50 2019 +0200
[KARAF-6234] Deal with unavalaible metatype service when registering command
---
.../apache/karaf/config/command/MetaCommand.java | 20 ++++++------
.../karaf/config/core/impl/MetaServiceCaller.java | 36 ++++++++++++----------
2 files changed, 31 insertions(+), 25 deletions(-)
diff --git a/config/src/main/java/org/apache/karaf/config/command/MetaCommand.java b/config/src/main/java/org/apache/karaf/config/command/MetaCommand.java
index 6b33f81..0662420 100644
--- a/config/src/main/java/org/apache/karaf/config/command/MetaCommand.java
+++ b/config/src/main/java/org/apache/karaf/config/command/MetaCommand.java
@@ -117,15 +117,17 @@ public class MetaCommand extends ConfigCommandSupport {
}
protected ObjectClassDefinition getMetatype(MetaTypeService metaTypeService, String pid) {
- for (Bundle bundle : context.getBundles()) {
- MetaTypeInformation info = metaTypeService.getMetaTypeInformation(bundle);
- if (info == null) {
- continue;
- }
- String[] pids = info.getPids();
- for (String cPid : pids) {
- if (cPid.equals(pid)) {
- return info.getObjectClassDefinition(cPid, null);
+ if (metaTypeService != null) {
+ for (Bundle bundle : context.getBundles()) {
+ MetaTypeInformation info = metaTypeService.getMetaTypeInformation(bundle);
+ if (info == null) {
+ continue;
+ }
+ String[] pids = info.getPids();
+ for (String cPid : pids) {
+ if (cPid.equals(pid)) {
+ return info.getObjectClassDefinition(cPid, null);
+ }
}
}
}
diff --git a/config/src/main/java/org/apache/karaf/config/core/impl/MetaServiceCaller.java b/config/src/main/java/org/apache/karaf/config/core/impl/MetaServiceCaller.java
index 0db2a79..1dccbdb 100644
--- a/config/src/main/java/org/apache/karaf/config/core/impl/MetaServiceCaller.java
+++ b/config/src/main/java/org/apache/karaf/config/core/impl/MetaServiceCaller.java
@@ -34,29 +34,33 @@ public class MetaServiceCaller {
public static <T> T withMetaTypeService(BundleContext context, Function<MetaTypeService, T> callable) {
ServiceReference<MetaTypeService> ref = context.getServiceReference(MetaTypeService.class);
- try {
- MetaTypeService metaService = context.getService(ref);
- return callable.apply(metaService);
- } finally {
- context.ungetService(ref);
+ if (ref != null) {
+ try {
+ MetaTypeService metaService = context.getService(ref);
+ return callable.apply(metaService);
+ } finally {
+ context.ungetService(ref);
+ }
}
+ return null;
}
public static List<String> getPidsWithMetaInfo(BundleContext context) {
return withMetaTypeService(context, metatypeService -> {
List<String> pids1 = new ArrayList<>();
Bundle[] bundles = context.getBundles();
- for (Bundle bundle : bundles) {
-
- MetaTypeInformation info = metatypeService.getMetaTypeInformation(bundle);
- if (info == null) {
- continue;
- }
- if (info.getFactoryPids() != null) {
- pids1.addAll(Arrays.asList(info.getFactoryPids()));
- }
- if (info.getPids() != null) {
- pids1.addAll(Arrays.asList(info.getPids()));
+ if (metatypeService != null) {
+ for (Bundle bundle : bundles) {
+ MetaTypeInformation info = metatypeService.getMetaTypeInformation(bundle);
+ if (info == null) {
+ continue;
+ }
+ if (info.getFactoryPids() != null) {
+ pids1.addAll(Arrays.asList(info.getFactoryPids()));
+ }
+ if (info.getPids() != null) {
+ pids1.addAll(Arrays.asList(info.getPids()));
+ }
}
}
return pids1;