src/jdk.packager/share/native/library/common/Package.h
author herrick
Wed, 17 Oct 2018 13:50:11 -0400
branchJDK-8200758-branch
changeset 56982 e094d5483bd6
parent 56854 aedce3eaaf17
child 56995 3d5b13207b70
permissions -rw-r--r--
8212048: Cleanup source code and fix issues discussed in preliminary review Reviewed-by: almatvee

/*
 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

#ifndef PACKAGE_H
#define PACKAGE_H


#include "Platform.h"
#include "PlatformString.h"
#include "FilePath.h"
#include "PropertyFile.h"

#include <map>
#include <list>

class PackageBootFields {
public:
    enum MemoryState {msManual, msAuto};

public:
    OrderedMap<TString, TString> FJVMArgs;
    std::list<TString> FArgs;

    TString FPackageRootDirectory;
    TString FPackageAppDirectory;
    TString FPackageLauncherDirectory;
    TString FAppDataDirectory;
    TString FAppID;
    TString FPackageAppDataDirectory;
    TString FClassPath;
    TString FModulePath;
    TString FMainJar;
    TString FMainModule;
    TString FMainClassName;
    TString FJVMRuntimeDirectory;
    TString FJVMLibraryFileName;
    TString FSplashScreenFileName;
    bool FUseJavaPreferences;
    TString FCommandName;

    TString FAppCDSCacheFileName;

    TPlatformNumber FMemorySize;
    MemoryState FMemoryState;
};


class Package {
private:
    Package(Package const&); // Don't Implement.
    void operator=(Package const&); // Don't implement

private:
    bool FInitialized;
    PackageBootFields* FBootFields;
    TString FJVMUserArgsConfigFileName;
    TString FAppCDSCacheDirectory;

    DebugState FDebugging;

    OrderedMap<TString, TString> FJVMUserArgsOverrides;
    // Contains JVM user defaults
    OrderedMap<TString, TString> FDefaultJVMUserArgs;
    // Contains a merge of JVM defaults and user overrides
    OrderedMap<TString, TString> FJVMUserArgs;

    Package(void);

    void MergeJVMDefaultsWithOverrides();
    TString GetMainJar();
    void SaveJVMUserArgOverrides(OrderedMap<TString, TString> Data);
    void ReadJVMArgs(ISectionalPropertyContainer* Config);
    void PromoteAppCDSState(ISectionalPropertyContainer* Config);

public:
    static Package& GetInstance();
    ~Package(void);

    void Initialize();
    void Clear();
    void FreeBootFields();
    bool CheckForSingleInstance();

    void SetCommandLineArguments(int argc, TCHAR* argv[]);

    OrderedMap<TString, TString> GetJVMArgs();
    OrderedMap<TString, TString> GetDefaultJVMUserArgs();
    OrderedMap<TString, TString> GetJVMUserArgOverrides();
    void SetJVMUserArgOverrides(OrderedMap<TString, TString> Value);
    OrderedMap<TString, TString> GetJVMUserArgs();
    TString GetMainModule();

    std::list<TString> GetArgs();

    TString GetPackageRootDirectory();
    TString GetPackageAppDirectory();
    TString GetPackageLauncherDirectory();
    TString GetAppDataDirectory();

    TString GetJVMUserArgsConfigFileName();
    TString GetAppCDSCacheDirectory();
    TString GetAppCDSCacheFileName();

    TString GetAppID();
    TString GetPackageAppDataDirectory();
    TString GetClassPath();
    TString GetModulePath();
    TString GetMainClassName();
    TString GetJVMLibraryFileName();
    TString GetJVMRuntimeDirectory();
    TString GetSplashScreenFileName();
    bool HasSplashScreen();
    TString GetCommandName();

    TPlatformNumber GetMemorySize();
    PackageBootFields::MemoryState GetMemoryState();

    DebugState Debugging();
};

#endif // PACKAGE_H