Skip to content

Commit 6f73d22

Browse files
authored
Merge pull request #91 from 1c-syntax/develop
Релиз 0.5
2 parents 4dbf7d1 + 93372b7 commit 6f73d22

File tree

212 files changed

+11653
-204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+11653
-204
lines changed

.github/workflows/qa.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: QA
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- master
8+
pull_request:
9+
10+
jobs:
11+
QA:
12+
runs-on: ubuntu-latest
13+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.event.repository.full_name
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
fetch-depth: ''
18+
- run: |
19+
git fetch --prune --unshallow
20+
- name: Set up JDK 11
21+
uses: actions/setup-java@v1
22+
with:
23+
java-version: 11
24+
- name: SonarCloud Scan
25+
run: ./gradlew check sonarqube
26+
env:
27+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build.gradle.kts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ repositories {
2222
val junitVersion = "5.5.2"
2323
dependencies {
2424

25+
// https://mvnrepository.com/artifact/io.vavr/vavr
26+
implementation("io.vavr", "vavr", "0.10.2")
27+
implementation("org.apache.commons", "commons-collections4", "4.4")
28+
2529
implementation("com.fasterxml.jackson.dataformat", "jackson-dataformat-xml", "2.10.3")
2630
implementation("com.fasterxml.jackson.module", "jackson-module-parameter-names", "2.10.3")
27-
2831
// логирование
2932
implementation("org.slf4j", "slf4j-api", "1.8.0-beta4")
3033
implementation("org.slf4j", "slf4j-simple", "1.8.0-beta4")
@@ -68,6 +71,17 @@ tasks.test {
6871
}
6972
}
7073

74+
tasks.check {
75+
dependsOn(tasks.jacocoTestReport)
76+
}
77+
78+
tasks.jacocoTestReport {
79+
reports {
80+
xml.isEnabled = true
81+
xml.destination = File("$buildDir/reports/jacoco/test/jacoco.xml")
82+
}
83+
}
84+
7185
tasks.withType<JavaCompile> {
7286
options.encoding = "UTF-8"
7387
options.compilerArgs.add("-Xlint:unchecked")
@@ -82,6 +96,7 @@ sonarqube {
8296
property("sonar.projectKey", "1c-syntax_mdclasses")
8397
property("sonar.projectName", "MDClasses")
8498
property("sonar.exclusions", "**/gen/**/*.*")
99+
property("sonar.coverage.jacoco.xmlReportPaths", "$buildDir/reports/jacoco/test/jacoco.xml")
85100
}
86101
}
87102

@@ -108,3 +123,10 @@ license {
108123
"**/*.os",
109124
"**/*.bsl"))
110125
}
126+
127+
tasks.register("precommit") {
128+
description = "Run all precommit tasks"
129+
group = "Developer tools"
130+
dependsOn(":test")
131+
dependsOn(":licenseFormat")
132+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* This file is a part of MDClasses.
3+
*
4+
* Copyright © 2019 - 2020
5+
* Tymko Oleg <[email protected]>, Maximov Valery <[email protected]> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* MDClasses is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* MDClasses is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with MDClasses.
21+
*/
22+
package com.github._1c_syntax.mdclasses.deserialize;
23+
24+
import com.fasterxml.jackson.core.JsonParser;
25+
import com.fasterxml.jackson.core.JsonToken;
26+
import com.fasterxml.jackson.core.TreeNode;
27+
import com.fasterxml.jackson.databind.DeserializationContext;
28+
import com.fasterxml.jackson.databind.JsonDeserializer;
29+
import com.fasterxml.jackson.databind.node.NullNode;
30+
import com.github._1c_syntax.mdclasses.utils.ObjectMapperFactory;
31+
32+
import java.io.IOException;
33+
import java.util.ArrayList;
34+
import java.util.Collection;
35+
import java.util.HashMap;
36+
import java.util.List;
37+
import java.util.Map;
38+
39+
/**
40+
* Класс реализация кастомной десериализации XML файлов конфигурации.
41+
* В дочерних классах необходимо реализовать только метод чтение свойства readToken
42+
*/
43+
abstract class AbstractDeserializer extends JsonDeserializer<Object> {
44+
45+
protected final String rootKey;
46+
47+
protected AbstractDeserializer(String key) {
48+
rootKey = key;
49+
}
50+
51+
@Override
52+
public Map<String, Object> deserialize(
53+
JsonParser parser,
54+
DeserializationContext context
55+
) throws IOException {
56+
Map<String, Object> childObjects = new HashMap<>();
57+
58+
if (parser.getCurrentToken() != JsonToken.START_OBJECT) {
59+
return childObjects;
60+
}
61+
62+
int level = 1;
63+
while (parser.nextToken() != null) {
64+
var token = parser.getCurrentToken();
65+
var name = parser.getCurrentName();
66+
67+
// скрректируем уровень, для того, чтобы вовремя выйти
68+
level = correctLevel(name, token, level);
69+
if (level == 0) {
70+
break;
71+
}
72+
73+
// обрабатываем только свойства
74+
if (token == JsonToken.FIELD_NAME) {
75+
readToken(parser, childObjects, name, context);
76+
}
77+
}
78+
return childObjects;
79+
}
80+
81+
protected abstract void readToken(JsonParser parser,
82+
Map<String, Object> childObjects,
83+
String name,
84+
DeserializationContext context) throws IOException;
85+
86+
private int correctLevel(String name, JsonToken token, int level) {
87+
var isRoot = rootKey.equals(name);
88+
if (isRoot && token == JsonToken.END_OBJECT) {
89+
level--;
90+
} else if (isRoot && token == JsonToken.START_OBJECT) {
91+
level++;
92+
}
93+
94+
return level;
95+
}
96+
97+
protected boolean isEndToken(String name, JsonParser parser) throws IOException {
98+
return parser.getCurrentToken() == JsonToken.END_OBJECT && name.equals(parser.getCurrentName());
99+
}
100+
101+
protected String getValueFromNode(TreeNode node) {
102+
if (node instanceof NullNode) {
103+
return null;
104+
}
105+
return getValueFromNode(node, String.class);
106+
}
107+
108+
protected <T> T getValueFromNode(TreeNode node, Class<T> classValue) {
109+
return ObjectMapperFactory.getXmlMapper().convertValue(node, classValue);
110+
}
111+
112+
protected <T> T readValueByType(JsonParser parser, Class<T> classValue) throws IOException {
113+
return ObjectMapperFactory.getXmlMapper().readValue(parser, classValue);
114+
}
115+
116+
protected void addProperty(Map<String, Object> childObjects, String name, Object newValue) {
117+
var value = childObjects.get(name);
118+
if (value == null) {
119+
childObjects.put(name, newValue);
120+
} else if (value instanceof List) {
121+
List<Object> values = new ArrayList<>((Collection<?>) value);
122+
values.add(newValue);
123+
childObjects.put(name, values);
124+
} else {
125+
List<Object> values = new ArrayList<>();
126+
values.add(value);
127+
values.add(newValue);
128+
childObjects.put(name, values);
129+
}
130+
}
131+
132+
protected void readAndAddProperty(Map<String, Object> childObjects, String name, JsonParser parser) throws IOException {
133+
var newValue = getValueFromNode(parser.readValueAsTree());
134+
addProperty(childObjects, name, newValue);
135+
}
136+
137+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* This file is a part of MDClasses.
3+
*
4+
* Copyright © 2019 - 2020
5+
* Tymko Oleg <[email protected]>, Maximov Valery <[email protected]> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* MDClasses is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* MDClasses is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with MDClasses.
21+
*/
22+
package com.github._1c_syntax.mdclasses.deserialize;
23+
24+
import com.fasterxml.jackson.core.JsonParser;
25+
import com.fasterxml.jackson.databind.DeserializationContext;
26+
import com.github._1c_syntax.mdclasses.mdo.Attribute;
27+
import com.github._1c_syntax.mdclasses.mdo.Command;
28+
import com.github._1c_syntax.mdclasses.mdo.Dimension;
29+
import com.github._1c_syntax.mdclasses.mdo.Resource;
30+
import com.github._1c_syntax.mdclasses.mdo.TabularSection;
31+
import com.github._1c_syntax.mdclasses.metadata.additional.MDOType;
32+
33+
import java.io.IOException;
34+
import java.util.Map;
35+
36+
public class ChildObjectsDeserializer extends AbstractDeserializer {
37+
38+
private static final String COMMAND_KEY = "Command";
39+
private static final String SUBSYSTEM_KEY = "Subsystem";
40+
private static final String DIMENSION_KEY = "Dimension";
41+
private static final String RESOURCE_KEY = "Resource";
42+
private static final String ATTRIBUTE_KEY = "Attribute";
43+
private static final String TABULAR_SECTION_KEY = "TabularSection";
44+
45+
public ChildObjectsDeserializer() {
46+
super("ChildObjects");
47+
}
48+
49+
@Override
50+
protected void readToken(JsonParser parser,
51+
Map<String, Object> childObjects,
52+
String name,
53+
DeserializationContext context) throws IOException {
54+
if (name.equals(COMMAND_KEY)) {
55+
parser.nextToken();
56+
var newValue = getValueFromNode(parser.readValueAsTree(), Command.class);
57+
addProperty(childObjects, name, newValue);
58+
} else if (name.equals(SUBSYSTEM_KEY)) {
59+
parser.nextToken();
60+
var newValue = MDOType.SUBSYSTEM.getName() + "." + getValueFromNode(parser.readValueAsTree());
61+
addProperty(childObjects, name, newValue);
62+
} else if (name.equals(DIMENSION_KEY)) {
63+
parser.nextToken();
64+
var newValue = getValueFromNode(parser.readValueAsTree(), Dimension.class);
65+
addProperty(childObjects, ATTRIBUTE_KEY, newValue);
66+
} else if (name.equals(RESOURCE_KEY)) {
67+
parser.nextToken();
68+
var newValue = getValueFromNode(parser.readValueAsTree(), Resource.class);
69+
addProperty(childObjects, ATTRIBUTE_KEY, newValue);
70+
} else if (name.equals(ATTRIBUTE_KEY)) {
71+
parser.nextToken();
72+
var newValue = getValueFromNode(parser.readValueAsTree(), Attribute.class);
73+
addProperty(childObjects, ATTRIBUTE_KEY, newValue);
74+
} else if (name.equals(TABULAR_SECTION_KEY)) {
75+
parser.nextToken();
76+
var newValue = readValueByType(parser, TabularSection.class);
77+
addProperty(childObjects, ATTRIBUTE_KEY, newValue);
78+
}
79+
}
80+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* This file is a part of MDClasses.
3+
*
4+
* Copyright © 2019 - 2020
5+
* Tymko Oleg <[email protected]>, Maximov Valery <[email protected]> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* MDClasses is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* MDClasses is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with MDClasses.
21+
*/
22+
package com.github._1c_syntax.mdclasses.deserialize;
23+
24+
import com.fasterxml.jackson.core.JsonParser;
25+
import com.fasterxml.jackson.core.JsonToken;
26+
import com.fasterxml.jackson.databind.DeserializationContext;
27+
28+
import java.io.IOException;
29+
import java.util.Map;
30+
31+
public class PropertiesDeserializer extends AbstractDeserializer {
32+
33+
private static final String CONTENT_KEY = "Content";
34+
35+
protected PropertiesDeserializer() {
36+
super("Properties");
37+
}
38+
39+
@Override
40+
protected void readToken(JsonParser parser,
41+
Map<String, Object> childObjects,
42+
String name,
43+
DeserializationContext context) throws IOException {
44+
45+
parser.nextToken(); // вошли во внутрь
46+
47+
if (parser.getCurrentToken() == JsonToken.START_OBJECT) {
48+
if (name.equals(CONTENT_KEY)) {
49+
readContent(parser, childObjects, name);
50+
} else {
51+
// объекты пропускаем
52+
while (parser.nextToken() != null) {
53+
if (isEndToken(name, parser)) {
54+
break;
55+
}
56+
}
57+
}
58+
} else {
59+
readAndAddProperty(childObjects, name, parser);
60+
}
61+
}
62+
63+
private void readContent(JsonParser parser, Map<String, Object> childObjects, String name) throws IOException {
64+
while (parser.nextToken() != null) {
65+
if (isEndToken(name, parser)) {
66+
break;
67+
}
68+
parser.nextToken();
69+
var value = parser.readValueAsTree();
70+
var newValue = getValueFromNode(value.get(""));
71+
addProperty(childObjects, name, newValue);
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)