From ac54b60c0fbd40eb11407c5d4e6abc6de99943fa Mon Sep 17 00:00:00 2001 From: "fenghao (P)" Date: Mon, 26 Apr 2021 14:45:47 +0800 Subject: [PATCH 1/7] =?UTF-8?q?IssueNo:#I3O7GN=20Description:EntryCard?= =?UTF-8?q?=E6=89=93=E5=8C=85=E6=A0=A1=E9=AA=8C=E5=A2=9E=E5=BC=BA=20Sig:aa?= =?UTF-8?q?fwk=20Feature=20or=20Bugfix:=20Bugfix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- com/huawei/ohos/CompressVerify.java | 19 ++- com/huawei/ohos/Compressor.java | 195 +++++++++++++++++++++++----- 2 files changed, 182 insertions(+), 32 deletions(-) diff --git a/com/huawei/ohos/CompressVerify.java b/com/huawei/ohos/CompressVerify.java index 06f1ba7b..2ee8b7b2 100755 --- a/com/huawei/ohos/CompressVerify.java +++ b/com/huawei/ohos/CompressVerify.java @@ -44,7 +44,7 @@ public class CompressVerify { private static final String TXT_SUFFIX = ".txt"; private static final String PNG_SUFFIX = ".png"; private static final String RES_SUFFIX = ".res"; - private static final String ENTRYCARD = "EntryCard"; + private static final String ENTRY_CARD_DIRECTORY_NAME = "EntryCard"; private static final Log LOG = new Log(CompressVerify.class.toString()); @@ -323,8 +323,13 @@ public class CompressVerify { return false; } + if (!isDirectoryValidStrictCase(utility.getEntryCardPath(), ENTRY_CARD_DIRECTORY_NAME)) { + LOG.error("CompressVerify::isArgsValidInResMode the level-1 directory name must is EntryCard" + + ", current is " + utility.getEntryCardPath()); + return false; + } if (!compatibleProcess(utility, utility.getEntryCardPath(), - utility.getformattedEntryCardPathList(), ENTRYCARD)) { + utility.getformattedEntryCardPathList(), PNG_SUFFIX)) { LOG.error("CompressVerify::isArgsValidInResMode entrycard-path is invalid!"); return false; } @@ -439,6 +444,14 @@ public class CompressVerify { return (!isFile) && file.isDirectory(); } + private static boolean isDirectoryValidStrictCase(String path, String directoryName) { + File file = new File(path); + if (file.isDirectory()) { + return directoryName.equals(file.getName()); + } + return false; + } + /** * remove duplicate in path. * @@ -456,4 +469,4 @@ public class CompressVerify { } return list; } -} \ No newline at end of file +} diff --git a/com/huawei/ohos/Compressor.java b/com/huawei/ohos/Compressor.java index 1dda71ce..42cb4620 100755 --- a/com/huawei/ohos/Compressor.java +++ b/com/huawei/ohos/Compressor.java @@ -25,10 +25,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.nio.file.attribute.FileTime; -import java.nio.file.Files; import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -95,6 +93,13 @@ public class Compressor { private static final String PIC_2X2 = "2x2"; private static final String PIC_2X4 = "2x4"; private static final String PIC_4X4 = "4x4"; + private static final String REGEX_LANGUAGE = "^[A-Z]{2}$"; + private static final String REGEX_SCRIPT = "^[A-Z][a-z]{3}$"; + private static final String REGEX_COUNTRY = "^[A-Z]{2,3}|[0-9]{3}$"; + private static final String REGEX_ORIENTATION = "^vertical|horizontal$"; + private static final String REGEX_DEVICE_TYPE = "^phone|tablet|car|tv|wearable|liteWearable$"; + private static final String REGEX_SCREEN_DENSITY = "^sdpi|mdpi|ldpi|xldpi|xxldpi$"; + private static final String REGEX_COLOR_MODE = "^light|dark$"; // set timestamp to get fixed MD5 @@ -109,11 +114,12 @@ public class Compressor { private static String versionName = ""; private ZipOutputStream zipOut = null; + private boolean mIsContain2x2EntryCard = true; private List list = new ArrayList(); private List formNamesList = new ArrayList(); private List fileNameList = new ArrayList(); - private List supportDimensionsList = Arrays.asList(PIC_1X2, PIC_2X4, PIC_4X4); + private List supportDimensionsList = Arrays.asList(PIC_1X2, PIC_2X2, PIC_2X4, PIC_4X4); /** * start compress. @@ -549,7 +555,10 @@ public class Compressor { } if (!utility.getEntryCardPath().isEmpty()) { getFileList(utility.getEntryCardPath()); - boolean isSatisfies = true; + if (!mIsContain2x2EntryCard) { + LOG.error("Compressor::compressPackResMode No 2x2 resource file exists"); + throw new BundleException("No 2x2 resource file exists"); + } for (String fileName : fileNameList) { if (fileName.endsWith(PNG_SUFFIX) || fileName.endsWith(UPPERCASE_PNG_SUFFIX)) { String fName = fileName.trim(); @@ -559,33 +568,32 @@ public class Compressor { + temp.length); continue; } - String fileModelName = temp[temp.length - 4]; - if (!isModelName(fileModelName)) { - LOG.error("Compressor::compressProcess compress failed ModelName Error!"); - isSatisfies = false; - break; + String moduleName = temp[temp.length - 4]; + if (!isModelName(moduleName)) { + LOG.error("Compressor::compressProcess compress pack.res failed moduleName " + + moduleName + " is error, please check it in config.json"); + throw new BundleException("Compress pack.res failed, moduleName Error"); } String fileLanguageCountryName = temp[temp.length - 3]; - if (!isLanguageCountry(fileLanguageCountryName)) { - LOG.error("Compressor::compressProcess compress failed LanguageCountryName Error!"); - isSatisfies = false; - break; + if (!isThirdLevelDirectoryNameValid(fileLanguageCountryName)) { + LOG.error("Compressor::compressProcess compress failed third level directory Error!"); + throw new BundleException("Compress failed third level directory Error!"); } String filePicturingName = temp[temp.length - 1]; - if (!filePicturingName.contains(PIC_2X2) && !isPicturing(filePicturingName)) { - LOG.error("Compressor::compressProcess compress failed PicturingName Error!"); - isSatisfies = false; - break; + if (!isPicturing(filePicturingName)) { + LOG.error("Compressor::compressProcess Compress failed pack.res failed, Invalid resource file" + + " name: " + filePicturingName + ", correct format example is formName-2x2.png"); + throw new BundleException("Compress failed pack.res failed, Invalid resource file name: " + + filePicturingName + ", correct format example is formName-2x2.png"); } } else { - isSatisfies = false; LOG.error("Compressor::compressProcess compress failed No image in PNG format is found!"); + throw new BundleException("Compress pack.res failed, compress failed No image in" + + " PNG format is found"); } } - if (isSatisfies) { - pathToFile(utility, utility.getEntryCardPath(), ENTRYCARD_NAME, false); - } + pathToFile(utility, utility.getEntryCardPath(), ENTRYCARD_NAME, false); } } @@ -604,6 +612,105 @@ public class Compressor { return false; } + private boolean isThirdLevelDirectoryNameValid(String thirdLevelDictoryName) { + if (thirdLevelDictoryName == null || thirdLevelDictoryName.isEmpty()) { + return false; + } + if (ENTRYCARD_BASE_NAME.equals(thirdLevelDictoryName)) { + return false; + } + // example: zh_Hani_CN-vertical-car-mdpi-dark or zh_Hani_CN-vertical-car-mdpi + int firstDelimiterIndex = thirdLevelDictoryName.indexOf("_"); + String language = thirdLevelDictoryName.substring(0, firstDelimiterIndex); + int secondDelimiterIndex = thirdLevelDictoryName.indexOf("_", firstDelimiterIndex + 1); + String script = thirdLevelDictoryName.substring(firstDelimiterIndex + 1, secondDelimiterIndex); + int thirdDelimiterIndex = thirdLevelDictoryName.indexOf("-", secondDelimiterIndex + 1); + String country = thirdLevelDictoryName.substring(secondDelimiterIndex + 1, thirdDelimiterIndex); + if (!checkLanguage(language) || !checkScript(script) || !checkCountry(country)) { + return false; + } + int forthDelimiterIndex = thirdLevelDictoryName.indexOf("-", thirdDelimiterIndex + 1); + String orientation = thirdLevelDictoryName.substring(thirdDelimiterIndex + 1, forthDelimiterIndex); + int fifthDelimiterIndex = thirdLevelDictoryName.indexOf("_", forthDelimiterIndex + 1); + String deviceType = thirdLevelDictoryName.substring(forthDelimiterIndex + 1, fifthDelimiterIndex); + if (!checkOrientation(orientation) || !checkDeviceType(deviceType)) { + return false; + } + int sixthDelimiterIndex = thirdLevelDictoryName.indexOf("-", fifthDelimiterIndex + 1); + if (sixthDelimiterIndex < 0) { + String screenDensity = thirdLevelDictoryName.substring(fifthDelimiterIndex + 1, + thirdLevelDictoryName.length()); + return checkScreenDensity(screenDensity); + } else { + String screenDensity = thirdLevelDictoryName.substring(fifthDelimiterIndex + 1, sixthDelimiterIndex); + if (!checkScreenDensity(screenDensity)) { + return false; + } + } + String colorMode = thirdLevelDictoryName.substring(sixthDelimiterIndex + 1, thirdLevelDictoryName.length()); + return checkColorMode(colorMode); + } + + private boolean checkLanguage(String language) { + if (!Pattern.compile(REGEX_LANGUAGE).matcher(language).matches()) { + LOG.error("Compressor::compressProcess language " + language + ", is not in ISO 639-1 list"); + return false; + } + return true; + } + + private boolean checkScript(String script) { + if (!Pattern.compile(REGEX_SCRIPT).matcher(script).matches()) { + LOG.error("Compressor::compressProcess script " + script + ", is not in ISO 15942 list"); + return false; + } + return true; + } + + private boolean checkCountry(String country) { + if (!Pattern.compile(REGEX_COUNTRY).matcher(country).matches()) { + LOG.error("Compressor::compressProcess country " + country + ", is not in ISO 3166-1 list"); + return false; + } + return true; + } + + private boolean checkOrientation(String orientation) { + if (!Pattern.compile(REGEX_ORIENTATION).matcher(orientation).matches()) { + LOG.error("Compressor::compressProcess orientation " + orientation + + ", is not in {vertical, horizontal} list"); + return false; + } + return true; + } + + private boolean checkDeviceType(String deviceType) { + if (!Pattern.compile(REGEX_DEVICE_TYPE).matcher(deviceType).matches()) { + LOG.error("Compressor::compressProcess deviceType " + deviceType + + ", is not in {phone, tablet, car, tv, wearable, liteWearable} list"); + return false; + } + return true; + } + + private boolean checkScreenDensity(String screenDensity) { + if (!Pattern.compile(REGEX_SCREEN_DENSITY).matcher(screenDensity).matches()) { + LOG.error("Compressor::compressProcess screenDensity " + screenDensity + + ", is not in {sdpi, mdpi, ldpi, xldpi, xxldpi} list"); + return false; + } + return true; + } + + private boolean checkColorMode(String colorMode) { + if (!Pattern.compile(REGEX_COLOR_MODE).matcher(colorMode).matches()) { + LOG.error("Compressor::compressProcess colorMode " + colorMode + + ", is not in {light, dark} list"); + return false; + } + return true; + } + /** * Check whether languageCountryName meets specifications. * @@ -665,16 +772,15 @@ public class Compressor { return false; } String dimension = name.substring(delimiterIndex + 1, name.lastIndexOf(".")); - return supportDimensionsList.contains(dimension); + if (!supportDimensionsList.contains(dimension)) { + LOG.error("isPicturing: the dimension: " + dimension + " is invalid, is not in the following list: " + + "{1x2, 2x2, 2x4, 4x4}"); + return false; + } + return true; } - /** - * get file list in filePath - * - * @param filePath file path - * @param fileList file path in arrayList - */ - private void getFileList(final String filePath) { + private void getFileList(final String filePath) throws BundleException { File file = new File(filePath); if (!file.exists()) { LOG.error("getFileList: file is not exists"); @@ -692,6 +798,14 @@ public class Compressor { deleteFile(f.getCanonicalPath()); continue; } + String snapshotDirectoryName = f.getParentFile().getName(); + if (!ENTRYCARD_SNAPSHOT_NAME.equals(snapshotDirectoryName)) { + LOG.error("The level-4 directory of EntryCard must be named as snapshot" + + ", but current is: " + snapshotDirectoryName); + throw new BundleException("The level-4 directory of EntryCard must be named as snapshot" + + ", but current is: " + snapshotDirectoryName); + } + checkContain2x2EntryCard(f.getParentFile()); fileNameList.add(f.getCanonicalPath()); } else if (f.isDirectory()) { getFileList(f.getCanonicalPath()); @@ -705,6 +819,29 @@ public class Compressor { } } + private void checkContain2x2EntryCard(final File snapshotDirectory) throws IOException, BundleException { + if (!snapshotDirectory.exists()) { + LOG.error("checkContain2x2EntryCard: file is not exist: " + snapshotDirectory.getName()); + throw new BundleException("checkContain2x2EntryCard: file is not exist"); + } + File[] files = snapshotDirectory.listFiles(); + if (files == null) { + LOG.error("checkContain2x2EntryCard: no file in this file path"); + throw new BundleException("checkContain2x2EntryCard: no file in this file path"); + } + + for (File entryCardFile : files) { + if (entryCardFile.isFile() && entryCardFile.getName().contains(PIC_2X2)) { + return; + } + } + mIsContain2x2EntryCard = false; + LOG.error("checkContain2x2EntryCard: must contains 2x2 entryCard, please check it in " + + snapshotDirectory.getCanonicalPath()); + throw new BundleException("checkContain2x2EntryCard: must contains 2x2 entryCard, please check it in " + + snapshotDirectory.getCanonicalPath()); + } + /** * compress file or directory. * -- Gitee From 69ec8fec38d781c0165b9e9029b9bc607c134495 Mon Sep 17 00:00:00 2001 From: "fenghao (P)" Date: Mon, 26 Apr 2021 16:06:49 +0800 Subject: [PATCH 2/7] =?UTF-8?q?ssueNo:#I3O7GN=20Description:EntryCard?= =?UTF-8?q?=E6=89=93=E5=8C=85=E6=A0=A1=E9=AA=8C=E5=A2=9E=E5=BC=BA=20Sig:aa?= =?UTF-8?q?fwk=20Feature=20or=20Bugfix:=20Bugfix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- com/huawei/ohos/CompressVerify.java | 5 ++ com/huawei/ohos/Compressor.java | 74 ++++++++++++++--------------- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/com/huawei/ohos/CompressVerify.java b/com/huawei/ohos/CompressVerify.java index 2ee8b7b2..de12390f 100755 --- a/com/huawei/ohos/CompressVerify.java +++ b/com/huawei/ohos/CompressVerify.java @@ -446,6 +446,11 @@ public class CompressVerify { private static boolean isDirectoryValidStrictCase(String path, String directoryName) { File file = new File(path); + if (!file.exists()) { + LOG.error("CompressVerify::isDirectoryValidStrictCase directory is not exist, directoryPath: " + + path); + return false; + } if (file.isDirectory()) { return directoryName.equals(file.getName()); } diff --git a/com/huawei/ohos/Compressor.java b/com/huawei/ohos/Compressor.java index 42cb4620..567d0f65 100755 --- a/com/huawei/ohos/Compressor.java +++ b/com/huawei/ohos/Compressor.java @@ -93,7 +93,7 @@ public class Compressor { private static final String PIC_2X2 = "2x2"; private static final String PIC_2X4 = "2x4"; private static final String PIC_4X4 = "4x4"; - private static final String REGEX_LANGUAGE = "^[A-Z]{2}$"; + private static final String REGEX_LANGUAGE = "^[a-z]{2}$"; private static final String REGEX_SCRIPT = "^[A-Z][a-z]{3}$"; private static final String REGEX_COUNTRY = "^[A-Z]{2,3}|[0-9]{3}$"; private static final String REGEX_ORIENTATION = "^vertical|horizontal$"; @@ -555,10 +555,10 @@ public class Compressor { } if (!utility.getEntryCardPath().isEmpty()) { getFileList(utility.getEntryCardPath()); - if (!mIsContain2x2EntryCard) { - LOG.error("Compressor::compressPackResMode No 2x2 resource file exists"); - throw new BundleException("No 2x2 resource file exists"); - } + if (!mIsContain2x2EntryCard) { + LOG.error("Compressor::compressPackResMode No 2x2 resource file exists"); + throw new BundleException("No 2x2 resource file exists"); + } for (String fileName : fileNameList) { if (fileName.endsWith(PNG_SUFFIX) || fileName.endsWith(UPPERCASE_PNG_SUFFIX)) { String fName = fileName.trim(); @@ -570,20 +570,20 @@ public class Compressor { } String moduleName = temp[temp.length - 4]; if (!isModelName(moduleName)) { - LOG.error("Compressor::compressProcess compress pack.res failed moduleName " + LOG.error("Compressor::compressProcess compress pack.res failed, moduleName " + moduleName + " is error, please check it in config.json"); throw new BundleException("Compress pack.res failed, moduleName Error"); } String fileLanguageCountryName = temp[temp.length - 3]; if (!isThirdLevelDirectoryNameValid(fileLanguageCountryName)) { - LOG.error("Compressor::compressProcess compress failed third level directory Error!"); - throw new BundleException("Compress failed third level directory Error!"); + LOG.error("Compressor::compressProcess compress failed third level directory name Error!"); + throw new BundleException("Compress failed third level directory name Error!"); } String filePicturingName = temp[temp.length - 1]; if (!isPicturing(filePicturingName)) { - LOG.error("Compressor::compressProcess Compress failed pack.res failed, Invalid resource file" + + LOG.error("Compressor::compressProcess Compress pack.res failed, Invalid resource file" + " name: " + filePicturingName + ", correct format example is formName-2x2.png"); - throw new BundleException("Compress failed pack.res failed, Invalid resource file name: " + throw new BundleException("Compress pack.res failed, Invalid resource file name: " + filePicturingName + ", correct format example is formName-2x2.png"); } @@ -612,48 +612,48 @@ public class Compressor { return false; } - private boolean isThirdLevelDirectoryNameValid(String thirdLevelDictoryName) { - if (thirdLevelDictoryName == null || thirdLevelDictoryName.isEmpty()) { + private boolean isThirdLevelDirectoryNameValid(String thirdLevelDirectoryName) { + if (thirdLevelDirectoryName == null || thirdLevelDirectoryName.isEmpty()) { return false; } - if (ENTRYCARD_BASE_NAME.equals(thirdLevelDictoryName)) { - return false; + if (ENTRYCARD_BASE_NAME.equals(thirdLevelDirectoryName)) { + return true; } // example: zh_Hani_CN-vertical-car-mdpi-dark or zh_Hani_CN-vertical-car-mdpi - int firstDelimiterIndex = thirdLevelDictoryName.indexOf("_"); - String language = thirdLevelDictoryName.substring(0, firstDelimiterIndex); - int secondDelimiterIndex = thirdLevelDictoryName.indexOf("_", firstDelimiterIndex + 1); - String script = thirdLevelDictoryName.substring(firstDelimiterIndex + 1, secondDelimiterIndex); - int thirdDelimiterIndex = thirdLevelDictoryName.indexOf("-", secondDelimiterIndex + 1); - String country = thirdLevelDictoryName.substring(secondDelimiterIndex + 1, thirdDelimiterIndex); + int firstDelimiterIndex = thirdLevelDirectoryName.indexOf("_"); + String language = thirdLevelDirectoryName.substring(0, firstDelimiterIndex); + int secondDelimiterIndex = thirdLevelDirectoryName.indexOf("_", firstDelimiterIndex + 1); + String script = thirdLevelDirectoryName.substring(firstDelimiterIndex + 1, secondDelimiterIndex); + int thirdDelimiterIndex = thirdLevelDirectoryName.indexOf("-", secondDelimiterIndex + 1); + String country = thirdLevelDirectoryName.substring(secondDelimiterIndex + 1, thirdDelimiterIndex); if (!checkLanguage(language) || !checkScript(script) || !checkCountry(country)) { return false; } - int forthDelimiterIndex = thirdLevelDictoryName.indexOf("-", thirdDelimiterIndex + 1); - String orientation = thirdLevelDictoryName.substring(thirdDelimiterIndex + 1, forthDelimiterIndex); - int fifthDelimiterIndex = thirdLevelDictoryName.indexOf("_", forthDelimiterIndex + 1); - String deviceType = thirdLevelDictoryName.substring(forthDelimiterIndex + 1, fifthDelimiterIndex); + int forthDelimiterIndex = thirdLevelDirectoryName.indexOf("-", thirdDelimiterIndex + 1); + String orientation = thirdLevelDirectoryName.substring(thirdDelimiterIndex + 1, forthDelimiterIndex); + int fifthDelimiterIndex = thirdLevelDirectoryName.indexOf("-", forthDelimiterIndex + 1); + String deviceType = thirdLevelDirectoryName.substring(forthDelimiterIndex + 1, fifthDelimiterIndex); if (!checkOrientation(orientation) || !checkDeviceType(deviceType)) { return false; } - int sixthDelimiterIndex = thirdLevelDictoryName.indexOf("-", fifthDelimiterIndex + 1); + int sixthDelimiterIndex = thirdLevelDirectoryName.indexOf("-", fifthDelimiterIndex + 1); if (sixthDelimiterIndex < 0) { - String screenDensity = thirdLevelDictoryName.substring(fifthDelimiterIndex + 1, - thirdLevelDictoryName.length()); + String screenDensity = thirdLevelDirectoryName.substring(fifthDelimiterIndex + 1, + thirdLevelDirectoryName.length()); return checkScreenDensity(screenDensity); } else { - String screenDensity = thirdLevelDictoryName.substring(fifthDelimiterIndex + 1, sixthDelimiterIndex); + String screenDensity = thirdLevelDirectoryName.substring(fifthDelimiterIndex + 1, sixthDelimiterIndex); if (!checkScreenDensity(screenDensity)) { return false; } } - String colorMode = thirdLevelDictoryName.substring(sixthDelimiterIndex + 1, thirdLevelDictoryName.length()); + String colorMode = thirdLevelDirectoryName.substring(sixthDelimiterIndex + 1, thirdLevelDirectoryName.length()); return checkColorMode(colorMode); } private boolean checkLanguage(String language) { if (!Pattern.compile(REGEX_LANGUAGE).matcher(language).matches()) { - LOG.error("Compressor::compressProcess language " + language + ", is not in ISO 639-1 list"); + LOG.error("Compressor::compressProcess language " + language + " is not in ISO 639-1 list"); return false; } return true; @@ -661,7 +661,7 @@ public class Compressor { private boolean checkScript(String script) { if (!Pattern.compile(REGEX_SCRIPT).matcher(script).matches()) { - LOG.error("Compressor::compressProcess script " + script + ", is not in ISO 15942 list"); + LOG.error("Compressor::compressProcess script " + script + " is not in ISO 15924 list"); return false; } return true; @@ -678,7 +678,7 @@ public class Compressor { private boolean checkOrientation(String orientation) { if (!Pattern.compile(REGEX_ORIENTATION).matcher(orientation).matches()) { LOG.error("Compressor::compressProcess orientation " + orientation + - ", is not in {vertical, horizontal} list"); + " is not in {vertical, horizontal} list"); return false; } return true; @@ -687,7 +687,7 @@ public class Compressor { private boolean checkDeviceType(String deviceType) { if (!Pattern.compile(REGEX_DEVICE_TYPE).matcher(deviceType).matches()) { LOG.error("Compressor::compressProcess deviceType " + deviceType + - ", is not in {phone, tablet, car, tv, wearable, liteWearable} list"); + " is not in {phone, tablet, car, tv, wearable, liteWearable} list"); return false; } return true; @@ -696,7 +696,7 @@ public class Compressor { private boolean checkScreenDensity(String screenDensity) { if (!Pattern.compile(REGEX_SCREEN_DENSITY).matcher(screenDensity).matches()) { LOG.error("Compressor::compressProcess screenDensity " + screenDensity + - ", is not in {sdpi, mdpi, ldpi, xldpi, xxldpi} list"); + " is not in {sdpi, mdpi, ldpi, xldpi, xxldpi} list"); return false; } return true; @@ -774,7 +774,7 @@ public class Compressor { String dimension = name.substring(delimiterIndex + 1, name.lastIndexOf(".")); if (!supportDimensionsList.contains(dimension)) { LOG.error("isPicturing: the dimension: " + dimension + " is invalid, is not in the following list: " - + "{1x2, 2x2, 2x4, 4x4}"); + + "{1X2, 2X2, 2X4, 4X4}"); return false; } return true; @@ -836,9 +836,9 @@ public class Compressor { } } mIsContain2x2EntryCard = false; - LOG.error("checkContain2x2EntryCard: must contains 2x2 entryCard, please check it in " + LOG.error("checkContain2x2EntryCard: must contain 2x2 entryCard, please check it in " + snapshotDirectory.getCanonicalPath()); - throw new BundleException("checkContain2x2EntryCard: must contains 2x2 entryCard, please check it in " + throw new BundleException("checkContain2x2EntryCard: must contain 2x2 entryCard, please check it in " + snapshotDirectory.getCanonicalPath()); } -- Gitee From d4a0c96696145e4981d761192b0631e518c8dc3b Mon Sep 17 00:00:00 2001 From: "fenghao (P)" Date: Mon, 26 Apr 2021 16:45:35 +0800 Subject: [PATCH 3/7] =?UTF-8?q?IsueNo:#I3O7GN=20Description:EntryCard?= =?UTF-8?q?=E6=89=93=E5=8C=85=E6=A0=A1=E9=AA=8C=E5=A2=9E=E5=BC=BA=20Sig:aa?= =?UTF-8?q?fwk=20Feature=20or=20Bugfix:=20Bugfix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- com/huawei/ohos/Compressor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com/huawei/ohos/Compressor.java b/com/huawei/ohos/Compressor.java index 567d0f65..9de03dca 100755 --- a/com/huawei/ohos/Compressor.java +++ b/com/huawei/ohos/Compressor.java @@ -669,7 +669,7 @@ public class Compressor { private boolean checkCountry(String country) { if (!Pattern.compile(REGEX_COUNTRY).matcher(country).matches()) { - LOG.error("Compressor::compressProcess country " + country + ", is not in ISO 3166-1 list"); + LOG.error("Compressor::compressProcess country " + country + " is not in ISO 3166-1 list"); return false; } return true; @@ -705,7 +705,7 @@ public class Compressor { private boolean checkColorMode(String colorMode) { if (!Pattern.compile(REGEX_COLOR_MODE).matcher(colorMode).matches()) { LOG.error("Compressor::compressProcess colorMode " + colorMode + - ", is not in {light, dark} list"); + " is not in {light, dark} list"); return false; } return true; -- Gitee From 11e104b8bbaa6fb3c809ba46e476a78032b78621 Mon Sep 17 00:00:00 2001 From: "fenghao (P)" Date: Mon, 26 Apr 2021 16:50:33 +0800 Subject: [PATCH 4/7] =?UTF-8?q?IssueNo:#I3O7GN=20Description:EntryCard?= =?UTF-8?q?=E6=89=93=E5=8C=85=E6=A0=A1=E9=AA=8C=E5=A2=9E=E5=BC=BA=20Sig:aa?= =?UTF-8?q?fwk=20Feature=20or=20Bugfix:=20Bugfix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- com/huawei/ohos/CompressVerify.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/com/huawei/ohos/CompressVerify.java b/com/huawei/ohos/CompressVerify.java index de12390f..4a8537a2 100755 --- a/com/huawei/ohos/CompressVerify.java +++ b/com/huawei/ohos/CompressVerify.java @@ -323,11 +323,11 @@ public class CompressVerify { return false; } - if (!isDirectoryValidStrictCase(utility.getEntryCardPath(), ENTRY_CARD_DIRECTORY_NAME)) { - LOG.error("CompressVerify::isArgsValidInResMode the level-1 directory name must is EntryCard" + - ", current is " + utility.getEntryCardPath()); - return false; - } + if (!isDirectoryValidStrictCase(utility.getEntryCardPath(), ENTRY_CARD_DIRECTORY_NAME)) { + LOG.error("CompressVerify::isArgsValidInResMode the level-1 directory name must is EntryCard" + + ", current is " + utility.getEntryCardPath()); + return false; + } if (!compatibleProcess(utility, utility.getEntryCardPath(), utility.getformattedEntryCardPathList(), PNG_SUFFIX)) { LOG.error("CompressVerify::isArgsValidInResMode entrycard-path is invalid!"); -- Gitee From cfd0d911c1e811b5cdf52f28e56acd6c109d6348 Mon Sep 17 00:00:00 2001 From: "fenghao (P)" Date: Mon, 26 Apr 2021 20:56:32 +0800 Subject: [PATCH 5/7] =?UTF-8?q?IssueNo:#I3O7GN=20Description:EntryCard?= =?UTF-8?q?=E6=89=93=E5=8C=85=E6=A0=A1=E9=AA=8C=E5=A2=9E=E5=BC=BA=20Sig:aa?= =?UTF-8?q?fwk=20Feature=20or=20Bugfix:=20Bugfix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- com/huawei/ohos/Compressor.java | 45 ++++++++++++++++++++++++--------- com/huawei/ohos/Utility.java | 17 +++++++++++++ 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/com/huawei/ohos/Compressor.java b/com/huawei/ohos/Compressor.java index 9de03dca..8137a3f2 100755 --- a/com/huawei/ohos/Compressor.java +++ b/com/huawei/ohos/Compressor.java @@ -576,11 +576,13 @@ public class Compressor { } String fileLanguageCountryName = temp[temp.length - 3]; if (!isThirdLevelDirectoryNameValid(fileLanguageCountryName)) { - LOG.error("Compressor::compressProcess compress failed third level directory name Error!"); + LOG.error("Compressor::compressProcess compress failed third level directory name: " + + fileLanguageCountryName + " is invalid, please check it with reference to this example: " + + "zh_Hani_CN-vertical-car-mdpi-dark or zh_Hani_CN-vertical-car-mdpi"); throw new BundleException("Compress failed third level directory name Error!"); } String filePicturingName = temp[temp.length - 1]; - if (!isPicturing(filePicturingName)) { + if (!isPicturing(filePicturingName, utility)) { LOG.error("Compressor::compressProcess Compress pack.res failed, Invalid resource file" + " name: " + filePicturingName + ", correct format example is formName-2x2.png"); throw new BundleException("Compress pack.res failed, Invalid resource file name: " @@ -621,17 +623,32 @@ public class Compressor { } // example: zh_Hani_CN-vertical-car-mdpi-dark or zh_Hani_CN-vertical-car-mdpi int firstDelimiterIndex = thirdLevelDirectoryName.indexOf("_"); + if (firstDelimiterIndex < 0) { + return false; + } String language = thirdLevelDirectoryName.substring(0, firstDelimiterIndex); int secondDelimiterIndex = thirdLevelDirectoryName.indexOf("_", firstDelimiterIndex + 1); + if (secondDelimiterIndex < 0) { + return false; + } String script = thirdLevelDirectoryName.substring(firstDelimiterIndex + 1, secondDelimiterIndex); int thirdDelimiterIndex = thirdLevelDirectoryName.indexOf("-", secondDelimiterIndex + 1); + if (thirdDelimiterIndex < 0) { + return false; + } String country = thirdLevelDirectoryName.substring(secondDelimiterIndex + 1, thirdDelimiterIndex); if (!checkLanguage(language) || !checkScript(script) || !checkCountry(country)) { return false; } int forthDelimiterIndex = thirdLevelDirectoryName.indexOf("-", thirdDelimiterIndex + 1); + if (forthDelimiterIndex < 0) { + return false; + } String orientation = thirdLevelDirectoryName.substring(thirdDelimiterIndex + 1, forthDelimiterIndex); int fifthDelimiterIndex = thirdLevelDirectoryName.indexOf("-", forthDelimiterIndex + 1); + if (fifthDelimiterIndex < 0) { + return false; + } String deviceType = thirdLevelDirectoryName.substring(forthDelimiterIndex + 1, fifthDelimiterIndex); if (!checkOrientation(orientation) || !checkDeviceType(deviceType)) { return false; @@ -752,7 +769,7 @@ public class Compressor { * @param name picturingName * @return false and true */ - private boolean isPicturing(String name) { + private boolean isPicturing(String name, Utility utility) { boolean isSpecifications = false; if (name == null || name.isEmpty()) { return isSpecifications; @@ -767,8 +784,9 @@ public class Compressor { return false; } String formName = name.substring(0, delimiterIndex); - if (!formNamesList.contains(formName)) { - LOG.error("isPicturing: the name is not same as formName, name: " + formName); + if (!utility.getFormNameList().contains(formName)) { + LOG.error("isPicturing: the name is not same as formName, name: " + formName + " is not in " + + utility.getFormNameList().toString()); return false; } String dimension = name.substring(delimiterIndex + 1, name.lastIndexOf(".")); @@ -1171,7 +1189,7 @@ public class Compressor { inputStreamReader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8); bufferedReader = new BufferedReader(inputStreamReader); bufferedReader.mark((int) srcFile.length() + 1); - // parse moduleName from config.json + // parse moduleName from pack.json parsePackModuleName(bufferedReader, utility); bufferedReader.reset(); parsePackFormName(bufferedReader, utility); @@ -1459,20 +1477,22 @@ public class Compressor { */ private void parsePackFormName(BufferedReader bufferedReader, Utility utility) throws BundleException { String lineStr = null; - boolean isDistroStart = false; try { + boolean isFormsStart = false; while ((lineStr = bufferedReader.readLine()) != null) { if (lineStr.contains("abilities")) { continue; } if (lineStr.contains(FORMS)) { + isFormsStart = true; continue; } if (lineStr.contains(JSON_END)) { continue; } - if (lineStr.contains(NAME)) { + if (isFormsStart && lineStr.contains(NAME)) { getNameFromString(lineStr, utility); + isFormsStart = false; } } } catch (IOException exception) { @@ -1497,14 +1517,15 @@ public class Compressor { throw new BundleException("Parse module name failed, module-name is invalid"); } int startIndex = lineStr.lastIndexOf(SEMICOLON, endIndex - 1) + 1; - String fromsName = lineStr.substring(startIndex, endIndex); - if (fromsName == null || fromsName.isEmpty()) { + String formName = lineStr.substring(startIndex, endIndex); + if (formName == null || formName.isEmpty()) { LOG.error("Compressor::getModuleNameFromString field module-name is empty"); throw new BundleException("Parse module name failed, module-name is empty"); } - String[] nameList = fromsName.split("\\."); + String[] nameList = formName.split("\\."); if (nameList.length <= 1) { - formNamesList.add(fromsName); + formNamesList.add(formName); + utility.addFormNameList(formName); } } catch (StringIndexOutOfBoundsException exception) { LOG.error("Compressor::parseModuleName field module-name is fault: " + exception.getMessage()); diff --git a/com/huawei/ohos/Utility.java b/com/huawei/ohos/Utility.java index 4b997643..da2e7c42 100755 --- a/com/huawei/ohos/Utility.java +++ b/com/huawei/ohos/Utility.java @@ -84,6 +84,7 @@ public class Utility { private List formattedJarPathList = new ArrayList<>(); private List formattedTxtPathList = new ArrayList<>(); private List formattedEntryCardPathList = new ArrayList<>(); + private List formNameList = new ArrayList<>(); public String getMode() { return mode; @@ -513,4 +514,20 @@ public class Utility { } } } + + /** + * Add form name. + */ + public void addFormNameList(String formName) { + this.formNameList.add(formName); + } + + /** + * Get all form names + * + * @return all form names + */ + public List getFormNameList() { + return formNameList; + } } -- Gitee From 233f640cb185cb137636abe4e0d873932bc455b6 Mon Sep 17 00:00:00 2001 From: "fenghao (P)" Date: Mon, 26 Apr 2021 21:43:18 +0800 Subject: [PATCH 6/7] =?UTF-8?q?IssueNo:#I3O7GN=20Description:EntryCard?= =?UTF-8?q?=E6=89=93=E5=8C=85=E6=A0=A1=E9=AA=8C=E5=A2=9E=E5=BC=BA=20Sig:aa?= =?UTF-8?q?fwk=20Feature=20or=20Bugfix:=20Bugfix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- com/huawei/ohos/Compressor.java | 3 ++- com/huawei/ohos/Utility.java | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/com/huawei/ohos/Compressor.java b/com/huawei/ohos/Compressor.java index 8137a3f2..54ee1eb6 100755 --- a/com/huawei/ohos/Compressor.java +++ b/com/huawei/ohos/Compressor.java @@ -767,6 +767,7 @@ public class Compressor { * Check whether picturingName meets specifications. * * @param name picturingName + * @param utility common data * @return false and true */ private boolean isPicturing(String name, Utility utility) { @@ -1189,7 +1190,7 @@ public class Compressor { inputStreamReader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8); bufferedReader = new BufferedReader(inputStreamReader); bufferedReader.mark((int) srcFile.length() + 1); - // parse moduleName from pack.json + // parse moduleName from pack.info parsePackModuleName(bufferedReader, utility); bufferedReader.reset(); parsePackFormName(bufferedReader, utility); diff --git a/com/huawei/ohos/Utility.java b/com/huawei/ohos/Utility.java index da2e7c42..ebf86e52 100755 --- a/com/huawei/ohos/Utility.java +++ b/com/huawei/ohos/Utility.java @@ -517,6 +517,8 @@ public class Utility { /** * Add form name. + * + * @param formName the name of form */ public void addFormNameList(String formName) { this.formNameList.add(formName); -- Gitee From 5deee21b41317c7f4bd0d2f4106a6a531316f6ed Mon Sep 17 00:00:00 2001 From: "fenghao (P)" Date: Tue, 27 Apr 2021 09:57:16 +0800 Subject: [PATCH 7/7] =?UTF-8?q?IssueNo:#I3O7GN=20Description:EntryCard?= =?UTF-8?q?=E6=89=93=E5=8C=85=E6=A0=A1=E9=AA=8C=E5=A2=9E=E5=BC=BA=20Sig:aa?= =?UTF-8?q?fwk=20Feature=20or=20Bugfix:=20Bugfix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- com/huawei/ohos/CompressVerify.java | 18 +++++++++--------- com/huawei/ohos/Compressor.java | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/com/huawei/ohos/CompressVerify.java b/com/huawei/ohos/CompressVerify.java index 4a8537a2..94715aa4 100755 --- a/com/huawei/ohos/CompressVerify.java +++ b/com/huawei/ohos/CompressVerify.java @@ -323,11 +323,11 @@ public class CompressVerify { return false; } - if (!isDirectoryValidStrictCase(utility.getEntryCardPath(), ENTRY_CARD_DIRECTORY_NAME)) { - LOG.error("CompressVerify::isArgsValidInResMode the level-1 directory name must is EntryCard" + - ", current is " + utility.getEntryCardPath()); - return false; - } + if (!isDirectoryValidStrictCase(utility.getEntryCardPath(), ENTRY_CARD_DIRECTORY_NAME)) { + LOG.error("CompressVerify::isArgsValidInResMode the level-1 directory name must is EntryCard" + + ", current is " + utility.getEntryCardPath()); + return false; + } if (!compatibleProcess(utility, utility.getEntryCardPath(), utility.getformattedEntryCardPathList(), PNG_SUFFIX)) { LOG.error("CompressVerify::isArgsValidInResMode entrycard-path is invalid!"); @@ -451,10 +451,10 @@ public class CompressVerify { + path); return false; } - if (file.isDirectory()) { - return directoryName.equals(file.getName()); - } - return false; + if (file.isDirectory()) { + return directoryName.equals(file.getName()); + } + return false; } /** diff --git a/com/huawei/ohos/Compressor.java b/com/huawei/ohos/Compressor.java index 54ee1eb6..1020310c 100755 --- a/com/huawei/ohos/Compressor.java +++ b/com/huawei/ohos/Compressor.java @@ -555,10 +555,10 @@ public class Compressor { } if (!utility.getEntryCardPath().isEmpty()) { getFileList(utility.getEntryCardPath()); - if (!mIsContain2x2EntryCard) { - LOG.error("Compressor::compressPackResMode No 2x2 resource file exists"); - throw new BundleException("No 2x2 resource file exists"); - } + if (!mIsContain2x2EntryCard) { + LOG.error("Compressor::compressPackResMode No 2x2 resource file exists"); + throw new BundleException("No 2x2 resource file exists"); + } for (String fileName : fileNameList) { if (fileName.endsWith(PNG_SUFFIX) || fileName.endsWith(UPPERCASE_PNG_SUFFIX)) { String fName = fileName.trim(); @@ -591,8 +591,8 @@ public class Compressor { } else { LOG.error("Compressor::compressProcess compress failed No image in PNG format is found!"); - throw new BundleException("Compress pack.res failed, compress failed No image in" - + " PNG format is found"); + throw new BundleException("Compress pack.res failed, compress failed No image in" + + " PNG format is found"); } } pathToFile(utility, utility.getEntryCardPath(), ENTRYCARD_NAME, false); -- Gitee