Merge branch 'master' of github.com:openwhisk/WhiskSwiftTools
diff --git a/WhiskSwiftTools.xcodeproj/project.xcworkspace/xcshareddata/WhiskSwiftTools.xcscmblueprint b/WhiskSwiftTools.xcodeproj/project.xcworkspace/xcshareddata/WhiskSwiftTools.xcscmblueprint
index 7bdb018..5b66749 100644
--- a/WhiskSwiftTools.xcodeproj/project.xcworkspace/xcshareddata/WhiskSwiftTools.xcscmblueprint
+++ b/WhiskSwiftTools.xcodeproj/project.xcworkspace/xcshareddata/WhiskSwiftTools.xcscmblueprint
@@ -1,16 +1,16 @@
 {
-  "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "C5EB0B156F4DC85EFDAB7971E2BB190CF3C28D25",
+  "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "E9057848A6186DD9CAE5574816428252CA2E16CD",
   "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : {
 
   },
   "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : {
     "65E71B0513DBFB09F39CEEF3A8B769CB93E66994" : 0,
-    "C5EB0B156F4DC85EFDAB7971E2BB190CF3C28D25" : 0
+    "E9057848A6186DD9CAE5574816428252CA2E16CD" : 0
   },
   "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "06E1D60A-07E3-45BC-8101-A3D050C33727",
   "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
     "65E71B0513DBFB09F39CEEF3A8B769CB93E66994" : "WhiskSwiftTools\/WhiskSwiftTools\/ZipArchive\/",
-    "C5EB0B156F4DC85EFDAB7971E2BB190CF3C28D25" : "WhiskSwiftTools\/"
+    "E9057848A6186DD9CAE5574816428252CA2E16CD" : "WhiskSwiftTools\/"
   },
   "DVTSourceControlWorkspaceBlueprintNameKey" : "WhiskSwiftTools",
   "DVTSourceControlWorkspaceBlueprintVersion" : 204,
@@ -24,7 +24,7 @@
     {
       "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:paulcastro\/WhiskSwiftTools.git",
       "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
-      "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "C5EB0B156F4DC85EFDAB7971E2BB190CF3C28D25"
+      "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "E9057848A6186DD9CAE5574816428252CA2E16CD"
     }
   ]
 }
