[UIMA-6190] Fix bugs found on Mac OSX (using the clang compiler)
Explicit casts between the 16-bit characters UChar & XMLCh.
Remove unused buggy xmiwriter template.
Replace unsigned int with size_t in strtools.hpp
Drop -module link flag so Mac creates .dylib rather than .so libraries.
Work around Mac's refusal to pass DYLD_LIBRARY_PATH through the environment.
Add icu namespace to UnicodeString declarations.
diff --git a/configure.ac b/configure.ac
index 75b9c92..4fe78fd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -120,7 +120,7 @@
 
 # check APR version number agains regex
 #APR_VER_REGEXES=["1\.3\.[0-9] 1\.3\.1[0-9] 1\.4\.[0-9]"]
-APR_VER_REGEXES=["1\.4\.[0-9] 1\.5\.[0-9] 1\.6\.[0-9]"]
+APR_VER_REGEXES=["1\.6\.[0-9] 1\.7\.[0-9]"]
 
 AC_MSG_CHECKING([APR version])
 apr_version="`$apr_config --version`"
diff --git a/src/cas/cas.cpp b/src/cas/cas.cpp
index 6c0507e..76a7937 100644
--- a/src/cas/cas.cpp
+++ b/src/cas/cas.cpp
@@ -1364,8 +1364,8 @@
     return fsCoveringAn;
   }
 
-  ANIterator AnnotationFS::subIterator( Type const & crType, EnIteratorAmbiguity enIsAmbiguous ) const {
-    return getCAS().getAnnotationIndex(crType).subIterator(*this, enIsAmbiguous);
+  ANIterator AnnotationFS::subIterator( Type const & crType, EnIteratorAmbiguity ambiguity ) const {
+    return getCAS().getAnnotationIndex(crType).subIterator(*this, ambiguity);
   }
 
 
@@ -1704,16 +1704,16 @@
   } // namespace lowlevel
 
 
