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