cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaz...@apache.org
Subject mac commit: Added ShellUtils for plugins to use.
Date Wed, 10 Apr 2013 00:55:46 GMT
Updated Branches:
  refs/heads/master 084578c12 -> 3eab1090b


Added ShellUtils for plugins to use.


Project: http://git-wip-us.apache.org/repos/asf/cordova-osx/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-osx/commit/3eab1090
Tree: http://git-wip-us.apache.org/repos/asf/cordova-osx/tree/3eab1090
Diff: http://git-wip-us.apache.org/repos/asf/cordova-osx/diff/3eab1090

Branch: refs/heads/master
Commit: 3eab1090beeb6ed0ccff0d1e9b2b88f05044388a
Parents: 084578c
Author: Shazron Abdullah <shazron@apache.org>
Authored: Tue Apr 9 17:55:52 2013 -0700
Committer: Shazron Abdullah <shazron@apache.org>
Committed: Tue Apr 9 17:55:52 2013 -0700

----------------------------------------------------------------------
 .../CordovaFramework.xcodeproj/project.pbxproj     |   10 ++
 .../CordovaFramework/Classes/Utils/ShellUtils.h    |   32 +++++++
 .../CordovaFramework/Classes/Utils/ShellUtils.m    |   73 +++++++++++++++
 3 files changed, 115 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/3eab1090/CordovaFramework/CordovaFramework.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/CordovaFramework/CordovaFramework.xcodeproj/project.pbxproj b/CordovaFramework/CordovaFramework.xcodeproj/project.pbxproj
index 1a93e74..ea990fa 100644
--- a/CordovaFramework/CordovaFramework.xcodeproj/project.pbxproj
+++ b/CordovaFramework/CordovaFramework.xcodeproj/project.pbxproj
@@ -68,6 +68,9 @@
 		7E4C0AF916EAA2AD00542982 /* NSWindow+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef
= 7E4C0AC516EAA2AD00542982 /* NSWindow+Utils.m */; };
 		7E4C0AFB16EAA35300542982 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile;
fileRef = 7E4C0AFA16EAA35300542982 /* SystemConfiguration.framework */; };
 		7E4C0AFD16EAA36400542982 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef
= 7E4C0AFC16EAA36400542982 /* WebKit.framework */; };
+		7EE6E73D1714E77C0051492C /* ShellUtils.h in Headers */ = {isa = PBXBuildFile; fileRef =
7EE6E73B1714E77C0051492C /* ShellUtils.h */; };
+		7EE6E73E1714E77C0051492C /* ShellUtils.m in Sources */ = {isa = PBXBuildFile; fileRef =
7EE6E73C1714E77C0051492C /* ShellUtils.m */; };
+		7EE6E73F1714E77C0051492C /* ShellUtils.m in Sources */ = {isa = PBXBuildFile; fileRef =
7EE6E73C1714E77C0051492C /* ShellUtils.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -133,6 +136,8 @@
 		7E4C0AC516EAA2AD00542982 /* NSWindow+Utils.m */ = {isa = PBXFileReference; fileEncoding
= 4; lastKnownFileType = sourcecode.c.objc; path = "NSWindow+Utils.m"; sourceTree = "<group>";
};
 		7E4C0AFA16EAA35300542982 /* SystemConfiguration.framework */ = {isa = PBXFileReference;
lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework;
sourceTree = SDKROOT; };
 		7E4C0AFC16EAA36400542982 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType
= wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework;
sourceTree = SDKROOT; };
+		7EE6E73B1714E77C0051492C /* ShellUtils.h */ = {isa = PBXFileReference; fileEncoding = 4;
lastKnownFileType = sourcecode.c.h; path = ShellUtils.h; sourceTree = "<group>"; };
+		7EE6E73C1714E77C0051492C /* ShellUtils.m */ = {isa = PBXFileReference; fileEncoding = 4;
lastKnownFileType = sourcecode.c.objc; path = ShellUtils.m; sourceTree = "<group>";
};
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -287,6 +292,8 @@
 				7E4C0AC316EAA2AD00542982 /* NSData+Base64.m */,
 				7E4C0AC416EAA2AD00542982 /* NSWindow+Utils.h */,
 				7E4C0AC516EAA2AD00542982 /* NSWindow+Utils.m */,
