Automate the JVM pre-caching of classes for a given profile (#290)

* Automate the JVM pre-caching of classes for a given profile

* Execute pre-cache and accunt for Linux base64 enc. diffs.

* Execute pre-cache and accunt for Linux base64 enc. diffs.

* Remove files with typos
diff --git a/knative-build/runtimes/java/core/java8/proxy/buildProfileClasses.sh b/knative-build/runtimes/java/core/java8/proxy/buildProfileClasses.sh
index a251888..e8b1976 100755
--- a/knative-build/runtimes/java/core/java8/proxy/buildProfileClasses.sh
+++ b/knative-build/runtimes/java/core/java8/proxy/buildProfileClasses.sh
@@ -21,7 +21,14 @@
 # Clean out previous build artifacts
  ./clean_all.sh
 
- # Create new build artifacts
+ # Create new build artifacts (e.g., JAR, ZIP, and their base64 encodings)
  ./build_all.sh
 
+ # Update the HTTP (body) payloads for OW and Knative (with base64 encoded archives)
+./update_payloads.sh
+
+# execute the functions that will cause the JVM cache to be populated for the profile
+# (e.g., invoke the /init and /run methods for each profile's "test" functions).
+./exec_tests.sh
+
  cd ../../..
diff --git a/knative-build/runtimes/java/core/java8/proxy/compileClassCache.sh b/knative-build/runtimes/java/core/java8/proxy/compileClassCache.sh
index 5ecc9b0..581375e 100755
--- a/knative-build/runtimes/java/core/java8/proxy/compileClassCache.sh
+++ b/knative-build/runtimes/java/core/java8/proxy/compileClassCache.sh
@@ -15,7 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-set -x
+set +x
 
 # Standard Options:
 # ================
@@ -38,6 +38,7 @@
 # #### Construct Class Cache with HTTP Server classes by starting the server ####
 JAVA_EXTENDED_OPTIONS="-Xshareclasses:cacheDir=/javaSharedCache/ -Xquickstart"
 JAVA_VERBOSE_OPTIONS="-verbose:class -verbose:sizes"
+#JAVA_VERBOSE_OPTIONS=""
 JAVA_JVM_KILL_DELAY=5s
 
 export OW_ALLOW_MULTIPLE_INIT=true
@@ -45,7 +46,13 @@
 echo "Creating shared class cache with Proxy and 'base' profile libraries..."
 java $JAVA_VERBOSE_OPTIONS $JAVA_STANDARD_OPTIONS $JAVA_EXTENDED_OPTIONS "-jar" "/javaAction/build/libs/javaAction-all.jar" &
 HTTP_PID=$!
+
+echo "Building pre-cache functions and executing..."
+./buildProfileClasses.sh
+
 echo "Sleeping (${JAVA_JVM_KILL_DELAY}) allowing cache to be populated before killing JVM process (${HTTP_PID})..."
 sleep $JAVA_JVM_KILL_DELAY
 echo "Killing JVM process (${HTTP_PID})..."
 kill $HTTP_PID
+
+unset OW_ALLOW_MULTIPLE_INIT
diff --git a/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/build_all.sh b/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/build_all.sh
index ba2cdd5..667f92c 100755
--- a/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/build_all.sh
+++ b/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/build_all.sh
@@ -28,7 +28,13 @@
         echo "Creating JAR..."
         jar cvf hello.jar *.class
         echo "Base64 encoding JAR..."
-        base64 hello.jar > hello.jar.base64
+        unameOut="$(uname -s)"
+        case "${unameOut}" in
+            Linux*)   B64_WRAP="-w0";;
+            Darwin*)  B64_WRAP="";;
+        esac
+        #base64 -w0 hello.jar > hello.jar.base64
+        base64 $B64_WRAP hello.jar > hello.jar.base64
         cd ..
     fi
 done
diff --git a/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/clean_all.sh b/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/clean_all.sh
index f38bed3..fd8d5ed 100755
--- a/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/clean_all.sh
+++ b/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/clean_all.sh
@@ -23,7 +23,7 @@
         echo "Cleaning up build artifacts for test: '${f}'"
         cd $f
         rm Hello.class
