1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package ohos; 17 18 import java.io.Closeable; 19 import java.io.File; 20 import java.io.IOException; 21 import java.util.ArrayList; 22 import java.util.List; 23 import java.util.Locale; 24 25 /** 26 * common resource. 27 * 28 */ 29 public class Utility { 30 static final String MODE_HAP = "hap"; 31 static final String MODE_HAR = "har"; 32 static final String MODE_APP = "app"; 33 static final String MODE_MULTI_APP = "multiApp"; 34 static final String MODE_HQF = "hqf"; 35 static final String MODE_APPQF = "appqf"; 36 static final String MODE_RES = "res"; 37 static final String MODE_HSP = "hsp"; 38 static final String FALSE_STRING = "false"; 39 40 private static final String CMD_PREFIX = "--"; 41 private static final Log LOG = new Log(Utility.class.toString()); 42 43 private String mode = ""; 44 private String jsonPath = ""; 45 private String profilePath = ""; 46 private String soPath = ""; 47 private String soDir = ""; 48 private String abilitySoPath = ""; 49 private String dexPath = ""; 50 private String abcPath = ""; 51 private String indexPath = ""; 52 private String hapPath = ""; 53 private String appPath = ""; 54 private String libPath = ""; 55 private String resPath = ""; 56 private String resourcesPath = ""; 57 private String assetsPath = ""; 58 private String apkPath = ""; 59 private String certificatePath = ""; 60 private String signaturePath = ""; 61 private String forceRewrite = "false"; 62 private String outPath = ""; 63 private String packInfoPath = ""; 64 private String binPath = ""; 65 private boolean isCompressNativeLibs = true; 66 private String moduleName = ""; 67 private String harPath = ""; 68 private String hspPath = ""; 69 private String jarPath = ""; 70 private String txtPath = ""; 71 private String parseMode = ""; 72 private String deviceType = ""; 73 private String hapName = ""; 74 private String sharedLibsPath = ""; 75 private String unpackApk = "false"; 76 private String unpackCutEntryApk = "false"; 77 private String entryCardPath = ""; 78 private String packRes = ""; 79 private String packResPath = ""; 80 private String filePath = ""; 81 private String jsPath = ""; 82 private String etsPath = ""; 83 private String rpcidPath = ""; 84 private int VersionCode = -1; 85 private String VersionName = ""; 86 private boolean isModuleJson = false; 87 private String rpcid = FALSE_STRING; 88 private String packPath = ""; 89 private boolean isParse = false; 90 private String appqfPath = ""; 91 private String anPath = ""; 92 private String apPath = ""; 93 private String mainModuleLimit = ""; 94 private String normalModuleLimit = ""; 95 private String totalLimit = ""; 96 97 private List<String> formattedSoPathList = new ArrayList<>(); 98 private List<String> formattedAbilitySoPathList = new ArrayList<>(); 99 private List<String> formattedDexPathList = new ArrayList<>(); 100 private List<String> formattedAbcPathList = new ArrayList<>(); 101 private List<String> formattedHapPathList = new ArrayList<>(); 102 private List<String> formattedHspPathList = new ArrayList<>(); 103 private List<String> formattedApkPathList = new ArrayList<>(); 104 private List<String> formattedJarPathList = new ArrayList<>(); 105 private List<String> formattedTxtPathList = new ArrayList<>(); 106 private List<String> formattedEntryCardPathList = new ArrayList<>(); 107 private List<String> formNameList = new ArrayList<>(); 108 private List<String> formattedAppList = new ArrayList<>(); 109 private List<String> formattedHapList = new ArrayList<>(); 110 private List<String> formatedDirList = new ArrayList<>(); 111 112 private List<String> formatedHQFList = new ArrayList<>(); 113 private List<String> formatedABCList = new ArrayList<>(); 114 115 private String appList = ""; 116 private String hapList = ""; 117 private String dirList = ""; 118 private String hqfList = ""; 119 private String hspList = ""; 120 setIsParse(boolean isParse)121 public void setIsParse(boolean isParse) { 122 this.isParse = isParse; 123 } 124 getIsParse()125 public boolean getIsParse() { 126 return isParse; 127 } 128 getMode()129 public String getMode() { 130 return mode; 131 } 132 setMode(String mode)133 public void setMode(String mode) { 134 if (!mode.startsWith(CMD_PREFIX)) { 135 this.mode = mode; 136 } 137 } 138 getJsonPath()139 public String getJsonPath() { 140 return jsonPath; 141 } 142 setJsonPath(String jsonPath)143 public void setJsonPath(String jsonPath) { 144 if (!jsonPath.startsWith(CMD_PREFIX)) { 145 this.jsonPath = getFormattedPath(jsonPath); 146 } 147 } 148 getProfilePath()149 public String getProfilePath() { 150 return profilePath; 151 } 152 setProfilePath(String profilePath)153 public void setProfilePath(String profilePath) { 154 if (!profilePath.startsWith(CMD_PREFIX)) { 155 this.profilePath = getFormattedPath(profilePath); 156 } 157 } 158 getSoPath()159 public String getSoPath() { 160 return soPath; 161 } 162 setSoPath(String soPath)163 public void setSoPath(String soPath) { 164 if (!soPath.startsWith(CMD_PREFIX)) { 165 this.soPath = soPath; 166 } 167 } 168 getAbilitySoPath()169 public String getAbilitySoPath() { 170 return abilitySoPath; 171 } 172 setAbilitySoPath(String abilitySoPath)173 public void setAbilitySoPath(String abilitySoPath) { 174 if (!abilitySoPath.startsWith(CMD_PREFIX)) { 175 this.abilitySoPath = abilitySoPath; 176 } 177 } 178 getSoDir()179 public String getSoDir() { 180 return soDir; 181 } 182 setSoDir(String soDir)183 public void setSoDir(String soDir) { 184 if (!soDir.startsWith(CMD_PREFIX)) { 185 this.soDir = soDir; 186 } 187 } 188 getDexPath()189 public String getDexPath() { 190 return dexPath; 191 } 192 setDexPath(String dexPath)193 public void setDexPath(String dexPath) { 194 if (!dexPath.startsWith(CMD_PREFIX)) { 195 this.dexPath = dexPath; 196 } 197 } 198 getAbcPath()199 public String getAbcPath() { 200 return abcPath; 201 } 202 setAbcPath(String abcPath)203 public void setAbcPath(String abcPath) { 204 if (!abcPath.startsWith(CMD_PREFIX)) { 205 this.abcPath = abcPath; 206 } 207 } 208 getABCList()209 public List<String> getABCList() { 210 return formatedABCList; 211 } 212 getFilePath()213 public String getFilePath() { 214 return filePath; 215 } 216 setFilePath(String filePath)217 public void setFilePath(String filePath) { 218 if (!filePath.startsWith(CMD_PREFIX)) { 219 this.filePath = filePath; 220 } 221 } 222 getIndexPath()223 public String getIndexPath() { 224 return indexPath; 225 } 226 setIndexPath(String indexPath)227 public void setIndexPath(String indexPath) { 228 if (!indexPath.startsWith(CMD_PREFIX)) { 229 this.indexPath = getFormattedPath(indexPath); 230 } 231 } 232 getBinPath()233 public String getBinPath() { 234 return binPath; 235 } 236 setBinPath(String binPath)237 public void setBinPath(String binPath) { 238 if (!binPath.startsWith(CMD_PREFIX)) { 239 this.binPath = getFormattedPath(binPath); 240 } 241 } 242 setIsModuleJson(boolean isModuleJson)243 public void setIsModuleJson(boolean isModuleJson) { 244 this.isModuleJson = isModuleJson; 245 } 246 getIsModuleJson()247 public boolean getIsModuleJson() { 248 return isModuleJson; 249 } 250 isCompressNativeLibs()251 public boolean isCompressNativeLibs() { 252 return isCompressNativeLibs; 253 } 254 setIsCompressNativeLibs(boolean isCompress)255 public void setIsCompressNativeLibs(boolean isCompress) { 256 this.isCompressNativeLibs = isCompress; 257 } 258 getHapPath()259 public String getHapPath() { 260 return hapPath; 261 } 262 setHapPath(String hapPath)263 public void setHapPath(String hapPath) { 264 if (!hapPath.startsWith(CMD_PREFIX)) { 265 this.hapPath = hapPath; 266 } 267 } 268 getAppPath()269 public String getAppPath() { 270 return appPath; 271 } 272 setAppPath(String appPath)273 public void setAppPath(String appPath) { 274 if (!appPath.startsWith(CMD_PREFIX)) { 275 this.appPath = appPath; 276 } 277 } 278 getLibPath()279 public String getLibPath() { 280 return libPath; 281 } 282 setLibPath(String libPath)283 public void setLibPath(String libPath) { 284 if (!libPath.startsWith(CMD_PREFIX)) { 285 this.libPath = getFormattedPath(libPath); 286 } 287 } 288 getResPath()289 public String getResPath() { 290 return resPath; 291 } 292 setResPath(String resPath)293 public void setResPath(String resPath) { 294 if (!resPath.startsWith(CMD_PREFIX)) { 295 this.resPath = getFormattedPath(resPath); 296 } 297 } 298 getResourcesPath()299 public String getResourcesPath() { 300 return resourcesPath; 301 } 302 setResourcesPath(String resourcesPath)303 public void setResourcesPath(String resourcesPath) { 304 if (!resourcesPath.startsWith(CMD_PREFIX)) { 305 this.resourcesPath = getFormattedPath(resourcesPath); 306 } 307 } 308 getAssetsPath()309 public String getAssetsPath() { 310 return assetsPath; 311 } 312 setAssetsPath(String assetsPath)313 public void setAssetsPath(String assetsPath) { 314 if (!assetsPath.startsWith(CMD_PREFIX)) { 315 this.assetsPath = getFormattedPath(assetsPath); 316 } 317 } 318 getModuleName()319 public String getModuleName() { 320 if (moduleName == null) { 321 moduleName = ""; 322 } 323 return moduleName; 324 } 325 setModuleName(String moduleName)326 public void setModuleName(String moduleName) { 327 this.moduleName = moduleName; 328 } 329 getApkPath()330 public String getApkPath() { 331 return apkPath; 332 } 333 setApkPath(String apkPath)334 public void setApkPath(String apkPath) { 335 if (!apkPath.startsWith(CMD_PREFIX)) { 336 this.apkPath = apkPath; 337 } 338 } 339 getCertificatePath()340 public String getCertificatePath() { 341 return certificatePath; 342 } 343 setCertificatePath(String certificatePath)344 public void setCertificatePath(String certificatePath) { 345 if (!certificatePath.startsWith(CMD_PREFIX)) { 346 this.certificatePath = getFormattedPath(certificatePath); 347 } 348 } 349 getSignaturePath()350 public String getSignaturePath() { 351 return signaturePath; 352 } 353 setSignaturePath(String signaturePath)354 public void setSignaturePath(String signaturePath) { 355 if (!signaturePath.startsWith(CMD_PREFIX)) { 356 this.signaturePath = getFormattedPath(signaturePath); 357 } 358 } 359 getForceRewrite()360 public String getForceRewrite() { 361 return forceRewrite; 362 } 363 setForceRewrite(String forceRewrite)364 public void setForceRewrite(String forceRewrite) { 365 if (!forceRewrite.startsWith(CMD_PREFIX)) { 366 this.forceRewrite = forceRewrite.toLowerCase(Locale.ENGLISH); 367 } 368 } 369 getOutPath()370 public String getOutPath() { 371 return outPath; 372 } 373 setOutPath(String outPath)374 public void setOutPath(String outPath) { 375 if (!outPath.startsWith(CMD_PREFIX)) { 376 this.outPath = getFormattedPath(outPath); 377 } 378 } 379 getPackInfoPath()380 public String getPackInfoPath() { 381 return packInfoPath; 382 } 383 setPackInfoPath(String packInfoPath)384 public void setPackInfoPath(String packInfoPath) { 385 if (!packInfoPath.startsWith(CMD_PREFIX)) { 386 this.packInfoPath = getFormattedPath(packInfoPath); 387 } 388 } 389 getJarPath()390 public String getJarPath() { 391 return jarPath; 392 } 393 setJarPath(String jarPath)394 public void setJarPath(String jarPath) { 395 if (!jarPath.startsWith(CMD_PREFIX)) { 396 this.jarPath = jarPath; 397 } 398 } 399 getTxtPath()400 public String getTxtPath() { 401 return txtPath; 402 } 403 setTxtPath(String txtPath)404 public void setTxtPath(String txtPath) { 405 if (!txtPath.startsWith(CMD_PREFIX)) { 406 this.txtPath = txtPath; 407 } 408 } 409 getHarPath()410 public String getHarPath() { 411 return harPath; 412 } 413 setHarPath(String harPath)414 public void setHarPath(String harPath) { 415 if (!harPath.startsWith(CMD_PREFIX)) { 416 this.harPath = harPath; 417 } 418 } 419 setHspPath(String hspPath)420 public void setHspPath(String hspPath) { 421 if (!hspPath.startsWith(CMD_PREFIX)) { 422 this.hspPath = hspPath; 423 } 424 } 425 getHspPath()426 public String getHspPath() { 427 return hspPath; 428 } 429 getParseMode()430 public String getParseMode() { 431 return parseMode; 432 } 433 setParseMode(String parseMode)434 public void setParseMode(String parseMode) { 435 if (!parseMode.startsWith(CMD_PREFIX)) { 436 this.parseMode = parseMode; 437 } 438 } 439 getDeviceType()440 public String getDeviceType() { 441 return deviceType; 442 } 443 setDeviceType(String deviceType)444 public void setDeviceType(String deviceType) { 445 if (!deviceType.startsWith(CMD_PREFIX)) { 446 this.deviceType = deviceType; 447 } 448 } 449 getUnpackApk()450 public String getUnpackApk() { 451 return unpackApk; 452 } 453 setUnpackApk(String unpackApk)454 public void setUnpackApk(String unpackApk) { 455 this.unpackApk = unpackApk; 456 } 457 getUnpackCutEntryApk()458 public String getUnpackCutEntryApk() { 459 return unpackCutEntryApk; 460 } 461 setUnpackCutEntryApk(String unpackCutEntryApk)462 public void setUnpackCutEntryApk(String unpackCutEntryApk) { 463 this.unpackCutEntryApk = unpackCutEntryApk; 464 } 465 getHapName()466 public String getHapName() { 467 return hapName; 468 } 469 setHapName(String hapName)470 public void setHapName(String hapName) { 471 if (!hapName.startsWith(CMD_PREFIX)) { 472 this.hapName = hapName; 473 } 474 } 475 getSharedLibsPath()476 public String getSharedLibsPath() { 477 return sharedLibsPath; 478 } 479 setSharedLibsPath(String sharedLibsPath)480 public void setSharedLibsPath(String sharedLibsPath) { 481 if (!sharedLibsPath.startsWith(CMD_PREFIX)) { 482 this.sharedLibsPath = sharedLibsPath; 483 } 484 } 485 getEntryCardPath()486 public String getEntryCardPath() { 487 return entryCardPath; 488 } 489 setEntryCardPath(String entryCardPath)490 public void setEntryCardPath(String entryCardPath) { 491 if (!entryCardPath.startsWith(CMD_PREFIX)) { 492 this.entryCardPath = entryCardPath; 493 } 494 } 495 getPackRes()496 public String getPackRes() { 497 return packRes; 498 } 499 setPackRes(String packRes)500 public void setPackRes(String packRes) { 501 this.packRes = packRes; 502 } 503 getPackResPath()504 public String getPackResPath() { 505 return packResPath; 506 } 507 setPackResPath(String packResPath)508 public void setPackResPath(String packResPath) { 509 this.packResPath = packResPath; 510 } 511 getJsPath()512 public String getJsPath() { return jsPath; } 513 setJsPath(String jsPath)514 public void setJsPath(String jsPath) { this.jsPath = jsPath; } 515 getEtsPath()516 public String getEtsPath() { return etsPath; } 517 setEtsPath(String etsPath)518 public void setEtsPath(String etsPath) { this.etsPath = etsPath; } 519 getRpcidPath()520 public String getRpcidPath() { 521 return rpcidPath; 522 } 523 setRpcidPath(String rpcidPath)524 public void setRpcidPath(String rpcidPath) { 525 this.rpcidPath = rpcidPath; 526 } 527 getRpcid()528 public String getRpcid() { return rpcid; } 529 setRpcid(String rpcid)530 public void setRpcid(String rpcid) { 531 this.rpcid = rpcid; 532 } 533 getVersionName()534 public String getVersionName() { 535 return VersionName; 536 } 537 setVersionName(String VersionName)538 public void setVersionName(String VersionName) { 539 this.VersionName = VersionName; 540 } 541 getVersionCode()542 public int getVersionCode() { 543 return VersionCode; 544 } 545 setVersionCode(int VersionCode)546 public void setVersionCode(int VersionCode) { 547 this.VersionCode = VersionCode; 548 } 549 getFormattedSoPathList()550 public List<String> getFormattedSoPathList() { 551 return formattedSoPathList; 552 } 553 getFormattedAbilitySoPathList()554 public List<String> getFormattedAbilitySoPathList() { 555 return formattedAbilitySoPathList; 556 } 557 getFormattedDexPathList()558 public List<String> getFormattedDexPathList() { 559 return formattedDexPathList; 560 } 561 getFormattedAbcPathList()562 public List<String> getFormattedAbcPathList() { 563 return formattedAbcPathList; 564 } 565 getFormattedHapPathList()566 public List<String> getFormattedHapPathList() { 567 return formattedHapPathList; 568 } 569 getFormattedHspPathList()570 public List<String> getFormattedHspPathList() { 571 return formattedHspPathList; 572 } 573 getFormattedApkPathList()574 public List<String> getFormattedApkPathList() { 575 return formattedApkPathList; 576 } 577 getFormattedJarPathList()578 public List<String> getFormattedJarPathList() { 579 return formattedJarPathList; 580 } 581 getFormattedTxtPathList()582 public List<String> getFormattedTxtPathList() { 583 return formattedTxtPathList; 584 } 585 getFormattedAppList()586 public List<String> getFormattedAppList() { 587 return formattedAppList; 588 } 589 getFormattedHapList()590 public List<String> getFormattedHapList() { 591 return formattedHapList; 592 } 593 setAppList(String appList)594 public void setAppList(String appList) { 595 this.appList = appList; 596 } 597 getAppList()598 public String getAppList() { 599 return this.appList; 600 } 601 setHapList(String hapList)602 public void setHapList(String hapList) { 603 this.hapList = hapList; 604 } 605 getHapList()606 public String getHapList() { 607 return this.hapList; 608 } 609 getDirList()610 public String getDirList() { 611 return this.dirList; 612 } 613 setDirList(String dirList)614 public void setDirList(String dirList) { 615 this.dirList = dirList; 616 } 617 getFormatedDirList()618 public List<String> getFormatedDirList() { 619 return this.formatedDirList; 620 } 621 setMainModuleLimit(String limit)622 public void setMainModuleLimit(String limit) { 623 this.mainModuleLimit = limit; 624 } 625 getMainModuleLimit()626 public String getMainModuleLimit() { 627 return mainModuleLimit; 628 } 629 getNormalModuleLimit()630 public String getNormalModuleLimit() { 631 return normalModuleLimit; 632 } 633 setNormalModuleLimit(String limit)634 public void setNormalModuleLimit(String limit) { 635 this.normalModuleLimit = limit; 636 } 637 getTotalLimit()638 public String getTotalLimit() { 639 return totalLimit; 640 } 641 setTotalLimit(String limit)642 public void setTotalLimit(String limit) { 643 this.totalLimit = limit; 644 } 645 646 /** 647 * get dEntryCard path 648 * 649 * @return formattedEntryCardPathList 650 */ getformattedEntryCardPathList()651 public List<String> getformattedEntryCardPathList() { 652 return formattedEntryCardPathList; 653 } 654 655 /** 656 * get canonical path 657 * 658 * @param path path input 659 * @return formatted path 660 */ getFormattedPath(String path)661 public String getFormattedPath(String path) { 662 if (path == null) { 663 return ""; 664 } 665 666 File file = new File(path); 667 String canonicalPath; 668 try { 669 canonicalPath = file.getCanonicalPath(); 670 } catch (IOException exception) { 671 canonicalPath = ""; 672 LOG.error("Utility::getFormattedPath exception," + exception.getMessage()); 673 } 674 return canonicalPath; 675 } 676 677 /** 678 * close stream. 679 * 680 * @param stream stream to close 681 */ closeStream(Closeable stream)682 static void closeStream(Closeable stream) { 683 if (stream != null) { 684 try { 685 stream.close(); 686 } catch (IOException exception) { 687 LOG.error("Utility::closeStream io close exception: " + exception.getMessage()); 688 } 689 } 690 } 691 692 /** 693 * Add form name. 694 * 695 * @param formName the name of form 696 */ addFormNameList(String formName)697 public void addFormNameList(String formName) { 698 this.formNameList.add(formName); 699 } 700 701 /** 702 * Get all form names 703 * 704 * @return all form names 705 */ getFormNameList()706 public List<String> getFormNameList() { 707 return formNameList; 708 } 709 getHqfList()710 public String getHqfList() { 711 return hqfList; 712 } 713 setHqfList(String hqfList)714 public void setHqfList(String hqfList) { 715 this.hqfList = hqfList; 716 } 717 getFormatedHQFList()718 public List<String> getFormatedHQFList() { 719 return formatedHQFList; 720 } 721 setFormatedHQFList(List<String> formatedHQFList)722 public void setFormatedHQFList(List<String> formatedHQFList) { 723 this.formatedHQFList = formatedHQFList; 724 } 725 setAPPQFPath(String appqfPath)726 public void setAPPQFPath(String appqfPath) { 727 this.appqfPath = appqfPath; 728 } 729 getAPPQFPath()730 public String getAPPQFPath() { 731 return this.appqfPath; 732 } 733 setANPath(String anPath)734 public void setANPath(String anPath) { 735 this.anPath = anPath; 736 } 737 getANPath()738 public String getANPath() { 739 return this.anPath; 740 } 741 setAPPath(String apPath)742 public void setAPPath(String apPath) { 743 this.apPath = apPath; 744 } 745 getAPPath()746 public String getAPPath() { 747 return this.apPath; 748 } 749 getHspList()750 public String getHspList() { 751 return hspList; 752 } 753 setHspList(String hspList)754 public void setHspList(String hspList) { 755 this.hspList = hspList; 756 } 757 } 758