Skip to content

Commit 98e8a6e

Browse files
committed
1. В Configuration добавлена коллекция со всеми дочерними объектами
2. Модифицирован алгритм определения поддержки
1 parent f3638fb commit 98e8a6e

File tree

7 files changed

+185
-286
lines changed

7 files changed

+185
-286
lines changed

src/main/java/com/github/_1c_syntax/mdclasses/mdo/MDObjectBase.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
import com.fasterxml.jackson.annotation.JsonProperty;
55
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
66
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
7+
import com.github._1c_syntax.mdclasses.metadata.additional.ModuleType;
78
import lombok.Builder;
8-
import lombok.Value;
9+
import lombok.Data;
910
import lombok.experimental.NonFinal;
1011
import lombok.experimental.SuperBuilder;
1112

13+
import java.net.URI;
1214
import java.util.Map;
1315

1416
import static com.github._1c_syntax.mdclasses.metadata.utils.MapExtension.getOrEmptyString;
1517

16-
@Value
18+
@Data
1719
@NonFinal
1820
@JsonDeserialize(builder = MDObjectBase.MDObjectBaseBuilderImpl.class)
1921
@SuperBuilder
@@ -23,6 +25,8 @@ public class MDObjectBase {
2325
protected String name;
2426
@Builder.Default
2527
protected String comment = "";
28+
protected URI mdoURI;
29+
protected Map<URI, ModuleType> modulesByType;
2630

2731
public abstract static class MDObjectBaseBuilder
2832
<C extends MDObjectBase, B extends MDObjectBase.MDObjectBaseBuilder<C, B>> {
@@ -38,6 +42,18 @@ protected MDObjectBaseBuilder<C, B> properties(Map<String, Object> properties) {
3842
}
3943
}
4044

45+
public void setMdoURI(URI uri) {
46+
if (this.mdoURI == null) {
47+
this.mdoURI = uri;
48+
}
49+
}
50+
51+
public void setModulesByType(Map<URI, ModuleType> modulesByType) {
52+
if (this.modulesByType == null) {
53+
this.modulesByType = modulesByType;
54+
}
55+
}
56+
4157
// Mark builder implementation as Jackson JSON builder with methods w/o `with-` in their names.
4258
@JsonPOJOBuilder(withPrefix = "")
4359
@JsonIgnoreProperties(ignoreUnknown = true)

src/main/java/com/github/_1c_syntax/mdclasses/metadata/Configuration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private Configuration() {
7171

7272
private Configuration(MDOConfiguration configurationXml, ConfigurationSource configurationSource, Path rootPath) {
7373
this.configurationSource = configurationSource;
74-
this.children = new HashMap<>();
74+
this.children = MDOUtils.getAllChildren(configurationSource, rootPath, true);
7575
this.rootPath = rootPath;
7676

7777
this.name = configurationXml.getName();
@@ -90,7 +90,7 @@ private Configuration(MDOConfiguration configurationXml, ConfigurationSource con
9090
this.synchronousPlatformExtensionAndAddInCallUseMode = configurationXml.getSynchronousPlatformExtensionAndAddInCallUseMode();
9191

9292
this.modulesByType = MDOUtils.getModuleTypesByPath(configurationSource, rootPath);
93-
this.modulesBySupport = Common.getModuleSupports(this, this.modulesByType);
93+
this.modulesBySupport = Common.getModuleSupports(this);
9494
}
9595

9696
public static Configuration create() {

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

Lines changed: 36 additions & 231 deletions
Original file line numberDiff line numberDiff line change
@@ -1,277 +1,82 @@
11
package com.github._1c_syntax.mdclasses.metadata.utils;
22

3+
import com.github._1c_syntax.mdclasses.mdo.MDObjectBase;
34
import com.github._1c_syntax.mdclasses.metadata.Configuration;
45
import com.github._1c_syntax.mdclasses.metadata.SupportConfiguration;
56
import com.github._1c_syntax.mdclasses.metadata.additional.ConfigurationSource;
6-
import com.github._1c_syntax.mdclasses.metadata.additional.ModuleType;
77
import com.github._1c_syntax.mdclasses.metadata.additional.SupportVariant;
88
import lombok.extern.slf4j.Slf4j;
9-
import org.apache.commons.io.FileUtils;
10-
import org.apache.commons.io.FilenameUtils;
119

1210
import java.io.File;
13-
import java.io.IOException;
1411
import java.net.URI;
15-
import java.nio.charset.StandardCharsets;
16-
import java.nio.file.Files;
1712
import java.nio.file.Path;
18-
import java.util.Collection;
13+
import java.nio.file.Paths;
14+
import java.util.Collections;
1915
import java.util.HashMap;
16+
import java.util.HashSet;
2017
import java.util.Map;
21-
import java.util.regex.Matcher;
22-
import java.util.regex.Pattern;
18+
import java.util.Set;
2319

2420
@Slf4j
2521
public class Common {
2622

27-
public static final String EXTENSION_BSL = "bsl";
28-
public static final String FILE_SEPARATOR = Pattern.quote(System.getProperty("file.separator"));
29-
30-
public static final String REGEX_GUID = "uuid=\"(.*)\"";
31-
public static final Pattern PATTERN_REGEX_GUID = Pattern.compile(REGEX_GUID, Pattern.MULTILINE);
3223
public static final String EXTENSION_XML = "xml";
3324
public static final String EXTENSION_MDO = "mdo";
3425

3526
private Common() {
3627
// only statics
3728
}
3829

39-
public static ModuleType getModuleTypeByFileName(String[] partsFileName) {
40-
41-
String fileName = partsFileName[0];
42-
43-
ModuleType moduleType;
44-
if (fileName.equalsIgnoreCase("CommandModule")) {
45-
moduleType = ModuleType.CommandModule;
46-
} else if (fileName.equalsIgnoreCase("ObjectModule")) {
47-
moduleType = ModuleType.ObjectModule;
48-
} else if (fileName.equalsIgnoreCase("ManagerModule")) {
49-
moduleType = ModuleType.ManagerModule;
50-
} else if (fileName.equalsIgnoreCase("ManagedApplicationModule")) {
51-
moduleType = ModuleType.ManagedApplicationModule;
52-
} else if (fileName.equalsIgnoreCase("OrdinaryApplicationModule")) {
53-
moduleType = ModuleType.OrdinaryApplicationModule;
54-
} else if (fileName.equalsIgnoreCase("SessionModule")) {
55-
moduleType = ModuleType.SessionModule;
56-
} else if (fileName.equalsIgnoreCase("RecordSetModule")) {
57-
moduleType = ModuleType.RecordSetModule;
58-
} else if (fileName.equalsIgnoreCase("ExternalConnectionModule")) {
59-
moduleType = ModuleType.ExternalConnectionModule;
60-
} else if (fileName.equalsIgnoreCase("ApplicationModule")) {
61-
moduleType = ModuleType.ApplicationModule;
62-
} else if (fileName.equalsIgnoreCase("ValueManagerModule")) {
63-
moduleType = ModuleType.ValueManagerModule;
64-
} else if (fileName.equalsIgnoreCase("Module")) {
65-
if (partsFileName[1].equalsIgnoreCase("Form")
66-
|| partsFileName[2].equalsIgnoreCase("Forms")
67-
|| partsFileName[2].equalsIgnoreCase("CommonForms")) {
68-
moduleType = ModuleType.FormModule;
69-
} else {
70-
moduleType = ModuleType.CommonModule;
71-
}
72-
} else {
73-
moduleType = null;
74-
LOGGER.error("Module type not find: " + fileName);
75-
}
76-
return moduleType;
77-
}
78-
79-
public static Map<URI, ModuleType> getModuleTypesByPath(Path rootPath) {
80-
81-
Map<URI, ModuleType> modulesByType = new HashMap<>();
82-
String rootPathString = rootPath.toString() + System.getProperty("file.separator");
83-
Collection<File> files = FileUtils.listFiles(rootPath.toFile(), new String[]{EXTENSION_BSL}, true);
84-
85-
files.stream().forEach(file -> {
86-
String[] elementsPath = getPartsByPath(file.toPath().toAbsolutePath());
87-
88-
// TODO: отрефакторить
89-
String thirdPath = "";
90-
if (elementsPath.length > 2) {
91-
thirdPath = elementsPath[elementsPath.length - 3];
92-
}
93-
94-
String[] partsFileName = new String[]{
95-
FilenameUtils.getBaseName(elementsPath[elementsPath.length - 1]),
96-
elementsPath[elementsPath.length - 2],
97-
thirdPath
98-
};
99-
100-
ModuleType moduleType = getModuleTypeByFileName(partsFileName);
101-
modulesByType.put(getAbsoluteUri(file), moduleType);
102-
});
103-
104-
return modulesByType;
105-
106-
}
107-
108-
public static Map<URI, Map<SupportConfiguration, SupportVariant>> getModuleSupports(Configuration configuration, Map<URI, ModuleType> modulesByType) {
109-
110-
final Path rootPath;
111-
boolean isEDT = configuration.getConfigurationSource() == ConfigurationSource.EDT;
30+
public static Map<URI, Map<SupportConfiguration, SupportVariant>> getModuleSupports(Configuration configuration) {
11231
Map<URI, Map<SupportConfiguration, SupportVariant>> modulesBySupport = new HashMap<>();
113-
11432
File fileParentConfiguration;
115-
if (isEDT) {
116-
rootPath = Path.of(configuration.getRootPath().toString(), "src");
117-
fileParentConfiguration = new File(rootPath.toString(), "Configuration/ParentConfigurations.bin");
33+
if (configuration.getConfigurationSource() == ConfigurationSource.EDT) {
34+
fileParentConfiguration = Paths.get(configuration.getRootPath().toString(),
35+
"src", "Configuration/ParentConfigurations.bin")
36+
.toFile();
11837
} else {
119-
rootPath = configuration.getRootPath();
120-
fileParentConfiguration = new File(rootPath.toString(), "Ext/ParentConfigurations.bin");
38+
fileParentConfiguration = Paths.get(configuration.getRootPath().toString(),
39+
"Ext/ParentConfigurations.bin")
40+
.toFile();
12141
}
12242

12343
if (fileParentConfiguration.exists()) {
12444
ParseSupportData supportData = new ParseSupportData(fileParentConfiguration.toPath());
12545
final Map<String, Map<SupportConfiguration, SupportVariant>> supportMap = supportData.getSupportMap();
12646

127-
String rootPathString = rootPath.toString() + System.getProperty("file.separator");
128-
Collection<File> files = FileUtils.listFiles(rootPath.toFile(), new String[]{EXTENSION_BSL}, true);
129-
130-
files.stream().forEach(file -> {
131-
132-
// FIXME: неправильное поведение, считается от каталога внутри scr
133-
URI uri = getAbsoluteUri(file);
134-
String[] elementsPath = file.toPath().toString().replace(rootPathString, "").split(FILE_SEPARATOR);
135-
136-
Map<SupportConfiguration, SupportVariant> moduleSupport = null;
137-
ModuleType moduleType = modulesByType.get(uri);
138-
String objectGuid = "";
139-
140-
// TODO: доработать поиски гуидов форм
141-
if (isEDT) {
142-
objectGuid = getObjectGuidEDT(rootPath, elementsPath, moduleType);
143-
} else {
144-
objectGuid = getObjectGuidOriginal(rootPath, elementsPath, moduleType);
145-
}
146-
147-
if (objectGuid.isEmpty()) {
148-
LOGGER.info("Не удалось найти идентфикатор по объекту " + uri.toString());
149-
} else {
150-
moduleSupport = supportMap.get(objectGuid);
151-
}
152-
153-
if (moduleSupport == null) {
154-
moduleSupport = new HashMap<>();
155-
}
156-
157-
modulesBySupport.put(uri, moduleSupport);
158-
159-
});
47+
configuration.getChildren()
48+
.forEach((mdoType, stringMDObjectBaseMap) ->
49+
stringMDObjectBaseMap.forEach((name, mdObject) -> {
50+
var mdoModuleSupport = getMDObjectSupport(supportMap, mdObject);
51+
if (!mdoModuleSupport.isEmpty()) {
52+
modulesBySupport.putAll(mdoModuleSupport);
53+
}
54+
})
55+
);
16056
}
16157
return modulesBySupport;
16258
}
16359

164-
private static String getObjectGuidEDT(Path rootPath, String[] elementsPath, ModuleType moduleType) {
165-
Path path = null;
166-
if (isModuleConfiguration(moduleType)) {
167-
168-
path = new File(rootPath.toString(), "Configuration/Configuration.mdo").toPath();
169-
170-
} else {
171-
String second = "";
172-
if (elementsPath.length >= 3) {
173-
second = elementsPath[elementsPath.length - 3];
174-
}
175-
if (second.equalsIgnoreCase("Commands") || (second.equalsIgnoreCase("Forms"))) {
176-
path = getSimplePath(rootPath, elementsPath, 4, EXTENSION_MDO);
177-
} else {
178-
path = getSimplePath(rootPath, elementsPath, 2, EXTENSION_MDO);
179-
}
180-
}
181-
return getGuidFromFile(path);
182-
}
183-
184-
private static String getObjectGuidOriginal(Path rootPath, String[] elementsPath, ModuleType moduleType) {
185-
String guid = "";
186-
Path path;
187-
if (isModuleConfiguration(moduleType)) {
188-
path = new File(rootPath.toString(), "Configuration.xml").toPath();
189-
} else {
190-
String currentElement = elementsPath[elementsPath.length - 2];
191-
if (currentElement.equalsIgnoreCase("Ext")) {
192-
String second = "";
193-
if (elementsPath.length >= 4) {
194-
second = elementsPath[elementsPath.length - 4];
195-
}
196-
if (second.equalsIgnoreCase("Commands")) {
197-
path = getSimplePath(rootPath, elementsPath, 5, EXTENSION_XML);
198-
} else {
199-
path = getSimplePath(rootPath, elementsPath, 3, EXTENSION_XML);
200-
}
201-
} else if (currentElement.equalsIgnoreCase("Form")) {
202-
path = getSimplePath(rootPath, elementsPath, 4, EXTENSION_XML);
203-
} else {
204-
return guid;
205-
}
60+
private static Map<URI, Map<SupportConfiguration, SupportVariant>> getMDObjectSupport(Map<String, Map<SupportConfiguration, SupportVariant>> supportMap, MDObjectBase mdObject) {
61+
Map<URI, Map<SupportConfiguration, SupportVariant>> modulesBySupport = new HashMap<>();
62+
Set<URI> uris = new HashSet<>();
63+
if (mdObject.getMdoURI() != null) {
64+
uris.add(mdObject.getMdoURI());
20665
}
207-
return getGuidFromFile(path);
208-
}
209-
210-
public static String getGuidFromFile(Path path) {
211-
File xml = path.toFile();
212-
String guid = "";
213-
if (xml.exists()) {
214-
guid = findGuidIntoFileXML(xml);
66+
if (mdObject.getModulesByType() != null) {
67+
mdObject.getModulesByType().forEach((uri, moduleType) -> uris.add(uri));
21568
}
216-
return guid;
217-
}
21869

219-
public static Path getSimplePath(Path rootPath, String[] elementsPath, int startPosition, String extension) {
220-
String path = "";
221-
String lastElement = "";
222-
int position = 0;
223-
for (String el : elementsPath) {
224-
if (position == elementsPath.length - startPosition + 1) {
225-
break;
226-
}
227-
path = path + (el + System.getProperty("file.separator"));
228-
lastElement = el;
229-
position++;
230-
}
231-
if (extension.equals(EXTENSION_XML)) {
232-
path = path.substring(0, path.length() - 1) + "." + extension;
70+
Map<SupportConfiguration, SupportVariant> moduleSupport = Collections.emptyMap();
71+
if (mdObject.getUuid() == null) {
72+
LOGGER.info("Не удалось найти идентфикатор по объекту " + mdObject);
23373
} else {
234-
path = path + lastElement + "." + extension;
235-
}
236-
return Path.of(rootPath.toString(), path).toAbsolutePath();
237-
}
238-
239-
public static String findGuidIntoFileXML(File file) {
240-
String result = "";
241-
String content = getContentFile(file);
242-
Matcher matcher = PATTERN_REGEX_GUID.matcher(content);
243-
if (matcher.find()) {
244-
result = matcher.group(1);
245-
}
246-
return result;
247-
}
248-
249-
public static String getContentFile(File file) {
250-
String content = "";
251-
try {
252-
content = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
253-
} catch (IOException e) {
254-
LOGGER.error("Don't read file", e.getMessage());
74+
moduleSupport = supportMap.getOrDefault(mdObject.getUuid(), Collections.emptyMap());
25575
}
256-
return content;
257-
}
258-
259-
public static boolean isModuleConfiguration(ModuleType moduleType) {
260-
return moduleType == ModuleType.ApplicationModule
261-
|| moduleType == ModuleType.ExternalConnectionModule
262-
|| moduleType == ModuleType.ManagedApplicationModule
263-
|| moduleType == ModuleType.OrdinaryApplicationModule
264-
|| moduleType == ModuleType.SessionModule;
265-
}
266-
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();
76+
for (URI uri : uris) {
77+
modulesBySupport.put(uri, moduleSupport);
27378
}
274-
return array;
79+
return modulesBySupport;
27580
}
27681

27782
public static Path getAbsolutePath(File file) {

0 commit comments

Comments
 (0)