\ No newline at end of file
diff --git a/WhiskSwiftTools/ProjectManager.swift b/WhiskSwiftTools/ProjectManager.swift
index 2d0006b..5a1160a 100644
--- a/WhiskSwiftTools/ProjectManager.swift
+++ b/WhiskSwiftTools/ProjectManager.swift
@@ -48,10 +48,10 @@
             queue.async(qos: .userInitiated) {
                 do {
                     self.projectReader?.clearAll()
-                    
+
+                    try self.projectReader?.readRootDependencies(clone: true)
                     try self.projectReader?.readProjectDirectory()
-                    try self.projectReader?.readDependencies()
-                    
+                                        
                     self.projectReader?.dumpProjectStructure()
                     
                     try self.installPackages()
@@ -92,8 +92,8 @@
                 do {
                     self.projectReader?.clearAll()
                     
+                    try self.projectReader?.readRootDependencies(clone: false)
                     try self.projectReader?.readProjectDirectory()
-                    try self.projectReader?.readDependencies()
                     self.projectReader?.dumpProjectStructure()
                     
                     try self.deleteRules()
diff --git a/WhiskSwiftTools/ProjectReader.swift b/WhiskSwiftTools/ProjectReader.swift
index 9910c4b..dfc434e 100644
--- a/WhiskSwiftTools/ProjectReader.swift
+++ b/WhiskSwiftTools/ProjectReader.swift
@@ -183,6 +183,40 @@
         
     }
     
+    public func readRootDependencies(clone: Bool) throws {
+        
+        let path = projectPath+"/"+BindingsFileName
+        let json = try ManifestReader.parseJson(atPath: path)
+        
+        
+        if let dependencies = json["dependencies"] {
+            for dependency in dependencies as! Array<[String:AnyObject]> {
+                guard let url = dependency["url"] as? NSString else {
+                    clearAll()
+                    throw WhiskProjectError.MalformedManifestFile(name: path as String, cause: "Declaration of dependency missing url")
+                }
+                
+                var repo = url
+                
+                if url.pathExtension == "git" {
+                    repo = String((repo as String).characters.dropLast(4))
+                }
+                
+                let name = repo.lastPathComponent
+                
+                var ver = "master"
+                if let version = dependency["version"] as? NSString {
+                    ver = version as String
+                }
+                
+                let dep = Dependency(name: name as NSString, url: repo, version: ver)
+                dependenciesDict[name] = dep
+            }
+        }
+        
+        try readDependencies(clone: clone)
+    }
+    
     public func readProjectDirectory() throws {
         // read project directory
         try readDirectory(dirPath: projectPath, isDependency: false)
@@ -190,14 +224,16 @@
         // read independent directories
     }
     
-    public func readDependencies() throws {
+    public func readDependencies(clone: Bool) throws {
         for (name, dependency) in dependenciesDict {
             
             let group = DispatchGroup()
             
             let zipFilePath = "\(dependency.url)/archive/\(dependency.version).zip"
-            try Git.cloneGitRepo(repo: zipFilePath, toPath: projectPath+"/Packages/", group: group)
-
+            if clone == true {
+                try Git.cloneGitRepo(repo: zipFilePath, toPath: projectPath+"/Packages/", group: group)
+            }
+            
             switch group.wait(timeout: DispatchTime.distantFuture) {
             case DispatchTimeoutResult.Success:
                 print("Clone repo \(dependency.url) success")
@@ -355,6 +391,7 @@
             
             // Check these items for a root manifest only
             if prefix == "" {
+                
                 // process packages
                 if let packages = json["bindings"] {
                     for package in packages as! Array<[String:AnyObject]> {
@@ -402,31 +439,6 @@
                     }
                     
                 }
-                
-                if let dependencies = json["dependencies"] {
-                    for dependency in dependencies as! Array<[String:AnyObject]> {
-                        guard let url = dependency["url"] as? NSString else {
-                            clearAll()
-                            throw WhiskProjectError.MalformedManifestFile(name: path as String, cause: "Declaration of dependency missing url")
-                        }
-                        
-                        var repo = url
-                        
-                        if url.pathExtension == "git" {
-                            repo = String((repo as String).characters.dropLast(4))
-                        }
-                        
-                        let name = repo.lastPathComponent
-                        
-                        var ver = "master"
-                        if let version = dependency["version"] as? NSString {
-                            ver = version as String
-                        }
-                        
-                        let dep = Dependency(name: name as NSString, url: repo, version: ver)
-                        dependenciesDict[name] = dep
-                    }
-                }
             }
             
             
@@ -491,6 +503,7 @@
         sequenceDict.removeAll()
         manifestDict.removeAll()
         bindingsDict.removeAll()
+        dependenciesDict.removeAll()
     }
 }
 
diff --git a/WhiskSwiftTools/WhiskAPI.swift b/WhiskSwiftTools/WhiskAPI.swift
index d3706f2..cd24eb2 100644
--- a/WhiskSwiftTools/WhiskAPI.swift
+++ b/WhiskSwiftTools/WhiskAPI.swift
@@ -347,17 +347,17 @@
             } else {
                 print("Disable response for rule \(name): \(response)")
                 
-                DispatchQueue.main.after(when: DispatchTime.now() + 2.0) {
+                group.enter()
+                //DispatchQueue.main.after(when: DispatchTime.now() + 0.5) {
                     
                     do {
-                        group.enter()
                         try self.networkManager.deleteCall(url: urlStr, path: path, group: group)
                     } catch {
                         print("Error deleting rule \(name), error: \(error)")
                     }
                     
                     
-                }
+               // }
             }
             
         }
@@ -470,7 +470,7 @@
         
     }
     
-    func postCall(url: String, path: String, parameters: [String:AnyObject]?, group: DispatchGroup, callback: (response: [String:Any]?, error: ErrorProtocol?) -> Void) throws {
+    func postCall(url: String, path: String, parameters: [String:AnyObject]?, group: DispatchGroup?, callback: (response: [String:Any]?, error: ErrorProtocol?) -> Void) throws {
         
         // encode path
         guard let encodedPath = path.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed) else {
@@ -512,7 +512,9 @@
                 callback(response: ["status":statusCode, "description":"Post call success"], error: nil)
             }
             
-            group.leave()
+            if let group = group {
+                group.leave()
+            }
             
         }