CELIX-352: Added support for an framework extender path to load descriptors 
from the framework bundle.


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/58f521f6
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/58f521f6
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/58f521f6

Branch: refs/heads/master
Commit: 58f521f6a10973d3dd84c99538e165bcb2ec11ac
Parents: 91ba2a1
Author: Pepijn Noltes <pepijnnol...@gmail.com>
Authored: Thu Feb 11 16:40:20 2016 +0100
Committer: Pepijn Noltes <pepijnnol...@gmail.com>
Committed: Thu Feb 11 16:40:20 2016 +0100

----------------------------------------------------------------------
 dependency_manager/CMakeLists.txt               |  18 ++--
 remote_services/remote_service_admin/README.md  |   1 +
 .../remote_service_admin_dfi/rsa/CMakeLists.txt |   1 +
 .../rsa/private/include/dfi_utils.h             |  30 ++++++
 .../private/include/import_registration_dfi.h   |   1 +
 .../rsa/private/src/dfi_utils.c                 | 100 +++++++++++++++++++
 .../rsa/private/src/export_registration_dfi.c   |  47 ++++-----
 .../rsa/private/src/import_registration_dfi.c   |  29 ++----
 8 files changed, 170 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/58f521f6/dependency_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/dependency_manager/CMakeLists.txt 
b/dependency_manager/CMakeLists.txt
index 7a2761b..8c1f74f 100644
--- a/dependency_manager/CMakeLists.txt
+++ b/dependency_manager/CMakeLists.txt
@@ -49,15 +49,15 @@ if (DEPENDENCY_MANAGER)
        private/src/dm_dependency_manager_impl
     )
 
-    #add_library(dependency_manager SHARED 
-    #  private/src/dm_activator_base 
-    #  private/src/dm_component_impl 
-    #  private/src/dm_service_dependency
-    #  private/src/dm_event
-    #   private/src/dm_dependency_manager_impl
-    #)
-    #set_target_properties(dependency_manager PROPERTIES SOVERSION 1)
-    #target_link_libraries(dependency_manager celix_framework -undefined 
dynamic_load)
+    add_library(dependency_manager_so SHARED 
+       private/src/dm_activator_base 
+       private/src/dm_component_impl 
+       private/src/dm_service_dependency
+       private/src/dm_event
+        private/src/dm_dependency_manager_impl
+    )
+    set_target_properties(dependency_manager_so PROPERTIES SOVERSION 1)
+    target_link_libraries(dependency_manager_so celix_framework)
 
        include_directories("public/include")
        include_directories("private/include")

http://git-wip-us.apache.org/repos/asf/celix/blob/58f521f6/remote_services/remote_service_admin/README.md
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/README.md 
b/remote_services/remote_service_admin/README.md
index a2ee5cd..c4bdebd 100644
--- a/remote_services/remote_service_admin/README.md
+++ b/remote_services/remote_service_admin/README.md
@@ -8,3 +8,4 @@ Note that this folder contains code commonly used by the RSA 
implementations and
 
 ###### Properties
     ENDPOINTS                           defines the relative directory where 
endpoints and proxys can be found (default: endpoints)
+    CELIX_FRAMEWORK_EXTENDER_PATH  Used in RSA_DFI only. Can be used to define 
a path to use as an extender path point for the framework bundle. For normal 
bundles the bundle cache is used. 

