diff --git a/README.md b/README.md index 86cdbc0..087e64a 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ https://42clouds.com/ru-ru/techdocs/raschyot-pokrytiya-koda-1C-testami.html путём ручного зарпуска дебаг сервера dbgs.exe (например так: ```dbgs.exe --addr=127.0.0.1 --port=1550```), к которому будет подключаться Coverage41C и клиент файловой базы (запущенный с флагами ```/debug -http -attach /debuggerURL «адрес отладчика»``` или через меню "Настройка->Параметры->Сервер отладки" в самом клиенте), см. https://its.1c.ru/db/v837doc#bookmark:adm:TI000000495 - *Примечание: если включить протокол отладки http через конфигуратор Сервис -> Параметры -> Отладка, то Coverage41C не сможет подключиться к серверу отладки, т.к. одновременно к информационной базе может быть подключен только один интерфей отладки.* + *Примечание: если включить протокол отладки http через конфигуратор Сервис -> Параметры -> Отладка, то Coverage41C не сможет подключиться к серверу отладки, т.к. одновременно к информационной базе может быть подключен только один интерфейс отладки.* 3) Проверяем что сервер отладки dbgs.exe (https://its.1c.ru/db/edtdoc/content/197/hdoc/_top/dbgs) запустился и работает. Для этого в браузере открываем его, адрес по умолчанию http://127.0.0.1:1550/. В случае успеха выдолжны увидеть сообщение "... it works!". 4) Выгружаем исходники конфигурации, расширения или внешней обработки в файлы (если у вас проекта EDT, то этот шаг пропускаем - он и так хранится в файлах) diff --git a/build.gradle b/build.gradle index d64b253..e6561a2 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ plugins { } group 'com.clouds42' -version '2.5.2' +version '2.7.1' sourceCompatibility = 11 @@ -20,7 +20,7 @@ repositories { configurations { - providedCompile + providedRuntime } dependencies { @@ -39,36 +39,36 @@ dependencies { } println 'EDT location: ' + edtLocation - compile group: 'info.picocli', name: 'picocli', version: '4.6.1' - annotationProcessor 'info.picocli:picocli-codegen:4.6.1' + compile group: 'info.picocli', name: 'picocli', version: '4.6.3' + annotationProcessor 'info.picocli:picocli-codegen:4.6.2' 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.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.common', version: '2.23.0' compile group: 'org.eclipse.emf', name: 'org.eclipse.emf.ecore.xmi', version: '2.16.0' - compile group: 'org.eclipse.emf', name: 'org.eclipse.emf.ecore.xcore.lib', version: '1.4.0' + compile group: 'org.eclipse.emf', name: 'org.eclipse.emf.ecore.xcore.lib', version: '1.6.0' - compile group: 'org.eclipse.platform', name: 'org.eclipse.osgi', version: '3.15.300' + compile group: 'org.eclipse.platform', name: 'org.eclipse.osgi', version: '3.17.100' - compile group: 'org.eclipse.platform', name: 'org.eclipse.core.runtime', version: '3.15.300' - compile group: 'org.eclipse.platform', name: 'org.eclipse.osgi.services', version: '3.8.0' - compile group: 'org.eclipse.platform', name: 'org.eclipse.equinox.common', version: '3.10.400' + compile group: 'org.eclipse.platform', name: 'org.eclipse.core.runtime', version: '3.24.0' + compile group: 'org.eclipse.platform', name: 'org.eclipse.osgi.services', version: '3.10.200' + compile group: 'org.eclipse.platform', name: 'org.eclipse.equinox.common', version: '3.15.100' - compile group: 'org.eclipse.jetty', name: 'jetty-client', version: '9.4.27.v20200227' + compile group: 'org.eclipse.jetty', name: 'jetty-client', version: '11.0.6' - compile group: 'com.google.guava', name: 'guava', version: '29.0-jre' + compile group: 'com.google.guava', name: 'guava', version: '31.0.1-jre' - compile group: 'com.google.inject', name: 'guice', version: '4.0' + compile group: 'com.google.inject', name: 'guice', version: '5.1.0' compile group: 'de.vandermeer', name:'asciitable', version: '0.3.2' - implementation 'com.github.1c-syntax:mdclasses:a5ce5cd5439201040caf27fdc8e4763a7f45f65c' + implementation 'com.github.1c-syntax:mdclasses:0.9.3' - implementation('com.github.1c-syntax:bsl-parser:0.19.3') { + implementation('com.github.1c-syntax:bsl-parser:0.20.3') { exclude group: "com.tunnelvisionlabs", module: "antlr4-annotations" exclude group: "com.ibm.icu", module: "*" exclude group: "org.antlr", module: "ST4" @@ -77,29 +77,29 @@ dependencies { exclude group: "org.glassfish", module: "javax.json" } - providedCompile fileTree(edtLocation) { include 'com._1c.g5.v8.dt.debug.*.jar' } + providedRuntime fileTree(edtLocation) { include 'com._1c.g5.v8.dt.debug.*.jar' } - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.2' - testCompile 'org.xmlunit:xmlunit-core:2.6.4' - testCompile 'org.xmlunit:xmlunit-matchers:2.6.4' - testCompile 'com.fasterxml.jackson.core:jackson-core:2.11.0' - testCompile 'com.fasterxml.jackson.core:jackson-databind:2.11.0' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' + testCompile 'org.xmlunit:xmlunit-core:2.9.0' + testCompile 'org.xmlunit:xmlunit-matchers:2.9.0' + testCompile 'com.fasterxml.jackson.core:jackson-core:2.13.1' + testCompile 'com.fasterxml.jackson.core:jackson-databind:2.13.1' } tasks.withType(JavaCompile) { - sourceSets.main.compileClasspath += configurations.providedCompile + sourceSets.main.compileClasspath += configurations.providedRuntime options.compilerArgs += ["-Aproject=${project.group}/${project.name}"] options.encoding = 'UTF-8' } run { - classpath += configurations.providedCompile + classpath += configurations.providedRuntime } test { finalizedBy jacocoTestReport - classpath += configurations.providedCompile + classpath += configurations.providedRuntime useJUnitPlatform() testLogging.showStandardStreams = true } diff --git a/src/main/java/com/clouds42/AbstractDebugClient.java b/src/main/java/com/clouds42/AbstractDebugClient.java index a8101c1..61b0689 100644 --- a/src/main/java/com/clouds42/AbstractDebugClient.java +++ b/src/main/java/com/clouds42/AbstractDebugClient.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later @@ -29,9 +29,15 @@ import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; +import org.eclipse.jetty.client.dynamic.HttpClientTransportDynamic; import org.eclipse.jetty.client.util.FutureResponseListener; -import org.eclipse.jetty.client.util.StringContentProvider; -import org.eclipse.jetty.http.*; +import org.eclipse.jetty.client.util.StringRequestContent; +import org.eclipse.jetty.http.HttpField; +import org.eclipse.jetty.http.HttpFields; +import org.eclipse.jetty.http.HttpHeader; +import org.eclipse.jetty.http.HttpMethod; +import org.eclipse.jetty.http.HttpStatus; +import org.eclipse.jetty.io.ClientConnector; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,16 +72,26 @@ protected HttpClient createHttpClient() { protected HttpClient createHttpClient(long idleTimeout) { SslContextFactory.Client sslContextFactory = new SslContextFactory.Client(); sslContextFactory.setTrustAll(true); - HttpClient httpClient = new HttpClient(sslContextFactory); - HttpField agent = new HttpField("User-Agent", "1CV8"); + + ClientConnector clientConnector = new ClientConnector(); + clientConnector.setSslContextFactory(sslContextFactory); + + HttpClient httpClient = new HttpClient(new HttpClientTransportDynamic(clientConnector)); httpClient.setFollowRedirects(true); - httpClient.setUserAgentField(agent); + httpClient.setUserAgentField(new HttpField("User-Agent", "1CV8")); httpClient.setIdleTimeout(idleTimeout); return httpClient; } protected Request buildRequest(HttpClient httpClient, HttpMethod method, String componentUrl) { - return httpClient.newRequest(this.toUri(componentUrl)).method(method).header(HttpHeader.ACCEPT, "application/xml").header(HttpHeader.CONNECTION, HttpHeader.KEEP_ALIVE.asString()).header(HttpHeader.CONTENT_TYPE, "application/xml").header("1C-ApplicationName", "1C:Enterprise DT"); + return httpClient.newRequest(this.toUri(componentUrl)) + .method(method) + .headers(httpFields -> httpFields + .add(HttpHeader.ACCEPT, "application/xml") + .add(HttpHeader.CONNECTION, HttpHeader.KEEP_ALIVE.asString()) + .add(HttpHeader.CONTENT_TYPE, "application/xml") + .add("1C-ApplicationName", "1C:Enterprise DT") + ); } protected String getComponentUrl(String debugServerUrl, String suffix) { @@ -101,7 +117,7 @@ protected static T performRuntimeHttpRequest(AbstractDebugCl if (requestContent != null) { try { String serializedRequest = abstractDebugClient.serializer.serialize(requestContent); - request.content(new StringContentProvider(serializedRequest)); + request.body(new StringRequestContent(serializedRequest)); } catch (IOException e) { throw new RuntimeDebugClientException("Error occurred while processing request", e); } diff --git a/src/main/java/com/clouds42/CommandLineOptions/ConnectionOptions.java b/src/main/java/com/clouds42/CommandLineOptions/ConnectionOptions.java index 372ca7e..a16d109 100644 --- a/src/main/java/com/clouds42/CommandLineOptions/ConnectionOptions.java +++ b/src/main/java/com/clouds42/CommandLineOptions/ConnectionOptions.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/CommandLineOptions/ConvertOptions.java b/src/main/java/com/clouds42/CommandLineOptions/ConvertOptions.java index f2c6ef1..8b2b149 100644 --- a/src/main/java/com/clouds42/CommandLineOptions/ConvertOptions.java +++ b/src/main/java/com/clouds42/CommandLineOptions/ConvertOptions.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/CommandLineOptions/DebuggerOptions.java b/src/main/java/com/clouds42/CommandLineOptions/DebuggerOptions.java index d39c33b..210caa7 100644 --- a/src/main/java/com/clouds42/CommandLineOptions/DebuggerOptions.java +++ b/src/main/java/com/clouds42/CommandLineOptions/DebuggerOptions.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later @@ -21,7 +21,8 @@ */ package com.clouds42.CommandLineOptions; -import com._1c.g5.v8.dt.debug.model.base.data.DebugTargetType; + +import com.clouds42.DebugTargetType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import picocli.CommandLine.Option; diff --git a/src/main/java/com/clouds42/CommandLineOptions/FilterOptions.java b/src/main/java/com/clouds42/CommandLineOptions/FilterOptions.java index b20c8f7..da9e345 100644 --- a/src/main/java/com/clouds42/CommandLineOptions/FilterOptions.java +++ b/src/main/java/com/clouds42/CommandLineOptions/FilterOptions.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/CommandLineOptions/LoggingOptions.java b/src/main/java/com/clouds42/CommandLineOptions/LoggingOptions.java index 1af5f5d..86173ea 100644 --- a/src/main/java/com/clouds42/CommandLineOptions/LoggingOptions.java +++ b/src/main/java/com/clouds42/CommandLineOptions/LoggingOptions.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/CommandLineOptions/MetadataOptions.java b/src/main/java/com/clouds42/CommandLineOptions/MetadataOptions.java index 19da877..fffc00a 100644 --- a/src/main/java/com/clouds42/CommandLineOptions/MetadataOptions.java +++ b/src/main/java/com/clouds42/CommandLineOptions/MetadataOptions.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/CommandLineOptions/OutputOptions.java b/src/main/java/com/clouds42/CommandLineOptions/OutputOptions.java index 71f3768..ff8f3c8 100644 --- a/src/main/java/com/clouds42/CommandLineOptions/OutputOptions.java +++ b/src/main/java/com/clouds42/CommandLineOptions/OutputOptions.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/Commands/ConvertCommand.java b/src/main/java/com/clouds42/Commands/ConvertCommand.java index 703eba4..0b94cac 100644 --- a/src/main/java/com/clouds42/Commands/ConvertCommand.java +++ b/src/main/java/com/clouds42/Commands/ConvertCommand.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/Commands/CoverServer.java b/src/main/java/com/clouds42/Commands/CoverServer.java index 8f82164..c74b0a2 100644 --- a/src/main/java/com/clouds42/Commands/CoverServer.java +++ b/src/main/java/com/clouds42/Commands/CoverServer.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/Commands/CoverageCommand.java b/src/main/java/com/clouds42/Commands/CoverageCommand.java index 5d533ba..5e0a612 100644 --- a/src/main/java/com/clouds42/Commands/CoverageCommand.java +++ b/src/main/java/com/clouds42/Commands/CoverageCommand.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later @@ -21,50 +21,27 @@ */ package com.clouds42.Commands; -import com._1c.g5.v8.dt.debug.core.runtime.client.RuntimeDebugClientException; -import com._1c.g5.v8.dt.debug.model.base.data.AttachDebugUIResult; -import com._1c.g5.v8.dt.debug.model.base.data.BSLModuleIdInternal; -import com._1c.g5.v8.dt.debug.model.base.data.DebugTargetId; -import com._1c.g5.v8.dt.debug.model.dbgui.commands.DBGUIExtCmdInfoBase; -import com._1c.g5.v8.dt.debug.model.dbgui.commands.DBGUIExtCmds; -import com._1c.g5.v8.dt.debug.model.dbgui.commands.impl.DBGUIExtCmdInfoMeasureImpl; -import com._1c.g5.v8.dt.debug.model.dbgui.commands.impl.DBGUIExtCmdInfoStartedImpl; -import com._1c.g5.v8.dt.debug.model.measure.PerformanceInfoLine; -import com._1c.g5.v8.dt.debug.model.measure.PerformanceInfoMain; -import com._1c.g5.v8.dt.debug.model.measure.PerformanceInfoModule; -import com._1c.g5.v8.dt.internal.debug.core.runtime.client.RuntimeDebugModelXmlSerializer; -import com.clouds42.CommandLineOptions.*; -import com.clouds42.DebugClient; -import com.clouds42.MyRuntimeDebugModelXmlSerializer; + +import com.clouds42.CommandLineOptions.ConnectionOptions; +import com.clouds42.CommandLineOptions.DebuggerOptions; +import com.clouds42.CommandLineOptions.FilterOptions; +import com.clouds42.CommandLineOptions.LoggingOptions; +import com.clouds42.CommandLineOptions.MetadataOptions; +import com.clouds42.CommandLineOptions.OutputOptions; +import com.clouds42.Coverager; import com.clouds42.PipeMessages; -import com.clouds42.Utils; -import org.eclipse.emf.common.util.EList; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import picocli.CommandLine; -import picocli.CommandLine.Command; import picocli.CommandLine.Mixin; +import picocli.CommandLine.Command; import picocli.CommandLine.Option; -import java.lang.module.ModuleDescriptor.Version; -import java.io.IOException; -import java.io.PrintWriter; -import java.lang.invoke.MethodHandles; -import java.math.BigDecimal; -import java.net.URI; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.*; import java.util.concurrent.Callable; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Stream; @Command(name = PipeMessages.START_COMMAND, mixinStandardHelpOptions = true, description = "Start measure and save coverage data to file", sortOptions = false) -public class CoverageCommand extends CoverServer implements Callable { +public class CoverageCommand implements Callable { - private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + private Coverager coverager; @Mixin private ConnectionOptions connectionOptions; @@ -87,291 +64,11 @@ public class CoverageCommand extends CoverServer implements Callable { @Option(names = {"--opid"}, description = "Owner process PID", defaultValue = "-1") Integer opid; - private DebugClient client; - - private final Map> coverageData = new HashMap<>() { - @Override - public Map get(Object key) { - Map map = super.get(key); - if (map == null) { - map = new HashMap<>(); - put((URI) key, map); - } - return map; - } - }; - - - private final AtomicBoolean stopExecution = new AtomicBoolean(false); - private boolean rawMode = false; - private boolean systemStarted = false; - - private void connectAllTargets(List debugTargets) { - logger.info("Current debug targets size: {}", debugTargets.size()); - debugTargets.forEach(debugTarget -> { - String id = debugTarget.getId(); - String seanceId = debugTarget.getSeanceId(); - String targetType = debugTarget.getTargetType().getName(); - logger.info("Id: {} , seance id: {} , target type: {}", id, seanceId, targetType); - try { - client.attachRuntimeDebugTargets(Collections.singletonList(UUID.fromString(debugTarget.getId()))); - } catch (RuntimeDebugClientException e) { - logger.error(e.getLocalizedMessage()); - } - }); - } - @Override public Integer call() throws Exception { + coverager= new Coverager(connectionOptions,filterOptions, metadataOptions, outputOptions, debuggerOptions, loggingOptions, opid); + return coverager.call(); - int result = CommandLine.ExitCode.OK; - getServerSocket(); - - - RuntimeDebugModelXmlSerializer serializer = new MyRuntimeDebugModelXmlSerializer(); - client = new DebugClient(serializer); - - UUID measureUuid = UUID.randomUUID(); - - rawMode = metadataOptions.isRawMode(); - - Map uriListByKey = Utils.readMetadata(metadataOptions, coverageData); - - try { - startSystem(measureUuid); - } catch (RuntimeDebugClientException e) { - logger.info("Connecting to dbgs failed"); - logger.error(e.getLocalizedMessage()); - result = CommandLine.ExitCode.SOFTWARE; - return result; - } - - addShutdownHook(); - - Set externalDataProcessorsUriSet = new HashSet<>(); - - try { - mainLoop(uriListByKey, externalDataProcessorsUriSet); - } catch (RuntimeDebugClientException e) { - logger.error("Can't send ping to debug server. Coverage analyzing finished"); - logger.error(e.getLocalizedMessage()); - e.printStackTrace(); - result = CommandLine.ExitCode.SOFTWARE; - } - Thread.sleep(debuggerOptions.getPingTimeout()); - - shutdown(); - return result; - } - - private void shutdown() throws IOException { - if (opid > 0 && !Utils.isProcessStillAlive(opid)) { - logger.info("Owner process stopped: {}", opid); - } - - gracefulShutdown(null); - - logger.info("Disconnecting from dbgs..."); - try { - client.disconnect(); - client.dispose(); - } catch (RuntimeDebugClientException e) { - logger.error(e.getLocalizedMessage()); - } - closeSocket(); - - logger.info("Main thread finished"); - stopExecution.set(true); - } - - private void addShutdownHook() { - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - try { - shutdown(); - } catch (IOException e) { - logger.info("Shutdown error."); - e.printStackTrace(); - } - })); } - private void targetStarted(DBGUIExtCmdInfoStartedImpl command) { - DebugTargetId targetId = command.getTargetID(); - try { - client.attachRuntimeDebugTargets(Collections.singletonList(UUID.fromString(targetId.getId()))); - } catch (RuntimeDebugClientException e) { - logger.info("Command: {} error!", command.getCmdID().getName()); - logger.error(e.getLocalizedMessage()); - } - } - - private void mainLoop(Map uriListByKey, Set externalDataProcessorsUriSet) throws RuntimeDebugClientException { - while (!stopExecution.get()) { - List commandsList = client.ping(); - logger.info("Ping result commands size: {}", commandsList.size()); - commandsList.forEach(command -> { - logger.info("Command: {}", command.getCmdID().getName()); - if (command.getCmdID() == DBGUIExtCmds.MEASURE_RESULT_PROCESSING) { - measureResultProcessing(uriListByKey, externalDataProcessorsUriSet, (DBGUIExtCmdInfoMeasureImpl) command); - } else if (command.getCmdID() == DBGUIExtCmds.TARGET_STARTED) { - targetStarted((DBGUIExtCmdInfoStartedImpl) command); - } - }); - } - } - - private void measureResultProcessing(Map uriListByKey, Set externalDataProcessorsUriSet, DBGUIExtCmdInfoMeasureImpl command) { - logger.info("Found MEASURE_RESULT_PROCESSING command"); - PerformanceInfoMain measure = command.getMeasure(); - EList moduleInfoList = measure.getModuleData(); - moduleInfoList.forEach(moduleInfo -> { - BSLModuleIdInternal moduleId = moduleInfo.getModuleID(); - String moduleUrl = moduleId.getURL(); - if (loggingOptions.isVerbose() && !moduleUrl.isEmpty() && !externalDataProcessorsUriSet.contains(moduleUrl)) { - logger.info("Found external data processor: {}", moduleUrl); - externalDataProcessorsUriSet.add(moduleUrl); - } - String moduleExtensionName = moduleId.getExtensionName(); - if (filterOptions.getExtensionName().equals(moduleExtensionName) - && filterOptions.getExternalDataProcessorUrl().equals(moduleUrl)) { - String objectId = moduleId.getObjectID(); - String propertyId = moduleId.getPropertyID(); - String key = Utils.getUriKey(objectId, propertyId); - - URI uri; - if (!rawMode) { - uri = uriListByKey.get(key); - } else { - uri = URI.create("file:///" + key); - } - if (uri == null) { - logger.info("Couldn't find object id {}, property id {} in sources!", objectId, propertyId); - } else { - EList lineInfoList = moduleInfo.getLineInfo(); - lineInfoList.forEach(lineInfo -> { - BigDecimal lineNo = lineInfo.getLineNo(); - Map coverMap = coverageData.get(uri); - if (!coverMap.isEmpty() || rawMode) { - if (!rawMode && !coverMap.containsKey(lineNo)) { - if (loggingOptions.isVerbose()) { - logger.info("Can't find line to cover {} in module {}", lineNo, uri); - try { - Stream all_lines = Files.lines(Paths.get(uri)); - Optional first = all_lines.skip(lineNo.longValue() - 1).findFirst(); - if (first.isPresent()) { - String specific_line_n = first.get(); - logger.info(">>> {}", specific_line_n); - } - } catch (Exception e) { - logger.error(e.getLocalizedMessage()); - } - } - } else { - int currentValue = coverMap.getOrDefault(lineNo, 0); - if (currentValue < 0) { - currentValue = 0; - } - coverMap.put(lineNo, - currentValue - + lineInfo.getFrequency().intValue()); - } - } - }); - } - } - }); - } - - private void startSystem(UUID measureUuid) throws RuntimeDebugClientException { - UUID debugServerUuid = UUID.randomUUID(); - client.configure( - connectionOptions.getDebugServerUrl(), - debugServerUuid, - connectionOptions.getInfobaseAlias()); - logger.info("Connecting to debugger..."); - AttachDebugUIResult connectionResult = client.connect(debuggerOptions.getPassword()); - if (connectionResult != AttachDebugUIResult.REGISTERED) { - if (connectionResult == AttachDebugUIResult.IB_IN_DEBUG) { - throw new RuntimeDebugClientException("Can't connect to debug server. IB is in debug. Close configurator or EDT first"); - } else if (connectionResult == AttachDebugUIResult.CREDENTIALS_REQUIRED) { - throw new RuntimeDebugClientException("Can't connect to debug server. Use -p option to set correct password"); - } else { - throw new RuntimeDebugClientException("Can't connect to debug server. Connection result: " + connectionResult); - } - } - Version apiver = Version.parse(client.getApiVersion()); - logger.info("Setup settings..."); - client.initSettings(false); - client.setAutoconnectDebugTargets( - debuggerOptions.getDebugAreaNames(), - debuggerOptions.getFilteredAutoconnectTargets(apiver)); - logger.info("Setup targets..."); - List debugTargets; - if (debuggerOptions.getDebugAreaNames().isEmpty()) { - debugTargets = client.getRuntimeDebugTargets(null); - } else { - debugTargets = new LinkedList<>(); - debuggerOptions.getDebugAreaNames().forEach(areaName -> { - try { - debugTargets.addAll(client.getRuntimeDebugTargets(areaName)); - } catch (RuntimeDebugClientException ex) { - logger.error(ex.getLocalizedMessage()); - } - }); - } - connectAllTargets(debugTargets); - - logger.info("Enabling profiling..."); - client.toggleProfiling(null); - client.toggleProfiling(measureUuid); - - systemStarted = true; - - } - - protected void gracefulShutdown(PrintWriter serverPipeOut) { - if (stopExecution.get()) { - return; - } - - logger.info("Disabling profiling..."); - try { - client.toggleProfiling(null); - } catch (RuntimeDebugClientException e) { - logger.error(e.getLocalizedMessage()); - } - - Utils.dumpCoverageFile(coverageData, metadataOptions, outputOptions); - if(serverPipeOut!=null) { - serverPipeOut.println(PipeMessages.OK_RESULT); - } - stopExecution.set(true); - - logger.info("Bye!"); - } - - @Override - protected MetadataOptions getMetadataOptions() { - return metadataOptions; - } - - @Override - protected Map> getCoverageData() { - return coverageData; - } - - @Override - protected OutputOptions getOutputOptions() { - return outputOptions; - } - - @Override - public ConnectionOptions getConnectionOptions() { - return connectionOptions; - } - - @Override - protected boolean getSystemStarted() { - return systemStarted; - } } diff --git a/src/main/java/com/clouds42/Commands/SendCheckMessageCommand.java b/src/main/java/com/clouds42/Commands/SendCheckMessageCommand.java index 24864aa..7f056e3 100644 --- a/src/main/java/com/clouds42/Commands/SendCheckMessageCommand.java +++ b/src/main/java/com/clouds42/Commands/SendCheckMessageCommand.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/Commands/SendCleanMessageCommand.java b/src/main/java/com/clouds42/Commands/SendCleanMessageCommand.java index eaab80d..caf0443 100644 --- a/src/main/java/com/clouds42/Commands/SendCleanMessageCommand.java +++ b/src/main/java/com/clouds42/Commands/SendCleanMessageCommand.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/Commands/SendDumpMessageCommand.java b/src/main/java/com/clouds42/Commands/SendDumpMessageCommand.java index d8b8522..ce83373 100644 --- a/src/main/java/com/clouds42/Commands/SendDumpMessageCommand.java +++ b/src/main/java/com/clouds42/Commands/SendDumpMessageCommand.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/Commands/SendMessageCommand.java b/src/main/java/com/clouds42/Commands/SendMessageCommand.java index 85214ac..27706d2 100644 --- a/src/main/java/com/clouds42/Commands/SendMessageCommand.java +++ b/src/main/java/com/clouds42/Commands/SendMessageCommand.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/Commands/SendStatsMessageCommand.java b/src/main/java/com/clouds42/Commands/SendStatsMessageCommand.java index 5cd1e5f..de5356f 100644 --- a/src/main/java/com/clouds42/Commands/SendStatsMessageCommand.java +++ b/src/main/java/com/clouds42/Commands/SendStatsMessageCommand.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/Commands/SendStopMessageCommand.java b/src/main/java/com/clouds42/Commands/SendStopMessageCommand.java index 0005c58..b29e55f 100644 --- a/src/main/java/com/clouds42/Commands/SendStopMessageCommand.java +++ b/src/main/java/com/clouds42/Commands/SendStopMessageCommand.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/Coverage41C.java b/src/main/java/com/clouds42/Coverage41C.java index c510ffe..dfd8851 100644 --- a/src/main/java/com/clouds42/Coverage41C.java +++ b/src/main/java/com/clouds42/Coverage41C.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/Coverager.java b/src/main/java/com/clouds42/Coverager.java new file mode 100644 index 0000000..d3eb443 --- /dev/null +++ b/src/main/java/com/clouds42/Coverager.java @@ -0,0 +1,397 @@ +/* + * This file is a part of Coverage41C. + * + * Copyright (c) 2020-2021 + * Kosolapov Stanislav aka proDOOMman and contributors + * + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Coverage41C is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * Coverage41C is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Coverage41C. + */ +package com.clouds42; + +import com._1c.g5.v8.dt.debug.core.runtime.client.RuntimeDebugClientException; +import com._1c.g5.v8.dt.debug.model.base.data.AttachDebugUIResult; +import com._1c.g5.v8.dt.debug.model.base.data.BSLModuleIdInternal; +import com._1c.g5.v8.dt.debug.model.base.data.DebugTargetId; +import com._1c.g5.v8.dt.debug.model.dbgui.commands.DBGUIExtCmdInfoBase; +import com._1c.g5.v8.dt.debug.model.dbgui.commands.DBGUIExtCmds; +import com._1c.g5.v8.dt.debug.model.dbgui.commands.impl.DBGUIExtCmdInfoMeasureImpl; +import com._1c.g5.v8.dt.debug.model.dbgui.commands.impl.DBGUIExtCmdInfoStartedImpl; +import com._1c.g5.v8.dt.debug.model.measure.PerformanceInfoLine; +import com._1c.g5.v8.dt.debug.model.measure.PerformanceInfoMain; +import com._1c.g5.v8.dt.debug.model.measure.PerformanceInfoModule; +import com._1c.g5.v8.dt.internal.debug.core.runtime.client.RuntimeDebugModelXmlSerializer; +import com.clouds42.CommandLineOptions.ConnectionOptions; +import com.clouds42.CommandLineOptions.DebuggerOptions; +import com.clouds42.CommandLineOptions.FilterOptions; +import com.clouds42.CommandLineOptions.LoggingOptions; +import com.clouds42.CommandLineOptions.MetadataOptions; +import com.clouds42.CommandLineOptions.OutputOptions; +import com.clouds42.Commands.CoverServer; +import org.eclipse.emf.common.util.EList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import picocli.CommandLine; +import picocli.CommandLine.Option; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.invoke.MethodHandles; +import java.lang.module.ModuleDescriptor.Version; +import java.math.BigDecimal; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Stream; + + +public class Coverager extends CoverServer { + + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + private ConnectionOptions connectionOptions; + + + private FilterOptions filterOptions; + + + private MetadataOptions metadataOptions; + + + private OutputOptions outputOptions; + + + private DebuggerOptions debuggerOptions; + + + private LoggingOptions loggingOptions; + + @Option(names = {"--opid"}, description = "Owner process PID", defaultValue = "-1") + Integer opid; + + private DebugClient client; + + private final Map> coverageData = new HashMap<>() { + @Override + public Map get(Object key) { + Map map = super.get(key); + if (map == null) { + map = new HashMap<>(); + put((URI) key, map); + } + return map; + } + }; + + + private final AtomicBoolean stopExecution = new AtomicBoolean(false); + private boolean rawMode = false; + private boolean systemStarted = false; + + public Coverager(ConnectionOptions connectionOptions, + FilterOptions filterOptions, + MetadataOptions metadataOptions, + OutputOptions outputOptions, + DebuggerOptions debuggerOptions, + LoggingOptions loggingOptions, + Integer opid) { + this.connectionOptions = connectionOptions; + this.filterOptions = filterOptions; + this.metadataOptions = metadataOptions; + this.outputOptions = outputOptions; + this.debuggerOptions = debuggerOptions; + this.loggingOptions = loggingOptions; + this.opid = opid; + } + + private void connectAllTargets(List debugTargets) { + logger.info("Current debug targets size: {}", debugTargets.size()); + debugTargets.forEach(debugTarget -> { + String id = debugTarget.getId(); + String seanceId = debugTarget.getSeanceId(); + String targetType = debugTarget.getTargetType().getName(); + logger.info("Id: {} , seance id: {} , target type: {}", id, seanceId, targetType); + try { + client.attachRuntimeDebugTargets(Collections.singletonList(UUID.fromString(debugTarget.getId()))); + } catch (RuntimeDebugClientException e) { + logger.error(e.getLocalizedMessage()); + } + }); + } + + + public Integer call() throws Exception { + + int result = CommandLine.ExitCode.OK; + getServerSocket(); + + + RuntimeDebugModelXmlSerializer serializer = new MyRuntimeDebugModelXmlSerializer(); + client = new DebugClient(serializer); + + UUID measureUuid = UUID.randomUUID(); + + rawMode = metadataOptions.isRawMode(); + + Map uriListByKey = Utils.readMetadata(metadataOptions, coverageData); + + try { + startSystem(measureUuid); + } catch (RuntimeDebugClientException e) { + logger.info("Connecting to dbgs failed"); + logger.error(e.getLocalizedMessage()); + result = CommandLine.ExitCode.SOFTWARE; + return result; + } + + addShutdownHook(); + + Set externalDataProcessorsUriSet = new HashSet<>(); + + try { + mainLoop(uriListByKey, externalDataProcessorsUriSet); + } catch (RuntimeDebugClientException e) { + logger.error("Can't send ping to debug server. Coverage analyzing finished"); + logger.error(e.getLocalizedMessage()); + e.printStackTrace(); + result = CommandLine.ExitCode.SOFTWARE; + } + Thread.sleep(debuggerOptions.getPingTimeout()); + + shutdown(); + return result; + } + + private void shutdown() throws IOException { + if (opid > 0 && !Utils.isProcessStillAlive(opid)) { + logger.info("Owner process stopped: {}", opid); + } + + gracefulShutdown(null); + + logger.info("Disconnecting from dbgs..."); + try { + client.disconnect(); + client.dispose(); + } catch (RuntimeDebugClientException e) { + logger.error(e.getLocalizedMessage()); + } + closeSocket(); + + logger.info("Main thread finished"); + stopExecution.set(true); + } + + private void addShutdownHook() { + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + try { + shutdown(); + } catch (IOException e) { + logger.info("Shutdown error."); + e.printStackTrace(); + } + })); + } + + private void targetStarted(DBGUIExtCmdInfoStartedImpl command) { + DebugTargetId targetId = command.getTargetID(); + try { + client.attachRuntimeDebugTargets(Collections.singletonList(UUID.fromString(targetId.getId()))); + } catch (RuntimeDebugClientException e) { + logger.info("Command: {} error!", command.getCmdID().getName()); + logger.error(e.getLocalizedMessage()); + } + } + + private void mainLoop(Map uriListByKey, Set externalDataProcessorsUriSet) throws RuntimeDebugClientException { + while (!stopExecution.get()) { + List commandsList = client.ping(); + logger.info("Ping result commands size: {}", commandsList.size()); + commandsList.forEach(command -> { + logger.info("Command: {}", command.getCmdID().getName()); + if (command.getCmdID() == DBGUIExtCmds.MEASURE_RESULT_PROCESSING) { + measureResultProcessing(uriListByKey, externalDataProcessorsUriSet, (DBGUIExtCmdInfoMeasureImpl) command); + } else if (command.getCmdID() == DBGUIExtCmds.TARGET_STARTED) { + targetStarted((DBGUIExtCmdInfoStartedImpl) command); + } + }); + } + } + + private void measureResultProcessing(Map uriListByKey, Set externalDataProcessorsUriSet, DBGUIExtCmdInfoMeasureImpl command) { + logger.info("Found MEASURE_RESULT_PROCESSING command"); + PerformanceInfoMain measure = command.getMeasure(); + EList moduleInfoList = measure.getModuleData(); + moduleInfoList.forEach(moduleInfo -> { + BSLModuleIdInternal moduleId = moduleInfo.getModuleID(); + String moduleUrl = moduleId.getURL(); + if (loggingOptions.isVerbose() && !moduleUrl.isEmpty() && !externalDataProcessorsUriSet.contains(moduleUrl)) { + logger.info("Found external data processor: {}", moduleUrl); + externalDataProcessorsUriSet.add(moduleUrl); + } + String moduleExtensionName = moduleId.getExtensionName(); + if (filterOptions.getExtensionName().equals(moduleExtensionName) + && filterOptions.getExternalDataProcessorUrl().equals(moduleUrl)) { + String objectId = moduleId.getObjectID(); + String propertyId = moduleId.getPropertyID(); + String key = Utils.getUriKey(objectId, propertyId); + + URI uri; + if (!rawMode) { + uri = uriListByKey.get(key); + } else { + uri = URI.create("file:///" + key); + } + if (uri == null) { + logger.info("Couldn't find object id {}, property id {} in sources!", objectId, propertyId); + } else { + EList lineInfoList = moduleInfo.getLineInfo(); + lineInfoList.forEach(lineInfo -> { + BigDecimal lineNo = lineInfo.getLineNo(); + Map coverMap = coverageData.get(uri); + if (!coverMap.isEmpty() || rawMode) { + if (!rawMode && !coverMap.containsKey(lineNo)) { + if (loggingOptions.isVerbose()) { + logger.info("Can't find line to cover {} in module {}", lineNo, uri); + try { + Stream all_lines = Files.lines(Paths.get(uri)); + Optional first = all_lines.skip(lineNo.longValue() - 1).findFirst(); + if (first.isPresent()) { + String specific_line_n = first.get(); + logger.info(">>> {}", specific_line_n); + } + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + } + } + } else { + int currentValue = coverMap.getOrDefault(lineNo, 0); + if (currentValue < 0) { + currentValue = 0; + } + coverMap.put(lineNo, + currentValue + + lineInfo.getFrequency().intValue()); + } + } + }); + } + } + }); + } + + private void startSystem(UUID measureUuid) throws RuntimeDebugClientException { + UUID debugServerUuid = UUID.randomUUID(); + client.configure( + connectionOptions.getDebugServerUrl(), + debugServerUuid, + connectionOptions.getInfobaseAlias()); + logger.info("Connecting to debugger..."); + AttachDebugUIResult connectionResult = client.connect(debuggerOptions.getPassword()); + if (connectionResult != AttachDebugUIResult.REGISTERED) { + if (connectionResult == AttachDebugUIResult.IB_IN_DEBUG) { + throw new RuntimeDebugClientException("Can't connect to debug server. IB is in debug. Close configurator or EDT first"); + } else if (connectionResult == AttachDebugUIResult.CREDENTIALS_REQUIRED) { + throw new RuntimeDebugClientException("Can't connect to debug server. Use -p option to set correct password"); + } else { + throw new RuntimeDebugClientException("Can't connect to debug server. Connection result: " + connectionResult); + } + } + Version apiver = Version.parse(client.getApiVersion()); + logger.info("Setup settings..."); + client.initSettings(false); + client.setAutoconnectDebugTargets( + debuggerOptions.getDebugAreaNames(), + debuggerOptions.getFilteredAutoconnectTargets(apiver)); + logger.info("Setup targets..."); + List debugTargets; + if (debuggerOptions.getDebugAreaNames().isEmpty()) { + debugTargets = client.getRuntimeDebugTargets(null); + } else { + debugTargets = new LinkedList<>(); + debuggerOptions.getDebugAreaNames().forEach(areaName -> { + try { + debugTargets.addAll(client.getRuntimeDebugTargets(areaName)); + } catch (RuntimeDebugClientException ex) { + logger.error(ex.getLocalizedMessage()); + } + }); + } + connectAllTargets(debugTargets); + + logger.info("Enabling profiling..."); + client.toggleProfiling(null); + client.toggleProfiling(measureUuid); + + systemStarted = true; + + } + + protected void gracefulShutdown(PrintWriter serverPipeOut) { + if (stopExecution.get()) { + return; + } + + logger.info("Disabling profiling..."); + try { + client.toggleProfiling(null); + } catch (RuntimeDebugClientException e) { + logger.error(e.getLocalizedMessage()); + } + + Utils.dumpCoverageFile(coverageData, metadataOptions, outputOptions); + if (serverPipeOut != null) { + serverPipeOut.println(PipeMessages.OK_RESULT); + } + stopExecution.set(true); + + logger.info("Bye!"); + } + + @Override + protected MetadataOptions getMetadataOptions() { + return metadataOptions; + } + + @Override + protected Map> getCoverageData() { + return coverageData; + } + + @Override + protected OutputOptions getOutputOptions() { + return outputOptions; + } + + @Override + public ConnectionOptions getConnectionOptions() { + return connectionOptions; + } + + @Override + protected boolean getSystemStarted() { + return systemStarted; + } +} diff --git a/src/main/java/com/clouds42/DebugClient.java b/src/main/java/com/clouds42/DebugClient.java index 42137fc..9daaa61 100644 --- a/src/main/java/com/clouds42/DebugClient.java +++ b/src/main/java/com/clouds42/DebugClient.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later @@ -332,13 +332,22 @@ public List getDebugAreas() throws RuntimeDebugClientException { public void setAutoconnectDebugTargets(List debugAreaNames, List debugTargets) throws RuntimeDebugClientException { RDBGSetAutoAttachSettingsRequest requestContent = ResponseFactory.eINSTANCE.createRDBGSetAutoAttachSettingsRequest(); DebugAutoAttachSettings settings = AttachFactory.eINSTANCE.createDebugAutoAttachSettings(); - settings.getTargetType().addAll(debugTargets); + + List v8debugTypes = debugTargets.stream() + .map(type -> castByName(type, com._1c.g5.v8.dt.debug.model.base.data.DebugTargetType.class)) + .collect(Collectors.toList()); + + settings.getTargetType().addAll(v8debugTypes); settings.getAreaName().addAll(debugAreaNames); requestContent.setAutoAttachSettings(settings); Request request = this.buildRequest(HttpMethod.POST, this.debugComponentUrl).param("cmd", "setAutoAttachSettings"); this.performRuntimeHttpRequest(request, this.initRequest(requestContent)); } + public > F castByName(final Enum e, final Class fClass) { + return F.valueOf(fClass, e.name()); + } + public void toggleProfiling(UUID uuid) throws RuntimeDebugClientException { RDBGSetMeasureModeRequest requestContent = ResponseFactory.eINSTANCE.createRDBGSetMeasureModeRequest(); if (uuid != null) { diff --git a/src/main/java/com/clouds42/DebugTargetType.java b/src/main/java/com/clouds42/DebugTargetType.java new file mode 100644 index 0000000..bdb7c41 --- /dev/null +++ b/src/main/java/com/clouds42/DebugTargetType.java @@ -0,0 +1,92 @@ +/* + * This file is a part of Coverage41C. + * + * Copyright (c) 2020-2021 + * Kosolapov Stanislav aka proDOOMman and contributors + * + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Coverage41C is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * Coverage41C is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Coverage41C. + */ +package com.clouds42; + +import org.eclipse.emf.common.util.Enumerator; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public enum DebugTargetType implements Enumerator { + UNKNOWN(0, "Unknown", "Unknown"), + CLIENT(1, "Client", "Client"), + MANAGED_CLIENT(2, "ManagedClient", "ManagedClient"), + WEB_CLIENT(3, "WEBClient", "WEBClient"), + COM_CONNECTOR(4, "COMConnector", "COMConnector"), + SERVER(5, "Server", "Server"), + SERVER_EMULATION(6, "ServerEmulation", "ServerEmulation"), + WEB_SERVICE(7, "WEBService", "WEBService"), + HTTP_SERVICE(8, "HTTPService", "HTTPService"), + ODATA(9, "OData", "OData"), + JOB(10, "JOB", "JOB"), + JOB_FILE_MODE(11, "JobFileMode", "JobFileMode"), + MOBILE_CLIENT(12, "MobileClient", "MobileClient"), + MOBILE_SERVER(13, "MobileServer", "MobileServer"), + MOBILE_JOB_FILE_MODE(14, "MobileJobFileMode", "MobileJobFileMode"), + MOBILE_MANAGED_CLIENT(15, "MobileManagedClient", "MobileManagedClient"); + + public static final int UNKNOWN_VALUE = 0; + public static final int CLIENT_VALUE = 1; + public static final int MANAGED_CLIENT_VALUE = 2; + public static final int WEB_CLIENT_VALUE = 3; + public static final int COM_CONNECTOR_VALUE = 4; + public static final int SERVER_VALUE = 5; + public static final int SERVER_EMULATION_VALUE = 6; + public static final int WEB_SERVICE_VALUE = 7; + public static final int HTTP_SERVICE_VALUE = 8; + public static final int ODATA_VALUE = 9; + public static final int JOB_VALUE = 10; + public static final int JOB_FILE_MODE_VALUE = 11; + public static final int MOBILE_CLIENT_VALUE = 12; + public static final int MOBILE_SERVER_VALUE = 13; + public static final int MOBILE_JOB_FILE_MODE_VALUE = 14; + public static final int MOBILE_MANAGED_CLIENT_VALUE = 15; + private static final DebugTargetType[] VALUES_ARRAY = new DebugTargetType[]{UNKNOWN, CLIENT, MANAGED_CLIENT, WEB_CLIENT, COM_CONNECTOR, SERVER, SERVER_EMULATION, WEB_SERVICE, HTTP_SERVICE, ODATA, JOB, JOB_FILE_MODE, MOBILE_CLIENT, MOBILE_SERVER, MOBILE_JOB_FILE_MODE, MOBILE_MANAGED_CLIENT}; + public static final List VALUES = Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY)); + private final int value; + private final String name; + private final String literal; + + private DebugTargetType(int value, String name, String literal) { + this.value = value; + this.name = name; + this.literal = literal; + } + + public int getValue() { + return this.value; + } + + public String getName() { + return this.name; + } + + public String getLiteral() { + return this.literal; + } + + public String toString() { + return this.literal; + } +} + diff --git a/src/main/java/com/clouds42/GlobalCallsFilter.java b/src/main/java/com/clouds42/GlobalCallsFilter.java index 7a3376b..703a4cd 100644 --- a/src/main/java/com/clouds42/GlobalCallsFilter.java +++ b/src/main/java/com/clouds42/GlobalCallsFilter.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/LinesToCoverage.java b/src/main/java/com/clouds42/LinesToCoverage.java index 2384333..2ec1d0c 100644 --- a/src/main/java/com/clouds42/LinesToCoverage.java +++ b/src/main/java/com/clouds42/LinesToCoverage.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later @@ -41,6 +41,7 @@ public class LinesToCoverage { BSLParser.BreakStatementContext.class, BSLParser.ContinueStatementContext.class, BSLParser.IfStatementContext.class, + BSLParser.ElsifBranchContext.class, BSLParser.RaiseStatementContext.class, BSLParser.ForEachStatementContext.class, BSLParser.ForStatementContext.class, diff --git a/src/main/java/com/clouds42/MyRuntimeDebugModelXmlSerializer.java b/src/main/java/com/clouds42/MyRuntimeDebugModelXmlSerializer.java index 941576a..ac4d622 100644 --- a/src/main/java/com/clouds42/MyRuntimeDebugModelXmlSerializer.java +++ b/src/main/java/com/clouds42/MyRuntimeDebugModelXmlSerializer.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/PipeMessages.java b/src/main/java/com/clouds42/PipeMessages.java index a166a09..64ceb1e 100644 --- a/src/main/java/com/clouds42/PipeMessages.java +++ b/src/main/java/com/clouds42/PipeMessages.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/main/java/com/clouds42/Utils.java b/src/main/java/com/clouds42/Utils.java index 7988eeb..e0c8651 100644 --- a/src/main/java/com/clouds42/Utils.java +++ b/src/main/java/com/clouds42/Utils.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/test/java/com/clouds42/ConvertTest.java b/src/test/java/com/clouds42/ConvertTest.java index e54480e..b3ed8aa 100644 --- a/src/test/java/com/clouds42/ConvertTest.java +++ b/src/test/java/com/clouds42/ConvertTest.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/test/java/com/clouds42/CoverageTest.java b/src/test/java/com/clouds42/CoverageTest.java index eed2ad7..e493dec 100644 --- a/src/test/java/com/clouds42/CoverageTest.java +++ b/src/test/java/com/clouds42/CoverageTest.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/test/java/com/clouds42/LinesToCoverageTest.java b/src/test/java/com/clouds42/LinesToCoverageTest.java index 1dcd9ae..d18aba7 100644 --- a/src/test/java/com/clouds42/LinesToCoverageTest.java +++ b/src/test/java/com/clouds42/LinesToCoverageTest.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later @@ -78,6 +78,18 @@ void SimpleTest() throws IOException { assertThat(linesToCover, equalTo(expected)); } + @Test + void IfTest() throws IOException { + + var file = new File("src/test/resources/linestocoverage/if.bsl"); + BSLTokenizer tokenizer = new BSLTokenizer(Files.readString(file.toPath())); + + int[] linesToCover = LinesToCoverage.getLines(tokenizer.getAst()); + + var expected = new int[]{3, 8, 10, 16, 17, 19, 21, 22, 23}; + assertThat(linesToCover, equalTo(expected)); + } + @Test void AssigmentTest() throws IOException { @@ -157,8 +169,8 @@ void FilterTest() throws IOException { int[] linesToCover = LinesToCoverage.getLines(tokenizer.getAst()); // Реальный замер - // 3, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 23, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 62, 63, 65, 70, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 122, 126, 128, 130, 132, 134, 135, 136, 137, 139, 141, 141, 142, 142, 143, 143 - var expected = new int[]{3, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 23, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 62, 63, 65, 70, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 122, 126, 128, 130, 132, 134, 135, 136, 137, 139, 141, 142, 143}; + // 3, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 23, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 62, 63, 65, 70, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 122, 126, 128, 130, 132, 134, 135, 136, 137, 139, 143, 146, 149, 152, 155, 155, 156, 156, 157, 157, 158, 158 + var expected = new int[]{3, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 23, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 62, 63, 65, 70, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 122, 126, 128, 130, 132, 134, 135, 136, 137, 139, 143, 146, 149, 152, 155, 156, 157, 158}; assertThat(linesToCover, equalTo(expected)); } diff --git a/src/test/java/com/clouds42/TestUtils.java b/src/test/java/com/clouds42/TestUtils.java index e6f4580..c319885 100644 --- a/src/test/java/com/clouds42/TestUtils.java +++ b/src/test/java/com/clouds42/TestUtils.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/test/java/com/clouds42/UtilsTest.java b/src/test/java/com/clouds42/UtilsTest.java index b254149..8e076be 100644 --- a/src/test/java/com/clouds42/UtilsTest.java +++ b/src/test/java/com/clouds42/UtilsTest.java @@ -1,7 +1,7 @@ /* * This file is a part of Coverage41C. * - * Copyright (c) 2020-2021 + * Copyright (c) 2020-2022 * Kosolapov Stanislav aka proDOOMman and contributors * * SPDX-License-Identifier: LGPL-3.0-or-later diff --git a/src/test/resources/linestocoverage/filtered.bsl b/src/test/resources/linestocoverage/filtered.bsl index 3ddb0c7..cc97acc 100644 --- a/src/test/resources/linestocoverage/filtered.bsl +++ b/src/test/resources/linestocoverage/filtered.bsl @@ -138,6 +138,21 @@ КонецПроцедуры +Процедура ФункцииТип(СоответствиеТипов); + +Тип = + Тип("Строка"); + +Тип = + ТипЗнч("Строка"); + +СоответствиеТипов.Вставить( +Тип("Строка"), "Строка"); + +КонецПроцедуры + + ФункцииРаботаСоСтроками(); ФункцииРаботыСДатой(); ФункцииПреобразованияЗначений(); +ФункцииТип(Новый Соответствие); diff --git a/src/test/resources/linestocoverage/if.bsl b/src/test/resources/linestocoverage/if.bsl new file mode 100644 index 0000000..f39be0e --- /dev/null +++ b/src/test/resources/linestocoverage/if.bsl @@ -0,0 +1,23 @@ +Функция Условие(А, Б) + + Если + А + = + Б + Тогда + Возврат + Истина; + ИначеЕсли + А + = + "М" + Тогда + Иначе + Возврат Истина; + КонецЕсли; + +КонецФункции + +Условие("В", "В"); +Условие("В", "М"); +Условие("В", "Г");