/* * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed 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. */ package ohos; import java.io.Closeable; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Locale; /** * common resource. * */ public class Utility { static final String MODE_HAP = "hap"; static final String MODE_HAR = "har"; static final String MODE_APP = "app"; static final String MODE_FAST_APP = "fastApp"; static final String MODE_MULTI_APP = "multiApp"; static final String MODE_HQF = "hqf"; static final String MODE_APPQF = "appqf"; static final String MODE_RES = "res"; static final String MODE_HSP = "hsp"; static final String MODE_HAPADDITION = "hapAddition"; static final String VERSION_NORMALIZE = "versionNormalize"; static final String PACKAGE_NORMALIZE = "packageNormalize"; static final String FALSE_STRING = "false"; static final String TRUE_STRING = "true"; private static final String INVALID_PATH = "invalid"; private static final String CMD_PREFIX = "--"; private static final Log LOG = new Log(Utility.class.toString()); private String mode = ""; private String jsonPath = ""; private String profilePath = ""; private String soPath = ""; private String soDir = ""; private String abilitySoPath = ""; private String dexPath = ""; private String abcPath = ""; private String indexPath = ""; private String hapPath = ""; private String appPath = ""; private String libPath = ""; private String resPath = ""; private String resourcesPath = ""; private String assetsPath = ""; private String apkPath = ""; private String certificatePath = ""; private String signaturePath = ""; private String forceRewrite = "false"; private String outPath = ""; private String packInfoPath = ""; private String encryptPath = ""; private String binPath = ""; private boolean isCompressNativeLibs = false; private String moduleName = ""; private String harPath = ""; private String hspPath = ""; private String jarPath = ""; private String txtPath = ""; private String parseMode = ""; private String deviceType = ""; private String hapName = ""; private String sharedLibsPath = ""; private String unpackApk = "false"; private String unpackCutEntryApk = "false"; private String entryCardPath = ""; private String packRes = ""; private String packResPath = ""; private String filePath = ""; private String jsPath = ""; private String etsPath = ""; private String hnpPath = ""; private String rpcidPath = ""; private int VersionCode = -1; private String VersionName = ""; private boolean isModuleJson = false; private String rpcid = FALSE_STRING; private boolean isParse = false; private String appqfPath = ""; private String anPath = ""; private String apPath = ""; private Boolean isSharedApp = false; private Boolean isAppService = false; private String mainModuleLimit = ""; private String normalModuleLimit = ""; private String totalLimit = ""; private int compressLevel = 1; private String pkgContextPath = ""; private String bundleName = ""; private String absoluteHapPath = ""; private boolean generateBuildHash = false; private boolean buildHashFinish = false; private List formattedSoPathList = new ArrayList<>(); private List formattedAbilitySoPathList = new ArrayList<>(); private List formattedDexPathList = new ArrayList<>(); private List formattedAbcPathList = new ArrayList<>(); private List formattedHapPathList = new ArrayList<>(); private List formattedHspPathList = new ArrayList<>(); private List formattedApkPathList = new ArrayList<>(); private List formattedJarPathList = new ArrayList<>(); private List formattedTxtPathList = new ArrayList<>(); private List formattedEntryCardPathList = new ArrayList<>(); private List formNameList = new ArrayList<>(); private List formattedAppList = new ArrayList<>(); private List formattedHapList = new ArrayList<>(); private List formatedDirList = new ArrayList<>(); private List formatedHQFList = new ArrayList<>(); private List formatedABCList = new ArrayList<>(); private String appList = ""; private String hapList = ""; private String dirList = ""; private String hqfList = ""; private String hspList = ""; private String inputList = ""; private String input = ""; private boolean statDuplicate = false; private boolean statSuffix = false; private String statFileSize = ""; public void setIsParse(boolean isParse) { this.isParse = isParse; } public boolean getIsParse() { return isParse; } public String getMode() { return mode; } public void setMode(String mode) { if (!mode.startsWith(CMD_PREFIX)) { this.mode = mode; } } public String getJsonPath() { return jsonPath; } public void setJsonPath(String jsonPath) { if (!jsonPath.startsWith(CMD_PREFIX)) { this.jsonPath = getFormattedPath(jsonPath); } } public String getProfilePath() { return profilePath; } public void setProfilePath(String profilePath) { if (!profilePath.startsWith(CMD_PREFIX)) { this.profilePath = getFormattedPath(profilePath); } } public String getSoPath() { return soPath; } public void setSoPath(String soPath) { if (!soPath.startsWith(CMD_PREFIX)) { this.soPath = soPath; } } public String getAbilitySoPath() { return abilitySoPath; } public void setAbilitySoPath(String abilitySoPath) { if (!abilitySoPath.startsWith(CMD_PREFIX)) { this.abilitySoPath = abilitySoPath; } } public String getSoDir() { return soDir; } public void setSoDir(String soDir) { if (!soDir.startsWith(CMD_PREFIX)) { this.soDir = soDir; } } public String getDexPath() { return dexPath; } public void setDexPath(String dexPath) { if (!dexPath.startsWith(CMD_PREFIX)) { this.dexPath = dexPath; } } public String getAbcPath() { return abcPath; } public void setAbcPath(String abcPath) { if (!abcPath.startsWith(CMD_PREFIX)) { this.abcPath = abcPath; } } public List getABCList() { return formatedABCList; } public String getFilePath() { return filePath; } public void setFilePath(String filePath) { if (!filePath.startsWith(CMD_PREFIX)) { this.filePath = filePath; } } public String getIndexPath() { return indexPath; } public void setIndexPath(String indexPath) { if (!indexPath.startsWith(CMD_PREFIX)) { this.indexPath = getFormattedPath(indexPath); } } public String getBinPath() { return binPath; } public void setBinPath(String binPath) { if (!binPath.startsWith(CMD_PREFIX)) { this.binPath = getFormattedPath(binPath); } } public void setIsModuleJson(boolean isModuleJson) { this.isModuleJson = isModuleJson; } public boolean getIsModuleJson() { return isModuleJson; } public boolean isCompressNativeLibs() { return isCompressNativeLibs; } public void setIsCompressNativeLibs(boolean isCompress) { this.isCompressNativeLibs = isCompress; } public String getHapPath() { return hapPath; } public void setHapPath(String hapPath) { if (!hapPath.startsWith(CMD_PREFIX)) { this.hapPath = hapPath; if (MODE_HAPADDITION.equals(this.getMode())) { this.absoluteHapPath = getFormattedPath(hapPath); } } } public String getAppPath() { return appPath; } public void setAppPath(String appPath) { if (!appPath.startsWith(CMD_PREFIX)) { this.appPath = appPath; } } public String getLibPath() { return libPath; } public void setLibPath(String libPath) { if (!libPath.startsWith(CMD_PREFIX)) { this.libPath = getFormattedPath(libPath); } } public String getResPath() { return resPath; } public void setResPath(String resPath) { if (!resPath.startsWith(CMD_PREFIX)) { this.resPath = getFormattedPath(resPath); } } public String getResourcesPath() { return resourcesPath; } public void setResourcesPath(String resourcesPath) { if (!resourcesPath.startsWith(CMD_PREFIX)) { this.resourcesPath = getFormattedPath(resourcesPath); } } public String getAssetsPath() { return assetsPath; } public void setAssetsPath(String assetsPath) { if (!assetsPath.startsWith(CMD_PREFIX)) { this.assetsPath = getFormattedPath(assetsPath); } } public String getModuleName() { if (moduleName == null) { moduleName = ""; } return moduleName; } public void setModuleName(String moduleName) { this.moduleName = moduleName; } public String getApkPath() { return apkPath; } public void setApkPath(String apkPath) { if (!apkPath.startsWith(CMD_PREFIX)) { this.apkPath = apkPath; } } public String getCertificatePath() { return certificatePath; } public void setCertificatePath(String certificatePath) { if (!certificatePath.startsWith(CMD_PREFIX)) { this.certificatePath = getFormattedPath(certificatePath); } } public String getSignaturePath() { return signaturePath; } public void setSignaturePath(String signaturePath) { if (!signaturePath.startsWith(CMD_PREFIX)) { this.signaturePath = getFormattedPath(signaturePath); } } public String getForceRewrite() { return forceRewrite; } public void setForceRewrite(String forceRewrite) { if (!forceRewrite.startsWith(CMD_PREFIX)) { this.forceRewrite = forceRewrite.toLowerCase(Locale.ENGLISH); } } public String getOutPath() { return outPath; } public void setOutPath(String outPath) { if (!outPath.startsWith(CMD_PREFIX)) { this.outPath = getFormattedPath(outPath); } } public String getPackInfoPath() { return packInfoPath; } public void setPackInfoPath(String packInfoPath) { if (!packInfoPath.startsWith(CMD_PREFIX)) { this.packInfoPath = getFormattedPath(packInfoPath); } } public String getEncryptPath() { return encryptPath; } public void setEncryptPath(String encryptPath) { if (!encryptPath.startsWith(CMD_PREFIX)) { this.encryptPath = getFormattedPath(encryptPath); } } public String getJarPath() { return jarPath; } public void setJarPath(String jarPath) { if (!jarPath.startsWith(CMD_PREFIX)) { this.jarPath = jarPath; } } public String getTxtPath() { return txtPath; } public void setTxtPath(String txtPath) { if (!txtPath.startsWith(CMD_PREFIX)) { this.txtPath = txtPath; } } public String getHarPath() { return harPath; } public void setHarPath(String harPath) { if (!harPath.startsWith(CMD_PREFIX)) { this.harPath = harPath; } } public void setHspPath(String hspPath) { if (!hspPath.startsWith(CMD_PREFIX)) { this.hspPath = hspPath; } } public String getHspPath() { return hspPath; } public String getParseMode() { return parseMode; } public void setParseMode(String parseMode) { if (!parseMode.startsWith(CMD_PREFIX)) { this.parseMode = parseMode; } } public String getDeviceType() { return deviceType; } public void setDeviceType(String deviceType) { if (!deviceType.startsWith(CMD_PREFIX)) { this.deviceType = deviceType; } } public String getUnpackApk() { return unpackApk; } public void setUnpackApk(String unpackApk) { this.unpackApk = unpackApk; } public String getUnpackCutEntryApk() { return unpackCutEntryApk; } public void setUnpackCutEntryApk(String unpackCutEntryApk) { this.unpackCutEntryApk = unpackCutEntryApk; } public String getHapName() { return hapName; } public void setHapName(String hapName) { if (!hapName.startsWith(CMD_PREFIX)) { this.hapName = hapName; } } public String getSharedLibsPath() { return sharedLibsPath; } public void setSharedLibsPath(String sharedLibsPath) { if (!sharedLibsPath.startsWith(CMD_PREFIX)) { this.sharedLibsPath = sharedLibsPath; } } public String getEntryCardPath() { return entryCardPath; } public void setEntryCardPath(String entryCardPath) { if (!entryCardPath.startsWith(CMD_PREFIX)) { this.entryCardPath = entryCardPath; } } public String getPackRes() { return packRes; } public void setPackRes(String packRes) { this.packRes = packRes; } public String getPackResPath() { return packResPath; } public void setPackResPath(String packResPath) { this.packResPath = packResPath; } public String getJsPath() { return jsPath; } public void setJsPath(String jsPath) { this.jsPath = jsPath; } public String getEtsPath() { return etsPath; } public void setEtsPath(String etsPath) { this.etsPath = etsPath; } public String getHnpPath() { return hnpPath; } public void setHnpPath(String hnpPath) { this.hnpPath = hnpPath; } public String getRpcidPath() { return rpcidPath; } public void setRpcidPath(String rpcidPath) { this.rpcidPath = rpcidPath; } public String getRpcid() { return rpcid; } public void setRpcid(String rpcid) { this.rpcid = rpcid; } public String getVersionName() { return VersionName; } public void setVersionName(String VersionName) { this.VersionName = VersionName; } public int getVersionCode() { return VersionCode; } public void setVersionCode(int VersionCode) { this.VersionCode = VersionCode; } public List getFormattedSoPathList() { return formattedSoPathList; } public List getFormattedAbilitySoPathList() { return formattedAbilitySoPathList; } public List getFormattedDexPathList() { return formattedDexPathList; } public List getFormattedAbcPathList() { return formattedAbcPathList; } public List getFormattedHapPathList() { return formattedHapPathList; } public List getFormattedHspPathList() { return formattedHspPathList; } public List getFormattedApkPathList() { return formattedApkPathList; } public List getFormattedJarPathList() { return formattedJarPathList; } public List getFormattedTxtPathList() { return formattedTxtPathList; } public List getFormattedAppList() { return formattedAppList; } public List getFormattedHapList() { return formattedHapList; } public void setAppList(String appList) { this.appList = appList; } public String getAppList() { return this.appList; } public void setHapList(String hapList) { this.hapList = hapList; } public String getHapList() { return this.hapList; } public String getDirList() { return this.dirList; } public void setDirList(String dirList) { this.dirList = dirList; } public List getFormatedDirList() { return this.formatedDirList; } /** * get dEntryCard path * * @return formattedEntryCardPathList */ public List getformattedEntryCardPathList() { return formattedEntryCardPathList; } /** * get canonical path * * @param path path input * @return formatted path */ public String getFormattedPath(String path) { if (path == null) { return ""; } File file = new File(path); String canonicalPath; try { canonicalPath = file.getCanonicalPath(); } catch (IOException exception) { canonicalPath = INVALID_PATH; LOG.error("Utility::getFormattedPath exception," + exception.getMessage()); } return canonicalPath; } /** * close stream. * * @param stream stream to close */ static void closeStream(Closeable stream) { if (stream != null) { try { stream.close(); } catch (IOException exception) { LOG.error("Utility::closeStream io close exception: " + exception.getMessage()); } } } /** * Add form name. * * @param formName the name of form */ public void addFormNameList(String formName) { this.formNameList.add(formName); } /** * Get all form names * * @return all form names */ public List getFormNameList() { return formNameList; } public String getHqfList() { return hqfList; } public void setHqfList(String hqfList) { this.hqfList = hqfList; } public List getFormatedHQFList() { return formatedHQFList; } public void setFormatedHQFList(List formatedHQFList) { this.formatedHQFList = formatedHQFList; } public void setAPPQFPath(String appqfPath) { this.appqfPath = appqfPath; } public String getAPPQFPath() { return this.appqfPath; } public void setANPath(String anPath) { this.anPath = anPath; } public String getANPath() { return this.anPath; } public void setAPPath(String apPath) { this.apPath = apPath; } public String getAPPath() { return this.apPath; } public String getAbsoluteHapPath() { return this.absoluteHapPath; } public void setAbsoluteHapPath(String absoluteHapPath) { if (!absoluteHapPath.startsWith(CMD_PREFIX)) { this.absoluteHapPath = getFormattedPath(absoluteHapPath); } } public void setIsSharedApp(boolean isSharedApp) { this.isSharedApp = isSharedApp; } public Boolean getSharedApp() { return isSharedApp; } public void setIsAppService(boolean isAppService) { this.isAppService = isAppService; } public Boolean getIsAppService() { return isAppService; } public void setMainModuleLimit(String limit) { this.mainModuleLimit = limit; } public String getMainModuleLimit() { return mainModuleLimit; } public String getNormalModuleLimit() { return normalModuleLimit; } public void setNormalModuleLimit(String limit) { this.normalModuleLimit = limit; } public String getTotalLimit() { return totalLimit; } public void setTotalLimit(String limit) { this.totalLimit = limit; } public int getCompressLevel() { return compressLevel; } public void setCompressLevel(int compressLevel) { this.compressLevel = compressLevel; } public String getPkgContextPath() { return pkgContextPath; } public void setPkgContextPath(String pkgContextPath) { this.pkgContextPath = pkgContextPath; } public String getBundleName() { return bundleName; } public void setBundleName(String bundleName) { this.bundleName = bundleName; } public String getHspList() { return hspList; } public void setHspList(String hspList) { this.hspList = hspList; } public void setGenerateBuildHash(boolean generateBuildHash) { this.generateBuildHash = generateBuildHash; } public boolean getGenerateBuildHash() { return generateBuildHash; } public void setBuildHashFinish(boolean buildHashFinish) { this.buildHashFinish = buildHashFinish; } public boolean isBuildHashFinish() { return buildHashFinish; } public String getInputList() { return inputList; } public void setInputList(String inputList) { this.inputList = inputList; } public String getInput() { return input; } public void setInput(String input) { this.input = getFormattedPath(input); } public boolean getStatDuplicate() { return statDuplicate; } public void setStatDuplicate(boolean statDuplicate) { this.statDuplicate = statDuplicate; } public boolean getStatSuffix() { return statSuffix; } public void setStatSuffix(boolean statSuffix) { this.statSuffix = statSuffix; } public String getStatFileSize() { return statFileSize; } public void setStatFileSize(String statFileSize) { this.statFileSize = statFileSize; } }