-        rm Hello.jar
+        rm hello.jar
         rm hello.jar.base64
         rm openwhisk-data-init.json
         rm knative-data-init.json
diff --git a/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/exec_tests.sh b/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/exec_tests.sh
index 5db373a..2590675 100755
--- a/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/exec_tests.sh
+++ b/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/exec_tests.sh
@@ -22,12 +22,8 @@
     if [ -d ${f} ]; then
         echo "Updating 'code' payload with base64 encoded archive data: ${f}"
         cd $f
-            sed "s#BASE64_ENCODED_JAR#$(cat hello.jar.base64)#" openwhisk-data-init.json.tmpl > openwhisk-data-init.json
-            sed "s#BASE64_ENCODED_JAR#$(cat hello.jar.base64)#" knative-data-init.json.tmpl > knative-data-init.json
-            sed "s#BASE64_ENCODED_JAR#$(cat hello.jar.base64)#" knative-data-init-run.json.tmpl > native-data-init-run.json
-            sed "s#BASE64_ENCODED_JAR#$(cat hello.jar.base64)#" payload-knative-init.http.tmpl > payload-knative-init.http
-            sed "s#BASE64_ENCODED_JAR#$(cat hello.jar.base64)#" payload-knative-init-run.http.tmpl > payload-knative-init-run.http
-            sed "s#BASE64_ENCODED_JAR#$(cat hello.jar.base64)#" payload-openwhisk-init.http.tmpl > payload-openwhisk-init.http
+            curl -d "@openwhisk-data-init.json" -H "Content-Type: application/json" -X POST http://localhost:8080/init
+            curl -d "@openwhisk-data-run.json" -H "Content-Type: application/json" -X POST http://localhost:8080/run
         cd ..
     fi
 done
