< prev index next >
src/jdk.jpackage/macosx/native/libapplauncher/MacPlatform.mm
Print this page
*** 23,43 ****
* questions.
*/
#include "Platform.h"
- #ifdef MAC
-
#include "MacPlatform.h"
#include "Helpers.h"
#include "Package.h"
#include "PropertyFile.h"
#include "IniFile.h"
#include <sys/sysctl.h>
#include <pthread.h>
#include <vector>
#import <Foundation/Foundation.h>
#import <AppKit/NSRunningApplication.h>
#include <CoreFoundation/CoreFoundation.h>
--- 23,43 ----
* questions.
*/
#include "Platform.h"
#include "MacPlatform.h"
#include "Helpers.h"
#include "Package.h"
#include "PropertyFile.h"
#include "IniFile.h"
#include <sys/sysctl.h>
#include <pthread.h>
#include <vector>
+ #include <signal.h>
+ #include <mach-o/dyld.h>
#import <Foundation/Foundation.h>
#import <AppKit/NSRunningApplication.h>
#include <CoreFoundation/CoreFoundation.h>
*** 49,69 ****
#define MAC_JPACKAGE_TMP_DIR \
"/Library/Application Support/Java/JPackage/tmp"
NSString* StringToNSString(TString Value) {
! NSString* result = [NSString stringWithCString:Value.c_str()
! encoding:[NSString defaultCStringEncoding]];
return result;
}
! MacPlatform::MacPlatform(void) : Platform(), GenericPlatform(), PosixPlatform() {
}
MacPlatform::~MacPlatform(void) {
}
bool MacPlatform::UsePListForConfigFile() {
return FilePath::FileExists(GetConfigFileName()) == false;
}
void MacPlatform::ShowMessage(TString Title, TString Description) {
--- 49,117 ----
#define MAC_JPACKAGE_TMP_DIR \
"/Library/Application Support/Java/JPackage/tmp"
NSString* StringToNSString(TString Value) {
! NSString* result = [NSString stringWithCString : Value.c_str()
! encoding : [NSString defaultCStringEncoding]];
return result;
}
! FileSystemStringToString::FileSystemStringToString(const TCHAR* value) {
! bool release = false;
! PlatformString lvalue = PlatformString(value);
! Platform& platform = Platform::GetInstance();
! TCHAR* buffer = platform.ConvertFileSystemStringToString(lvalue, release);
! FData = buffer;
!
! if (buffer != NULL && release == true) {
! delete[] buffer;
! }
! }
!
! FileSystemStringToString::operator TString() {
! return FData;
! }
!
! StringToFileSystemString::StringToFileSystemString(const TString &value) {
! FRelease = false;
! PlatformString lvalue = PlatformString(value);
! Platform& platform = Platform::GetInstance();
! FData = platform.ConvertStringToFileSystemString(lvalue, FRelease);
! }
!
! StringToFileSystemString::~StringToFileSystemString() {
! if (FRelease == true) {
! delete[] FData;
! }
! }
!
! StringToFileSystemString::operator TCHAR* () {
! return FData;
! }
!
! MacPlatform::MacPlatform(void) : Platform(), PosixPlatform() {
}
MacPlatform::~MacPlatform(void) {
}
+ TString MacPlatform::GetPackageAppDirectory() {
+ return FilePath::IncludeTrailingSeparator(
+ GetPackageRootDirectory()) + _T("Java");
+ }
+
+ TString MacPlatform::GetPackageLauncherDirectory() {
+ return FilePath::IncludeTrailingSeparator(
+ GetPackageRootDirectory()) + _T("MacOS");
+ }
+
+ TString MacPlatform::GetPackageRuntimeBinDirectory() {
+ return FilePath::IncludeTrailingSeparator(GetPackageRootDirectory()) +
+ _T("Plugins/Java.runtime/Contents/Home/bin");
+ }
+
bool MacPlatform::UsePListForConfigFile() {
return FilePath::FileExists(GetConfigFileName()) == false;
}
void MacPlatform::ShowMessage(TString Title, TString Description) {
*** 89,114 ****
release = false;
CFStringRef StringRef = CFStringCreateWithCString(kCFAllocatorDefault,
Source, kCFStringEncodingUTF8);
if (StringRef != NULL) {
! @try {
CFIndex length =
CFStringGetMaximumSizeOfFileSystemRepresentation(StringRef);
result = new char[length + 1];
if (result != NULL) {
if (CFStringGetFileSystemRepresentation(StringRef,
result, length)) {
release = true;
! }
! else {
delete[] result;
result = NULL;
}
}
}
! @finally {
CFRelease(StringRef);
}
}
return result;
--- 137,162 ----
release = false;
CFStringRef StringRef = CFStringCreateWithCString(kCFAllocatorDefault,
Source, kCFStringEncodingUTF8);
if (StringRef != NULL) {
! @ try {
CFIndex length =
CFStringGetMaximumSizeOfFileSystemRepresentation(StringRef);
result = new char[length + 1];
if (result != NULL) {
if (CFStringGetFileSystemRepresentation(StringRef,
result, length)) {
release = true;
! } else {
delete[] result;
result = NULL;
}
}
}
! @finally
! {
CFRelease(StringRef);
}
}
return result;
*** 120,130 ****
release = false;
CFStringRef StringRef = CFStringCreateWithFileSystemRepresentation(
kCFAllocatorDefault, Source);
if (StringRef != NULL) {
! @try {
CFIndex length = CFStringGetLength(StringRef);
if (length > 0) {
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(
length, kCFStringEncodingUTF8);
--- 168,178 ----
release = false;
CFStringRef StringRef = CFStringCreateWithFileSystemRepresentation(
kCFAllocatorDefault, Source);
if (StringRef != NULL) {
! @ try {
CFIndex length = CFStringGetLength(StringRef);
if (length > 0) {
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(
length, kCFStringEncodingUTF8);
*** 132,150 ****
result = new char[maxSize + 1];
if (result != NULL) {
if (CFStringGetCString(StringRef, result, maxSize,
kCFStringEncodingUTF8) == true) {
release = true;
! }
! else {
delete[] result;
result = NULL;
}
}
}
}
! @finally {
CFRelease(StringRef);
}
}
return result;
--- 180,198 ----
result = new char[maxSize + 1];
if (result != NULL) {
if (CFStringGetCString(StringRef, result, maxSize,
kCFStringEncodingUTF8) == true) {
release = true;
! } else {
delete[] result;
result = NULL;
}
}
}
}
! @finally
! {
CFRelease(StringRef);
}
}
return result;
*** 156,166 ****
TString MacPlatform::GetPackageRootDirectory() {
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *mainBundlePath = [mainBundle bundlePath];
NSString *contentsPath =
! [mainBundlePath stringByAppendingString:@"/Contents"];
TString result = [contentsPath UTF8String];
return result;
}
TString MacPlatform::GetAppDataDirectory() {
--- 204,214 ----
TString MacPlatform::GetPackageRootDirectory() {
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *mainBundlePath = [mainBundle bundlePath];
NSString *contentsPath =
! [mainBundlePath stringByAppendingString : @"/Contents"];
TString result = [contentsPath UTF8String];
return result;
}
TString MacPlatform::GetAppDataDirectory() {
*** 197,214 ****
NSString *appName = [[NSProcessInfo processInfo] processName];
TString result = [appName UTF8String];
return result;
}
void AppendPListArrayToIniFile(NSDictionary *infoDictionary,
IniFile *result, TString Section) {
NSString *sectionKey =
! [NSString stringWithUTF8String:PlatformString(Section).toMultibyte()];
! NSDictionary *array = [infoDictionary objectForKey:sectionKey];
for (id option in array) {
! if ([option isKindOfClass:[NSString class]]) {
TString arg = [option UTF8String];
TString name;
TString value;
--- 245,356 ----
NSString *appName = [[NSProcessInfo processInfo] processName];
TString result = [appName UTF8String];
return result;
}
+ void PosixProcess::Cleanup() {
+ if (FOutputHandle != 0) {
+ close(FOutputHandle);
+ FOutputHandle = 0;
+ }
+
+ if (FInputHandle != 0) {
+ close(FInputHandle);
+ FInputHandle = 0;
+ }
+
+ sigaction(SIGINT, &savintr, (struct sigaction *) 0);
+ sigaction(SIGQUIT, &savequit, (struct sigaction *) 0);
+ sigprocmask(SIG_SETMASK, &saveblock, (sigset_t *) 0);
+ }
+
+ #define PIPE_READ 0
+ #define PIPE_WRITE 1
+
+ bool PosixProcess::Execute(const TString Application,
+ const std::vector<TString> Arguments, bool AWait) {
+ bool result = false;
+
+ if (FRunning == false) {
+ FRunning = true;
+
+ int handles[2];
+
+ if (pipe(handles) == -1) {
+ return false;
+ }
+
+ struct sigaction sa;
+ sa.sa_handler = SIG_IGN;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sigemptyset(&savintr.sa_mask);
+ sigemptyset(&savequit.sa_mask);
+ sigaction(SIGINT, &sa, &savintr);
+ sigaction(SIGQUIT, &sa, &savequit);
+ sigaddset(&sa.sa_mask, SIGCHLD);
+ sigprocmask(SIG_BLOCK, &sa.sa_mask, &saveblock);
+
+ FChildPID = fork();
+
+ // PID returned by vfork is 0 for the child process and the
+ // PID of the child process for the parent.
+ if (FChildPID == -1) {
+ // Error
+ TString message = PlatformString::Format(
+ _T("Error: Unable to create process %s"),
+ Application.data());
+ throw Exception(message);
+ } else if (FChildPID == 0) {
+ Cleanup();
+ TString command = Application;
+
+ for (std::vector<TString>::const_iterator iterator =
+ Arguments.begin(); iterator != Arguments.end();
+ iterator++) {
+ command += TString(_T(" ")) + *iterator;
+ }
+ #ifdef DEBUG
+ printf("%s\n", command.data());
+ #endif // DEBUG
+
+ dup2(handles[PIPE_READ], STDIN_FILENO);
+ dup2(handles[PIPE_WRITE], STDOUT_FILENO);
+
+ close(handles[PIPE_READ]);
+ close(handles[PIPE_WRITE]);
+
+ execl("/bin/sh", "sh", "-c", command.data(), (char *) 0);
+
+ _exit(127);
+ } else {
+ FOutputHandle = handles[PIPE_READ];
+ FInputHandle = handles[PIPE_WRITE];
+
+ if (AWait == true) {
+ ReadOutput();
+ Wait();
+ Cleanup();
+ FRunning = false;
+ result = true;
+ } else {
+ result = true;
+ }
+ }
+ }
+
+ return result;
+ }
+
void AppendPListArrayToIniFile(NSDictionary *infoDictionary,
IniFile *result, TString Section) {
NSString *sectionKey =
! [NSString stringWithUTF8String : PlatformString(Section).toMultibyte()];
! NSDictionary *array = [infoDictionary objectForKey : sectionKey];
for (id option in array) {
! if ([option isKindOfClass : [NSString class]]) {
TString arg = [option UTF8String];
TString name;
TString value;
*** 222,244 ****
void AppendPListDictionaryToIniFile(NSDictionary *infoDictionary,
IniFile *result, TString Section, bool FollowSection = true) {
NSDictionary *dictionary = NULL;
if (FollowSection == true) {
! NSString *sectionKey = [NSString stringWithUTF8String:PlatformString(
Section).toMultibyte()];
! dictionary = [infoDictionary objectForKey:sectionKey];
! }
! else {
dictionary = infoDictionary;
}
for (id key in dictionary) {
! id option = [dictionary valueForKey:key];
! if ([key isKindOfClass:[NSString class]] &&
! [option isKindOfClass:[NSString class]]) {
TString name = [key UTF8String];
TString value = [option UTF8String];
result->Append(Section, name, value);
}
}
--- 364,385 ----
void AppendPListDictionaryToIniFile(NSDictionary *infoDictionary,
IniFile *result, TString Section, bool FollowSection = true) {
NSDictionary *dictionary = NULL;
if (FollowSection == true) {
! NSString *sectionKey = [NSString stringWithUTF8String : PlatformString(
Section).toMultibyte()];
! dictionary = [infoDictionary objectForKey : sectionKey];
! } else {
dictionary = infoDictionary;
}
for (id key in dictionary) {
! id option = [dictionary valueForKey : key];
! if ([key isKindOfClass : [NSString class]] &&
! [option isKindOfClass : [NSString class]]) {
TString name = [key UTF8String];
TString value = [option UTF8String];
result->Append(Section, name, value);
}
}
*** 256,267 ****
if (result->LoadFromFile(FileName) == false) {
// New property file format was not found,
// attempt to load old property file format.
Helpers::LoadOldConfigFile(FileName, result);
}
! }
! else {
NSBundle *mainBundle = [NSBundle mainBundle];
NSDictionary *infoDictionary = [mainBundle infoDictionary];
std::map<TString, TString> keys = GetKeys();
// JPackage options.
--- 397,407 ----
if (result->LoadFromFile(FileName) == false) {
// New property file format was not found,
// attempt to load old property file format.
Helpers::LoadOldConfigFile(FileName, result);
}
! } else {
NSBundle *mainBundle = [NSBundle mainBundle];
NSDictionary *infoDictionary = [mainBundle infoDictionary];
std::map<TString, TString> keys = GetKeys();
// JPackage options.
*** 286,308 ****
return result;
}
TString GetModuleFileNameOSX() {
Dl_info module_info;
! if (dladdr(reinterpret_cast<void*>(GetModuleFileNameOSX),
&module_info) == 0) {
// Failed to find the symbol we asked for.
return std::string();
}
return TString(module_info.dli_fname);
}
- #include <mach-o/dyld.h>
-
TString MacPlatform::GetModuleFileName() {
- //return GetModuleFileNameOSX();
-
TString result;
DynamicBuffer<TCHAR> buffer(MAX_PATH);
uint32_t size = buffer.GetSize();
if (_NSGetExecutablePath(buffer.GetData(), &size) == 0) {
--- 426,444 ----
return result;
}
TString GetModuleFileNameOSX() {
Dl_info module_info;
! if (dladdr(reinterpret_cast<void*> (GetModuleFileNameOSX),
&module_info) == 0) {
// Failed to find the symbol we asked for.
return std::string();
}
return TString(module_info.dli_fname);
}
TString MacPlatform::GetModuleFileName() {
TString result;
DynamicBuffer<TCHAR> buffer(MAX_PATH);
uint32_t size = buffer.GetSize();
if (_NSGetExecutablePath(buffer.GetData(), &size) == 0) {
*** 328,340 ****
std::map<TString, TString> MacPlatform::GetKeys() {
std::map<TString, TString> keys;
if (UsePListForConfigFile() == false) {
! return GenericPlatform::GetKeys();
! }
! else {
keys.insert(std::map<TString, TString>::value_type(CONFIG_VERSION,
_T("app.version")));
keys.insert(std::map<TString, TString>::value_type(CONFIG_MAINJAR_KEY,
_T("JVMMainJarName")));
keys.insert(std::map<TString, TString>::value_type(CONFIG_MAINMODULE_KEY,
--- 464,475 ----
std::map<TString, TString> MacPlatform::GetKeys() {
std::map<TString, TString> keys;
if (UsePListForConfigFile() == false) {
! return Platform::GetKeys();
! } else {
keys.insert(std::map<TString, TString>::value_type(CONFIG_VERSION,
_T("app.version")));
keys.insert(std::map<TString, TString>::value_type(CONFIG_MAINJAR_KEY,
_T("JVMMainJarName")));
keys.insert(std::map<TString, TString>::value_type(CONFIG_MAINMODULE_KEY,
*** 374,406 ****
CONFIG_SECTION_ARGOPTIONS, _T("ArgOptions")));
}
return keys;
}
-
- #ifdef DEBUG
- bool MacPlatform::IsNativeDebuggerPresent() {
- int state;
- int mib[4];
- struct kinfo_proc info;
- size_t size;
-
- info.kp_proc.p_flag = 0;
-
- mib[0] = CTL_KERN;
- mib[1] = KERN_PROC;
- mib[2] = KERN_PROC_PID;
- mib[3] = getpid();
-
- size = sizeof(info);
- state = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);
- assert(state == 0);
- return ((info.kp_proc.p_flag & P_TRACED) != 0);
- }
-
- int MacPlatform::GetProcessID() {
- int pid = [[NSProcessInfo processInfo] processIdentifier];
- return pid;
- }
- #endif //DEBUG
-
- #endif //MAC
--- 509,513 ----
< prev index next >