+				7EE6E73B1714E77C0051492C /* ShellUtils.h */,
+				7EE6E73C1714E77C0051492C /* ShellUtils.m */,
 			);
 			name = Utils;
 			path = Classes/Utils;
@@ -319,6 +326,7 @@
 				7E4C0AF116EAA2AD00542982 /* CDVReachability.h in Headers */,
 				7E4C0AF416EAA2AD00542982 /* NSData+Base64.h in Headers */,
 				7E4C0AF716EAA2AD00542982 /* NSWindow+Utils.h in Headers */,
+				7EE6E73D1714E77C0051492C /* ShellUtils.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -445,6 +453,7 @@
 				7E4C0AF216EAA2AD00542982 /* CDVReachability.m in Sources */,
 				7E4C0AF516EAA2AD00542982 /* NSData+Base64.m in Sources */,
 				7E4C0AF816EAA2AD00542982 /* NSWindow+Utils.m in Sources */,
+				7EE6E73E1714E77C0051492C /* ShellUtils.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -469,6 +478,7 @@
 				7E4C0AF316EAA2AD00542982 /* CDVReachability.m in Sources */,
 				7E4C0AF616EAA2AD00542982 /* NSData+Base64.m in Sources */,
 				7E4C0AF916EAA2AD00542982 /* NSWindow+Utils.m in Sources */,
+				7EE6E73F1714E77C0051492C /* ShellUtils.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/3eab1090/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.h
----------------------------------------------------------------------
diff --git a/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.h b/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.h
new file mode 100644
index 0000000..ab84604
--- /dev/null
+++ b/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.h
@@ -0,0 +1,32 @@
+/*
+ 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.
+ */
+
+
+#import <Foundation/Foundation.h>
+
+@interface ShellUtils : NSObject
+
++ (BOOL) restartComputer;
++ (void) quitApp;
+
++ (NSTask*) shellTask:(NSString*)command;
++ (oneway void) executeShellTaskAsync:(NSString*)command;
++ (NSString*) executeShellTask:(NSString*)command;
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/3eab1090/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.m
----------------------------------------------------------------------
diff --git a/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.m b/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.m
new file mode 100644
index 0000000..27e127f
--- /dev/null
+++ b/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.m
@@ -0,0 +1,73 @@
+/*
+ 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.
+ */
+
+
+#import "ShellUtils.h"
+#import <Cocoa/Cocoa.h>
+#import <Security/Authorization.h>
+
+@implementation ShellUtils
+
++ (BOOL) restartComputer
+{
+	NSAppleScript* script = [[NSAppleScript alloc] initWithSource:@"tell application \"System
Events\" to restart"];
+	NSDictionary* errorInfo;
+	NSAppleEventDescriptor* descriptor = [script executeAndReturnError:&errorInfo];
+    
+	return (descriptor != nil);
+}
+
++ (void) quitApp
+{
+    [[NSApplication sharedApplication] terminate:nil];    
+}
+
++ (NSTask*) shellTask:(NSString*)command
+{
+	NSTask* task = [[NSTask alloc] init];
+    [task setLaunchPath: @"/bin/sh"];
+	[task setStandardInput:[NSFileHandle fileHandleWithNullDevice]];
+    [task setArguments: @[@"-c", command]];
+    
+    return task;
+}
+
++ (NSString*) executeShellTask:(NSString*)command
+{
+    NSPipe* pipe = [NSPipe pipe];
+    NSFileHandle* fileHandle = [pipe fileHandleForReading];
+    
+	NSTask* task = [[self class] shellTask:command];
+    [task setStandardOutput:pipe];
+	[task setStandardError:pipe];
+    [task launch];
+    
+    NSData* outputData = [fileHandle readDataToEndOfFile];
+    
+	return [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];
+}
+
++ (oneway void) executeShellTaskAsync:(NSString*)command
+{
+	[[[self class] shellTask:command] launch];
+    
+	return;
+}
+
+@end


Mime
View raw message