← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/declare-uri-file into lp:zorba

 

Chris Hillery has proposed merging lp:~zorba-coders/zorba/declare-uri-file into lp:zorba.

Requested reviews:
  Chris Hillery (ceejatec)
  Cezar Andrei (cezar-andrei)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/declare-uri-file/+merge/91049
-- 
https://code.launchpad.net/~zorba-coders/zorba/declare-uri-file/+merge/91049
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'cmake_modules/ZorbaModule.cmake'
--- cmake_modules/ZorbaModule.cmake	2012-01-29 10:07:34 +0000
+++ cmake_modules/ZorbaModule.cmake	2012-02-01 11:02:13 +0000
@@ -66,7 +66,8 @@
 #
 # Parameters:
 #   URI - URI to mangle
-#   EXT - extension to ensure URI ends with
+#   EXT - extension to ensure URI ends with (may be empty; if set, must
+#         include leading "."
 #   DIR_VAR - variable to set with the directory part of the mangled path
 #   FILE_VAR - variable to set with the file part of the mangled path
 MACRO (MANGLE_URI URI EXT DIR_VAR FILE_VAR)
@@ -89,13 +90,14 @@
 
   # Convert final component into proper filename
   IF (NOT final_comp)
-    SET (${FILE_VAR} "index.${EXT}")
+    SET (${FILE_VAR} "index${EXT}")
   ELSE (NOT final_comp)
-    IF ("${final_comp}" MATCHES "\\.${EXT}$")
+    # \\ necessary to escape the leading . in EXT
+    IF ("${final_comp}" MATCHES "\\${EXT}$")
       SET (${FILE_VAR} "${final_comp}")
-    ELSE ("${final_comp}" MATCHES "\\.${EXT}$")
-      SET (${FILE_VAR} "${final_comp}.${EXT}")
-    ENDIF ("${final_comp}" MATCHES "\\.${EXT}$")
+    ELSE ("${final_comp}" MATCHES "\\${EXT}$")
+      SET (${FILE_VAR} "${final_comp}${EXT}")
+    ENDIF ("${final_comp}" MATCHES "\\${EXT}$")
   ENDIF (NOT final_comp)
 
   # Stick the reversed authority back on the front of the path: done!
@@ -139,7 +141,7 @@
   GET_FILENAME_COMPONENT (module_name "${MODULE_FILE}" NAME)
 
 
-  MANGLE_URI (${MODULE_URI} "xq" module_path module_filename)
+  MANGLE_URI (${MODULE_URI} ".xq" module_path module_filename)
 
   # Compute a CMake-symbol-safe version of the target URI, for storing
   # things in CMake properties.
@@ -355,7 +357,7 @@
     SET (SOURCE_FILE "${SCHEMA_FILE}")
   ENDIF (NOT IS_ABSOLUTE "${SCHEMA_FILE}")
   GET_FILENAME_COMPONENT (schema_name "${SCHEMA_FILE}" NAME)
-  MANGLE_URI (${SCHEMA_URI} "xsd" schema_path schema_filename)
+  MANGLE_URI (${SCHEMA_URI} ".xsd" schema_path schema_filename)
 
   # Add to schema manifest (except test schema).
   IF (NOT SCHEMA_TEST_ONLY)
@@ -367,11 +369,44 @@
 
 ENDMACRO (DECLARE_ZORBA_SCHEMA)
 