diff --git a/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/helloworld/native-data-init-run.json b/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/helloworld/native-data-init-run.json
deleted file mode 100644
index 30282d3..0000000
--- a/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/helloworld/native-data-init-run.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
-  "init": {
-    "name": "java-helloworld",
-    "main": "Hello",
-    "binary": true,
-    "code" : "UEsDBBQACAgIAA18LU8AAAAAAAAAAAAAAAAJAAQATUVUQS1JTkYv/soAAAMAUEsHCAAAAAACAAAAAAAAAFBLAwQUAAgICAANfC1PAAAAAAAAAAAAAAAAFAAAA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If4BAACRAwAACwAAAAAAAAAAAAAAAADAAAAASGVsbG8uY2xhc3NQSwUGAAAAAAMAAwC2AAAA9wIAAAAA"
-  },
-  "activation": {
-    "namespace": "default",
-    "action_name": "java-helloworld",
-    "api_host": "",
-    "api_key": "",
-    "activation_id": "",
-    "deadline": "4102498800000"
-  },
-  "value": {
-  }
-}
diff --git a/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/helloworldwithparams/native-data-init-run.json b/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/helloworldwithparams/native-data-init-run.json
deleted file mode 100644
index 752b692..0000000
--- a/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/helloworldwithparams/native-data-init-run.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
-    "init": {
-        "name" : "java-helloworld-with-params",
-        "main" : "Hello",
-        "binary": true,
-        "code" : "UEsDBBQACAgIAA18LU8AAAAAAAAAAAAAAAAJAAQATUVUQS1JTkYv/soAAAMAUEsHCAAAAAACAAAAAAAAAFBLAwQUAAgICAANfC1PAAAAAAAAAAAAAAAAFAAAAE1FVEEtSU5GL01BTklGRVNULk1G803My0xLLS7RDUstKs7Mz7NSMNQz4OVyLkpNLElN0XWqBAlY6BnEGxkYKWi4JudkFhSnKvgXpOZ5WWrycvFyAQBQSwcIMFMkp0EAAABBAAAAUEsDBBQACAgIAA18LU8AAAAAAAAAAAAAAAALAAAASGVsbG8uY2xhc3N9Uu1uEkEUPcPXLssiuG2t1KJQtQUKRW39KrW1mhhjoDbBNFHjjwHG7db9IMtS46P4BP7VPzSxiQ/gO2m8s4omlXZn986dO2fPOXMz339+/QZgDdsaZlBQUVSxoOKqhiSuyXBdwyKWVJQUlOWaIBUFyxp0mVblXFOxoqIu0xsSclPBLQWrDIkNy7WCTYZoqbzHEHvs9QRDpmm5YmfodIT/gndsqsQcbrkM66Vm13PqpueZtqibA8+tP6PwvHMgukGjfNYmQ7od8O67Fu+HnArWGLS2N/S74oklNbSnwra9lQN+yHVcwCyDOgh87prCZ0gOPEe83xe+NONyR+i4jTs67uKegvs61kEK8b7NuwSYO90HkZq+EIHlmgyzUqtuk0S9HfhUejS07J6US4ReCjo28IBWhbe+5xQYWFHHJho6tvCQ5EIQQ/YfzVgke5KZOrzPBwwzpebJrUb5FYNhimB7IH3u+pZjBdYhnWN1Enhik//+RF3InwlgSIVSY1vTpfL/InRk3u8Lt8dQm+jhlMbRj2rgjalTvNfb9b2+8IMPDEsTiCZQ76GIabro8omAyYtA8SKt8jQzmuOVI7AvlDDkKCbC4hTd6jlc+gP9hBgN4I0RaRrRVsWIjRD/iHSYJEZQmhVDHZfU36XWMZIvj6Dt1IzUMXRK08a5ETLL9BlZClWZnKcwgjHCVO1z6FBaWCRxkOcouU2Q3wyZyNFYIEtVMrWGebwm//OE0hH5gZyCPL0G2b0cslz5BVBLBwistPL2OQIAAOYDAABQSwECFAAUAAgICAANfC1PAAAAAAIAAAAAAAAACQAEAAAAAAAAAAAAAAAAAAAATUVUQS1JTkYv/soAAFBLAQIUABQACAgIAA18LU8wUySnQQAAAEEAAAAUAAAAAAAAAAAAAAAAAD0AAABNRVRBLUlORi9NQU5JRkVTVC5NRlBLAQIUABQACAgIAA18LU+stPL2OQIAAOYDAAALAAAAAAAAAAAAAAAAAMAAAABIZWxsby5jbGFzc1BLBQYAAAAAAwADALYAAAAyAwAAAAA="
-    },
-    "activation": {
-        "namespace": "default",
-        "action_name": "java-helloworld-with-params",
-        "api_host": "",
-        "api_key": "",
-        "activation_id": "",
-        "deadline": "4102498800000"
-    },
-    "value": {
-        "name" : "Joe",
-        "place" : "TX"
-    }
-}
diff --git a/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/helloworldwithparamsfromenv/native-data-init-run.json b/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/helloworldwithparamsfromenv/native-data-init-run.json
deleted file mode 100644
index ca94e97..0000000
--- a/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/helloworldwithparamsfromenv/native-data-init-run.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
-    "init": {
-        "name" : "java-helloworld-with-params-from-env",
-        "main" : "Hello",
-        "binary": true,
-        "code" : "UEsDBBQACAgIAA58LU8AAAAAAAAAAAAAAAAJAAQATUVUQS1JTkYv/soAAAMAUEsHCAAAAAACAAAAAAAAAFBLAwQUAAgICAAOfC1PAAAAAAAAAAAAAAAAFAAAAE1FVEEtSU5GL01BTklGRVNULk1G803My0xLLS7RDUstKs7Mz7NSMNQz4OVyLkpNLElN0XWqBAlY6BnEGxkYKWi4JudkFhSnKvgXpOZ5WWrycvFyAQBQSwcIMFMkp0EAAABBAAAAUEsDBBQACAgIAA58LU8AAAAAAAAAAAAAAAALAAAASGVsbG8uY2xhc3ONUttu00AUnNMmsesaWtzQGxQSLq3TNjW3Jwo8gIQQCgUpqBKPm/hgubJ3I9ep1L+ClxRRiQ/goxBnQ7kIAsKWZ2dnz5lZ2/v5y8dPAO7hrocLWHVxycNlrLm44uCqh6qVGg6aHlxLr9nxuosbLm5aum5LNhyEDlqE2oNUp+UjwnTY2idUnpiYCXOdVPPeMO9x8Vr1MlEquUo14X7Y6Zs8SoxJMo6SQ6Oj5wIvewfcL3db/1okeF0zLPr8NLWG3jPOMrNzoI6UjwALEqFVzg42fWxhm1AdZKovhat/9yS4ScFcpjohLFmrKFM6ibplIdLjYZrFXMg7jqMaPtrYkVnjbWHyBoGaPiLc8nEbdyRuXESY/2nzPeQXqXt8WHIuJgmXrI8I62Hn91z5DH9I0qEGA9Yxof1fHWebl0a3NN8kQj2caD2r4vhVYQZclMeEjQn+ExL30cS8nB97TYHsLxCsy2xNRpKxunkCei+EcFGwNhYXMINFLJ2VMipyAw+DqQ+Y7gQVwRenqL45QW2vHTincIXOBN4Is1vyBL7AtiXnBEY4P8Jc+92PiEU5mRBWE+ZLSB3L2MWKrC6Pd7nyFVBLBwhnUa6bvgEAAPsCAABQSwECFAAUAAgICAAOfC1PAAAAAAIAAAAAAAAACQAEAAAAAAAAAAAAAAAAAAAATUVUQS1JTkYv/soAAFBLAQIUABQACAgIAA58LU8wUySnQQAAAEEAAAAUAAAAAAAAAAAAAAAAAD0AAABNRVRBLUlORi9NQU5JRkVTVC5NRlBLAQIUABQACAgIAA58LU9nUa6bvgEAAPsCAAALAAAAAAAAAAAAAAAAAMAAAABIZWxsby5jbGFzc1BLBQYAAAAAAwADALYAAAC3AgAAAAA="
-    },
-    "activation": {
-        "namespace": "default",
-        "action_name": "java-helloworld-with-params-from-env",
-        "api_host": "",
-        "api_key": "",
-        "activation_id": "",
-        "deadline": "4102498800000"
-    },
-    "value": {
-        "name" : "Jess",
-        "place" : "OK"
-    }
-}
diff --git a/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/update_payloads.sh b/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/update_payloads.sh
index 5db373a..6d73a6e 100755
--- a/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/update_payloads.sh
+++ b/knative-build/runtimes/java/core/java8/proxy/profiles/base/tests/update_payloads.sh
@@ -24,7 +24,7 @@
         cd $f
             sed "s#BASE64_ENCODED_JAR#$(cat hello.jar.base64)#" openwhisk-data-init.json.tmpl > openwhisk-data-init.json
             sed "s#BASE64_ENCODED_JAR#$(cat hello.jar.base64)#" knative-data-init.json.tmpl > knative-data-init.json
-            sed "s#BASE64_ENCODED_JAR#$(cat hello.jar.base64)#" knative-data-init-run.json.tmpl > native-data-init-run.json
+            sed "s#BASE64_ENCODED_JAR#$(cat hello.jar.base64)#" knative-data-init-run.json.tmpl > knative-data-init-run.json
             sed "s#BASE64_ENCODED_JAR#$(cat hello.jar.base64)#" payload-knative-init.http.tmpl > payload-knative-init.http
             sed "s#BASE64_ENCODED_JAR#$(cat hello.jar.base64)#" payload-knative-init-run.http.tmpl > payload-knative-init-run.http
             sed "s#BASE64_ENCODED_JAR#$(cat hello.jar.base64)#" payload-openwhisk-init.http.tmpl > payload-openwhisk-init.http