Skip to content

Commit

Permalink
Подготовка к релизу:
Browse files Browse the repository at this point in the history
* исправлена работа в Linux
* добавлен формат Codebura
* обновлены зависимости
  • Loading branch information
Станислав Косолапов committed Jun 19, 2021
1 parent e05bd9e commit 8489c30
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 39 deletions.
21 changes: 13 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
plugins {
id 'java'
id 'application'
id 'jacoco'
id "com.github.breadmoirai.github-release" version "2.2.12"
id "com.github.jarmstrong.buildconfig" version "1.9.0"
}

group 'com.clouds42'
version '2.4'
version '2.5'

sourceCompatibility = 11

repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
// maven { url 'https://dl.bintray.com/epsilonlabs/epsilon-standalone/'}
maven { url 'https://repo1.maven.org/maven2/' }
}

Expand All @@ -31,20 +31,20 @@ dependencies {
ringExecutable = 'ring.cmd'
}
exec {
commandLine ringExecutable, 'edt@2020.5.1', 'locations', 'list'
commandLine ringExecutable, 'edt@2021.1.5', 'locations', 'list'
standardOutput = output
}
edtLocation = output.toString().trim().split("\n")[0].trim() + '/plugins/'
}
println 'EDT location: ' + edtLocation

compile group: 'info.picocli', name: 'picocli', version: '4.3.2'
annotationProcessor 'info.picocli:picocli-codegen:4.3.2'
compile group: 'info.picocli', name: 'picocli', version: '4.6.1'
annotationProcessor 'info.picocli:picocli-codegen:4.6.1'

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

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

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

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

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

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

