<NME> merge_services_files.sh
<BEF> ADDFILE
<MSG> Merge java service files in META-INF/services of 3rdparty jars

Lucene 4.x and ElasticSearch 0.90.0 have some service files with naming conflicts if put them in a single jar.

<DFF> @@ -0,0 +1,38 @@
+#!/bin/bash
+
+build_jar=build/jar
+build_services=build/META-INF/services
+build_monolith=${1}
+shift
+
+mkdir -p ${build_jar}
+
+# echo "******$(pwd)"
+# echo "******${build_monolith}"
+
+# Unpack META-INF/services in jars into individual directories
+for jar in $(find "$@" -name \*.jar)
+do
+    # echo "******${jar}"
+    dir="${jar##*/}"
+    mkdir -p "${build_jar}/${dir}"
+    pushd "${build_jar}/${dir}" &>/dev/null
+    jar xf "../../../${jar}" META-INF/services
+    popd &>/dev/null
+done
+
+# Merge all files under META-INF/services in jars
+mkdir -p ${build_services}
+rm -f ${build_services}/*
+for src in $(find ${build_jar} -type f)
+do
+    dest=${src##*/}
+    if [ -e "${build_services}/${dest}" ]
+    then
+	cat "${src}" >> "${build_services}/${dest}"
+    else
+	cp "${src}" ${build_services}
+    fi
+done
+
+cp -f ${build_services}/* ${build_monolith}/META-INF/services/

Merge java service files in META-INF/services of 3rdparty jars