modules/fxpackager/src/main/native/library/common/LinuxPlatform.cpp

Print this page




  91         result = buffer.GetData();
  92     }
  93 
  94     return result;
  95 }
  96 
  97 void LinuxPlatform::SetCurrentDirectory(TString Value) {
  98     chdir(PlatformString(Value).toPlatformString());
  99 }
 100 
 101 TString LinuxPlatform::GetPackageRootDirectory() {
 102     TString filename = GetModuleFileName();
 103     return FilePath::ExtractFilePath(filename);
 104 }
 105 
 106 TString LinuxPlatform::GetAppDataDirectory() {
 107     TString result;
 108     TString home = GetEnv(_T("HOME"));
 109 
 110     if (home.empty() == false) {
 111         result += FilePath::IncludeTrailingSlash(home) + _T(".local");
 112     }
 113 
 114     return result;
 115 }
 116 
 117 PropertyContainer* LinuxPlatform::GetConfigFile(TString FileName) {
 118     return new PropertyFile(FileName);







 119 }
 120 
 121 TString LinuxPlatform::GetBundledJVMLibraryFileName(TString RuntimePath) {
 122     TString result = FilePath::IncludeTrailingSlash(RuntimePath) +
 123         "jre/lib/"JAVAARCH"/client/libjvm.so";
 124 
 125     if (FilePath::FileExists(result) == false) {
 126         result = FilePath::IncludeTrailingSlash(RuntimePath) +
 127             "jre/lib/"JAVAARCH"/server/libjvm.so";
 128     }
 129 
 130     if (FilePath::FileExists(result) == false) {
 131         result = FilePath::IncludeTrailingSlash(RuntimePath) +
 132             "lib/"JAVAARCH"/server/libjvm.so";
 133     }
 134 
 135     if (FilePath::FileExists(result) == false) {
 136         result = FilePath::IncludeTrailingSlash(RuntimePath) +
 137             "lib/"JAVAARCH"/server/libjvm.so";
 138     }
 139 
 140     return result;
 141 }
 142 
 143 TString LinuxPlatform::GetSystemJRE() {





 144     TString result;
 145     TString jreHome = GetEnv("JRE_HOME");
 146 
 147     if (jreHome.empty() == false) {
 148         result = FilePath::IncludeTrailingSlash(jreHome);
 149 
 150         if (FilePath::FileExists(result + _T("lib/rt.jar")) == false) {
 151             result = FilePath::IncludeTrailingSlash(jreHome) + _T("jre");
 152 
 153             if (FilePath::FileExists(result + _T("/lib/rt.jar")) == false) {
 154                 //check redhat location
 155                 if (FilePath::FileExists(_T("/usr/java/latest/jre/lib/rt.jar")) == true) {
 156                     result = _T("/usr/java/latest/jre");
 157                 }
 158                 else if (FilePath::FileExists(_T("/usr/lib/jvm/default-java/jre/lib/rt.jar")) == true) {
 159                     result = _T("/usr/lib/jvm/default-java/jre");
 160                 }
 161                 else {
 162                     result = _T("");
 163                 }
 164             }
 165         }
 166     }
 167 
 168     return result;
 169 }
 170 
 171 TString LinuxPlatform::GetSystemJVMLibraryFileName() {
 172     TString result;
 173     TString jreHome = GetSystemJRE();
 174 
 175     if (jreHome.empty() == false && FilePath::DirectoryExists(jreHome) == true) {
 176         result = FilePath::IncludeTrailingSlash(jreHome) +
 177             _T("/lib/"JAVAARCH"/client/libjvm.so");
 178 
 179         if (FilePath::FileExists(result) == false) {
 180             result = FilePath::IncludeTrailingSlash(jreHome) +
 181                 _T("/lib/"JAVAARCH"/server/libjvm.so");
 182         }
 183     }
 184 
 185     return result;
 186 }
 187 
 188 bool LinuxPlatform::IsMainThread() {
 189     bool result = (FMainThread == pthread_self());
 190     return result;
 191 }
 192 
 193 TPlatformNumber LinuxPlatform::GetMemorySize() {
 194     long pages = sysconf(_SC_PHYS_PAGES);
 195     long page_size = sysconf(_SC_PAGE_SIZE);
 196     TPlatformNumber result = pages * page_size;
 197     result = result / 1048576; // Convert from bytes to megabytes.
 198     return result;
 199 }
 200 