+# Macro which declares a file to be loaded by URI. This sets up the
+# installation of the file into the URI_PATH folder so it will be
+# found at runtime.
+#
+# Args: URI - the URI of the file
+#       FILE - path to file (if not absolute, will be resolved
+#              relative to CMAKE_CURRENT_SOURCE_DIR)
+#       TEST_ONLY - (optional) File is for testcases only and should not
+#              be installed
+MACRO (DECLARE_ZORBA_URI_FILE)
+  # QQQ Refactor - this macro is basically identical to DECLARE_ZORBA_SCHEMA
+  PARSE_ARGUMENTS(URI_FILE "" "URI;FILE" "TEST_ONLY" ${ARGN})
+  IF (NOT URI_FILE_FILE)
+    MESSAGE (FATAL_ERROR "'FILE' argument is required for ZORBA_DECLARE_URI_FILE()")
+  ENDIF (NOT URI_FILE_FILE)
+  IF (NOT URI_FILE_URI)
+    MESSAGE (FATAL_ERROR "'URI' argument is required for ZORBA_DECLARE_URI_FILE()")
+  ENDIF (NOT URI_FILE_URI)
+  IF (NOT IS_ABSOLUTE "${URI_FILE_FILE}")
+    SET (SOURCE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${URI_FILE_FILE}")
+  ELSE (NOT IS_ABSOLUTE "${URI_FILE_FILE}")
+    SET (SOURCE_FILE "${URI_FILE_FILE}")
+  ENDIF (NOT IS_ABSOLUTE "${URI_FILE_FILE}")
+  GET_FILENAME_COMPONENT (uri_file_name "${URI_FILE_FILE}" NAME)
+  # Don't enforce any extension on general files
+  MANGLE_URI (${URI_FILE_URI} "" uri_file_path uri_file_filename)
+
+  ADD_COPY_RULE ("URI" "${SOURCE_FILE}" "${uri_file_path}/${uri_file_filename}"
+    "" "" "${URI_FILE_TEST_ONLY}")
+
+ENDMACRO (DECLARE_ZORBA_URI_FILE)
+
 # Utility macro for setting up a build rule to copy a file to a
 # particular (possibly versioned) file in a shared directory if such a file has
 # not already been output.
 # FILE_TYPE: Either "URI" or "LIB"; will be used to determine which shared
-#    directory to place output in (URI_PATH or LIB_PATH).
+#    directory to place output in (URI_PATH or LIB_PATH). Also, "URI" files
+#    will have an INSTALL() directive to put them in the install image.
 # INPUT_FILE: Absolute path to file to copy.
 # OUTPUT_FILE: Relative path to output file (relative to URI_PATH).
 # VERSION_ARG: Version; may be "" for non-versioned files.
@@ -425,39 +460,37 @@
     SET_PROPERTY (GLOBAL APPEND PROPERTY ZORBA_URI_FILES
       "${INPUT_FILE}" "${_output_file}" "${DEPEND_TARGET}" "${_is_core}")
 
-    # For .xq and .xsd files, also set up an INSTALL rule (if not TEST_ONLY).
-    IF (NOT ${TEST_ONLY} EQUAL 1)
-      IF (${_output_ext} STREQUAL ".xq" OR ${_output_ext} STREQUAL ".xsd")
+    # Also set up an INSTALL rule (unless TEST_ONLY or LIB).
+    IF ( (NOT "${FILE_TYPE}" STREQUAL "LIB") AND (NOT ${TEST_ONLY} EQUAL 1) )
         
-        IF(NOT _is_core)
-          STRING(REPLACE "-" "_"  component_name ${PROJECT_NAME})   
-          INSTALL (FILES "${INPUT_FILE}"
-            DESTINATION "${ZORBA_NONCORE_URI_DIR}/${_output_path}"
-            RENAME "${_output_filename}"
-            COMPONENT "${component_name}")
+      IF(NOT _is_core)
+        STRING(REPLACE "-" "_"  component_name ${PROJECT_NAME})   
+        INSTALL (FILES "${INPUT_FILE}"
+          DESTINATION "${ZORBA_NONCORE_URI_DIR}/${_output_path}"
+          RENAME "${_output_filename}"
+          COMPONENT "${component_name}")
           
-          IF (NOT ${component_name}_cpack)
-            SET (${component_name}_cpack 1)
+        IF (NOT ${component_name}_cpack)
+          SET (${component_name}_cpack 1)
         
-            STRING(TOUPPER ${component_name} component_name2)
-            FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeCPackModules.cmake "SET(CPACK_COMPONENT_${component_name2}_GROUP \"external_modules\")\n")
-            
-            STRING(REPLACE "zorba_" "" component_display_name ${component_name})
-            STRING(REPLACE "_" " " component_display_name ${component_display_name})
-            FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeCPackModules.cmake "SET(CPACK_COMPONENT_${component_name2}_DISPLAY_NAME \"${component_display_name}\")\n")
-            
-            FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeCPackModules.cmake "SET(CPACK_COMPONENT_${component_name2}_DESCRIPTION \"Install the functionalities of the ${component_display_name}.\")\n")
-            FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeCPackModules.cmake "SET(CPACK_COMPONENT_${component_name2}_INSTALL_TYPES Full)\n")
-          ENDIF (NOT ${component_name}_cpack)  
-            
-        ELSE(NOT _is_core)
-          INSTALL (FILES "${INPUT_FILE}"
+          STRING(TOUPPER ${component_name} component_name2)
+          FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeCPackModules.cmake "SET(CPACK_COMPONENT_${component_name2}_GROUP \"external_modules\")\n")
+            
+          STRING(REPLACE "zorba_" "" component_display_name ${component_name})
+          STRING(REPLACE "_" " " component_display_name ${component_display_name})
+          FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeCPackModules.cmake "SET(CPACK_COMPONENT_${component_name2}_DISPLAY_NAME \"${component_display_name}\")\n")
+            
+          FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeCPackModules.cmake "SET(CPACK_COMPONENT_${component_name2}_DESCRIPTION \"Install the functionalities of the ${component_display_name}.\")\n")
+          FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeCPackModules.cmake "SET(CPACK_COMPONENT_${component_name2}_INSTALL_TYPES Full)\n")
+        ENDIF (NOT ${component_name}_cpack)  
+            
+      ELSE(NOT _is_core)
+        INSTALL (FILES "${INPUT_FILE}"
           DESTINATION "${ZORBA_CORE_URI_DIR}/${_output_path}"
           RENAME "${_output_filename}")
