Skip to content

Commit 8489c30

Browse files
author
Станислав Косолапов
committed
Подготовка к релизу:
* исправлена работа в Linux * добавлен формат Codebura * обновлены зависимости
1 parent e05bd9e commit 8489c30

File tree

7 files changed

+153
-39
lines changed

7 files changed

+153
-39
lines changed

build.gradle

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
plugins {
22
id 'java'
33
id 'application'
4+
id 'jacoco'
45
id "com.github.breadmoirai.github-release" version "2.2.12"
56
id "com.github.jarmstrong.buildconfig" version "1.9.0"
67
}
78

89
group 'com.clouds42'
9-
version '2.4'
10+
version '2.5'
1011

1112
sourceCompatibility = 11
1213

1314
repositories {
1415
mavenCentral()
1516
maven { url 'https://jitpack.io' }
16-
// maven { url 'https://dl.bintray.com/epsilonlabs/epsilon-standalone/'}
1717
maven { url 'https://repo1.maven.org/maven2/' }
1818
}
1919

@@ -31,20 +31,20 @@ dependencies {
3131
ringExecutable = 'ring.cmd'
3232
}
3333
exec {
34-
commandLine ringExecutable, 'edt@2020.5.1', 'locations', 'list'
34+
commandLine ringExecutable, 'edt@2021.1.5', 'locations', 'list'
3535
standardOutput = output
3636
}
3737
edtLocation = output.toString().trim().split("\n")[0].trim() + '/plugins/'
3838
}
3939
println 'EDT location: ' + edtLocation
4040

41-
compile group: 'info.picocli', name: 'picocli', version: '4.3.2'
42-
annotationProcessor 'info.picocli:picocli-codegen:4.3.2'
41+
compile group: 'info.picocli', name: 'picocli', version: '4.6.1'
42+
annotationProcessor 'info.picocli:picocli-codegen:4.6.1'
4343

4444
compile group: 'org.slf4j', name: 'slf4j-api', version: '2.0.0-alpha1'
4545
compile group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.0-alpha1'
4646

47-
compile group: 'org.scala-sbt.ipcsocket', name: 'ipcsocket', version: '1.1.0'
47+
compile group: 'org.scala-sbt.ipcsocket', name: 'ipcsocket', version: '1.4.0'
4848

