1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates.
   3  * All rights reserved. Use is subject to license terms.
   4  *
   5  * This file is available and licensed under the following license:
   6  *
   7  * Redistribution and use in source and binary forms, with or without
   8  * modification, are permitted provided that the following conditions
   9  * are met:
  10  *
  11  *  - Redistributions of source code must retain the above copyright
  12  *    notice, this list of conditions and the following disclaimer.
  13  *  - Redistributions in binary form must reproduce the above copyright
  14  *    notice, this list of conditions and the following disclaimer in
  15  *    the documentation and/or other materials provided with the distribution.
  16  *  - Neither the name of Oracle Corporation nor the names of its
  17  *    contributors may be used to endorse or promote products derived
  18  *    from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31  */
  32 
  33 
  34 #ifndef PACKAGE_H
  35 #define PACKAGE_H
  36 
  37 
  38 #include "Platform.h"
  39 #include "PlatformString.h"
  40 #include "FilePath.h"
  41 #include "PropertyFile.h"
  42 
  43 #include <map>
  44 #include <list>
  45 
  46 class PackageBootFields {
  47 public:
  48     enum MemoryState {msManual, msAuto};
  49 
  50 public:
  51     OrderedMap<TString, TString> FJVMArgs;
  52     std::list<TString> FArgs;
  53 
  54     TString FPackageRootDirectory;
  55     TString FPackageAppDirectory;
  56     TString FPackageLauncherDirectory;
  57     TString FAppDataDirectory;
  58     TString FAppID;
  59     TString FPackageAppDataDirectory;
  60     TString FClassPath;
  61     TString FMainJar;
  62     TString FMainClassName;
  63     bool FIsRuntimeBundled;
  64     TString FJVMRuntimeDirectory;
  65     TString FJVMLibraryFileName;
  66     TString FSplashScreenFileName;
  67     bool FUseJavaPreferences;
  68     TString FCommandName;
  69 
  70     TString FAppCDSCacheFileName;
  71 
  72     TPlatformNumber FMemorySize;
  73     MemoryState FMemoryState;
  74 };
  75 
  76 
  77 class Package {
  78 private:
  79     Package(Package const&); // Don't Implement.
  80     void operator=(Package const&); // Don't implement
  81 
  82 private:
  83     bool FInitialized;
  84     PackageBootFields* FBootFields;
  85     TString FJVMUserArgsConfigFileName;
  86     TString FAppCDSCacheDirectory;
  87 
  88     DebugState FDebugging;
  89 
  90     OrderedMap<TString, TString> FJVMUserArgsOverrides;
  91     OrderedMap<TString, TString> FDefaultJVMUserArgs; // Contains JVM user defaults
  92     OrderedMap<TString, TString> FJVMUserArgs; // Contains a merge of JVM defaults and user overrides
  93 
  94 
  95     Package(void);
  96 
  97     //void Initialize();
  98     void MergeJVMDefaultsWithOverrides();
  99     TString GetMainJar();
 100     void SaveJVMUserArgOverrides(OrderedMap<TString, TString> Data);
 101     void ReadJVMArgs(ISectionalPropertyContainer* Config);
 102 
 103 public:
 104     static Package& GetInstance();
 105     ~Package(void);
 106 
 107     void Initialize();
 108     void Clear();
 109     void FreeBootFields();
 110 
 111     void SetCommandLineArguments(int argc, TCHAR* argv[]);
 112 
 113     OrderedMap<TString, TString> GetJVMArgs();
 114     OrderedMap<TString, TString> GetDefaultJVMUserArgs();
 115     OrderedMap<TString, TString> GetJVMUserArgOverrides();
 116     void SetJVMUserArgOverrides(OrderedMap<TString, TString> Value);
 117     OrderedMap<TString, TString> GetJVMUserArgs();
 118 
 119     std::list<TString> GetArgs();
 120 
 121     TString GetPackageRootDirectory();
 122     TString GetPackageAppDirectory();
 123     TString GetPackageLauncherDirectory();
 124     TString GetAppDataDirectory();
 125 
 126     TString GetJVMUserArgsConfigFileName();
 127     TString GetAppCDSCacheDirectory();
 128     TString GetAppCDSCacheFileName();
 129 
 130     TString GetAppID();
 131     TString GetPackageAppDataDirectory();
 132     TString GetClassPath();
 133     TString GetMainClassName();
 134     bool IsRuntimeBundled();
 135     TString GetJVMLibraryFileName();
 136     TString GetJVMRuntimeDirectory();
 137     TString GetSplashScreenFileName();
 138     bool HasSplashScreen();
 139     TString GetCommandName();
 140 
 141     TPlatformNumber GetMemorySize();
 142     PackageBootFields::MemoryState GetMemoryState();
 143 
 144     DebugState Debugging();
 145 };
 146 
 147 #endif //PACKAGE_H