http://git-wip-us.apache.org/repos/asf/celix/blob/58f521f6/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt 
b/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
index 17a0c02..c1a2150 100644
--- a/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
@@ -36,6 +36,7 @@ add_bundle(remote_service_admin_dfi
     private/src/remote_service_admin_activator.c
     private/src/export_registration_dfi.c
     private/src/import_registration_dfi.c
+    private/src/dfi_utils.c
 
     
${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
 

http://git-wip-us.apache.org/repos/asf/celix/blob/58f521f6/remote_services/remote_service_admin_dfi/rsa/private/include/dfi_utils.h
----------------------------------------------------------------------
diff --git 
a/remote_services/remote_service_admin_dfi/rsa/private/include/dfi_utils.h 
b/remote_services/remote_service_admin_dfi/rsa/private/include/dfi_utils.h
new file mode 100644
index 0000000..cec8aa1
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/private/include/dfi_utils.h
@@ -0,0 +1,30 @@
+/**
+ *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
+ *
+ *  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.
+ */
+#ifndef DFI_UTILS_H_
+#define DFI_UTILS_H_
+
+#include "bundle.h"
+#include "bundle_context.h"
+#include <stdio.h>
+#include "celix_errno.h"
+
+
+celix_status_t dfi_findDescriptor(bundle_context_pt context, bundle_pt bundle, 
const char *name, FILE **out);
+
+#endif

http://git-wip-us.apache.org/repos/asf/celix/blob/58f521f6/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
----------------------------------------------------------------------
diff --git 
a/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
 
b/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
index 53eb604..aac4bc7 100644
--- 
a/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
+++ 
b/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
@@ -21,6 +21,7 @@
 #define CELIX_IMPORT_REGISTRATION_DFI_H
 
 #include "import_registration.h"
+#include "dfi_utils.h"
 
 #include <celix_errno.h>
 

http://git-wip-us.apache.org/repos/asf/celix/blob/58f521f6/remote_services/remote_service_admin_dfi/rsa/private/src/dfi_utils.c
----------------------------------------------------------------------
diff --git 
a/remote_services/remote_service_admin_dfi/rsa/private/src/dfi_utils.c 
b/remote_services/remote_service_admin_dfi/rsa/private/src/dfi_utils.c
new file mode 100644
index 0000000..e9888f9
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/dfi_utils.c
@@ -0,0 +1,100 @@
+/**
+ *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
+ *
+ *  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.
+ */
+
+#include "dfi_utils.h"
+#include <stdlib.h>
+#include <unistd.h>
+
+static celix_status_t dfi_findFileForFramework(bundle_context_pt context, 
const char *fileName, FILE **out) {
+    celix_status_t  status;
+
+    char cwd[1024];
+    char *extPath = NULL;
+    char path[1024];
+   
+    status = bundleContext_getProperty(context, 
"CELIX_FRAMEWORK_EXTENDER_PATH", &extPath);
+    if (status != CELIX_SUCCESS || extPath == NULL) {
+        getcwd(cwd, sizeof(cwd));
+        extPath = cwd;
+        if (extPath == NULL) {
+            status = CELIX_FILE_IO_EXCEPTION;
+        }
+    }
+
+    snprintf(path, sizeof(path), "%s/%s", extPath, fileName);
+
+    if (status == CELIX_SUCCESS) {
+        FILE *df = fopen(path, "r");
+        if (df == NULL) {
+            status = CELIX_FILE_IO_EXCEPTION;
+        } else {
+            *out = df;
+        }
+    }
+
+    return status;
+}
+
+static celix_status_t dfi_findFileForBundle(bundle_pt bundle, const char 
*fileName, FILE **out) {
+    celix_status_t  status;
+
+    char *path = NULL;
+    char metaInfFileName[128];
+    snprintf(metaInfFileName, sizeof(metaInfFileName), 
"META-INF/descriptors/%s", fileName);
+
+    status = bundle_getEntry(bundle, (char *)fileName, &path);
+    
+    if (status != CELIX_SUCCESS || path == NULL) {
+        status = bundle_getEntry(bundle, metaInfFileName, &path);
+    }
+
+    if (status == CELIX_SUCCESS && path != NULL) {
+        FILE *df = fopen(path, "r");
+        if (df == NULL) {
+            status = CELIX_FILE_IO_EXCEPTION;
+        } else {
+            *out = df;
+        }
+
+        free(path);
+    }
+    return status;
+}
+
+celix_status_t dfi_findDescriptor(bundle_context_pt context, bundle_pt bundle, 
const char *name, FILE **out) {
+    celix_status_t  status;
+    char fileName[128];
+
+    snprintf(fileName, 128, "%s.descriptor", name);
+
+    long id;
+    status = bundle_getBundleId(bundle, &id);
+    
+    if (status == CELIX_SUCCESS) {
+        if (id == 0) {
+            //framework bundle
+            status = dfi_findFileForFramework(context, fileName, out);
+        } else {
+            //normal bundle
+            status = dfi_findFileForBundle(bundle, fileName, out);
+        }
+    }
+
+    return status;
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/58f521f6/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
----------------------------------------------------------------------
diff --git 
a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
 
b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
index 6eb4b86..a8d61ff 100644
--- 
a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
+++ 
b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
@@ -27,6 +27,7 @@
 #include <json_rpc.h>
 #include "constants.h"
 #include "export_registration_dfi.h"
+#include "dfi_utils.h"
 
 struct export_reference {
     endpoint_description_pt endpoint; //owner
@@ -83,44 +84,30 @@ celix_status_t exportRegistration_create(log_helper_pt 
helper, service_reference
     bundle_pt bundle = NULL;
     CELIX_DO_IF(status, serviceReference_getBundle(reference, &bundle));
 
-
-    char *descriptorFile = NULL;
+    FILE *descriptor = NULL;
     if (status == CELIX_SUCCESS) {
-        char name[128];
-        snprintf(name, 128, "%s.descriptor", exports);
-        status = bundle_getEntry(bundle, name, &descriptorFile);
-        logHelper_log(helper, OSGI_LOGSERVICE_DEBUG, "RSA: Found descriptor 
'%s' for %'s'.", descriptorFile, exports);
+        status = dfi_findDescriptor(context, bundle, exports, &descriptor);
     }
 
-    if (descriptorFile == NULL) {
-        logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "RSA: Cannot find 
descrriptor in bundle for service '%s'", exports);
-        status = CELIX_ILLEGAL_ARGUMENT;
+    if (status != CELIX_SUCCESS || descriptor == NULL) {
+        status = CELIX_BUNDLE_EXCEPTION;
+        logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Cannot find/open 
descriptor for '%s'", exports);
     }
 
     if (status == CELIX_SUCCESS) {
-        FILE *df = fopen(descriptorFile, "r");
-        if (df != NULL) {
-            int rc = dynInterface_parse(df, &reg->intf);
-            fclose(df);
-            if (rc != 0) {
-                status = CELIX_BUNDLE_EXCEPTION;
-                logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "RSA: Error 
parsing service descriptor.");
-            }
-            else{
-                /* Add the interface version as a property in the 
properties_map */
-                char* intfVersion = NULL;
-                dynInterface_getVersionString(reg->intf, &intfVersion);
-                properties_set(endpoint->properties, (char*) 
CELIX_FRAMEWORK_SERVICE_VERSION, intfVersion);
-            }
-        } else {
+        int rc = dynInterface_parse(descriptor, &reg->intf);
+        fclose(descriptor);
+        if (rc != 0) {
             status = CELIX_BUNDLE_EXCEPTION;
-            logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Cannot open 
descriptor '%s'", descriptorFile);
+            logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "RSA: Error parsing 
service descriptor.");
         }
-
-        free(descriptorFile);
-    }
-
-
+        else{
+            /* Add the interface version as a property in the properties_map */
+            char* intfVersion = NULL;
+            dynInterface_getVersionString(reg->intf, &intfVersion);
+            properties_set(endpoint->properties, (char*) 
CELIX_FRAMEWORK_SERVICE_VERSION, intfVersion);
+        }
+    } 
 
     if (status == CELIX_SUCCESS) {
         service_tracker_customizer_pt cust = NULL;

http://git-wip-us.apache.org/repos/asf/celix/blob/58f521f6/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git 
a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
 
b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
index 16e27a5..ee1dbbf 100644
--- 
a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
+++ 
b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
@@ -196,29 +196,22 @@ celix_status_t 
importRegistration_getService(import_registration_pt import, bund
 static celix_status_t importRegistration_createProxy(import_registration_pt 
import, bundle_pt bundle, struct service_proxy **out) {
     celix_status_t  status;
     dyn_interface_type* intf = NULL;
-    char *descriptorFile = NULL;
-    char name[128];
+    FILE *descriptor = NULL;
 
-    snprintf(name, 128, "%s.descriptor", import->classObject);
-    status = bundle_getEntry(bundle, name, &descriptorFile);
-    if (descriptorFile == NULL) {
-        printf("Cannot find entry '%s'\n", name);
-        status = CELIX_ILLEGAL_ARGUMENT;
-    } else {
-        printf("Found descriptor at '%s'\n", descriptorFile);
+    status = dfi_findDescriptor(import->context, bundle, import->classObject, 
&descriptor);
+
+    if (status != CELIX_SUCCESS || descriptor == NULL) {
+        status = CELIX_BUNDLE_EXCEPTION;
+        //TODO use log helper logHelper_log(helper, OSGI_LOGSERVICE_ERROR, 
"Cannot find/open descriptor for '%s'", import->classObject);
+        fprintf(stderr, "RSA_DFI: Cannot find/open descriptor for '%s'", 
import->classObject);
     }
 
     if (status == CELIX_SUCCESS) {
-        FILE *df = fopen(descriptorFile, "r");
-        if (df != NULL) {
-            int rc = dynInterface_parse(df, &intf);
-            fclose(df);
-            if (rc != 0) {
-                status = CELIX_BUNDLE_EXCEPTION;
-            }
+        int rc = dynInterface_parse(descriptor, &intf);
+        fclose(descriptor);
+        if (rc != 0) {
+            status = CELIX_BUNDLE_EXCEPTION;
         }
-
-        free(descriptorFile);
     }
 
     /* Check if the imported service version is compatible with the one in the 
consumer descriptor */

Reply via email to