Skip to content

Commit d5cf05a

Browse files
authored
Merge pull request #40 from 1c-syntax/feature/issue39
Фикс поиска типа модулей форм в EDT
2 parents b44dda3 + 3010455 commit d5cf05a

3 files changed

Lines changed: 50 additions & 14 deletions

File tree

  • src
    • main/java/com/github/_1c_syntax/mdclasses/metadata/utils
    • test

src/main/java/com/github/_1c_syntax/mdclasses/metadata/utils/Common.java

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ private Common() {
3636
// only statics
3737
}
3838

39-
public static ModuleType changeModuleTypeByFileName(String fileName, String secondFileName) {
39+
public static ModuleType getModuleTypeByFileName(String[] partsFileName) {
40+
41+
String fileName = partsFileName[0];
4042

4143
ModuleType moduleType;
4244
if (fileName.equalsIgnoreCase("CommandModule")) {
@@ -60,7 +62,8 @@ public static ModuleType changeModuleTypeByFileName(String fileName, String seco
6062
} else if (fileName.equalsIgnoreCase("ValueManagerModule")) {
6163
moduleType = ModuleType.ValueManagerModule;
6264
} else if (fileName.equalsIgnoreCase("Module")) {
63-
if (secondFileName.equalsIgnoreCase("Form")) {
65+
if (partsFileName[1].equalsIgnoreCase("Form")
66+
|| partsFileName[2].equalsIgnoreCase("Forms")) {
6467
moduleType = ModuleType.FormModule;
6568
} else {
6669
moduleType = ModuleType.CommonModule;
@@ -77,12 +80,23 @@ public static Map<URI, ModuleType> getModuleTypesByPath(Path rootPath) {
7780
Map<URI, ModuleType> modulesByType = new HashMap<>();
7881
String rootPathString = rootPath.toString() + System.getProperty("file.separator");
7982
Collection<File> files = FileUtils.listFiles(rootPath.toFile(), new String[]{EXTENSION_BSL}, true);
80-
files.parallelStream().forEach(file -> {
81-
String[] elementsPath =
82-
file.toPath().toString().replace(rootPathString, "").split(FILE_SEPARATOR);
83-
String secondFileName = elementsPath[elementsPath.length - 2];
84-
String fileName = FilenameUtils.getBaseName(elementsPath[elementsPath.length - 1]);
85-
ModuleType moduleType = Common.changeModuleTypeByFileName(fileName, secondFileName);
83+
84+
files.stream().forEach(file -> {
85+
String[] elementsPath = getPartsByPath(file.toPath().toAbsolutePath());
86+
87+
// TODO: отрефакторить
88+
String thirdPath = "";
89+
if (elementsPath.length > 2) {
90+
thirdPath = elementsPath[elementsPath.length - 3];
91+
}
92+
93+
String[] partsFileName = new String[]{
94+
FilenameUtils.getBaseName(elementsPath[elementsPath.length - 1]),
95+
elementsPath[elementsPath.length - 2],
96+
thirdPath
97+
};
98+
99+
ModuleType moduleType = getModuleTypeByFileName(partsFileName);
86100
modulesByType.put(file.toURI(), moduleType);
87101
});
88102

@@ -112,14 +126,17 @@ public static Map<URI, Map<SupportConfiguration, SupportVariant>> getModuleSuppo
112126
String rootPathString = rootPath.toString() + System.getProperty("file.separator");
113127
Collection<File> files = FileUtils.listFiles(rootPath.toFile(), new String[]{EXTENSION_BSL}, true);
114128

115-
files.parallelStream().forEach(file -> {
116-
URI uri = file.toPath().toAbsolutePath().toUri();
117-
String[] elementsPath =
118-
file.toPath().toString().replace(rootPathString, "").split(FILE_SEPARATOR);
129+
files.stream().forEach(file -> {
130+
131+
// FIXME: неправильное поведение, считается от каталога внутри scr
132+
var path = file.toPath();
133+
URI uri = path.toAbsolutePath().toUri();
134+
String[] elementsPath = file.toPath().toString().replace(rootPathString, "").split(FILE_SEPARATOR);
119135

120136
Map<SupportConfiguration, SupportVariant> moduleSupport = null;
121137
ModuleType moduleType = modulesByType.get(uri);
122138
String objectGuid = "";
139+
123140
// TODO: доработать поиски гуидов форм
124141
if (isEDT) {
125142
objectGuid = getObjectGuidEDT(rootPath, elementsPath, moduleType);
@@ -151,7 +168,10 @@ private static String getObjectGuidEDT(Path rootPath, String[] elementsPath, Mod
151168
path = new File(rootPath.toString(), "Configuration/Configuration.mdo").toPath();
152169

153170
} else {
154-
String second = elementsPath[elementsPath.length - 3];
171+
String second = "";
172+
if (elementsPath.length >= 3) {
173+
second = elementsPath[elementsPath.length - 3];
174+
}
155175
if (second.equalsIgnoreCase("Commands") || (second.equalsIgnoreCase("Forms"))) {
156176
path = getSimplePath(rootPath, elementsPath, 4, EXTENSION_MDO);
157177
} else {
@@ -169,7 +189,10 @@ private static String getObjectGuidOriginal(Path rootPath, String[] elementsPath
169189
} else {
170190
String currentElement = elementsPath[elementsPath.length - 2];
171191
if (currentElement.equalsIgnoreCase("Ext")) {
172-
String second = elementsPath[elementsPath.length - 4];
192+
String second = "";
193+
if (elementsPath.length >= 4) {
194+
second = elementsPath[elementsPath.length - 4];
195+
}
173196
if (second.equalsIgnoreCase("Commands")) {
174197
path = getSimplePath(rootPath, elementsPath, 5, EXTENSION_XML);
175198
} else {
@@ -241,4 +264,14 @@ public static boolean isModuleConfiguration(ModuleType moduleType) {
241264
|| moduleType == ModuleType.SessionModule;
242265
}
243266

267+
private static String[] getPartsByPath(Path path) {
268+
var count = path.getNameCount();
269+
String[] array = new String[count];
270+
for (int position = 0; position < path.getNameCount(); position++) {
271+
//array[count - 1 - position] = path.getName(position).toString();
272+
array[position] = path.getName(position).toString();
273+
}
274+
return array;
275+
}
276+
244277
}

src/test/java/com/github/_1c_syntax/mdclasses/ConfigurationEDTTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ void testBuilder() {
3333
file = new File("src/test/resources/metadata/edt/src/CommonModules/ПростойОбщийМодуль/Module.bsl");
3434
assertThat(configuration.getModuleType(file.toURI())).isEqualTo(ModuleType.CommonModule);
3535

36+
file = new File("src/test/resources/metadata/edt/src/Catalogs/Справочник1/Forms/ФормаЭлемента/Module.bsl");
37+
assertThat(configuration.getModuleType(file.toURI())).isEqualTo(ModuleType.FormModule);
38+
3639
CommonModule commonModule = (CommonModule) configuration.getChild(MDOType.COMMON_MODULE, "ПростойОбщийМодуль");
3740
assertThat(commonModule).isNotNull();
3841
assertThat(commonModule.getName()).isEqualTo("ПростойОбщийМодуль");

src/test/resources/metadata/edt/src/Catalogs/Справочник1/Forms/ФормаЭлемента/Module.bsl

Whitespace-only changes.

0 commit comments

Comments
 (0)