test {
finalizedBy jacocoTestReport
classpath += configurations.providedCompile
useJUnitPlatform()
testLogging.showStandardStreams = true
Expand All @@ -111,6 +112,10 @@ application {
mainClassName = 'com.clouds42.Coverage41C'
}

jacocoTestReport {
dependsOn test
}

buildConfig {
className("BuildConfig")
packageName("com.clouds42")
Expand Down
2 changes: 1 addition & 1 deletion choco/coverage41c.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>Coverage41C</id>
<version>2.3</version>
<version>2.5</version>
<packageSourceUrl>https://github.com/proDOOMman/Coverage41C</packageSourceUrl>
<owners>proDOOMman</owners>
<title>Coverage41C (Install)</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.clouds42.CommandLineOptions;

import com.github._1c_syntax.mdclasses.metadata.additional.SupportVariant;
import com.github._1c_syntax.mdclasses.supportconf.SupportVariant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Option;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class OutputOptions {

public enum OutputFormat {
GENERIC_COVERAGE,
LCOV
LCOV,
COBERTURA
}

private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/com/clouds42/MyRuntimeDebugModelXmlSerializer.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package com.clouds42;

import com._1c.g5.v8.dt.internal.debug.core.DebugCorePlugin;
import com._1c.g5.v8.dt.internal.debug.core.runtime.client.RuntimeDebugModelXmlSerializer;
import com._1c.g5.v8.dt.internal.debug.core.runtime.client.RuntimeExtendedMetaData;
import com.google.common.base.Preconditions;
import com.google.inject.Singleton;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
import com.google.inject.Singleton;
import org.xml.sax.InputSource;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -74,7 +72,7 @@ public <T extends EObject> T deserialize(String xmlString, Class<T> deserializeT
return result;
}

private EObject convertToEObject(String xmlString) throws IOException {
protected EObject convertToEObject(String xmlString) throws IOException {
Map<Object, Object> loadOptions = new HashMap();
loadOptions.put("EXTENDED_META_DATA", true);
loadOptions.put("LAX_FEATURE_PROCESSING", true);
Expand All @@ -84,7 +82,7 @@ private EObject convertToEObject(String xmlString) throws IOException {
return (EObject)resource.getContents().get(0);
}

private String convertToXml(EObject eObject) throws IOException {
protected String convertToXml(EObject eObject) throws IOException {
XMLResourceImpl resource = new XMLResourceImpl();
resource.setEncoding(ENCODING.name());
resource.getContents().add(eObject);
Expand All @@ -95,7 +93,7 @@ private String convertToXml(EObject eObject) throws IOException {
return new String(outputStream.toByteArray(), ENCODING);
}

private String replaceRootElement(String xmlString, String replaceFromTag, String replaceToTag) {
protected String replaceRootElement(String xmlString, String replaceFromTag, String replaceToTag) {

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



private String removeUtf8Bom(String string) {
protected String removeUtf8Bom(String string) {
return string.startsWith(String.valueOf('\ufeff')) ? string.substring(1) : string;
}
}
146 changes: 129 additions & 17 deletions src/main/java/com/clouds42/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
import com.clouds42.CommandLineOptions.ConnectionOptions;
import com.clouds42.CommandLineOptions.MetadataOptions;
import com.clouds42.CommandLineOptions.OutputOptions;
import com.github._1c_syntax.bsl.parser.BSLLexer;
import com.github._1c_syntax.bsl.parser.BSLParser;
import com.github._1c_syntax.bsl.parser.BSLParserRuleContext;
import com.github._1c_syntax.bsl.parser.BSLTokenizer;
import com.github._1c_syntax.bsl.parser.Tokenizer;
import com.github._1c_syntax.mdclasses.mdo.MDObjectBase;
import com.github._1c_syntax.mdclasses.mdo.SettingsStorage;
import com.github._1c_syntax.mdclasses.metadata.Configuration;
import com.github._1c_syntax.mdclasses.metadata.additional.MDOModule;
import com.github._1c_syntax.mdclasses.metadata.additional.ModuleType;
import com.github._1c_syntax.mdclasses.metadata.additional.SupportVariant;
import com.github._1c_syntax.bsl.parser.*;
import com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase;
import com.github._1c_syntax.mdclasses.mdo.MDSettingsStorage;
import com.github._1c_syntax.mdclasses.Configuration;
import com.github._1c_syntax.mdclasses.mdo.support.MDOModule;
import com.github._1c_syntax.mdclasses.mdo.support.ModuleType;
import com.github._1c_syntax.mdclasses.supportconf.SupportVariant;
import de.vandermeer.asciitable.AsciiTable;
import de.vandermeer.asciitable.CWC_LongestLine;
import org.antlr.v4.runtime.Token;
Expand Down Expand Up @@ -46,6 +42,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -56,13 +53,13 @@ public class Utils {

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

public static String getModuleTypeUuid(ModuleType moduleType, MDObjectBase mdObject) {
public static String getModuleTypeUuid(ModuleType moduleType, AbstractMDObjectBase mdObject) {
if (moduleType == ModuleType.CommandModule) {
return "078a6af8-d22c-4248-9c33-7e90075a3d2c";
} else if (moduleType == ModuleType.ObjectModule) {
return "a637f77f-3840-441d-a1c3-699c8c5cb7e0";
} else if (moduleType == ModuleType.ManagerModule) {
if (mdObject instanceof SettingsStorage) {
if (mdObject instanceof MDSettingsStorage) {
return "0c8cad23-bf8c-468e-b49e-12f1927c048b";
} else {
return "d1b64a2c-8078-4982-8190-8f81aefda192";
Expand Down Expand Up @@ -92,7 +89,7 @@ public static String getModuleTypeUuid(ModuleType moduleType, MDObjectBase mdObj
return "UNKNOWN";
}

private static String getUriKey(String mdObjUuid, ModuleType moduleType, MDObjectBase mdObj) {
private static String getUriKey(String mdObjUuid, ModuleType moduleType, AbstractMDObjectBase mdObj) {
return mdObjUuid + "/" + getModuleTypeUuid(moduleType, mdObj);
}

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

if (linesToCover.length > 0) {

List<Token> comments = tokenizer.getTokens().stream()
List<Token> allTokens = tokenizer.getTokens();
List<Token> comments = allTokens.stream()
.filter(token -> token.getType() == BSLLexer.LINE_COMMENT)
.collect(Collectors.toList());

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

for (MDOModule module : conf.getModules()) {
MDObjectBase mdObj = module.getOwner();
AbstractMDObjectBase mdObj = module.getOwner();

String mdObjUuid = mdObj.getUuid();

Expand Down Expand Up @@ -347,11 +345,123 @@ public static void dumpCoverageFile(Map<URI, Map<BigDecimal, Integer>> coverageD
dumpGenericCoverageFile(coverageData, metadataOptions, outputOptions);
} else if (outputOptions.getOutputFormat() == OutputOptions.OutputFormat.LCOV) {
dumpLcovFile(coverageData, metadataOptions, outputOptions);
} else if (outputOptions.getOutputFormat() == OutputOptions.OutputFormat.COBERTURA) {
dumpCoberturaFile(coverageData, metadataOptions, outputOptions);
} else {
logger.info("Unknown format");
}
}

private static void dumpCoberturaFile(Map<URI, Map<BigDecimal, Integer>> coverageData,
MetadataOptions metadataOptions,
OutputOptions outputOptions) {
DocumentBuilderFactory icFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder icBuilder;
try {
long linesToCover = 0;
long coveredLinesCount = 0;
for (Map<BigDecimal, Integer> bigDecimalMap : coverageData.values()) {
linesToCover += bigDecimalMap.values().stream().filter(value -> value >= 0).count();
coveredLinesCount += bigDecimalMap.values().stream().filter(value -> value > 0).count();
}
logger.info("Lines to cover: " + linesToCover);
logger.info("Covered lines: " + coveredLinesCount);
if (linesToCover > 0) {
logger.info("Coverage: " + Math.floorDiv(coveredLinesCount * 10000, linesToCover) / 100. + "%");
}

URI projectUri = Path.of(metadataOptions.getProjectDirName()).toUri();
icBuilder = icFactory.newDocumentBuilder();
Document doc = icBuilder.newDocument();
Element mainRootElement = doc.createElement("coverage");
String lineRate = "0.0";
if (linesToCover > 0) {
lineRate = String.valueOf(Math.floorDiv(coveredLinesCount * 100, linesToCover) / 100.);
}
mainRootElement.setAttribute("line-rate", lineRate);
mainRootElement.setAttribute("branch-rate", "0.0");
mainRootElement.setAttribute("lines-covered", String.valueOf(coveredLinesCount));
mainRootElement.setAttribute("lines-valid", String.valueOf(linesToCover));
mainRootElement.setAttribute("branches-covered", "0");
mainRootElement.setAttribute("branches-valid", "0");
mainRootElement.setAttribute("complexity", "0");
mainRootElement.setAttribute("version", "0");
mainRootElement.setAttribute("timestamp", String.valueOf(Instant.now().getEpochSecond()));
doc.appendChild(mainRootElement);

Element sourcesElement = doc.createElement("sources");
mainRootElement.appendChild(sourcesElement);

Element sourceElement = doc.createElement("source");
String[] projectDirArray = projectUri.getPath().split("/");
if (projectDirArray.length > 2) {
sourceElement.setTextContent("/builds/" + projectDirArray[projectDirArray.length - 2] + "/" + projectDirArray[projectDirArray.length - 1] + "/");
} else {
sourcesElement.setTextContent(projectUri.getPath());
}
sourcesElement.appendChild(sourceElement);

Element packagesElement = doc.createElement("packages");
mainRootElement.appendChild(packagesElement);

Element packageElement = doc.createElement("package");
packageElement.setAttribute("name", "Main");
packageElement.setAttribute("line-rate", lineRate);
packageElement.setAttribute("branch-rate", "0.0");
packageElement.setAttribute("complexity", "0");
packagesElement.appendChild(packageElement);

Element classesElement = doc.createElement("classes");
packageElement.appendChild(classesElement);

coverageData.forEach((uri, bigDecimalsMap) -> {
if (bigDecimalsMap.isEmpty()) {
return;
}

long fileLinesToCover = bigDecimalsMap.values().stream().filter(value -> value >= 0).count();
long fileCoveredLinesCount = bigDecimalsMap.values().stream().filter(value -> value > 0).count();
String fileLineRate = "0.0";
if (fileLinesToCover > 0) {
fileLineRate = String.valueOf(Math.floorDiv(fileCoveredLinesCount * 100, fileLinesToCover) / 100.);
}

Element classElement = doc.createElement("class");
classElement.setAttribute("name", projectUri.relativize(uri).getPath());
classElement.setAttribute("line-rate", fileLineRate);
classElement.setAttribute("branch-rate", "0.0");
classElement.setAttribute("complexity", "0");
classElement.setAttribute("filename", projectUri.relativize(uri).getPath());
classesElement.appendChild(classElement);

Element methodsElement = doc.createElement("methods");
classElement.appendChild(methodsElement);

bigDecimalsMap.forEach((bigDecimal, hits) -> {
if (hits >= 0) {
Element lineElement = doc.createElement("line");
lineElement.setAttribute("hits", String.valueOf(hits));
lineElement.setAttribute("number", bigDecimal.toString());
lineElement.setAttribute("branch", "false");
classElement.appendChild(lineElement);
}
});
});
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
DOMSource source = new DOMSource(doc);
StreamResult outputStream;
if (outputOptions.getOutputFile() == null) {
outputStream = new StreamResult(System.out);
} else {
outputStream = new StreamResult(new FileOutputStream(outputOptions.getOutputFile()));
}
transformer.transform(source, outputStream);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
}
}

private static void dumpGenericCoverageFile(Map<URI, Map<BigDecimal, Integer>> coverageData,
MetadataOptions metadataOptions,
OutputOptions outputOptions) {
Expand Down Expand Up @@ -537,7 +647,9 @@ public static String getPipeName(ConnectionOptions connectionOptions) throws IOE
pipeName = String.format("\\\\.\\pipe\\COVER_%s_%s", connectionOptions.getInfobaseAlias(),
debugUri.toString().replaceAll("[^a-zA-Z0-9-_.]", "_"));
} else {
Path tempDir = Files.createTempDirectory("coverage41c");
File tempDirFile = new File("/tmp/coverage41c/");
tempDirFile.mkdirs();
Path tempDir = tempDirFile.toPath();
Path sock = tempDir.resolve(String.format("%s_%s.sock", connectionOptions.getInfobaseAlias(),
debugUri.toString().replaceAll("[^a-zA-Z0-9-_.]", "_")));
pipeName = sock.toString();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/clouds42/CoverageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CoverageTest {

final String ibUser = "Администратор";
final String ibPassword = "\\\"\\\"";
final String v8version = "8.3.17";
final String v8version = "8.3.18.";
final String buildDirName = "build";

String vrunnerExecutable = "vrunner";
Expand Down Expand Up @@ -136,7 +136,7 @@ void testCoverage(
return mainAppReturnCode;
});

Thread.sleep(500); // wait for socket server
Thread.sleep(1500); // wait for socket server

String[] mainAppCheckArguments = {
PipeMessages.CHECK_COMMAND,
Expand Down

0 comments on commit 8489c30

Please sign in to comment.