cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [2/8] git commit: Support extension handlers for urls
Date Tue, 30 Apr 2013 15:03:58 GMT
Support extension handlers for urls


Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/911968cd
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/911968cd
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/911968cd

Branch: refs/heads/master
Commit: 911968cdd2fd2639f043707dd517fcf19c4f4011
Parents: af2861c
Author: Shravan Narayan <shravanrn@google.com>
Authored: Thu Apr 25 15:09:02 2013 -0400
Committer: Shravan Narayan <shravanrn@google.com>
Committed: Thu Apr 25 15:30:31 2013 -0400

----------------------------------------------------------------------
 packapp                      |   69 +++++++++++++++++++++++++++++++++++++
 www/index.html               |    1 +
 www/js/AddCtrl.js            |    4 +-
 www/js/AppsService.js        |   59 +++++++++++++++++--------------
 www/js/CdvhPackageHandler.js |   30 ++++++++++++++++
 www/views/add.html           |    4 +-
 zipapp                       |   69 -------------------------------------
 7 files changed, 137 insertions(+), 99 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/911968cd/packapp
----------------------------------------------------------------------
diff --git a/packapp b/packapp
new file mode 100755
index 0000000..d43ec5a
--- /dev/null
+++ b/packapp
@@ -0,0 +1,69 @@
+#!/bin/bash
+#       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.
+#
+# package a cordova project into a cdvh for app harness (zip file with a specific file and
folder layout)
+#
+# USAGE
+#   ./packapp project_directory [packageName.cdhv]
+#
+if [ $# -lt 1 ]
+then
+  echo "Usage: packapp project_directory [packageName.cdhv]"
+  exit -1
+fi
+
+ORIG_DIR=$(pwd)
+
+
+cd $1
+FILE_NAME=$(basename "`pwd`" ).cdvh
+
+if [ $# -ge 2 ]
+then
+    FILE_NAME=$2
+fi
+
+if [ -d "./platforms/android" ]
+then
+    echo "Platform: android found"
+    cp -f ./platforms/android/res/xml/config.xml ./app/config.android.xml
+    if [ -f "./app/config.android.xml" ]
+    then
+        echo "Platform: android added successfully"
+    else
+        echo "Unable to locate config.xml for android"
+    fi
+fi
+
+if [ -d "./platforms/ios" ]
+then
+    echo "Platform: ios found"
+    find ./platforms/ios/ -name config.xml -exec cp {} ./app/config.ios.xml \;
+    if [ -f "./app/config.ios.xml" ]
+    then
+        echo "Platform: ios added successfully"
+    else
+        echo "Unable to locate config.xml for ios"
+    fi
+fi
+
+
+cd ./app
+zip -r $ORIG_DIR/$FILE_NAME www config.*.xml
+
+rm config.*.xml
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/911968cd/www/index.html
----------------------------------------------------------------------
diff --git a/www/index.html b/www/index.html
index c897d14..89aff26 100644
--- a/www/index.html
+++ b/www/index.html
@@ -9,6 +9,7 @@
         <script type="text/javascript" src="js/AppConstants.js"></script>
         <script type="text/javascript" src="js/ResourcesLoader.js"></script>
         <script type="text/javascript" src="js/AppsService.js"></script>
+        <script type="text/javascript" src="js/CdvhPackageHandler.js"></script>
         <script type="text/javascript" src="js/ListCtrl.js"></script>
         <script type="text/javascript" src="js/AddCtrl.js"></script>
     </head>

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/911968cd/www/js/AddCtrl.js
----------------------------------------------------------------------
diff --git a/www/js/AddCtrl.js b/www/js/AddCtrl.js
index f828f54..a2f3b32 100644
--- a/www/js/AddCtrl.js
+++ b/www/js/AddCtrl.js
@@ -4,13 +4,13 @@
     myApp.controller("AddCtrl", ["$scope", "AppsService", function ($scope, AppsService)
{
 
         $scope.addApp = function(appName, appSource, appUrl) {
-            if(appSource === "urlToZip") {
+            if(appSource === "urlToPackage") {
                 if(!appUrl) {
                     alert("Url not specified");
                     return;
                 }
 
-                AppsService.addAppFromZipUrl(appName, appUrl)
+                AppsService.addAppFromUrl(appName, appUrl)
                 .then(function() {
                     alert("Successfully installed");
                 }, function(error) {

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/911968cd/www/js/AppsService.js
----------------------------------------------------------------------
diff --git a/www/js/AppsService.js b/www/js/AppsService.js
index eb60d28..6c6ecd1 100644
--- a/www/js/AppsService.js
+++ b/www/js/AppsService.js
@@ -4,9 +4,22 @@
     myApp.factory("AppsService", [ "ResourcesLoader", "INSTALL_DIRECTORY", "TEMP_DIRECTORY",
"APPS_JSON", "METADATA_JSON", function(ResourcesLoader, INSTALL_DIRECTORY, TEMP_DIRECTORY,
APPS_JSON, METADATA_JSON) {
 
         var platformId = cordova.require("cordova/platform").id;
+        // handlers that have registered to unpack certain extensions during the installation
of an app
+        var extensionHandlers = {};
+
+        function grabExtensionFromUrl(url) {
+            var lastSegment = url.split("#")[0].split("?")[0].split("/").pop();
+            var dotLocation = lastSegment.lastIndexOf(".");
+            var extension = "";
+            if(dotLocation !== -1) {
+                extension = lastSegment.substring(dotLocation + 1);
+            }
+            return extension;
+        }
 
         function addNewAppFromUrl(appName, appUrl) {
-            var fileName = TEMP_DIRECTORY + appName + ".zip";
+            var extension = grabExtensionFromUrl(appUrl);
+            var fileName = TEMP_DIRECTORY + appName + "." + extension;
             var _fullFilePath;
 
             return ResourcesLoader.deleteDirectory(INSTALL_DIRECTORY + appName)
@@ -18,35 +31,16 @@
                 return ResourcesLoader.ensureDirectoryExists(INSTALL_DIRECTORY + appName);
             })
             .then(function(directoryPath){
-                return extractZipToDirectory(_fullFilePath, directoryPath);
+                if(!extensionHandlers[extension]) {
+                    throw new Error("No handler for extension " + extension + " found");
+                }
+                return extensionHandlers[extension].extractPackageToDirectory(_fullFilePath,
directoryPath);
             })
             .then(function(){
-                return registerApp(appName, "urlToZip", appUrl);
+                return registerApp(appName, "urlToPackage", appUrl);
             });
         }
 
-        function extractZipToDirectory(fileName, outputDirectory){
-            var deferred = Q.defer();
-
-            //will throw an exception if the zip plugin is not loaded
-            try {
-                var onZipDone = function(returnCode) {
-                    if(returnCode !== 0) {
-                        deferred.reject(new Error("Something went wrong during the unzipping
of: " + fileName));
-                    } else {
-                        deferred.resolve();
-                    }
-                };
-
-                /* global zip */
-                zip.unzip(fileName, outputDirectory, onZipDone);
-            } catch(e) {
-                deferred.reject(e);
-            } finally {
-                return deferred.promise;
-            }
-        }
-
         function registerApp(appName, appSource, appUrl) {
             return ResourcesLoader.readJSONFileContents(APPS_JSON)
             .then(function(result){
@@ -126,7 +120,7 @@
                 });
             },
 
-            addAppFromZipUrl : function(appName, appUrl) {
+            addAppFromUrl : function(appName, appUrl) {
                 return this.getAppsList()
                 .then(function(appsList){
                     if(appsList.indexOf(appName) !== -1) {
@@ -171,6 +165,19 @@
                     }
                     return self.launchApp(settings.lastLaunched);
                 });
+            },
+
+            registerPackageHandler : function(extension, handler) {
+                if(!extension) {
+                    throw new Error("Expcted extension");
+                }
+                if(!handler || typeof(handler.extractPackageToDirectory) !== "function")
{
+                    throw new Error("Expected function for handler.extractPackageToDirectory
to exist");
+                }
+                if(handler[extension]) {
+                    throw new Error("Handler already exists for the extension: " + extension);
+                }
+                extensionHandlers[extension] = handler;
             }
         };
     }]);

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/911968cd/www/js/CdvhPackageHandler.js
----------------------------------------------------------------------
diff --git a/www/js/CdvhPackageHandler.js b/www/js/CdvhPackageHandler.js
new file mode 100644
index 0000000..152280d
--- /dev/null
+++ b/www/js/CdvhPackageHandler.js
@@ -0,0 +1,30 @@
+(function(){
+    "use strict";
+    /* global myApp */
+    myApp.run(["AppsService", function(AppsService){
+        AppsService.registerPackageHandler("cdvh", {
+            extractPackageToDirectory : function (fileName, outputDirectory){
+                var deferred = Q.defer();
+
+                //will throw an exception if the zip plugin is not loaded
+                try {
+                    var onZipDone = function(returnCode) {
+                        if(returnCode !== 0) {
+                            deferred.reject(new Error("Something went wrong during the unzipping
of: " + fileName));
+                        } else {
+                            deferred.resolve();
+                        }
+                    };
+
+                    /* global zip */
+                    zip.unzip(fileName, outputDirectory, onZipDone);
+                } catch(e) {
+                    deferred.reject(e);
+                } finally {
+                    return deferred.promise;
+                }
+            }
+        });
+    }]);
+
+})();
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/911968cd/www/views/add.html
----------------------------------------------------------------------
diff --git a/www/views/add.html b/www/views/add.html
index 3016d4b..ae2b2dd 100644
--- a/www/views/add.html
+++ b/www/views/add.html
@@ -6,8 +6,8 @@
     <span ng-show="addForm.appName.$error.maxlength">Too long</span>
     <br />
 
-    <input type="radio" ng-model="appSource" name="appSource" value="urlToZip" ng-init="appUrlChecked=true;
appSource='urlToZip'" ng-checked="appUrlChecked" />
-        <label for="inputAppUrl">Enter the URL(should point to a zip file)</label><br
/>
+    <input type="radio" ng-model="appSource" name="appSource" value="urlToPackage" ng-init="appUrlChecked=true;
appSource='urlToPackage'" ng-checked="appUrlChecked" />
+        <label for="inputAppUrl">Enter the URL to a file</label><br />
         <input id="inputAppUrl" type="url" name="appUrl" ng-model="appUrl" ng-disabled="!appUrlChecked"
ng-required="appUrlChecked" />
         <span ng-show="addForm.appUrl.$error.required">Required</span>
         <span ng-show="addForm.appUrl.$error.url">Not a URL</span>

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/911968cd/zipapp
----------------------------------------------------------------------
diff --git a/zipapp b/zipapp
deleted file mode 100755
index d4e8457..0000000
--- a/zipapp
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/bin/bash
-#       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.
-#
-# package a cordova project into a zip for app harness
-#
-# USAGE
-#   ./zipapp project_directory [zipfileName]
-#
-if [ $# -lt 1 ]
-then
-  echo "Usage: zipapp project_directory [zipfileName]"
-  exit -1
-fi
-
-ORIG_DIR=$(pwd)
-
-
-cd $1
-FILE_NAME=$(basename "`pwd`" ).zip
-
-if [ $# -ge 2 ]
-then
-    FILE_NAME=$2
-fi
-
-if [ -d "./platforms/android" ]
-then
-    echo "Platform: android found"
-    cp -f ./platforms/android/res/xml/config.xml ./app/config.android.xml
-    if [ -f "./app/config.android.xml" ]
-    then
-        echo "Platform: android added successfully"
-    else
-        echo "Unable to locate config.xml for android"
-    fi
-fi
-
-if [ -d "./platforms/ios" ]
-then
-    echo "Platform: ios found"
-    find ./platforms/ios/ -name config.xml -exec cp {} ./app/config.ios.xml \;
-    if [ -f "./app/config.ios.xml" ]
-    then
-        echo "Platform: ios added successfully"
-    else
-        echo "Unable to locate config.xml for ios"
-    fi
-fi
-
-
-cd ./app
-zip -r $ORIG_DIR/$FILE_NAME www config.*.xml
-
-rm config.*.xml
\ No newline at end of file


Mime
View raw message