4949
compile group: 'org.eclipse.emf', name: 'org.eclipse.emf.common', version: '2.16.0'
5050
compile group: 'org.eclipse.emf', name: 'org.eclipse.emf.ecore.xmi', version: '2.16.0'
@@ -65,9 +65,9 @@ dependencies {
6565

6666
compile group: 'de.vandermeer', name:'asciitable', version: '0.3.2'
6767

68-
implementation 'com.github.1c-syntax:mdclasses:0.8.0'
68+
implementation 'com.github.1c-syntax:mdclasses:0.9.1'
6969

70-
implementation('com.github.1c-syntax:bsl-parser:0.18.0') {
70+
implementation('com.github.1c-syntax:bsl-parser:0.19.3') {
7171
exclude group: "com.tunnelvisionlabs", module: "antlr4-annotations"
7272
exclude group: "com.ibm.icu", module: "*"
7373
exclude group: "org.antlr", module: "ST4"
@@ -97,6 +97,7 @@ run {
9797
}
9898

9999
test {
100+
finalizedBy jacocoTestReport
100101
classpath += configurations.providedCompile
101102
useJUnitPlatform()
102103
testLogging.showStandardStreams = true
@@ -111,6 +112,10 @@ application {
111112
mainClassName = 'com.clouds42.Coverage41C'
112113
}
113114

115+
jacocoTestReport {
116+
dependsOn test
117+
}
118+
114119
buildConfig {
115120
className("BuildConfig")
116121
packageName("com.clouds42")

choco/coverage41c.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
33
<metadata>
44
<id>Coverage41C</id>
5-
<version>2.3</version>
5+
<version>2.5</version>
66
<packageSourceUrl>https://github.com/proDOOMman/Coverage41C</packageSourceUrl>
77
<owners>proDOOMman</owners>
88
<title>Coverage41C (Install)</title>

src/main/java/com/clouds42/CommandLineOptions/MetadataOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.clouds42.CommandLineOptions;
22

3-
import com.github._1c_syntax.mdclasses.metadata.additional.SupportVariant;
3+
import com.github._1c_syntax.mdclasses.supportconf.SupportVariant;
44
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
66
import picocli.CommandLine.Option;

src/main/java/com/clouds42/CommandLineOptions/OutputOptions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public class OutputOptions {
1111

1212
public enum OutputFormat {
1313
GENERIC_COVERAGE,
14-
LCOV
14+
LCOV,
15+
COBERTURA
1516
}
1617

1718
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

src/main/java/com/clouds42/MyRuntimeDebugModelXmlSerializer.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
package com.clouds42;
22

3-
import com._1c.g5.v8.dt.internal.debug.core.DebugCorePlugin;
43
import com._1c.g5.v8.dt.internal.debug.core.runtime.client.RuntimeDebugModelXmlSerializer;
54
import com._1c.g5.v8.dt.internal.debug.core.runtime.client.RuntimeExtendedMetaData;
65
import com.google.common.base.Preconditions;
6+
import com.google.inject.Singleton;
77
import org.eclipse.emf.ecore.EObject;
88
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
9-
import com.google.inject.Singleton;
109
import org.xml.sax.InputSource;
1110

1211
import java.io.ByteArrayOutputStream;
1312
import java.io.IOException;
1413
import java.io.StringReader;
1514
import java.nio.charset.Charset;
1615
import java.nio.charset.StandardCharsets;
17-
import java.text.MessageFormat;
1816
import java.util.HashMap;
1917
import java.util.Map;
2018

@@ -74,7 +72,7 @@ public <T extends EObject> T deserialize(String xmlString, Class<T> deserializeT
7472
return result;
7573
}
7674

77-
private EObject convertToEObject(String xmlString) throws IOException {
75+
protected EObject convertToEObject(String xmlString) throws IOException {
7876
Map<Object, Object> loadOptions = new HashMap();
7977
loadOptions.put("EXTENDED_META_DATA", true);
8078
loadOptions.put("LAX_FEATURE_PROCESSING", true);
@@ -84,7 +82,7 @@ private EObject convertToEObject(String xmlString) throws IOException {
8482
return (EObject)resource.getContents().get(0);
8583
}
8684

87-
private String convertToXml(EObject eObject) throws IOException {
85+
protected String convertToXml(EObject eObject) throws IOException {
8886
XMLResourceImpl resource = new XMLResourceImpl();
8987
resource.setEncoding(ENCODING.name());
9088
resource.getContents().add(eObject);
@@ -95,7 +93,7 @@ private String convertToXml(EObject eObject) throws IOException {
9593
return new String(outputStream.toByteArray(), ENCODING);
9694
}
9795

98-
private String replaceRootElement(String xmlString, String replaceFromTag, String replaceToTag) {
96+
protected String replaceRootElement(String xmlString, String replaceFromTag, String replaceToTag) {
9997

10098
xmlString = xmlString.replaceFirst("<" + replaceFromTag, "<" + replaceToTag);
10199
if (!xmlString.endsWith("/>")) {
@@ -111,9 +109,7 @@ private String replaceRootElement(String xmlString, String replaceFromTag, Strin
111109
return xmlString;
112110
}
113111

114-
115-
116-
private String removeUtf8Bom(String string) {
112+
protected String removeUtf8Bom(String string) {
117113
return string.startsWith(String.valueOf('\ufeff')) ? string.substring(1) : string;
118114
}
119115
}

src/main/java/com/clouds42/Utils.java

Lines changed: 129 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@
33
import com.clouds42.CommandLineOptions.ConnectionOptions;
44
import com.clouds42.CommandLineOptions.MetadataOptions;
55
import com.clouds42.CommandLineOptions.OutputOptions;
6-
import com.github._1c_syntax.bsl.parser.BSLLexer;
7-
import com.github._1c_syntax.bsl.parser.BSLParser;
8-
import com.github._1c_syntax.bsl.parser.BSLParserRuleContext;
9-
import com.github._1c_syntax.bsl.parser.BSLTokenizer;
10-
import com.github._1c_syntax.bsl.parser.Tokenizer;
11-
import com.github._1c_syntax.mdclasses.mdo.MDObjectBase;
12-
import com.github._1c_syntax.mdclasses.mdo.SettingsStorage;
13-
import com.github._1c_syntax.mdclasses.metadata.Configuration;
14-
import com.github._1c_syntax.mdclasses.metadata.additional.MDOModule;
15-
import com.github._1c_syntax.mdclasses.metadata.additional.ModuleType;
16-
import com.github._1c_syntax.mdclasses.metadata.additional.SupportVariant;
6+
import com.github._1c_syntax.bsl.parser.*;
7+
import com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase;
8+
import com.github._1c_syntax.mdclasses.mdo.MDSettingsStorage;
9+
import com.github._1c_syntax.mdclasses.Configuration;
10+
import com.github._1c_syntax.mdclasses.mdo.support.MDOModule;
11+
import com.github._1c_syntax.mdclasses.mdo.support.ModuleType;
12+
import com.github._1c_syntax.mdclasses.supportconf.SupportVariant;
1713
import de.vandermeer.asciitable.AsciiTable;
1814
import de.vandermeer.asciitable.CWC_LongestLine;
1915
import org.antlr.v4.runtime.Token;
@@ -46,6 +42,7 @@
4642
import java.nio.file.Files;
4743
import java.nio.file.Path;
4844
import java.nio.file.Paths;
45+
import java.time.Instant;
4946
import java.util.*;
5047
import java.util.regex.Matcher;
5148
import java.util.regex.Pattern;
@@ -56,13 +53,13 @@ public class Utils {
5653

5754
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
5855

59-
public static String getModuleTypeUuid(ModuleType moduleType, MDObjectBase mdObject) {
56+
public static String getModuleTypeUuid(ModuleType moduleType, AbstractMDObjectBase mdObject) {
6057
if (moduleType == ModuleType.CommandModule) {
6158
return "078a6af8-d22c-4248-9c33-7e90075a3d2c";
6259
} else if (moduleType == ModuleType.ObjectModule) {
6360
return "a637f77f-3840-441d-a1c3-699c8c5cb7e0";
6461
} else if (moduleType == ModuleType.ManagerModule) {
65-
if (mdObject instanceof SettingsStorage) {
62+
if (mdObject instanceof MDSettingsStorage) {
6663
return "0c8cad23-bf8c-468e-b49e-12f1927c048b";
6764
} else {
6865
return "d1b64a2c-8078-4982-8190-8f81aefda192";
@@ -92,7 +89,7 @@ public static String getModuleTypeUuid(ModuleType moduleType, MDObjectBase mdObj
9289
return "UNKNOWN";
9390
}
9491

95-
private static String getUriKey(String mdObjUuid, ModuleType moduleType, MDObjectBase mdObj) {
92+
private static String getUriKey(String mdObjUuid, ModuleType moduleType, AbstractMDObjectBase mdObj) {
9693
return mdObjUuid + "/" + getModuleTypeUuid(moduleType, mdObj);
9794
}
9895

@@ -135,7 +132,8 @@ private static void addCoverageData(Map<URI, Map<BigDecimal, Integer>> coverageD
135132

136133
if (linesToCover.length > 0) {
137134

138-
List<Token> comments = tokenizer.getTokens().stream()
135+
List<Token> allTokens = tokenizer.getTokens();
136+
List<Token> comments = allTokens.stream()
139137
.filter(token -> token.getType() == BSLLexer.LINE_COMMENT)
140138
.collect(Collectors.toList());
141139

@@ -220,7 +218,7 @@ public static Map<String, URI> readMetadata(MetadataOptions metadataOptions,
220218
Configuration conf = Configuration.create(rootPath);
221219

222220
for (MDOModule module : conf.getModules()) {
223-
MDObjectBase mdObj = module.getOwner();
221+
AbstractMDObjectBase mdObj = module.getOwner();
224222

225223
String mdObjUuid = mdObj.getUuid();
226224

@@ -347,11 +345,123 @@ public static void dumpCoverageFile(Map<URI, Map<BigDecimal, Integer>> coverageD
347345
dumpGenericCoverageFile(coverageData, metadataOptions, outputOptions);
348346
} else if (outputOptions.getOutputFormat() == OutputOptions.OutputFormat.LCOV) {
349347
dumpLcovFile(coverageData, metadataOptions, outputOptions);
348+
} else if (outputOptions.getOutputFormat() == OutputOptions.OutputFormat.COBERTURA) {
349+
dumpCoberturaFile(coverageData, metadataOptions, outputOptions);
350350
} else {
351351
logger.info("Unknown format");
352352
}
353353
}
354354

355+
private static void dumpCoberturaFile(Map<URI, Map<BigDecimal, Integer>> coverageData,
356+
MetadataOptions metadataOptions,
357+
OutputOptions outputOptions) {
358+
DocumentBuilderFactory icFactory = DocumentBuilderFactory.newInstance();
359+
DocumentBuilder icBuilder;
360+
try {
361+
long linesToCover = 0;
362+
long coveredLinesCount = 0;
363+
for (Map<BigDecimal, Integer> bigDecimalMap : coverageData.values()) {
364+
linesToCover += bigDecimalMap.values().stream().filter(value -> value >= 0).count();
365+
coveredLinesCount += bigDecimalMap.values().stream().filter(value -> value > 0).count();
366+
}
367+
logger.info("Lines to cover: " + linesToCover);
368+
logger.info("Covered lines: " + coveredLinesCount);
369+
if (linesToCover > 0) {
370+
logger.info("Coverage: " + Math.floorDiv(coveredLinesCount * 10000, linesToCover) / 100. + "%");
371+
}
372+
373+
URI projectUri = Path.of(metadataOptions.getProjectDirName()).toUri();
374+
icBuilder = icFactory.newDocumentBuilder();
375+
Document doc = icBuilder.newDocument();
376+
Element mainRootElement = doc.createElement("coverage");
377+
String lineRate = "0.0";
378+
if (linesToCover > 0) {
379+
lineRate = String.valueOf(Math.floorDiv(coveredLinesCount * 100, linesToCover) / 100.);
380+
}
381+
mainRootElement.setAttribute("line-rate", lineRate);
382+
mainRootElement.setAttribute("branch-rate", "0.0");
383+
mainRootElement.setAttribute("lines-covered", String.valueOf(coveredLinesCount));
384+
mainRootElement.setAttribute("lines-valid", String.valueOf(linesToCover));
385+
mainRootElement.setAttribute("branches-covered", "0");
386+
mainRootElement.setAttribute("branches-valid", "0");
387+
mainRootElement.setAttribute("complexity", "0");
388+
mainRootElement.setAttribute("version", "0");
389+
mainRootElement.setAttribute("timestamp", String.valueOf(Instant.now().getEpochSecond()));
390+
doc.appendChild(mainRootElement);
391+
392+
Element sourcesElement = doc.createElement("sources");
393+
mainRootElement.appendChild(sourcesElement);
394+
395+
Element sourceElement = doc.createElement("source");
396+
String[] projectDirArray = projectUri.getPath().split("/");
397+
if (projectDirArray.length > 2) {
398+
sourceElement.setTextContent("/builds/" + projectDirArray[projectDirArray.length - 2] + "/" + projectDirArray[projectDirArray.length - 1] + "/");
399+
} else {
400+
sourcesElement.setTextContent(projectUri.getPath());
401+
}
402+
sourcesElement.appendChild(sourceElement);
403+
404+
Element packagesElement = doc.createElement("packages");
405+
mainRootElement.appendChild(packagesElement);
406+
407+
Element packageElement = doc.createElement("package");
408+
packageElement.setAttribute("name", "Main");
409+
packageElement.setAttribute("line-rate", lineRate);
410+
packageElement.setAttribute("branch-rate", "0.0");
411+
packageElement.setAttribute("complexity", "0");
412+
packagesElement.appendChild(packageElement);
413+
414+
Element classesElement = doc.createElement("classes");
415+
packageElement.appendChild(classesElement);
416+
417+
coverageData.forEach((uri, bigDecimalsMap) -> {
418+
if (bigDecimalsMap.isEmpty()) {
419+
return;
420+
}
421+
422+
long fileLinesToCover = bigDecimalsMap.values().stream().filter(value -> value >= 0).count();
423+
long fileCoveredLinesCount = bigDecimalsMap.values().stream().filter(value -> value > 0).count();
424+
String fileLineRate = "0.0";
425+
if (fileLinesToCover > 0) {
426+
fileLineRate = String.valueOf(Math.floorDiv(fileCoveredLinesCount * 100, fileLinesToCover) / 100.);
427+
}
428+
429+
Element classElement = doc.createElement("class");
430+
classElement.setAttribute("name", projectUri.relativize(uri).getPath());
431+
classElement.setAttribute("line-rate", fileLineRate);
432+
classElement.setAttribute("branch-rate", "0.0");
433+
classElement.setAttribute("complexity", "0");
434+
classElement.setAttribute("filename", projectUri.relativize(uri).getPath());
435+
classesElement.appendChild(classElement);
436+
437+
Element methodsElement = doc.createElement("methods");
438+
classElement.appendChild(methodsElement);
439+
440+
bigDecimalsMap.forEach((bigDecimal, hits) -> {
441+
if (hits >= 0) {
442+
Element lineElement = doc.createElement("line");
443+
lineElement.setAttribute("hits", String.valueOf(hits));
444+
lineElement.setAttribute("number", bigDecimal.toString());
445+
lineElement.setAttribute("branch", "false");
446+
classElement.appendChild(lineElement);
447+
}
448+
});
449+
});
450+
Transformer transformer = TransformerFactory.newInstance().newTransformer();
451+
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
452+
DOMSource source = new DOMSource(doc);
453+
StreamResult outputStream;
454+
if (outputOptions.getOutputFile() == null) {
455+
outputStream = new StreamResult(System.out);
456+
} else {
457+
outputStream = new StreamResult(new FileOutputStream(outputOptions.getOutputFile()));
458+
}
459+
transformer.transform(source, outputStream);
460+
} catch (Exception e) {
461+
logger.error(e.getLocalizedMessage());
462+
}
463+
}
464+
355465
private static void dumpGenericCoverageFile(Map<URI, Map<BigDecimal, Integer>> coverageData,
356466
MetadataOptions metadataOptions,
357467
OutputOptions outputOptions) {
@@ -537,7 +647,9 @@ public static String getPipeName(ConnectionOptions connectionOptions) throws IOE
537647
pipeName = String.format("\\\\.\\pipe\\COVER_%s_%s", connectionOptions.getInfobaseAlias(),
538648
debugUri.toString().replaceAll("[^a-zA-Z0-9-_.]", "_"));
539649
} else {
540-
Path tempDir = Files.createTempDirectory("coverage41c");
650+
File tempDirFile = new File("/tmp/coverage41c/");
651+
tempDirFile.mkdirs();
652+
Path tempDir = tempDirFile.toPath();
541653
Path sock = tempDir.resolve(String.format("%s_%s.sock", connectionOptions.getInfobaseAlias(),
542654
debugUri.toString().replaceAll("[^a-zA-Z0-9-_.]", "_")));
543655
pipeName = sock.toString();

src/test/java/com/clouds42/CoverageTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CoverageTest {
3636

3737
final String ibUser = "Администратор";
3838
final String ibPassword = "\\\"\\\"";
39-
final String v8version = "8.3.17";
39+
final String v8version = "8.3.18.";
4040
final String buildDirName = "build";
4141

4242
String vrunnerExecutable = "vrunner";
@@ -136,7 +136,7 @@ void testCoverage(
136136
return mainAppReturnCode;
137137
});
138138

139-
Thread.sleep(500); // wait for socket server
139+
Thread.sleep(1500); // wait for socket server
140140

141141
String[] mainAppCheckArguments = {
142142
PipeMessages.CHECK_COMMAND,

0 commit comments

Comments
 (0)