-  ANIterator ANIndex::subIterator( AnnotationFS const & an, EnIteratorAmbiguity enIsAmbiguous ) const {
+  ANIterator ANIndex::subIterator( AnnotationFS const & an, EnIteratorAmbiguity ambiguity ) const {
     checkValidity();
     lowlevel::IndexIterator* pitBase = iv_pIndex->createIterator();
     assert( EXISTS(pitBase) );
 
     lowlevel::IndexIterator* pitSub;
-    if (enIsAmbiguous == enUnambiguous) {
+    if (ambiguity == enUnambiguous) {
       pitSub = new lowlevel::UnAmbiguousSubIterator( iv_indexRepository->getFSHeap(), internal::FSPromoter::demoteFS(an), pitBase);
     } else {
-      assert(enIsAmbiguous == enAmbiguous);
+      assert(ambiguity == enAmbiguous);
       pitSub = new lowlevel::SubIterator(iv_indexRepository->getFSHeap(), internal::FSPromoter::demoteFS(an), pitBase);
     }
     assert( EXISTS(pitSub) );
diff --git a/src/cas/uima/cas.hpp b/src/cas/uima/cas.hpp
index 44f0600..33e4146 100644
--- a/src/cas/uima/cas.hpp
+++ b/src/cas/uima/cas.hpp
@@ -1226,8 +1226,8 @@
      * and begin positon < this.getEndPosition()
      *
      * @param crType      The type of annotation over which to iterate.
-                          crType must be subsumed by type annotation.
-     * @param enAmbiguous If set to CAS::enAmbiguous calling
+     *                    crType must be subsumed by type annotation.
+     * @param ambiguity   If set to CAS::enAmbiguous calling
      *                    moveToNext/moveToPrevious will alway move the resulting
      *                    interator to an annotation that is no longer covered
      *                    by the current annotation.
@@ -1249,7 +1249,7 @@
      *
      * @throws InvalidIndexObjectException
      */
-    ANIterator subIterator( Type const & crType, EnIteratorAmbiguity enIsAmbiguous = enAmbiguous ) const;
+    ANIterator subIterator( Type const & crType, EnIteratorAmbiguity ambiguity = enAmbiguous ) const;
   protected:
   }
   ; // class AnnotationFS
@@ -1352,7 +1352,7 @@
      *
      * @param an          The annotatation "under" which the subiterator
      *                    iterates
-     * @param enAmbiguous If set to CAS::enAmbiguous calling
+     * @param ambiguity   If set to CAS::enAmbiguous calling
      *                    moveToNext/moveToPrevious will alway move the resulting
      *                    interator to an annotation that is no longer covered
      *                    by the current annotation.
@@ -1373,7 +1373,7 @@
      *                    annotations cover the area.)
      * @throws InvalidIndexObjectException
      */
-    ANIterator subIterator( AnnotationFS const & an, EnIteratorAmbiguity enIsAmbiguous = enAmbiguous ) const;
+    ANIterator subIterator( AnnotationFS const & an, EnIteratorAmbiguity ambiguity = enAmbiguous ) const;
 
     /**
      * create an iterator over this index such that calling
diff --git a/src/cas/xcasdeserializer_handler.cpp b/src/cas/xcasdeserializer_handler.cpp
index 53012d7..c2f4807 100644
--- a/src/cas/xcasdeserializer_handler.cpp
+++ b/src/cas/xcasdeserializer_handler.cpp
@@ -353,7 +353,8 @@
       if (extsz > 256) {
         cout << "ACK!" << endl;
       }
-      const UChar* sofaID = attrs.getValue(ubuff);
+	  // Xerces deals with char type XMLCh so cast from/to our UChar (both are 16-bits)
+      const UChar* sofaID = (UChar*)attrs.getValue((XMLCh*)ubuff);
       if (0==UnicodeStringRef(sofaID).compare(icu::UnicodeString("_DefaultTextSofaName"))) {
         sofaID = ubuff;
       }
@@ -370,12 +371,12 @@
       if (extsz > 256) {
         cout << "ACK!" << endl;
       }
-      const UChar* aString = attrs.getValue(ubuff);
+      const UChar* aString = (UChar*)attrs.getValue((XMLCh*)ubuff);
       int thisSofaNum = atoi(UnicodeStringRef(aString).asUTF8().c_str());
 
       // get the sofa's FeatureStructure id
       icu::UnicodeString(ID_ATTR_NAME).extract(ubuff,256, errorCode);
-      aString = attrs.getValue(ubuff);
+      aString = (UChar*)attrs.getValue((XMLCh*)ubuff);
       int sofaFsId = atoi(UnicodeStringRef(aString).asUTF8().c_str());
 
       // for v1 and v2 formats, create the index map
diff --git a/src/cas/xmideserializer_handler.cpp b/src/cas/xmideserializer_handler.cpp
index 34fae1d..dbddd7b 100644
--- a/src/cas/xmideserializer_handler.cpp
+++ b/src/cas/xmideserializer_handler.cpp
@@ -593,7 +593,8 @@
 			if (extsz > 256) {
 				cout << "ACK!" << endl;
 			}
-			const UChar* sofaID = attrs.getValue(ubuff);
+			// Xerces deals with char type XMLCh so cast from/to our UChar (both are 16-bits)
+			const UChar* sofaID = (UChar*)attrs.getValue((XMLCh*)ubuff);
 
 			if (0==UnicodeStringRef(sofaID).compare(icu::UnicodeString("_DefaultTextSofaName"))) {  
 				// initial view Sofa always has sofaNum = 1
diff --git a/src/cas/xmiwriter.cpp b/src/cas/xmiwriter.cpp
index c462c8e..fd2c5bc 100644
--- a/src/cas/xmiwriter.cpp
+++ b/src/cas/xmiwriter.cpp
@@ -400,6 +400,7 @@
     }
   }
 
+  /*  Not used ?? ... also ID_ATTR_NAME is private
   template<class Array>
   void writeArray(ostream & os, Array const & array, char const * tag, int xmiid) {
     size_t i;
@@ -414,7 +415,8 @@
       //XCAS os << " size=\"0\"/>" << endl;
     }
   }
-
+  */
+  
   void XmiWriter::writeArray(ostream & os, 
                             FeatureStructure const & array, 
                             char const * tag, int xmiid) { 
diff --git a/src/framework/uima/strtools.hpp b/src/framework/uima/strtools.hpp
index f57a5a0..ac8e6f1 100644
--- a/src/framework/uima/strtools.hpp
+++ b/src/framework/uima/strtools.hpp
@@ -1671,8 +1671,8 @@
     size_t                  pos
   ) {
     const BASIC_STRING_TEMPLATE ENV_VAR = "$ENV(";
-    unsigned int envBegPos = s.find(ENV_VAR, pos);
-    unsigned int envEndPos;
+    size_t envBegPos = s.find(ENV_VAR, pos);
+    size_t envEndPos;
     if (envBegPos != STRING_NPOS) {
       envEndPos = s.find(')', envBegPos+1);
       if (envEndPos != STRING_NPOS) {
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
index 7a45dfa..0339919 100644
--- a/src/test/Makefile.am
+++ b/src/test/Makefile.am
@@ -94,7 +94,8 @@
 #   Otherwise we get: object `tt_types.$(OBJEXT)' created both with libtool and without
 #
 
-LT_FLAGS = -avoid-version -module -rpath /somewhere
+# Removed -module from LT_FLAGS as it produced .so instead of .dylib files on OSX
+LT_FLAGS = -avoid-version -rpath /somewhere
 
 libtoknz_la_SOURCES  = src/annotator_tok.cpp
 libtoknz_la_SOURCES += src/ss_tokenizer.cpp
diff --git a/src/test/fvt.sh b/src/test/fvt.sh
index 4d2ba9e..0a25a48 100755
--- a/src/test/fvt.sh
+++ b/src/test/fvt.sh
@@ -24,7 +24,8 @@
  Testbin=.libs
 
 export LD_LIBRARY_PATH=$Testlib:$APR_HOME/lib:$ICU_HOME/lib:$XERCES_HOME/lib:$UIMACPP_HOME/lib
-export DYLD_LIBRARY_PATH=$Testlib:$APR_HOME/lib:$ICU_HOME/lib:$XERCES_HOME/lib:$UIMACPP_HOME/lib
+# OSX does not allow DYLD_LIBRARY_PATH to be propagated in the environment
+export OSX_LIBRARYPATH=$Testlib:$APR_HOME/lib:$ICU_HOME/lib:$XERCES_HOME/lib:$UIMACPP_HOME/lib:$UIMACPP_HOME/dependencies/lib
 export PATH=$Testbin:$PATH
 
 export UIMACPP_DATAPATH=./data
diff --git a/src/test/fvtTestfile b/src/test/fvtTestfile
index c4df9c8..f100190 100644
--- a/src/test/fvtTestfile
+++ b/src/test/fvtTestfile
@@ -15,6 +15,12 @@
 # limitations under the License.
 # ---------------------------------------------------------------------------
 
+# OSX removes DYLD_LIBRARY_PATH from the environment so set it for each call
+uname = ${shell "uname" "-s"}
+ifeq "$(uname)" "Darwin"
+	 DEBUG_FVT := DYLD_LIBRARY_PATH=$(OSX_LIBRARYPATH) $(DEBUG_FVT)
+endif
+
 all:	cas sofa engine typepriority language iterators casserializer primitivetypes xcasdeserialization xmideserialization jni
 
 cas:
diff --git a/src/utils/ActiveMQAnalysisEngineService.cpp b/src/utils/ActiveMQAnalysisEngineService.cpp
index 7f3dc2b..d881098 100644
--- a/src/utils/ActiveMQAnalysisEngineService.cpp
+++ b/src/utils/ActiveMQAnalysisEngineService.cpp
@@ -960,7 +960,7 @@
         int payload = textMessage->getIntProperty("Payload");
         //get the text in the payload 
         string text = textMessage->getText().c_str();
-        UnicodeString utext(text.c_str());
+		icu::UnicodeString utext(text.c_str());
 		text = UnicodeStringRef(utext).asUTF8();
         astr.str("");
         astr << "Payload: " << payload << " Content: " << text ;
@@ -1280,8 +1280,8 @@
         uima::ResourceManager::createInstance("ActiveMQAnalysisEngineService");
       }
       ErrorInfo errInfo;
-      UnicodeString ustr(this->iv_aeDescriptor.c_str());
-      UnicodeString ufn = ResourceManager::resolveFilename(ustr,ustr);
+	  icu::UnicodeString ustr(this->iv_aeDescriptor.c_str());
+	  icu::UnicodeString ufn = ResourceManager::resolveFilename(ustr,ustr);
 
       //create a AnalysisEngine and CAS for each instance
       for (int i=0; i < iv_numInstances; i++) {