-        ENDIF(NOT _is_core)
+      ENDIF(NOT _is_core)
           
-      ENDIF (${_output_ext} STREQUAL ".xq" OR ${_output_ext} STREQUAL ".xsd")
-    ENDIF (NOT ${TEST_ONLY} EQUAL 1)
+    ENDIF ( (NOT "${FILE_TYPE}" STREQUAL "LIB") AND (NOT ${TEST_ONLY} EQUAL 1) )
   ENDIF (file_found EQUAL -1)
 ENDMACRO (ADD_COPY_RULE)
 

=== modified file 'src/context/default_uri_mappers.cpp'
--- src/context/default_uri_mappers.cpp	2011-11-08 03:11:02 +0000
+++ src/context/default_uri_mappers.cpp	2012-02-01 11:02:13 +0000
@@ -38,19 +38,30 @@
 (zstring const& aUri, EntityData const* aEntityData,
   static_context const& aSctx, std::vector<zstring>& oUris)
 {
-  // File-izing is only for schemas and modules.
+  // File-izing isn't for collections.
   EntityData::Kind lKind = aEntityData->getKind();
-  if (lKind != EntityData::SCHEMA && lKind != EntityData::MODULE) {
+  if (lKind == EntityData::COLLECTION) {
     return;
   }
 
-  // Append extension / filename as necessary
-  zstring lExtension(lKind == EntityData::SCHEMA ? ".xsd": ".xq");
+  // Append extension / filename as necessary.
+  zstring lExtension;
+  switch (lKind) {
+    case EntityData::SCHEMA:
+      lExtension = ".xsd";
+      break;
+    case EntityData::MODULE:
+      lExtension = ".xq";
+      break;
+    default:
+      lExtension = "";
+      break;
+  }
   URI lUri(aUri);
   zstring lPath = lUri.get_encoded_path();
   bool lChanged = false;
   if (ascii::ends_with(lPath, "/")) {
-    // If URI ends with /, append "index.xsd" or "index.xq".
+    // If URI ends with /, append "index.<extension>".
     lPath.append("index");
     lPath.append(lExtension);
     lChanged = true;
@@ -128,9 +139,9 @@
 (zstring const& aUri, EntityData const* aEntityData,
   static_context const& aSctx, std::vector<zstring>& oUris)
 {
-  // Automatic resolution is (currently?) only for schemas and modules
+  // Filesystem resolution doesn't make sense for collections
   EntityData::Kind lKind = aEntityData->getKind();
-  if (lKind != EntityData::SCHEMA && lKind != EntityData::MODULE) {
+  if (lKind == EntityData::COLLECTION) {
     return;
   }
   // Automatic resolution is for NON-file: URIs

=== added file 'test/rbkt/ExpQueryResults/zorba/fetch/fetch_random_file.xml.res'
--- test/rbkt/ExpQueryResults/zorba/fetch/fetch_random_file.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/fetch/fetch_random_file.xml.res	2012-02-01 11:02:13 +0000
@@ -0,0 +1,1 @@
+This is a random file that I would like to load by URI.

=== added file 'test/rbkt/Queries/zorba/fetch/fetch_random_file.xq'
--- test/rbkt/Queries/zorba/fetch/fetch_random_file.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/fetch/fetch_random_file.xq	2012-02-01 11:02:13 +0000
@@ -0,0 +1,4 @@
+(: Fetch a random file from the filesystem :)
+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch#2.0";;
+
+fetch:content("http://www.zorba-xquery.com/random-file";)

=== modified file 'test/rbkt/modules/CMakeLists.txt'
--- test/rbkt/modules/CMakeLists.txt	2012-01-11 17:30:25 +0000
+++ test/rbkt/modules/CMakeLists.txt	2012-02-01 11:02:13 +0000
@@ -54,3 +54,7 @@
     -e "manifest:=${CMAKE_BINARY_DIR}/ZorbaManifest.xml"
     --module-path "${CMAKE_BINARY_DIR}/TEST_URI_PATH")
 ENDIF (NOT ZORBA_NO_XMLSCHEMA)
+
+# This is as good a place as any to test this feature
+DECLARE_ZORBA_URI_FILE(FILE "random-file.txt"
+  URI "http://www.zorba-xquery.com/random-file"; TEST_ONLY)

=== added file 'test/rbkt/modules/random-file.txt'
--- test/rbkt/modules/random-file.txt	1970-01-01 00:00:00 +0000
+++ test/rbkt/modules/random-file.txt	2012-02-01 11:02:13 +0000
@@ -0,0 +1,1 @@
+This is a random file that I would like to load by URI.


Follow ups