From 7564b35461f27b6fb3caeec0b838a46f3b36de90 Mon Sep 17 00:00:00 2001 From: theshadowco Date: Tue, 19 Dec 2023 18:17:10 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=97=D0=B0=D1=89=D0=B8=D1=89=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=B5=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_1c_syntax/bsl/mdo/CommonModule.java | 2 + .../com/github/_1c_syntax/bsl/mdo/Module.java | 5 + .../bsl/mdo/children/ObjectModule.java | 2 + .../reader/common/TransformationUtils.java | 25 ++++ .../converter/CommonModuleConverter.java | 17 ++- .../edt/converter/CommonModuleConverter.java | 24 +++- .../bsl/mdo/CalculationRegisterTest.java | 5 + .../_1c_syntax/bsl/mdo/CatalogTest.java | 5 +- .../_1c_syntax/bsl/mdo/DocumentTest.java | 3 +- .../Ext/RecordSetModule.bin" | Bin 0 -> 1903 bytes .../Ext/RecordSetModule.bsl" | 7 - .../Ext/ObjectModule.bin" | Bin 0 -> 1903 bytes .../Ext/ObjectModule.bsl" | 2 - .../RecordSetModule.bsl" | Bin 211 -> 1903 bytes .../ObjectModule.bsl" | Bin 2 -> 1903 bytes ...276\321\206\320\265\321\201\321\2011.json" | 3 +- ...321\206\320\265\321\201\321\2011_edt.json" | 3 +- ...201\321\207\320\265\321\202\320\2601.json" | 10 +- ...321\207\320\265\321\202\320\2601_edt.json" | 6 +- ...276\321\207\320\275\320\270\320\2721.json" | 35 +++-- ...321\207\320\275\320\270\320\2721_edt.json" | 27 ++-- ...207\320\265\321\202\320\276\320\2621.json" | 3 +- ...320\265\321\202\320\276\320\2621_edt.json" | 3 +- ...270\321\201\321\202\320\270\320\2721.json" | 14 +- ...321\201\321\202\320\270\320\2721_edt.json" | 14 +- ...274\320\260\320\275\320\264\320\2601.json" | 3 +- ...320\260\320\275\320\264\320\2601_edt.json" | 3 +- ...\244\320\276\321\200\320\274\320\260.json" | 3 +- ...\320\276\321\200\320\274\320\260_edt.json" | 3 +- ...\276\320\264\321\203\320\273\321\214.json" | 3 +- ...\320\264\321\203\320\273\321\214_edt.json" | 3 +- ...\200\320\262\320\265\321\200\320\260.json" | 3 +- ...\320\262\320\265\321\200\320\260_edt.json" | 3 +- ...\222\321\213\320\267\320\276\320\262.json" | 3 +- ...\321\213\320\267\320\276\320\262_edt.json" | 3 +- ...\241\320\265\320\260\320\275\321\201.json" | 3 +- ...\320\265\320\260\320\275\321\201_edt.json" | 3 +- ...\237\321\200\320\260\320\262\320\260.json" | 3 +- ...\321\200\320\260\320\262\320\260_edt.json" | 3 +- ...\276\320\264\321\203\320\273\321\214.json" | 3 +- ...\320\264\321\203\320\273\321\214_edt.json" | 3 +- ...202\320\260\320\275\321\202\320\2601.json" | 14 +- ...320\260\320\275\321\202\320\2601_edt.json" | 14 +- ...261\320\276\321\202\320\272\320\2601.json" | 12 +- ...320\276\321\202\320\272\320\2601_edt.json" | 12 +- ...265\320\275\321\202\320\276\320\2621.json" | 3 +- ...320\275\321\202\320\276\320\2621_edt.json" | 3 +- ...203\320\274\320\265\320\275\321\2021.json" | 44 +++--- ...320\274\320\265\320\275\321\2021_edt.json" | 44 +++--- ...273\320\265\320\275\320\270\320\2651.json" | 3 +- ...320\265\320\275\320\270\320\2651_edt.json" | 3 +- ...261\320\274\320\265\320\275\320\2601.json" | 3 +- ...320\274\320\265\320\275\320\2601_edt.json" | 3 +- ...\217\320\241\320\243\320\221\320\224.json" | 42 ++++-- ...\320\241\320\243\320\221\320\224_edt.json" | 42 ++++-- ...202\320\261\320\276\321\200\320\2601.json" | 3 +- ...320\261\320\276\321\200\320\2601_edt.json" | 3 +- ...265\321\200\320\262\320\270\321\2011.json" | 3 +- ...321\200\320\262\320\270\321\2011_edt.json" | 3 +- ...264\320\265\320\275\320\270\320\2711.json" | 5 +- ...320\265\320\275\320\270\320\2711_edt.json" | 5 +- ...236\321\202\321\207\320\265\321\2021.json" | 14 +- ...321\202\321\207\320\265\321\2021_edt.json" | 14 +- ...275\320\276\321\201\321\202\321\2141.json" | 3 +- ...320\276\321\201\321\202\321\2141_edt.json" | 3 +- ...265\321\200\320\262\320\270\321\2011.json" | 3 +- ...321\200\320\262\320\270\321\2011_edt.json" | 3 +- .../Bots.\320\221\320\276\321\2021.json" | 3 +- .../Bots.\320\221\320\276\321\2021_edt.json" | 3 +- .../mdclasses_3_18/Configuration.json | 1 + .../mdclasses_3_18/Configuration_edt.json | 1 + ...200\320\260\321\206\320\270\320\2701.json" | 3 +- ...320\260\321\206\320\270\320\2701_edt.json" | 3 +- ...\264\320\260\320\275\320\270\320\265.json" | 38 ++++-- ...\320\260\320\275\320\270\320\265_edt.json" | 38 ++++-- ...\274\320\265\321\202\320\272\320\270.json" | 39 ++++-- ...\320\265\321\202\320\272\320\270_edt.json" | 39 ++++-- ...\264\320\265\320\275\320\270\321\217.json" | 42 ++++-- ...\320\265\320\275\320\270\321\217_edt.json" | 42 ++++-- ...\270\321\201\321\214\320\274\320\276.json" | 3 +- ...\321\201\321\214\320\274\320\276_edt.json" | 3 +- ...\276\320\277\321\200\320\276\321\201.json" | 3 +- ...\320\277\321\200\320\276\321\201_edt.json" | 3 +- ...\260\320\261\320\276\321\202\320\260.json" | 1 + ...\320\261\320\276\321\202\320\260_edt.json" | 1 + ...\222\320\260\320\273\321\216\321\202.json" | 38 ++++-- ...\320\260\320\273\321\216\321\202_edt.json" | 38 ++++-- ...\201\321\202\320\262\320\270\321\217.json" | 129 ++++++++++++------ ...\321\202\320\262\320\270\321\217_edt.json" | 129 ++++++++++++------ ...\275\320\272\320\265\321\202\320\260.json" | 26 ++-- ...\320\272\320\265\321\202\320\260_edt.json" | 26 ++-- ...\273\320\265\320\275\320\270\321\217.json" | 3 +- ...\320\265\320\275\320\270\321\217_edt.json" | 3 +- ...\271\320\221\320\260\320\267\321\213.json" | 10 +- ...\320\221\320\260\320\267\321\213_edt.json" | 10 +- ...\264\320\277\320\270\321\201\320\270.json" | 3 +- ...\320\277\320\270\321\201\320\270_edt.json" | 3 +- ...\207\320\265\321\202\320\276\320\262.json" | 87 ++++++++---- ...\320\265\321\202\320\276\320\262_edt.json" | 87 ++++++++---- ...\270\321\202\320\265\320\273\321\217.json" | 122 +++++++++++------ ...\321\202\320\265\320\273\321\217_edt.json" | 122 +++++++++++------ ...rvices.EnterpriseDataExchange_1_0_1_1.json | 3 +- ...es.EnterpriseDataExchange_1_0_1_1_edt.json | 3 +- 103 files changed, 1110 insertions(+), 565 deletions(-) create mode 100644 "src/test/resources/ext/designer/mdclasses/src/cf/CalculationRegisters/\320\240\320\265\320\263\320\270\321\201\321\202\321\200\320\240\320\260\321\201\321\207\320\265\321\202\320\2601/Recalculations/\320\237\320\265\321\200\320\265\321\200\320\260\321\201\321\207\320\265\321\202/Ext/RecordSetModule.bin" delete mode 100644 "src/test/resources/ext/designer/mdclasses/src/cf/CalculationRegisters/\320\240\320\265\320\263\320\270\321\201\321\202\321\200\320\240\320\260\321\201\321\207\320\265\321\202\320\2601/Recalculations/\320\237\320\265\321\200\320\265\321\200\320\260\321\201\321\207\320\265\321\202/Ext/RecordSetModule.bsl" create mode 100644 "src/test/resources/ext/designer/mdclasses/src/cf/Catalogs/\320\241\320\277\321\200\320\260\320\262\320\276\321\207\320\275\320\270\320\2721/Ext/ObjectModule.bin" delete mode 100644 "src/test/resources/ext/designer/mdclasses/src/cf/Catalogs/\320\241\320\277\321\200\320\260\320\262\320\276\321\207\320\275\320\270\320\2721/Ext/ObjectModule.bsl" diff --git a/src/main/java/com/github/_1c_syntax/bsl/mdo/CommonModule.java b/src/main/java/com/github/_1c_syntax/bsl/mdo/CommonModule.java index dea424343..b7d443888 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/mdo/CommonModule.java +++ b/src/main/java/com/github/_1c_syntax/bsl/mdo/CommonModule.java @@ -70,6 +70,8 @@ public class CommonModule implements MDObject, Module, ModuleOwner { URI uri; + boolean isProtected; + /* * Свое */ diff --git a/src/main/java/com/github/_1c_syntax/bsl/mdo/Module.java b/src/main/java/com/github/_1c_syntax/bsl/mdo/Module.java index f52be221b..2d31761da 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/mdo/Module.java +++ b/src/main/java/com/github/_1c_syntax/bsl/mdo/Module.java @@ -44,4 +44,9 @@ public interface Module { * Вариант поддержки родительской конфигурации */ SupportVariant getSupportVariant(); + + /** + * Признак "защищенности" модуля, т.е. наличия пароля и отсутствие исходного кода + */ + boolean isProtected(); } diff --git a/src/main/java/com/github/_1c_syntax/bsl/mdo/children/ObjectModule.java b/src/main/java/com/github/_1c_syntax/bsl/mdo/children/ObjectModule.java index a5980a680..b72f34005 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/mdo/children/ObjectModule.java +++ b/src/main/java/com/github/_1c_syntax/bsl/mdo/children/ObjectModule.java @@ -46,4 +46,6 @@ public class ObjectModule implements Module { MdoReference owner = MdoReference.EMPTY; @Default SupportVariant supportVariant = SupportVariant.NONE; + + boolean isProtected; } diff --git a/src/main/java/com/github/_1c_syntax/bsl/reader/common/TransformationUtils.java b/src/main/java/com/github/_1c_syntax/bsl/reader/common/TransformationUtils.java index 2cedb1870..1be1ded8b 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/reader/common/TransformationUtils.java +++ b/src/main/java/com/github/_1c_syntax/bsl/reader/common/TransformationUtils.java @@ -43,13 +43,17 @@ import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.map.CaseInsensitiveMap; +import org.apache.commons.io.FilenameUtils; +import java.io.FileInputStream; +import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.lang.reflect.WildcardType; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -72,6 +76,8 @@ public class TransformationUtils { private static final String BUILDER_METHOD_NAME = "builder"; private static final String LOGGER_MESSAGE_PREF = "Class {}, method {}"; + private static final byte[] PROTECTED_FILE_HEADER = new byte[]{-1, -1, -1, 127}; + public void setValue(Object source, String methodName, Object value) { var method = getMethod(source.getClass(), methodName); if (method != null && value != null) { @@ -362,12 +368,31 @@ private void addModules() { modulePath = EDTPaths.modulePath(folder, name, moduleType); } + var isProtected = false; + // возможно модуль защищен + if (!modulePath.toFile().exists()) { + var prtModulePath = Paths.get(FilenameUtils.removeExtension(modulePath.toFile().getPath()) + ".bin"); + if (prtModulePath.toFile().exists()) { + isProtected = true; + modulePath = prtModulePath; + } + } else { + var bytes = new byte[PROTECTED_FILE_HEADER.length]; + try (var fis = new FileInputStream(modulePath.toFile())) { + isProtected = (fis.read(bytes) == PROTECTED_FILE_HEADER.length + && Arrays.equals(bytes, PROTECTED_FILE_HEADER)); + } catch (IOException e) { + // ошибка чтения в данном случае неважна + } + } + if (modulePath.toFile().exists()) { modules.add(ObjectModule.builder() .moduleType(moduleType) .uri(modulePath.toUri()) .owner(mdoReference) .supportVariant(supportVariant) + .isProtected(isProtected) .build()); } } diff --git a/src/main/java/com/github/_1c_syntax/bsl/reader/designer/converter/CommonModuleConverter.java b/src/main/java/com/github/_1c_syntax/bsl/reader/designer/converter/CommonModuleConverter.java index a4026076b..95c95cdc2 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/reader/designer/converter/CommonModuleConverter.java +++ b/src/main/java/com/github/_1c_syntax/bsl/reader/designer/converter/CommonModuleConverter.java @@ -27,19 +27,34 @@ import com.github._1c_syntax.bsl.types.ModuleType; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.HierarchicalStreamReader; +import org.apache.commons.io.FilenameUtils; + +import java.nio.file.Paths; @DesignerConverter public class CommonModuleConverter extends AbstractReadConverter { private static final String URI_FIELD = "uri"; + private static final String IS_PROTECTED_FIELD = "isProtected"; @Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { var readerContext = super.read(reader, context); - var folder = DesignerPaths.moduleFolder(currentPath, MDOType.COMMON_MODULE); var modulePath = DesignerPaths.modulePath(folder, readerContext.getName(), ModuleType.CommonModule); + + var isProtected = false; + if (!modulePath.toFile().exists()) { + // возможно модуль защищен + var prtModulePath = Paths.get(FilenameUtils.removeExtension(modulePath.toFile().getPath()) + ".bin"); + if (prtModulePath.toFile().exists()) { + isProtected = true; + modulePath = prtModulePath; + } + } + readerContext.setValue(URI_FIELD, modulePath.toUri()); + readerContext.setValue(IS_PROTECTED_FIELD, isProtected); return readerContext.build(); } diff --git a/src/main/java/com/github/_1c_syntax/bsl/reader/edt/converter/CommonModuleConverter.java b/src/main/java/com/github/_1c_syntax/bsl/reader/edt/converter/CommonModuleConverter.java index 1d3551bf3..fcfc56f74 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/reader/edt/converter/CommonModuleConverter.java +++ b/src/main/java/com/github/_1c_syntax/bsl/reader/edt/converter/CommonModuleConverter.java @@ -28,19 +28,39 @@ import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.HierarchicalStreamReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Arrays; + @EDTConverter public class CommonModuleConverter extends AbstractReadConverter { private static final String URI_FIELD = "uri"; + private static final String IS_PROTECTED_FIELD = "isProtected"; + + private static final byte[] PROTECTED_FILE_HEADER = new byte[]{-1, -1, -1, 127}; @Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { var readerContext = super.read(reader, context); - var folder = EDTPaths.moduleFolder(currentPath, MDOType.COMMON_MODULE); var modulePath = EDTPaths.modulePath(folder, readerContext.getName(), ModuleType.CommonModule); - readerContext.setValue(URI_FIELD, modulePath.toUri()); + var isProtected = false; + if (modulePath.toFile().exists()) { + // возможно модуль защищен + var bytes = new byte[PROTECTED_FILE_HEADER.length]; + + try (var fis = new FileInputStream(modulePath.toFile())) { + isProtected = (fis.read(bytes) == PROTECTED_FILE_HEADER.length + && Arrays.equals(bytes, PROTECTED_FILE_HEADER)); + } catch (IOException e) { + // ошибка чтения в данном случае неважна + } + } + + readerContext.setValue(URI_FIELD, modulePath.toUri()); + readerContext.setValue(IS_PROTECTED_FIELD, isProtected); return readerContext.build(); } diff --git a/src/test/java/com/github/_1c_syntax/bsl/mdo/CalculationRegisterTest.java b/src/test/java/com/github/_1c_syntax/bsl/mdo/CalculationRegisterTest.java index 023cc934d..704063427 100644 --- a/src/test/java/com/github/_1c_syntax/bsl/mdo/CalculationRegisterTest.java +++ b/src/test/java/com/github/_1c_syntax/bsl/mdo/CalculationRegisterTest.java @@ -46,5 +46,10 @@ void test(ArgumentsAccessor argumentsAccessor) { assertThat(calculationRegister.getDimensions()).hasSize(1); assertThat(calculationRegister.getAttributes()).isEmpty(); assertThat(calculationRegister.getRecalculations()).hasSize(1); + var recalc = calculationRegister.getRecalculations().get(0); + assertThat(recalc.getModules()) + .hasSize(1) + .allMatch(Module::isProtected) + ; } } \ No newline at end of file diff --git a/src/test/java/com/github/_1c_syntax/bsl/mdo/CatalogTest.java b/src/test/java/com/github/_1c_syntax/bsl/mdo/CatalogTest.java index 65e6589b7..889952ddf 100644 --- a/src/test/java/com/github/_1c_syntax/bsl/mdo/CatalogTest.java +++ b/src/test/java/com/github/_1c_syntax/bsl/mdo/CatalogTest.java @@ -57,7 +57,10 @@ void test(ArgumentsAccessor argumentsAccessor) { assertThat(catalog.getForms()).hasSize(3); assertThat(catalog.getTemplates()).hasSize(1); assertThat(catalog.getCommands()).hasSize(1); - assertThat(catalog.getModules()).hasSize(2); + assertThat(catalog.getModules()) + .hasSize(2) + .anyMatch(Module::isProtected) + ; assertThat(catalog.getAllModules()).hasSize(6); assertThat(catalog.getMDOChildren()) .hasSize(4) diff --git a/src/test/java/com/github/_1c_syntax/bsl/mdo/DocumentTest.java b/src/test/java/com/github/_1c_syntax/bsl/mdo/DocumentTest.java index 26a4c4658..8951d4186 100644 --- a/src/test/java/com/github/_1c_syntax/bsl/mdo/DocumentTest.java +++ b/src/test/java/com/github/_1c_syntax/bsl/mdo/DocumentTest.java @@ -39,5 +39,4 @@ class DocumentTest { void test(ArgumentsAccessor argumentsAccessor) { var mdo = MDTestUtils.getMDWithSimpleTest(argumentsAccessor); } - -} \ No newline at end of file +} diff --git "a/src/test/resources/ext/designer/mdclasses/src/cf/CalculationRegisters/\320\240\320\265\320\263\320\270\321\201\321\202\321\200\320\240\320\260\321\201\321\207\320\265\321\202\320\2601/Recalculations/\320\237\320\265\321\200\320\265\321\200\320\260\321\201\321\207\320\265\321\202/Ext/RecordSetModule.bin" "b/src/test/resources/ext/designer/mdclasses/src/cf/CalculationRegisters/\320\240\320\265\320\263\320\270\321\201\321\202\321\200\320\240\320\260\321\201\321\207\320\265\321\202\320\2601/Recalculations/\320\237\320\265\321\200\320\265\321\200\320\260\321\201\321\207\320\265\321\202/Ext/RecordSetModule.bin" new file mode 100644 index 0000000000000000000000000000000000000000..5ebae878e02755d72145fd3f02c607228c72f6e7 GIT binary patch literal 1903 zcmbtVU279T6dembxU!%i^wDLg;KMA;Og7mpP3%Jpf`V4_1Ip&B6pTs@G|&b=CUOU%30|uMqkof)MXyon?z@7PFHb_U_EiJ!kGYvl$MDkI4)nXGqvg zgO8eYtSE5nVY5u5gm3L)AL6neE<47q;)`bqS;ns7D23E1q!ml?aOwH{#?lPYcZIt~ z8pJ27q^2H7l)w)YNY3L4e)PX>3T7Icbg@yTOfW}!j+b+#msO)uGTt@~bun7F0&k!T zN5K;q1WzqW;Vpc?hc0}9!{Ax)!h&7s2QMwy$FWcF5eCqM0j1YWW9*DoSfF$Z=PlTS z&z1!pID{kUo5s1qf?BkX8NR|nu%l<7J5NVskQ*P-4im4yI~c6!w*7}FXLwIhy&LgPS`_Z>$}2RBlk(2JW!#==JIrRWmpDnMV)2u z_RVs>b+@unx_AB2jgnt#EZ!*=(Q|k<+9ycWxyZQXnpdrQp*L0ilt*t-Cfh1Ri#?K=4WdUgAJ@A7PC@50qzt>5qE&)M~3+ToX8HUBaCM8T8x!QAwUOU%30|uMqkof)MXyon?z@7PFHb_U_EiJ!kGYvl$MDkI4)nXGqvg zgO8eYtSE5nVY5u5gm3L)AL6neE<47q;)`bqS;ns7D23E1q!ml?aOwH{#?lPYcZIt~ z8pJ27q^2H7l)w)YNY3L4e)PX>3T7Icbg@yTOfW}!j+b+#msO)uGTt@~bun7F0&k!T zN5K;q1WzqW;Vpc?hc0}9!{Ax)!h&7s2QMwy$FWcF5eCqM0j1YWW9*DoSfF$Z=PlTS z&z1!pID{kUo5s1qf?BkX8NR|nu%l<7J5NVskQ*P-4im4yI~c6!w*7}FXLwIhy&LgPS`_Z>$}2RBlk(2JW!#==JIrRWmpDnMV)2u z_RVs>b+@unx_AB2jgnt#EZ!*=(Q|k<+9ycWxyZQXnpdrQp*L0ilt*t-Cfh1Ri#?K=4WdUgAJ@A7PC@50qzt>5qE&)M~3+ToX8HUBaCM8T8x!QAwUOU%30|uMqkof)MXyon?z@7PFHb_U_EiJ!kGYvl$MDkI4)nXGqvg zgO8eYtSE5nVY5u5gm3L)AL6neE<47q;)`bqS;ns7D23E1q!ml?aOwH{#?lPYcZIt~ z8pJ27q^2H7l)w)YNY3L4e)PX>3T7Icbg@yTOfW}!j+b+#msO)uGTt@~bun7F0&k!T zN5K;q1WzqW;Vpc?hc0}9!{Ax)!h&7s2QMwy$FWcF5eCqM0j1YWW9*DoSfF$Z=PlTS z&z1!pID{kUo5s1qf?BkX8NR|nu%l<7J5NVskQ*P-4im4yI~c6!w*7}FXLwIhy&LgPS`_Z>$}2RBlk(2JW!#==JIrRWmpDnMV)2u z_RVs>b+@unx_AB2jgnt#EZ!*=(Q|k<+9ycWxyZQXnpdrQp*L0ilt*t-Cfh1Ri#?K=4WdUgAJ@A7PC@50qzt>5qE&)M~3+ToX8HUBaCM8T8x!QAwUOU%30|uMqkof)MXyon?z@7PFHb_U_EiJ!kGYvl$MDkI4)nXGqvg zgO8eYtSE5nVY5u5gm3L)AL6neE<47q;)`bqS;ns7D23E1q!ml?aOwH{#?lPYcZIt~ z8pJ27q^2H7l)w)YNY3L4e)PX>3T7Icbg@yTOfW}!j+b+#msO)uGTt@~bun7F0&k!T zN5K;q1WzqW;Vpc?hc0}9!{Ax)!h&7s2QMwy$FWcF5eCqM0j1YWW9*DoSfF$Z=PlTS z&z1!pID{kUo5s1qf?BkX8NR|nu%l<7J5NVskQ*P-4im4yI~c6!w*7}FXLwIhy&LgPS`_Z>$}2RBlk(2JW!#==JIrRWmpDnMV)2u z_RVs>b+@unx_AB2jgnt#EZ!*=(Q|k<+9ycWxyZQXnpdrQp*L0ilt*t-Cfh1Ri#?K=4WdUgAJ@A7PC@50qzt>5qE&)M~3+ToX8HUBaCM8T8x!QAw Date: Wed, 20 Dec 2023 17:32:35 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=BE=D0=B9=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bsl/reader/common/ReaderUtils.java | 81 +++++++++++++++++++ .../reader/common/TransformationUtils.java | 31 +------ .../edt/converter/CommonModuleConverter.java | 23 +----- 3 files changed, 89 insertions(+), 46 deletions(-) create mode 100644 src/main/java/com/github/_1c_syntax/bsl/reader/common/ReaderUtils.java diff --git a/src/main/java/com/github/_1c_syntax/bsl/reader/common/ReaderUtils.java b/src/main/java/com/github/_1c_syntax/bsl/reader/common/ReaderUtils.java new file mode 100644 index 000000000..3ad9d7c97 --- /dev/null +++ b/src/main/java/com/github/_1c_syntax/bsl/reader/common/ReaderUtils.java @@ -0,0 +1,81 @@ +/* + * This file is a part of MDClasses. + * + * Copyright (c) 2019 - 2023 + * Tymko Oleg , Maximov Valery and contributors + * + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * MDClasses is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * MDClasses is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with MDClasses. + */ +package com.github._1c_syntax.bsl.reader.common; + +import lombok.Getter; +import lombok.experimental.UtilityClass; +import org.apache.commons.io.FilenameUtils; + +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; + +/** + * Набор вспомогательных методов, используемых при чтении данных + */ +@UtilityClass +public class ReaderUtils { + private static final byte[] PROTECTED_FILE_HEADER = new byte[]{-1, -1, -1, 127}; + + /** + * Читает информацию о "защищенности" модуля + * + * @param modulePath Путь к файлу модуля + * @return Параметы "защищенности" + */ + public ProtectedModuleInfo readProtectedModuleInfo(Path modulePath) { + return new ProtectedModuleInfo(modulePath); + } + + /** + * Описание "защищенности" модуля + */ + public static class ProtectedModuleInfo { + @Getter + private boolean isProtected; + @Getter + private Path modulePath; + + private ProtectedModuleInfo(Path path) { + modulePath = path; + isProtected = false; + + if (!modulePath.toFile().exists()) { + var prtModulePath = Paths.get(FilenameUtils.removeExtension(modulePath.toFile().getPath()) + ".bin"); + if (prtModulePath.toFile().exists()) { + isProtected = true; + modulePath = prtModulePath; + } + } else { + var bytes = new byte[PROTECTED_FILE_HEADER.length]; + try (var fis = new FileInputStream(modulePath.toFile())) { + isProtected = (fis.read(bytes) == PROTECTED_FILE_HEADER.length + && Arrays.equals(bytes, PROTECTED_FILE_HEADER)); + } catch (IOException e) { + // ошибка чтения в данном случае неважна + } + } + } + } +} diff --git a/src/main/java/com/github/_1c_syntax/bsl/reader/common/TransformationUtils.java b/src/main/java/com/github/_1c_syntax/bsl/reader/common/TransformationUtils.java index 1be1ded8b..9d804c7f8 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/reader/common/TransformationUtils.java +++ b/src/main/java/com/github/_1c_syntax/bsl/reader/common/TransformationUtils.java @@ -43,17 +43,13 @@ import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.map.CaseInsensitiveMap; -import org.apache.commons.io.FilenameUtils; -import java.io.FileInputStream; -import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.lang.reflect.WildcardType; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -76,8 +72,6 @@ public class TransformationUtils { private static final String BUILDER_METHOD_NAME = "builder"; private static final String LOGGER_MESSAGE_PREF = "Class {}, method {}"; - private static final byte[] PROTECTED_FILE_HEADER = new byte[]{-1, -1, -1, 127}; - public void setValue(Object source, String methodName, Object value) { var method = getMethod(source.getClass(), methodName); if (method != null && value != null) { @@ -368,31 +362,14 @@ private void addModules() { modulePath = EDTPaths.modulePath(folder, name, moduleType); } - var isProtected = false; - // возможно модуль защищен - if (!modulePath.toFile().exists()) { - var prtModulePath = Paths.get(FilenameUtils.removeExtension(modulePath.toFile().getPath()) + ".bin"); - if (prtModulePath.toFile().exists()) { - isProtected = true; - modulePath = prtModulePath; - } - } else { - var bytes = new byte[PROTECTED_FILE_HEADER.length]; - try (var fis = new FileInputStream(modulePath.toFile())) { - isProtected = (fis.read(bytes) == PROTECTED_FILE_HEADER.length - && Arrays.equals(bytes, PROTECTED_FILE_HEADER)); - } catch (IOException e) { - // ошибка чтения в данном случае неважна - } - } - - if (modulePath.toFile().exists()) { + var protectedModuleInfo = ReaderUtils.readProtectedModuleInfo(modulePath); + if (protectedModuleInfo.getModulePath().toFile().exists()) { modules.add(ObjectModule.builder() .moduleType(moduleType) - .uri(modulePath.toUri()) + .uri(protectedModuleInfo.getModulePath().toUri()) .owner(mdoReference) .supportVariant(supportVariant) - .isProtected(isProtected) + .isProtected(protectedModuleInfo.isProtected()) .build()); } } diff --git a/src/main/java/com/github/_1c_syntax/bsl/reader/edt/converter/CommonModuleConverter.java b/src/main/java/com/github/_1c_syntax/bsl/reader/edt/converter/CommonModuleConverter.java index fcfc56f74..923724e86 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/reader/edt/converter/CommonModuleConverter.java +++ b/src/main/java/com/github/_1c_syntax/bsl/reader/edt/converter/CommonModuleConverter.java @@ -22,16 +22,13 @@ package com.github._1c_syntax.bsl.reader.edt.converter; import com.github._1c_syntax.bsl.mdo.CommonModule; +import com.github._1c_syntax.bsl.reader.common.ReaderUtils; import com.github._1c_syntax.bsl.reader.edt.EDTPaths; import com.github._1c_syntax.bsl.types.MDOType; import com.github._1c_syntax.bsl.types.ModuleType; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.HierarchicalStreamReader; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Arrays; - @EDTConverter public class CommonModuleConverter extends AbstractReadConverter { @@ -46,21 +43,9 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co var folder = EDTPaths.moduleFolder(currentPath, MDOType.COMMON_MODULE); var modulePath = EDTPaths.modulePath(folder, readerContext.getName(), ModuleType.CommonModule); - var isProtected = false; - if (modulePath.toFile().exists()) { - // возможно модуль защищен - var bytes = new byte[PROTECTED_FILE_HEADER.length]; - - try (var fis = new FileInputStream(modulePath.toFile())) { - isProtected = (fis.read(bytes) == PROTECTED_FILE_HEADER.length - && Arrays.equals(bytes, PROTECTED_FILE_HEADER)); - } catch (IOException e) { - // ошибка чтения в данном случае неважна - } - } - - readerContext.setValue(URI_FIELD, modulePath.toUri()); - readerContext.setValue(IS_PROTECTED_FIELD, isProtected); + var protectedModuleInfo = ReaderUtils.readProtectedModuleInfo(modulePath); + readerContext.setValue(URI_FIELD, protectedModuleInfo.getModulePath().toUri()); + readerContext.setValue(IS_PROTECTED_FIELD, protectedModuleInfo.isProtected()); return readerContext.build(); }