1008     }
1009     return (++p);
1010 }
1011 
1012 static int IsPCData(TCHAR *p) {
1013     return (DEPLOY_STRNCMP(CDStart, p, sizeof(CDStart)) == 0);
1014 }
1015 
1016 //--------------------------------------------------------------------------------------------------
1017 
1018 LinuxJavaUserPreferences::LinuxJavaUserPreferences(void) : JavaUserPreferences() {
1019 }
1020 
1021 LinuxJavaUserPreferences::~LinuxJavaUserPreferences(void) {
1022 }
1023 
1024 TString LinuxJavaUserPreferences::GetUserPrefFileName(TString Appid) {
1025     TString result;
1026     struct passwd *pw = getpwuid(getuid());
1027     TString homedir = pw->pw_dir;
1028     TString userOverrideFileName = FilePath::IncludeTrailingSlash(homedir) +
1029         FilePath::IncludeTrailingSlash(_T(".java/.userPrefs")) +
1030         FilePath::IncludeTrailingSlash(Appid) +
1031         _T("JVMUserOptions/prefs.xml");
1032 
1033     if (FilePath::FileExists(userOverrideFileName) == true) {
1034         result = userOverrideFileName;
1035     }
1036 
1037     return result;
1038 }
1039 
1040 TOrderedMap ReadNode(XMLNode* node) {
1041     TOrderedMap result;
1042     XMLNode* keyNode = FindXMLChild(node->_sub, _T("entry"));
1043     int index = 1;
1044 
1045     while (keyNode != NULL) {
1046         TString key = FindXMLAttribute(keyNode->_attributes, _T("key"));
1047         TString value = FindXMLAttribute(keyNode->_attributes, _T("value"));
1048         keyNode = keyNode->_next;
1049 
1050         if (key.empty() == false) {
1051             TValueIndex item;
1052             item.value = value;
1053             item.index = index;
1054             result.insert(TOrderedMap::value_type(key, item));
1055             index++;
1056         }
1057     }
1058 
1059     return result;
1060 }
1061 
1062 TOrderedMap GetJvmUserArgs(TString filename) {
1063     TOrderedMap result;
1064 
1065     if (FilePath::FileExists(filename) == true) {
1066         //scan file for the key
1067         FILE* fp = fopen(PlatformString(filename).toPlatformString(), "r");
1068 
1069         if (fp != NULL) {
1070             fseek(fp, 0, SEEK_END);
1071             long fsize = ftell(fp);
1072             rewind(fp);
1073             DynamicBuffer<char> buffer(fsize + 1);
1074             fread(buffer.GetData(), fsize, 1, fp);
1075             fclose(fp);
1076             buffer[fsize] = 0;
1077 
1078             XMLNode* node = NULL;
1079             XMLNode* doc = ParseXMLDocument(buffer.GetData());
1080 
1081             if (doc != NULL) {
1082                 node = FindXMLChild(doc, _T("map"));
1083 




  91         result = buffer.GetData();
  92     }
  93 
  94     return result;
  95 }
  96 
  97 void LinuxPlatform::SetCurrentDirectory(TString Value) {
  98     chdir(PlatformString(Value).toPlatformString());
  99 }
 100 
 101 TString LinuxPlatform::GetPackageRootDirectory() {
 102     TString filename = GetModuleFileName();
 103     return FilePath::ExtractFilePath(filename);
 104 }
 105 
 106 TString LinuxPlatform::GetAppDataDirectory() {
 107     TString result;
 108     TString home = GetEnv(_T("HOME"));
 109 
 110     if (home.empty() == false) {
 111         result += FilePath::IncludeTrailingSeparater(home) + _T(".local");
 112     }
 113 
 114     return result;
 115 }
 116 
 117 ISectionalPropertyContainer* LinuxPlatform::GetConfigFile(TString FileName) {
 118     IniFile *result = new IniFile();
 119 
 120     if (result->LoadFromFile(FileName) == false) {
 121         // New property file format was not found, attempt to load old property file format.
 122         Helpers::LoadOldConfigFile(FileName, result);
 123     }
 124 
 125     return result;
 126 }
 127 
 128 TString LinuxPlatform::GetBundledJVMLibraryFileName(TString RuntimePath) {
 129     TString result = FilePath::IncludeTrailingSeparater(RuntimePath) +
 130         "jre/lib/"JAVAARCH"/client/libjvm.so";
 131 
 132     if (FilePath::FileExists(result) == false) {
 133         result = FilePath::IncludeTrailingSeparater(RuntimePath) +
 134             "jre/lib/"JAVAARCH"/server/libjvm.so";
 135     }
 136 
 137     if (FilePath::FileExists(result) == false) {
 138         result = FilePath::IncludeTrailingSeparater(RuntimePath) +
 139             "lib/"JAVAARCH"/server/libjvm.so";
 140     }
 141 
 142     if (FilePath::FileExists(result) == false) {
 143         result = FilePath::IncludeTrailingSeparater(RuntimePath) +
 144             "lib/"JAVAARCH"/server/libjvm.so";
 145     }
 146 
 147     return result;
 148 }
 149 
 150 TString LinuxPlatform::GetSystemJRE() {
 151     if (GetAppCDSState() == cdsOn || GetAppCDSState() == cdsGenCache) {
 152         //TODO throw exception
 153         return _T("");
 154     }
 155 
 156     TString result;
 157     TString jreHome = GetEnv("JRE_HOME");
 158 
 159     if (jreHome.empty() == false) {
 160         result = FilePath::IncludeTrailingSeparater(jreHome);
 161 
 162         if (FilePath::FileExists(result + _T("lib/rt.jar")) == false) {
 163             result = FilePath::IncludeTrailingSeparater(jreHome) + _T("jre");
 164 
 165             if (FilePath::FileExists(result + _T("/lib/rt.jar")) == false) {
 166                 //check redhat location
 167                 if (FilePath::FileExists(_T("/usr/java/latest/jre/lib/rt.jar")) == true) {
 168                     result = _T("/usr/java/latest/jre");
 169                 }
 170                 else if (FilePath::FileExists(_T("/usr/lib/jvm/default-java/jre/lib/rt.jar")) == true) {
 171                     result = _T("/usr/lib/jvm/default-java/jre");
 172                 }
 173                 else {
 174                     result = _T("");
 175                 }
 176             }
 177         }
 178     }
 179 
 180     return result;
 181 }
 182 
 183 TString LinuxPlatform::GetSystemJVMLibraryFileName() {
 184     TString result;
 185     TString jreHome = GetSystemJRE();
 186 
 187     if (jreHome.empty() == false && FilePath::DirectoryExists(jreHome) == true) {
 188         result = FilePath::IncludeTrailingSeparater(jreHome) +
 189             _T("/lib/"JAVAARCH"/client/libjvm.so");
 190 
 191         if (FilePath::FileExists(result) == false) {
 192             result = FilePath::IncludeTrailingSeparater(jreHome) +
 193                 _T("/lib/"JAVAARCH"/server/libjvm.so");
 194         }
 195     }
 196 
 197     return result;
 198 }
 199 
 200 bool LinuxPlatform::IsMainThread() {
 201     bool result = (FMainThread == pthread_self());
 202     return result;
 203 }
 204 
 205 TPlatformNumber LinuxPlatform::GetMemorySize() {
 206     long pages = sysconf(_SC_PHYS_PAGES);
 207     long page_size = sysconf(_SC_PAGE_SIZE);
 208     TPlatformNumber result = pages * page_size;
 209     result = result / 1048576; // Convert from bytes to megabytes.
 210     return result;
 211 }
 212 


1020     }
1021     return (++p);
1022 }
1023 
1024 static int IsPCData(TCHAR *p) {
1025     return (DEPLOY_STRNCMP(CDStart, p, sizeof(CDStart)) == 0);
1026 }
1027 
1028 //--------------------------------------------------------------------------------------------------
1029 
1030 LinuxJavaUserPreferences::LinuxJavaUserPreferences(void) : JavaUserPreferences() {
1031 }
1032 
1033 LinuxJavaUserPreferences::~LinuxJavaUserPreferences(void) {
1034 }
1035 
1036 TString LinuxJavaUserPreferences::GetUserPrefFileName(TString Appid) {
1037     TString result;
1038     struct passwd *pw = getpwuid(getuid());
1039     TString homedir = pw->pw_dir;
1040     TString userOverrideFileName = FilePath::IncludeTrailingSeparater(homedir) +
1041         FilePath::IncludeTrailingSeparater(_T(".java/.userPrefs")) +
1042         FilePath::IncludeTrailingSeparater(Appid) +
1043         _T("JVMUserOptions/prefs.xml");
1044 
1045     if (FilePath::FileExists(userOverrideFileName) == true) {
1046         result = userOverrideFileName;
1047     }
1048 
1049     return result;
1050 }
1051 
1052 OrderedMap<TString, TString> ReadNode(XMLNode* node) {
1053     OrderedMap<TString, TString> result;
1054     XMLNode* keyNode = FindXMLChild(node->_sub, _T("entry"));

1055 
1056     while (keyNode != NULL) {
1057         TString key = FindXMLAttribute(keyNode->_attributes, _T("key"));
1058         TString value = FindXMLAttribute(keyNode->_attributes, _T("value"));
1059         keyNode = keyNode->_next;
1060 
1061         if (key.empty() == false) {
1062             result.Append(key, value);




1063         }
1064     }
1065 
1066     return result;
1067 }
1068 
1069 OrderedMap<TString, TString> GetJvmUserArgs(TString filename) {
1070     OrderedMap<TString, TString> result;
1071 
1072     if (FilePath::FileExists(filename) == true) {
1073         //scan file for the key
1074         FILE* fp = fopen(PlatformString(filename).toPlatformString(), "r");
1075 
1076         if (fp != NULL) {
1077             fseek(fp, 0, SEEK_END);
1078             long fsize = ftell(fp);
1079             rewind(fp);
1080             DynamicBuffer<char> buffer(fsize + 1);
1081             fread(buffer.GetData(), fsize, 1, fp);
1082             fclose(fp);
1083             buffer[fsize] = 0;
1084 
1085             XMLNode* node = NULL;
1086             XMLNode* doc = ParseXMLDocument(buffer.GetData());
1087 
1088             if (doc != NULL) {
1089                 node = FindXMLChild(doc, _T("map"));
1090