-
Notifications
You must be signed in to change notification settings - Fork 26
feat: API записи объектов метаданных (Subsystem, Catalog, Configuration) в форматах EDT и Конфигуратор #595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
johnnyshut
wants to merge
4
commits into
1c-syntax:develop
Choose a base branch
from
johnnyshut:feature/158
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5d60e9b
feat(writeObject): Добавлены методы writeObject и класс MDCWriteSettings
johnnyshut 1603f78
feat(writeObject): Добавлены классы и конвертеры для записи метаданны…
johnnyshut 24d5cf8
test(writeObject): Добавлены тесты для записи метаданных в форматах E…
johnnyshut 3c4a54d
refactor(writeObject): Обновлены классы и методы для записи метаданны…
johnnyshut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/main/java/com/github/_1c_syntax/bsl/mdclasses/MDCWriteSettings.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * This file is a part of MDClasses. | ||
| * | ||
| * Copyright (c) 2019 - 2026 | ||
| * Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> 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.mdclasses; | ||
|
|
||
| import lombok.Builder; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
|
|
||
| /** | ||
| * Настройки записи объектов метаданных в файлы (EDT и Designer). | ||
| * Используется при вызове {@link com.github._1c_syntax.bsl.mdclasses.MDClasses#writeObject(java.nio.file.Path, Object, MDCWriteSettings)}. | ||
| * | ||
| * @param encoding Кодировка записываемых файлов (по умолчанию UTF-8) | ||
| */ | ||
| @Builder | ||
| public record MDCWriteSettings(@Nullable String encoding) { | ||
|
|
||
| /** | ||
| * Настройки по умолчанию: кодировка UTF-8. | ||
| */ | ||
| public static final MDCWriteSettings DEFAULT = MDCWriteSettings.builder() | ||
| .encoding(StandardCharsets.UTF_8.name()) | ||
| .build(); | ||
|
|
||
| /** | ||
| * Возвращает кодировку для записи файлов; при null в настройках возвращается UTF-8. | ||
| */ | ||
| public String encoding() { | ||
| return encoding != null ? encoding : StandardCharsets.UTF_8.name(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/com/github/_1c_syntax/bsl/writer/MDOWriter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * This file is a part of MDClasses. | ||
| * | ||
| * Copyright (c) 2019 - 2026 | ||
| * Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> 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.writer; | ||
|
|
||
| import com.github._1c_syntax.bsl.mdclasses.MDCWriteSettings; | ||
| import com.github._1c_syntax.bsl.writer.designer.DesignerWriter; | ||
| import com.github._1c_syntax.bsl.writer.edt.EDTWriter; | ||
| import lombok.experimental.UtilityClass; | ||
| import org.apache.commons.io.FilenameUtils; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Path; | ||
|
|
||
| /** | ||
| * Фасад записи объектов метаданных в файлы (EDT .mdo и Designer .xml). | ||
| */ | ||
| @UtilityClass | ||
| public class MDOWriter { | ||
|
|
||
| /** | ||
| * Записывает объект метаданных в файл. | ||
| * Формат определяется по расширению пути: .mdo — EDT, .xml — Designer. | ||
| * | ||
| * @param path Путь к файлу (например, .../Subsystems/Name/Name.mdo или .../Subsystems/Name.xml) | ||
| * @param object Объект метаданных (Subsystem, Catalog, Configuration) | ||
| * @throws IOException при ошибке записи | ||
| * @throws UnsupportedOperationException если формат или тип объекта не поддерживается | ||
| */ | ||
| public void writeObject(Path path, Object object) throws IOException { | ||
| writeObject(path, object, MDCWriteSettings.DEFAULT); | ||
| } | ||
|
|
||
| /** | ||
| * Записывает объект метаданных в файл с настройками. | ||
| * | ||
| * @param path Путь к файлу (расширение .mdo или .xml определяет формат) | ||
| * @param object Объект метаданных (Subsystem, Catalog, Configuration) | ||
| * @param writeSettings Настройки записи (кодировка и др.); может быть null — тогда используются настройки по умолчанию | ||
| * @throws IOException при ошибке записи | ||
| * @throws UnsupportedOperationException если формат или тип объекта не поддерживается | ||
| */ | ||
| public void writeObject(Path path, Object object, MDCWriteSettings writeSettings) throws IOException { | ||
| if (path == null || object == null) { | ||
| throw new IllegalArgumentException("path and object must not be null"); | ||
| } | ||
| if (FilenameUtils.isExtension(path.toString(), "mdo")) { | ||
| var writer = new EDTWriter(writeSettings); | ||
| writer.write(path, object); | ||
| } else if (FilenameUtils.isExtension(path.toString(), "xml")) { | ||
| var writer = new DesignerWriter(writeSettings); | ||
| writer.write(path, object); | ||
| } else { | ||
| throw new UnsupportedOperationException("Write is supported only for EDT (.mdo) or Designer (.xml) format, got: " + path); | ||
| } | ||
| } | ||
| } | ||
135 changes: 135 additions & 0 deletions
135
src/main/java/com/github/_1c_syntax/bsl/writer/ReadWriteDemo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| /* | ||
| * This file is a part of MDClasses. | ||
| * | ||
| * Copyright (c) 2019 - 2026 | ||
| * Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> 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.writer; | ||
|
|
||
| import com.github._1c_syntax.bsl.mdclasses.Configuration; | ||
| import com.github._1c_syntax.bsl.mdclasses.MDClasses; | ||
| import com.github._1c_syntax.bsl.mdclasses.MDCReadSettings; | ||
| import com.github._1c_syntax.bsl.mdo.Catalog; | ||
| import com.github._1c_syntax.bsl.mdo.Subsystem; | ||
| import com.github._1c_syntax.bsl.reader.MDOReader; | ||
| import com.github._1c_syntax.bsl.reader.edt.EDTReader; | ||
| import com.github._1c_syntax.bsl.types.MultiLanguageString; | ||
|
|
||
| import java.nio.file.Files; | ||
| import java.nio.file.Paths; | ||
|
|
||
| /** | ||
| * Демонстрация чтения и записи метаданных: три типа объектов (Subsystem, Catalog, Configuration) | ||
| * в двух форматах — EDT (.mdo) и Конфигуратор (Designer .xml). Артефакты раскладываются по каталогам: | ||
| * build/read-write-demo-output/edt/ и build/read-write-demo-output/designer/. | ||
| * Запуск: {@code ./gradlew runReadWriteDemo} или указать путь в аргументе. | ||
| */ | ||
| public final class ReadWriteDemo { | ||
|
|
||
| private ReadWriteDemo() { | ||
| } | ||
|
|
||
| /** | ||
| * Точка входа: создаёт примеры Subsystem, Catalog, Configuration и записывает их в EDT и Designer. | ||
| * | ||
| * @param args необязательный путь к каталогу вывода; по умолчанию build/read-write-demo-output | ||
| */ | ||
| public static void main(String[] args) throws Exception { | ||
| var baseDir = args.length > 0 ? Paths.get(args[0]) : Paths.get("build", "read-write-demo-output"); | ||
| var edtDir = baseDir.resolve("edt"); | ||
| var designerDir = baseDir.resolve("designer"); | ||
| var edtSrc = edtDir.resolve("src"); | ||
| var designerSrc = designerDir.resolve("src").resolve("cf"); | ||
| Files.createDirectories(edtSrc); | ||
| Files.createDirectories(designerSrc); | ||
|
|
||
| var subsystem = Subsystem.builder() | ||
| .name("DemoSubsystem") | ||
| .uuid("0421b67e-ed26-491d-ab98-ec59002ed4ce") | ||
| .synonym(MultiLanguageString.create("ru", "Демо подсистема")) | ||
| .build(); | ||
| var catalog = Catalog.builder() | ||
| .name("DemoCatalog") | ||
| .uuid("c6c26c3c-de7a-4ed4-944d-ada62cf1ab8f") | ||
| .synonym(MultiLanguageString.create("ru", "Демо справочник")) | ||
| .build(); | ||
| var config = Configuration.builder() | ||
| .name("DemoConfiguration") | ||
| .uuid("46c7c1d0-b04d-4295-9b04-ae3207c18d29") | ||
| .build(); | ||
|
|
||
| var ok = true; | ||
|
|
||
| // --- EDT (.mdo) — каталог edt/ --- | ||
| System.out.println("=== EDT (edt/) ==="); | ||
| var subsystemMdo = edtSrc.resolve("Subsystems").resolve("DemoSubsystem").resolve("DemoSubsystem.mdo"); | ||
| MDClasses.writeObject(subsystemMdo, subsystem); | ||
| System.out.println("Written: " + subsystemMdo.toAbsolutePath()); | ||
| var readSub = new EDTReader(subsystemMdo, MDCReadSettings.SKIP_SUPPORT).read(subsystemMdo); | ||
| ok &= checkReadBack("Subsystem", readSub instanceof Subsystem s ? s.getName() : null, subsystem.getName()); | ||
|
|
||
| var catalogMdo = edtSrc.resolve("Catalogs").resolve("DemoCatalog").resolve("DemoCatalog.mdo"); | ||
| MDClasses.writeObject(catalogMdo, catalog); | ||
| System.out.println("Written: " + catalogMdo.toAbsolutePath()); | ||
| var readCat = new EDTReader(catalogMdo, MDCReadSettings.SKIP_SUPPORT).read(catalogMdo); | ||
| ok &= checkReadBack("Catalog", readCat instanceof Catalog c ? c.getName() : null, catalog.getName()); | ||
|
|
||
| var configMdo = edtSrc.resolve("Configuration").resolve("Configuration.mdo"); | ||
| MDClasses.writeObject(configMdo, config); | ||
| System.out.println("Written: " + configMdo.toAbsolutePath()); | ||
| var readConfig = MDOReader.readConfiguration(configMdo, MDCReadSettings.SKIP_SUPPORT); | ||
| if (readConfig != null && readConfig instanceof Configuration) { | ||
| System.out.println(" Read back Configuration: " + readConfig.getClass().getSimpleName()); | ||
| } else { | ||
| System.out.println(" ERROR: read back Configuration failed"); | ||
| ok = false; | ||
| } | ||
|
|
||
| // --- Конфигуратор (Designer .xml) — каталог designer/ --- | ||
| System.out.println("=== Designer (designer/) ==="); | ||
| var subsystemXml = designerSrc.resolve("Subsystems").resolve("DemoSubsystem.xml"); | ||
| MDClasses.writeObject(subsystemXml, subsystem); | ||
| System.out.println("Written: " + subsystemXml.toAbsolutePath()); | ||
| ok &= Files.exists(subsystemXml) && Files.size(subsystemXml) > 0; | ||
|
|
||
| var catalogXml = designerSrc.resolve("Catalogs").resolve("DemoCatalog.xml"); | ||
| MDClasses.writeObject(catalogXml, catalog); | ||
| System.out.println("Written: " + catalogXml.toAbsolutePath()); | ||
| ok &= Files.exists(catalogXml) && Files.size(catalogXml) > 0; | ||
|
|
||
| var configXml = designerSrc.resolve("Configuration.xml"); | ||
| MDClasses.writeObject(configXml, config); | ||
| System.out.println("Written: " + configXml.toAbsolutePath()); | ||
| ok &= Files.exists(configXml) && Files.size(configXml) > 0; | ||
|
|
||
| if (ok) { | ||
| System.out.println("OK: all objects written to edt/ and designer/ (Subsystem, Catalog, Configuration)."); | ||
| } else { | ||
| System.exit(1); | ||
| } | ||
| } | ||
|
|
||
| private static boolean checkReadBack(String type, String readName, String expectedName) { | ||
| if (readName != null && readName.equals(expectedName)) { | ||
| System.out.println(" Read back " + type + ": " + readName); | ||
| return true; | ||
| } | ||
| System.out.println(" ERROR: read back " + type + " failed (expected " + expectedName + ", got " + readName + ")"); | ||
| return false; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normalize unsupported-type handling before dispatch.
The facade documents one failure mode, but the
.mdobranch can currently leakIllegalArgumentExceptionfromsrc/main/java/com/github/_1c_syntax/bsl/writer/edt/EDTWriter.java:77-80, while the.xmlbranch usesUnsupportedOperationExceptionviasrc/main/java/com/github/_1c_syntax/bsl/writer/designer/DesignerWriter.java:67-70. The same unsupported object should not fail differently based only on the extension.🤖 Prompt for AI Agents